Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / web_contents / aura / overscroll_window_animation.h
blob876368d3f980dffbfe14a135a9199b42f2c2e8a0
1 // Copyright 2015 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_OVERSCROLL_WINDOW_ANIMATION_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_
8 #include "base/gtest_prod_util.h"
9 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
10 #include "content/common/content_export.h"
11 #include "ui/compositor/layer_animation_observer.h"
13 namespace aura {
14 class Window;
17 namespace ui {
18 class Layer;
19 class LayerAnimator;
22 namespace content {
24 class ShadowLayerDelegate;
25 class WebContentsImpl;
27 // Manages the animation of a window sliding on top or behind another one. The
28 // main window, which is the one displayed before the animation starts, is not
29 // owned by OverscrollWindowAnimation, while the slide window, created at the
30 // start of the animation, is owned by us for its duration.
31 class CONTENT_EXPORT OverscrollWindowAnimation
32 : public OverscrollControllerDelegate,
33 ui::ImplicitAnimationObserver {
34 public:
35 // The direction of this animation. SLIDE_FRONT indicates that the slide
36 // window moves on top of the main window, entering the screen from the right.
37 // SLIDE_BACK means that the main window is animated to the right, revealing
38 // the slide window in the back. SLIDE_NONE means we are not animating yet.
39 // Both windows are animated at the same time but at different speeds,
40 // creating a parallax scrolling effect. Left and right are reversed for RTL
41 // languages, but stack order remains unchanged.
42 enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE };
44 // Delegate class that interfaces with the window animation.
45 class CONTENT_EXPORT Delegate {
46 public:
47 virtual ~Delegate() {}
49 // Create a slide window with the given |bounds| relative to its parent.
50 virtual scoped_ptr<aura::Window> CreateFrontWindow(
51 const gfx::Rect& bounds) = 0;
52 virtual scoped_ptr<aura::Window> CreateBackWindow(
53 const gfx::Rect& bounds) = 0;
55 // Returns the main window that participates in the animation. The delegate
56 // does not own this window.
57 virtual aura::Window* GetMainWindow() const = 0;
59 // Called when we know the animation is going to complete successfully, but
60 // before it actually completes.
61 virtual void OnOverscrollCompleting() = 0;
63 // Called when the animation has been completed. The slide window is
64 // transferred to the delegate.
65 virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0;
67 // Called when the overscroll gesture has been cancelled, after the cancel
68 // animation finishes.
69 virtual void OnOverscrollCancelled() = 0;
72 explicit OverscrollWindowAnimation(Delegate* delegate);
74 ~OverscrollWindowAnimation() override;
76 // Returns true if we are currently animating.
77 bool is_active() const { return !!slide_window_; }
79 // OverscrollControllerDelegate:
80 gfx::Rect GetVisibleBounds() const override;
81 bool OnOverscrollUpdate(float delta_x, float delta_y) override;
82 void OnOverscrollComplete(OverscrollMode overscroll_mode) override;
83 void OnOverscrollModeChange(OverscrollMode old_mode,
84 OverscrollMode new_mode) override;
86 private:
87 // Cancels the slide, animating the front and back window to their original
88 // positions.
89 void CancelSlide();
91 // Returns a translation on the x axis for the given overscroll.
92 float GetTranslationForOverscroll(float delta_x);
94 // Animates a translation of the given |layer|. If |listen_for_completion| is
95 // true, adds |this| as observer of the animation.
96 void AnimateTranslation(ui::Layer* layer,
97 float translate_x,
98 bool listen_for_completion);
100 // Return the front/back layer that is involved in the animation. The caller
101 // does not own it.
102 ui::Layer* GetFrontLayer() const;
103 ui::Layer* GetBackLayer() const;
105 // ui::ImplicitAnimationObserver:
106 void OnImplicitAnimationsCompleted() override;
108 // We own the window created for the animation.
109 scoped_ptr<aura::Window> slide_window_;
111 // Shadow shown under the animated layer.
112 scoped_ptr<ShadowLayerDelegate> shadow_;
114 // Delegate that provides the animation target and is notified of the
115 // animation state.
116 Delegate* delegate_;
118 // The current animation direction.
119 Direction direction_;
121 // Indicates if the current slide has been cancelled. True while the cancel
122 // animation is in progress.
123 bool overscroll_cancelled_;
125 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimation);
128 } // namespace content
130 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_