Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/web_contents/aura/overscroll_window_animation.h" | |
| 6 | |
| 7 #include "base/i18n/rtl.h" | |
| 8 #include "content/browser/web_contents/aura/overscroll_layer_wrapper.h" | |
| 9 #include "ui/compositor/layer_animation_observer.h" | |
| 10 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 OverscrollWindowAnimation::Direction GetDirectionForMode(OverscrollMode mode) { | |
| 17 LOG(ERROR) << "Getting navigation direction"; | |
| 18 if (mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST)) | |
| 19 return OverscrollWindowAnimation::FORWARD; | |
| 20 if (mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST)) | |
| 21 return OverscrollWindowAnimation::BACKWARD; | |
| 22 return OverscrollWindowAnimation::NONE; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 OverscrollWindowAnimation::OverscrollWindowAnimation() | |
| 28 : delegate_(nullptr), | |
| 29 direction_(NONE), | |
| 30 animation_active_(false) { | |
| 31 } | |
| 32 | |
| 33 OverscrollWindowAnimation::~OverscrollWindowAnimation() { | |
| 34 LOG(ERROR) << "OWA destructor"; | |
| 35 } | |
| 36 | |
| 37 void OverscrollWindowAnimation::CancelOverscroll() { | |
| 38 LOG(ERROR) << "OWA: Cancelling overscroll"; | |
| 39 ui::ScopedLayerAnimationSettings settings(layer_wrapper_->GetAnimator()); | |
| 40 settings.SetPreemptionStrategy( | |
| 41 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 42 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
| 43 settings.AddObserver(this); | |
| 44 layer_wrapper_->SetTransform(gfx::Transform()); | |
| 45 direction_ = NONE; | |
| 46 } | |
| 47 | |
| 48 void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() { | |
| 49 LOG(ERROR) << "OWA: On implicit animations completed"; | |
| 50 animation_active_ = false; | |
| 51 delegate_->OnOverscrollCompleted(); | |
| 52 layer_wrapper_.reset(); | |
| 53 } | |
| 54 | |
| 55 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.
| |
| 56 float delta_x) { | |
| 57 DCHECK(direction_ != NONE); | |
| 58 const float bounds_width = layer_wrapper_->GetBounds().width(); | |
| 59 if (direction_ == FORWARD) | |
| 60 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
| |
| 61 else | |
| 62 return gfx::Vector2dF(std::min(bounds_width, delta_x), 0); | |
| 63 } | |
| 64 | |
| 65 gfx::Rect OverscrollWindowAnimation::GetVisibleBounds() const { | |
| 66 return layer_wrapper_->GetBounds(); | |
| 67 } | |
| 68 | |
| 69 bool OverscrollWindowAnimation::OnOverscrollUpdate(float delta_x, | |
| 70 float delta_y) { | |
| 71 if (direction_ == NONE) | |
| 72 return false; | |
| 73 LOG(ERROR) << "OWA: OnOverscrollUpdate"; | |
| 74 gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x); | |
| 75 gfx::Transform transform; | |
| 76 transform.Translate(translate.x(), translate.y()); | |
| 77 layer_wrapper_->SetTransform(transform); | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 void OverscrollWindowAnimation::OnOverscrollModeChange( | |
| 82 OverscrollMode old_mode, | |
| 83 OverscrollMode new_mode) { | |
| 84 LOG(ERROR) << "OWA: OnOverscrollModeChange for mode " << new_mode; | |
| 85 direction_ = GetDirectionForMode(new_mode); | |
| 86 | |
| 87 if (direction_ == NONE) { | |
| 88 // The user cancelled the in progress overscroll gesture. | |
| 89 // TODO(nsatragno): in this case, show a feedback animation. | |
| 90 LOG(ERROR) << "Direction: NONE"; | |
| 91 if (is_animation_in_progress()) | |
| 92 CancelOverscroll(); | |
| 93 return; | |
| 94 } | |
| 95 LOG(ERROR) << "Preparing layer wrapper"; | |
| 96 if (layer_wrapper_) { | |
| 97 LOG(ERROR) << "Aborting animations on layer wrapper"; | |
| 98 layer_wrapper_->GetAnimator()->AbortAllAnimations(); | |
| 99 } | |
| 100 animation_active_ = true; | |
| 101 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
| |
| 102 : delegate_->CreateBackLayer(); | |
| 103 if (!layer_wrapper_) { | |
| 104 LOG(ERROR) << "Cannot navigate, setting direction to NONE"; | |
| 105 animation_active_ = false; | |
| 106 direction_ = NONE; | |
| 107 } | |
| 108 LOG(ERROR) << "Done with OnOverscrollModeChange"; | |
| 109 } | |
| 110 | |
| 111 void OverscrollWindowAnimation::OnOverscrollComplete( | |
| 112 OverscrollMode overscroll_mode) { | |
| 113 LOG(ERROR) << "OWA: OnOverscrollComplete"; | |
| 114 delegate_->OnOverscrollCompleting(); | |
| 115 ui::ScopedLayerAnimationSettings settings(layer_wrapper_->GetAnimator()); | |
| 116 settings.SetPreemptionStrategy( | |
| 117 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 118 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
| 119 settings.AddObserver(this); | |
| 120 gfx::Transform transform; | |
| 121 int content_width = layer_wrapper_->GetBounds().width(); | |
| 122 float translate_x = static_cast<float>( | |
| 123 direction_ == FORWARD ? -content_width | |
|
mfomitchev
2015/02/27 21:33:42
RTL?
| |
| 124 : content_width); | |
| 125 transform.Translate(translate_x, 0); | |
| 126 layer_wrapper_->SetTransform(transform); | |
| 127 direction_ = NONE; | |
| 128 } | |
| 129 | |
| 130 } // namespace content | |
| OLD | NEW |