Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: athena/wm/window_overview_mode.cc

Issue 525443002: athena: Hide the windows when exiting from overview mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/wm/window_manager_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 10 matching lines...) Expand all
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/scoped_layer_animation_settings.h" 25 #include "ui/compositor/scoped_layer_animation_settings.h"
26 #include "ui/events/event_handler.h" 26 #include "ui/events/event_handler.h"
27 #include "ui/events/gestures/fling_curve.h" 27 #include "ui/events/gestures/fling_curve.h"
28 #include "ui/gfx/frame_time.h" 28 #include "ui/gfx/frame_time.h"
29 #include "ui/gfx/transform.h" 29 #include "ui/gfx/transform.h"
30 #include "ui/wm/core/shadow_types.h" 30 #include "ui/wm/core/shadow_types.h"
31 #include "ui/wm/core/window_util.h"
31 32
32 namespace { 33 namespace {
33 34
34 struct WindowOverviewState { 35 struct WindowOverviewState {
35 // The transform for when the window is at the topmost position. 36 // The transform for when the window is at the topmost position.
36 gfx::Transform top; 37 gfx::Transform top;
37 38
38 // The transform for when the window is at the bottom-most position. 39 // The transform for when the window is at the bottom-most position.
39 gfx::Transform bottom; 40 gfx::Transform bottom;
40 41
(...skipping 19 matching lines...) Expand all
60 state->bottom); 61 state->bottom);
61 } 62 }
62 63
63 // Sets the progress-state for the window in the overview mode. 64 // Sets the progress-state for the window in the overview mode.
64 void SetWindowProgress(aura::Window* window, float progress) { 65 void SetWindowProgress(aura::Window* window, float progress) {
65 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 66 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
66 state->progress = progress; 67 state->progress = progress;
67 window->SetTransform(GetTransformForState(state)); 68 window->SetTransform(GetTransformForState(state));
68 } 69 }
69 70
71 void HideWindowIfNotVisible(aura::Window* window,
72 SplitViewController* split_view_controller) {
73 bool should_hide = true;
74 if (split_view_controller->IsSplitViewModeActive()) {
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 }
80 if (should_hide)
81 window->Hide();
82 }
83
70 // Resets the overview-related state for |window|. 84 // Resets the overview-related state for |window|.
71 void RestoreWindowState(aura::Window* window) { 85 void RestoreWindowState(aura::Window* window,
86 SplitViewController* split_view_controller) {
72 window->ClearProperty(kWindowOverviewState); 87 window->ClearProperty(kWindowOverviewState);
73 88
74 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 89 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
75 settings.SetPreemptionStrategy( 90 settings.SetPreemptionStrategy(
76 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 91 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
77 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); 92 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250));
93
94 settings.AddObserver(new ui::ClosureAnimationObserver(
95 base::Bind(&HideWindowIfNotVisible, window, split_view_controller)));
96
78 window->SetTransform(gfx::Transform()); 97 window->SetTransform(gfx::Transform());
79 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE); 98 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE);
80 } 99 }
81 100
82 // Always returns the same target. 101 // Always returns the same target.
83 class StaticWindowTargeter : public aura::WindowTargeter { 102 class StaticWindowTargeter : public aura::WindowTargeter {
84 public: 103 public:
85 explicit StaticWindowTargeter(aura::Window* target) : target_(target) {} 104 explicit StaticWindowTargeter(aura::Window* target) : target_(target) {}
86 virtual ~StaticWindowTargeter() {} 105 virtual ~StaticWindowTargeter() {}
87 106
(...skipping 17 matching lines...) Expand all
105 class WindowOverviewModeImpl : public WindowOverviewMode, 124 class WindowOverviewModeImpl : public WindowOverviewMode,
106 public ui::EventHandler, 125 public ui::EventHandler,
107 public ui::CompositorAnimationObserver { 126 public ui::CompositorAnimationObserver {
108 public: 127 public:
109 WindowOverviewModeImpl(aura::Window* container, 128 WindowOverviewModeImpl(aura::Window* container,
110 const WindowListProvider* window_list_provider, 129 const WindowListProvider* window_list_provider,
111 SplitViewController* split_view_controller, 130 SplitViewController* split_view_controller,
112 WindowOverviewModeDelegate* delegate) 131 WindowOverviewModeDelegate* delegate)
113 : container_(container), 132 : container_(container),
114 window_list_provider_(window_list_provider), 133 window_list_provider_(window_list_provider),
134 split_view_controller_(split_view_controller),
115 delegate_(delegate), 135 delegate_(delegate),
116 scoped_targeter_(new aura::ScopedWindowTargeter( 136 scoped_targeter_(new aura::ScopedWindowTargeter(
117 container, 137 container,
118 scoped_ptr<ui::EventTargeter>( 138 scoped_ptr<ui::EventTargeter>(
119 new StaticWindowTargeter(container)))), 139 new StaticWindowTargeter(container)))),
120 dragged_window_(NULL), 140 dragged_window_(NULL) {
121 split_({false, NULL, NULL}) {
122 CHECK(delegate_); 141 CHECK(delegate_);
123 container_->set_target_handler(this); 142 container_->set_target_handler(this);
124 143
125 split_.enabled = split_view_controller->IsSplitViewModeActive();
126 if (split_.enabled) {
127 split_.left = split_view_controller->left_window();
128 split_.right = split_view_controller->right_window();
129 }
130
131 // Prepare the desired transforms for all the windows, and set the initial 144 // Prepare the desired transforms for all the windows, and set the initial
132 // state on the windows. 145 // state on the windows.
133 ComputeTerminalStatesForAllWindows(); 146 ComputeTerminalStatesForAllWindows();
134 SetInitialWindowStates(); 147 SetInitialWindowStates();
135 } 148 }
136 149
137 virtual ~WindowOverviewModeImpl() { 150 virtual ~WindowOverviewModeImpl() {
138 container_->set_target_handler(container_->delegate()); 151 container_->set_target_handler(container_->delegate());
139 RemoveAnimationObserver(); 152 RemoveAnimationObserver();
140 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 153 aura::Window::Windows windows = window_list_provider_->GetWindowList();
141 if (windows.empty()) 154 if (windows.empty())
142 return; 155 return;
143 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); 156 std::for_each(windows.begin(), windows.end(),
157 std::bind2nd(std::ptr_fun(&RestoreWindowState),
158 split_view_controller_));
144 } 159 }
145 160
146 private: 161 private:
147 // Computes the transforms for all windows in both the topmost and bottom-most 162 // Computes the transforms for all windows in both the topmost and bottom-most
148 // positions. The transforms are set in the |kWindowOverviewState| property of 163 // positions. The transforms are set in the |kWindowOverviewState| property of
149 // the windows. 164 // the windows.
150 void ComputeTerminalStatesForAllWindows() { 165 void ComputeTerminalStatesForAllWindows() {
151 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 166 aura::Window::Windows windows = window_list_provider_->GetWindowList();
152 size_t index = 0; 167 size_t index = 0;
153 168
154 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); 169 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
155 iter != windows.rend(); 170 iter != windows.rend();
156 ++iter, ++index) { 171 ++iter, ++index) {
157 aura::Window* window = (*iter); 172 aura::Window* window = (*iter);
158 wm::SetShadowType(window, wm::SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE); 173 wm::SetShadowType(window, wm::SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE);
159 174
160 WindowOverviewState* state = new WindowOverviewState; 175 WindowOverviewState* state = new WindowOverviewState;
161 window->SetProperty(kWindowOverviewState, state); 176 window->SetProperty(kWindowOverviewState, state);
162 if (split_.enabled && (window == split_.left || window == split_.right)) { 177 if (split_view_controller_->IsSplitViewModeActive() &&
178 (window == split_view_controller_->left_window() ||
179 window == split_view_controller_->right_window())) {
163 // Do not let the left/right windows be scrolled. 180 // Do not let the left/right windows be scrolled.
164 int x_translate = window->bounds().width() * (1 - kMaxScale) / 2; 181 int x_translate = window->bounds().width() * (1 - kMaxScale) / 2;
165 state->top.Translate(x_translate, window->bounds().height() * 0.65); 182 state->top.Translate(x_translate, window->bounds().height() * 0.65);
166 state->top.Scale(kMaxScale, kMaxScale); 183 state->top.Scale(kMaxScale, kMaxScale);
167 state->bottom = state->top; 184 state->bottom = state->top;
168 --index; 185 --index;
169 continue; 186 continue;
170 } 187 }
171 UpdateTerminalStateForWindowAtIndex(window, index, windows.size()); 188 UpdateTerminalStateForWindowAtIndex(window, index, windows.size());
172 } 189 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void SetInitialWindowStates() { 222 void SetInitialWindowStates() {
206 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 223 aura::Window::Windows windows = window_list_provider_->GetWindowList();
207 // The initial overview state of the topmost three windows. 224 // The initial overview state of the topmost three windows.
208 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; 225 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f };
209 size_t index = 0; 226 size_t index = 0;
210 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); 227 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
211 iter != windows.rend(); 228 iter != windows.rend();
212 ++iter) { 229 ++iter) {
213 float progress = 0.f; 230 float progress = 0.f;
214 aura::Window* window = *iter; 231 aura::Window* window = *iter;
215 if (split_.enabled && (window == split_.left || window == split_.right)) { 232 if (split_view_controller_->IsSplitViewModeActive() &&
233 (window == split_view_controller_->left_window() ||
234 window == split_view_controller_->right_window())) {
216 progress = 1; 235 progress = 1;
217 } else { 236 } else {
218 if (index < arraysize(kInitialProgress)) 237 if (index < arraysize(kInitialProgress))
219 progress = kInitialProgress[index]; 238 progress = kInitialProgress[index];
220 ++index; 239 ++index;
221 } 240 }
222 241
223 scoped_refptr<ui::LayerAnimator> animator = 242 scoped_refptr<ui::LayerAnimator> animator =
224 window->layer()->GetAnimator(); 243 window->layer()->GetAnimator();
225 244
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); 312 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p));
294 delta_y_p /= 2.f; 313 delta_y_p /= 2.f;
295 } 314 }
296 } 315 }
297 } 316 }
298 } 317 }
299 318
300 int GetScrollableHeight() const { 319 int GetScrollableHeight() const {
301 const float kScrollableFraction = 0.65f; 320 const float kScrollableFraction = 0.65f;
302 const float kScrollableFractionInSplit = 0.5f; 321 const float kScrollableFractionInSplit = 0.5f;
303 const float fraction = 322 const float fraction = split_view_controller_->IsSplitViewModeActive()
304 split_.enabled ? kScrollableFractionInSplit : kScrollableFraction; 323 ? kScrollableFractionInSplit
324 : kScrollableFraction;
305 return container_->bounds().height() * fraction; 325 return container_->bounds().height() * fraction;
306 } 326 }
307 327
308 void CreateFlingerFor(const ui::GestureEvent& event) { 328 void CreateFlingerFor(const ui::GestureEvent& event) {
309 gfx::Vector2dF velocity(event.details().velocity_x(), 329 gfx::Vector2dF velocity(event.details().velocity_x(),
310 event.details().velocity_y()); 330 event.details().velocity_y());
311 fling_.reset(new ui::FlingCurve(velocity, gfx::FrameTime::Now())); 331 fling_.reset(new ui::FlingCurve(velocity, gfx::FrameTime::Now()));
312 } 332 }
313 333
314 void AddAnimationObserver() { 334 void AddAnimationObserver() {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 overview_toolbar_.reset(); 484 overview_toolbar_.reset();
465 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) 485 if (action == OverviewToolbar::ACTION_TYPE_SPLIT)
466 delegate_->OnSplitViewMode(NULL, dragged_window_); 486 delegate_->OnSplitViewMode(NULL, dragged_window_);
467 else if (ShouldCloseDragWindow(gesture)) 487 else if (ShouldCloseDragWindow(gesture))
468 CloseDragWindow(gesture); 488 CloseDragWindow(gesture);
469 else 489 else
470 RestoreDragWindow(); 490 RestoreDragWindow();
471 } 491 }
472 492
473 void SelectWindow(aura::Window* window) { 493 void SelectWindow(aura::Window* window) {
474 if (!split_.enabled) { 494 if (!split_view_controller_->IsSplitViewModeActive()) {
475 delegate_->OnSelectWindow(window); 495 delegate_->OnSelectWindow(window);
476 } else { 496 } else {
477 // If the selected window is one of the left/right windows, then keep the 497 // If the selected window is one of the left/right windows, then keep the
478 // current state. 498 // current state.
479 if (window == split_.left || window == split_.right) { 499 if (window == split_view_controller_->left_window() ||
480 delegate_->OnSplitViewMode(split_.left, split_.right); 500 window == split_view_controller_->right_window()) {
501 delegate_->OnSplitViewMode(split_view_controller_->left_window(),
502 split_view_controller_->right_window());
481 } else { 503 } else {
482 delegate_->OnSelectWindow(window); 504 delegate_->OnSelectWindow(window);
483 } 505 }
484 } 506 }
485 } 507 }
486 508
487 // ui::EventHandler: 509 // ui::EventHandler:
488 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { 510 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE {
489 if (mouse->type() == ui::ET_MOUSE_PRESSED) { 511 if (mouse->type() == ui::ET_MOUSE_PRESSED) {
490 aura::Window* select = SelectWindowAt(mouse); 512 aura::Window* select = SelectWindowAt(mouse);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 583
562 const int kMinDistanceForDismissal = 300; 584 const int kMinDistanceForDismissal = 300;
563 const float kMinScale = 0.6f; 585 const float kMinScale = 0.6f;
564 const float kMaxScale = 0.75f; 586 const float kMaxScale = 0.75f;
565 const float kMaxOpacity = 1.0f; 587 const float kMaxOpacity = 1.0f;
566 const float kMinOpacity = 0.2f; 588 const float kMinOpacity = 0.2f;
567 589
568 aura::Window* container_; 590 aura::Window* container_;
569 // Provider of the stack of windows to show in the overview mode. Not owned. 591 // Provider of the stack of windows to show in the overview mode. Not owned.
570 const WindowListProvider* window_list_provider_; 592 const WindowListProvider* window_list_provider_;
593 SplitViewController* split_view_controller_;
594
571 WindowOverviewModeDelegate* delegate_; 595 WindowOverviewModeDelegate* delegate_;
572 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 596 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
573 scoped_ptr<ui::FlingCurve> fling_; 597 scoped_ptr<ui::FlingCurve> fling_;
574 598
575 aura::Window* dragged_window_; 599 aura::Window* dragged_window_;
576 gfx::Point dragged_start_location_; 600 gfx::Point dragged_start_location_;
577 scoped_ptr<OverviewToolbar> overview_toolbar_; 601 scoped_ptr<OverviewToolbar> overview_toolbar_;
578 602
579 struct {
580 bool enabled;
581 aura::Window* left;
582 aura::Window* right;
583 } split_;
584
585 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 603 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
586 }; 604 };
587 605
588 } // namespace 606 } // namespace
589 607
590 // static 608 // static
591 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 609 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
592 aura::Window* container, 610 aura::Window* container,
593 const WindowListProvider* window_list_provider, 611 const WindowListProvider* window_list_provider,
594 SplitViewController* split_view_controller, 612 SplitViewController* split_view_controller,
595 WindowOverviewModeDelegate* delegate) { 613 WindowOverviewModeDelegate* delegate) {
596 return scoped_ptr<WindowOverviewMode>( 614 return scoped_ptr<WindowOverviewMode>(
597 new WindowOverviewModeImpl(container, window_list_provider, 615 new WindowOverviewModeImpl(container, window_list_provider,
598 split_view_controller, delegate)); 616 split_view_controller, delegate));
599 } 617 }
600 618
601 } // namespace athena 619 } // namespace athena
OLDNEW
« no previous file with comments | « athena/wm/window_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698