Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: content/browser/web_contents/aura/overscroll_window_animation.h

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last round of comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 behind while the slide window one moves in from the right. SLIDE_BACK
mfomitchev 2015/03/31 21:04:07 stays still, while the slide window moves on top o
Nina 2015/04/01 18:10:01 Done.
37 // means that the main window is animated to the right, revealing the slide
38 // window on the back. SLIDE_NONE means we are not animating yet. Left and
mfomitchev 2015/03/31 21:04:07 in the back, which stays still.
Nina 2015/04/01 18:10:01 Done.
39 // right are reversed for users of RTL languages, but stack order remains
mfomitchev 2015/03/31 21:04:08 Directions are reversed for RTL languages,..
Nina 2015/04/01 18:10:01 Done.
40 // unchanged.
41 enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE };
42
43 // Delegate class that interfaces with the window animation.
44 class Delegate {
45 public:
46 virtual ~Delegate() {}
47
48 // The following two functions create a slide window and transfer back its
49 // ownership.
50 virtual scoped_ptr<aura::Window> CreateFrontWindow() = 0;
51 virtual scoped_ptr<aura::Window> CreateBackWindow() = 0;
52
53 // Returns the main window that participates in the animation. We do not own
54 // this window.
55 virtual aura::Window* GetMainWindow() const = 0;
56
57 // Called when we know the animation is going to complete successfully, but
58 // before it actually completes.
59 virtual void OnOverscrollCompleting() = 0;
60
61 // Called when the animation has been completed. The slide window's
62 // ownership is transferred.
mfomitchev 2015/03/31 21:04:08 "The slide window's ownership is transferred" -> "
Nina 2015/04/01 18:10:01 Done.
63 virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0;
64
65 // Called when the overscroll gesture has been aborted, after the abort
66 // animation finishes.
67 virtual void OnOverscrollAborted() = 0;
68 };
69
70 explicit OverscrollWindowAnimation(Delegate* delegate);
71
72 ~OverscrollWindowAnimation() override;
73
74 // Returns true if we are currently animating.
75 bool is_active() const { return !!slide_window_; }
76
77 // Overridden from OverscrollControllerDelegate:
78 gfx::Rect GetVisibleBounds() const override;
79
80 bool OnOverscrollUpdate(float delta_x, float delta_y) override;
81
82 void OnOverscrollComplete(OverscrollMode overscroll_mode) override;
83
84 void OnOverscrollModeChange(OverscrollMode old_mode,
mfomitchev 2015/03/31 21:04:07 Leave no space between overridden methods
Nina 2015/04/01 18:10:01 Done.
85 OverscrollMode new_mode) override;
86
87 private:
88 // Cancels the animation, animating the front window to its original position.
89 void CancelAnimation();
90
91 // Moves the animated window according to the given scroll deltas. Returns
92 // true if the update moved the window.
93 bool UpdateForScroll(float delta_x);
94
95 // Returns a translation on the x axis for the given overscroll.
96 float GetTranslationForOverscroll(float delta_x);
97
98 // Returns the layer that is animated for the animation.
99 ui::Layer* GetFrontLayer() const;
100
101 // ui::ImplicitAnimationObserver:
102 void OnImplicitAnimationsCompleted() override;
103
104 // We own the window created for the animation.
105 scoped_ptr<aura::Window> slide_window_;
106
107 // Shadow shown under the animated layer.
108 scoped_ptr<ShadowLayerDelegate> shadow_;
109
110 // Delegate that provides the animation target and is notified of the
111 // animation state.
112 Delegate* delegate_;
113
114 // The current animation direction.
115 Direction direction_;
116
117 // Indicates if the current animation has been cancelled.
mfomitchev 2015/03/31 21:04:07 Pick either "aborted" or "cancelled and stick to t
Nina 2015/04/01 18:10:01 s/abort/cancel for the overscroll related function
118 bool overscroll_cancelled_;
119 };
120
121 } // namespace content
122
123 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698