summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authornsatragno <nsatragno@chromium.org>2015-04-10 16:59:22 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-11 00:00:00 +0000
commitb0da040a2f55ed37df434814fd9c4a5f35b2c9a3 (patch)
treed16c78ad6a41ee6e1db787796b8a4479f4b65fed /content
parentf0483511ab1fe131c9af2a9268ada63631e1d9fe (diff)
downloadchromium_src-b0da040a2f55ed37df434814fd9c4a5f35b2c9a3.zip
chromium_src-b0da040a2f55ed37df434814fd9c4a5f35b2c9a3.tar.gz
chromium_src-b0da040a2f55ed37df434814fd9c4a5f35b2c9a3.tar.bz2
Implement parallax scrolling on Gesture Navigation
This patch adds eye candy to the gesture navigation by moving two layers at the same time as opposed to only one. The back layer moves at half the speed as the front layer. BUG=420125 TEST=manual Review URL: https://codereview.chromium.org/1044533002 Cr-Commit-Position: refs/heads/master@{#324718}
Diffstat (limited to 'content')
-rw-r--r--content/browser/web_contents/aura/overscroll_window_animation.cc51
-rw-r--r--content/browser/web_contents/aura/overscroll_window_animation.h29
2 files changed, 55 insertions, 25 deletions
diff --git a/content/browser/web_contents/aura/overscroll_window_animation.cc b/content/browser/web_contents/aura/overscroll_window_animation.cc
index 18bfc9c..ef9e79d 100644
--- a/content/browser/web_contents/aura/overscroll_window_animation.cc
+++ b/content/browser/web_contents/aura/overscroll_window_animation.cc
@@ -38,14 +38,9 @@ OverscrollWindowAnimation::~OverscrollWindowAnimation() {
}
void OverscrollWindowAnimation::CancelSlide() {
- ui::Layer* layer = GetFrontLayer();
- ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
- settings.SetPreemptionStrategy(
- ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
- settings.SetTweenType(gfx::Tween::EASE_OUT);
- settings.AddObserver(this);
- layer->SetTransform(gfx::Transform());
overscroll_cancelled_ = true;
+ AnimateTranslation(GetBackLayer(), 0, false);
+ AnimateTranslation(GetFrontLayer(), 0, true);
}
float OverscrollWindowAnimation::GetTranslationForOverscroll(float delta_x) {
@@ -65,9 +60,13 @@ bool OverscrollWindowAnimation::OnOverscrollUpdate(float delta_x,
float delta_y) {
if (direction_ == SLIDE_NONE)
return false;
- gfx::Transform transform;
- transform.Translate(GetTranslationForOverscroll(delta_x), 0);
- GetFrontLayer()->SetTransform(transform);
+ gfx::Transform front_transform;
+ gfx::Transform back_transform;
+ float translate_x = GetTranslationForOverscroll(delta_x);
+ front_transform.Translate(translate_x, 0);
+ back_transform.Translate(translate_x / 2, 0);
+ GetFrontLayer()->SetTransform(front_transform);
+ GetBackLayer()->SetTransform(back_transform);
return true;
}
@@ -92,15 +91,21 @@ void OverscrollWindowAnimation::OnOverscrollModeChange(
CancelSlide();
return;
}
- if (is_active())
- GetFrontLayer()->GetAnimator()->StopAnimating();
-
+ if (is_active()) {
+ slide_window_->layer()->GetAnimator()->StopAnimating();
+ delegate_->GetMainWindow()->layer()->GetAnimator()->StopAnimating();
+ }
gfx::Rect slide_window_bounds = gfx::Rect(GetVisibleBounds().size());
if (new_direction == SLIDE_FRONT) {
slide_window_bounds.Offset(base::i18n::IsRTL()
? -slide_window_bounds.width()
: slide_window_bounds.width(),
0);
+ } else {
+ slide_window_bounds.Offset(base::i18n::IsRTL()
+ ? slide_window_bounds.width() / 2
+ : -slide_window_bounds.width() / 2,
+ 0);
}
slide_window_ = new_direction == SLIDE_FRONT
? delegate_->CreateFrontWindow(slide_window_bounds)
@@ -128,14 +133,21 @@ void OverscrollWindowAnimation::OnOverscrollComplete(
} else {
translate_x = -content_width;
}
- ui::Layer* layer = GetFrontLayer();
+ AnimateTranslation(GetBackLayer(), translate_x / 2, false);
+ AnimateTranslation(GetFrontLayer(), translate_x, true);
+}
+
+void OverscrollWindowAnimation::AnimateTranslation(ui::Layer* layer,
+ float translate_x,
+ bool listen_for_completion) {
gfx::Transform transform;
transform.Translate(translate_x, 0);
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings.SetTweenType(gfx::Tween::EASE_OUT);
- settings.AddObserver(this);
+ if (listen_for_completion)
+ settings.AddObserver(this);
layer->SetTransform(transform);
}
@@ -148,4 +160,13 @@ ui::Layer* OverscrollWindowAnimation::GetFrontLayer() const {
return delegate_->GetMainWindow()->layer();
}
+ui::Layer* OverscrollWindowAnimation::GetBackLayer() const {
+ DCHECK(direction_ != SLIDE_NONE);
+ if (direction_ == SLIDE_BACK) {
+ DCHECK(slide_window_);
+ return slide_window_->layer();
+ }
+ return delegate_->GetMainWindow()->layer();
+}
+
} // namespace content
diff --git a/content/browser/web_contents/aura/overscroll_window_animation.h b/content/browser/web_contents/aura/overscroll_window_animation.h
index 791437b..876368d 100644
--- a/content/browser/web_contents/aura/overscroll_window_animation.h
+++ b/content/browser/web_contents/aura/overscroll_window_animation.h
@@ -32,11 +32,12 @@ 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
+ // The direction of this animation. SLIDE_FRONT indicates that the slide
+ // window moves on top of the main window, entering the screen from the right.
+ // SLIDE_BACK means that the main window is animated to the right, revealing
+ // the slide window in the back. SLIDE_NONE means we are not animating yet.
+ // Both windows are animated at the same time but at different speeds,
+ // creating a parallax scrolling effect. Left and right are reversed for RTL
// languages, but stack order remains unchanged.
enum Direction { SLIDE_FRONT, SLIDE_BACK, SLIDE_NONE };
@@ -83,15 +84,23 @@ class CONTENT_EXPORT OverscrollWindowAnimation
OverscrollMode new_mode) override;
private:
- // Cancels the slide, animating the front window to its original position.
+ // Cancels the slide, animating the front and back window to their original
+ // positions.
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.
+ // Animates a translation of the given |layer|. If |listen_for_completion| is
+ // true, adds |this| as observer of the animation.
+ void AnimateTranslation(ui::Layer* layer,
+ float translate_x,
+ bool listen_for_completion);
+
+ // Return the front/back layer that is involved in the animation. The caller
+ // does not own it.
ui::Layer* GetFrontLayer() const;
+ ui::Layer* GetBackLayer() const;
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override;
@@ -109,8 +118,8 @@ class CONTENT_EXPORT OverscrollWindowAnimation
// The current animation direction.
Direction direction_;
- // Indicates if the current animation has been cancelled. True while the
- // cancel animation is in progress.
+ // Indicates if the current slide has been cancelled. True while the cancel
+ // animation is in progress.
bool overscroll_cancelled_;
DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimation);