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