Chromium Code Reviews| 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..93be76cbe12e9a096549cfd792781b6f1b5532fd |
| --- /dev/null |
| +++ b/content/browser/web_contents/aura/overscroll_window_animation.h |
| @@ -0,0 +1,119 @@ |
| +// 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() {} |
| + |
| + // The following two functions create a slide window. |
|
sadrul
2015/04/07 17:10:08
This comment isn't necessary.
Nina
2015/04/07 19:08:56
Removed.
|
| + virtual scoped_ptr<aura::Window> CreateFrontWindow() = 0; |
| + virtual scoped_ptr<aura::Window> CreateBackWindow() = 0; |
| + |
| + // Returns the main window that participates in the animation. We do not own |
| + // this window. |
|
sadrul
2015/04/07 17:10:08
Not clear what 'We' here means. Either 'The delega
Nina
2015/04/07 19:08:56
Good call. s/ to The delegate does not own this wi
|
| + 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. |
| + virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0; |
|
sadrul
2015/04/07 17:10:08
What is |window|?
Nina
2015/04/07 19:08:56
Added "The slide window is transferred to the dele
|
| + |
| + // 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_; } |
| + |
| + // Overridden from OverscrollControllerDelegate: |
|
sadrul
2015/04/07 17:10:08
// OverscrollControllerDelegate:
(like below for
Nina
2015/04/07 19:08:56
Done.
|
| + 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 animation, animating the front window to its original position. |
| + void CancelAnimation(); |
| + |
| + // Moves the animated window according to the given scroll deltas. Returns |
| + // true if the update moved the window. |
| + bool UpdateForScroll(float delta_x); |
| + |
| + // 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. |
| + ui::Layer* GetFrontLayer() const; |
|
sadrul
2015/04/07 17:10:08
Document ownership of the returned layer. If the c
Nina
2015/04/07 19:08:56
The caller does not own it, made it clear in the c
|
| + |
| + // 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_; |
|
sadrul
2015/04/07 17:10:08
DISALLOW_COPY_AND_ASSIGN
Nina
2015/04/07 19:08:56
Done.
|
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |