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 "content/browser/renderer_host/overscroll_controller_delegate.h" |
| 9 #include "content/common/content_export.h" |
| 10 #include "ui/compositor/layer_animation_observer.h" |
| 11 |
| 12 namespace aura { |
| 13 class Window; |
| 14 } |
| 15 |
| 16 namespace ui { |
| 17 class Layer; |
| 18 class LayerAnimator; |
| 19 } |
| 20 |
| 21 namespace content { |
| 22 |
| 23 class ShadowLayerDelegate; |
| 24 class WebContentsImpl; |
| 25 |
| 26 // Manages the animations during an overscroll navigation by handling overscroll |
| 27 // events. |
| 28 class CONTENT_EXPORT OverscrollWindowAnimation |
| 29 : public OverscrollControllerDelegate, |
| 30 ui::ImplicitAnimationObserver { |
| 31 public: |
| 32 enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE }; |
| 33 |
| 34 // Delegate class that interfaces with the window animation, responsible for |
| 35 // navigation. |
| 36 class Delegate { |
| 37 public: |
| 38 virtual ~Delegate() {} |
| 39 |
| 40 // The following two functions create a slide window and transfer back its |
| 41 // ownership. |
| 42 virtual scoped_ptr<aura::Window> CreateFrontWindow() = 0; |
| 43 virtual scoped_ptr<aura::Window> CreateBackWindow() = 0; |
| 44 |
| 45 // Returns the live window that participates in the overscroll gesture. |
| 46 virtual aura::Window* GetTargetWindow() const = 0; |
| 47 |
| 48 // Called when we know the animation is going to complete successfully. |
| 49 virtual void OnOverscrollCompleting() = 0; |
| 50 |
| 51 // Called when the animation has been completed. |
| 52 virtual void OnOverscrollCompleted( |
| 53 scoped_ptr<aura::Window> window) = 0; |
| 54 |
| 55 // Called when the overscroll gesture has been aborted. |
| 56 virtual void OnOverscrollAborted() = 0; |
| 57 }; |
| 58 |
| 59 explicit OverscrollWindowAnimation(Delegate* delegate); |
| 60 |
| 61 ~OverscrollWindowAnimation() override; |
| 62 |
| 63 // Returns true if we are currently handling a slide animation. |
| 64 bool is_active() const { return !!window_; } |
| 65 |
| 66 // Overridden from OverscrollControllerDelegate: |
| 67 gfx::Rect GetVisibleBounds() const override; |
| 68 |
| 69 bool OnOverscrollUpdate(float delta_x, float delta_y) override; |
| 70 |
| 71 void OnOverscrollComplete(OverscrollMode overscroll_mode) override; |
| 72 |
| 73 void OnOverscrollModeChange(OverscrollMode old_mode, |
| 74 OverscrollMode new_mode) override; |
| 75 |
| 76 private: |
| 77 // Starts the overscroll cancelled animation. |
| 78 void CancelOverscroll(); |
| 79 |
| 80 // Moves the animated window according to the given scroll deltas. Returns |
| 81 // true if the update moved the window. |
| 82 bool UpdateForScroll(float delta_x); |
| 83 |
| 84 // Returns a translation on the x axis for the given overscroll. |
| 85 float GetTranslationForOverscroll(float delta_x); |
| 86 |
| 87 // Returns the layer that is animated for the overscroll gesture. |
| 88 ui::Layer* GetFrontLayer() const; |
| 89 |
| 90 // ui::ImplicitAnimationObserver: |
| 91 void OnImplicitAnimationsCompleted() override; |
| 92 |
| 93 // Owns the new window created on the overscroll gesture. |
| 94 scoped_ptr<aura::Window> window_; |
| 95 |
| 96 // Shadow shown under the animated layer. |
| 97 scoped_ptr<ShadowLayerDelegate> shadow_; |
| 98 |
| 99 // Delegate that provides the animation target and handles navigation. |
| 100 Delegate* delegate_; |
| 101 |
| 102 // The current overscroll direction. |
| 103 Direction direction_; |
| 104 |
| 105 // Indicates if the current overscroll gesture has been cancelled. |
| 106 bool overscroll_cancelled_; |
| 107 }; |
| 108 |
| 109 } // namespace content |
| 110 |
| 111 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |
OLD | NEW |