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

Prevent Aura Overlay Scrollbar fade out when tickmarks show

Currently, Aura Overlay Scrollbar will fade out when user finding in the
page. This patch is to improve this UX.

In this patch, we check HasFindInPageTickmarks in root vertical Scrollbar Layer
then show and prevent it fadeout or post the hide animation the scrollbar at the
end of syncing pending tree to active tree.

After this, we will show Aura Overlay Scrollbar when user type the first
character in find in page box and post fade out animation when user
close find in page or delete last character in find in page box.

Bug: 759152
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: Id2baf95a6441ffa58a09597dba6b0bed5299a1c3
Reviewed-on: https://chromium-review.googlesource.com/946744Reviewed-by: default avatarweiliangc <weiliangc@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Jianpeng Chao <chaopeng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542281}
parent a012da09
...@@ -54,6 +54,7 @@ ScrollbarAnimationController::ScrollbarAnimationController( ...@@ -54,6 +54,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
show_scrollbars_on_scroll_gesture_(false), show_scrollbars_on_scroll_gesture_(false),
need_thinning_animation_(false), need_thinning_animation_(false),
is_mouse_down_(false), is_mouse_down_(false),
tickmarks_showing_(false),
weak_factory_(this) {} weak_factory_(this) {}
ScrollbarAnimationController::ScrollbarAnimationController( ScrollbarAnimationController::ScrollbarAnimationController(
...@@ -76,6 +77,7 @@ ScrollbarAnimationController::ScrollbarAnimationController( ...@@ -76,6 +77,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
show_scrollbars_on_scroll_gesture_(true), show_scrollbars_on_scroll_gesture_(true),
need_thinning_animation_(true), need_thinning_animation_(true),
is_mouse_down_(false), is_mouse_down_(false),
tickmarks_showing_(false),
weak_factory_(this) { weak_factory_(this) {
vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
scroll_element_id, ScrollbarOrientation::VERTICAL, client, scroll_element_id, ScrollbarOrientation::VERTICAL, client,
...@@ -194,11 +196,15 @@ void ScrollbarAnimationController::DidScrollEnd() { ...@@ -194,11 +196,15 @@ void ScrollbarAnimationController::DidScrollEnd() {
if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) if (need_thinning_animation_ && MouseIsNearAnyScrollbar())
return; return;
if (has_scrolled) if (has_scrolled && !tickmarks_showing_)
PostDelayedAnimation(FADE_OUT); PostDelayedAnimation(FADE_OUT);
} }
void ScrollbarAnimationController::DidScrollUpdate() { void ScrollbarAnimationController::DidScrollUpdate() {
UpdateScrollbarState();
}
void ScrollbarAnimationController::UpdateScrollbarState() {
if (need_thinning_animation_ && Captured()) if (need_thinning_animation_ && Captured())
return; return;
...@@ -209,10 +215,14 @@ void ScrollbarAnimationController::DidScrollUpdate() { ...@@ -209,10 +215,14 @@ void ScrollbarAnimationController::DidScrollUpdate() {
// As an optimization, we avoid spamming fade delay tasks during active fast // As an optimization, we avoid spamming fade delay tasks during active fast
// scrolls. But if we're not within one, we need to post every scroll update. // scrolls. But if we're not within one, we need to post every scroll update.
if (!currently_scrolling_) { if (!currently_scrolling_) {
// We don't fade out scrollbar if they need thinning animation and mouse is // We don't fade out scrollbar if they need thinning animation (Aura
// near. // Overlay) and mouse is near or tickmarks show.
if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) if (need_thinning_animation_) {
if (!MouseIsNearAnyScrollbar() && !tickmarks_showing_)
PostDelayedAnimation(FADE_OUT);
} else {
PostDelayedAnimation(FADE_OUT); PostDelayedAnimation(FADE_OUT);
}
} else { } else {
show_in_fast_scroll_ = true; show_in_fast_scroll_ = true;
} }
...@@ -225,11 +235,22 @@ void ScrollbarAnimationController::DidScrollUpdate() { ...@@ -225,11 +235,22 @@ void ScrollbarAnimationController::DidScrollUpdate() {
void ScrollbarAnimationController::WillUpdateScroll() { void ScrollbarAnimationController::WillUpdateScroll() {
if (show_scrollbars_on_scroll_gesture_) if (show_scrollbars_on_scroll_gesture_)
DidScrollUpdate(); UpdateScrollbarState();
} }
void ScrollbarAnimationController::DidRequestShowFromMainThread() { void ScrollbarAnimationController::DidRequestShowFromMainThread() {
DidScrollUpdate(); UpdateScrollbarState();
}
void ScrollbarAnimationController::UpdateTickmarksVisibility(bool show) {
if (!need_thinning_animation_)
return;
if (tickmarks_showing_ == show)
return;
tickmarks_showing_ = show;
UpdateScrollbarState();
} }
void ScrollbarAnimationController::DidMouseDown() { void ScrollbarAnimationController::DidMouseDown() {
...@@ -267,7 +288,7 @@ void ScrollbarAnimationController::DidMouseUp() { ...@@ -267,7 +288,7 @@ void ScrollbarAnimationController::DidMouseUp() {
vertical_controller_->DidMouseUp(); vertical_controller_->DidMouseUp();
horizontal_controller_->DidMouseUp(); horizontal_controller_->DidMouseUp();
if (!MouseIsNearAnyScrollbar() && !ScrollbarsHidden()) if (!MouseIsNearAnyScrollbar() && !ScrollbarsHidden() && !tickmarks_showing_)
PostDelayedAnimation(FADE_OUT); PostDelayedAnimation(FADE_OUT);
} }
...@@ -281,7 +302,7 @@ void ScrollbarAnimationController::DidMouseLeave() { ...@@ -281,7 +302,7 @@ void ScrollbarAnimationController::DidMouseLeave() {
delayed_scrollbar_animation_.Cancel(); delayed_scrollbar_animation_.Cancel();
need_trigger_scrollbar_fade_in_ = false; need_trigger_scrollbar_fade_in_ = false;
if (ScrollbarsHidden() || Captured()) if (ScrollbarsHidden() || Captured() || tickmarks_showing_)
return; return;
PostDelayedAnimation(FADE_OUT); PostDelayedAnimation(FADE_OUT);
...@@ -297,7 +318,7 @@ void ScrollbarAnimationController::DidMouseMove( ...@@ -297,7 +318,7 @@ void ScrollbarAnimationController::DidMouseMove(
vertical_controller_->DidMouseMove(device_viewport_point); vertical_controller_->DidMouseMove(device_viewport_point);
horizontal_controller_->DidMouseMove(device_viewport_point); horizontal_controller_->DidMouseMove(device_viewport_point);
if (Captured()) { if (Captured() || tickmarks_showing_) {
DCHECK(!ScrollbarsHidden()); DCHECK(!ScrollbarsHidden());
return; return;
} }
......
...@@ -84,6 +84,8 @@ class CC_EXPORT ScrollbarAnimationController { ...@@ -84,6 +84,8 @@ class CC_EXPORT ScrollbarAnimationController {
// ScrollableArea::showOverlayScrollbars). // ScrollableArea::showOverlayScrollbars).
void DidRequestShowFromMainThread(); void DidRequestShowFromMainThread();
void UpdateTickmarksVisibility(bool show);
// These methods are public for testing. // These methods are public for testing.
bool MouseIsOverScrollbarThumb(ScrollbarOrientation orientation) const; bool MouseIsOverScrollbarThumb(ScrollbarOrientation orientation) const;
bool MouseIsNearScrollbarThumb(ScrollbarOrientation orientation) const; bool MouseIsNearScrollbarThumb(ScrollbarOrientation orientation) const;
...@@ -114,6 +116,10 @@ class CC_EXPORT ScrollbarAnimationController { ...@@ -114,6 +116,10 @@ class CC_EXPORT ScrollbarAnimationController {
SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController( SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController(
ScrollbarOrientation) const; ScrollbarOrientation) const;
// Any scrollbar state update would show scrollbar hen post the delay fade out
// if needed.
void UpdateScrollbarState();
// Returns how far through the animation we are as a progress value from // Returns how far through the animation we are as a progress value from
// 0 to 1. // 0 to 1.
float AnimationProgressAtTime(base::TimeTicks now); float AnimationProgressAtTime(base::TimeTicks now);
...@@ -156,6 +162,8 @@ class CC_EXPORT ScrollbarAnimationController { ...@@ -156,6 +162,8 @@ class CC_EXPORT ScrollbarAnimationController {
bool is_mouse_down_; bool is_mouse_down_;
bool tickmarks_showing_;
std::unique_ptr<SingleScrollbarAnimationControllerThinning> std::unique_ptr<SingleScrollbarAnimationControllerThinning>
vertical_controller_; vertical_controller_;
std::unique_ptr<SingleScrollbarAnimationControllerThinning> std::unique_ptr<SingleScrollbarAnimationControllerThinning>
......
...@@ -1318,6 +1318,54 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ...@@ -1318,6 +1318,54 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
client_.start_fade().IsCancelled()); client_.start_fade().IsCancelled());
} }
// Ensure Aura Overlay Scrollbars shows and did not fade out when tickmarks show
// and fade out when tickmarks hide.
TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TickmakrsShowHide) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
// Overlay Scrollbar hidden at beginnging.
EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Scrollbars show when tickmarks show.
scrollbar_controller_->UpdateTickmarksVisibility(true);
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Scroll update, no delay fade animation.
scrollbar_controller_->DidScrollUpdate();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Scroll update with phase, no delay fade animation.
scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
scrollbar_controller_->DidScrollEnd();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Move mouse, no delay fade animation.
scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Mouse leave, no delay fade animation.
scrollbar_controller_->DidMouseLeave();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
// Scrollbars fade out animation has enqueued when tickmarks hide.
scrollbar_controller_->UpdateTickmarksVisibility(false);
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
EXPECT_EQ(kFadeDelay, client_.delay());
}
class ScrollbarAnimationControllerAndroidTest class ScrollbarAnimationControllerAndroidTest
: public testing::Test, : public testing::Test,
public ScrollbarAnimationControllerClient { public ScrollbarAnimationControllerClient {
......
...@@ -232,4 +232,8 @@ const char* PaintedOverlayScrollbarLayerImpl::LayerTypeAsString() const { ...@@ -232,4 +232,8 @@ const char* PaintedOverlayScrollbarLayerImpl::LayerTypeAsString() const {
return "cc::PaintedOverlayScrollbarLayerImpl"; return "cc::PaintedOverlayScrollbarLayerImpl";
} }
bool PaintedOverlayScrollbarLayerImpl::HasFindInPageTickmarks() const {
return track_ui_resource_id_ != 0;
}
} // namespace cc } // namespace cc
...@@ -51,6 +51,8 @@ class CC_EXPORT PaintedOverlayScrollbarLayerImpl ...@@ -51,6 +51,8 @@ class CC_EXPORT PaintedOverlayScrollbarLayerImpl
track_ui_resource_id_ = uid; track_ui_resource_id_ = uid;
} }
bool HasFindInPageTickmarks() const override;
protected: protected:
PaintedOverlayScrollbarLayerImpl(LayerTreeImpl* tree_impl, PaintedOverlayScrollbarLayerImpl(LayerTreeImpl* tree_impl,
int id, int id,
......
...@@ -270,4 +270,8 @@ ScrollbarLayerImplBase::GetScrollbarAnimator() const { ...@@ -270,4 +270,8 @@ ScrollbarLayerImplBase::GetScrollbarAnimator() const {
return layer_tree_impl()->settings().scrollbar_animator; return layer_tree_impl()->settings().scrollbar_animator;
} }
bool ScrollbarLayerImplBase::HasFindInPageTickmarks() const {
return false;
}
} // namespace cc } // namespace cc
...@@ -64,6 +64,10 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { ...@@ -64,6 +64,10 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl {
virtual LayerTreeSettings::ScrollbarAnimator GetScrollbarAnimator() const; virtual LayerTreeSettings::ScrollbarAnimator GetScrollbarAnimator() const;
// Only PaintedOverlayScrollbar(Aura Overlay Scrollbar) need to know
// tickmarks's state.
virtual bool HasFindInPageTickmarks() const;
protected: protected:
ScrollbarLayerImplBase(LayerTreeImpl* tree_impl, ScrollbarLayerImplBase(LayerTreeImpl* tree_impl,
int id, int id,
......
...@@ -505,9 +505,33 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { ...@@ -505,9 +505,33 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
target_tree->has_ever_been_drawn_ = false; target_tree->has_ever_been_drawn_ = false;
// Note: this needs to happen after SetPropertyTrees. // Note: this needs to happen after SetPropertyTrees.
target_tree->HandleTickmarksVisibilityChange();
target_tree->HandleScrollbarShowRequestsFromMain(); target_tree->HandleScrollbarShowRequestsFromMain();
} }
void LayerTreeImpl::HandleTickmarksVisibilityChange() {
if (!host_impl_->ViewportMainScrollLayer())
return;
ScrollbarAnimationController* controller =
host_impl_->ScrollbarAnimationControllerForElementId(
OuterViewportScrollLayer()->element_id());
if (!controller)
return;
for (ScrollbarLayerImplBase* scrollbar : controller->Scrollbars()) {
if (scrollbar->orientation() != VERTICAL)
continue;
// Android Overlay Scrollbar don't have FindInPage Tickmarks.
if (scrollbar->GetScrollbarAnimator() != LayerTreeSettings::AURA_OVERLAY)
DCHECK(!scrollbar->HasFindInPageTickmarks());
controller->UpdateTickmarksVisibility(scrollbar->HasFindInPageTickmarks());
}
}
void LayerTreeImpl::HandleScrollbarShowRequestsFromMain() { void LayerTreeImpl::HandleScrollbarShowRequestsFromMain() {
LayerTreeHostCommon::CallFunctionForEveryLayer(this, [this]( LayerTreeHostCommon::CallFunctionForEveryLayer(this, [this](
LayerImpl* layer) { LayerImpl* layer) {
......
...@@ -551,6 +551,8 @@ class CC_EXPORT LayerTreeImpl { ...@@ -551,6 +551,8 @@ class CC_EXPORT LayerTreeImpl {
void ClearLayerList(); void ClearLayerList();
void BuildLayerListForTesting(); void BuildLayerListForTesting();
void HandleTickmarksVisibilityChange();
void HandleScrollbarShowRequestsFromMain(); void HandleScrollbarShowRequestsFromMain();
void InvalidateRegionForImages( void InvalidateRegionForImages(
......
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