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