OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/window_overview_mode.h" | 5 #include "athena/wm/window_overview_mode.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <complex> |
8 #include <functional> | |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "athena/wm/overview_toolbar.h" | 10 #include "athena/wm/overview_toolbar.h" |
12 #include "athena/wm/public/window_list_provider.h" | 11 #include "athena/wm/public/window_list_provider.h" |
13 #include "athena/wm/public/window_list_provider_observer.h" | 12 #include "athena/wm/public/window_list_provider_observer.h" |
14 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
15 #include "base/bind.h" | 14 #include "base/bind.h" |
16 #include "base/macros.h" | 15 #include "base/memory/scoped_vector.h" |
17 #include "ui/aura/scoped_window_targeter.h" | 16 #include "ui/aura/scoped_window_targeter.h" |
18 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
20 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
21 #include "ui/aura/window_targeter.h" | 20 #include "ui/aura/window_targeter.h" |
22 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
23 #include "ui/compositor/closure_animation_observer.h" | 22 #include "ui/compositor/closure_animation_observer.h" |
24 #include "ui/compositor/compositor.h" | 23 #include "ui/compositor/compositor.h" |
25 #include "ui/compositor/compositor_animation_observer.h" | 24 #include "ui/compositor/compositor_animation_observer.h" |
26 #include "ui/compositor/scoped_layer_animation_settings.h" | 25 #include "ui/compositor/scoped_layer_animation_settings.h" |
27 #include "ui/events/event_handler.h" | 26 #include "ui/events/event_handler.h" |
28 #include "ui/events/gestures/fling_curve.h" | 27 #include "ui/events/gestures/fling_curve.h" |
29 #include "ui/gfx/frame_time.h" | 28 #include "ui/gfx/frame_time.h" |
30 #include "ui/gfx/transform.h" | 29 #include "ui/gfx/transform.h" |
31 #include "ui/wm/core/shadow_types.h" | 30 #include "ui/wm/core/shadow_types.h" |
32 #include "ui/wm/core/window_animations.h" | 31 #include "ui/wm/core/window_animations.h" |
33 #include "ui/wm/core/window_util.h" | 32 #include "ui/wm/core/window_util.h" |
| 33 #include "ui/wm/public/activation_client.h" |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const float kOverviewDefaultScale = 0.75f; | |
38 | |
39 struct WindowOverviewState { | 37 struct WindowOverviewState { |
40 // The current overview state of the window. 0.f means the window is at the | 38 // The current overview state of the window. 0.f means the window is at the |
41 // topmost position. 1.f means the window is at the bottom-most position. | 39 // topmost position. 1.f means the window is at the bottom-most position. |
42 float progress; | 40 float progress; |
43 | 41 |
44 // The top-most and bottom-most vertical position of the window in overview | 42 // The top-most and bottom-most vertical position of the window in overview |
45 // mode. | 43 // mode. |
46 float max_y; | 44 float max_y; |
47 float min_y; | 45 float min_y; |
48 | 46 |
49 // |split| is set if this window is one of the two split windows in split-view | 47 // |split| is set if this window is one of the two split windows in split-view |
50 // mode. | 48 // mode. |
51 bool split; | 49 bool split; |
52 }; | 50 }; |
53 | 51 |
54 } // namespace | 52 } // namespace |
55 | 53 |
56 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*) | 54 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*); |
57 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, | 55 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, |
58 kWindowOverviewState, | 56 kWindowOverviewState, |
59 NULL) | 57 NULL); |
| 58 |
60 namespace athena { | 59 namespace athena { |
61 | 60 |
62 namespace { | 61 namespace { |
63 | 62 |
| 63 const float kOverviewDefaultScale = 0.75f; |
| 64 |
64 gfx::Transform GetTransformForSplitWindow(aura::Window* window, float scale) { | 65 gfx::Transform GetTransformForSplitWindow(aura::Window* window, float scale) { |
65 const float kScrollWindowPositionInOverview = 0.65f; | 66 const float kScrollWindowPositionInOverview = 0.65f; |
66 int x_translate = window->bounds().width() * (1 - scale) / 2; | 67 int x_translate = window->bounds().width() * (1 - scale) / 2; |
67 gfx::Transform transform; | 68 gfx::Transform transform; |
68 transform.Translate( | 69 transform.Translate( |
69 x_translate, window->bounds().height() * kScrollWindowPositionInOverview); | 70 x_translate, window->bounds().height() * kScrollWindowPositionInOverview); |
70 transform.Scale(scale, scale); | 71 transform.Scale(scale, scale); |
71 return transform; | 72 return transform; |
72 } | 73 } |
73 | 74 |
(...skipping 18 matching lines...) Expand all Loading... |
92 int window_x = window->bounds().x(); | 93 int window_x = window->bounds().x(); |
93 float x_translate = (container_width - (window_width * scale)) / 2 - window_x; | 94 float x_translate = (container_width - (window_width * scale)) / 2 - window_x; |
94 float y_translate = gfx::Tween::FloatValueBetween( | 95 float y_translate = gfx::Tween::FloatValueBetween( |
95 state->progress, state->min_y, state->max_y); | 96 state->progress, state->min_y, state->max_y); |
96 gfx::Transform transform; | 97 gfx::Transform transform; |
97 transform.Translate(x_translate, y_translate); | 98 transform.Translate(x_translate, y_translate); |
98 transform.Scale(scale, scale); | 99 transform.Scale(scale, scale); |
99 return transform; | 100 return transform; |
100 } | 101 } |
101 | 102 |
102 // Sets the progress-state for the window in the overview mode. | 103 // A utility class used to set the transform/opacity to the window and |
103 void SetWindowProgress(aura::Window* window, float progress) { | 104 // its transient children. |
104 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 105 class TransientGroupSetter { |
105 state->progress = progress; | 106 public: |
| 107 explicit TransientGroupSetter(aura::Window* window) : window_(window) { |
| 108 } |
| 109 ~TransientGroupSetter() {} |
106 | 110 |
107 gfx::Transform transform = GetTransformForState(window, state); | 111 // Aborts all animations including its transient children. |
108 window->SetTransform(transform); | 112 void AbortAllAnimations() { |
109 } | 113 window_->layer()->GetAnimator()->AbortAllAnimations(); |
| 114 for (auto* transient_child : wm::GetTransientChildren(window_)) |
| 115 transient_child->layer()->GetAnimator()->AbortAllAnimations(); |
| 116 } |
| 117 |
| 118 // Applys transform to the window and its transient children. |
| 119 // Transient children gets a tranfrorm with the offset relateive |
| 120 // it its transient parent. |
| 121 void SetTransform(const gfx::Transform& transform) { |
| 122 window_->SetTransform(transform); |
| 123 for (auto* transient_child : wm::GetTransientChildren(window_)) { |
| 124 gfx::Rect window_bounds = window_->bounds(); |
| 125 gfx::Rect child_bounds = transient_child->bounds(); |
| 126 gfx::Transform transient_window_transform(TranslateTransformOrigin( |
| 127 child_bounds.origin() - window_bounds.origin(), transform)); |
| 128 transient_child->SetTransform(transient_window_transform); |
| 129 } |
| 130 } |
| 131 |
| 132 // Sets the opacity to the window and its transient children. |
| 133 void SetOpacity(float opacity) { |
| 134 window_->layer()->SetOpacity(opacity); |
| 135 for (auto* transient_child : wm::GetTransientChildren(window_)) { |
| 136 transient_child->layer()->SetOpacity(opacity); |
| 137 } |
| 138 } |
| 139 |
| 140 // Apply the transform with the overview scroll |progress|. |
| 141 void SetWindowProgress(float progress) { |
| 142 WindowOverviewState* state = window_->GetProperty(kWindowOverviewState); |
| 143 state->progress = progress; |
| 144 |
| 145 SetTransform(GetTransformForState(window_, state)); |
| 146 } |
| 147 |
| 148 private: |
| 149 static gfx::Transform TranslateTransformOrigin( |
| 150 const gfx::Vector2d& new_origin, |
| 151 const gfx::Transform& transform) { |
| 152 gfx::Transform result; |
| 153 result.Translate(-new_origin.x(), -new_origin.y()); |
| 154 result.PreconcatTransform(transform); |
| 155 result.Translate(new_origin.x(), new_origin.y()); |
| 156 return result; |
| 157 } |
| 158 |
| 159 aura::Window* window_; |
| 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(TransientGroupSetter); |
| 162 }; |
| 163 |
| 164 // TransientGroupSetter with animation. |
| 165 class AnimateTransientGroupSetter : public TransientGroupSetter { |
| 166 public: |
| 167 explicit AnimateTransientGroupSetter(aura::Window* window) |
| 168 : TransientGroupSetter(window) { |
| 169 animation_settings_.push_back(CreateScopedLayerAnimationSettings(window)); |
| 170 for (auto* transient_child : wm::GetTransientChildren(window)) { |
| 171 animation_settings_.push_back( |
| 172 CreateScopedLayerAnimationSettings(transient_child)); |
| 173 } |
| 174 } |
| 175 ~AnimateTransientGroupSetter() {} |
| 176 |
| 177 ui::ScopedLayerAnimationSettings* GetMainWindowAnimationSettings() { |
| 178 CHECK(animation_settings_.size()); |
| 179 return animation_settings_[0]; |
| 180 } |
| 181 |
| 182 private: |
| 183 static ui::ScopedLayerAnimationSettings* CreateScopedLayerAnimationSettings( |
| 184 aura::Window* window) { |
| 185 const int kTransitionMs = 250; |
| 186 |
| 187 ui::ScopedLayerAnimationSettings* settings = |
| 188 new ui::ScopedLayerAnimationSettings(window->layer()->GetAnimator()); |
| 189 settings->SetPreemptionStrategy( |
| 190 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 191 settings->SetTransitionDuration( |
| 192 base::TimeDelta::FromMilliseconds(kTransitionMs)); |
| 193 return settings; |
| 194 } |
| 195 |
| 196 ScopedVector<ui::ScopedLayerAnimationSettings> animation_settings_; |
| 197 DISALLOW_COPY_AND_ASSIGN(AnimateTransientGroupSetter); |
| 198 }; |
110 | 199 |
111 void HideWindowIfNotVisible(aura::Window* window, | 200 void HideWindowIfNotVisible(aura::Window* window, |
112 SplitViewController* split_view_controller) { | 201 SplitViewController* split_view_controller) { |
113 bool should_hide = true; | 202 bool should_hide = true; |
114 if (split_view_controller->IsSplitViewModeActive()) { | 203 if (split_view_controller->IsSplitViewModeActive()) { |
115 should_hide = window != split_view_controller->left_window() && | 204 should_hide = window != split_view_controller->left_window() && |
116 window != split_view_controller->right_window(); | 205 window != split_view_controller->right_window(); |
117 } else { | 206 } else { |
118 should_hide = !wm::IsActiveWindow(window); | 207 aura::Window* active = aura::client::GetActivationClient( |
| 208 window->GetRootWindow())->GetActiveWindow(); |
| 209 should_hide = active != window && wm::GetTransientParent(active) != window; |
119 } | 210 } |
120 if (should_hide) | 211 if (should_hide) |
121 window->Hide(); | 212 window->Hide(); |
122 } | 213 } |
123 | 214 |
124 // Resets the overview-related state for |window|. | 215 // Resets the overview-related state for |window|. |
125 void RestoreWindowState(aura::Window* window, | 216 void RestoreWindowState(aura::Window* window, |
126 SplitViewController* split_view_controller) { | 217 SplitViewController* split_view_controller) { |
127 window->ClearProperty(kWindowOverviewState); | 218 window->ClearProperty(kWindowOverviewState); |
128 | 219 |
129 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 220 AnimateTransientGroupSetter setter(window); |
130 settings.SetPreemptionStrategy( | |
131 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
132 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | |
133 | 221 |
134 settings.AddObserver(new ui::ClosureAnimationObserver( | 222 setter.GetMainWindowAnimationSettings()->AddObserver( |
135 base::Bind(&HideWindowIfNotVisible, window, split_view_controller))); | 223 new ui::ClosureAnimationObserver( |
| 224 base::Bind(&HideWindowIfNotVisible, window, split_view_controller))); |
136 | 225 |
137 window->SetTransform(gfx::Transform()); | 226 setter.SetTransform(gfx::Transform()); |
138 | |
139 // Reset the window opacity in case the user is dragging a window. | 227 // Reset the window opacity in case the user is dragging a window. |
140 window->layer()->SetOpacity(1.0f); | 228 setter.SetOpacity(1.0f); |
141 | 229 |
142 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE); | 230 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE); |
143 } | 231 } |
144 | 232 |
145 gfx::RectF GetTransformedBounds(aura::Window* window) { | 233 gfx::RectF GetTransformedBounds(aura::Window* window) { |
146 gfx::Transform transform; | 234 gfx::Transform transform; |
147 gfx::RectF bounds = window->bounds(); | 235 gfx::RectF bounds = window->bounds(); |
148 transform.Translate(bounds.x(), bounds.y()); | 236 transform.Translate(bounds.x(), bounds.y()); |
149 transform.PreconcatTransform(window->layer()->transform()); | 237 transform.PreconcatTransform(window->layer()->transform()); |
150 transform.Translate(-bounds.x(), -bounds.y()); | 238 transform.Translate(-bounds.x(), -bounds.y()); |
151 transform.TransformRect(&bounds); | 239 transform.TransformRect(&bounds); |
152 return bounds; | 240 return bounds; |
153 } | 241 } |
154 | 242 |
155 void TransformSplitWindowScale(aura::Window* window, float scale) { | 243 void TransformSplitWindowScale(aura::Window* window, float scale) { |
156 gfx::Transform transform = window->layer()->GetTargetTransform(); | 244 gfx::Transform transform = window->layer()->GetTargetTransform(); |
157 if (transform.Scale2d() == gfx::Vector2dF(scale, scale)) | 245 if (transform.Scale2d() == gfx::Vector2dF(scale, scale)) |
158 return; | 246 return; |
159 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 247 AnimateTransientGroupSetter setter(window); |
160 window->SetTransform(GetTransformForSplitWindow(window, scale)); | 248 setter.SetTransform(GetTransformForSplitWindow(window, scale)); |
161 } | 249 } |
162 | 250 |
163 void AnimateWindowTo(aura::Window* animate_window, | 251 void AnimateWindowTo(aura::Window* animate_window, |
164 aura::Window* target_window) { | 252 aura::Window* target_window) { |
165 ui::ScopedLayerAnimationSettings settings( | 253 AnimateTransientGroupSetter setter(animate_window); |
166 animate_window->layer()->GetAnimator()); | 254 |
167 settings.SetPreemptionStrategy( | |
168 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
169 WindowOverviewState* target_state = | 255 WindowOverviewState* target_state = |
170 target_window->GetProperty(kWindowOverviewState); | 256 target_window->GetProperty(kWindowOverviewState); |
171 SetWindowProgress(animate_window, target_state->progress); | 257 setter.SetWindowProgress(target_state->progress); |
172 } | 258 } |
173 | 259 |
174 // Always returns the same target. | 260 // Always returns the same target. |
175 class StaticWindowTargeter : public aura::WindowTargeter { | 261 class StaticWindowTargeter : public aura::WindowTargeter { |
176 public: | 262 public: |
177 explicit StaticWindowTargeter(aura::Window* target) : target_(target) {} | 263 explicit StaticWindowTargeter(aura::Window* target) : target_(target) {} |
178 virtual ~StaticWindowTargeter() {} | 264 virtual ~StaticWindowTargeter() {} |
179 | 265 |
180 private: | 266 private: |
181 // aura::WindowTargeter: | 267 // aura::WindowTargeter: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 310 } |
225 | 311 |
226 virtual ~WindowOverviewModeImpl() { | 312 virtual ~WindowOverviewModeImpl() { |
227 window_list_provider_->RemoveObserver(this); | 313 window_list_provider_->RemoveObserver(this); |
228 container_->set_target_handler(container_->delegate()); | 314 container_->set_target_handler(container_->delegate()); |
229 RemoveAnimationObserver(); | 315 RemoveAnimationObserver(); |
230 const aura::Window::Windows& windows = | 316 const aura::Window::Windows& windows = |
231 window_list_provider_->GetWindowList(); | 317 window_list_provider_->GetWindowList(); |
232 if (windows.empty()) | 318 if (windows.empty()) |
233 return; | 319 return; |
234 std::for_each(windows.begin(), | 320 for (auto* window : windows) |
235 windows.end(), | 321 RestoreWindowState(window, split_view_controller_); |
236 std::bind2nd(std::ptr_fun(&RestoreWindowState), | |
237 split_view_controller_)); | |
238 } | 322 } |
239 | 323 |
240 private: | 324 private: |
241 // Computes the transforms for all windows in both the topmost and bottom-most | 325 // Computes the transforms for all windows in both the topmost and bottom-most |
242 // positions. The transforms are set in the |kWindowOverviewState| property of | 326 // positions. The transforms are set in the |kWindowOverviewState| property of |
243 // the windows. | 327 // the windows. |
244 void ComputeTerminalStatesForAllWindows() { | 328 void ComputeTerminalStatesForAllWindows() { |
245 size_t index = 0; | 329 size_t index = 0; |
246 | 330 |
247 const aura::Window::Windows& windows = | 331 const aura::Window::Windows& windows = |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (split_view_controller_->IsSplitViewModeActive() && | 391 if (split_view_controller_->IsSplitViewModeActive() && |
308 (window == split_view_controller_->left_window() || | 392 (window == split_view_controller_->left_window() || |
309 window == split_view_controller_->right_window())) { | 393 window == split_view_controller_->right_window())) { |
310 progress = 1; | 394 progress = 1; |
311 } else { | 395 } else { |
312 if (index < arraysize(kInitialProgress)) | 396 if (index < arraysize(kInitialProgress)) |
313 progress = kInitialProgress[index]; | 397 progress = kInitialProgress[index]; |
314 ++index; | 398 ++index; |
315 } | 399 } |
316 | 400 |
317 scoped_refptr<ui::LayerAnimator> animator = | 401 TransientGroupSetter setter(window); |
318 window->layer()->GetAnimator(); | |
319 | 402 |
320 // Unset any in-progress animation. | 403 // Unset any in-progress animation. |
321 animator->AbortAllAnimations(); | 404 setter.AbortAllAnimations(); |
| 405 |
| 406 // Showing transient parent will show the transient children if any. |
322 window->Show(); | 407 window->Show(); |
323 window->SetTransform(gfx::Transform()); | 408 |
| 409 setter.SetTransform(gfx::Transform()); |
324 // Setup the animation. | 410 // Setup the animation. |
325 { | 411 { |
326 ui::ScopedLayerAnimationSettings settings(animator); | 412 AnimateTransientGroupSetter setter(window); |
327 settings.SetPreemptionStrategy( | 413 setter.SetWindowProgress(progress); |
328 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
329 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | |
330 SetWindowProgress(window, progress); | |
331 } | 414 } |
332 } | 415 } |
333 } | 416 } |
334 | 417 |
335 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { | 418 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { |
336 CHECK_EQ(container_, event->target()); | 419 CHECK_EQ(container_, event->target()); |
337 // Find the old targeter to find the target of the event. | 420 // Find the old targeter to find the target of the event. |
338 ui::EventTarget* window = container_; | 421 ui::EventTarget* window = container_; |
339 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); | 422 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); |
340 while (!targeter && window->GetParentTarget()) { | 423 while (!targeter && window->GetParentTarget()) { |
341 window = window->GetParentTarget(); | 424 window = window->GetParentTarget(); |
342 targeter = window->GetEventTargeter(); | 425 targeter = window->GetEventTargeter(); |
343 } | 426 } |
344 if (!targeter) | 427 if (!targeter) |
345 return NULL; | 428 return NULL; |
346 aura::Window* target = static_cast<aura::Window*>( | 429 aura::Window* target = static_cast<aura::Window*>( |
347 targeter->FindTargetForLocatedEvent(container_, event)); | 430 targeter->FindTargetForLocatedEvent(container_, event)); |
348 while (target && target->parent() != container_) | 431 while (target && target->parent() != container_) |
349 target = target->parent(); | 432 target = target->parent(); |
350 return target; | 433 aura::Window* transient_parent = wm::GetTransientParent(target); |
| 434 return transient_parent ? transient_parent : target; |
351 } | 435 } |
352 | 436 |
353 // Scroll the window list by |delta_y| amount. |delta_y| is negative when | 437 // Scroll the window list by |delta_y| amount. |delta_y| is negative when |
354 // scrolling up; and positive when scrolling down. | 438 // scrolling up; and positive when scrolling down. |
355 void DoScroll(float delta_y) { | 439 void DoScroll(float delta_y) { |
356 const float kEpsilon = 1e-3f; | 440 const float kEpsilon = 1e-3f; |
357 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); | 441 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); |
358 const aura::Window::Windows& windows = | 442 const aura::Window::Windows& windows = |
359 window_list_provider_->GetWindowList(); | 443 window_list_provider_->GetWindowList(); |
360 if (delta_y < 0) { | 444 if (delta_y < 0) { |
361 // Scroll up. Start with the top-most (i.e. behind-most in terms of | 445 // Scroll up. Start with the top-most (i.e. behind-most in terms of |
362 // z-index) window, and try to scroll them up. | 446 // z-index) window, and try to scroll them up. |
363 for (aura::Window::Windows::const_iterator iter = windows.begin(); | 447 for (aura::Window::Windows::const_iterator iter = windows.begin(); |
364 delta_y_p > kEpsilon && iter != windows.end(); | 448 delta_y_p > kEpsilon && iter != windows.end(); |
365 ++iter) { | 449 ++iter) { |
366 aura::Window* window = (*iter); | 450 aura::Window* window = (*iter); |
367 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 451 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
368 if (state->progress > kEpsilon) { | 452 if (state->progress > kEpsilon) { |
369 // It is possible to scroll |window| up. Scroll it up, and update | 453 // It is possible to scroll |window| up. Scroll it up, and update |
370 // |delta_y_p| for the next window. | 454 // |delta_y_p| for the next window. |
371 float apply = delta_y_p * state->progress; | 455 float apply = delta_y_p * state->progress; |
372 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); | 456 TransientGroupSetter setter(window); |
| 457 setter.SetWindowProgress(std::max(0.f, state->progress - apply * 3)); |
373 delta_y_p -= apply; | 458 delta_y_p -= apply; |
374 } | 459 } |
375 } | 460 } |
376 } else { | 461 } else { |
377 // Scroll down. Start with the bottom-most (i.e. front-most in terms of | 462 // Scroll down. Start with the bottom-most (i.e. front-most in terms of |
378 // z-index) window, and try to scroll them down. | 463 // z-index) window, and try to scroll them down. |
379 aura::Window::Windows::const_reverse_iterator iter; | 464 aura::Window::Windows::const_reverse_iterator iter; |
380 for (iter = windows.rbegin(); | 465 for (iter = windows.rbegin(); |
381 delta_y_p > kEpsilon && iter != windows.rend(); | 466 delta_y_p > kEpsilon && iter != windows.rend(); |
382 ++iter) { | 467 ++iter) { |
383 aura::Window* window = (*iter); | 468 aura::Window* window = (*iter); |
384 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 469 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
385 if (1.f - state->progress > kEpsilon) { | 470 if (1.f - state->progress > kEpsilon) { |
386 // It is possible to scroll |window| down. Scroll it down, and update | 471 // It is possible to scroll |window| down. Scroll it down, and update |
387 // |delta_y_p| for the next window. | 472 // |delta_y_p| for the next window. |
388 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); | 473 TransientGroupSetter setter(window); |
| 474 setter.SetWindowProgress(std::min(1.f, state->progress + delta_y_p)); |
389 delta_y_p /= 2.f; | 475 delta_y_p /= 2.f; |
390 } | 476 } |
391 } | 477 } |
392 } | 478 } |
393 } | 479 } |
394 | 480 |
395 int GetScrollableHeight() const { | 481 int GetScrollableHeight() const { |
396 const float kScrollableFraction = 0.85f; | 482 const float kScrollableFraction = 0.85f; |
397 const float kScrollableFractionInSplit = 0.5f; | 483 const float kScrollableFractionInSplit = 0.5f; |
398 const float fraction = split_view_controller_->IsSplitViewModeActive() | 484 const float fraction = split_view_controller_->IsSplitViewModeActive() |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); | 525 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); |
440 CHECK(overview_toolbar_); | 526 CHECK(overview_toolbar_); |
441 gfx::Vector2dF dragged_distance = | 527 gfx::Vector2dF dragged_distance = |
442 dragged_start_location_ - event.location(); | 528 dragged_start_location_ - event.location(); |
443 WindowOverviewState* dragged_state = | 529 WindowOverviewState* dragged_state = |
444 dragged_window_->GetProperty(kWindowOverviewState); | 530 dragged_window_->GetProperty(kWindowOverviewState); |
445 CHECK(dragged_state); | 531 CHECK(dragged_state); |
446 gfx::Transform transform = | 532 gfx::Transform transform = |
447 GetTransformForState(dragged_window_, dragged_state); | 533 GetTransformForState(dragged_window_, dragged_state); |
448 transform.Translate(-dragged_distance.x(), 0); | 534 transform.Translate(-dragged_distance.x(), 0); |
449 dragged_window_->SetTransform(transform); | 535 TransientGroupSetter setter(dragged_window_); |
| 536 setter.SetTransform(transform); |
450 | 537 |
451 // Update the toolbar. | 538 // Update the toolbar. |
452 const int kMinDistanceForActionButtons = 20; | 539 const int kMinDistanceForActionButtons = 20; |
453 if (fabs(dragged_distance.x()) > kMinDistanceForActionButtons) | 540 if (fabs(dragged_distance.x()) > kMinDistanceForActionButtons) |
454 overview_toolbar_->ShowActionButtons(); | 541 overview_toolbar_->ShowActionButtons(); |
455 else | 542 else |
456 overview_toolbar_->HideActionButtons(); | 543 overview_toolbar_->HideActionButtons(); |
457 | 544 |
458 // See if the touch-point is above one of the action-buttons. | 545 // See if the touch-point is above one of the action-buttons. |
459 OverviewToolbar::ActionType new_action = | 546 OverviewToolbar::ActionType new_action = |
(...skipping 21 matching lines...) Expand all Loading... |
481 (new_action != previous_action) && | 568 (new_action != previous_action) && |
482 ((new_action == OverviewToolbar::ACTION_TYPE_SPLIT) || | 569 ((new_action == OverviewToolbar::ACTION_TYPE_SPLIT) || |
483 (previous_action == OverviewToolbar::ACTION_TYPE_SPLIT)); | 570 (previous_action == OverviewToolbar::ACTION_TYPE_SPLIT)); |
484 float ratio = std::min( | 571 float ratio = std::min( |
485 1.f, std::abs(dragged_distance.x()) / kMinDistanceForDismissal); | 572 1.f, std::abs(dragged_distance.x()) / kMinDistanceForDismissal); |
486 float opacity = | 573 float opacity = |
487 (new_action == OverviewToolbar::ACTION_TYPE_SPLIT || split_drop) | 574 (new_action == OverviewToolbar::ACTION_TYPE_SPLIT || split_drop) |
488 ? 1 | 575 ? 1 |
489 : gfx::Tween::FloatValueBetween(ratio, kMaxOpacity, kMinOpacity); | 576 : gfx::Tween::FloatValueBetween(ratio, kMaxOpacity, kMinOpacity); |
490 if (animate_opacity) { | 577 if (animate_opacity) { |
491 ui::ScopedLayerAnimationSettings settings( | 578 AnimateTransientGroupSetter setter(dragged_window_); |
492 dragged_window_->layer()->GetAnimator()); | 579 setter.SetOpacity(opacity); |
493 dragged_window_->layer()->SetOpacity(opacity); | |
494 } else { | 580 } else { |
495 dragged_window_->layer()->SetOpacity(opacity); | 581 TransientGroupSetter setter(dragged_window_); |
| 582 setter.SetOpacity(opacity); |
496 } | 583 } |
497 | 584 |
498 if (split_view_controller_->IsSplitViewModeActive()) { | 585 if (split_view_controller_->IsSplitViewModeActive()) { |
499 float scale = kOverviewDefaultScale; | 586 float scale = kOverviewDefaultScale; |
500 if (split_drop == split_view_controller_->left_window()) | 587 if (split_drop == split_view_controller_->left_window()) |
501 scale = kMaxScaleForSplitTarget; | 588 scale = kMaxScaleForSplitTarget; |
502 TransformSplitWindowScale(split_view_controller_->left_window(), scale); | 589 TransformSplitWindowScale(split_view_controller_->left_window(), scale); |
503 | 590 |
504 scale = kOverviewDefaultScale; | 591 scale = kOverviewDefaultScale; |
505 if (split_drop == split_view_controller_->right_window()) | 592 if (split_drop == split_view_controller_->right_window()) |
(...skipping 12 matching lines...) Expand all Loading... |
518 const bool swipe_towards_right = event.details().velocity_x() > 0; | 605 const bool swipe_towards_right = event.details().velocity_x() > 0; |
519 if (dragging_towards_right != swipe_towards_right) | 606 if (dragging_towards_right != swipe_towards_right) |
520 return false; | 607 return false; |
521 const float kMinVelocityForDismissal = 500.f; | 608 const float kMinVelocityForDismissal = 500.f; |
522 return std::abs(event.details().velocity_x()) > kMinVelocityForDismissal; | 609 return std::abs(event.details().velocity_x()) > kMinVelocityForDismissal; |
523 } | 610 } |
524 | 611 |
525 void CloseDragWindow(const ui::GestureEvent& gesture) { | 612 void CloseDragWindow(const ui::GestureEvent& gesture) { |
526 // Animate |dragged_window_| offscreen first, then destroy it. | 613 // Animate |dragged_window_| offscreen first, then destroy it. |
527 { | 614 { |
528 wm::ScopedHidingAnimationSettings settings(dragged_window_); | 615 AnimateTransientGroupSetter setter(dragged_window_); |
529 settings.layer_animation_settings()->SetPreemptionStrategy( | |
530 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
531 | 616 |
532 WindowOverviewState* dragged_state = | 617 WindowOverviewState* dragged_state = |
533 dragged_window_->GetProperty(kWindowOverviewState); | 618 dragged_window_->GetProperty(kWindowOverviewState); |
534 CHECK(dragged_state); | 619 CHECK(dragged_state); |
535 gfx::Transform transform = dragged_window_->layer()->transform(); | 620 gfx::Transform transform = dragged_window_->layer()->transform(); |
536 gfx::RectF transformed_bounds = dragged_window_->bounds(); | 621 gfx::RectF transformed_bounds = dragged_window_->bounds(); |
537 transform.TransformRect(&transformed_bounds); | 622 transform.TransformRect(&transformed_bounds); |
538 float transform_x = 0.f; | 623 float transform_x = 0.f; |
539 if (gesture.location().x() > dragged_start_location_.x()) | 624 if (gesture.location().x() > dragged_start_location_.x()) |
540 transform_x = container_->bounds().right() - transformed_bounds.x(); | 625 transform_x = container_->bounds().right() - transformed_bounds.x(); |
541 else | 626 else |
542 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); | 627 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); |
543 transform.Translate(transform_x / kOverviewDefaultScale, 0); | 628 transform.Translate(transform_x / kOverviewDefaultScale, 0); |
544 dragged_window_->SetTransform(transform); | 629 |
545 dragged_window_->layer()->SetOpacity(kMinOpacity); | 630 setter.SetOpacity(kMinOpacity); |
546 } | 631 } |
547 delete dragged_window_; | 632 delete dragged_window_; |
548 dragged_window_ = NULL; | 633 dragged_window_ = NULL; |
549 } | 634 } |
550 | 635 |
551 void RestoreDragWindow() { | 636 void RestoreDragWindow() { |
552 CHECK(dragged_window_); | 637 CHECK(dragged_window_); |
553 WindowOverviewState* dragged_state = | 638 WindowOverviewState* dragged_state = |
554 dragged_window_->GetProperty(kWindowOverviewState); | 639 dragged_window_->GetProperty(kWindowOverviewState); |
555 CHECK(dragged_state); | 640 CHECK(dragged_state); |
556 | 641 |
557 ui::ScopedLayerAnimationSettings settings( | 642 AnimateTransientGroupSetter setter(dragged_window_); |
558 dragged_window_->layer()->GetAnimator()); | 643 setter.SetTransform(GetTransformForState(dragged_window_, dragged_state)); |
559 settings.SetPreemptionStrategy( | 644 setter.SetOpacity(1.0f); |
560 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
561 dragged_window_->SetTransform( | |
562 GetTransformForState(dragged_window_, dragged_state)); | |
563 dragged_window_->layer()->SetOpacity(1.f); | |
564 dragged_window_ = NULL; | 645 dragged_window_ = NULL; |
565 } | 646 } |
566 | 647 |
567 void EndDragWindow(const ui::GestureEvent& gesture) { | 648 void EndDragWindow(const ui::GestureEvent& gesture) { |
568 CHECK(dragged_window_); | 649 CHECK(dragged_window_); |
569 CHECK(overview_toolbar_); | 650 CHECK(overview_toolbar_); |
570 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); | 651 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); |
571 overview_toolbar_.reset(); | 652 overview_toolbar_.reset(); |
572 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) { | 653 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) { |
573 delegate_->OnSelectSplitViewWindow(NULL, | 654 delegate_->OnSelectSplitViewWindow(NULL, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 aura::Window* container, | 857 aura::Window* container, |
777 WindowListProvider* window_list_provider, | 858 WindowListProvider* window_list_provider, |
778 SplitViewController* split_view_controller, | 859 SplitViewController* split_view_controller, |
779 WindowOverviewModeDelegate* delegate) { | 860 WindowOverviewModeDelegate* delegate) { |
780 return scoped_ptr<WindowOverviewMode>( | 861 return scoped_ptr<WindowOverviewMode>( |
781 new WindowOverviewModeImpl(container, window_list_provider, | 862 new WindowOverviewModeImpl(container, window_list_provider, |
782 split_view_controller, delegate)); | 863 split_view_controller, delegate)); |
783 } | 864 } |
784 | 865 |
785 } // namespace athena | 866 } // namespace athena |
OLD | NEW |