Chromium Code Reviews| 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; |
|
sadrul
2014/03/19 20:21:18
I want the window-slider to work in terms of back/
mfomitchev
2014/03/20 15:10:06
Ah, do you mean back/front in a sense of below/abo
sadrul
2014/03/24 20:20:46
Yes.
mfomitchev
2014/03/24 22:36:47
Ok, that makes sense. I am still not a big fan of
sadrul
2014/03/25 23:01:56
I don't understand what you mean by 'updating the
| |
| 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 sliding window is flinged off-screen (in the direction | |
| 48 // it was sliding). | |
| 49 // This callback is always preceeded by one of the OnSlide***Started() | |
|
sadrul
2014/03/19 20:21:18
What are the OnSlide***Started() callbacks?
mfomitchev
2014/03/20 15:10:06
Done.
| |
| 50 // callbacks, and is guaranteed to be followed by the | |
| 51 // OnWindowFlingCompleted() callback. | |
| 52 virtual void OnWindowFlingStarted() = 0; | |
| 53 | |
| 54 // Called when the window fling animation is complete. Note that at the end | |
| 55 // the window-layer may have been transformed. The callback here should | |
| 56 // reset the transform if necessary. | |
| 57 virtual void OnWindowFlingCompleted() = 0; | |
|
sadrul
2014/03/19 20:21:18
What if the gesture ends without a fling?
Can we
mfomitchev
2014/03/20 15:10:06
Done.
| |
| 58 | |
| 50 // Called when the slider is destroyed. | 59 // Called when the slider is destroyed. |
| 51 virtual void OnWindowSliderDestroyed() = 0; | 60 virtual void OnWindowSliderDestroyed() = 0; |
| 52 }; | 61 }; |
| 53 | 62 |
| 54 // The WindowSlider slides the layers in the |owner| window. It starts | 63 // The WindowSlider slides the layers in the |owner| window. It starts |
| 55 // intercepting scroll events on |event_window|, and uses those events to | 64 // 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 | 65 // 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 | 66 // lifetime of |owner|, i.e. if |owner| is destroyed, then the slider also |
| 58 // destroys itself. | 67 // destroys itself. |
| 59 WindowSlider(Delegate* delegate, | 68 WindowSlider(Delegate* delegate, |
| 60 aura::Window* event_window, | 69 aura::Window* event_window, |
| 61 aura::Window* owner); | 70 aura::Window* owner); |
| 62 | 71 |
| 63 virtual ~WindowSlider(); | 72 virtual ~WindowSlider(); |
| 64 | 73 |
| 65 // Changes the owner of the slider. | 74 // Changes the owner of the slider. |
| 66 void ChangeOwner(aura::Window* new_owner); | 75 void ChangeOwner(aura::Window* new_owner); |
| 67 | 76 |
| 68 bool IsSlideInProgress() const; | 77 bool IsSlideInProgress() const; |
| 69 | 78 |
| 70 private: | 79 private: |
| 71 // Sets up the slider layer correctly (sets the correct bounds of the layer, | 80 // 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). | 81 // parents it to the right layer, and sets up the correct stacking order). |
| 73 void SetupSliderLayer(); | 82 void SetupSliderLayer(); |
| 74 | 83 |
| 75 void UpdateForScroll(float x_offset, float y_offset); | 84 void UpdateForScroll(float x_offset, float y_offset); |
| 76 | 85 |
| 77 void UpdateForFling(float x_velocity, float y_velocity); | 86 void UpdateForFling(float x_velocity, float y_velocity); |
| 78 | 87 |
| 79 // Resets any in-progress slide. | 88 // Stops all slider-owned animations, progressing them to their end-points. |
| 80 void ResetScroll(); | 89 // Note that depending on the sate of the Delegate and the WindowSlider, this |
| 90 // may destroy the WindowSlider through animation callbacks. | |
| 91 void CompleteActiveAnimations(); | |
| 81 | 92 |
| 82 // Cancels any scroll/animation in progress. | 93 // Resets in-progress slide if any, and starts the animation of the slidden |
| 83 void CancelScroll(); | 94 // window to its original position. |
| 95 void ResetSlide(); | |
| 84 | 96 |
| 85 // The following callbacks are triggered after an animation. | 97 // The following callbacks are triggered after an animation. |
| 86 void CompleteWindowSlideAfterAnimation(); | 98 void FlingAnimationCompleted(ui::Layer* layer, ShadowLayerDelegate* shadow); |
| 87 | 99 |
| 88 void AbortWindowSlideAfterAnimation(); | 100 void ResetSlideAnimationCompleted(ui::Layer* layer, |
| 101 ShadowLayerDelegate* shadow); | |
| 89 | 102 |
| 90 // Overridden from ui::EventHandler: | 103 // Overridden from ui::EventHandler: |
| 91 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 104 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 92 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 105 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 93 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 106 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| 94 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 107 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 95 | 108 |
| 96 // Overridden from aura::WindowObserver: | 109 // Overridden from aura::WindowObserver: |
| 97 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; | 110 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; |
| 98 | 111 |
| 99 Delegate* delegate_; | 112 Delegate* delegate_; |
| 100 | 113 |
| 101 // The slider intercepts scroll events from this window. The slider does not | 114 // 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 | 115 // own |event_window_|. If |event_window_| is destroyed, then the slider stops |
| 103 // listening for events, but it doesn't destroy itself. | 116 // listening for events, but it doesn't destroy itself. |
| 104 aura::Window* event_window_; | 117 aura::Window* event_window_; |
| 105 | 118 |
| 106 // The window the slider operates on. The lifetime of the slider is bound to | 119 // 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 | 120 // 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 | 121 // can also delete itself when a slide gesture is completed. This does not |
| 109 // destroy |owner_|. | 122 // destroy |owner_|. |
| 110 aura::Window* owner_; | 123 aura::Window* owner_; |
| 111 | 124 |
| 125 // Set to the Animator of the currently active animation. If no animation is | |
| 126 // active, this is set to NULL. | |
| 127 ui::LayerAnimator* active_animator_; | |
| 128 | |
| 112 // The accumulated amount of horizontal scroll. | 129 // The accumulated amount of horizontal scroll. |
| 113 float delta_x_; | 130 float delta_x_; |
| 114 | 131 |
| 115 // This keeps track of the layer created by the delegate. | 132 // This keeps track of the layer created by the delegate. |
| 116 scoped_ptr<ui::Layer> slider_; | 133 scoped_ptr<ui::Layer> slider_; |
| 117 | 134 |
| 118 // This manages the shadow for the layers. | 135 // This manages the shadow for the layers. |
| 119 scoped_ptr<ShadowLayerDelegate> shadow_; | 136 scoped_ptr<ShadowLayerDelegate> shadow_; |
| 120 | 137 |
| 121 base::WeakPtrFactory<WindowSlider> weak_factory_; | 138 base::WeakPtrFactory<WindowSlider> weak_factory_; |
| 122 | 139 |
| 123 float active_start_threshold_; | 140 float active_start_threshold_; |
| 124 | 141 |
| 125 const float start_threshold_touchscreen_; | 142 const float start_threshold_touchscreen_; |
| 126 const float start_threshold_touchpad_; | 143 const float start_threshold_touchpad_; |
| 127 const float complete_threshold_; | 144 const float complete_threshold_; |
| 128 | 145 |
| 129 DISALLOW_COPY_AND_ASSIGN(WindowSlider); | 146 DISALLOW_COPY_AND_ASSIGN(WindowSlider); |
| 130 }; | 147 }; |
| 131 | 148 |
| 132 } // namespace content | 149 } // namespace content |
| 133 | 150 |
| 134 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ | 151 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ |
| OLD | NEW |