Index: content/browser/web_contents/aura/overscroll_window_animation.cc |
diff --git a/content/browser/web_contents/aura/overscroll_window_animation.cc b/content/browser/web_contents/aura/overscroll_window_animation.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1646a4d53bde3f694ccb5eee4d4aad13d84acc3b |
--- /dev/null |
+++ b/content/browser/web_contents/aura/overscroll_window_animation.cc |
@@ -0,0 +1,117 @@ |
+// Copyright (c) 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. |
+ |
+#include "content/browser/web_contents/aura/overscroll_window_animation.h" |
+ |
+#include "ui/compositor/layer_animation_observer.h" |
+#include "ui/compositor/scoped_layer_animation_settings.h" |
+ |
+namespace content { |
+ |
+OverscrollWindowAnimation::OverscrollWindowAnimation( |
+ Delegate* delegate) |
+ : delegate_(delegate), |
+ direction_(NONE), |
+ overscroll_cancelled_(false), |
+ animation_completed_(true) { |
mfomitchev
2015/02/19 19:04:59
It's a bit weird initialized completed to true giv
Nina
2015/02/27 19:32:51
Done.
|
+} |
+ |
+OverscrollWindowAnimation::~OverscrollWindowAnimation() { |
+ LOG(ERROR) << "OWA destructor"; |
+} |
+ |
+void OverscrollWindowAnimation::CancelOverscroll() { |
+ LOG(ERROR) << "Cancelling animation"; |
+ overscroll_cancelled_ = true; |
+ ui::ScopedLayerAnimationSettings settings(delegate_->GetAnimator()); |
+ settings.SetPreemptionStrategy( |
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
+ settings.SetTweenType(gfx::Tween::EASE_OUT); |
+ settings.AddObserver(this); |
+ delegate_->SetTransform(gfx::Transform()); |
+ direction_ = NONE; |
+} |
+ |
+void OverscrollWindowAnimation::AbortAllAnimations() { |
mfomitchev
2015/02/19 19:04:59
This method is called only once. Consider getting
Nina
2015/02/27 19:32:51
Done.
|
+ delegate_->GetAnimator()->AbortAllAnimations(); |
+} |
+ |
+bool OverscrollWindowAnimation::IsSlideInProgress() const { |
mfomitchev
2015/02/19 19:04:59
Lets call this something else. Perhaps IsAnimation
Nina
2015/02/27 19:32:51
Done.
|
+ return !animation_completed_; |
+} |
+ |
+void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() { |
+ animation_completed_ = true; |
+ delegate_->OnAnimationCompleted(); |
+} |
+ |
+gfx::Vector2dF OverscrollWindowAnimation::GetTranslationForOverscroll( |
+ float delta_x) { |
+ DCHECK(direction_ != NONE); |
+ const float bounds_width = delegate_->GetContentsBounds().width(); |
+ if (direction_ == FORWARD) |
+ return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0); |
+ else |
+ return gfx::Vector2dF(std::min(bounds_width, delta_x), 0); |
+} |
+ |
+gfx::Rect OverscrollWindowAnimation::GetVisibleBounds() const { |
+ return delegate_->GetContentsBounds(); |
+} |
+ |
+bool OverscrollWindowAnimation::OnOverscrollUpdate(float delta_x, |
+ float delta_y) { |
+ if (direction_ == NONE) |
+ return false; |
+ LOG(ERROR) << "OWA: OnOverscrollUpdate"; |
+ gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x); |
+ gfx::Transform transform; |
+ transform.Translate(translate.x(), translate.y()); |
+ delegate_->SetTransform(transform); |
+ return true; |
+} |
+ |
+void OverscrollWindowAnimation::OnOverscrollModeChange( |
+ OverscrollMode old_mode, |
+ OverscrollMode new_mode) { |
+ LOG(ERROR) << "OWA: OnOverscrollModeChange"; |
+ AbortAllAnimations(); |
mfomitchev
2015/02/19 19:04:59
Seems like an overkill to call this every time. We
Nina
2015/02/27 19:32:51
Done.
|
+ direction_ = delegate_->StartNavigation(new_mode); |
mfomitchev
2015/02/19 19:04:59
StartNavigation(OVERSCROLL_NONE) sounds a bit misl
Nina
2015/02/27 19:32:51
This should no longer be the case after changing t
|
+ |
+ if (direction_ == NONE) { |
+ // The user cancelled the in progress overscroll gesture. |
+ // TODO(nsatragno): in this case, show a feedback animation. |
+ if (IsSlideInProgress()) |
+ CancelOverscroll(); |
+ return; |
+ } |
+ StartAnimating(); |
+} |
+ |
+void OverscrollWindowAnimation::StartAnimating() { |
mfomitchev
2015/02/19 19:04:59
I don't see much reason for the existence of this
Nina
2015/02/27 19:32:51
Removed.
|
+ LOG(ERROR) << "OWA: StartAnimating"; |
+ overscroll_cancelled_ = false; |
+ animation_completed_ = false; |
+} |
+ |
+void OverscrollWindowAnimation::OnOverscrollComplete( |
+ OverscrollMode overscroll_mode) { |
+ LOG(ERROR) << "OWA: OnOverscrollComplete"; |
+ delegate_->OnAnimationCompleting(); |
+ ui::ScopedLayerAnimationSettings settings(delegate_->GetAnimator()); |
+ settings.SetPreemptionStrategy( |
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
+ settings.SetTweenType(gfx::Tween::EASE_OUT); |
+ settings.AddObserver(this); |
+ gfx::Transform transform; |
+ int content_width = delegate_->GetContentsBounds().width(); |
+ float translate_x = static_cast<float>( |
+ direction_ == FORWARD ? -content_width |
+ : content_width); |
+ transform.Translate(translate_x, 0); |
+ delegate_->SetTransform(transform); |
+ direction_ = NONE; |
+} |
+ |
+} // namespace content |