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

Unified Diff: cc/input/scrollbar_animation_controller_thinning.cc

Issue 2554913002: Prevent overlay scrollbars expand or hover together (Closed)
Patch Set: separate responsibilities of SACT and SSACT Created 4 years 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: 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 587c60f79a8b6355b1a23423c0e693ba87ac678e..d542f7308bf0779af70b08131993aa98ec2d684e 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>
@@ -41,171 +36,132 @@ ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
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);
+ opacity_(1.0f),
bokan 2016/12/19 16:11:47 Why did we change starting opacity to 1? IIRC, sta
chaopeng 2016/12/20 20:05:55 Because scrollbars show when page load is done, th
bokan 2016/12/21 15:56:02 Right, but this worked before. Blink is responsibl
+ fade_duration_(fade_duration) {
+ vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
+ scroll_layer_id, ScrollbarOrientation::VERTICAL, client,
+ delayed_scrollbar_fade(), thinning_duration);
+ horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
+ scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
+ delayed_scrollbar_fade(), thinning_duration);
}
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));
-
- client_->SetNeedsRedrawForScrollbarAnimation();
- if (progress == 1.f) {
- StopAnimation();
- if (current_animating_property_ == THICKNESS) {
- thickness_change_ = NONE;
- SetCurrentAnimatingProperty(OPACITY);
- if (!mouse_is_near_scrollbar_)
- PostDelayedAnimationTask(false);
- }
- }
+ return *(horizontal_controller_.get());
}
-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 {
+ return GetScrollbarAnimationController(orientation).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 {
+ return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar();
+}
- StopAnimation();
- captured_ = true;
- ApplyOpacity(1.f);
- ApplyThumbThicknessScale(1.f);
+bool ScrollbarAnimationControllerThinning::mouse_is_near_any_scrollbar() const {
+ return vertical_controller_->mouse_is_near_scrollbar() ||
+ horizontal_controller_->mouse_is_near_scrollbar();
}
-void ScrollbarAnimationControllerThinning::DidMouseUp() {
- if (!captured_ || opacity_ == 0.0f)
- return;
+bool ScrollbarAnimationControllerThinning::captured() const {
+ return vertical_controller_->captured() || horizontal_controller_->captured();
+}
- captured_ = false;
- StopAnimation();
+bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
+ return opacity_ == 0.0f;
+}
- if (!mouse_is_near_scrollbar_) {
- SetCurrentAnimatingProperty(THICKNESS);
- thickness_change_ = DECREASE;
- StartAnimation();
- } else {
- SetCurrentAnimatingProperty(OPACITY);
- }
+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);
}
-void ScrollbarAnimationControllerThinning::DidMouseLeave() {
- if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
- return;
+bool ScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
+ if (animating())
+ return ScrollbarAnimationController::Animate(now);
bokan 2016/12/19 16:11:47 As I noted in a comment in the SingleScrollbar cla
- mouse_is_over_scrollbar_ = false;
- mouse_is_near_scrollbar_ = false;
+ bool need_animate = vertical_controller_->Animate(now);
+ need_animate = horizontal_controller_->Animate(now) || need_animate;
bokan 2016/12/19 16:11:47 need_animate |=
- if (captured_ || opacity_ == 0.0f)
- return;
+ if (need_animate) {
+ client_->SetNeedsAnimateForScrollbarAnimation();
+ } else if (vertical_controller_->ShouldFadeOut() &&
+ horizontal_controller_->ShouldFadeOut()) {
+ PostDelayedAnimationTask(false);
+ }
- thickness_change_ = DECREASE;
- SetCurrentAnimatingProperty(THICKNESS);
- StartAnimation();
+ return need_animate;
}
-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);
-
- // Don't fade out the scrollbar when mouse is near.
- if (mouse_is_near_scrollbar_)
+void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
+ ApplyOpacity(1.f - progress);
+ if (progress == 1.f)
StopAnimation();
}
-void ScrollbarAnimationControllerThinning::DidScrollEnd() {
- ScrollbarAnimationController::DidScrollEnd();
+const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() {
+ return fade_duration_;
+}
- // Don't fade out the scrollbar when mouse is near.
- if (mouse_is_near_scrollbar_)
- StopAnimation();
+void ScrollbarAnimationControllerThinning::DidMouseDown() {
+ vertical_controller_->DidMouseDown();
+ horizontal_controller_->DidMouseDown();
}
-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_;
+void ScrollbarAnimationControllerThinning::DidMouseUp() {
+ vertical_controller_->DidMouseUp();
+ horizontal_controller_->DidMouseUp();
+}
- if (captured_ || opacity_ == 0.0f) {
- mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
- mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
- return;
- }
+void ScrollbarAnimationControllerThinning::DidMouseLeave() {
+ vertical_controller_->DidMouseLeave();
+ horizontal_controller_->DidMouseLeave();
+}
+
+void ScrollbarAnimationControllerThinning::DidMouseMoveNear(
+ ScrollbarOrientation orientation,
+ float distance) {
+ GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
+ EnsureScrollbarFadeIn();
+}
- if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ &&
- mouse_is_near_scrollbar == mouse_is_near_scrollbar_)
+void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
+ if (captured())
return;
- if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar)
- mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
+ FadeIn();
+ vertical_controller_->UpdateThumbThicknessScale();
+ horizontal_controller_->UpdateThumbThicknessScale();
- 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();
+ // Don't fade out the scrollbar when mouse is near.
+ if (!mouse_is_near_any_scrollbar())
+ PostDelayedAnimationTask(on_resize);
}
-bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
- return opacity_ == 0.0f;
+void ScrollbarAnimationControllerThinning::DidScrollEnd() {
+ ScrollbarAnimationController::DidScrollEnd();
+ EnsureScrollbarFadeIn();
}
-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;
+void ScrollbarAnimationControllerThinning::EnsureScrollbarFadeIn() {
bokan 2016/12/19 16:11:47 Call this FadeInIfNeeded
+ // Don't fade out the scrollbar when mouse is near.
bokan 2016/12/19 16:11:47 I don't get why we need this method, the fade in/o
chaopeng 2016/12/20 20:05:54 I changed it to `if (mouse_is_near_any_scrollbar()
bokan 2016/12/21 15:56:02 Ah, ok. In that case, I would just inline this ins
+ if (mouse_is_near_any_scrollbar())
+ FadeIn();
}
-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::FadeIn() {
+ ApplyOpacity(1);
+ StopAnimation();
}
void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
@@ -233,32 +189,11 @@ void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
bool currentlyVisible = opacity > 0.0f;
opacity_ = opacity;
+ vertical_controller_->SetHidden(!currentlyVisible);
+ horizontal_controller_->SetHidden(!currentlyVisible);
if (previouslyVisible != currentlyVisible)
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

Powered by Google App Engine
This is Rietveld 408576698