Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1183)

Unified Diff: content/browser/web_contents/aura/overscroll_window_animation.cc

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Checked comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a71eb525b652f6c2e95dcc06e784f99de43be871
--- /dev/null
+++ b/content/browser/web_contents/aura/overscroll_window_animation.cc
@@ -0,0 +1,130 @@
+// 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 "base/i18n/rtl.h"
+#include "content/browser/web_contents/aura/overscroll_layer_wrapper.h"
+#include "ui/compositor/layer_animation_observer.h"
+#include "ui/compositor/scoped_layer_animation_settings.h"
+
+namespace content {
+
+namespace {
+
+OverscrollWindowAnimation::Direction GetDirectionForMode(OverscrollMode mode) {
+ LOG(ERROR) << "Getting navigation direction";
+ if (mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST))
+ return OverscrollWindowAnimation::FORWARD;
+ if (mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST))
+ return OverscrollWindowAnimation::BACKWARD;
+ return OverscrollWindowAnimation::NONE;
+}
+
+} // namespace
+
+OverscrollWindowAnimation::OverscrollWindowAnimation()
+ : delegate_(nullptr),
+ direction_(NONE),
+ animation_active_(false) {
+}
+
+OverscrollWindowAnimation::~OverscrollWindowAnimation() {
+ LOG(ERROR) << "OWA destructor";
+}
+
+void OverscrollWindowAnimation::CancelOverscroll() {
+ LOG(ERROR) << "OWA: Cancelling overscroll";
+ ui::ScopedLayerAnimationSettings settings(layer_wrapper_->GetAnimator());
+ settings.SetPreemptionStrategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+ settings.SetTweenType(gfx::Tween::EASE_OUT);
+ settings.AddObserver(this);
+ layer_wrapper_->SetTransform(gfx::Transform());
+ direction_ = NONE;
+}
+
+void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() {
+ LOG(ERROR) << "OWA: On implicit animations completed";
+ animation_active_ = false;
+ delegate_->OnOverscrollCompleted();
+ layer_wrapper_.reset();
+}
+
+gfx::Vector2dF OverscrollWindowAnimation::GetTranslationForOverscroll(
mfomitchev 2015/02/27 21:33:42 any reason this doesn't just return an int/float?
Nina 2015/03/09 15:54:52 None, changed the code.
+ float delta_x) {
+ DCHECK(direction_ != NONE);
+ const float bounds_width = layer_wrapper_->GetBounds().width();
+ if (direction_ == FORWARD)
+ return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0);
mfomitchev 2015/02/27 21:33:42 confirm if delta_x is always positive
Nina 2015/03/09 15:54:52 It isn't, and it shouldn't. However I do realize n
+ else
+ return gfx::Vector2dF(std::min(bounds_width, delta_x), 0);
+}
+
+gfx::Rect OverscrollWindowAnimation::GetVisibleBounds() const {
+ return layer_wrapper_->GetBounds();
+}
+
+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());
+ layer_wrapper_->SetTransform(transform);
+ return true;
+}
+
+void OverscrollWindowAnimation::OnOverscrollModeChange(
+ OverscrollMode old_mode,
+ OverscrollMode new_mode) {
+ LOG(ERROR) << "OWA: OnOverscrollModeChange for mode " << new_mode;
+ direction_ = GetDirectionForMode(new_mode);
+
+ if (direction_ == NONE) {
+ // The user cancelled the in progress overscroll gesture.
+ // TODO(nsatragno): in this case, show a feedback animation.
+ LOG(ERROR) << "Direction: NONE";
+ if (is_animation_in_progress())
+ CancelOverscroll();
+ return;
+ }
+ LOG(ERROR) << "Preparing layer wrapper";
+ if (layer_wrapper_) {
+ LOG(ERROR) << "Aborting animations on layer wrapper";
+ layer_wrapper_->GetAnimator()->AbortAllAnimations();
+ }
+ animation_active_ = true;
+ layer_wrapper_ = direction_ == FORWARD ? delegate_->CreateFrontLayer()
mfomitchev 2015/02/27 21:33:42 Leak old layer if you change the direction from Ea
Nina 2015/03/09 15:54:52 After some analysis it seems we don't. However, th
+ : delegate_->CreateBackLayer();
+ if (!layer_wrapper_) {
+ LOG(ERROR) << "Cannot navigate, setting direction to NONE";
+ animation_active_ = false;
+ direction_ = NONE;
+ }
+ LOG(ERROR) << "Done with OnOverscrollModeChange";
+}
+
+void OverscrollWindowAnimation::OnOverscrollComplete(
+ OverscrollMode overscroll_mode) {
+ LOG(ERROR) << "OWA: OnOverscrollComplete";
+ delegate_->OnOverscrollCompleting();
+ ui::ScopedLayerAnimationSettings settings(layer_wrapper_->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 = layer_wrapper_->GetBounds().width();
+ float translate_x = static_cast<float>(
+ direction_ == FORWARD ? -content_width
mfomitchev 2015/02/27 21:33:42 RTL?
+ : content_width);
+ transform.Translate(translate_x, 0);
+ layer_wrapper_->SetTransform(transform);
+ direction_ = NONE;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698