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

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

Issue 436213002: athena: Add support for fling-scroll in overview 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
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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "ui/aura/scoped_window_targeter.h" 12 #include "ui/aura/scoped_window_targeter.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h" 14 #include "ui/aura/window_delegate.h"
15 #include "ui/aura/window_property.h" 15 #include "ui/aura/window_property.h"
16 #include "ui/aura/window_targeter.h" 16 #include "ui/aura/window_targeter.h"
17 #include "ui/aura/window_tree_host.h"
18 #include "ui/compositor/compositor.h"
19 #include "ui/compositor/compositor_animation_observer.h"
17 #include "ui/compositor/scoped_layer_animation_settings.h" 20 #include "ui/compositor/scoped_layer_animation_settings.h"
18 #include "ui/events/event_handler.h" 21 #include "ui/events/event_handler.h"
22 #include "ui/events/gestures/fling_curve.h"
23 #include "ui/gfx/frame_time.h"
19 #include "ui/gfx/transform.h" 24 #include "ui/gfx/transform.h"
20 #include "ui/wm/core/shadow.h" 25 #include "ui/wm/core/shadow.h"
21 26
22 namespace { 27 namespace {
23 28
24 struct WindowOverviewState { 29 struct WindowOverviewState {
25 // The transform for when the window is at the topmost position. 30 // The transform for when the window is at the topmost position.
26 gfx::Transform top; 31 gfx::Transform top;
27 32
28 // The transform for when the window is at the bottom-most position. 33 // The transform for when the window is at the bottom-most position.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ui::EventTarget* root, 91 ui::EventTarget* root,
87 ui::LocatedEvent* event) OVERRIDE { 92 ui::LocatedEvent* event) OVERRIDE {
88 return target_; 93 return target_;
89 } 94 }
90 95
91 aura::Window* target_; 96 aura::Window* target_;
92 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); 97 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter);
93 }; 98 };
94 99
95 class WindowOverviewModeImpl : public WindowOverviewMode, 100 class WindowOverviewModeImpl : public WindowOverviewMode,
96 public ui::EventHandler { 101 public ui::EventHandler,
102 public ui::CompositorAnimationObserver {
97 public: 103 public:
98 WindowOverviewModeImpl(aura::Window* container, 104 WindowOverviewModeImpl(aura::Window* container,
99 WindowOverviewModeDelegate* delegate) 105 WindowOverviewModeDelegate* delegate)
100 : container_(container), 106 : container_(container),
101 delegate_(delegate), 107 delegate_(delegate),
102 scoped_targeter_(new aura::ScopedWindowTargeter( 108 scoped_targeter_(new aura::ScopedWindowTargeter(
103 container, 109 container,
104 scoped_ptr<ui::EventTargeter>( 110 scoped_ptr<ui::EventTargeter>(
105 new StaticWindowTargeter(container)))) { 111 new StaticWindowTargeter(container)))) {
106 container_->set_target_handler(this); 112 container_->set_target_handler(this);
107 113
108 // Prepare the desired transforms for all the windows, and set the initial 114 // Prepare the desired transforms for all the windows, and set the initial
109 // state on the windows. 115 // state on the windows.
110 ComputeTerminalStatesForAllWindows(); 116 ComputeTerminalStatesForAllWindows();
111 SetInitialWindowStates(); 117 SetInitialWindowStates();
112 } 118 }
113 119
114 virtual ~WindowOverviewModeImpl() { 120 virtual ~WindowOverviewModeImpl() {
115 container_->set_target_handler(container_->delegate()); 121 container_->set_target_handler(container_->delegate());
116 122 RemoveAnimationObserver();
117 const aura::Window::Windows& windows = container_->children(); 123 const aura::Window::Windows& windows = container_->children();
118 for (aura::Window::Windows::const_iterator iter = windows.begin(); 124 for (aura::Window::Windows::const_iterator iter = windows.begin();
119 iter != windows.end(); 125 iter != windows.end();
120 ++iter) { 126 ++iter) {
121 if ((*iter)->GetProperty(kWindowOverviewState)) 127 if ((*iter)->GetProperty(kWindowOverviewState))
122 RestoreWindowState(*iter); 128 RestoreWindowState(*iter);
123 } 129 }
124 } 130 }
125 131
126 private: 132 private:
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 286 }
281 } 287 }
282 } 288 }
283 } 289 }
284 290
285 int GetScrollableHeight() const { 291 int GetScrollableHeight() const {
286 const float kScrollableFraction = 0.65f; 292 const float kScrollableFraction = 0.65f;
287 return container_->bounds().height() * kScrollableFraction; 293 return container_->bounds().height() * kScrollableFraction;
288 } 294 }
289 295
296 void CreateFlingerFor(const ui::GestureEvent& event) {
297 gfx::Vector2dF velocity(event.details().velocity_x(),
298 event.details().velocity_y());
299 fling_.reset(new ui::FlingCurve(velocity, gfx::FrameTime::Now()));
300 }
301
302 void AddAnimationObserver() {
303 ui::Compositor* compositor = container_->GetHost()->compositor();
304 if (!compositor->HasAnimationObserver(this))
305 compositor->AddAnimationObserver(this);
306 }
307
308 void RemoveAnimationObserver() {
309 ui::Compositor* compositor = container_->GetHost()->compositor();
310 if (compositor->HasAnimationObserver(this))
311 compositor->RemoveAnimationObserver(this);
312 }
313
290 // ui::EventHandler: 314 // ui::EventHandler:
291 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { 315 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE {
292 if (mouse->type() == ui::ET_MOUSE_PRESSED) { 316 if (mouse->type() == ui::ET_MOUSE_PRESSED) {
293 aura::Window* select = SelectWindowAt(mouse); 317 aura::Window* select = SelectWindowAt(mouse);
294 if (select) { 318 if (select) {
295 mouse->SetHandled(); 319 mouse->SetHandled();
296 delegate_->OnSelectWindow(select); 320 delegate_->OnSelectWindow(select);
297 } 321 }
298 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { 322 } else if (mouse->type() == ui::ET_MOUSEWHEEL) {
299 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); 323 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset());
300 } 324 }
301 } 325 }
302 326
303 virtual void OnScrollEvent(ui::ScrollEvent* scroll) OVERRIDE { 327 virtual void OnScrollEvent(ui::ScrollEvent* scroll) OVERRIDE {
304 if (scroll->type() == ui::ET_SCROLL) 328 if (scroll->type() == ui::ET_SCROLL)
305 DoScroll(scroll->y_offset()); 329 DoScroll(scroll->y_offset());
306 } 330 }
307 331
308 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { 332 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
309 if (gesture->type() == ui::ET_GESTURE_TAP) { 333 if (gesture->type() == ui::ET_GESTURE_TAP) {
310 aura::Window* select = SelectWindowAt(gesture); 334 aura::Window* select = SelectWindowAt(gesture);
311 if (select) { 335 if (select) {
312 gesture->SetHandled(); 336 gesture->SetHandled();
313 delegate_->OnSelectWindow(select); 337 delegate_->OnSelectWindow(select);
314 } 338 }
315 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 339 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
316 DoScroll(gesture->details().scroll_y()); 340 DoScroll(gesture->details().scroll_y());
341 gesture->SetHandled();
342 } else if (gesture->type() == ui::ET_SCROLL_FLING_START) {
343 CreateFlingerFor(*gesture);
344 AddAnimationObserver();
345 gesture->SetHandled();
346 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN && fling_) {
347 fling_.reset();
348 RemoveAnimationObserver();
349 gesture->SetHandled();
350 }
351 }
352
353 // ui::CompositorAnimationObserver:
354 virtual void OnAnimationStep(base::TimeTicks timestamp) OVERRIDE {
355 CHECK(fling_);
356 if (fling_->start_timestamp() > timestamp)
357 return;
358 gfx::Vector2dF scroll = fling_->GetScrollAmountAtTime(timestamp);
359 if (scroll.IsZero()) {
Jun Mukai 2014/08/06 05:31:39 Vector2dF::IsZero() simply checks if both x and y
sadrul 2014/08/06 11:53:50 scroll eventually becomes 0, yes. I have added a t
360 fling_.reset();
361 RemoveAnimationObserver();
362 } else {
363 DoScroll(scroll.y());
317 } 364 }
318 } 365 }
319 366
320 aura::Window* container_; 367 aura::Window* container_;
321 WindowOverviewModeDelegate* delegate_; 368 WindowOverviewModeDelegate* delegate_;
322 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 369 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
370 scoped_ptr<ui::FlingCurve> fling_;
323 371
324 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 372 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
325 }; 373 };
326 374
327 } // namespace 375 } // namespace
328 376
329 // static 377 // static
330 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 378 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
331 aura::Window* container, 379 aura::Window* container,
332 WindowOverviewModeDelegate* delegate) { 380 WindowOverviewModeDelegate* delegate) {
333 return scoped_ptr<WindowOverviewMode>( 381 return scoped_ptr<WindowOverviewMode>(
334 new WindowOverviewModeImpl(container, delegate)); 382 new WindowOverviewModeImpl(container, delegate));
335 } 383 }
336 384
337 } // namespace athena 385 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698