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

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

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

Powered by Google App Engine
This is Rietveld 408576698