OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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/memory/scoped_ptr.h" |
| 9 #include "content/browser/renderer_host/overscroll_controller.h" |
| 10 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
| 11 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/aura_extra/image_window_delegate.h" |
| 14 #include "ui/compositor/layer_animation_observer.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class ShadowLayerDelegate; |
| 19 class WebContentsImpl; |
| 20 |
| 21 // Manages the animations during an overscroll navigation. |
| 22 // TODO write doc and nice comment explaining how overscroll navigation works. |
| 23 class OverscrollWindowAnimation : ui::ImplicitAnimationObserver, |
| 24 OverscrollControllerDelegate { |
| 25 public: |
| 26 OverscrollWindowAnimation(WebContentsImpl* web_contents, |
| 27 OverscrollNavigationOverlay* ono, |
| 28 aura::Window* web_contents_window); |
| 29 |
| 30 ~OverscrollWindowAnimation() override; |
| 31 |
| 32 // Cancels the current animation. |
| 33 void CancelAnimation(); |
| 34 |
| 35 // Moves the animated window according to the given scroll deltas. Returns |
| 36 // true if the update moved the window. |
| 37 bool UpdateForScroll(float delta_x); |
| 38 |
| 39 // Aborts all current running animations. |
| 40 void AbortAllAnimations(); |
| 41 |
| 42 // Dismisses the overlay. |
| 43 void DismissOverlay(); |
| 44 |
| 45 // Returns the overscroll window delegate as an ImageWindowDelegate. |
| 46 aura_extra::ImageWindowDelegate* delegate() { |
| 47 return static_cast<aura_extra::ImageWindowDelegate*>( |
| 48 overscroll_window_->delegate()); |
| 49 } |
| 50 |
| 51 // Overridden from ui::ImplicitAnimationObserver: |
| 52 void OnImplicitAnimationsCompleted() override; |
| 53 |
| 54 // Overridn from OverscrollControllerDelegate: |
| 55 gfx::Rect GetVisibleBounds() const override; |
| 56 |
| 57 bool OnOverscrollUpdate(float delta_x, float delta_y) override; |
| 58 |
| 59 void OnOverscrollComplete(OverscrollMode overscroll_mode) override; |
| 60 |
| 61 void OnOverscrollModeChange(OverscrollMode old_mode, |
| 62 OverscrollMode new_mode) override; |
| 63 |
| 64 private: |
| 65 // Prepares the overscroll window to begin animating. |
| 66 void StartAnimating(); |
| 67 |
| 68 // Adds a new layer on top of the overscroll window. |
| 69 void AddNewLayer(); |
| 70 |
| 71 // Stops the animation, dismissing the overscroll window. |
| 72 void FadeOutOverscrollWindow(); |
| 73 |
| 74 // Returns the bounds for the overscroll current direction and RTL status. |
| 75 gfx::Rect GetStarterBounds() const; |
| 76 |
| 77 // Returns the window that should be animated for the overscroll navigation. |
| 78 aura::Window* GetWindowToAnimateForOverscroll() const; |
| 79 |
| 80 gfx::Vector2dF GetTranslationForOverscroll(float delta_x); |
| 81 |
| 82 // The window shown on top of the live window for the animations. |
| 83 scoped_ptr<aura::Window> overscroll_window_; |
| 84 |
| 85 // Shadow shown under the animated window. |
| 86 scoped_ptr<ShadowLayerDelegate> overscroll_shadow_; |
| 87 |
| 88 // Web contents that this instance refers to. |
| 89 WebContentsImpl* web_contents_; |
| 90 |
| 91 // Reference to the navigation overlay. |
| 92 OverscrollNavigationOverlay* ono_; |
| 93 |
| 94 // The current overscroll direction. |
| 95 OverscrollNavigationOverlay::Direction direction_; |
| 96 |
| 97 // Window that hosts the web contents. |
| 98 aura::Window* web_contents_window_; |
| 99 |
| 100 // Sliding layer used during second stage overscroll navigation. |
| 101 // TODO it is very likely that we don't need to own this layer. |
| 102 scoped_ptr<ui::Layer> slide_layer_; |
| 103 |
| 104 // TODO rename and make the following fields behave better. |
| 105 // Indicates if we should fade out the overlay prior to destroying it. |
| 106 bool fade_out_; |
| 107 |
| 108 // Indicates if the overscroll gesture has been cancelled. |
| 109 bool animation_cancelled_; |
| 110 |
| 111 // Indicates if the overscroll gesture has been completed. |
| 112 bool gesture_completed_; |
| 113 }; |
| 114 |
| 115 } // namespace content |
| 116 |
| 117 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |
OLD | NEW |