summaryrefslogtreecommitdiff
path: root/chromium/cc/input
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 13:57:45 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-19 13:44:40 +0000
commit6ec7b8da05d21a3878bd21c691b41e675d74bb1c (patch)
treeb87f250bc19413750b9bb9cdbf2da20ef5014820 /chromium/cc/input
parentec02ee4181c49b61fce1c8fb99292dbb8139cc90 (diff)
downloadqtwebengine-chromium-6ec7b8da05d21a3878bd21c691b41e675d74bb1c.tar.gz
BASELINE: Update Chromium to 60.0.3112.70
Change-Id: I9911c2280a014d4632f254857876a395d4baed2d Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/cc/input')
-rw-r--r--chromium/cc/input/browser_controls_offset_manager.h4
-rw-r--r--chromium/cc/input/main_thread_scrolling_reason.h10
-rw-r--r--chromium/cc/input/scrollbar_animation_controller.cc189
-rw-r--r--chromium/cc/input/scrollbar_animation_controller.h52
-rw-r--r--chromium/cc/input/scrollbar_animation_controller_unittest.cc418
-rw-r--r--chromium/cc/input/scroller_size_metrics.h20
-rw-r--r--chromium/cc/input/single_scrollbar_animation_controller_thinning.cc103
-rw-r--r--chromium/cc/input/single_scrollbar_animation_controller_thinning.h28
-rw-r--r--chromium/cc/input/single_scrollbar_animation_controller_thinning_unittest.cc89
-rw-r--r--chromium/cc/input/touch_action.h56
10 files changed, 646 insertions, 323 deletions
diff --git a/chromium/cc/input/browser_controls_offset_manager.h b/chromium/cc/input/browser_controls_offset_manager.h
index 88e76fa113d..ae4d9e4268f 100644
--- a/chromium/cc/input/browser_controls_offset_manager.h
+++ b/chromium/cc/input/browser_controls_offset_manager.h
@@ -8,7 +8,6 @@
#include <memory>
#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "cc/input/browser_controls_state.h"
#include "cc/layers/layer_impl.h"
@@ -20,8 +19,7 @@ namespace cc {
class BrowserControlsOffsetManagerClient;
// Manages the position of the browser controls.
-class CC_EXPORT BrowserControlsOffsetManager
- : public base::SupportsWeakPtr<BrowserControlsOffsetManager> {
+class CC_EXPORT BrowserControlsOffsetManager {
public:
enum AnimationDirection { NO_ANIMATION, SHOWING_CONTROLS, HIDING_CONTROLS };
diff --git a/chromium/cc/input/main_thread_scrolling_reason.h b/chromium/cc/input/main_thread_scrolling_reason.h
index a8c586eee95..e7d88471aff 100644
--- a/chromium/cc/input/main_thread_scrolling_reason.h
+++ b/chromium/cc/input/main_thread_scrolling_reason.h
@@ -44,7 +44,8 @@ struct MainThreadScrollingReason {
kHasBorderRadius = 1 << 19,
kHasClipRelatedProperty = 1 << 20,
kHasBoxShadowFromNonRootLayer = 1 << 21,
- kNonCompositedReasonsLast = 21,
+ kIsNotStackingContextAndLCDText = 1 << 22,
+ kNonCompositedReasonsLast = 22,
// Transient scrolling reasons. These are computed for each scroll begin.
kNonFastScrollableRegion = 1 << 5,
@@ -59,13 +60,14 @@ struct MainThreadScrollingReason {
// New flags should increment this number but it should never be decremented
// because the values are used in UMA histograms. It should also be noted
// that it excludes the kNotScrollingOnMain value.
- kMainThreadScrollingReasonCount = 22,
+ kMainThreadScrollingReasonCount = 23,
};
static const uint32_t kNonCompositedReasons =
kHasOpacityAndLCDText | kHasTransformAndLCDText |
kBackgroundNotOpaqueInRectAndLCDText | kHasBorderRadius |
- kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer;
+ kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer |
+ kIsNotStackingContextAndLCDText;
// Returns true if the given MainThreadScrollingReason can be set by the main
// thread.
@@ -140,6 +142,8 @@ struct MainThreadScrollingReason {
tracedValue->AppendString("Has clip related property");
if (reasons & MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer)
tracedValue->AppendString("Has box shadow from non-root layer");
+ if (reasons & MainThreadScrollingReason::kIsNotStackingContextAndLCDText)
+ tracedValue->AppendString("Is not stacking context and LCD text");
// Transient scrolling reasons.
if (reasons & MainThreadScrollingReason::kNonFastScrollableRegion)
diff --git a/chromium/cc/input/scrollbar_animation_controller.cc b/chromium/cc/input/scrollbar_animation_controller.cc
index 8fb3c25a48b..6234d3ce53f 100644
--- a/chromium/cc/input/scrollbar_animation_controller.cc
+++ b/chromium/cc/input/scrollbar_animation_controller.cc
@@ -13,86 +13,82 @@ namespace cc {
std::unique_ptr<ScrollbarAnimationController>
ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
- base::TimeDelta fade_duration) {
- return base::WrapUnique(
- new ScrollbarAnimationController(scroll_layer_id, client, fade_delay,
- fade_out_resize_delay, fade_duration));
+ base::TimeDelta fade_duration,
+ float initial_opacity) {
+ return base::WrapUnique(new ScrollbarAnimationController(
+ scroll_element_id, client, fade_delay, fade_duration, initial_opacity));
}
std::unique_ptr<ScrollbarAnimationController>
ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
base::TimeDelta fade_duration,
- base::TimeDelta thinning_duration) {
+ base::TimeDelta thinning_duration,
+ float initial_opacity) {
return base::WrapUnique(new ScrollbarAnimationController(
- scroll_layer_id, client, fade_delay, fade_out_resize_delay,
- fade_duration, thinning_duration));
+ scroll_element_id, client, fade_delay, fade_duration, thinning_duration,
+ initial_opacity));
}
ScrollbarAnimationController::ScrollbarAnimationController(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
- base::TimeDelta fade_duration)
+ base::TimeDelta fade_duration,
+ float initial_opacity)
: client_(client),
fade_delay_(fade_delay),
- fade_out_resize_delay_(fade_out_resize_delay),
fade_duration_(fade_duration),
- need_trigger_scrollbar_show_(false),
+ need_trigger_scrollbar_fade_in_(false),
is_animating_(false),
animation_change_(NONE),
- scroll_layer_id_(scroll_layer_id),
+ scroll_element_id_(scroll_element_id),
currently_scrolling_(false),
show_in_fast_scroll_(false),
- opacity_(0.0f),
+ opacity_(initial_opacity),
show_scrollbars_on_scroll_gesture_(false),
need_thinning_animation_(false),
- weak_factory_(this) {
- ApplyOpacityToScrollbars(0.0f);
-}
+ is_mouse_down_(false),
+ weak_factory_(this) {}
ScrollbarAnimationController::ScrollbarAnimationController(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
base::TimeDelta fade_duration,
- base::TimeDelta thinning_duration)
+ base::TimeDelta thinning_duration,
+ float initial_opacity)
: client_(client),
fade_delay_(fade_delay),
- fade_out_resize_delay_(fade_out_resize_delay),
fade_duration_(fade_duration),
- need_trigger_scrollbar_show_(false),
+ need_trigger_scrollbar_fade_in_(false),
is_animating_(false),
animation_change_(NONE),
- scroll_layer_id_(scroll_layer_id),
+ scroll_element_id_(scroll_element_id),
currently_scrolling_(false),
show_in_fast_scroll_(false),
- opacity_(0.0f),
+ 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_layer_id, ScrollbarOrientation::VERTICAL, client,
+ scroll_element_id, ScrollbarOrientation::VERTICAL, client,
thinning_duration);
horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
- scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
+ scroll_element_id, ScrollbarOrientation::HORIZONTAL, client,
thinning_duration);
- ApplyOpacityToScrollbars(0.0f);
}
ScrollbarAnimationController::~ScrollbarAnimationController() {}
ScrollbarSet ScrollbarAnimationController::Scrollbars() const {
- return client_->ScrollbarsFor(scroll_layer_id_);
+ return client_->ScrollbarsFor(scroll_element_id_);
}
SingleScrollbarAnimationControllerThinning&
@@ -108,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();
@@ -115,23 +112,20 @@ void ScrollbarAnimationController::StartAnimation() {
void ScrollbarAnimationController::StopAnimation() {
delayed_scrollbar_animation_.Cancel();
+ need_trigger_scrollbar_fade_in_ = false;
is_animating_ = false;
animation_change_ = NONE;
}
void ScrollbarAnimationController::PostDelayedAnimation(
- AnimationChange animation_change,
- bool on_resize) {
+ AnimationChange animation_change) {
animation_change_ = animation_change;
-
- base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_delay_;
-
delayed_scrollbar_animation_.Cancel();
delayed_scrollbar_animation_.Reset(
base::Bind(&ScrollbarAnimationController::StartAnimation,
weak_factory_.GetWeakPtr()));
client_->PostDelayedScrollbarAnimationTask(
- delayed_scrollbar_animation_.callback(), delay);
+ delayed_scrollbar_animation_.callback(), fade_delay_);
}
bool ScrollbarAnimationController::Animate(base::TimeTicks now) {
@@ -196,7 +190,7 @@ void ScrollbarAnimationController::DidScrollEnd() {
return;
if (has_scrolled)
- PostDelayedAnimation(FADE_OUT, false);
+ PostDelayedAnimation(FADE_OUT);
}
void ScrollbarAnimationController::DidScrollUpdate() {
@@ -213,7 +207,7 @@ void ScrollbarAnimationController::DidScrollUpdate() {
// We don't fade out scrollbar if they need thinning animation and mouse is
// near.
if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar())
- PostDelayedAnimation(FADE_OUT, false);
+ PostDelayedAnimation(FADE_OUT);
} else {
show_in_fast_scroll_ = true;
}
@@ -230,39 +224,46 @@ void ScrollbarAnimationController::WillUpdateScroll() {
}
void ScrollbarAnimationController::DidRequestShowFromMainThread() {
- // TODO(skobes): Call DidScrollUpdate here (suppressed for crbug.com/706927).
+ DidScrollUpdate();
}
-void ScrollbarAnimationController::DidResize() {
- StopAnimation();
- Show();
+void ScrollbarAnimationController::DidMouseDown() {
+ if (!need_thinning_animation_)
+ return;
- // As an optimization, we avoid spamming fade delay tasks during active fast
- // scrolls.
- if (!currently_scrolling_) {
- PostDelayedAnimation(FADE_OUT, true);
- } else {
- show_in_fast_scroll_ = true;
- }
-}
+ is_mouse_down_ = true;
-void ScrollbarAnimationController::DidMouseDown() {
- if (!need_thinning_animation_ || ScrollbarsHidden())
+ 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())
- PostDelayedAnimation(FADE_OUT, false);
+ if (!MouseIsNearAnyScrollbar() && !ScrollbarsHidden())
+ PostDelayedAnimation(FADE_OUT);
}
void ScrollbarAnimationController::DidMouseLeave() {
@@ -273,34 +274,39 @@ void ScrollbarAnimationController::DidMouseLeave() {
horizontal_controller_->DidMouseLeave();
delayed_scrollbar_animation_.Cancel();
- need_trigger_scrollbar_show_ = false;
+ need_trigger_scrollbar_fade_in_ = false;
if (ScrollbarsHidden() || Captured())
return;
- PostDelayedAnimation(FADE_OUT, false);
+ PostDelayedAnimation(FADE_OUT);
}
-void ScrollbarAnimationController::DidMouseMoveNear(
- ScrollbarOrientation orientation,
- float distance) {
+void ScrollbarAnimationController::DidMouseMove(
+ const gfx::PointF& device_viewport_point) {
if (!need_thinning_animation_)
return;
- bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_;
+ bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_;
- GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
+ vertical_controller_->DidMouseMove(device_viewport_point);
+ horizontal_controller_->DidMouseMove(device_viewport_point);
- need_trigger_scrollbar_show_ =
- CalcNeedTriggerScrollbarShow(orientation, distance);
-
- if (Captured())
+ if (Captured()) {
+ DCHECK(!ScrollbarsHidden());
return;
+ }
if (ScrollbarsHidden()) {
- if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) {
- if (need_trigger_scrollbar_show_) {
- PostDelayedAnimation(FADE_IN, false);
+ // 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_) {
+ PostDelayedAnimation(FADE_IN);
} else {
delayed_scrollbar_animation_.Cancel();
}
@@ -310,47 +316,36 @@ void ScrollbarAnimationController::DidMouseMoveNear(
Show();
StopAnimation();
} else if (!is_animating_) {
- PostDelayedAnimation(FADE_OUT, false);
+ PostDelayedAnimation(FADE_OUT);
}
}
}
-bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow(
- ScrollbarOrientation orientation,
- float distance) const {
+bool ScrollbarAnimationController::MouseIsOverScrollbarThumb(
+ ScrollbarOrientation orientation) const {
DCHECK(need_thinning_animation_);
-
- if (vertical_controller_->mouse_is_over_scrollbar() ||
- horizontal_controller_->mouse_is_over_scrollbar())
- return true;
-
- for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
- if (scrollbar->orientation() != orientation)
- continue;
-
- if (distance < kMouseMoveDistanceToTriggerFadeIn)
- return true;
- }
-
- return false;
+ return GetScrollbarAnimationController(orientation)
+ .mouse_is_over_scrollbar_thumb();
}
-bool ScrollbarAnimationController::MouseIsOverScrollbar(
+bool ScrollbarAnimationController::MouseIsNearScrollbarThumb(
ScrollbarOrientation orientation) const {
DCHECK(need_thinning_animation_);
- return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar();
+ return GetScrollbarAnimationController(orientation)
+ .mouse_is_near_scrollbar_thumb();
}
bool ScrollbarAnimationController::MouseIsNearScrollbar(
ScrollbarOrientation orientation) const {
DCHECK(need_thinning_animation_);
- return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar();
+ return GetScrollbarAnimationController(orientation)
+ .mouse_is_near_scrollbar_track();
}
bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const {
DCHECK(need_thinning_animation_);
- return vertical_controller_->mouse_is_near_scrollbar() ||
- horizontal_controller_->mouse_is_near_scrollbar();
+ return vertical_controller_->mouse_is_near_scrollbar_track() ||
+ horizontal_controller_->mouse_is_near_scrollbar_track();
}
bool ScrollbarAnimationController::ScrollbarsHidden() const {
@@ -359,7 +354,8 @@ bool ScrollbarAnimationController::ScrollbarsHidden() const {
bool ScrollbarAnimationController::Captured() const {
DCHECK(need_thinning_animation_);
- return vertical_controller_->captured() || horizontal_controller_->captured();
+ return GetScrollbarAnimationController(VERTICAL).captured() ||
+ GetScrollbarAnimationController(HORIZONTAL).captured();
}
void ScrollbarAnimationController::Show() {
@@ -369,8 +365,7 @@ void ScrollbarAnimationController::Show() {
void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) {
for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
- if (!scrollbar->is_overlay_scrollbar())
- continue;
+ DCHECK(scrollbar->is_overlay_scrollbar());
float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity);
}
diff --git a/chromium/cc/input/scrollbar_animation_controller.h b/chromium/cc/input/scrollbar_animation_controller.h
index 60676d95044..64bf2b6ac06 100644
--- a/chromium/cc/input/scrollbar_animation_controller.h
+++ b/chromium/cc/input/scrollbar_animation_controller.h
@@ -23,7 +23,7 @@ class CC_EXPORT ScrollbarAnimationControllerClient {
virtual void SetNeedsRedrawForScrollbarAnimation() = 0;
virtual void SetNeedsAnimateForScrollbarAnimation() = 0;
virtual void DidChangeScrollbarVisibility() = 0;
- virtual ScrollbarSet ScrollbarsFor(int scroll_layer_id) const = 0;
+ virtual ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const = 0;
protected:
virtual ~ScrollbarAnimationControllerClient() {}
@@ -41,22 +41,22 @@ class CC_EXPORT ScrollbarAnimationController {
// animation.
static std::unique_ptr<ScrollbarAnimationController>
CreateScrollbarAnimationControllerAndroid(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
- base::TimeDelta fade_duration);
+ base::TimeDelta fade_duration,
+ float initial_opacity);
// ScrollbarAnimationController for Desktop Overlay Scrollbar. It has show &
// fade out animation and thinning animation.
static std::unique_ptr<ScrollbarAnimationController>
CreateScrollbarAnimationControllerAuraOverlay(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
base::TimeDelta fade_duration,
- base::TimeDelta thinning_duration);
+ base::TimeDelta thinning_duration,
+ float initial_opacity);
~ScrollbarAnimationController();
@@ -72,46 +72,45 @@ class CC_EXPORT ScrollbarAnimationController {
// Effect both Android and Aura Overlay Scrollbar.
void DidScrollUpdate();
- // DidResize expects to be called when clip layer size changed or scroll layer
- // size changed.
- void DidResize();
-
void DidScrollBegin();
void DidScrollEnd();
void DidMouseDown();
void DidMouseUp();
void DidMouseLeave();
- void DidMouseMoveNear(ScrollbarOrientation, float);
+ void DidMouseMove(const gfx::PointF& device_viewport_point);
// Called when Blink wants to show the scrollbars (via
// ScrollableArea::showOverlayScrollbars).
void DidRequestShowFromMainThread();
- bool MouseIsOverScrollbar(ScrollbarOrientation orientation) const;
+ // These methods are public for testing.
+ bool MouseIsOverScrollbarThumb(ScrollbarOrientation orientation) const;
+ bool MouseIsNearScrollbarThumb(ScrollbarOrientation orientation) const;
bool MouseIsNearScrollbar(ScrollbarOrientation orientation) const;
bool MouseIsNearAnyScrollbar() const;
+ ScrollbarSet Scrollbars() const;
+
static constexpr float kMouseMoveDistanceToTriggerFadeIn = 30.0f;
private:
// Describes whether the current animation should FadeIn or FadeOut.
enum AnimationChange { NONE, FADE_IN, FADE_OUT };
- ScrollbarAnimationController(int scroll_layer_id,
+ ScrollbarAnimationController(ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
- base::TimeDelta fade_duration);
+ base::TimeDelta fade_duration,
+ float initial_opacity);
- ScrollbarAnimationController(int scroll_layer_id,
+ ScrollbarAnimationController(ElementId scroll_element_id,
ScrollbarAnimationControllerClient* client,
base::TimeDelta fade_delay,
- base::TimeDelta fade_out_resize_delay,
base::TimeDelta fade_duration,
- base::TimeDelta thinning_duration);
+ base::TimeDelta thinning_duration,
+ float initial_opacity);
- ScrollbarSet Scrollbars() const;
SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController(
ScrollbarOrientation) const;
@@ -125,13 +124,10 @@ class CC_EXPORT ScrollbarAnimationController {
void Show();
- void PostDelayedAnimation(AnimationChange animation_change, bool on_resize);
+ void PostDelayedAnimation(AnimationChange animation_change);
bool Captured() const;
- bool CalcNeedTriggerScrollbarShow(ScrollbarOrientation orientation,
- float distance) const;
-
void ApplyOpacityToScrollbars(float opacity);
ScrollbarAnimationControllerClient* client_;
@@ -139,16 +135,15 @@ class CC_EXPORT ScrollbarAnimationController {
base::TimeTicks last_awaken_time_;
base::TimeDelta fade_delay_;
- base::TimeDelta fade_out_resize_delay_;
base::TimeDelta fade_duration_;
- bool need_trigger_scrollbar_show_;
+ bool need_trigger_scrollbar_fade_in_;
bool is_animating_;
AnimationChange animation_change_;
- const int scroll_layer_id_;
+ const ElementId scroll_element_id_;
bool currently_scrolling_;
bool show_in_fast_scroll_;
@@ -158,6 +153,9 @@ 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>
diff --git a/chromium/cc/input/scrollbar_animation_controller_unittest.cc b/chromium/cc/input/scrollbar_animation_controller_unittest.cc
index ebb22757703..e7e4926c3e5 100644
--- a/chromium/cc/input/scrollbar_animation_controller_unittest.cc
+++ b/chromium/cc/input/scrollbar_animation_controller_unittest.cc
@@ -23,11 +23,11 @@ namespace {
const float kIdleThicknessScale =
SingleScrollbarAnimationControllerThinning::kIdleThicknessScale;
-const float kDefaultMouseMoveDistanceToTriggerAnimation =
- SingleScrollbarAnimationControllerThinning::
- kDefaultMouseMoveDistanceToTriggerAnimation;
const float kMouseMoveDistanceToTriggerFadeIn =
ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
+const float kMouseMoveDistanceToTriggerExpand =
+ SingleScrollbarAnimationControllerThinning::
+ kMouseMoveDistanceToTriggerExpand;
const int kThumbThickness = 10;
class MockScrollbarAnimationControllerClient
@@ -44,8 +44,8 @@ class MockScrollbarAnimationControllerClient
}
void SetNeedsRedrawForScrollbarAnimation() override {}
void SetNeedsAnimateForScrollbarAnimation() override {}
- ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override {
- return host_impl_->ScrollbarsFor(scroll_layer_id);
+ ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
+ return host_impl_->ScrollbarsFor(scroll_element_id);
}
MOCK_METHOD0(DidChangeScrollbarVisibility, void());
@@ -71,7 +71,6 @@ class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test {
protected:
const base::TimeDelta kFadeDelay = base::TimeDelta::FromSeconds(4);
- const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5);
const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3);
const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2);
@@ -81,10 +80,13 @@ class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test {
std::unique_ptr<LayerImpl> clip =
LayerImpl::Create(host_impl_.active_tree(), 2);
clip_layer_ = clip.get();
+ scroll_layer->SetElementId(
+ LayerIdToElementIdForTesting(scroll_layer->id()));
scroll_layer->SetScrollClipLayer(clip_layer_->id());
LayerImpl* scroll_layer_ptr = scroll_layer.get();
const int kTrackStart = 0;
+ const int kTrackLength = 100;
const bool kIsLeftSideVerticalScrollbar = false;
const bool kIsOverlayScrollbar = true;
@@ -92,10 +94,12 @@ class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test {
SolidColorScrollbarLayerImpl::Create(
host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness,
kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
+ h_scrollbar->test_properties()->opacity = 0.0f;
std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar =
SolidColorScrollbarLayerImpl::Create(
host_impl_.active_tree(), 4, VERTICAL, kThumbThickness, kTrackStart,
kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
+ v_scrollbar->test_properties()->opacity = 0.0f;
v_scrollbar_layer_ = v_scrollbar.get();
h_scrollbar_layer_ = h_scrollbar.get();
@@ -104,18 +108,48 @@ class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test {
clip_layer_->test_properties()->AddChild(std::move(scroll_layer));
host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
- v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
- h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
+ v_scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength));
+ v_scrollbar_layer_->SetPosition(gfx::PointF(90, 0));
+ v_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id());
v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
+
+ h_scrollbar_layer_->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
+ h_scrollbar_layer_->SetPosition(gfx::PointF(0, 90));
+ h_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id());
h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
+
clip_layer_->SetBounds(gfx::Size(100, 100));
scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
scrollbar_controller_ = ScrollbarAnimationController::
CreateScrollbarAnimationControllerAuraOverlay(
- scroll_layer_ptr->id(), &client_, kFadeDelay,
- kResizeFadeOutDelay, kFadeDuration, kThinningDuration);
+ scroll_layer_ptr->element_id(), &client_, kFadeDelay, kFadeDuration,
+ kThinningDuration, 0.0f);
+ v_scrollbar_layer_->SetCurrentPos(0);
+ h_scrollbar_layer_->SetCurrentPos(0);
+ }
+
+ // Return a point with given offset from the top-left of vertical scrollbar.
+ gfx::PointF NearVerticalScrollbarBegin(float offset_x, float offset_y) {
+ gfx::PointF p(90, 0);
+ p.Offset(offset_x, offset_y);
+ return p;
+ }
+
+ // Return a point with given offset from the bottom-left of vertical
+ // scrollbar.
+ gfx::PointF NearVerticalScrollbarEnd(float offset_x, float offset_y) {
+ gfx::PointF p(90, 90);
+ p.Offset(offset_x, offset_y);
+ return p;
+ }
+
+ // Return a point with given offset from the top-left of horizontal scrollbar.
+ gfx::PointF NearHorizontalScrollbarBegin(float offset_x, float offset_y) {
+ gfx::PointF p(0, 90);
+ p.Offset(offset_x, offset_y);
+ return p;
}
FakeImplTaskRunnerProvider task_runner_provider_;
@@ -257,8 +291,70 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
}
-// Scroll content. Move the mouse near the scrollbar and confirm it becomes
-// thick. Ensure it remains visible as long as the mouse is near the scrollbar.
+// Scroll content. Move the mouse near the scrollbar track but not near thumb
+// and confirm it stay thin. Move the mouse near the scrollbar thumb and
+// confirm it becomes thick.
+TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
+ MoveNearTrackThenNearThumb) {
+ base::TimeTicks time;
+ time += base::TimeDelta::FromSeconds(1);
+
+ scrollbar_controller_->DidScrollBegin();
+ scrollbar_controller_->DidScrollUpdate();
+ scrollbar_controller_->DidScrollEnd();
+
+ // An fade out animation should have been enqueued.
+ EXPECT_EQ(kFadeDelay, client_.delay());
+ EXPECT_FALSE(client_.start_fade().is_null());
+ EXPECT_FALSE(client_.start_fade().IsCancelled());
+
+ // Now move the mouse near the vertical scrollbar track. This should cancel
+ // the currently queued fading animation and stay scrollbar thin.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarEnd(-1, 0));
+ ExpectScrollbarsOpacity(1);
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ v_scrollbar_layer_->thumb_thickness_scale_factor());
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ h_scrollbar_layer_->thumb_thickness_scale_factor());
+ EXPECT_TRUE(client_.start_fade().IsCancelled());
+
+ scrollbar_controller_->Animate(time);
+ time += kThinningDuration;
+ scrollbar_controller_->Animate(time);
+
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ v_scrollbar_layer_->thumb_thickness_scale_factor());
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ h_scrollbar_layer_->thumb_thickness_scale_factor());
+
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
+ scrollbar_controller_->Animate(time);
+ time += kThinningDuration;
+ scrollbar_controller_->Animate(time);
+
+ EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ h_scrollbar_layer_->thumb_thickness_scale_factor());
+
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarEnd(-1, 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().IsCancelled());
+
+ scrollbar_controller_->Animate(time);
+ time += kThinningDuration;
+ scrollbar_controller_->Animate(time);
+
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ v_scrollbar_layer_->thumb_thickness_scale_factor());
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ h_scrollbar_layer_->thumb_thickness_scale_factor());
+}
+
+// Scroll content. Move the mouse near the scrollbar thumb and confirm it
+// becomes thick. Ensure it remains visible as long as the mouse is near the
+// scrollbar.
TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
@@ -272,9 +368,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) {
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse near the scrollbar. This should cancel the currently
- // queued fading animation and start animating thickness.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
+ // Now move the mouse near the vertical scrollbar thumb. This should cancel
+ // the currently queued fading animation and start animating thickness.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -313,9 +409,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) {
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the scrollbar. This should cancel the currently
- // queued fading animation and start animating thickness.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Now move the mouse over the vertical scrollbar thumb. This should cancel
+ // the currently queued fading animation and start animating thickness.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -354,9 +450,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_EQ(kFadeDelay, client_.delay());
EXPECT_FALSE(client_.start_fade().is_null());
- // Now move the mouse over the scrollbar and capture it. It should become
- // thick without need for an animation.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Now move the mouse over the vertical scrollbar thumb and capture it. It
+ // should become thick without need for an animation.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
scrollbar_controller_->DidMouseDown();
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -382,9 +478,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_EQ(kFadeDelay, client_.delay());
EXPECT_FALSE(client_.start_fade().is_null());
- // Now move the mouse over the scrollbar and capture it. It should become
- // thick without need for an animation.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Now move the mouse over the vertical scrollbar and capture it. It should
+ // become thick without need for an animation.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
scrollbar_controller_->DidMouseDown();
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -397,8 +493,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
// Then move mouse away, The fade out animation should have been cleared or
// cancelled.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerExpand, 0));
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
@@ -419,8 +515,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) {
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the scrollbar and animate it until it's thick.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Now move the mouse over the vertical scrollbar thumb and animate it until
+ // it's thick.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -456,8 +553,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) {
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the scrollbar and capture it.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Now move the mouse over the vertical scrollbar thumb and capture it.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
scrollbar_controller_->DidMouseDown();
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -470,8 +567,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) {
client_.start_fade().IsCancelled());
// Now move the mouse away from the scrollbar and release it.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn, 0));
scrollbar_controller_->DidMouseUp();
scrollbar_controller_->Animate(time);
@@ -507,8 +604,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) {
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the scrollbar and capture it.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Now move the mouse over the vertical scrollbar thumb and capture it.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
scrollbar_controller_->DidMouseDown();
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -554,9 +651,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
scrollbar_controller_->Animate(time);
ExpectScrollbarsOpacity(.5f);
- // Now move the mouse near the scrollbar. It should reset opacity to 1
- // instantly and start animating to thick.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
+ // Now move the mouse near the vertical scrollbar thumb. It should reset
+ // opacity to 1 instantly and start animating to thick.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
v_scrollbar_layer_->thumb_thickness_scale_factor());
@@ -593,9 +690,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) {
scrollbar_controller_->Animate(time);
ExpectScrollbarsOpacity(0);
- // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since
- // it's completely faded out.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
+ // Move mouse over the vertical scrollbar thumb. It shouldn't thicken the
+ // scrollbar since it's completely faded out.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -615,13 +712,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
@@ -630,7 +742,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
@@ -693,27 +805,6 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_EQ(kFadeDelay, client_.delay());
}
-// Make sure that if the scroll update is as a result of a resize, we use the
-// resize delay time instead of the default one.
-TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) {
- ASSERT_TRUE(client_.delay().is_zero());
-
- scrollbar_controller_->DidResize();
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kResizeFadeOutDelay, client_.delay());
-
- client_.delay() = base::TimeDelta();
-
- // We should use the gesture delay rather than the resize delay if we're in a
- // gesture scroll, even if it is resizing.
- scrollbar_controller_->DidScrollBegin();
- scrollbar_controller_->DidResize();
- scrollbar_controller_->DidScrollEnd();
-
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kFadeDelay, client_.delay());
-}
-
// Tests that the fade effect is animated.
TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) {
base::TimeTicks time;
@@ -804,8 +895,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
scrollbar_controller_->DidScrollUpdate();
scrollbar_controller_->DidScrollEnd();
- // Near vertical scrollbar
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
+ // Near vertical scrollbar.
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
scrollbar_controller_->Animate(time);
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
@@ -822,7 +913,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
h_scrollbar_layer_->thumb_thickness_scale_factor());
// Subsequent moves within the nearness threshold should not change anything.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 2);
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-2, 0));
scrollbar_controller_->Animate(time);
time += base::TimeDelta::FromSeconds(10);
scrollbar_controller_->Animate(time);
@@ -832,8 +923,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
h_scrollbar_layer_->thumb_thickness_scale_factor());
// Now move away from bar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerExpand, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -844,7 +935,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
h_scrollbar_layer_->thumb_thickness_scale_factor());
// Near horizontal scrollbar
- scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 2);
+ scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(0, -1));
scrollbar_controller_->Animate(time);
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
@@ -861,7 +952,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
// Subsequent moves within the nearness threshold should not change anything.
- scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
+ scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(0, -2));
scrollbar_controller_->Animate(time);
time += base::TimeDelta::FromSeconds(10);
scrollbar_controller_->Animate(time);
@@ -871,8 +962,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
// Now move away from bar.
- scrollbar_controller_->DidMouseMoveNear(
- HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearHorizontalScrollbarBegin(0, -kMouseMoveDistanceToTriggerExpand));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -897,9 +988,12 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) {
scrollbar_controller_->DidScrollUpdate();
scrollbar_controller_->DidScrollEnd();
+ // Move scrollbar thumb to the end of track.
+ v_scrollbar_layer_->SetCurrentPos(100);
+ h_scrollbar_layer_->SetCurrentPos(100);
+
// Near both Scrollbar
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
- scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarEnd(-1, -1));
scrollbar_controller_->Animate(time);
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
@@ -928,7 +1022,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
scrollbar_controller_->DidScrollEnd();
// Near vertical scrollbar.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
scrollbar_controller_->Animate(time);
ExpectScrollbarsOpacity(1);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
@@ -946,9 +1040,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
h_scrollbar_layer_->thumb_thickness_scale_factor());
// Away vertical scrollbar and near horizontal scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation);
- scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
+ scrollbar_controller_->DidMouseMove(gfx::PointF(0, 0));
+ scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(0, -1));
scrollbar_controller_->Animate(time);
// Vertical scrollbar animate to thin. horizontal scrollbar animate to
@@ -961,8 +1054,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
// Away horizontal scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(gfx::PointF(0, 0));
scrollbar_controller_->Animate(time);
// Horizontal scrollbar animate to thin.
@@ -986,7 +1078,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) {
time += base::TimeDelta::FromSeconds(1);
// Move mouse near scrollbar.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
+ scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
// Scroll to make the scrollbars visible.
scrollbar_controller_->DidScrollBegin();
@@ -1011,9 +1103,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- // Move mouse hover the fade in scrollbar region of scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 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());
@@ -1045,9 +1137,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- // Move mouse hover the fade in scrollbar region of scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 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());
@@ -1055,10 +1147,10 @@ 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_->DidMouseMoveNear(
- VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 2);
+ scrollbar_controller_->DidMouseMove(
+ NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 2, 0));
EXPECT_TRUE(fade.Equals(client_.start_fade()));
}
@@ -1070,9 +1162,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- // Move mouse hover the fade in scrollbar region of scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 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());
@@ -1080,8 +1172,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_EQ(kFadeDelay, client_.delay());
// Move mouse far away,delay fade in should be canceled.
- scrollbar_controller_->DidMouseMoveNear(VERTICAL,
- kMouseMoveDistanceToTriggerFadeIn);
+ scrollbar_controller_->DidMouseMove(
+ NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn, 0));
+
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
}
@@ -1093,9 +1186,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- // Move mouse hover the fade in scrollbar region of scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 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());
@@ -1107,9 +1200,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
- // Move mouse hover the fade in scrollbar region of scrollbar.
- scrollbar_controller_->DidMouseMoveNear(
- VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 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());
@@ -1127,6 +1220,94 @@ 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 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());
+ 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 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 {
@@ -1147,8 +1328,8 @@ class ScrollbarAnimationControllerAndroidTest
void SetNeedsAnimateForScrollbarAnimation() override {
did_request_animate_ = true;
}
- ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override {
- return host_impl_.ScrollbarsFor(scroll_layer_id);
+ ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
+ return host_impl_.ScrollbarsFor(scroll_element_id);
}
void DidChangeScrollbarVisibility() override {}
@@ -1164,26 +1345,31 @@ class ScrollbarAnimationControllerAndroidTest
SolidColorScrollbarLayerImpl::Create(
host_impl_.active_tree(), 2, orientation(), kThumbThickness,
kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
+ scrollbar->test_properties()->opacity = 0.0f;
scrollbar_layer_ = scrollbar.get();
scrollbar_layer_->test_properties()->opacity_can_animate = true;
std::unique_ptr<LayerImpl> clip =
LayerImpl::Create(host_impl_.active_tree(), 3);
clip_layer_ = clip.get();
+ scroll_layer->SetElementId(
+ LayerIdToElementIdForTesting(scroll_layer->id()));
+
scroll_layer->SetScrollClipLayer(clip_layer_->id());
LayerImpl* scroll_layer_ptr = scroll_layer.get();
scroll_layer->test_properties()->AddChild(std::move(scrollbar));
clip->test_properties()->AddChild(std::move(scroll_layer));
host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
- scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
+ scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id());
clip_layer_->SetBounds(gfx::Size(100, 100));
scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
scrollbar_controller_ =
ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid(
- scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2),
- base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3));
+ scroll_layer_ptr->element_id(), this,
+ base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3),
+ 0.0f);
}
virtual ScrollbarOrientation orientation() const { return HORIZONTAL; }
@@ -1207,24 +1393,6 @@ class VerticalScrollbarAnimationControllerAndroidTest
ScrollbarOrientation orientation() const override { return VERTICAL; }
};
-TEST_F(ScrollbarAnimationControllerAndroidTest, DelayAnimationOnResize) {
- scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f);
- // We should use the gesture delay rather than the resize delay if we're in a
- // gesture scroll, even if it is resizing.
- scrollbar_controller_->DidScrollBegin();
- scrollbar_controller_->DidResize();
- scrollbar_controller_->DidScrollEnd();
- // Normal Animation delay of 2 seconds.
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2));
-
- scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f);
- scrollbar_controller_->DidResize();
- // Delay animation on resize to 5 seconds.
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(5));
-}
-
TEST_F(ScrollbarAnimationControllerAndroidTest, HiddenInBegin) {
scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f);
scrollbar_controller_->Animate(base::TimeTicks());
diff --git a/chromium/cc/input/scroller_size_metrics.h b/chromium/cc/input/scroller_size_metrics.h
new file mode 100644
index 00000000000..c805934522e
--- /dev/null
+++ b/chromium/cc/input/scroller_size_metrics.h
@@ -0,0 +1,20 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_INPUT_SCROLLER_SIZE_METRICS_H_
+#define CC_INPUT_SCROLLER_SIZE_METRICS_H_
+
+namespace cc {
+
+// Use the two constants to add scroller size related UMA metrics.
+// The goal of the metrics is to find the frequency of scrollers of
+// different sizes that get scrolled. This experiment is aiming at small
+// scrollers therefore the big ones, e.g. larger than 400px * 500px, will get
+// capped into one bucket.
+static constexpr int kScrollerSizeLargestBucket = 200000;
+static constexpr int kScrollerSizeBucketCount = 50;
+
+} // namespace cc
+
+#endif // CC_INPUT_SCROLLER_SIZE_METRICS_H_
diff --git a/chromium/cc/input/single_scrollbar_animation_controller_thinning.cc b/chromium/cc/input/single_scrollbar_animation_controller_thinning.cc
index d09dd054310..0515aaff879 100644
--- a/chromium/cc/input/single_scrollbar_animation_controller_thinning.cc
+++ b/chromium/cc/input/single_scrollbar_animation_controller_thinning.cc
@@ -15,34 +15,69 @@
namespace cc {
+namespace {
+
+float DistanceToScrollbarPart(const gfx::PointF& device_viewport_point,
+ const ScrollbarLayerImplBase& scrollbar,
+ const ScrollbarPart part) {
+ gfx::RectF rect;
+ if (part == ScrollbarPart::THUMB) {
+ rect = gfx::RectF(gfx::Rect(scrollbar.ComputeExpandedThumbQuadRect()));
+ } else {
+ rect = gfx::RectF(gfx::Rect(scrollbar.bounds()));
+ }
+
+ gfx::RectF device_viewport_rect =
+ MathUtil::MapClippedRect(scrollbar.ScreenSpaceTransform(), rect);
+
+ return device_viewport_rect.ManhattanDistanceToPoint(device_viewport_point) /
+ scrollbar.layer_tree_impl()->device_scale_factor();
+}
+
+} // namespace
+
std::unique_ptr<SingleScrollbarAnimationControllerThinning>
SingleScrollbarAnimationControllerThinning::Create(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
base::TimeDelta thinning_duration) {
return base::WrapUnique(new SingleScrollbarAnimationControllerThinning(
- scroll_layer_id, orientation, client, thinning_duration));
+ scroll_element_id, orientation, client, thinning_duration));
}
SingleScrollbarAnimationControllerThinning::
SingleScrollbarAnimationControllerThinning(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
base::TimeDelta thinning_duration)
: client_(client),
is_animating_(false),
- scroll_layer_id_(scroll_layer_id),
+ scroll_element_id_(scroll_element_id),
orientation_(orientation),
captured_(false),
- mouse_is_over_scrollbar_(false),
- mouse_is_near_scrollbar_(false),
+ mouse_is_over_scrollbar_thumb_(false),
+ mouse_is_near_scrollbar_thumb_(false),
+ mouse_is_near_scrollbar_track_(false),
thickness_change_(NONE),
thinning_duration_(thinning_duration) {
ApplyThumbThicknessScale(kIdleThicknessScale);
}
+ScrollbarLayerImplBase*
+SingleScrollbarAnimationControllerThinning::GetScrollbar() const {
+ for (ScrollbarLayerImplBase* scrollbar :
+ client_->ScrollbarsFor(scroll_element_id_)) {
+ DCHECK(scrollbar->is_overlay_scrollbar());
+
+ if (scrollbar->orientation() == orientation_)
+ return scrollbar;
+ }
+
+ return nullptr;
+}
+
bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
if (!is_animating_)
return false;
@@ -92,7 +127,7 @@ void SingleScrollbarAnimationControllerThinning::StopAnimation() {
}
void SingleScrollbarAnimationControllerThinning::DidMouseDown() {
- if (!mouse_is_over_scrollbar_)
+ if (!mouse_is_over_scrollbar_thumb_)
return;
StopAnimation();
@@ -107,7 +142,7 @@ void SingleScrollbarAnimationControllerThinning::DidMouseUp() {
captured_ = false;
StopAnimation();
- if (!mouse_is_near_scrollbar_) {
+ if (!mouse_is_near_scrollbar_thumb_) {
thickness_change_ = DECREASE;
StartAnimation();
} else {
@@ -116,11 +151,12 @@ void SingleScrollbarAnimationControllerThinning::DidMouseUp() {
}
void SingleScrollbarAnimationControllerThinning::DidMouseLeave() {
- if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
+ if (!mouse_is_over_scrollbar_thumb_ && !mouse_is_near_scrollbar_thumb_)
return;
- mouse_is_over_scrollbar_ = false;
- mouse_is_near_scrollbar_ = false;
+ mouse_is_over_scrollbar_thumb_ = false;
+ mouse_is_near_scrollbar_thumb_ = false;
+ mouse_is_near_scrollbar_track_ = false;
if (captured_)
return;
@@ -129,24 +165,39 @@ void SingleScrollbarAnimationControllerThinning::DidMouseLeave() {
StartAnimation();
}
-void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear(
- float distance) {
- bool mouse_is_over_scrollbar = distance == 0.0f;
- bool mouse_is_near_scrollbar =
- distance < kDefaultMouseMoveDistanceToTriggerAnimation;
+void SingleScrollbarAnimationControllerThinning::DidMouseMove(
+ const gfx::PointF& device_viewport_point) {
+ ScrollbarLayerImplBase* scrollbar = GetScrollbar();
+
+ if (!scrollbar)
+ return;
+
+ float distance_to_scrollbar_track = DistanceToScrollbarPart(
+ device_viewport_point, *scrollbar, ScrollbarPart::TRACK);
+ float distance_to_scrollbar_thumb = DistanceToScrollbarPart(
+ device_viewport_point, *scrollbar, ScrollbarPart::THUMB);
+
+ mouse_is_near_scrollbar_track_ =
+ distance_to_scrollbar_track <
+ ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
+
+ bool mouse_is_over_scrollbar_thumb = distance_to_scrollbar_thumb == 0.0f;
+ bool mouse_is_near_scrollbar_thumb =
+ distance_to_scrollbar_thumb < kMouseMoveDistanceToTriggerExpand;
- if (!captured_ && mouse_is_near_scrollbar != mouse_is_near_scrollbar_) {
- thickness_change_ = mouse_is_near_scrollbar ? INCREASE : DECREASE;
+ if (!captured_ &&
+ mouse_is_near_scrollbar_thumb != mouse_is_near_scrollbar_thumb_) {
+ thickness_change_ = mouse_is_near_scrollbar_thumb ? INCREASE : DECREASE;
StartAnimation();
}
- mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
- mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
+ mouse_is_near_scrollbar_thumb_ = mouse_is_near_scrollbar_thumb;
+ mouse_is_over_scrollbar_thumb_ = mouse_is_over_scrollbar_thumb;
}
float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
float progress) {
if (thickness_change_ == NONE)
- return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale;
+ return mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale;
float factor = thickness_change_ == INCREASE ? progress : (1.f - progress);
return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
}
@@ -173,18 +224,16 @@ float SingleScrollbarAnimationControllerThinning::AdjustScale(
void SingleScrollbarAnimationControllerThinning::UpdateThumbThicknessScale() {
StopAnimation();
- ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f
- : kIdleThicknessScale);
+ ApplyThumbThicknessScale(
+ mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale);
}
void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
float thumb_thickness_scale) {
- for (ScrollbarLayerImplBase* scrollbar :
- client_->ScrollbarsFor(scroll_layer_id_)) {
+ for (auto* scrollbar : client_->ScrollbarsFor(scroll_element_id_)) {
if (scrollbar->orientation() != orientation_)
continue;
- if (!scrollbar->is_overlay_scrollbar())
- continue;
+ DCHECK(scrollbar->is_overlay_scrollbar());
float scale = AdjustScale(thumb_thickness_scale,
scrollbar->thumb_thickness_scale_factor(),
diff --git a/chromium/cc/input/single_scrollbar_animation_controller_thinning.h b/chromium/cc/input/single_scrollbar_animation_controller_thinning.h
index 32ba069a12b..20c06835b3e 100644
--- a/chromium/cc/input/single_scrollbar_animation_controller_thinning.h
+++ b/chromium/cc/input/single_scrollbar_animation_controller_thinning.h
@@ -23,18 +23,26 @@ class ScrollbarAnimationControllerClient;
class CC_EXPORT SingleScrollbarAnimationControllerThinning {
public:
static constexpr float kIdleThicknessScale = 0.4f;
- static constexpr float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
+ static constexpr float kMouseMoveDistanceToTriggerExpand = 25.f;
static std::unique_ptr<SingleScrollbarAnimationControllerThinning> Create(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
base::TimeDelta thinning_duration);
~SingleScrollbarAnimationControllerThinning() {}
- bool mouse_is_over_scrollbar() const { return mouse_is_over_scrollbar_; }
- bool mouse_is_near_scrollbar() const { return mouse_is_near_scrollbar_; }
+ bool mouse_is_over_scrollbar_thumb() const {
+ return mouse_is_over_scrollbar_thumb_;
+ }
+ bool mouse_is_near_scrollbar_thumb() const {
+ return mouse_is_near_scrollbar_thumb_;
+ }
+ bool mouse_is_near_scrollbar_track() const {
+ return mouse_is_near_scrollbar_track_;
+ }
+
bool captured() const { return captured_; }
bool Animate(base::TimeTicks now);
@@ -46,15 +54,16 @@ class CC_EXPORT SingleScrollbarAnimationControllerThinning {
void DidMouseDown();
void DidMouseUp();
void DidMouseLeave();
- void DidMouseMoveNear(float distance);
+ void DidMouseMove(const gfx::PointF& device_viewport_point);
private:
SingleScrollbarAnimationControllerThinning(
- int scroll_layer_id,
+ ElementId scroll_element_id,
ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
base::TimeDelta thinning_duration);
+ ScrollbarLayerImplBase* GetScrollbar() const;
float AnimationProgressAtTime(base::TimeTicks now);
void RunAnimationFrame(float progress);
const base::TimeDelta& Duration();
@@ -76,12 +85,13 @@ class CC_EXPORT SingleScrollbarAnimationControllerThinning {
base::TimeTicks last_awaken_time_;
bool is_animating_;
- int scroll_layer_id_;
+ ElementId scroll_element_id_;
ScrollbarOrientation orientation_;
bool captured_;
- bool mouse_is_over_scrollbar_;
- bool mouse_is_near_scrollbar_;
+ bool mouse_is_over_scrollbar_thumb_;
+ bool mouse_is_near_scrollbar_thumb_;
+ bool mouse_is_near_scrollbar_track_;
// Are we narrowing or thickening the bars.
AnimationChange thickness_change_;
diff --git a/chromium/cc/input/single_scrollbar_animation_controller_thinning_unittest.cc b/chromium/cc/input/single_scrollbar_animation_controller_thinning_unittest.cc
index 50659ff44d8..0faa8d3265b 100644
--- a/chromium/cc/input/single_scrollbar_animation_controller_thinning_unittest.cc
+++ b/chromium/cc/input/single_scrollbar_animation_controller_thinning_unittest.cc
@@ -23,9 +23,11 @@ namespace {
const float kIdleThicknessScale =
SingleScrollbarAnimationControllerThinning::kIdleThicknessScale;
-const float kDefaultMouseMoveDistanceToTriggerAnimation =
+const float kMouseMoveDistanceToTriggerExpand =
SingleScrollbarAnimationControllerThinning::
- kDefaultMouseMoveDistanceToTriggerAnimation;
+ kMouseMoveDistanceToTriggerExpand;
+const float kMouseMoveDistanceToTriggerFadeIn =
+ ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
class MockSingleScrollbarAnimationControllerClient
: public ScrollbarAnimationControllerClient {
@@ -35,8 +37,8 @@ class MockSingleScrollbarAnimationControllerClient
: host_impl_(host_impl) {}
virtual ~MockSingleScrollbarAnimationControllerClient() {}
- ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override {
- return host_impl_->ScrollbarsFor(scroll_layer_id);
+ ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
+ return host_impl_->ScrollbarsFor(scroll_element_id);
}
MOCK_METHOD2(PostDelayedScrollbarAnimationTask,
@@ -65,6 +67,8 @@ class SingleScrollbarAnimationControllerThinningTest : public testing::Test {
LayerImpl::Create(host_impl_.active_tree(), 1);
std::unique_ptr<LayerImpl> clip =
LayerImpl::Create(host_impl_.active_tree(), 3);
+ scroll_layer->SetElementId(
+ LayerIdToElementIdForTesting(scroll_layer->id()));
clip_layer_ = clip.get();
scroll_layer->SetScrollClipLayer(clip_layer_->id());
LayerImpl* scroll_layer_ptr = scroll_layer.get();
@@ -72,6 +76,7 @@ class SingleScrollbarAnimationControllerThinningTest : public testing::Test {
const int kId = 2;
const int kThumbThickness = 10;
const int kTrackStart = 0;
+ const int kTrackLength = 100;
const bool kIsLeftSideVerticalScrollbar = false;
const bool kIsOverlayScrollbar = true;
@@ -85,14 +90,17 @@ class SingleScrollbarAnimationControllerThinningTest : public testing::Test {
clip_layer_->test_properties()->AddChild(std::move(scroll_layer));
host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
- scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
+ scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength));
+ scrollbar_layer_->SetPosition(gfx::PointF(90, 0));
+ scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id());
scrollbar_layer_->test_properties()->opacity_can_animate = true;
clip_layer_->SetBounds(gfx::Size(100, 100));
scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create(
- scroll_layer_ptr->id(), HORIZONTAL, &client_, kThinningDuration);
+ scroll_layer_ptr->element_id(), HORIZONTAL, &client_,
+ kThinningDuration);
}
FakeImplTaskRunnerProvider task_runner_provider_;
@@ -105,6 +113,13 @@ class SingleScrollbarAnimationControllerThinningTest : public testing::Test {
NiceMock<MockSingleScrollbarAnimationControllerClient> client_;
};
+// Return a point with given offset from the top-left of scrollbar.
+gfx::PointF NearScrollbar(float offset_x, float offset_y) {
+ gfx::PointF p(90, 0);
+ p.Offset(offset_x, offset_y);
+ return p;
+}
+
// Check initialization of scrollbar. Should start thin.
TEST_F(SingleScrollbarAnimationControllerThinningTest, Idle) {
EXPECT_FLOAT_EQ(kIdleThicknessScale,
@@ -117,7 +132,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidMouseMoveNear(1);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0));
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
scrollbar_layer_->thumb_thickness_scale_factor());
@@ -128,15 +143,24 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) {
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
// Subsequent moves within the nearness threshold should not change anything.
- scrollbar_controller_->DidMouseMoveNear(2);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(-2, 0));
scrollbar_controller_->Animate(time);
time += base::TimeDelta::FromSeconds(10);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
- // Now move away from bar.
- scrollbar_controller_->DidMouseMoveNear(
- kDefaultMouseMoveDistanceToTriggerAnimation);
+ // Now move away from thumb.
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0));
+ scrollbar_controller_->Animate(time);
+ time += kThinningDuration;
+ scrollbar_controller_->Animate(time);
+ EXPECT_FLOAT_EQ(kIdleThicknessScale,
+ scrollbar_layer_->thumb_thickness_scale_factor());
+
+ // Move away from track.
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerFadeIn, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -150,7 +174,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidMouseMoveNear(0);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0));
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
scrollbar_layer_->thumb_thickness_scale_factor());
@@ -161,7 +185,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) {
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
// Subsequent moves should not change anything.
- scrollbar_controller_->DidMouseMoveNear(0);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0));
scrollbar_controller_->Animate(time);
time += base::TimeDelta::FromSeconds(10);
scrollbar_controller_->Animate(time);
@@ -169,16 +193,16 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) {
// Moving off the scrollbar but still withing the "near" threshold should do
// nothing.
- scrollbar_controller_->DidMouseMoveNear(
- kDefaultMouseMoveDistanceToTriggerAnimation - 1.f);
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerExpand + 1, 0));
scrollbar_controller_->Animate(time);
time += base::TimeDelta::FromSeconds(10);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
- // Now move away from bar.
- scrollbar_controller_->DidMouseMoveNear(
- kDefaultMouseMoveDistanceToTriggerAnimation);
+ // Now move away from thumb.
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -188,13 +212,13 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) {
// First move the pointer over the scrollbar off of it. Make sure the thinning
// animation kicked off in DidMouseMoveOffScrollbar gets overridden by the
-// thickening animation in the DidMouseMoveNear call.
+// thickening animation in the DidMouseMove call.
TEST_F(SingleScrollbarAnimationControllerThinningTest,
MouseNearThenAwayWhileAnimating) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidMouseMoveNear(0);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0));
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
scrollbar_layer_->thumb_thickness_scale_factor());
@@ -205,7 +229,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
// This is tricky. The DidMouseLeave() is sent before the
- // subsequent DidMouseMoveNear(), if the mouse moves in that direction.
+ // subsequent DidMouseMove(), if the mouse moves in that direction.
// This results in the thumb thinning. We want to make sure that when the
// thumb starts expanding it doesn't first narrow to the idle thinness.
time += base::TimeDelta::FromSeconds(1);
@@ -222,7 +246,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
// Now we get a notification for the mouse moving over the scroller. The
// animation is reset to the thickening direction but we won't start
// thickening until the new animation catches up to the current thickness.
- scrollbar_controller_->DidMouseMoveNear(1);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0));
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f,
scrollbar_layer_->thumb_thickness_scale_factor());
@@ -260,7 +284,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
time += base::TimeDelta::FromSeconds(1);
// Move over the scrollbar.
- scrollbar_controller_->DidMouseMoveNear(0);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -278,8 +302,8 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
// Move outside the "near" threshold. Because the scrollbar is captured it
// should remain thick.
- scrollbar_controller_->DidMouseMoveNear(
- kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0));
time += kThinningDuration;
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
@@ -305,7 +329,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
time += base::TimeDelta::FromSeconds(1);
// Move over scrollbar.
- scrollbar_controller_->DidMouseMoveNear(0);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0));
scrollbar_controller_->Animate(time);
time += kThinningDuration;
scrollbar_controller_->Animate(time);
@@ -320,8 +344,8 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
// Move away from scrollbar. Nothing should change.
- scrollbar_controller_->DidMouseMoveNear(
- kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(kMouseMoveDistanceToTriggerExpand, 0));
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
time += base::TimeDelta::FromSeconds(10);
@@ -330,7 +354,8 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest,
// Move over scrollbar and release. Since we're near the scrollbar, it should
// remain thick.
- scrollbar_controller_->DidMouseMoveNear(0);
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerExpand + 1, 0));
scrollbar_controller_->DidMouseUp();
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
@@ -346,7 +371,7 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) {
// Move mouse near scrollbar. Test that at half the duration time, the
// thickness is half way through its animation.
- scrollbar_controller_->DidMouseMoveNear(1);
+ scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0));
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(kIdleThicknessScale,
scrollbar_layer_->thumb_thickness_scale_factor());
@@ -362,8 +387,8 @@ TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) {
// Move mouse away from scrollbar. Same check.
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidMouseMoveNear(
- kDefaultMouseMoveDistanceToTriggerAnimation);
+ scrollbar_controller_->DidMouseMove(
+ NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0));
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
diff --git a/chromium/cc/input/touch_action.h b/chromium/cc/input/touch_action.h
new file mode 100644
index 00000000000..8b11c4c9d7e
--- /dev/null
+++ b/chromium/cc/input/touch_action.h
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_INPUT_TOUCH_ACTION_H_
+#define CC_INPUT_TOUCH_ACTION_H_
+
+#include <cstdlib>
+
+namespace cc {
+
+// The current touch action specifies what accelerated browser operations
+// (panning and zooming) are currently permitted via touch input.
+// See http://www.w3.org/TR/pointerevents/#the-touch-action-css-property.
+// This is intended to be the single canonical definition of the enum, it's used
+// elsewhere in both Blink and content since touch action logic spans those
+// subsystems.
+// TODO(crbug.com/720553): rework this enum to enum class.
+const size_t kTouchActionBits = 6;
+
+enum TouchAction {
+ // No scrolling or zooming allowed.
+ kTouchActionNone = 0x0,
+ kTouchActionPanLeft = 0x1,
+ kTouchActionPanRight = 0x2,
+ kTouchActionPanX = kTouchActionPanLeft | kTouchActionPanRight,
+ kTouchActionPanUp = 0x4,
+ kTouchActionPanDown = 0x8,
+ kTouchActionPanY = kTouchActionPanUp | kTouchActionPanDown,
+ kTouchActionPan = kTouchActionPanX | kTouchActionPanY,
+ kTouchActionPinchZoom = 0x10,
+ kTouchActionManipulation = kTouchActionPan | kTouchActionPinchZoom,
+ kTouchActionDoubleTapZoom = 0x20,
+ kTouchActionAuto = kTouchActionManipulation | kTouchActionDoubleTapZoom,
+ kTouchActionMax = (1 << 6) - 1
+};
+
+inline TouchAction operator|(TouchAction a, TouchAction b) {
+ return static_cast<TouchAction>(int(a) | int(b));
+}
+
+inline TouchAction& operator|=(TouchAction& a, TouchAction b) {
+ return a = a | b;
+}
+
+inline TouchAction operator&(TouchAction a, TouchAction b) {
+ return static_cast<TouchAction>(int(a) & int(b));
+}
+
+inline TouchAction& operator&=(TouchAction& a, TouchAction b) {
+ return a = a & b;
+}
+
+} // namespace cc
+
+#endif // CC_INPUT_TOUCH_ACTION_H_