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 "ui/compositor/layer_animation_observer.h" | |
| 8 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 OverscrollWindowAnimation::OverscrollWindowAnimation( | |
| 13 Delegate* delegate) | |
| 14 : delegate_(delegate), | |
| 15 direction_(NONE), | |
| 16 overscroll_cancelled_(false), | |
| 17 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.
| |
| 18 } | |
| 19 | |
| 20 OverscrollWindowAnimation::~OverscrollWindowAnimation() { | |
| 21 LOG(ERROR) << "OWA destructor"; | |
| 22 } | |
| 23 | |
| 24 void OverscrollWindowAnimation::CancelOverscroll() { | |
| 25 LOG(ERROR) << "Cancelling animation"; | |
| 26 overscroll_cancelled_ = true; | |
| 27 ui::ScopedLayerAnimationSettings settings(delegate_->GetAnimator()); | |
| 28 settings.SetPreemptionStrategy( | |
| 29 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 30 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
| 31 settings.AddObserver(this); | |
| 32 delegate_->SetTransform(gfx::Transform()); | |
| 33 direction_ = NONE; | |
| 34 } | |
| 35 | |
| 36 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.
| |
| 37 delegate_->GetAnimator()->AbortAllAnimations(); | |
| 38 } | |
| 39 | |
| 40 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.
| |
| 41 return !animation_completed_; | |
| 42 } | |
| 43 | |
| 44 void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() { | |
| 45 animation_completed_ = true; | |
| 46 delegate_->OnAnimationCompleted(); | |
| 47 } | |
| 48 | |
| 49 gfx::Vector2dF OverscrollWindowAnimation::GetTranslationForOverscroll( | |
| 50 float delta_x) { | |
| 51 DCHECK(direction_ != NONE); | |
| 52 const float bounds_width = delegate_->GetContentsBounds().width(); | |
| 53 if (direction_ == FORWARD) | |
| 54 return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0); | |
| 55 else | |
| 56 return gfx::Vector2dF(std::min(bounds_width, delta_x), 0); | |
| 57 } | |
| 58 | |
| 59 gfx::Rect OverscrollWindowAnimation::GetVisibleBounds() const { | |
| 60 return delegate_->GetContentsBounds(); | |
| 61 } | |
| 62 | |
| 63 bool OverscrollWindowAnimation::OnOverscrollUpdate(float delta_x, | |
| 64 float delta_y) { | |
| 65 if (direction_ == NONE) | |
| 66 return false; | |
| 67 LOG(ERROR) << "OWA: OnOverscrollUpdate"; | |
| 68 gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x); | |
| 69 gfx::Transform transform; | |
| 70 transform.Translate(translate.x(), translate.y()); | |
| 71 delegate_->SetTransform(transform); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 void OverscrollWindowAnimation::OnOverscrollModeChange( | |
| 76 OverscrollMode old_mode, | |
| 77 OverscrollMode new_mode) { | |
| 78 LOG(ERROR) << "OWA: OnOverscrollModeChange"; | |
| 79 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.
| |
| 80 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
| |
| 81 | |
| 82 if (direction_ == NONE) { | |
| 83 // The user cancelled the in progress overscroll gesture. | |
| 84 // TODO(nsatragno): in this case, show a feedback animation. | |
| 85 if (IsSlideInProgress()) | |
| 86 CancelOverscroll(); | |
| 87 return; | |
| 88 } | |
| 89 StartAnimating(); | |
| 90 } | |
| 91 | |
| 92 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.
| |
| 93 LOG(ERROR) << "OWA: StartAnimating"; | |
| 94 overscroll_cancelled_ = false; | |
| 95 animation_completed_ = false; | |
| 96 } | |
| 97 | |
| 98 void OverscrollWindowAnimation::OnOverscrollComplete( | |
| 99 OverscrollMode overscroll_mode) { | |
| 100 LOG(ERROR) << "OWA: OnOverscrollComplete"; | |
| 101 delegate_->OnAnimationCompleting(); | |
| 102 ui::ScopedLayerAnimationSettings settings(delegate_->GetAnimator()); | |
| 103 settings.SetPreemptionStrategy( | |
| 104 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 105 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
| 106 settings.AddObserver(this); | |
| 107 gfx::Transform transform; | |
| 108 int content_width = delegate_->GetContentsBounds().width(); | |
| 109 float translate_x = static_cast<float>( | |
| 110 direction_ == FORWARD ? -content_width | |
| 111 : content_width); | |
| 112 transform.Translate(translate_x, 0); | |
| 113 delegate_->SetTransform(transform); | |
| 114 direction_ = NONE; | |
| 115 } | |
| 116 | |
| 117 } // namespace content | |
| OLD | NEW |