OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/overview/window_selector_window.h" | 5 #include "ash/wm/overview/scoped_transform_overview_window.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
9 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/compositor/layer_animation_observer.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
13 #include "ui/compositor/scoped_layer_animation_settings.h" | 13 #include "ui/compositor/scoped_layer_animation_settings.h" |
14 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
15 #include "ui/gfx/interpolated_transform.h" | 15 #include "ui/gfx/interpolated_transform.h" |
16 #include "ui/gfx/transform_util.h" | 16 #include "ui/gfx/transform_util.h" |
17 #include "ui/views/corewm/shadow_types.h" | 17 #include "ui/views/corewm/shadow_types.h" |
18 #include "ui/views/corewm/window_animations.h" | 18 #include "ui/views/corewm/window_animations.h" |
19 #include "ui/views/corewm/window_util.h" | 19 #include "ui/views/corewm/window_util.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const int kOverviewWindowTransitionMilliseconds = 100; | |
27 | |
28 // Creates a copy of |window| with |recreated_layer| in the |target_root|. | 26 // Creates a copy of |window| with |recreated_layer| in the |target_root|. |
29 views::Widget* CreateCopyOfWindow(aura::RootWindow* target_root, | 27 views::Widget* CreateCopyOfWindow(aura::RootWindow* target_root, |
30 aura::Window* src_window, | 28 aura::Window* src_window, |
31 ui::Layer* recreated_layer) { | 29 ui::Layer* recreated_layer) { |
32 views::Widget* widget = new views::Widget; | 30 views::Widget* widget = new views::Widget; |
33 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 31 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
34 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 32 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
35 params.parent = src_window->parent(); | 33 params.parent = src_window->parent(); |
36 params.can_activate = false; | 34 params.can_activate = false; |
37 params.keep_on_top = true; | 35 params.keep_on_top = true; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 128 |
131 // The animation settings used for window selector animations. | 129 // The animation settings used for window selector animations. |
132 class WindowSelectorAnimationSettings | 130 class WindowSelectorAnimationSettings |
133 : public ui::ScopedLayerAnimationSettings { | 131 : public ui::ScopedLayerAnimationSettings { |
134 public: | 132 public: |
135 WindowSelectorAnimationSettings(aura::Window* window) : | 133 WindowSelectorAnimationSettings(aura::Window* window) : |
136 ui::ScopedLayerAnimationSettings(window->layer()->GetAnimator()) { | 134 ui::ScopedLayerAnimationSettings(window->layer()->GetAnimator()) { |
137 SetPreemptionStrategy( | 135 SetPreemptionStrategy( |
138 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 136 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
139 SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 137 SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
140 kOverviewWindowTransitionMilliseconds)); | 138 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
141 } | 139 } |
142 | 140 |
143 virtual ~WindowSelectorAnimationSettings() { | 141 virtual ~WindowSelectorAnimationSettings() { |
144 } | 142 } |
145 }; | 143 }; |
146 | 144 |
147 } // namespace | 145 } // namespace |
148 | 146 |
149 WindowSelectorWindow::WindowSelectorWindow(aura::Window* window) | 147 const int ScopedTransformOverviewWindow::kTransitionMilliseconds = 100; |
| 148 |
| 149 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow( |
| 150 aura::Window* window) |
150 : window_(window), | 151 : window_(window), |
151 window_copy_(NULL), | 152 window_copy_(NULL), |
152 layer_(NULL), | 153 layer_(NULL), |
153 minimized_(window->GetProperty(aura::client::kShowStateKey) == | 154 minimized_(window->GetProperty(aura::client::kShowStateKey) == |
154 ui::SHOW_STATE_MINIMIZED), | 155 ui::SHOW_STATE_MINIMIZED), |
| 156 overview_started_(false), |
155 original_transform_(window->layer()->GetTargetTransform()) { | 157 original_transform_(window->layer()->GetTargetTransform()) { |
156 } | 158 } |
157 | 159 |
158 WindowSelectorWindow::~WindowSelectorWindow() { | 160 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { |
159 if (window_) { | 161 if (window_) { |
160 WindowSelectorAnimationSettings animation_settings(window_); | 162 WindowSelectorAnimationSettings animation_settings(window_); |
161 gfx::Transform transform; | 163 gfx::Transform transform; |
162 window_->SetTransform(original_transform_); | 164 window_->SetTransform(original_transform_); |
163 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) != | 165 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) != |
164 ui::SHOW_STATE_MINIMIZED) { | 166 ui::SHOW_STATE_MINIMIZED) { |
165 // Setting opacity 0 and visible false ensures that the property change | 167 // Setting opacity 0 and visible false ensures that the property change |
166 // to SHOW_STATE_MINIMIZED will not animate the window from its original | 168 // to SHOW_STATE_MINIMIZED will not animate the window from its original |
167 // bounds to the minimized position. | 169 // bounds to the minimized position. |
168 window_->layer()->SetOpacity(0); | 170 window_->layer()->SetOpacity(0); |
169 window_->layer()->SetVisible(false); | 171 window_->Hide(); |
170 window_->SetProperty(aura::client::kShowStateKey, | 172 window_->SetProperty(aura::client::kShowStateKey, |
171 ui::SHOW_STATE_MINIMIZED); | 173 ui::SHOW_STATE_MINIMIZED); |
172 } | 174 } |
173 } | 175 } |
174 // If a copy of the window was created, clean it up. | 176 // If a copy of the window was created, clean it up. |
175 if (window_copy_) { | 177 if (window_copy_) { |
176 if (window_) { | 178 if (window_) { |
177 // If the initial window wasn't destroyed, the copy needs to be animated | 179 // If the initial window wasn't destroyed, the copy needs to be animated |
178 // out. CleanupWidgetAfterAnimationObserver will destroy the widget and | 180 // out. CleanupWidgetAfterAnimationObserver will destroy the widget and |
179 // layer after the animation is complete. | 181 // layer after the animation is complete. |
180 new CleanupWidgetAfterAnimationObserver(window_copy_, layer_); | 182 new CleanupWidgetAfterAnimationObserver(window_copy_, layer_); |
181 WindowSelectorAnimationSettings animation_settings( | 183 WindowSelectorAnimationSettings animation_settings( |
182 window_copy_->GetNativeWindow()); | 184 window_copy_->GetNativeWindow()); |
183 window_copy_->GetNativeWindow()->SetTransform(original_transform_); | 185 window_copy_->GetNativeWindow()->SetTransform(original_transform_); |
184 } else { | 186 } else { |
185 window_copy_->Close(); | 187 window_copy_->Close(); |
186 if (layer_) | 188 if (layer_) |
187 views::corewm::DeepDeleteLayers(layer_); | 189 views::corewm::DeepDeleteLayers(layer_); |
188 } | 190 } |
189 window_copy_ = NULL; | 191 window_copy_ = NULL; |
190 layer_ = NULL; | 192 layer_ = NULL; |
191 } | 193 } |
192 } | 194 } |
193 | 195 |
194 bool WindowSelectorWindow::Contains(const aura::Window* window) const { | 196 bool ScopedTransformOverviewWindow::Contains(const aura::Window* window) const { |
195 if (window_copy_ && window_copy_->GetNativeWindow()->Contains(window)) | 197 if (window_copy_ && window_copy_->GetNativeWindow()->Contains(window)) |
196 return true; | 198 return true; |
197 return window_->Contains(window); | 199 return window_->Contains(window); |
198 } | 200 } |
199 | 201 |
200 void WindowSelectorWindow::RestoreWindowOnExit() { | 202 void ScopedTransformOverviewWindow::RestoreWindow() { |
| 203 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) == |
| 204 ui::SHOW_STATE_MINIMIZED) { |
| 205 window_->Show(); |
| 206 } |
| 207 } |
| 208 |
| 209 void ScopedTransformOverviewWindow::RestoreWindowOnExit() { |
201 minimized_ = false; | 210 minimized_ = false; |
202 original_transform_ = gfx::Transform(); | 211 original_transform_ = gfx::Transform(); |
203 } | 212 } |
204 | 213 |
205 void WindowSelectorWindow::OnWindowDestroyed() { | 214 void ScopedTransformOverviewWindow::OnWindowDestroyed() { |
206 window_ = NULL; | 215 window_ = NULL; |
207 } | 216 } |
208 | 217 |
209 void WindowSelectorWindow::TransformToFitBounds( | 218 gfx::Transform ScopedTransformOverviewWindow:: |
210 aura::RootWindow* root_window, | 219 GetTransformForRectPreservingAspectRatio(const gfx::Rect& rect, |
211 const gfx::Rect& target_bounds) { | 220 const gfx::Rect& bounds) { |
212 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) == | 221 DCHECK(!rect.IsEmpty()); |
213 ui::SHOW_STATE_MINIMIZED) { | 222 DCHECK(!bounds.IsEmpty()); |
214 window_->Show(); | |
215 } | |
216 fit_bounds_ = target_bounds; | |
217 const gfx::Rect bounds = window_->GetBoundsInScreen(); | |
218 float scale = std::min(1.0f, | 223 float scale = std::min(1.0f, |
219 std::min(static_cast<float>(target_bounds.width()) / bounds.width(), | 224 std::min(static_cast<float>(bounds.width()) / rect.width(), |
220 static_cast<float>(target_bounds.height()) / bounds.height())); | 225 static_cast<float>(bounds.height()) / rect.height())); |
221 gfx::Transform transform; | 226 gfx::Transform transform; |
222 gfx::Vector2d offset( | 227 gfx::Vector2d offset( |
223 0.5 * (target_bounds.width() - scale * bounds.width()), | 228 0.5 * (bounds.width() - scale * rect.width()), |
224 0.5 * (target_bounds.height() - scale * bounds.height())); | 229 0.5 * (bounds.height() - scale * rect.height())); |
225 transform.Translate(target_bounds.x() - bounds.x() + offset.x(), | 230 transform.Translate(bounds.x() - rect.x() + offset.x(), |
226 target_bounds.y() - bounds.y() + offset.y()); | 231 bounds.y() - rect.y() + offset.y()); |
227 transform.Scale(scale, scale); | 232 transform.Scale(scale, scale); |
| 233 return transform; |
| 234 } |
| 235 |
| 236 void ScopedTransformOverviewWindow::SetTransform( |
| 237 aura::RootWindow* root_window, |
| 238 const gfx::Transform& transform) { |
| 239 // If this is the first transform, perform one-time window modifications |
| 240 // necessary for overview mode. |
| 241 if (!overview_started_) { |
| 242 OnOverviewStarted(); |
| 243 overview_started_ = true; |
| 244 } |
| 245 |
228 if (root_window != window_->GetRootWindow()) { | 246 if (root_window != window_->GetRootWindow()) { |
229 if (!window_copy_) { | 247 if (!window_copy_) { |
230 DCHECK(!layer_); | 248 DCHECK(!layer_); |
231 layer_ = views::corewm::RecreateWindowLayers(window_, true); | 249 layer_ = views::corewm::RecreateWindowLayers(window_, true); |
232 window_copy_ = CreateCopyOfWindow(root_window, window_, layer_); | 250 window_copy_ = CreateCopyOfWindow(root_window, window_, layer_); |
233 } | 251 } |
234 WindowSelectorAnimationSettings animation_settings( | 252 WindowSelectorAnimationSettings animation_settings( |
235 window_copy_->GetNativeWindow()); | 253 window_copy_->GetNativeWindow()); |
236 window_copy_->GetNativeWindow()->SetTransform(transform); | 254 window_copy_->GetNativeWindow()->SetTransform(transform); |
237 } | 255 } |
238 WindowSelectorAnimationSettings animation_settings(window_); | 256 WindowSelectorAnimationSettings animation_settings(window_); |
239 window_->SetTransform(transform); | 257 window_->SetTransform(transform); |
240 } | 258 } |
241 | 259 |
| 260 void ScopedTransformOverviewWindow::OnOverviewStarted() { |
| 261 RestoreWindow(); |
| 262 } |
| 263 |
242 } // namespace ash | 264 } // namespace ash |
OLD | NEW |