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 "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "ui/aura/scoped_window_targeter.h" | 16 #include "ui/aura/scoped_window_targeter.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
18 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
19 #include "ui/aura/window_targeter.h" | 20 #include "ui/aura/window_targeter.h" |
20 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
21 #include "ui/compositor/closure_animation_observer.h" | 22 #include "ui/compositor/closure_animation_observer.h" |
22 #include "ui/compositor/compositor.h" | 23 #include "ui/compositor/compositor.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 aura::Window* target_; | 101 aura::Window* target_; |
101 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); | 102 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); |
102 }; | 103 }; |
103 | 104 |
104 class WindowOverviewModeImpl : public WindowOverviewMode, | 105 class WindowOverviewModeImpl : public WindowOverviewMode, |
105 public ui::EventHandler, | 106 public ui::EventHandler, |
106 public ui::CompositorAnimationObserver { | 107 public ui::CompositorAnimationObserver { |
107 public: | 108 public: |
108 WindowOverviewModeImpl(aura::Window* container, | 109 WindowOverviewModeImpl(aura::Window* container, |
109 const WindowListProvider* window_list_provider, | 110 const WindowListProvider* window_list_provider, |
111 SplitViewController* split_view_controller, | |
110 WindowOverviewModeDelegate* delegate) | 112 WindowOverviewModeDelegate* delegate) |
111 : container_(container), | 113 : container_(container), |
112 window_list_provider_(window_list_provider), | 114 window_list_provider_(window_list_provider), |
115 split_view_controller_(split_view_controller), | |
113 delegate_(delegate), | 116 delegate_(delegate), |
114 scoped_targeter_(new aura::ScopedWindowTargeter( | 117 scoped_targeter_(new aura::ScopedWindowTargeter( |
115 container, | 118 container, |
116 scoped_ptr<ui::EventTargeter>( | 119 scoped_ptr<ui::EventTargeter>( |
117 new StaticWindowTargeter(container)))), | 120 new StaticWindowTargeter(container)))), |
118 dragged_window_(NULL) { | 121 dragged_window_(NULL), |
122 split_({false, NULL, NULL}) { | |
123 CHECK(delegate_); | |
119 container_->set_target_handler(this); | 124 container_->set_target_handler(this); |
120 | 125 |
126 split_.enabled = split_view_controller_->IsSplitViewModeActive(); | |
127 if (split_.enabled) { | |
128 split_.left = split_view_controller_->left_window(); | |
129 split_.right = split_view_controller_->right_window(); | |
oshima
2014/08/28 19:59:46
do you still need to copy these state?
If you cop
sadrul
2014/08/28 20:28:29
Done (removed split_view_controller_).
| |
130 } | |
131 | |
121 // Prepare the desired transforms for all the windows, and set the initial | 132 // Prepare the desired transforms for all the windows, and set the initial |
122 // state on the windows. | 133 // state on the windows. |
123 ComputeTerminalStatesForAllWindows(); | 134 ComputeTerminalStatesForAllWindows(); |
124 SetInitialWindowStates(); | 135 SetInitialWindowStates(); |
125 } | 136 } |
126 | 137 |
127 virtual ~WindowOverviewModeImpl() { | 138 virtual ~WindowOverviewModeImpl() { |
128 container_->set_target_handler(container_->delegate()); | 139 container_->set_target_handler(container_->delegate()); |
129 RemoveAnimationObserver(); | 140 RemoveAnimationObserver(); |
130 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 141 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
(...skipping 11 matching lines...) Expand all Loading... | |
142 size_t index = 0; | 153 size_t index = 0; |
143 | 154 |
144 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); | 155 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
145 iter != windows.rend(); | 156 iter != windows.rend(); |
146 ++iter, ++index) { | 157 ++iter, ++index) { |
147 aura::Window* window = (*iter); | 158 aura::Window* window = (*iter); |
148 wm::SetShadowType(window, wm::SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE); | 159 wm::SetShadowType(window, wm::SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE); |
149 | 160 |
150 WindowOverviewState* state = new WindowOverviewState; | 161 WindowOverviewState* state = new WindowOverviewState; |
151 window->SetProperty(kWindowOverviewState, state); | 162 window->SetProperty(kWindowOverviewState, state); |
163 if (split_.enabled && (window == split_.left || window == split_.right)) { | |
164 // Do not let the left/right windows be scrolled. | |
165 int x_translate = window->bounds().width() * (1 - kMaxScale) / 2; | |
166 state->top.Translate(x_translate, window->bounds().height() * 0.65); | |
167 state->top.Scale(kMaxScale, kMaxScale); | |
168 state->bottom = state->top; | |
169 --index; | |
170 continue; | |
171 } | |
152 UpdateTerminalStateForWindowAtIndex(window, index, windows.size()); | 172 UpdateTerminalStateForWindowAtIndex(window, index, windows.size()); |
153 } | 173 } |
154 } | 174 } |
155 | 175 |
156 void UpdateTerminalStateForWindowAtIndex(aura::Window* window, | 176 void UpdateTerminalStateForWindowAtIndex(aura::Window* window, |
157 size_t index, | 177 size_t index, |
158 size_t window_count) { | 178 size_t window_count) { |
159 const int kGapBetweenWindowsBottom = 10; | 179 const int kGapBetweenWindowsBottom = 10; |
160 const int kGapBetweenWindowsTop = 5; | 180 const int kGapBetweenWindowsTop = 5; |
161 | 181 |
(...skipping 16 matching lines...) Expand all Loading... | |
178 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 198 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
179 CHECK(state); | 199 CHECK(state); |
180 state->top = top_transform; | 200 state->top = top_transform; |
181 state->bottom = bottom_transform; | 201 state->bottom = bottom_transform; |
182 state->progress = 0.f; | 202 state->progress = 0.f; |
183 } | 203 } |
184 | 204 |
185 // Sets the initial position for the windows for the overview mode. | 205 // Sets the initial position for the windows for the overview mode. |
186 void SetInitialWindowStates() { | 206 void SetInitialWindowStates() { |
187 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 207 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
188 size_t window_count = windows.size(); | |
189 // The initial overview state of the topmost three windows. | 208 // The initial overview state of the topmost three windows. |
190 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; | 209 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; |
191 for (size_t i = 0; i < window_count; ++i) { | 210 size_t index = 0; |
211 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); | |
212 iter != windows.rend(); | |
213 ++iter) { | |
192 float progress = 0.f; | 214 float progress = 0.f; |
193 aura::Window* window = windows[window_count - 1 - i]; | 215 aura::Window* window = *iter; |
194 if (i < arraysize(kInitialProgress)) | 216 if (split_.enabled && (window == split_.left || window == split_.right)) { |
195 progress = kInitialProgress[i]; | 217 progress = 1; |
218 } else { | |
219 if (index < arraysize(kInitialProgress)) | |
220 progress = kInitialProgress[index]; | |
221 ++index; | |
222 } | |
196 | 223 |
197 scoped_refptr<ui::LayerAnimator> animator = | 224 scoped_refptr<ui::LayerAnimator> animator = |
198 window->layer()->GetAnimator(); | 225 window->layer()->GetAnimator(); |
199 | 226 |
200 // Unset any in-progress animation. | 227 // Unset any in-progress animation. |
201 animator->AbortAllAnimations(); | 228 animator->AbortAllAnimations(); |
202 window->Show(); | 229 window->Show(); |
203 window->SetTransform(gfx::Transform()); | 230 window->SetTransform(gfx::Transform()); |
204 // Setup the animation. | 231 // Setup the animation. |
205 { | 232 { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 // |delta_y_p| for the next window. | 293 // |delta_y_p| for the next window. |
267 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); | 294 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); |
268 delta_y_p /= 2.f; | 295 delta_y_p /= 2.f; |
269 } | 296 } |
270 } | 297 } |
271 } | 298 } |
272 } | 299 } |
273 | 300 |
274 int GetScrollableHeight() const { | 301 int GetScrollableHeight() const { |
275 const float kScrollableFraction = 0.65f; | 302 const float kScrollableFraction = 0.65f; |
276 return container_->bounds().height() * kScrollableFraction; | 303 const float kScrollableFractionInSplit = 0.5f; |
304 const float fraction = | |
305 split_.enabled ? kScrollableFractionInSplit : kScrollableFraction; | |
306 return container_->bounds().height() * fraction; | |
277 } | 307 } |
278 | 308 |
279 void CreateFlingerFor(const ui::GestureEvent& event) { | 309 void CreateFlingerFor(const ui::GestureEvent& event) { |
280 gfx::Vector2dF velocity(event.details().velocity_x(), | 310 gfx::Vector2dF velocity(event.details().velocity_x(), |
281 event.details().velocity_y()); | 311 event.details().velocity_y()); |
282 fling_.reset(new ui::FlingCurve(velocity, gfx::FrameTime::Now())); | 312 fling_.reset(new ui::FlingCurve(velocity, gfx::FrameTime::Now())); |
283 } | 313 } |
284 | 314 |
285 void AddAnimationObserver() { | 315 void AddAnimationObserver() { |
286 ui::Compositor* compositor = container_->GetHost()->compositor(); | 316 ui::Compositor* compositor = container_->GetHost()->compositor(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); | 464 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); |
435 overview_toolbar_.reset(); | 465 overview_toolbar_.reset(); |
436 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) | 466 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) |
437 delegate_->OnSplitViewMode(NULL, dragged_window_); | 467 delegate_->OnSplitViewMode(NULL, dragged_window_); |
438 else if (ShouldCloseDragWindow(gesture)) | 468 else if (ShouldCloseDragWindow(gesture)) |
439 CloseDragWindow(gesture); | 469 CloseDragWindow(gesture); |
440 else | 470 else |
441 RestoreDragWindow(); | 471 RestoreDragWindow(); |
442 } | 472 } |
443 | 473 |
474 void SelectWindow(aura::Window* window) { | |
475 if (!split_.enabled) { | |
476 delegate_->OnSelectWindow(window); | |
477 } else { | |
478 // If the selected window is one of the left/right windows, then keep the | |
479 // current state. | |
480 if (window == split_.left || window == split_.right) { | |
481 delegate_->OnSplitViewMode(split_.left, split_.right); | |
482 } else { | |
483 delegate_->OnSelectWindow(window); | |
484 } | |
485 } | |
486 } | |
487 | |
444 // ui::EventHandler: | 488 // ui::EventHandler: |
445 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { | 489 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { |
446 if (mouse->type() == ui::ET_MOUSE_PRESSED) { | 490 if (mouse->type() == ui::ET_MOUSE_PRESSED) { |
447 aura::Window* select = SelectWindowAt(mouse); | 491 aura::Window* select = SelectWindowAt(mouse); |
448 if (select) { | 492 if (select) { |
449 mouse->SetHandled(); | 493 mouse->SetHandled(); |
450 delegate_->OnSelectWindow(select); | 494 SelectWindow(select); |
451 } | 495 } |
452 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { | 496 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { |
453 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); | 497 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); |
454 } | 498 } |
455 } | 499 } |
456 | 500 |
457 virtual void OnScrollEvent(ui::ScrollEvent* scroll) OVERRIDE { | 501 virtual void OnScrollEvent(ui::ScrollEvent* scroll) OVERRIDE { |
458 if (scroll->type() == ui::ET_SCROLL) | 502 if (scroll->type() == ui::ET_SCROLL) |
459 DoScroll(scroll->y_offset()); | 503 DoScroll(scroll->y_offset()); |
460 } | 504 } |
461 | 505 |
462 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { | 506 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { |
463 if (gesture->type() == ui::ET_GESTURE_TAP) { | 507 if (gesture->type() == ui::ET_GESTURE_TAP) { |
464 aura::Window* select = SelectWindowAt(gesture); | 508 aura::Window* select = SelectWindowAt(gesture); |
465 if (select) { | 509 if (select) { |
466 gesture->SetHandled(); | 510 gesture->SetHandled(); |
467 delegate_->OnSelectWindow(select); | 511 SelectWindow(select); |
468 } | 512 } |
469 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 513 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
470 if (std::abs(gesture->details().scroll_x_hint()) > | 514 if (std::abs(gesture->details().scroll_x_hint()) > |
471 std::abs(gesture->details().scroll_y_hint()) * 2) { | 515 std::abs(gesture->details().scroll_y_hint()) * 2) { |
472 dragged_start_location_ = gesture->location(); | 516 dragged_start_location_ = gesture->location(); |
473 dragged_window_ = SelectWindowAt(gesture); | 517 dragged_window_ = SelectWindowAt(gesture); |
474 if (dragged_window_) | 518 if (dragged_window_) |
475 overview_toolbar_.reset(new OverviewToolbar(container_)); | 519 overview_toolbar_.reset(new OverviewToolbar(container_)); |
476 } | 520 } |
477 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { | 521 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 if (scroll.IsZero()) { | 555 if (scroll.IsZero()) { |
512 fling_.reset(); | 556 fling_.reset(); |
513 RemoveAnimationObserver(); | 557 RemoveAnimationObserver(); |
514 } else { | 558 } else { |
515 DoScroll(scroll.y()); | 559 DoScroll(scroll.y()); |
516 } | 560 } |
517 } | 561 } |
518 | 562 |
519 const int kMinDistanceForDismissal = 300; | 563 const int kMinDistanceForDismissal = 300; |
520 const float kMinScale = 0.6f; | 564 const float kMinScale = 0.6f; |
521 const float kMaxScale = 0.95f; | 565 const float kMaxScale = 0.75f; |
522 const float kMaxOpacity = 1.0f; | 566 const float kMaxOpacity = 1.0f; |
523 const float kMinOpacity = 0.2f; | 567 const float kMinOpacity = 0.2f; |
524 | 568 |
525 aura::Window* container_; | 569 aura::Window* container_; |
526 // Provider of the stack of windows to show in the overview mode. Not owned. | 570 // Provider of the stack of windows to show in the overview mode. Not owned. |
527 const WindowListProvider* window_list_provider_; | 571 const WindowListProvider* window_list_provider_; |
572 SplitViewController* split_view_controller_; | |
528 WindowOverviewModeDelegate* delegate_; | 573 WindowOverviewModeDelegate* delegate_; |
529 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; | 574 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; |
530 scoped_ptr<ui::FlingCurve> fling_; | 575 scoped_ptr<ui::FlingCurve> fling_; |
531 | 576 |
532 aura::Window* dragged_window_; | 577 aura::Window* dragged_window_; |
533 gfx::Point dragged_start_location_; | 578 gfx::Point dragged_start_location_; |
534 scoped_ptr<OverviewToolbar> overview_toolbar_; | 579 scoped_ptr<OverviewToolbar> overview_toolbar_; |
535 | 580 |
581 struct { | |
582 bool enabled; | |
583 aura::Window* left; | |
584 aura::Window* right; | |
585 } split_; | |
586 | |
536 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); | 587 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); |
537 }; | 588 }; |
538 | 589 |
539 } // namespace | 590 } // namespace |
540 | 591 |
541 // static | 592 // static |
542 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( | 593 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
543 aura::Window* container, | 594 aura::Window* container, |
544 const WindowListProvider* window_list_provider, | 595 const WindowListProvider* window_list_provider, |
596 SplitViewController* split_view_controller, | |
545 WindowOverviewModeDelegate* delegate) { | 597 WindowOverviewModeDelegate* delegate) { |
546 return scoped_ptr<WindowOverviewMode>( | 598 return scoped_ptr<WindowOverviewMode>( |
547 new WindowOverviewModeImpl(container, window_list_provider, delegate)); | 599 new WindowOverviewModeImpl(container, window_list_provider, |
600 split_view_controller, delegate)); | |
548 } | 601 } |
549 | 602 |
550 } // namespace athena | 603 } // namespace athena |
OLD | NEW |