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 virtual scoped_ptr<aura::Window> CreateFrontWindow( | |
| 49 const gfx::Rect& bounds) = 0; | |
|
mfomitchev
2015/04/08 17:33:16
Please comment what bounds are
Nina
2015/04/08 17:46:49
Done.
| |
| 50 virtual scoped_ptr<aura::Window> CreateBackWindow( | |
| 51 const gfx::Rect& bounds) = 0; | |
| 52 | |
| 53 // Returns the main window that participates in the animation. The delegate | |
| 54 // does not own 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 is | |
| 62 // transferred to the delegate. | |
| 63 virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0; | |
| 64 | |
| 65 // Called when the overscroll gesture has been cancelled, after the cancel | |
| 66 // animation finishes. | |
| 67 virtual void OnOverscrollCancelled() = 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 // OverscrollControllerDelegate: | |
| 78 gfx::Rect GetVisibleBounds() const override; | |
| 79 bool OnOverscrollUpdate(float delta_x, float delta_y) override; | |
| 80 void OnOverscrollComplete(OverscrollMode overscroll_mode) override; | |
| 81 void OnOverscrollModeChange(OverscrollMode old_mode, | |
| 82 OverscrollMode new_mode) override; | |
| 83 | |
| 84 private: | |
| 85 // Cancels the slide, animating the front window to its original position. | |
| 86 void CancelSlide(); | |
| 87 | |
| 88 // Returns a translation on the x axis for the given overscroll. | |
| 89 float GetTranslationForOverscroll(float delta_x); | |
| 90 | |
| 91 // Returns the layer that is animated for the animation. The caller does not | |
| 92 // own it. | |
| 93 ui::Layer* GetFrontLayer() const; | |
| 94 | |
| 95 // ui::ImplicitAnimationObserver: | |
| 96 void OnImplicitAnimationsCompleted() override; | |
| 97 | |
| 98 // We own the window created for the animation. | |
| 99 scoped_ptr<aura::Window> slide_window_; | |
| 100 | |
| 101 // Shadow shown under the animated layer. | |
| 102 scoped_ptr<ShadowLayerDelegate> shadow_; | |
| 103 | |
| 104 // Delegate that provides the animation target and is notified of the | |
| 105 // animation state. | |
| 106 Delegate* delegate_; | |
| 107 | |
| 108 // The current animation direction. | |
| 109 Direction direction_; | |
| 110 | |
| 111 // Indicates if the current animation has been cancelled. True while the | |
| 112 // cancel animation is in progress. | |
| 113 bool overscroll_cancelled_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimation); | |
| 116 }; | |
| 117 | |
| 118 } // namespace content | |
| 119 | |
| 120 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ | |
| OLD | NEW |