OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ | |
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ | |
7 | |
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" | |
12 | |
13 namespace aura { | |
14 class Window; | |
15 } | |
16 | |
17 namespace ui { | |
18 class Layer; | |
19 class LayerAnimator; | |
20 } | |
21 | |
22 namespace content { | |
23 | |
24 class ShadowLayerDelegate; | |
25 class WebContentsImpl; | |
26 | |
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 main window | |
36 // stays still while the slide window moves on top of it, entering in from the | |
37 // right. SLIDE_BACK means that the main window is animated to the right, | |
38 // revealing the slide window in the back, which stays still. SLIDE_NONE | |
39 // means we are not animating yet. Left and right are reversed for RTL | |
40 // languages, but stack order remains unchanged. | |
41 enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE }; | |
42 | |
43 // Delegate class that interfaces with the window animation. | |
44 class CONTENT_EXPORT Delegate { | |
45 public: | |
46 virtual ~Delegate() {} | |
47 | |
48 // Create a slide window with the given |bounds| relative to its parent. | |
49 virtual scoped_ptr<aura::Window> CreateFrontWindow( | |
50 const gfx::Rect& bounds) = 0; | |
51 virtual scoped_ptr<aura::Window> CreateBackWindow( | |
52 const gfx::Rect& bounds) = 0; | |
53 | |
54 // Returns the main window that participates in the animation. The delegate | |
55 // does not own this window. | |
56 virtual aura::Window* GetMainWindow() const = 0; | |
57 | |
58 // Called when we know the animation is going to complete successfully, but | |
59 // before it actually completes. | |
60 virtual void OnOverscrollCompleting() = 0; | |
61 | |
62 // Called when the animation has been completed. The slide window is | |
63 // transferred to the delegate. | |
64 virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0; | |
65 | |
66 // Called when the overscroll gesture has been cancelled, after the cancel | |
67 // animation finishes. | |
68 virtual void OnOverscrollCancelled() = 0; | |
69 }; | |
70 | |
71 explicit OverscrollWindowAnimation(Delegate* delegate); | |
72 | |
73 ~OverscrollWindowAnimation() override; | |
74 | |
75 // Returns true if we are currently animating. | |
76 bool is_active() const { return !!slide_window_; } | |
77 | |
78 // OverscrollControllerDelegate: | |
79 gfx::Rect GetVisibleBounds() const override; | |
80 bool OnOverscrollUpdate(float delta_x, float delta_y) override; | |
81 void OnOverscrollComplete(OverscrollMode overscroll_mode) override; | |
82 void OnOverscrollModeChange(OverscrollMode old_mode, | |
83 OverscrollMode new_mode) override; | |
84 | |
85 private: | |
86 // Cancels the slide, animating the front window to its original position. | |
87 void CancelSlide(); | |
88 | |
89 // Returns a translation on the x axis for the given overscroll. | |
90 float GetTranslationForOverscroll(float delta_x); | |
91 | |
92 // Returns the layer that is animated for the animation. The caller does not | |
93 // own it. | |
94 ui::Layer* GetFrontLayer() const; | |
95 | |
96 // ui::ImplicitAnimationObserver: | |
97 void OnImplicitAnimationsCompleted() override; | |
98 | |
99 // We own the window created for the animation. | |
100 scoped_ptr<aura::Window> slide_window_; | |
101 | |
102 // Shadow shown under the animated layer. | |
103 scoped_ptr<ShadowLayerDelegate> shadow_; | |
104 | |
105 // Delegate that provides the animation target and is notified of the | |
106 // animation state. | |
107 Delegate* delegate_; | |
108 | |
109 // The current animation direction. | |
110 Direction direction_; | |
111 | |
112 // Indicates if the current animation has been cancelled. True while the | |
113 // cancel animation is in progress. | |
114 bool overscroll_cancelled_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimation); | |
117 }; | |
118 | |
119 } // namespace content | |
120 | |
121 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ | |
OLD | NEW |