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

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: New design with window|wrapper in OWA 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..b3657a684f8b32f37c0843f06b3f7192312ebefc
--- /dev/null
+++ b/content/browser/web_contents/aura/overscroll_window_animation.cc
@@ -0,0 +1,158 @@
+// 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 "content/browser/web_contents/aura/shadow_layer_delegate.h"
+#include "ui/aura/window.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()
+ : layer_wrapper_(nullptr),
+ shadow_(nullptr),
+ live_window_(nullptr),
mfomitchev 2015/03/05 23:37:06 Don't allow this or add null checks elsewhere (or
Nina 2015/03/09 15:54:52 Done.
+ delegate_(nullptr),
mfomitchev 2015/03/05 23:37:06 Same thing here
Nina 2015/03/09 15:54:52 Done.
+ direction_(NONE) {
+}
+
+OverscrollWindowAnimation::~OverscrollWindowAnimation() {
+ LOG(ERROR) << "OWA destructor";
+}
+
+void OverscrollWindowAnimation::CancelOverscroll() {
+ LOG(ERROR) << "OWA: Cancelling overscroll";
+ ui::Layer* layer = GetAnimatedLayer();
+ 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());
+ direction_ = NONE;
+}
+
+float OverscrollWindowAnimation::GetTranslationForOverscroll(
+ float delta_x) {
+ LOG(ERROR) << "Translation for delta_x: " << delta_x;
+ DCHECK(direction_ != NONE);
+ const float bounds_width = layer_wrapper_->GetBounds().width();
+ if (direction_ == FORWARD)
+ return std::max(-bounds_width, delta_x);
+ else
+ return std::min(bounds_width, delta_x);
+}
+
+gfx::Rect OverscrollWindowAnimation::GetVisibleBounds() const {
+ return live_window_->bounds();
+}
+
+bool OverscrollWindowAnimation::OnOverscrollUpdate(float delta_x,
+ float delta_y) {
+ if (direction_ == NONE)
+ return false;
+ LOG(ERROR) << "OWA: OnOverscrollUpdate";
+ gfx::Transform transform;
+ transform.Translate(GetTranslationForOverscroll(delta_x), 0);
+ GetAnimatedLayer()->SetTransform(transform);
+ return true;
+}
+
+void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() {
mfomitchev 2015/03/05 23:37:06 Failure vs Success
Nina 2015/03/09 15:54:52 Done.
+ LOG(ERROR) << "OnImplicitAnimationsCompleted";
+ LOG(ERROR) << "LAYER_WRAPPER_: " << layer_wrapper_;
+ if (layer_wrapper_)
+ delegate_->OnOverscrollCompleted(layer_wrapper_.Pass());
+}
+
+void OverscrollWindowAnimation::OnOverscrollModeChange(
+ OverscrollMode old_mode,
+ OverscrollMode new_mode) {
+ LOG(ERROR) << "OWA: OnOverscrollModeChange for mode " << new_mode;
+ Direction new_direction = GetDirectionForMode(new_mode);
+
+ if (new_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_active())
+ CancelOverscroll();
+ return;
+ }
+ LOG(ERROR) << "Preparing layer wrapper";
+ if (layer_wrapper_) {
+ LOG(ERROR) << "ALERT: MODE CHANGE WITH LAYER WRAPPER ACTIVE! "
+ << "Aborting animations.";
+ }
+ layer_wrapper_ = new_direction == FORWARD ? delegate_->CreateFrontLayer()
+ : delegate_->CreateBackLayer();
+ if (!layer_wrapper_) {
+ LOG(ERROR) << "Cannot navigate, setting direction to NONE";
+ direction_ = NONE;
+ return;
+ }
+ gfx::Rect bounds = gfx::Rect(live_window_->bounds().size());
+ if (new_direction == OverscrollWindowAnimation::FORWARD)
+ bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0);
+ // TODO maybe we want to set the window bounds here, too.
+ layer_wrapper_->layer()->SetBounds(bounds);
+ LOG(ERROR) << "Setting shadow delegate.";
+ direction_ = new_direction;
+ shadow_.reset(new ShadowLayerDelegate(GetAnimatedLayer()));
+}
+
+void OverscrollWindowAnimation::OnOverscrollComplete(
+ OverscrollMode overscroll_mode) {
+ LOG(ERROR) << "OWA: OnOverscrollComplete";
+ // TODO we might want to also check for direction_ == NONE.
+ // I think there is a case in which is_active == false && direction_ == NONE,
+ // but I can't find it.
+ if (!is_active())
+ return;
+ delegate_->OnOverscrollCompleting();
+ int content_width = layer_wrapper_->GetBounds().width();
+ float translate_x;
+ if ((base::i18n::IsRTL() && direction_ == FORWARD) ||
+ (!base::i18n::IsRTL() && direction_ == BACKWARD)) {
+ translate_x = content_width;
+ } else {
+ translate_x = -content_width;
+ }
+ // TODO refactor into one function.
+ ui::Layer* layer = GetAnimatedLayer();
+ 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);
+ layer->SetTransform(transform);
+ direction_ = NONE;
+}
+
+ui::Layer* OverscrollWindowAnimation::GetAnimatedLayer() {
mfomitchev 2015/03/06 01:36:43 Perhaps call this GetFrontLayer() - this way we wo
Nina 2015/03/09 15:54:52 Done.
+ if (direction_ == FORWARD)
+ return layer_wrapper_->layer();
+ return live_window_->layer();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698