| Index: cc/input/scrollbar_animation_controller_thinning.cc
|
| diff --git a/cc/input/scrollbar_animation_controller_thinning.cc b/cc/input/scrollbar_animation_controller_thinning.cc
|
| index 358a9cefa324d3e444f50358f75792b57aaa84d5..48a3d2732957c1763ec080b073b75a05d2e6d718 100644
|
| --- a/cc/input/scrollbar_animation_controller_thinning.cc
|
| +++ b/cc/input/scrollbar_animation_controller_thinning.cc
|
| @@ -10,11 +10,6 @@
|
| #include "cc/layers/scrollbar_layer_impl_base.h"
|
| #include "cc/trees/layer_tree_impl.h"
|
|
|
| -namespace {
|
| -const float kIdleThicknessScale = 0.4f;
|
| -const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
|
| -}
|
| -
|
| namespace cc {
|
|
|
| std::unique_ptr<ScrollbarAnimationControllerThinning>
|
| @@ -42,102 +37,124 @@ ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
|
| delay_before_starting,
|
| resize_delay_before_starting),
|
| opacity_(0.0f),
|
| - captured_(false),
|
| - mouse_is_over_scrollbar_(false),
|
| - mouse_is_near_scrollbar_(false),
|
| - thickness_change_(NONE),
|
| - mouse_move_distance_to_trigger_animation_(
|
| - kDefaultMouseMoveDistanceToTriggerAnimation),
|
| - fade_duration_(fade_duration),
|
| - thinning_duration_(thinning_duration),
|
| - current_animating_property_(OPACITY) {
|
| - ApplyOpacity(0.f);
|
| - ApplyThumbThicknessScale(kIdleThicknessScale);
|
| + fade_duration_(fade_duration) {
|
| + vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
|
| + scroll_layer_id, ScrollbarOrientation::VERTICAL, client,
|
| + thinning_duration);
|
| + horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
|
| + scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
|
| + thinning_duration);
|
| + ApplyOpacity(0.0f);
|
| }
|
|
|
| ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
|
|
|
| -void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
|
| - if (captured_)
|
| - return;
|
| -
|
| - if (current_animating_property_ == OPACITY)
|
| - ApplyOpacity(1.f - progress);
|
| +SingleScrollbarAnimationControllerThinning&
|
| +ScrollbarAnimationControllerThinning::GetScrollbarAnimationController(
|
| + ScrollbarOrientation orientation) const {
|
| + if (orientation == ScrollbarOrientation::VERTICAL)
|
| + return *(vertical_controller_.get());
|
| else
|
| - ApplyThumbThicknessScale(ThumbThicknessScaleAt(progress));
|
| + return *(horizontal_controller_.get());
|
| +}
|
| +
|
| +bool ScrollbarAnimationControllerThinning::mouse_is_over_scrollbar(
|
| + ScrollbarOrientation orientation) const {
|
| + return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar();
|
| +}
|
| +
|
| +bool ScrollbarAnimationControllerThinning::mouse_is_near_scrollbar(
|
| + ScrollbarOrientation orientation) const {
|
| + return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar();
|
| +}
|
| +
|
| +bool ScrollbarAnimationControllerThinning::mouse_is_near_any_scrollbar() const {
|
| + return vertical_controller_->mouse_is_near_scrollbar() ||
|
| + horizontal_controller_->mouse_is_near_scrollbar();
|
| +}
|
| +
|
| +bool ScrollbarAnimationControllerThinning::Captured() const {
|
| + return vertical_controller_->captured() || horizontal_controller_->captured();
|
| +}
|
| +
|
| +bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
|
| + return opacity_ == 0.0f;
|
| +}
|
| +
|
| +void ScrollbarAnimationControllerThinning::set_mouse_move_distance_for_test(
|
| + float distance) {
|
| + vertical_controller_->set_mouse_move_distance_for_test(distance);
|
| + horizontal_controller_->set_mouse_move_distance_for_test(distance);
|
| +}
|
|
|
| - client_->SetNeedsRedrawForScrollbarAnimation();
|
| - if (progress == 1.f) {
|
| +bool ScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
|
| + bool animated = ScrollbarAnimationController::Animate(now);
|
| + animated |= vertical_controller_->Animate(now);
|
| + animated |= horizontal_controller_->Animate(now);
|
| +
|
| + return animated;
|
| +}
|
| +
|
| +void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
|
| + ApplyOpacity(1.f - progress);
|
| + if (progress == 1.f)
|
| StopAnimation();
|
| - if (current_animating_property_ == THICKNESS) {
|
| - thickness_change_ = NONE;
|
| - SetCurrentAnimatingProperty(OPACITY);
|
| - if (!mouse_is_near_scrollbar_)
|
| - PostDelayedAnimationTask(false);
|
| - }
|
| - }
|
| }
|
|
|
| const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() {
|
| - if (current_animating_property_ == OPACITY)
|
| - return fade_duration_;
|
| - else
|
| - return thinning_duration_;
|
| + return fade_duration_;
|
| }
|
|
|
| void ScrollbarAnimationControllerThinning::DidMouseDown() {
|
| - if (!mouse_is_over_scrollbar_ || opacity_ == 0.0f)
|
| + if (ScrollbarsHidden())
|
| return;
|
| -
|
| - StopAnimation();
|
| - captured_ = true;
|
| - ApplyOpacity(1.f);
|
| - ApplyThumbThicknessScale(1.f);
|
| + vertical_controller_->DidMouseDown();
|
| + horizontal_controller_->DidMouseDown();
|
| }
|
|
|
| void ScrollbarAnimationControllerThinning::DidMouseUp() {
|
| - if (!captured_ || opacity_ == 0.0f)
|
| - return;
|
| -
|
| - captured_ = false;
|
| - StopAnimation();
|
| + vertical_controller_->DidMouseUp();
|
| + horizontal_controller_->DidMouseUp();
|
|
|
| - if (!mouse_is_near_scrollbar_) {
|
| - SetCurrentAnimatingProperty(THICKNESS);
|
| - thickness_change_ = DECREASE;
|
| - StartAnimation();
|
| - } else {
|
| - SetCurrentAnimatingProperty(OPACITY);
|
| - }
|
| + if (!mouse_is_near_any_scrollbar())
|
| + PostDelayedAnimationTask(false);
|
| }
|
|
|
| void ScrollbarAnimationControllerThinning::DidMouseLeave() {
|
| - if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
|
| - return;
|
| + vertical_controller_->DidMouseLeave();
|
| + horizontal_controller_->DidMouseLeave();
|
| +}
|
|
|
| - mouse_is_over_scrollbar_ = false;
|
| - mouse_is_near_scrollbar_ = false;
|
| +void ScrollbarAnimationControllerThinning::DidMouseMoveNear(
|
| + ScrollbarOrientation orientation,
|
| + float distance) {
|
| + GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
|
|
|
| - if (captured_ || opacity_ == 0.0f)
|
| + if (ScrollbarsHidden() || Captured())
|
| return;
|
|
|
| - thickness_change_ = DECREASE;
|
| - SetCurrentAnimatingProperty(THICKNESS);
|
| - StartAnimation();
|
| + if (mouse_is_near_any_scrollbar()) {
|
| + ApplyOpacity(1);
|
| + StopAnimation();
|
| + } else if (!animating_fade()) {
|
| + PostDelayedAnimationTask(false);
|
| + }
|
| }
|
|
|
| void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
|
| - if (captured_)
|
| + if (Captured())
|
| return;
|
|
|
| ScrollbarAnimationController::DidScrollUpdate(on_resize);
|
| - ApplyOpacity(1.f);
|
| - ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f
|
| - : kIdleThicknessScale);
|
| - SetCurrentAnimatingProperty(OPACITY);
|
|
|
| - // Don't fade out the scrollbar when mouse is near.
|
| - if (mouse_is_near_scrollbar_)
|
| + ApplyOpacity(1);
|
| + vertical_controller_->UpdateThumbThicknessScale();
|
| + horizontal_controller_->UpdateThumbThicknessScale();
|
| +
|
| + // we started a fade out timer in
|
| + // |ScrollbarAnimationController::DidScrollUpdate| but don't want to
|
| + // fade out if the mouse is nearby.
|
| + if (mouse_is_near_any_scrollbar())
|
| StopAnimation();
|
| }
|
|
|
| @@ -145,69 +162,10 @@ void ScrollbarAnimationControllerThinning::DidScrollEnd() {
|
| ScrollbarAnimationController::DidScrollEnd();
|
|
|
| // Don't fade out the scrollbar when mouse is near.
|
| - if (mouse_is_near_scrollbar_)
|
| + if (mouse_is_near_any_scrollbar())
|
| StopAnimation();
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) {
|
| - bool mouse_is_over_scrollbar = distance == 0.0f;
|
| - bool mouse_is_near_scrollbar =
|
| - distance < mouse_move_distance_to_trigger_animation_;
|
| -
|
| - if (captured_ || opacity_ == 0.0f) {
|
| - mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
|
| - mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
|
| - return;
|
| - }
|
| -
|
| - if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ &&
|
| - mouse_is_near_scrollbar == mouse_is_near_scrollbar_)
|
| - return;
|
| -
|
| - if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar)
|
| - mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
|
| -
|
| - if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) {
|
| - mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
|
| - thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE;
|
| - }
|
| -
|
| - SetCurrentAnimatingProperty(THICKNESS);
|
| - StartAnimation();
|
| -}
|
| -
|
| -bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
|
| - return opacity_ == 0.0f;
|
| -}
|
| -
|
| -float ScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
|
| - float progress) {
|
| - if (thickness_change_ == NONE)
|
| - return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale;
|
| - float factor = thickness_change_ == INCREASE ? progress : (1.f - progress);
|
| - return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
|
| -}
|
| -
|
| -float ScrollbarAnimationControllerThinning::AdjustScale(
|
| - float new_value,
|
| - float current_value,
|
| - AnimationChange animation_change,
|
| - float min_value,
|
| - float max_value) {
|
| - float result;
|
| - if (animation_change == INCREASE && current_value > new_value)
|
| - result = current_value;
|
| - else if (animation_change == DECREASE && current_value < new_value)
|
| - result = current_value;
|
| - else
|
| - result = new_value;
|
| - if (result > max_value)
|
| - return max_value;
|
| - if (result < min_value)
|
| - return min_value;
|
| - return result;
|
| -}
|
| -
|
| void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
|
| for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
|
| if (!scrollbar->is_overlay_scrollbar())
|
| @@ -238,27 +196,4 @@ void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
|
| client_->DidChangeScrollbarVisibility();
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
|
| - float thumb_thickness_scale) {
|
| - for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
|
| - if (!scrollbar->is_overlay_scrollbar())
|
| - continue;
|
| -
|
| - scrollbar->SetThumbThicknessScaleFactor(AdjustScale(
|
| - thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(),
|
| - thickness_change_, kIdleThicknessScale, 1));
|
| - }
|
| -}
|
| -
|
| -void ScrollbarAnimationControllerThinning::SetCurrentAnimatingProperty(
|
| - AnimatingProperty property) {
|
| - if (current_animating_property_ == property)
|
| - return;
|
| -
|
| - StopAnimation();
|
| - current_animating_property_ = property;
|
| - if (current_animating_property_ == THICKNESS)
|
| - ApplyOpacity(1.f);
|
| -}
|
| -
|
| } // namespace cc
|
|
|