Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / web_contents / aura / window_slider.h
blob64458834403eedfbd46141a923a14ae8b00d1ac7
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/compositor/layer_animator.h"
14 #include "ui/events/event_handler.h"
16 namespace ui {
17 class Layer;
20 namespace content {
22 class ShadowLayerDelegate;
24 // A class for sliding the layer in a Window on top of other layers.
25 class CONTENT_EXPORT WindowSlider : public ui::EventHandler,
26 public aura::WindowObserver {
27 public:
28 class CONTENT_EXPORT Delegate {
29 public:
30 virtual ~Delegate() {}
32 // Creates a layer to show behind the window-layer. Called when the
33 // window-layer starts sliding out to reveal the layer underneath.
34 // The WindowSlider takes ownership of the created layer.
35 virtual ui::Layer* CreateBackLayer() = 0;
37 // Creates a layer to show on top of the window-layer. Called when the new
38 // layer needs to start sliding in on top of the window-layer.
39 // The WindowSlider takes ownership of the created layer.
40 virtual ui::Layer* CreateFrontLayer() = 0;
42 // Called when the slide is aborted. Note that when the slide is aborted,
43 // the WindowSlider resets any transform it applied on the window-layer.
44 virtual void OnWindowSlideAborted() = 0;
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;
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;
59 // Called when the slider is destroyed.
60 virtual void OnWindowSliderDestroyed() = 0;
63 // The WindowSlider slides the layers in the |owner| window. It starts
64 // intercepting scroll events on |event_window|, and uses those events to
65 // control the layer-slide. The lifetime of the slider is managed by the
66 // lifetime of |owner|, i.e. if |owner| is destroyed, then the slider also
67 // destroys itself.
68 WindowSlider(Delegate* delegate,
69 aura::Window* event_window,
70 aura::Window* owner);
72 virtual ~WindowSlider();
74 // Changes the owner of the slider.
75 void ChangeOwner(aura::Window* new_owner);
77 bool IsSlideInProgress() const;
79 private:
80 // Sets up the slider layer correctly (sets the correct bounds of the layer,
81 // parents it to the right layer, and sets up the correct stacking order).
82 void SetupSliderLayer();
84 void UpdateForScroll(float x_offset, float y_offset);
86 // Completes or resets the slide depending on whether the sliding layer
87 // passed the "complete slide threshold".
88 void CompleteOrResetSlide();
90 // Stops all slider-owned animations, progressing them to their end-points.
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();
95 // Resets in-progress slide if any, and starts the animation of the slidden
96 // window to its original position.
97 void ResetSlide();
99 // The following callbacks are triggered after an animation.
100 void SlideAnimationCompleted(scoped_ptr<ui::Layer> layer,
101 scoped_ptr<ShadowLayerDelegate> shadow);
103 void ResetSlideAnimationCompleted(scoped_ptr<ui::Layer> layer,
104 scoped_ptr<ShadowLayerDelegate> shadow);
106 // Overridden from ui::EventHandler:
107 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
108 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
109 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
110 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
112 // Overridden from aura::WindowObserver:
113 virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
114 aura::Window* new_root) OVERRIDE;
116 Delegate* delegate_;
118 // The slider intercepts scroll events from this window. The slider does not
119 // own |event_window_|. If |event_window_| is destroyed, then the slider stops
120 // listening for events, but it doesn't destroy itself.
121 aura::Window* event_window_;
123 // The window the slider operates on. The lifetime of the slider is bound to
124 // this window (i.e. if |owner_| does, the slider destroys itself). The slider
125 // can also delete itself when a slide gesture is completed. This does not
126 // destroy |owner_|.
127 aura::Window* owner_;
129 // Set to the Animator of the currently active animation. If no animation is
130 // active, this is set to NULL.
131 ui::LayerAnimator* active_animator_;
133 // The accumulated amount of horizontal scroll.
134 float delta_x_;
136 // This keeps track of the layer created by the delegate.
137 scoped_ptr<ui::Layer> slider_;
139 // This manages the shadow for the layers.
140 scoped_ptr<ShadowLayerDelegate> shadow_;
142 base::WeakPtrFactory<WindowSlider> weak_factory_;
144 float active_start_threshold_;
146 const float start_threshold_touchscreen_;
147 const float start_threshold_touchpad_;
148 const float complete_threshold_;
150 DISALLOW_COPY_AND_ASSIGN(WindowSlider);
153 } // namespace content
155 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_WINDOW_SLIDER_H_