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

Unified Diff: cc/input/single_scrollbar_animation_controller_thinning.cc

Issue 2554913002: Prevent overlay scrollbars expand or hover together (Closed)
Patch Set: fix for fade in/out together 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/single_scrollbar_animation_controller_thinning.cc
diff --git a/cc/input/scrollbar_animation_controller_thinning.cc b/cc/input/single_scrollbar_animation_controller_thinning.cc
similarity index 60%
copy from cc/input/scrollbar_animation_controller_thinning.cc
copy to cc/input/single_scrollbar_animation_controller_thinning.cc
index 587c60f79a8b6355b1a23423c0e693ba87ac678e..1ba943e57c4ba8b84380db61b059c8a54c8caa9f 100644
--- a/cc/input/scrollbar_animation_controller_thinning.cc
+++ b/cc/input/single_scrollbar_animation_controller_thinning.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/input/scrollbar_animation_controller_thinning.h"
+#include "cc/input/single_scrollbar_animation_controller_thinning.h"
+
+#include <algorithm>
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
@@ -17,30 +19,32 @@ const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
namespace cc {
-std::unique_ptr<ScrollbarAnimationControllerThinning>
-ScrollbarAnimationControllerThinning::Create(
+std::unique_ptr<SingleScrollbarAnimationControllerThinning>
+SingleScrollbarAnimationControllerThinning::Create(
int scroll_layer_id,
+ ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
- base::TimeDelta delay_before_starting,
- base::TimeDelta resize_delay_before_starting,
+ base::CancelableClosure* delayed_scrollbar_fade,
base::TimeDelta fade_duration,
base::TimeDelta thinning_duration) {
- return base::WrapUnique(new ScrollbarAnimationControllerThinning(
- scroll_layer_id, client, delay_before_starting,
- resize_delay_before_starting, fade_duration, thinning_duration));
+ return base::WrapUnique(new SingleScrollbarAnimationControllerThinning(
+ scroll_layer_id, orientation, client, delayed_scrollbar_fade,
+ fade_duration, thinning_duration));
}
-ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
- int scroll_layer_id,
- ScrollbarAnimationControllerClient* client,
- base::TimeDelta delay_before_starting,
- base::TimeDelta resize_delay_before_starting,
- base::TimeDelta fade_duration,
- base::TimeDelta thinning_duration)
- : ScrollbarAnimationController(scroll_layer_id,
- client,
- delay_before_starting,
- resize_delay_before_starting),
+SingleScrollbarAnimationControllerThinning::
+ SingleScrollbarAnimationControllerThinning(
+ int scroll_layer_id,
+ ScrollbarOrientation orientation,
+ ScrollbarAnimationControllerClient* client,
+ base::CancelableClosure* delayed_scrollbar_fade,
+ base::TimeDelta fade_duration,
+ base::TimeDelta thinning_duration)
+ : client_(client),
+ delayed_scrollbar_fade_(delayed_scrollbar_fade),
+ is_animating_(false),
+ scroll_layer_id_(scroll_layer_id),
+ orientation_(orientation),
opacity_(0.0f),
captured_(false),
mouse_is_over_scrollbar_(false),
@@ -55,9 +59,39 @@ ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
ApplyThumbThicknessScale(kIdleThicknessScale);
}
-ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
+ScrollbarSet SingleScrollbarAnimationControllerThinning::Scrollbars() const {
+ return client_->ScrollbarsFor(scroll_layer_id_);
+}
+
+bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
+ if (!is_animating_)
+ return false;
+
+ if (last_awaken_time_.is_null())
+ last_awaken_time_ = now;
+
+ float progress = AnimationProgressAtTime(now);
+ RunAnimationFrame(progress);
+
+ return true;
+}
+
+float SingleScrollbarAnimationControllerThinning::AnimationProgressAtTime(
+ base::TimeTicks now) {
+ base::TimeDelta delta = now - last_awaken_time_;
+ float progress = delta.InSecondsF() / Duration().InSecondsF();
+ return std::max(std::min(progress, 1.f), 0.f);
+}
+
+const base::TimeDelta& SingleScrollbarAnimationControllerThinning::Duration() {
+ if (current_animating_property_ == OPACITY)
+ return fade_duration_;
+ else
+ return thinning_duration_;
+}
-void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
+void SingleScrollbarAnimationControllerThinning::RunAnimationFrame(
+ float progress) {
if (captured_)
return;
@@ -72,20 +106,40 @@ void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
if (current_animating_property_ == THICKNESS) {
thickness_change_ = NONE;
SetCurrentAnimatingProperty(OPACITY);
- if (!mouse_is_near_scrollbar_)
- PostDelayedAnimationTask(false);
}
}
}
-const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() {
+void SingleScrollbarAnimationControllerThinning::StartAnimation() {
+ delayed_scrollbar_fade_->Cancel();
+ is_animating_ = true;
+ last_awaken_time_ = base::TimeTicks();
+ client_->SetNeedsAnimateForScrollbarAnimation();
+}
+
+void SingleScrollbarAnimationControllerThinning::StopAnimation() {
+ delayed_scrollbar_fade_->Cancel();
+ is_animating_ = false;
+}
+
+void SingleScrollbarAnimationControllerThinning::FadeIn() {
+ if (captured_)
+ return;
+
if (current_animating_property_ == OPACITY)
- return fade_duration_;
- else
- return thinning_duration_;
+ StopAnimation();
+
+ ApplyOpacity(1.f);
+ ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f
+ : kIdleThicknessScale);
+}
+
+bool SingleScrollbarAnimationControllerThinning::ShouldFadeOut() const {
+ return !captured_ && !mouse_is_near_scrollbar_ && !is_animating_ &&
+ current_animating_property_ == OPACITY && !ScrollbarsHidden();
}
-void ScrollbarAnimationControllerThinning::DidMouseDown() {
+void SingleScrollbarAnimationControllerThinning::DidMouseDown() {
if (!mouse_is_over_scrollbar_ || opacity_ == 0.0f)
return;
@@ -95,7 +149,7 @@ void ScrollbarAnimationControllerThinning::DidMouseDown() {
ApplyThumbThicknessScale(1.f);
}
-void ScrollbarAnimationControllerThinning::DidMouseUp() {
+void SingleScrollbarAnimationControllerThinning::DidMouseUp() {
if (!captured_ || opacity_ == 0.0f)
return;
@@ -111,7 +165,7 @@ void ScrollbarAnimationControllerThinning::DidMouseUp() {
}
}
-void ScrollbarAnimationControllerThinning::DidMouseLeave() {
+void SingleScrollbarAnimationControllerThinning::DidMouseLeave() {
if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
return;
@@ -126,30 +180,8 @@ void ScrollbarAnimationControllerThinning::DidMouseLeave() {
StartAnimation();
}
-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_)
- StopAnimation();
-}
-
-void ScrollbarAnimationControllerThinning::DidScrollEnd() {
- ScrollbarAnimationController::DidScrollEnd();
-
- // Don't fade out the scrollbar when mouse is near.
- if (mouse_is_near_scrollbar_)
- StopAnimation();
-}
-
-void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) {
+void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear(
+ float distance) {
bool mouse_is_over_scrollbar = distance == 0.0f;
bool mouse_is_near_scrollbar =
distance < mouse_move_distance_to_trigger_animation_;
@@ -176,11 +208,11 @@ void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) {
StartAnimation();
}
-bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
+bool SingleScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
return opacity_ == 0.0f;
}
-float ScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
+float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
float progress) {
if (thickness_change_ == NONE)
return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale;
@@ -188,7 +220,7 @@ float ScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
}
-float ScrollbarAnimationControllerThinning::AdjustScale(
+float SingleScrollbarAnimationControllerThinning::AdjustScale(
float new_value,
float current_value,
AnimationChange animation_change,
@@ -208,10 +240,13 @@ float ScrollbarAnimationControllerThinning::AdjustScale(
return result;
}
-void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
+void SingleScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
+ if (scrollbar->orientation() != orientation_)
+ continue;
if (!scrollbar->is_overlay_scrollbar())
continue;
+
float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
PropertyTrees* property_trees =
scrollbar->layer_tree_impl()->property_trees();
@@ -229,28 +264,26 @@ void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
}
}
- bool previouslyVisible = opacity_ > 0.0f;
- bool currentlyVisible = opacity > 0.0f;
-
opacity_ = opacity;
-
- if (previouslyVisible != currentlyVisible)
- client_->DidChangeScrollbarVisibility();
}
-void ScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
+void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
float thumb_thickness_scale) {
for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
+ if (scrollbar->orientation() != orientation_)
+ continue;
if (!scrollbar->is_overlay_scrollbar())
continue;
- scrollbar->SetThumbThicknessScaleFactor(AdjustScale(
- thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(),
- thickness_change_, kIdleThicknessScale, 1));
+ float scale = AdjustScale(thumb_thickness_scale,
+ scrollbar->thumb_thickness_scale_factor(),
+ thickness_change_, kIdleThicknessScale, 1);
+
+ scrollbar->SetThumbThicknessScaleFactor(scale);
}
}
-void ScrollbarAnimationControllerThinning::SetCurrentAnimatingProperty(
+void SingleScrollbarAnimationControllerThinning::SetCurrentAnimatingProperty(
AnimatingProperty property) {
if (current_animating_property_ == property)
return;

Powered by Google App Engine
This is Rietveld 408576698