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..79a37c1a0dd6d9c9b55443b074e38709111cc9de |
| --- /dev/null |
| +++ b/content/browser/web_contents/aura/overscroll_window_animation.h |
| @@ -0,0 +1,123 @@ |
| +// 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 behind while the slide window one moves in from the right. SLIDE_BACK |
|
mfomitchev
2015/03/31 21:04:07
stays still, while the slide window moves on top o
Nina
2015/04/01 18:10:01
Done.
|
| + // means that the main window is animated to the right, revealing the slide |
| + // window on the back. SLIDE_NONE means we are not animating yet. Left and |
|
mfomitchev
2015/03/31 21:04:07
in the back, which stays still.
Nina
2015/04/01 18:10:01
Done.
|
| + // right are reversed for users of RTL languages, but stack order remains |
|
mfomitchev
2015/03/31 21:04:08
Directions are reversed for RTL languages,..
Nina
2015/04/01 18:10:01
Done.
|
| + // unchanged. |
| + enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE }; |
| + |
| + // Delegate class that interfaces with the window animation. |
| + class Delegate { |
| + public: |
| + virtual ~Delegate() {} |
| + |
| + // The following two functions create a slide window and transfer back its |
| + // ownership. |
| + 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. |
| + 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's |
| + // ownership is transferred. |
|
mfomitchev
2015/03/31 21:04:08
"The slide window's ownership is transferred" -> "
Nina
2015/04/01 18:10:01
Done.
|
| + virtual void OnOverscrollCompleted(scoped_ptr<aura::Window> window) = 0; |
| + |
| + // Called when the overscroll gesture has been aborted, after the abort |
| + // animation finishes. |
| + virtual void OnOverscrollAborted() = 0; |
| + }; |
| + |
| + explicit OverscrollWindowAnimation(Delegate* delegate); |
| + |
| + ~OverscrollWindowAnimation() override; |
| + |
| + // Returns true if we are currently animating. |
| + bool is_active() const { return !!slide_window_; } |
| + |
| + // Overridden from 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, |
|
mfomitchev
2015/03/31 21:04:07
Leave no space between overridden methods
Nina
2015/04/01 18:10:01
Done.
|
| + 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; |
| + |
| + // 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. |
|
mfomitchev
2015/03/31 21:04:07
Pick either "aborted" or "cancelled and stick to t
Nina
2015/04/01 18:10:01
s/abort/cancel for the overscroll related function
|
| + bool overscroll_cancelled_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_WINDOW_ANIMATION_H_ |