Index: content/browser/web_contents/aura/overscroll_window_animation.h |
diff --git a/content/browser/web_contents/aura/overscroll_window_animation.h b/content/browser/web_contents/aura/overscroll_window_animation.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..791437baa35bef3b500a0386bd644adfd9d6fb1f |
--- /dev/null |
+++ b/content/browser/web_contents/aura/overscroll_window_animation.h |
@@ -0,0 +1,121 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |
+#define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |
+ |
+#include "base/gtest_prod_util.h" |
+#include "content/browser/renderer_host/overscroll_controller_delegate.h" |
+#include "content/common/content_export.h" |
+#include "ui/compositor/layer_animation_observer.h" |
+ |
+namespace aura { |
+class Window; |
+} |
+ |
+namespace ui { |
+class Layer; |
+class LayerAnimator; |
+} |
+ |
+namespace content { |
+ |
+class ShadowLayerDelegate; |
+class WebContentsImpl; |
+ |
+// Manages the animation of a window sliding on top or behind another one. The |
+// main window, which is the one displayed before the animation starts, is not |
+// owned by OverscrollWindowAnimation, while the slide window, created at the |
+// start of the animation, is owned by us for its duration. |
+class CONTENT_EXPORT OverscrollWindowAnimation |
+ : public OverscrollControllerDelegate, |
+ ui::ImplicitAnimationObserver { |
+ public: |
+ // The direction of this animation. SLIDE_FRONT indicates that the main window |
+ // stays still while the slide window moves on top of it, entering in from the |
+ // right. SLIDE_BACK means that the main window is animated to the right, |
+ // revealing the slide window in the back, which stays still. SLIDE_NONE |
+ // means we are not animating yet. Left and right are reversed for RTL |
+ // languages, but stack order remains unchanged. |
+ enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE }; |
+ |
+ // Delegate class that interfaces with the window animation. |
+ class CONTENT_EXPORT Delegate { |
+ public: |
+ virtual ~Delegate() {} |
+ |
+ // Create a slide window with the given |bounds| relative to its parent. |
+ virtual scoped_ptr<aura::Window> CreateFrontWindow( |
+ const gfx::Rect& bounds) = 0; |
+ virtual scoped_ptr<aura::Window> CreateBackWindow( |
+ const gfx::Rect& bounds) = 0; |
+ |
+ // Returns the main window that participates in the animation. The delegate |
+ // does not own this window. |
+ virtual aura::Window* GetMainWindow() const = 0; |
+ |
+ // Called when we know the animation is going to complete successfully, but |
+ // before it actually completes. |
+ virtual void OnOverscrollCompleting() = 0; |
+ |
+ // Called when the animation has been completed. The slide window is |
+ // transferred to the delegate. |
+ virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0; |
+ |
+ // Called when the overscroll gesture has been cancelled, after the cancel |
+ // animation finishes. |
+ virtual void OnOverscrollCancelled() = 0; |
+ }; |
+ |
+ explicit OverscrollWindowAnimation(Delegate* delegate); |
+ |
+ ~OverscrollWindowAnimation() override; |
+ |
+ // Returns true if we are currently animating. |
+ bool is_active() const { return !!slide_window_; } |
+ |
+ // OverscrollControllerDelegate: |
+ gfx::Rect GetVisibleBounds() const override; |
+ bool OnOverscrollUpdate(float delta_x, float delta_y) override; |
+ void OnOverscrollComplete(OverscrollMode overscroll_mode) override; |
+ void OnOverscrollModeChange(OverscrollMode old_mode, |
+ OverscrollMode new_mode) override; |
+ |
+ private: |
+ // Cancels the slide, animating the front window to its original position. |
+ void CancelSlide(); |
+ |
+ // Returns a translation on the x axis for the given overscroll. |
+ float GetTranslationForOverscroll(float delta_x); |
+ |
+ // Returns the layer that is animated for the animation. The caller does not |
+ // own it. |
+ ui::Layer* GetFrontLayer() const; |
+ |
+ // ui::ImplicitAnimationObserver: |
+ void OnImplicitAnimationsCompleted() override; |
+ |
+ // We own the window created for the animation. |
+ scoped_ptr<aura::Window> slide_window_; |
+ |
+ // Shadow shown under the animated layer. |
+ scoped_ptr<ShadowLayerDelegate> shadow_; |
+ |
+ // Delegate that provides the animation target and is notified of the |
+ // animation state. |
+ Delegate* delegate_; |
+ |
+ // The current animation direction. |
+ Direction direction_; |
+ |
+ // Indicates if the current animation has been cancelled. True while the |
+ // cancel animation is in progress. |
+ bool overscroll_cancelled_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimation); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |