| 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 // Creates a layer to show behind the window-layer. Called when the |
| 32 // with the scroll gesture. | 33 // window-layer starts sliding out to reveal the layer underneath. |
| 33 // The WindowSlider takes ownership of the created layer. | 34 // The WindowSlider takes ownership of the created layer. |
| 34 virtual ui::Layer* CreateBackLayer() = 0; | 35 virtual ui::Layer* CreateBackLayer() = 0; |
| 35 | 36 |
| 36 // Creates a layer to slide on top of the window-layer with the scroll | 37 // Creates a layer to show on top of the window-layer. Called when the new |
| 37 // gesture. | 38 // layer needs to start sliding in on top of the window-layer. |
| 38 // The WindowSlider takes ownership of the created layer. | 39 // The WindowSlider takes ownership of the created layer. |
| 39 virtual ui::Layer* CreateFrontLayer() = 0; | 40 virtual ui::Layer* CreateFrontLayer() = 0; |
| 40 | 41 |
| 41 // Called when the slide is complete. Note that at the end of a completed | |
| 42 // slide, the window-layer may have been transformed. The callback here | |
| 43 // should reset the transform if necessary. | |
| 44 virtual void OnWindowSlideComplete() = 0; | |
| 45 | |
| 46 // Called when the slide is aborted. Note that when the slide is aborted, | 42 // 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. | 43 // the WindowSlider resets any transform it applied on the window-layer. |
| 48 virtual void OnWindowSlideAborted() = 0; | 44 virtual void OnWindowSlideAborted() = 0; |
| 49 | 45 |
| 46 // Called when the slide is about to be complete. The delegate can take |
| 47 // action with the assumption that slide will complete soon (within the |
| 48 // duration of the final transition animation effect). |
| 49 // This callback is always preceeded by CreateBackLayerAndSetAsTarget() or |
| 50 // by CreateFrontLayerAndSetAsTarget() callback, and is guaranteed to be |
| 51 // followed by the OnWindowSlideCompleted() callback. |
| 52 virtual void OnWindowSlideCompleting() = 0; |
| 53 |
| 54 // Called when the window slide completes. Note that at the end the |
| 55 // window-layer may have been transformed. The callback here should reset |
| 56 // the transform if necessary. |
| 57 virtual void OnWindowSlideCompleted() = 0; |
| 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 // Completes or resets the slide depending on whether the sliding layer |
| 87 // passed the "complete slide threshold". |
| 88 void CompleteOrResetSlide(); |
| 78 | 89 |
| 79 // Resets any in-progress slide. | 90 // Stops all slider-owned animations, progressing them to their end-points. |
| 80 void ResetScroll(); | 91 // Note that depending on the sate of the Delegate and the WindowSlider, this |
| 92 // may destroy the WindowSlider through animation callbacks. |
| 93 void CompleteActiveAnimations(); |
| 81 | 94 |
| 82 // Cancels any scroll/animation in progress. | 95 // Resets in-progress slide if any, and starts the animation of the slidden |
| 83 void CancelScroll(); | 96 // window to its original position. |
| 97 void ResetSlide(); |
| 84 | 98 |
| 85 // The following callbacks are triggered after an animation. | 99 // The following callbacks are triggered after an animation. |
| 86 void CompleteWindowSlideAfterAnimation(); | 100 void SlideAnimationCompleted(scoped_ptr<ui::Layer> layer, |
| 101 scoped_ptr<ShadowLayerDelegate> shadow); |
| 87 | 102 |
| 88 void AbortWindowSlideAfterAnimation(); | 103 void ResetSlideAnimationCompleted(scoped_ptr<ui::Layer> layer, |
| 104 scoped_ptr<ShadowLayerDelegate> shadow); |
| 89 | 105 |
| 90 // Overridden from ui::EventHandler: | 106 // Overridden from ui::EventHandler: |
| 91 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 107 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 92 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 108 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 93 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 109 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| 94 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 110 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 95 | 111 |
| 96 // Overridden from aura::WindowObserver: | 112 // Overridden from aura::WindowObserver: |
| 97 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; | 113 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; |
| 98 | 114 |
| 99 Delegate* delegate_; | 115 Delegate* delegate_; |
| 100 | 116 |
| 101 // The slider intercepts scroll events from this window. The slider does not | 117 // 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 | 118 // own |event_window_|. If |event_window_| is destroyed, then the slider stops |
| 103 // listening for events, but it doesn't destroy itself. | 119 // listening for events, but it doesn't destroy itself. |
| 104 aura::Window* event_window_; | 120 aura::Window* event_window_; |
| 105 | 121 |
| 106 // The window the slider operates on. The lifetime of the slider is bound to | 122 // 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 | 123 // 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 | 124 // can also delete itself when a slide gesture is completed. This does not |
| 109 // destroy |owner_|. | 125 // destroy |owner_|. |
| 110 aura::Window* owner_; | 126 aura::Window* owner_; |
| 111 | 127 |
| 128 // Set to the Animator of the currently active animation. If no animation is |
| 129 // active, this is set to NULL. |
| 130 ui::LayerAnimator* active_animator_; |
| 131 |
| 112 // The accumulated amount of horizontal scroll. | 132 // The accumulated amount of horizontal scroll. |
| 113 float delta_x_; | 133 float delta_x_; |
| 114 | 134 |
| 115 // This keeps track of the layer created by the delegate. | 135 // This keeps track of the layer created by the delegate. |
| 116 scoped_ptr<ui::Layer> slider_; | 136 scoped_ptr<ui::Layer> slider_; |
| 117 | 137 |
| 118 // This manages the shadow for the layers. | 138 // This manages the shadow for the layers. |
| 119 scoped_ptr<ShadowLayerDelegate> shadow_; | 139 scoped_ptr<ShadowLayerDelegate> shadow_; |
| 120 | 140 |
| 121 base::WeakPtrFactory<WindowSlider> weak_factory_; | 141 base::WeakPtrFactory<WindowSlider> weak_factory_; |
| 122 | 142 |
| 123 float active_start_threshold_; | 143 float active_start_threshold_; |
| 124 | 144 |
| 125 const float start_threshold_touchscreen_; | 145 const float start_threshold_touchscreen_; |
| 126 const float start_threshold_touchpad_; | 146 const float start_threshold_touchpad_; |
| 127 const float complete_threshold_; | 147 const float complete_threshold_; |
| 128 | 148 |
| 129 DISALLOW_COPY_AND_ASSIGN(WindowSlider); | 149 DISALLOW_COPY_AND_ASSIGN(WindowSlider); |
| 130 }; | 150 }; |
| 131 | 151 |
| 132 } // namespace content | 152 } // namespace content |
| 133 | 153 |
| 134 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ | 154 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_ |
| OLD | NEW |