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 <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "athena/wm/overview_toolbar.h" | 11 #include "athena/wm/overview_toolbar.h" |
| 12 #include "athena/wm/public/window_list_provider.h" | 12 #include "athena/wm/public/window_list_provider.h" |
| 13 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "ui/aura/scoped_window_targeter.h" | 16 #include "ui/aura/scoped_window_targeter.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
| 19 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
| 20 #include "ui/aura/window_targeter.h" | 20 #include "ui/aura/window_targeter.h" |
| 21 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/compositor/closure_animation_observer.h" | 22 #include "ui/compositor/closure_animation_observer.h" |
| 23 #include "ui/compositor/compositor.h" | 23 #include "ui/compositor/compositor.h" |
| 24 #include "ui/compositor/compositor_animation_observer.h" | 24 #include "ui/compositor/compositor_animation_observer.h" |
| 25 #include "ui/compositor/layer_animation_observer.h" | |
| 25 #include "ui/compositor/scoped_layer_animation_settings.h" | 26 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 26 #include "ui/events/event_handler.h" | 27 #include "ui/events/event_handler.h" |
| 27 #include "ui/events/gestures/fling_curve.h" | 28 #include "ui/events/gestures/fling_curve.h" |
| 28 #include "ui/gfx/frame_time.h" | 29 #include "ui/gfx/frame_time.h" |
| 29 #include "ui/gfx/transform.h" | 30 #include "ui/gfx/transform.h" |
| 30 #include "ui/wm/core/shadow_types.h" | 31 #include "ui/wm/core/shadow_types.h" |
| 31 #include "ui/wm/core/window_util.h" | 32 #include "ui/wm/core/window_util.h" |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 61 state->bottom); | 62 state->bottom); |
| 62 } | 63 } |
| 63 | 64 |
| 64 // Sets the progress-state for the window in the overview mode. | 65 // Sets the progress-state for the window in the overview mode. |
| 65 void SetWindowProgress(aura::Window* window, float progress) { | 66 void SetWindowProgress(aura::Window* window, float progress) { |
| 66 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 67 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| 67 state->progress = progress; | 68 state->progress = progress; |
| 68 window->SetTransform(GetTransformForState(state)); | 69 window->SetTransform(GetTransformForState(state)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void HideWindowIfNotVisible(aura::Window* window, | 72 void HideWindowIfTransparent(aura::Window* window) { |
| 72 SplitViewController* split_view_controller) { | 73 if (window->layer()->opacity() == 0.0f) { |
| 73 bool should_hide = true; | 74 window->Hide(); |
| 74 if (split_view_controller->IsSplitViewModeActive()) { | 75 window->layer()->SetOpacity(1.0f); |
| 75 should_hide = window != split_view_controller->left_window() && | |
| 76 window != split_view_controller->right_window(); | |
| 77 } else { | |
| 78 should_hide = !wm::IsActiveWindow(window); | |
| 79 } | 76 } |
| 80 if (should_hide) | |
| 81 window->Hide(); | |
| 82 } | 77 } |
| 83 | 78 |
| 84 // Resets the overview-related state for |window|. | 79 // Resets the overview-related state for |window|. |
| 85 void RestoreWindowState(aura::Window* window, | 80 void RestoreWindowState(aura::Window* window) { |
| 86 SplitViewController* split_view_controller) { | |
| 87 window->ClearProperty(kWindowOverviewState); | 81 window->ClearProperty(kWindowOverviewState); |
| 82 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE); | |
| 88 | 83 |
| 89 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 84 { |
| 90 settings.SetPreemptionStrategy( | 85 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 91 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 86 settings.SetPreemptionStrategy( |
| 92 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | 87 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 88 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | |
| 89 window->SetTransform(gfx::Transform()); | |
| 90 } | |
| 93 | 91 |
| 94 settings.AddObserver(new ui::ClosureAnimationObserver( | 92 { |
| 95 base::Bind(&HideWindowIfNotVisible, window, split_view_controller))); | 93 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 94 settings.SetPreemptionStrategy( | |
| 95 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 96 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | |
| 97 settings.AddObserver(new ui::ClosureAnimationObserver( | |
| 98 base::Bind(&HideWindowIfTransparent, base::Unretained(window)))); | |
| 96 | 99 |
| 97 window->SetTransform(gfx::Transform()); | 100 // The window opacity may not be 1.0f if the user was dragging a window. |
| 101 window->layer()->SetOpacity(1.0f); | |
| 98 | 102 |
| 99 // Reset the window opacity in case the user is dragging a window. | 103 // Ideally we would animate the window's visibility. However, animating the |
| 100 window->layer()->SetOpacity(1.0f); | 104 // window's visibility causes the web contents to hide before the animation |
| 101 | 105 // completes. Enqueue a zero duration opacity animation and hide |window| |
| 102 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE); | 106 // unless the opacity animation is aborted. |
| 107 settings.SetPreemptionStrategy( | |
| 108 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
| 109 settings.SetTransitionDuration(base::TimeDelta()); | |
| 110 window->layer()->SetOpacity(0.0f); | |
| 111 } | |
| 103 } | 112 } |
| 104 | 113 |
| 105 gfx::RectF GetTransformedBounds(aura::Window* window) { | 114 gfx::RectF GetTransformedBounds(aura::Window* window) { |
| 106 gfx::Transform transform; | 115 gfx::Transform transform; |
| 107 gfx::RectF bounds = window->bounds(); | 116 gfx::RectF bounds = window->bounds(); |
| 108 transform.Translate(bounds.x(), bounds.y()); | 117 transform.Translate(bounds.x(), bounds.y()); |
| 109 transform.PreconcatTransform(window->layer()->transform()); | 118 transform.PreconcatTransform(window->layer()->transform()); |
| 110 transform.Translate(-bounds.x(), -bounds.y()); | 119 transform.Translate(-bounds.x(), -bounds.y()); |
| 111 transform.TransformRect(&bounds); | 120 transform.TransformRect(&bounds); |
| 112 return bounds; | 121 return bounds; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 ComputeTerminalStatesForAllWindows(); | 185 ComputeTerminalStatesForAllWindows(); |
| 177 SetInitialWindowStates(); | 186 SetInitialWindowStates(); |
| 178 } | 187 } |
| 179 | 188 |
| 180 virtual ~WindowOverviewModeImpl() { | 189 virtual ~WindowOverviewModeImpl() { |
| 181 container_->set_target_handler(container_->delegate()); | 190 container_->set_target_handler(container_->delegate()); |
| 182 RemoveAnimationObserver(); | 191 RemoveAnimationObserver(); |
| 183 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 192 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| 184 if (windows.empty()) | 193 if (windows.empty()) |
| 185 return; | 194 return; |
| 186 std::for_each(windows.begin(), windows.end(), | 195 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); |
| 187 std::bind2nd(std::ptr_fun(&RestoreWindowState), | |
| 188 split_view_controller_)); | |
| 189 } | 196 } |
| 190 | 197 |
| 191 private: | 198 private: |
| 192 // Computes the transforms for all windows in both the topmost and bottom-most | 199 // Computes the transforms for all windows in both the topmost and bottom-most |
| 193 // positions. The transforms are set in the |kWindowOverviewState| property of | 200 // positions. The transforms are set in the |kWindowOverviewState| property of |
| 194 // the windows. | 201 // the windows. |
| 195 void ComputeTerminalStatesForAllWindows() { | 202 void ComputeTerminalStatesForAllWindows() { |
| 196 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 203 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| 197 size_t index = 0; | 204 size_t index = 0; |
| 198 | 205 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 dragged_window_->layer()->SetOpacity(1.f); | 571 dragged_window_->layer()->SetOpacity(1.f); |
| 565 dragged_window_ = NULL; | 572 dragged_window_ = NULL; |
| 566 } | 573 } |
| 567 | 574 |
| 568 void EndDragWindow(const ui::GestureEvent& gesture) { | 575 void EndDragWindow(const ui::GestureEvent& gesture) { |
| 569 CHECK(dragged_window_); | 576 CHECK(dragged_window_); |
| 570 CHECK(overview_toolbar_); | 577 CHECK(overview_toolbar_); |
| 571 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); | 578 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); |
| 572 overview_toolbar_.reset(); | 579 overview_toolbar_.reset(); |
| 573 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) { | 580 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) { |
| 574 delegate_->OnSplitViewMode(NULL, dragged_window_); | 581 delegate_->OnSelectWindow(dragged_window_, |
| 582 WindowOverviewModeDelegate::SPLIT_RIGHT); | |
| 575 return; | 583 return; |
| 576 } | 584 } |
| 577 | 585 |
| 578 // If the window is dropped on one of the left/right windows in split-mode, | 586 // If the window is dropped on one of the left/right windows in split-mode, |
| 579 // then switch that window. | 587 // then switch that window. |
| 580 aura::Window* split_drop = GetSplitWindowDropTarget(gesture); | 588 aura::Window* split_drop = GetSplitWindowDropTarget(gesture); |
| 581 if (split_drop) { | 589 if (split_drop) { |
| 582 aura::Window* left = split_view_controller_->left_window(); | 590 WindowOverviewModeDelegate::SplitType split_type = |
| 583 aura::Window* right = split_view_controller_->right_window(); | 591 (split_view_controller_->left_window() == split_drop) |
| 584 if (left == split_drop) | 592 ? WindowOverviewModeDelegate::SPLIT_LEFT |
| 585 left = dragged_window_; | 593 : WindowOverviewModeDelegate::SPLIT_RIGHT; |
| 586 else | 594 delegate_->OnSelectWindow(dragged_window_, split_type); |
| 587 right = dragged_window_; | |
| 588 delegate_->OnSplitViewMode(left, right); | |
| 589 return; | 595 return; |
| 590 } | 596 } |
| 591 | 597 |
| 592 if (ShouldCloseDragWindow(gesture)) | 598 if (ShouldCloseDragWindow(gesture)) |
| 593 CloseDragWindow(gesture); | 599 CloseDragWindow(gesture); |
| 594 else | 600 else |
| 595 RestoreDragWindow(); | 601 RestoreDragWindow(); |
| 596 } | 602 } |
| 597 | 603 |
| 598 void SelectWindow(aura::Window* window) { | 604 void SelectWindow(aura::Window* window) { |
| 599 if (!split_view_controller_->IsSplitViewModeActive()) { | 605 WindowOverviewModeDelegate::SplitType split_type = |
| 600 delegate_->OnSelectWindow(window); | 606 WindowOverviewModeDelegate::SPLIT_NONE; |
| 601 } else { | 607 if (split_view_controller_->IsSplitViewModeActive()) { |
| 602 // If the selected window is one of the left/right windows, then keep the | 608 // Do not exit split view if the split view's left/right window was |
| 603 // current state. | 609 // selected. |
| 604 if (window == split_view_controller_->left_window() || | 610 if (window == split_view_controller_->left_window()) |
| 605 window == split_view_controller_->right_window()) { | 611 split_type = WindowOverviewModeDelegate::SPLIT_LEFT; |
| 606 delegate_->OnSplitViewMode(split_view_controller_->left_window(), | 612 else if (window == split_view_controller_->right_window()) |
| 607 split_view_controller_->right_window()); | 613 split_type = WindowOverviewModeDelegate::SPLIT_RIGHT; |
| 608 } else { | |
| 609 delegate_->OnSelectWindow(window); | |
| 610 } | |
| 611 } | 614 } |
| 615 delegate_->OnSelectWindow(window, split_type); | |
| 616 } | |
| 617 | |
| 618 // WindowOverviewMode: | |
| 619 virtual void SelectDefaultWindow() OVERRIDE { | |
| 620 // TODO(pkotwicz): Do not select a window which is about to be deleted. | |
| 621 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | |
| 622 SelectWindow(windows.empty() ? NULL : *windows.rbegin()); | |
|
pkotwicz
2014/09/07 01:57:24
This CL introduces a crash when a user exits overv
| |
| 612 } | 623 } |
| 613 | 624 |
| 614 // ui::EventHandler: | 625 // ui::EventHandler: |
| 615 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { | 626 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { |
| 616 if (mouse->type() == ui::ET_MOUSE_PRESSED) { | 627 if (mouse->type() == ui::ET_MOUSE_PRESSED) { |
| 617 aura::Window* select = SelectWindowAt(mouse); | 628 aura::Window* select = SelectWindowAt(mouse); |
| 618 if (select) { | 629 if (select) { |
| 619 mouse->SetHandled(); | 630 mouse->SetHandled(); |
| 620 SelectWindow(select); | 631 SelectWindow(select); |
| 621 } | 632 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 aura::Window* container, | 745 aura::Window* container, |
| 735 const WindowListProvider* window_list_provider, | 746 const WindowListProvider* window_list_provider, |
| 736 SplitViewController* split_view_controller, | 747 SplitViewController* split_view_controller, |
| 737 WindowOverviewModeDelegate* delegate) { | 748 WindowOverviewModeDelegate* delegate) { |
| 738 return scoped_ptr<WindowOverviewMode>( | 749 return scoped_ptr<WindowOverviewMode>( |
| 739 new WindowOverviewModeImpl(container, window_list_provider, | 750 new WindowOverviewModeImpl(container, window_list_provider, |
| 740 split_view_controller, delegate)); | 751 split_view_controller, delegate)); |
| 741 } | 752 } |
| 742 | 753 |
| 743 } // namespace athena | 754 } // namespace athena |
| OLD | NEW |