| 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 2006d98fddb44a0779c850a7be0c32edb12c5d1c..8c2bb1a9007d0e930c8c4deb7172e447cd809bca 100644
|
| --- a/cc/input/scrollbar_animation_controller_thinning.cc
|
| +++ b/cc/input/scrollbar_animation_controller_thinning.cc
|
| @@ -11,13 +11,14 @@
|
| #include "cc/trees/layer_tree_impl.h"
|
|
|
| namespace {
|
| -const float kIdleThicknessScale = 0.4f;
|
| const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
|
| }
|
|
|
| namespace cc {
|
|
|
| -std::unique_ptr<ScrollbarAnimationControllerThinning>
|
| +using std::for_each;
|
| +
|
| +unique_ptr<ScrollbarAnimationControllerThinning>
|
| ScrollbarAnimationControllerThinning::Create(
|
| int scroll_layer_id,
|
| ScrollbarAnimationControllerClient* client,
|
| @@ -40,213 +41,116 @@ ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
|
| : ScrollbarAnimationController(scroll_layer_id,
|
| client,
|
| 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);
|
| + resize_delay_before_starting) {
|
| + scrollbar_controllers.push_back(
|
| + SingleScrollbarAnimationControllerThinning::Create(
|
| + scroll_layer_id, ScrollbarOrientation::VERTICAL, client,
|
| + delay_before_starting, resize_delay_before_starting, fade_duration,
|
| + thinning_duration));
|
| + scrollbar_controllers.push_back(
|
| + SingleScrollbarAnimationControllerThinning::Create(
|
| + scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
|
| + delay_before_starting, resize_delay_before_starting, fade_duration,
|
| + thinning_duration));
|
| }
|
|
|
| ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
|
|
|
| -void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
|
| - if (captured_)
|
| - return;
|
| -
|
| - if (current_animating_property_ == OPACITY)
|
| - ApplyOpacity(1.f - progress);
|
| - else
|
| - ApplyThumbThicknessScale(ThumbThicknessScaleAt(progress));
|
| -
|
| - client_->SetNeedsRedrawForScrollbarAnimation();
|
| - if (progress == 1.f) {
|
| - StopAnimation();
|
| - if (current_animating_property_ == THICKNESS) {
|
| - thickness_change_ = NONE;
|
| - SetCurrentAnimatingProperty(OPACITY);
|
| - PostDelayedAnimationTask(false);
|
| +void ScrollbarAnimationControllerThinning::GetScrollbarAnimationController(
|
| + ScrollbarOrientation orientation,
|
| + SingleScrollbarAnimationControllerThinning* scrollbar_controller) const {
|
| + for (auto itr = scrollbar_controllers.begin();
|
| + itr != scrollbar_controllers.end(); itr++) {
|
| + if ((*itr)->orientation() == orientation) {
|
| + scrollbar_controller = itr->get();
|
| }
|
| }
|
| + DCHECK(scrollbar_controller);
|
| }
|
|
|
| -const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() {
|
| - if (current_animating_property_ == OPACITY)
|
| - return fade_duration_;
|
| - else
|
| - return thinning_duration_;
|
| +bool ScrollbarAnimationControllerThinning::mouse_is_over_scrollbar(
|
| + ScrollbarOrientation orientation) const {
|
| + SingleScrollbarAnimationControllerThinning* scrollbar_controller_ptr =
|
| + nullptr;
|
| + GetScrollbarAnimationController(orientation, scrollbar_controller_ptr);
|
| + return scrollbar_controller_ptr->mouse_is_over_scrollbar();
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::DidMouseDown() {
|
| - if (!mouse_is_over_scrollbar_ || opacity_ == 0.0f)
|
| - return;
|
| +bool ScrollbarAnimationControllerThinning::mouse_is_near_scrollbar(
|
| + ScrollbarOrientation orientation) const {
|
| + SingleScrollbarAnimationControllerThinning* scrollbar_controller_ptr =
|
| + nullptr;
|
| + GetScrollbarAnimationController(orientation, scrollbar_controller_ptr);
|
| + return scrollbar_controller_ptr->mouse_is_near_scrollbar();
|
| +}
|
|
|
| - StopAnimation();
|
| - captured_ = true;
|
| - ApplyOpacity(1.f);
|
| - ApplyThumbThicknessScale(1.f);
|
| +bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
|
| + return scrollbar_controllers[0]->ScrollbarsHidden();
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::DidMouseUp() {
|
| - if (!captured_ || opacity_ == 0.0f)
|
| - return;
|
| -
|
| - captured_ = false;
|
| - StopAnimation();
|
| -
|
| - if (!mouse_is_near_scrollbar_) {
|
| - SetCurrentAnimatingProperty(THICKNESS);
|
| - thickness_change_ = DECREASE;
|
| - StartAnimation();
|
| - } else {
|
| - SetCurrentAnimatingProperty(OPACITY);
|
| - PostDelayedAnimationTask(false);
|
| +void ScrollbarAnimationControllerThinning::set_mouse_move_distance_for_test(
|
| + float distance) {
|
| + for (auto itr = scrollbar_controllers.begin();
|
| + itr != scrollbar_controllers.end(); itr++) {
|
| + (*itr)->set_mouse_move_distance_for_test(distance);
|
| }
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::DidMouseLeave() {
|
| - if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
|
| - return;
|
| -
|
| - mouse_is_over_scrollbar_ = false;
|
| - mouse_is_near_scrollbar_ = false;
|
| -
|
| - if (captured_ || opacity_ == 0.0f)
|
| - return;
|
| +bool ScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
|
| + bool result = false;
|
| + for (auto itr = scrollbar_controllers.begin();
|
| + itr != scrollbar_controllers.end(); itr++) {
|
| + result |= (*itr)->Animate(now);
|
| + }
|
|
|
| - thickness_change_ = DECREASE;
|
| - SetCurrentAnimatingProperty(THICKNESS);
|
| - StartAnimation();
|
| + return result;
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
|
| - if (captured_)
|
| - return;
|
| -
|
| - ScrollbarAnimationController::DidScrollUpdate(on_resize);
|
| - ApplyOpacity(1.f);
|
| - ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f
|
| - : kIdleThicknessScale);
|
| - SetCurrentAnimatingProperty(OPACITY);
|
| +void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
|
| + // do nothing
|
| }
|
|
|
| -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();
|
| +const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() {
|
| + // should not call
|
| + return scrollbar_controllers[0]->Duration();
|
| }
|
|
|
| -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::DidMouseDown() {
|
| + for_each(
|
| + scrollbar_controllers.begin(), scrollbar_controllers.end(),
|
| + [](unique_ptr<SingleScrollbarAnimationControllerThinning>&
|
| + scrollbar_controller) { scrollbar_controller->DidMouseDown(); });
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
|
| - for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
|
| - if (!scrollbar->is_overlay_scrollbar())
|
| - continue;
|
| - float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
|
| - PropertyTrees* property_trees =
|
| - scrollbar->layer_tree_impl()->property_trees();
|
| - // If this method is called during LayerImpl::PushPropertiesTo, we may not
|
| - // yet have valid effect_id_to_index_map entries as property trees are
|
| - // pushed after layers during activation. We can skip updating opacity in
|
| - // that case as we are only registering a scrollbar and because opacity will
|
| - // be overwritten anyway when property trees are pushed.
|
| - if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT,
|
| - scrollbar->id())) {
|
| - property_trees->effect_tree.OnOpacityAnimated(
|
| - effective_opacity,
|
| - property_trees->effect_id_to_index_map[scrollbar->id()],
|
| - scrollbar->layer_tree_impl());
|
| - }
|
| - }
|
| -
|
| - bool previouslyVisible = opacity_ > 0.0f;
|
| - bool currentlyVisible = opacity > 0.0f;
|
| -
|
| - opacity_ = opacity;
|
| -
|
| - if (previouslyVisible != currentlyVisible)
|
| - client_->DidChangeScrollbarVisibility();
|
| +void ScrollbarAnimationControllerThinning::DidMouseUp() {
|
| + for_each(
|
| + scrollbar_controllers.begin(), scrollbar_controllers.end(),
|
| + [](unique_ptr<SingleScrollbarAnimationControllerThinning>&
|
| + scrollbar_controller) { scrollbar_controller->DidMouseUp(); });
|
| }
|
|
|
| -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::DidMouseLeave() {
|
| + for_each(
|
| + scrollbar_controllers.begin(), scrollbar_controllers.end(),
|
| + [](unique_ptr<SingleScrollbarAnimationControllerThinning>&
|
| + scrollbar_controller) { scrollbar_controller->DidMouseLeave(); });
|
| }
|
|
|
| -void ScrollbarAnimationControllerThinning::SetCurrentAnimatingProperty(
|
| - AnimatingProperty property) {
|
| - if (current_animating_property_ == property)
|
| - return;
|
| -
|
| - StopAnimation();
|
| - current_animating_property_ = property;
|
| - if (current_animating_property_ == THICKNESS)
|
| - ApplyOpacity(1.f);
|
| +void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
|
| + for_each(scrollbar_controllers.begin(), scrollbar_controllers.end(),
|
| + [&on_resize](unique_ptr<SingleScrollbarAnimationControllerThinning>&
|
| + scrollbar_controller) {
|
| + scrollbar_controller->DidScrollUpdate(on_resize);
|
| + });
|
| +}
|
| +
|
| +void ScrollbarAnimationControllerThinning::DidMouseMoveNear(
|
| + vector<DistanceToScrollbar> distances) {
|
| + for_each(scrollbar_controllers.begin(), scrollbar_controllers.end(),
|
| + [&distances](unique_ptr<SingleScrollbarAnimationControllerThinning>&
|
| + scrollbar_controller) {
|
| + scrollbar_controller->DidMouseMoveNear(distances);
|
| + });
|
| }
|
|
|
| } // namespace cc
|
|
|