Chromium Code Reviews| 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 // The following two functions create a slide window. | |
|
sadrul
2015/04/07 17:10:08
This comment isn't necessary.
Nina
2015/04/07 19:08:56
Removed.
| |
| 49 virtual scoped_ptr<aura::Window> CreateFrontWindow() = 0; | |
| 50 virtual scoped_ptr<aura::Window> CreateBackWindow() = 0; | |
| 51 | |
| 52 // Returns the main window that participates in the animation. We do not own | |
| 53 // this window. | |
|
sadrul
2015/04/07 17:10:08
Not clear what 'We' here means. Either 'The delega
Nina
2015/04/07 19:08:56
Good call. s/ to The delegate does not own this wi
| |
| 54 virtual aura::Window* GetMainWindow() const = 0; | |
| 55 | |
| 56 // Called when we know the animation is going to complete successfully, but | |
| 57 // before it actually completes. | |
| 58 virtual void OnOverscrollCompleting() = 0; | |
| 59 | |
| 60 // Called when the animation has been completed. | |
| 61 virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0; | |
|
sadrul
2015/04/07 17:10:08
What is |window|?
Nina
2015/04/07 19:08:56
Added "The slide window is transferred to the dele
| |
| 62 | |
| 63 // Called when the overscroll gesture has been cancelled, after the cancel | |
| 64 // animation finishes. | |
| 65 virtual void OnOverscrollCancelled() = 0; | |
| 66 }; | |
| 67 | |
| 68 explicit OverscrollWindowAnimation(Delegate* delegate); | |
| 69 | |
| 70 ~OverscrollWindowAnimation() override; | |
| 71 | |
| 72 // Returns true if we are currently animating. | |
| 73 bool is_active() const { return !!slide_window_; } | |
| 74 | |
| 75 // Overridden from OverscrollControllerDelegate: | |
|
sadrul
2015/04/07 17:10:08
// OverscrollControllerDelegate:
(like below for
Nina
2015/04/07 19:08:56
Done.
| |
| 76 gfx::Rect GetVisibleBounds() const override; | |
| 77 bool OnOverscrollUpdate(float delta_x, float delta_y) override; | |
| 78 void OnOverscrollComplete(OverscrollMode overscroll_mode) override; | |
| 79 void OnOverscrollModeChange(OverscrollMode old_mode, | |
| 80 OverscrollMode new_mode) override; | |
| 81 | |
| 82 private: | |
| 83 // Cancels the animation, animating the front window to its original position. | |
| 84 void CancelAnimation(); | |
| 85 | |
| 86 // Moves the animated window according to the given scroll deltas. Returns | |
| 87 // true if the update moved the window. | |
| 88 bool UpdateForScroll(float delta_x); | |
| 89 | |
| 90 // Returns a translation on the x axis for the given overscroll. | |
| 91 float GetTranslationForOverscroll(float delta_x); | |
| 92 | |
| 93 // Returns the layer that is animated for the animation. | |
| 94 ui::Layer* GetFrontLayer() const; | |
|
sadrul
2015/04/07 17:10:08
Document ownership of the returned layer. If the c
Nina
2015/04/07 19:08:56
The caller does not own it, made it clear in the c
| |
| 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_; | |
|
sadrul
2015/04/07 17:10:08
DISALLOW_COPY_AND_ASSIGN
Nina
2015/04/07 19:08:56
Done.
| |
| 115 }; | |
| 116 | |
| 117 } // namespace content | |
| 118 | |
| 119 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ | |
| OLD | NEW |