OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ | 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ |
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ | 6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "ui/aura/window_observer.h" | 12 #include "ui/aura/window_observer.h" |
13 #include "ui/compositor/layer_animator.h" | |
13 #include "ui/events/event_handler.h" | 14 #include "ui/events/event_handler.h" |
14 | 15 |
15 namespace ui { | 16 namespace ui { |
16 class Layer; | 17 class Layer; |
17 } | 18 } |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 class ShadowLayerDelegate; | 22 class ShadowLayerDelegate; |
22 | 23 |
23 // A class for sliding the layer in a Window on top of other layers. | 24 // A class for sliding the layer in a Window on top of other layers. |
24 class CONTENT_EXPORT WindowSlider : public ui::EventHandler, | 25 class CONTENT_EXPORT WindowSlider : public ui::EventHandler, |
25 public aura::WindowObserver { | 26 public aura::WindowObserver { |
26 public: | 27 public: |
27 class CONTENT_EXPORT Delegate { | 28 class CONTENT_EXPORT Delegate { |
28 public: | 29 public: |
29 virtual ~Delegate() {} | 30 virtual ~Delegate() {} |
30 | 31 |
31 // Creates a layer to show in the background, as the window-layer slides | 32 // Called when the slide in the backward direction starts. Returns a layer |
32 // with the scroll gesture. | 33 // to show in the background, as the window-layer slides with the scroll |
33 // The WindowSlider takes ownership of the created layer. | |
34 virtual ui::Layer* CreateBackLayer() = 0; | |
35 | |
36 // Creates a layer to slide on top of the window-layer with the scroll | |
37 // gesture. | 34 // gesture. |
38 // The WindowSlider takes ownership of the created layer. | 35 // The WindowSlider takes ownership of the created layer. |
39 virtual ui::Layer* CreateFrontLayer() = 0; | 36 virtual ui::Layer* OnSlideBackStartedCreateLayer() = 0; |
40 | 37 |
41 // Called when the slide is complete. Note that at the end of a completed | 38 // Called when the slide in the forward direction starts. Returns a layer |
42 // slide, the window-layer may have been transformed. The callback here | 39 // to slide on top of the window-layer with the scroll gesture. |
43 // should reset the transform if necessary. | 40 // The WindowSlider takes ownership of the created layer. |
44 virtual void OnWindowSlideComplete() = 0; | 41 virtual ui::Layer* OnSlideForwardStartedCreateLayer() = 0; |
45 | 42 |
46 // Called when the slide is aborted. Note that when the slide is aborted, | 43 // Called when the slide is aborted. Note that when the slide is aborted, |
47 // the WindowSlider resets any transform it applied on the window-layer. | 44 // the WindowSlider resets any transform it applied on the window-layer. |
48 virtual void OnWindowSlideAborted() = 0; | 45 virtual void OnWindowSlideAborted() = 0; |
49 | 46 |
47 // Called when the slide is about to be complete. The delegate can take | |
48 // action with the assumption that slide will complete soon (within the | |
49 // duration of the final transition animation effect). | |
50 // This callback is always preceeded by OnSlideBackStartedCreateLayer() or | |
51 // by OnSlideForwardStartedCreateLayer() callback, and is guaranteed to be | |
52 // followed by the OnWindowSlideCompleted() callback. | |
53 virtual void OnWindowSlideCompleting() = 0; | |
54 | |
55 // Called when the window slide completes. Note that at the end the | |
56 // window-layer may have been transformed. The callback here should reset | |
57 // the transform if necessary. | |
58 virtual void OnWindowSlideCompleted() = 0; | |
59 | |
50 // Called when the slider is destroyed. | 60 // Called when the slider is destroyed. |
51 virtual void OnWindowSliderDestroyed() = 0; | 61 virtual void OnWindowSliderDestroyed() = 0; |
52 }; | 62 }; |
53 | 63 |
54 // The WindowSlider slides the layers in the |owner| window. It starts | 64 // The WindowSlider slides the layers in the |owner| window. It starts |
55 // intercepting scroll events on |event_window|, and uses those events to | 65 // intercepting scroll events on |event_window|, and uses those events to |
56 // control the layer-slide. The lifetime of the slider is managed by the | 66 // control the layer-slide. The lifetime of the slider is managed by the |
57 // lifetime of |owner|, i.e. if |owner| is destroyed, then the slider also | 67 // lifetime of |owner|, i.e. if |owner| is destroyed, then the slider also |
58 // destroys itself. | 68 // destroys itself. |
59 WindowSlider(Delegate* delegate, | 69 WindowSlider(Delegate* delegate, |
60 aura::Window* event_window, | 70 aura::Window* event_window, |
61 aura::Window* owner); | 71 aura::Window* owner); |
62 | 72 |
63 virtual ~WindowSlider(); | 73 virtual ~WindowSlider(); |
64 | 74 |
65 // Changes the owner of the slider. | 75 // Changes the owner of the slider. |
66 void ChangeOwner(aura::Window* new_owner); | 76 void ChangeOwner(aura::Window* new_owner); |
67 | 77 |
68 bool IsSlideInProgress() const; | 78 bool IsSlideInProgress() const; |
69 | 79 |
70 private: | 80 private: |
71 // Sets up the slider layer correctly (sets the correct bounds of the layer, | 81 // Sets up the slider layer correctly (sets the correct bounds of the layer, |
72 // parents it to the right layer, and sets up the correct stacking order). | 82 // parents it to the right layer, and sets up the correct stacking order). |
73 void SetupSliderLayer(); | 83 void SetupSliderLayer(); |
74 | 84 |
75 void UpdateForScroll(float x_offset, float y_offset); | 85 void UpdateForScroll(float x_offset, float y_offset); |
76 | 86 |
77 void UpdateForFling(float x_velocity, float y_velocity); | 87 void UpdateForFling(float x_velocity, float y_velocity); |
78 | 88 |
79 // Resets any in-progress slide. | 89 // Stops all slider-owned animations, progressing them to their end-points. |
80 void ResetScroll(); | 90 // Note that depending on the sate of the Delegate and the WindowSlider, this |
91 // may destroy the WindowSlider through animation callbacks. | |
92 void CompleteActiveAnimations(); | |
81 | 93 |
82 // Cancels any scroll/animation in progress. | 94 // Resets in-progress slide if any, and starts the animation of the slidden |
83 void CancelScroll(); | 95 // window to its original position. |
96 void ResetSlide(); | |
84 | 97 |
85 // The following callbacks are triggered after an animation. | 98 // The following callbacks are triggered after an animation. |
86 void CompleteWindowSlideAfterAnimation(); | 99 void FlingAnimationCompleted(ui::Layer* layer, ShadowLayerDelegate* shadow); |
sadrul
2014/03/24 20:20:47
A window-slide can complete without a fling. We sh
mfomitchev
2014/03/24 22:36:47
True, but this callback is used (only) by the Upda
| |
87 | 100 |
88 void AbortWindowSlideAfterAnimation(); | 101 void ResetSlideAnimationCompleted(ui::Layer* layer, |
102 ShadowLayerDelegate* shadow); | |
89 | 103 |
90 // Overridden from ui::EventHandler: | 104 // Overridden from ui::EventHandler: |
91 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 105 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
92 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 106 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
93 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 107 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
94 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 108 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
95 | 109 |
96 // Overridden from aura::WindowObserver: | 110 // Overridden from aura::WindowObserver: |
97 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; | 111 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; |
98 | 112 |
99 Delegate* delegate_; | 113 Delegate* delegate_; |
100 | 114 |
101 // The slider intercepts scroll events from this window. The slider does not | 115 // The slider intercepts scroll events from this window. The slider does not |
102 // own |event_window_|. If |event_window_| is destroyed, then the slider stops | 116 // own |event_window_|. If |event_window_| is destroyed, then the slider stops |
103 // listening for events, but it doesn't destroy itself. | 117 // listening for events, but it doesn't destroy itself. |
104 aura::Window* event_window_; | 118 aura::Window* event_window_; |
105 | 119 |
106 // The window the slider operates on. The lifetime of the slider is bound to | 120 // The window the slider operates on. The lifetime of the slider is bound to |
107 // this window (i.e. if |owner_| does, the slider destroys itself). The slider | 121 // this window (i.e. if |owner_| does, the slider destroys itself). The slider |
108 // can also delete itself when a slide gesture is completed. This does not | 122 // can also delete itself when a slide gesture is completed. This does not |
109 // destroy |owner_|. | 123 // destroy |owner_|. |
110 aura::Window* owner_; | 124 aura::Window* owner_; |
111 | 125 |
126 // Set to the Animator of the currently active animation. If no animation is | |
127 // active, this is set to NULL. | |
128 ui::LayerAnimator* active_animator_; | |
129 | |
112 // The accumulated amount of horizontal scroll. | 130 // The accumulated amount of horizontal scroll. |
113 float delta_x_; | 131 float delta_x_; |
114 | 132 |
115 // This keeps track of the layer created by the delegate. | 133 // This keeps track of the layer created by the delegate. |
116 scoped_ptr<ui::Layer> slider_; | 134 scoped_ptr<ui::Layer> slider_; |
117 | 135 |
118 // This manages the shadow for the layers. | 136 // This manages the shadow for the layers. |
119 scoped_ptr<ShadowLayerDelegate> shadow_; | 137 scoped_ptr<ShadowLayerDelegate> shadow_; |
120 | 138 |
121 base::WeakPtrFactory<WindowSlider> weak_factory_; | 139 base::WeakPtrFactory<WindowSlider> weak_factory_; |
122 | 140 |
123 float active_start_threshold_; | 141 float active_start_threshold_; |
124 | 142 |
125 const float start_threshold_touchscreen_; | 143 const float start_threshold_touchscreen_; |
126 const float start_threshold_touchpad_; | 144 const float start_threshold_touchpad_; |
127 const float complete_threshold_; | 145 const float complete_threshold_; |
128 | 146 |
129 DISALLOW_COPY_AND_ASSIGN(WindowSlider); | 147 DISALLOW_COPY_AND_ASSIGN(WindowSlider); |
130 }; | 148 }; |
131 | 149 |
132 } // namespace content | 150 } // namespace content |
133 | 151 |
134 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ | 152 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ |
OLD | NEW |