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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/common/content_export.h"
12 #include "ui/aura/window_observer.h"
13 #include "ui/events/event_handler.h"
21 class ShadowLayerDelegate;
23 // A class for sliding the layer in a Window on top of other layers.
24 class CONTENT_EXPORT WindowSlider : public ui::EventHandler,
25 public aura::WindowObserver {
29 virtual ~Delegate() {}
31 // Creates a layer to show in the background, as the window-layer slides
32 // with the scroll gesture.
33 // The WindowSlider takes ownership of the created layer.
34 virtual ui::Layer* CreateBackLayer() = 0;
36 // Creates a layer to slide on top of the window-layer with the scroll
38 // The WindowSlider takes ownership of the created layer.
39 virtual ui::Layer* CreateFrontLayer() = 0;
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;
46 // 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.
48 virtual void OnWindowSlideAborted() = 0;
50 // Called when the slider is destroyed.
51 virtual void OnWindowSliderDestroyed() = 0;
54 // The WindowSlider slides the layers in the |owner| window. It starts
55 // 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
57 // lifetime of |owner|, i.e. if |owner| is destroyed, then the slider also
59 WindowSlider(Delegate* delegate,
60 aura::Window* event_window,
63 virtual ~WindowSlider();
65 // Changes the owner of the slider.
66 void ChangeOwner(aura::Window* new_owner);
68 bool IsSlideInProgress() const;
71 // 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).
73 void SetupSliderLayer();
75 void UpdateForScroll(float x_offset, float y_offset);
77 void UpdateForFling(float x_velocity, float y_velocity);
79 // Resets any in-progress slide.
82 // Cancels any scroll/animation in progress.
85 // The following callbacks are triggered after an animation.
86 void CompleteWindowSlideAfterAnimation();
88 void AbortWindowSlideAfterAnimation();
90 // Overridden from ui::EventHandler:
91 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
92 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
93 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
94 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
96 // Overridden from aura::WindowObserver:
97 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE;
101 // 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
103 // listening for events, but it doesn't destroy itself.
104 aura::Window* event_window_;
106 // 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
108 // can also delete itself when a slide gesture is completed. This does not
110 aura::Window* owner_;
112 // The accumulated amount of horizontal scroll.
115 // This keeps track of the layer created by the delegate.
116 scoped_ptr<ui::Layer> slider_;
118 // This manages the shadow for the layers.
119 scoped_ptr<ShadowLayerDelegate> shadow_;
121 base::WeakPtrFactory<WindowSlider> weak_factory_;
123 float active_start_threshold_;
125 const float start_threshold_touchscreen_;
126 const float start_threshold_touchpad_;
127 const float complete_threshold_;
129 DISALLOW_COPY_AND_ASSIGN(WindowSlider);
132 } // namespace content
134 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_