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