Commit ac6ccd29 authored by chaopeng's avatar chaopeng Committed by Commit Bot

Don't fade in overlay scrollbar when user interacting the content under scrollbar.

The issue (crbug.com/719011) indicate that it is hard to interact with
the content under the the scrollbar because the scrollbar will fade in
while mouse moves in the hover fade in region of scrollbar.

In this patch, we prevent fade in overlay scrollbar when user mouse
down. 3 behaviors changed:

1. When mouse move in hover fade in region of scrollbar with mouse
   press, we don't trigger delay fade in.
2. When mouse down after a delay fade in triggered, cancel the delay
   fade in.
3. When mouse up in hover fade in region of scrollbar, trigger a delay
   fade in.

BUG=719011
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2931703002
Cr-Commit-Position: refs/heads/master@{#478733}
parent 2cf1510e
......@@ -53,6 +53,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
opacity_(initial_opacity),
show_scrollbars_on_scroll_gesture_(false),
need_thinning_animation_(false),
is_mouse_down_(false),
weak_factory_(this) {}
ScrollbarAnimationController::ScrollbarAnimationController(
......@@ -74,6 +75,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
opacity_(initial_opacity),
show_scrollbars_on_scroll_gesture_(true),
need_thinning_animation_(true),
is_mouse_down_(false),
weak_factory_(this) {
vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
scroll_element_id, ScrollbarOrientation::VERTICAL, client,
......@@ -102,6 +104,7 @@ ScrollbarAnimationController::GetScrollbarAnimationController(
void ScrollbarAnimationController::StartAnimation() {
DCHECK(animation_change_ != NONE);
delayed_scrollbar_animation_.Cancel();
need_trigger_scrollbar_fade_in_ = false;
is_animating_ = true;
last_awaken_time_ = base::TimeTicks();
client_->SetNeedsAnimateForScrollbarAnimation();
......@@ -109,6 +112,7 @@ void ScrollbarAnimationController::StartAnimation() {
void ScrollbarAnimationController::StopAnimation() {
delayed_scrollbar_animation_.Cancel();
need_trigger_scrollbar_fade_in_ = false;
is_animating_ = false;
animation_change_ = NONE;
}
......@@ -224,21 +228,41 @@ void ScrollbarAnimationController::DidRequestShowFromMainThread() {
}
void ScrollbarAnimationController::DidMouseDown() {
if (!need_thinning_animation_ || ScrollbarsHidden())
if (!need_thinning_animation_)
return;
is_mouse_down_ = true;
if (ScrollbarsHidden()) {
if (need_trigger_scrollbar_fade_in_) {
delayed_scrollbar_animation_.Cancel();
need_trigger_scrollbar_fade_in_ = false;
}
return;
}
vertical_controller_->DidMouseDown();
horizontal_controller_->DidMouseDown();
}
void ScrollbarAnimationController::DidMouseUp() {
if (!need_thinning_animation_ || !Captured())
if (!need_thinning_animation_)
return;
is_mouse_down_ = false;
if (!Captured()) {
if (MouseIsNearAnyScrollbar() && ScrollbarsHidden()) {
PostDelayedAnimation(FADE_IN);
need_trigger_scrollbar_fade_in_ = true;
}
return;
}
vertical_controller_->DidMouseUp();
horizontal_controller_->DidMouseUp();
if (!MouseIsNearAnyScrollbar())
if (!MouseIsNearAnyScrollbar() && !ScrollbarsHidden())
PostDelayedAnimation(FADE_OUT);
}
......@@ -268,12 +292,17 @@ void ScrollbarAnimationController::DidMouseMove(
vertical_controller_->DidMouseMove(device_viewport_point);
horizontal_controller_->DidMouseMove(device_viewport_point);
need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar();
if (Captured())
if (Captured()) {
DCHECK(!ScrollbarsHidden());
return;
}
if (ScrollbarsHidden()) {
// Do not fade in scrollbar when user interacting with the content below
// scrollbar.
if (is_mouse_down_)
return;
need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar();
if (need_trigger_scrollbar_fade_in_before !=
need_trigger_scrollbar_fade_in_) {
if (need_trigger_scrollbar_fade_in_) {
......
......@@ -154,6 +154,8 @@ class CC_EXPORT ScrollbarAnimationController {
const bool show_scrollbars_on_scroll_gesture_;
const bool need_thinning_animation_;
bool is_mouse_down_;
std::unique_ptr<SingleScrollbarAnimationControllerThinning>
vertical_controller_;
std::unique_ptr<SingleScrollbarAnimationControllerThinning>
......
......@@ -717,13 +717,28 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) {
h_scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_TRUE(client_.start_fade().is_null());
// Similarly, releasing the scrollbar should have no effect.
// Similarly, releasing the scrollbar should have no effect but trigger a fade
// in.
scrollbar_controller_->DidMouseUp();
ExpectScrollbarsOpacity(0);
EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FLOAT_EQ(kIdleThicknessScale,
h_scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_TRUE(client_.start_fade().is_null());
// An fade in animation should have been enqueued.
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
EXPECT_EQ(kFadeDelay, client_.delay());
// Play the delay animation.
client_.start_fade().Run();
EXPECT_TRUE(client_.start_fade().IsCancelled());
scrollbar_controller_->Animate(time);
time += kFadeDuration;
scrollbar_controller_->Animate(time);
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
}
// Initiate a scroll when the pointer is already near the scrollbar. It should
......@@ -1093,7 +1108,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Move mouse hover the fade in scrollbar region of scrollbar.
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
......@@ -1127,7 +1142,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Move mouse hover the fade in scrollbar region of scrollbar.
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
......@@ -1137,7 +1152,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_EQ(kFadeDelay, client_.delay());
base::Closure& fade = client_.start_fade();
// Move mouse still hover the fade in scrollbar region of scrollbar should not
// Move mouse still hover the fade in region of scrollbar should not
// post a new fade in.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 2, 0));
......@@ -1152,7 +1167,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Move mouse hover the fade in scrollbar region of scrollbar.
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
......@@ -1176,7 +1191,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Move mouse hover the fade in scrollbar region of scrollbar.
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
......@@ -1190,10 +1205,59 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Move mouse hover the fade in scrollbar region of scrollbar.
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
// An fade in animation should have been enqueued.
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
EXPECT_EQ(kFadeDelay, client_.delay());
// Play the delay animation.
client_.start_fade().Run();
EXPECT_TRUE(client_.start_fade().IsCancelled());
scrollbar_controller_->Animate(time);
time += kFadeDuration;
scrollbar_controller_->Animate(time);
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
}
// Make sure mouse down will cancel hover fade in timer, then mouse move with
// press will not trigger hover fade in, mouse release near will trigger new
// hover fade in.
TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
MouseHoverThenMouseDownShouldCancelFadeInThenReleaseNearShouldFadeIn) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
// An fade in animation should have been enqueued.
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
EXPECT_EQ(kFadeDelay, client_.delay());
// Mouse down,delay fade in should be canceled.
scrollbar_controller_->DidMouseDown();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Move mouse hover the fade in region of scrollbar with press.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
// Should not have delay fade animation.
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Mouse up.
scrollbar_controller_->DidMouseUp();
// An fade in animation should have been enqueued.
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
......@@ -1210,6 +1274,45 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
}
// Make sure mouse down will cancel hover fade in timer, then mouse move with
// press will not trigger hover fade in, mouse release far will not trigger new
// hover fade in.
TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
MouseReleaseFarShouldNotFadeIn) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Move mouse over the fade in region of scrollbar.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
// An fade in animation should have been enqueued.
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
EXPECT_EQ(kFadeDelay, client_.delay());
// Mouse down,delay fade in should be canceled.
scrollbar_controller_->DidMouseDown();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Move mouse far from hover the fade in region of scrollbar with
// press.
scrollbar_controller_->DidMouseMove(
NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn, 0));
// Should not have delay fade animation.
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Mouse up.
scrollbar_controller_->DidMouseUp();
// Should not have delay fade animation.
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
}
class ScrollbarAnimationControllerAndroidTest
: public testing::Test,
public ScrollbarAnimationControllerClient {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment