summaryrefslogtreecommitdiff
path: root/chromium/cc/input
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/input')
-rw-r--r--chromium/cc/input/browser_controls_offset_manager.cc26
-rw-r--r--chromium/cc/input/browser_controls_offset_manager_unittest.cc56
-rw-r--r--chromium/cc/input/input_handler.cc17
-rw-r--r--chromium/cc/input/input_handler.h39
-rw-r--r--chromium/cc/input/main_thread_scrolling_reason.cc12
-rw-r--r--chromium/cc/input/main_thread_scrolling_reason.h11
-rw-r--r--chromium/cc/input/main_thread_scrolling_reason_unittest.cc6
-rw-r--r--chromium/cc/input/scroll_elasticity_helper.cc7
-rw-r--r--chromium/cc/input/scroll_elasticity_helper.h4
-rw-r--r--chromium/cc/input/scroll_state.h8
-rw-r--r--chromium/cc/input/scroll_state_data.cc3
-rw-r--r--chromium/cc/input/scroll_state_data.h10
-rw-r--r--chromium/cc/input/scroll_utils.cc45
-rw-r--r--chromium/cc/input/scroll_utils.h43
-rw-r--r--chromium/cc/input/scrollbar.h8
-rw-r--r--chromium/cc/input/scrollbar_animation_controller.cc39
-rw-r--r--chromium/cc/input/scrollbar_animation_controller.h5
-rw-r--r--chromium/cc/input/scrollbar_animation_controller_unittest.cc109
-rw-r--r--chromium/cc/input/scrollbar_controller.cc171
-rw-r--r--chromium/cc/input/scrollbar_controller.h79
-rw-r--r--chromium/cc/input/touch_action.h2
21 files changed, 380 insertions, 320 deletions
diff --git a/chromium/cc/input/browser_controls_offset_manager.cc b/chromium/cc/input/browser_controls_offset_manager.cc
index ea4c6e27993..5ebc925c1e6 100644
--- a/chromium/cc/input/browser_controls_offset_manager.cc
+++ b/chromium/cc/input/browser_controls_offset_manager.cc
@@ -207,17 +207,20 @@ void BrowserControlsOffsetManager::OnBrowserControlsParamsChanged(
return;
}
+ // We continue to update both top and bottom controls even if one has a height
+ // of 0 so that animations work properly. So here, we should preserve the
+ // ratios even if the controls height is 0.
float old_top_height = old_browser_controls_params_.top_controls_height;
float new_top_ratio =
TopControlsHeight()
? TopControlsShownRatio() * old_top_height / TopControlsHeight()
- : 0.f;
+ : TopControlsShownRatio();
float old_bottom_height = old_browser_controls_params_.bottom_controls_height;
float new_bottom_ratio = BottomControlsHeight()
? BottomControlsShownRatio() *
old_bottom_height / BottomControlsHeight()
- : 0.f;
+ : BottomControlsShownRatio();
if (!animate_changes) {
// If the min-heights changed when the controls were at the min-height, the
@@ -268,8 +271,13 @@ void BrowserControlsOffsetManager::OnBrowserControlsParamsChanged(
bool bottom_controls_need_animation = animate_changes;
float top_target_ratio;
- // If the top controls height changed when they were fully shown.
- if (TopControlsShownRatio() == 1.f && TopControlsHeight() != old_top_height) {
+ // We can't animate if we don't have top controls.
+ if (!TopControlsHeight()) {
+ top_controls_need_animation = false;
+
+ // If the top controls height changed when they were fully shown.
+ } else if (TopControlsShownRatio() == 1.f &&
+ TopControlsHeight() != old_top_height) {
top_target_ratio = 1.f; // i.e. new_height / new_height
// If the top controls min-height changed when they were at the minimum
@@ -284,9 +292,13 @@ void BrowserControlsOffsetManager::OnBrowserControlsParamsChanged(
}
float bottom_target_ratio;
- // If the bottom controls height changed when they were fully shown.
- if (BottomControlsShownRatio() == 1.f &&
- BottomControlsHeight() != old_bottom_height) {
+ // We can't animate if we don't have bottom controls.
+ if (!BottomControlsHeight()) {
+ bottom_controls_need_animation = false;
+
+ // If the bottom controls height changed when they were fully shown.
+ } else if (BottomControlsShownRatio() == 1.f &&
+ BottomControlsHeight() != old_bottom_height) {
bottom_target_ratio = 1.f; // i.e. new_height / new_height
// If the bottom controls min-height changed when they were at the minimum
diff --git a/chromium/cc/input/browser_controls_offset_manager_unittest.cc b/chromium/cc/input/browser_controls_offset_manager_unittest.cc
index 8c443fd0bee..507ca1f3a5a 100644
--- a/chromium/cc/input/browser_controls_offset_manager_unittest.cc
+++ b/chromium/cc/input/browser_controls_offset_manager_unittest.cc
@@ -1087,5 +1087,61 @@ TEST(BrowserControlsOffsetManagerTest, ScrollWithMinHeightSetForBothControls) {
manager->ScrollEnd();
}
+TEST(BrowserControlsOffsetManagerTest, ChangingBottomHeightFromZeroAnimates) {
+ MockBrowserControlsOffsetManagerClient client(100, 0.5f, 0.5f);
+ client.SetBrowserControlsParams({100, 30, 0, 0, false, false});
+ BrowserControlsOffsetManager* manager = client.manager();
+ EXPECT_FLOAT_EQ(1.f, client.CurrentTopControlsShownRatio());
+ EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
+
+ // Set the bottom controls height to 100 with animation.
+ client.SetBrowserControlsParams({100, 30, 100, 0, true, false});
+ EXPECT_TRUE(manager->HasAnimation());
+ // The bottom controls should be hidden in the beginning.
+ EXPECT_FLOAT_EQ(0.f, manager->ContentBottomOffset());
+ EXPECT_FLOAT_EQ(0.f, client.CurrentBottomControlsShownRatio());
+
+ base::TimeTicks time = base::TimeTicks::Now();
+
+ // First animate will establish the animaion.
+ float previous_ratio = manager->BottomControlsShownRatio();
+ manager->Animate(time);
+ EXPECT_EQ(manager->BottomControlsShownRatio(), previous_ratio);
+
+ while (manager->HasAnimation()) {
+ previous_ratio = manager->BottomControlsShownRatio();
+ time = base::TimeDelta::FromMicroseconds(100) + time;
+ manager->Animate(time);
+ EXPECT_GT(manager->BottomControlsShownRatio(), previous_ratio);
+ }
+
+ // Now the bottom controls should be fully shown.
+ EXPECT_FLOAT_EQ(100.f, manager->ContentBottomOffset());
+ EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
+}
+
+TEST(BrowserControlsOffsetManagerTest,
+ ChangingControlsHeightToZeroWithAnimationIsNoop) {
+ MockBrowserControlsOffsetManagerClient client(100, 0.5f, 0.5f);
+ client.SetBrowserControlsParams({100, 20, 80, 10, false, false});
+ BrowserControlsOffsetManager* manager = client.manager();
+ EXPECT_FLOAT_EQ(1.f, client.CurrentTopControlsShownRatio());
+ EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
+
+ // Set the bottom controls height to 0 with animation.
+ client.SetBrowserControlsParams({100, 20, 0, 0, true, false});
+
+ // There shouldn't be an animation because we can't animate controls with 0
+ // height.
+ EXPECT_FALSE(manager->HasAnimation());
+ // Also, the bottom controls ratio should stay the same.
+ EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
+
+ // Increase the top controls height with animation.
+ client.SetBrowserControlsParams({120, 20, 0, 0, true, false});
+ // This shouldn't override the bottom controls shown ratio.
+ EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/input/input_handler.cc b/chromium/cc/input/input_handler.cc
deleted file mode 100644
index 55ca46ef2c0..00000000000
--- a/chromium/cc/input/input_handler.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2014 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.
-
-#include "cc/input/input_handler.h"
-
-namespace cc {
-
-InputHandlerScrollResult::InputHandlerScrollResult()
- : did_scroll(false), did_overscroll_root(false) {
-}
-
-InputHandlerPointerResult::InputHandlerPointerResult()
- : type(kUnhandled),
- scroll_units(ui::ScrollGranularity::kScrollByPrecisePixel) {}
-
-} // namespace cc
diff --git a/chromium/cc/input/input_handler.h b/chromium/cc/input/input_handler.h
index eaaa9afde45..43309848b23 100644
--- a/chromium/cc/input/input_handler.h
+++ b/chromium/cc/input/input_handler.h
@@ -50,13 +50,14 @@ enum class ScrollBeginThreadState {
};
struct CC_EXPORT InputHandlerPointerResult {
- InputHandlerPointerResult();
+ InputHandlerPointerResult() = default;
// Tells what type of processing occurred in the input handler as a result of
// the pointer event.
- PointerResultType type;
+ PointerResultType type = kUnhandled;
// Tells what scroll_units should be used.
- ui::ScrollGranularity scroll_units;
+ ui::ScrollGranularity scroll_units =
+ ui::ScrollGranularity::kScrollByPrecisePixel;
// If the input handler processed the event as a scrollbar scroll, it will
// return a gfx::ScrollOffset that produces the necessary scroll. However,
@@ -73,11 +74,11 @@ struct CC_EXPORT InputHandlerPointerResult {
};
struct CC_EXPORT InputHandlerScrollResult {
- InputHandlerScrollResult();
+ InputHandlerScrollResult() = default;
// Did any layer scroll as a result this ScrollUpdate call?
- bool did_scroll;
+ bool did_scroll = false;
// Was any of the scroll delta argument to this ScrollUpdate call not used?
- bool did_overscroll_root;
+ bool did_overscroll_root = false;
// The total overscroll that has been accumulated by all ScrollUpdate calls
// that have had overscroll since the last ScrollBegin call. This resets upon
// a ScrollUpdate with no overscroll.
@@ -139,17 +140,25 @@ class CC_EXPORT InputHandler {
InputHandler& operator=(const InputHandler&) = delete;
struct ScrollStatus {
- ScrollStatus()
- : thread(SCROLL_ON_IMPL_THREAD),
- main_thread_scrolling_reasons(
- MainThreadScrollingReason::kNotScrollingOnMain),
- bubble(false) {}
+ ScrollStatus() = default;
ScrollStatus(ScrollThread thread, uint32_t main_thread_scrolling_reasons)
: thread(thread),
main_thread_scrolling_reasons(main_thread_scrolling_reasons) {}
- ScrollThread thread;
- uint32_t main_thread_scrolling_reasons;
- bool bubble;
+ ScrollStatus(ScrollThread thread,
+ uint32_t main_thread_scrolling_reasons,
+ bool needs_main_thread_hit_test)
+ : thread(thread),
+ main_thread_scrolling_reasons(main_thread_scrolling_reasons),
+ needs_main_thread_hit_test(needs_main_thread_hit_test) {}
+ ScrollThread thread = SCROLL_ON_IMPL_THREAD;
+ uint32_t main_thread_scrolling_reasons =
+ MainThreadScrollingReason::kNotScrollingOnMain;
+ bool bubble = false;
+
+ // Used only in scroll unification. Tells the caller that the input handler
+ // detected a case where it cannot reliably target a scroll node and needs
+ // the main thread to perform a hit test.
+ bool needs_main_thread_hit_test = false;
};
enum class TouchStartOrMoveEventListenerType {
@@ -256,7 +265,7 @@ class CC_EXPORT InputHandler {
// suppress scrolling by consuming touch events that started at
// |viewport_point|, and whether |viewport_point| is on the currently
// scrolling layer.
- // |out_touch_action| is assigned the whitelisted touch action for the
+ // |out_touch_action| is assigned the allowed touch action for the
// |viewport_point|. In the case there are no touch handlers or touch action
// regions, |out_touch_action| is assigned TouchAction::kAuto since the
// default touch action is auto.
diff --git a/chromium/cc/input/main_thread_scrolling_reason.cc b/chromium/cc/input/main_thread_scrolling_reason.cc
index b84c31dd04c..a116970e49b 100644
--- a/chromium/cc/input/main_thread_scrolling_reason.cc
+++ b/chromium/cc/input/main_thread_scrolling_reason.cc
@@ -44,14 +44,10 @@ void MainThreadScrollingReason::AddToTracedValue(
traced_value.AppendString("Handling scroll from main thread");
if (reasons & kHasTransformAndLCDText)
traced_value.AppendString("Has transform and LCD text");
- if (reasons & kBackgroundNotOpaqueInRectAndLCDText)
- traced_value.AppendString("Background is not opaque in rect and LCD text");
- if (reasons & kCantPaintScrollingBackground)
- traced_value.AppendString("Can't paint scrolling background");
- if (reasons & kHasClipRelatedProperty)
- traced_value.AppendString("Has clip related property");
- if (reasons & kIsNotStackingContextAndLCDText)
- traced_value.AppendString("Is not stacking context and LCD text");
+ if (reasons & kNotOpaqueForTextAndLCDText)
+ traced_value.AppendString("Not opaque for text and LCD text");
+ if (reasons & kCantPaintScrollingBackgroundAndLCDText)
+ traced_value.AppendString("Can't paint scrolling background and LCD text");
// Transient scrolling reasons.
if (reasons & kNonFastScrollableRegion)
diff --git a/chromium/cc/input/main_thread_scrolling_reason.h b/chromium/cc/input/main_thread_scrolling_reason.h
index cd129cf69fc..8354bbb401d 100644
--- a/chromium/cc/input/main_thread_scrolling_reason.h
+++ b/chromium/cc/input/main_thread_scrolling_reason.h
@@ -44,10 +44,8 @@ struct CC_EXPORT MainThreadScrollingReason {
// screen position; transparency and transforms break this.
kNonCompositedReasonsFirst = 17,
kHasTransformAndLCDText = 1 << 17,
- kBackgroundNotOpaqueInRectAndLCDText = 1 << 18,
- kCantPaintScrollingBackground = 1 << 19,
- kHasClipRelatedProperty = 1 << 20,
- kIsNotStackingContextAndLCDText = 1 << 22,
+ kNotOpaqueForTextAndLCDText = 1 << 18,
+ kCantPaintScrollingBackgroundAndLCDText = 1 << 19,
kNonCompositedReasonsLast = 22,
// Transient scrolling reasons. These are computed for each scroll begin.
@@ -69,9 +67,8 @@ struct CC_EXPORT MainThreadScrollingReason {
};
static const uint32_t kNonCompositedReasons =
- kHasTransformAndLCDText | kBackgroundNotOpaqueInRectAndLCDText |
- kCantPaintScrollingBackground | kHasClipRelatedProperty |
- kIsNotStackingContextAndLCDText;
+ kHasTransformAndLCDText | kNotOpaqueForTextAndLCDText |
+ kCantPaintScrollingBackgroundAndLCDText;
// Returns true if the given MainThreadScrollingReason can be set by the main
// thread.
diff --git a/chromium/cc/input/main_thread_scrolling_reason_unittest.cc b/chromium/cc/input/main_thread_scrolling_reason_unittest.cc
index 7cf3f40d164..4f8b75516af 100644
--- a/chromium/cc/input/main_thread_scrolling_reason_unittest.cc
+++ b/chromium/cc/input/main_thread_scrolling_reason_unittest.cc
@@ -20,10 +20,8 @@ TEST_F(MainThreadScrollingReasonTest, AsText) {
"Frame overlay, "
"Handling scroll from main thread, "
"Has transform and LCD text, "
- "Background is not opaque in rect and LCD text, "
- "Can't paint scrolling background, "
- "Has clip related property, "
- "Is not stacking context and LCD text, "
+ "Not opaque for text and LCD text, "
+ "Can't paint scrolling background and LCD text, "
"Non fast scrollable region, "
"Failed hit test, "
"No scrolling layer, "
diff --git a/chromium/cc/input/scroll_elasticity_helper.cc b/chromium/cc/input/scroll_elasticity_helper.cc
index 739daaa72a3..451bfcd81ba 100644
--- a/chromium/cc/input/scroll_elasticity_helper.cc
+++ b/chromium/cc/input/scroll_elasticity_helper.cc
@@ -18,6 +18,7 @@ class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
bool IsUserScrollable() const override;
gfx::Vector2dF StretchAmount() const override;
+ gfx::Size ScrollBounds() const override;
void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
gfx::ScrollOffset ScrollOffset() const override;
gfx::ScrollOffset MaxScrollOffset() const override;
@@ -46,6 +47,12 @@ gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() const {
return host_impl_->active_tree()->elastic_overscroll()->Current(true);
}
+gfx::Size ScrollElasticityHelperImpl::ScrollBounds() const {
+ return host_impl_->OuterViewportScrollNode()
+ ? host_impl_->OuterViewportScrollNode()->container_bounds
+ : gfx::Size();
+}
+
void ScrollElasticityHelperImpl::SetStretchAmount(
const gfx::Vector2dF& stretch_amount) {
if (stretch_amount == StretchAmount())
diff --git a/chromium/cc/input/scroll_elasticity_helper.h b/chromium/cc/input/scroll_elasticity_helper.h
index 81281310ecb..4ae282fe51b 100644
--- a/chromium/cc/input/scroll_elasticity_helper.h
+++ b/chromium/cc/input/scroll_elasticity_helper.h
@@ -8,6 +8,7 @@
#include "base/time/time.h"
#include "cc/cc_export.h"
#include "ui/gfx/geometry/scroll_offset.h"
+#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@@ -54,6 +55,9 @@ class CC_EXPORT ScrollElasticityHelper {
virtual bool IsUserScrollable() const = 0;
+ // The bounds of the root scroller.
+ virtual gfx::Size ScrollBounds() const = 0;
+
// The amount that the view is stretched past the normal allowable bounds.
virtual gfx::Vector2dF StretchAmount() const = 0;
virtual void SetStretchAmount(const gfx::Vector2dF& stretch_amount) = 0;
diff --git a/chromium/cc/input/scroll_state.h b/chromium/cc/input/scroll_state.h
index a73b9b117c4..8ac3850ca51 100644
--- a/chromium/cc/input/scroll_state.h
+++ b/chromium/cc/input/scroll_state.h
@@ -86,6 +86,14 @@ class CC_EXPORT ScrollState {
// it's a scroll update
gfx::ScrollOffset DeltaOrHint() const;
+ ElementId target_element_id() const {
+ return data_.current_native_scrolling_element();
+ }
+
+ bool is_main_thread_hit_tested() const {
+ return data_.is_main_thread_hit_tested;
+ }
+
ScrollStateData* data() { return &data_; }
private:
diff --git a/chromium/cc/input/scroll_state_data.cc b/chromium/cc/input/scroll_state_data.cc
index 4c472790f15..f18676f4b85 100644
--- a/chromium/cc/input/scroll_state_data.cc
+++ b/chromium/cc/input/scroll_state_data.cc
@@ -25,7 +25,8 @@ ScrollStateData::ScrollStateData()
delta_granularity(ui::ScrollGranularity::kScrollByPrecisePixel),
caused_scroll_x(false),
caused_scroll_y(false),
- is_scroll_chain_cut(false) {}
+ is_scroll_chain_cut(false),
+ is_main_thread_hit_tested(false) {}
ScrollStateData::ScrollStateData(const ScrollStateData& other) = default;
diff --git a/chromium/cc/input/scroll_state_data.h b/chromium/cc/input/scroll_state_data.h
index 297517031ae..a3a2755c61b 100644
--- a/chromium/cc/input/scroll_state_data.h
+++ b/chromium/cc/input/scroll_state_data.h
@@ -70,12 +70,18 @@ class CC_EXPORT ScrollStateData {
ElementId current_native_scrolling_element() const;
void set_current_native_scrolling_element(ElementId element_id);
+ // Used in scroll unification to specify that a scroll state has been hit
+ // tested on the main thread. If this is true, the hit test result will be
+ // placed in the current_native_scrolling_element_.
+ bool is_main_thread_hit_tested;
+
private:
// The id of the last native element to respond to a scroll, or 0 if none
// exists.
// TODO(bokan): In the compositor, this is now only used as an override to
- // scroller targeting, i.e. we'll latch scrolling to the specified
- // element_id. It will be renamed when the main thread is also converted.
+ // scroller targeting. I.e. we'll latch scrolling to the specified
+ // element_id. It will be renamed to a better name (target_element_id?) when
+ // the main thread is also converted.
ElementId current_native_scrolling_element_;
};
diff --git a/chromium/cc/input/scroll_utils.cc b/chromium/cc/input/scroll_utils.cc
new file mode 100644
index 00000000000..e9c036e3896
--- /dev/null
+++ b/chromium/cc/input/scroll_utils.cc
@@ -0,0 +1,45 @@
+// Copyright 2020 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.
+
+#include "cc/input/scroll_utils.h"
+
+#include "base/numerics/ranges.h"
+#include "ui/gfx/geometry/size_f.h"
+#include "ui/gfx/geometry/vector2d_f.h"
+
+namespace cc {
+
+// static
+gfx::Vector2dF ScrollUtils::ResolveScrollPercentageToPixels(
+ const gfx::Vector2dF& delta,
+ const gfx::SizeF& scroller,
+ const gfx::SizeF& viewport) {
+ // Work with unsigned values and keep sign information in sign_x / sign_y.
+ float sign_x = std::signbit(delta.x()) ? -1 : 1;
+ float sign_y = std::signbit(delta.y()) ? -1 : 1;
+ float delta_x = std::abs(delta.x());
+ float delta_y = std::abs(delta.y());
+
+ // Resolved deltas in percent based scrolling are clamped at min by 16 pixels.
+ float min = kMinPixelDeltaForPercentBasedScroll;
+
+ // Resolve and clamp horizontal scroll
+ if (delta_x > 0) {
+ delta_x = delta_x * std::min(scroller.width(), viewport.width());
+ if (delta_x < min)
+ delta_x = min;
+ }
+
+ // Resolve and clamps vertical scroll.
+ if (delta_y > 0) {
+ delta_y = delta_y * std::min(scroller.height(), viewport.height());
+ if (delta_y < min)
+ delta_y = min;
+ }
+
+ return gfx::Vector2dF(std::copysign(delta_x, sign_x),
+ std::copysign(delta_y, sign_y));
+}
+
+} // namespace cc
diff --git a/chromium/cc/input/scroll_utils.h b/chromium/cc/input/scroll_utils.h
new file mode 100644
index 00000000000..34fb3be7773
--- /dev/null
+++ b/chromium/cc/input/scroll_utils.h
@@ -0,0 +1,43 @@
+// Copyright 2020 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_SCROLL_UTILS_H_
+#define CC_INPUT_SCROLL_UTILS_H_
+
+#include "cc/cc_export.h"
+
+namespace gfx {
+class Vector2dF;
+class SizeF;
+} // namespace gfx
+
+namespace cc {
+
+static constexpr int kPixelsPerLineStep = 40;
+static constexpr float kMinFractionToStepWhenPaging = 0.875f;
+
+// Each directional scroll for percentage-based units should scroll 1/8th of
+// the scrollable area.
+static constexpr float kPercentDeltaForDirectionalScroll = 0.125f;
+
+// Scroll deltas are lower-bounded by 16 physical pixels in percent-based
+// scrolls.
+static constexpr float kMinPixelDeltaForPercentBasedScroll = 16;
+
+// Class for scroll helper methods in cc and blink.
+class CC_EXPORT ScrollUtils {
+ public:
+ // Transforms a |scroll_delta| in percent units to pixel units based in its
+ // |scroller_size|. Clamps it by 16 pixels to avoid too small deltas for tiny
+ // scrollers and 12.5% of |viewport_size| to avoid too large deltas.
+ // Inputs and output muest be in physical pixels.
+ static gfx::Vector2dF ResolveScrollPercentageToPixels(
+ const gfx::Vector2dF& scroll_delta,
+ const gfx::SizeF& scroller_size,
+ const gfx::SizeF& viewport_size);
+};
+
+} // namespace cc
+
+#endif // CC_INPUT_SCROLL_UTILS_H_
diff --git a/chromium/cc/input/scrollbar.h b/chromium/cc/input/scrollbar.h
index af8cef429b1..4fc7a3e57e9 100644
--- a/chromium/cc/input/scrollbar.h
+++ b/chromium/cc/input/scrollbar.h
@@ -11,13 +11,6 @@
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
-static constexpr int kPixelsPerLineStep = 40;
-static constexpr float kMinFractionToStepWhenPaging = 0.875f;
-
-// Each directional scroll for percentage-based units should scroll 1/8th of
-// the scrollable area.
-static constexpr float kPercentDeltaForDirectionalScroll = 0.125f;
-
// Autoscrolling (on the main thread) happens by applying a delta every 50ms.
// Hence, pixels per second for a autoscroll cc animation can be calculated as:
// autoscroll velocity = delta / 0.05 sec = delta x 20
@@ -58,6 +51,7 @@ class Scrollbar : public base::RefCounted<Scrollbar> {
virtual bool IsOverlay() const = 0;
virtual bool HasThumb() const = 0;
virtual bool SupportsDragSnapBack() const = 0;
+ virtual bool JumpOnTrackClick() const = 0;
// The following rects are all relative to the scrollbar's origin.
// The location of ThumbRect reflects scroll offset, but cc will ignore it
diff --git a/chromium/cc/input/scrollbar_animation_controller.cc b/chromium/cc/input/scrollbar_animation_controller.cc
index 2435aa156fe..50242fb337c 100644
--- a/chromium/cc/input/scrollbar_animation_controller.cc
+++ b/chromium/cc/input/scrollbar_animation_controller.cc
@@ -51,8 +51,6 @@ ScrollbarAnimationController::ScrollbarAnimationController(
is_animating_(false),
animation_change_(NONE),
scroll_element_id_(scroll_element_id),
- currently_scrolling_(false),
- show_in_fast_scroll_(false),
opacity_(initial_opacity),
show_scrollbars_on_scroll_gesture_(false),
need_thinning_animation_(false),
@@ -73,8 +71,6 @@ ScrollbarAnimationController::ScrollbarAnimationController(
is_animating_(false),
animation_change_(NONE),
scroll_element_id_(scroll_element_id),
- currently_scrolling_(false),
- show_in_fast_scroll_(false),
opacity_(initial_opacity),
show_scrollbars_on_scroll_gesture_(true),
need_thinning_animation_(true),
@@ -182,25 +178,6 @@ void ScrollbarAnimationController::RunAnimationFrame(float progress) {
StopAnimation();
}
-void ScrollbarAnimationController::DidScrollBegin() {
- currently_scrolling_ = true;
-}
-
-void ScrollbarAnimationController::DidScrollEnd() {
- bool has_scrolled = show_in_fast_scroll_;
- show_in_fast_scroll_ = false;
-
- currently_scrolling_ = false;
-
- // We don't fade out scrollbar if they need thinning animation and mouse is
- // near.
- if (need_thinning_animation_ && MouseIsNearAnyScrollbar())
- return;
-
- if (has_scrolled && !tickmarks_showing_)
- PostDelayedAnimation(FADE_OUT);
-}
-
void ScrollbarAnimationController::DidScrollUpdate() {
UpdateScrollbarState();
}
@@ -213,19 +190,13 @@ void ScrollbarAnimationController::UpdateScrollbarState() {
Show();
- // 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.
- if (!currently_scrolling_) {
- // We don't fade out scrollbar if they need thinning animation (Aura
- // Overlay) and mouse is near or tickmarks show.
- if (need_thinning_animation_) {
- if (!MouseIsNearAnyScrollbar() && !tickmarks_showing_)
- PostDelayedAnimation(FADE_OUT);
- } else {
+ // We don't fade out scrollbar if they need thinning animation (Aura
+ // Overlay) and mouse is near or tickmarks show.
+ if (need_thinning_animation_) {
+ if (!MouseIsNearAnyScrollbar() && !tickmarks_showing_)
PostDelayedAnimation(FADE_OUT);
- }
} else {
- show_in_fast_scroll_ = true;
+ PostDelayedAnimation(FADE_OUT);
}
if (need_thinning_animation_) {
diff --git a/chromium/cc/input/scrollbar_animation_controller.h b/chromium/cc/input/scrollbar_animation_controller.h
index 67a9ed5c8fc..1f2c22af131 100644
--- a/chromium/cc/input/scrollbar_animation_controller.h
+++ b/chromium/cc/input/scrollbar_animation_controller.h
@@ -72,9 +72,6 @@ class CC_EXPORT ScrollbarAnimationController {
// Effect both Android and Aura Overlay Scrollbar.
void DidScrollUpdate();
- void DidScrollBegin();
- void DidScrollEnd();
-
void DidMouseDown();
void DidMouseUp();
void DidMouseLeave();
@@ -150,8 +147,6 @@ class CC_EXPORT ScrollbarAnimationController {
AnimationChange animation_change_;
const ElementId scroll_element_id_;
- bool currently_scrolling_;
- bool show_in_fast_scroll_;
base::CancelableOnceClosure delayed_scrollbar_animation_;
diff --git a/chromium/cc/input/scrollbar_animation_controller_unittest.cc b/chromium/cc/input/scrollbar_animation_controller_unittest.cc
index f9593321d61..985f45bae4b 100644
--- a/chromium/cc/input/scrollbar_animation_controller_unittest.cc
+++ b/chromium/cc/input/scrollbar_animation_controller_unittest.cc
@@ -163,9 +163,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, AppearOnResize) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
ExpectScrollbarsOpacity(1);
// Make the Layer non-scrollable, scrollbar disappears.
@@ -199,13 +197,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) {
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollEnd();
-
// Shrink along Y axis and expand along X, horizontal scrollbar
// should disappear.
clip_layer_->SetBounds(gfx::Size(200, 100));
@@ -214,12 +208,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) {
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(0.0f, h_scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
// Scroll content. Confirm the scrollbar appears and fades out.
@@ -232,7 +222,6 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicAppearAndFadeOut) {
EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
// Scrollbar should appear only on scroll update.
- scrollbar_controller_->DidScrollBegin();
ExpectScrollbarsOpacity(0);
EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
@@ -240,7 +229,6 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicAppearAndFadeOut) {
ExpectScrollbarsOpacity(1);
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- scrollbar_controller_->DidScrollEnd();
ExpectScrollbarsOpacity(1);
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
@@ -295,9 +283,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
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());
@@ -355,9 +341,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) {
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());
@@ -396,9 +380,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) {
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());
@@ -438,9 +420,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
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());
@@ -466,9 +446,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
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());
@@ -502,9 +480,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) {
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());
@@ -540,9 +516,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) {
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());
@@ -591,9 +565,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) {
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());
@@ -630,9 +602,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
// A fade out animation should have been enqueued. Start it.
EXPECT_EQ(kFadeDelay, client_.delay());
@@ -670,9 +640,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
EXPECT_EQ(kFadeDelay, client_.delay());
EXPECT_FALSE(client_.start_fade().is_null());
@@ -748,7 +716,6 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) {
EXPECT_FLOAT_EQ(kIdleThicknessScale,
h_scrollbar_layer_->thumb_thickness_scale_factor());
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
// Now that we've received a scroll, we should be thick without an animation.
@@ -756,7 +723,6 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) {
// An animation for the fade should be either null or cancelled, since
// mouse is still near the scrollbar.
- scrollbar_controller_->DidScrollEnd();
EXPECT_TRUE(client_.start_fade().is_null() ||
client_.start_fade().IsCancelled());
@@ -775,29 +741,16 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) {
h_scrollbar_layer_->thumb_thickness_scale_factor());
}
-// Tests that main thread scroll updates immediatley queue a fade out animation
-// without requiring a ScrollEnd.
+// Tests that main thread scroll updates immediately queue a fade out animation
TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
MainThreadScrollQueuesFade) {
ASSERT_TRUE(client_.start_fade().is_null());
- // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update
- // so we should schedule a fade out animation without waiting for a ScrollEnd
- // (which will never come).
+ // A ScrollUpdate indicates a main thread scroll update so we should schedule
+ // a fade out animation since there is no scroll end notification.
scrollbar_controller_->DidScrollUpdate();
EXPECT_FALSE(client_.start_fade().is_null());
EXPECT_EQ(kFadeDelay, client_.delay());
-
- client_.start_fade().Reset();
-
- // If we got a ScrollBegin, we shouldn't schedule the fade out animation until
- // we get a corresponding ScrollEnd.
- scrollbar_controller_->DidScrollBegin();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_TRUE(client_.start_fade().is_null());
- scrollbar_controller_->DidScrollEnd();
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kFadeDelay, client_.delay());
}
// Tests that the fade effect is animated.
@@ -806,9 +759,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) {
time += base::TimeDelta::FromSeconds(1);
// Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
// Appearance is instant.
ExpectScrollbarsOpacity(1);
@@ -838,13 +789,10 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) {
EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
// Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
Mock::VerifyAndClearExpectations(&client_);
- scrollbar_controller_->DidScrollEnd();
-
// Play out the fade out animation. We shouldn't notify that the scrollbars
// are hidden until the animation is completly over. We can (but don't have
// to) notify during the animation that the scrollbars are still visible.
@@ -886,9 +834,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
time += base::TimeDelta::FromSeconds(1);
// Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
// Near vertical scrollbar.
scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
@@ -979,9 +925,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) {
time += base::TimeDelta::FromSeconds(1);
// Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
// Move scrollbar thumb to the end of track.
v_scrollbar_layer_->SetCurrentPos(100);
@@ -1012,9 +956,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
time += base::TimeDelta::FromSeconds(1);
// Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
// Near vertical scrollbar.
scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
@@ -1076,9 +1018,7 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) {
scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
// Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
// Should not have delay fadeout animation.
EXPECT_TRUE(client_.start_fade().is_null() ||
@@ -1323,11 +1263,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TickmakrsShowHide) {
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());
@@ -1430,13 +1368,11 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HiddenInBegin) {
TEST_F(ScrollbarAnimationControllerAndroidTest,
HiddenAfterNonScrollingGesture) {
scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f);
- scrollbar_controller_->DidScrollBegin();
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(100);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollEnd();
EXPECT_TRUE(start_fade_.is_null());
@@ -1473,11 +1409,9 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) {
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollEnd();
// Shrink along Y axis and expand along X, horizontal scrollbar
// should disappear.
@@ -1485,12 +1419,8 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) {
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) {
@@ -1502,23 +1432,17 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) {
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollEnd();
// Shrink along Y axis and expand along X, vertical scrollbar should appear.
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableHorz) {
@@ -1527,12 +1451,8 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableHorz) {
GetScrollNode(scroll_layer_)->user_scrollable_horizontal = false;
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
TEST_F(ScrollbarAnimationControllerAndroidTest, ShowOnUserNonScrollableVert) {
@@ -1541,12 +1461,8 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, ShowOnUserNonScrollableVert) {
GetScrollNode(scroll_layer_)->user_scrollable_vertical = false;
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
TEST_F(VerticalScrollbarAnimationControllerAndroidTest,
@@ -1556,12 +1472,8 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest,
GetScrollNode(scroll_layer_)->user_scrollable_vertical = false;
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
TEST_F(VerticalScrollbarAnimationControllerAndroidTest,
@@ -1571,32 +1483,26 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest,
GetScrollNode(scroll_layer_)->user_scrollable_horizontal = false;
UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollBegin();
-
scrollbar_controller_->DidScrollUpdate();
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
-
- scrollbar_controller_->DidScrollEnd();
}
TEST_F(ScrollbarAnimationControllerAndroidTest, AwakenByScrollingGesture) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidScrollBegin();
EXPECT_FALSE(did_request_animate_);
scrollbar_controller_->DidScrollUpdate();
EXPECT_FALSE(did_request_animate_);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- EXPECT_TRUE(start_fade_.is_null());
+ EXPECT_FALSE(start_fade_.is_null());
time += base::TimeDelta::FromSeconds(100);
scrollbar_controller_->Animate(time);
EXPECT_FALSE(did_request_animate_);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollEnd();
EXPECT_FALSE(did_request_animate_);
std::move(start_fade_).Run();
EXPECT_TRUE(did_request_animate_);
@@ -1622,9 +1528,7 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, AwakenByScrollingGesture) {
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidScrollBegin();
scrollbar_controller_->DidScrollUpdate();
- scrollbar_controller_->DidScrollEnd();
std::move(start_fade_).Run();
EXPECT_TRUE(did_request_animate_);
@@ -1743,7 +1647,6 @@ TEST_F(ScrollbarAnimationControllerAndroidTest,
did_request_animate_ = false;
EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollBegin();
EXPECT_FALSE(did_request_animate_);
EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
@@ -1753,7 +1656,6 @@ TEST_F(ScrollbarAnimationControllerAndroidTest,
did_request_animate_ = false;
EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollEnd();
EXPECT_FALSE(did_request_animate_);
EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
@@ -1783,7 +1685,6 @@ TEST_F(ScrollbarAnimationControllerAndroidTest,
did_request_animate_ = false;
EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollBegin();
EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
time += base::TimeDelta::FromSeconds(1);
@@ -1798,10 +1699,10 @@ TEST_F(ScrollbarAnimationControllerAndroidTest,
EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
time += base::TimeDelta::FromSeconds(1);
- scrollbar_controller_->DidScrollEnd();
EXPECT_FALSE(did_request_animate_);
EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
}
} // namespace
+
} // namespace cc
diff --git a/chromium/cc/input/scrollbar_controller.cc b/chromium/cc/input/scrollbar_controller.cc
index aac1d4ceccd..490cd44d1d4 100644
--- a/chromium/cc/input/scrollbar_controller.cc
+++ b/chromium/cc/input/scrollbar_controller.cc
@@ -8,6 +8,7 @@
#include "base/cancelable_callback.h"
#include "cc/base/math_util.h"
+#include "cc/input/scroll_utils.h"
#include "cc/input/scrollbar.h"
#include "cc/input/scrollbar_controller.h"
#include "cc/trees/layer_tree_impl.h"
@@ -35,7 +36,7 @@ void ScrollbarController::WillBeginImplFrame() {
}
// Retrieves the ScrollbarLayerImplBase corresponding to the stashed ElementId.
-ScrollbarLayerImplBase* ScrollbarController::ScrollbarLayer() {
+ScrollbarLayerImplBase* ScrollbarController::ScrollbarLayer() const {
if (!captured_scrollbar_metadata_.has_value())
return nullptr;
@@ -52,7 +53,7 @@ ScrollbarLayerImplBase* ScrollbarController::ScrollbarLayer() {
// GSU.
InputHandlerPointerResult ScrollbarController::HandlePointerDown(
const gfx::PointF position_in_widget,
- bool shift_modifier) {
+ bool jump_key_modifier) {
LayerImpl* layer_impl = GetLayerHitByPoint(position_in_widget);
// If a non-custom scrollbar layer was not found, we return early as there is
@@ -88,12 +89,15 @@ InputHandlerPointerResult ScrollbarController::HandlePointerDown(
scroll_result.type = PointerResultType::kScrollbarScroll;
layer_tree_host_impl_->active_tree()->UpdateScrollbarGeometries();
const ScrollbarPart scrollbar_part =
- GetScrollbarPartFromPointerDown(scrollbar, position_in_widget);
+ GetScrollbarPartFromPointerDown(position_in_widget);
+ const bool perform_jump_click_on_track =
+ scrollbar->JumpOnTrackClick() != jump_key_modifier;
scroll_result.scroll_offset = GetScrollOffsetForScrollbarPart(
- scrollbar, scrollbar_part, shift_modifier);
+ scrollbar_part, perform_jump_click_on_track);
last_known_pointer_position_ = position_in_widget;
scrollbar_scroll_is_active_ = true;
- scroll_result.scroll_units = Granularity(scrollbar_part, shift_modifier);
+ scroll_result.scroll_units =
+ Granularity(scrollbar_part, perform_jump_click_on_track);
if (scrollbar_part == ScrollbarPart::THUMB) {
drag_state_ = DragState();
drag_state_->drag_origin = position_in_widget;
@@ -112,12 +116,12 @@ InputHandlerPointerResult ScrollbarController::HandlePointerDown(
// have the potential of initiating an autoscroll (if held down for long
// enough).
DCHECK(scrollbar_part != ScrollbarPart::THUMB);
- cancelable_autoscroll_task_ = std::make_unique<base::CancelableOnceClosure>(
- base::BindOnce(&ScrollbarController::StartAutoScrollAnimation,
- base::Unretained(this),
- InitialDeltaToAutoscrollVelocity(
- scrollbar, scroll_result.scroll_offset),
- scrollbar, scrollbar_part));
+ cancelable_autoscroll_task_ =
+ std::make_unique<base::CancelableOnceClosure>(base::BindOnce(
+ &ScrollbarController::StartAutoScrollAnimation,
+ base::Unretained(this),
+ InitialDeltaToAutoscrollVelocity(scroll_result.scroll_offset),
+ scrollbar_part));
layer_tree_host_impl_->task_runner_provider()
->ImplThreadTaskRunner()
->PostDelayedTask(FROM_HERE, cancelable_autoscroll_task_->callback(),
@@ -127,16 +131,16 @@ InputHandlerPointerResult ScrollbarController::HandlePointerDown(
}
bool ScrollbarController::SnapToDragOrigin(
- const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF pointer_position_in_widget) {
+ const gfx::PointF pointer_position_in_widget) const {
// Consult the ScrollbarTheme to check if thumb snapping is supported on the
// current platform.
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
if (!(scrollbar && scrollbar->SupportsDragSnapBack()))
return false;
bool clipped = false;
- const gfx::PointF pointer_position_in_layer = GetScrollbarRelativePosition(
- scrollbar, pointer_position_in_widget, &clipped);
+ const gfx::PointF pointer_position_in_layer =
+ GetScrollbarRelativePosition(pointer_position_in_widget, &clipped);
if (clipped)
return false;
@@ -189,10 +193,10 @@ bool ScrollbarController::SnapToDragOrigin(
ui::ScrollGranularity ScrollbarController::Granularity(
const ScrollbarPart scrollbar_part,
- const bool shift_modifier) {
+ const bool jump_key_modifier) const {
const bool shift_click_on_scrollbar_track =
- shift_modifier && (scrollbar_part == ScrollbarPart::FORWARD_TRACK ||
- scrollbar_part == ScrollbarPart::BACK_TRACK);
+ jump_key_modifier && (scrollbar_part == ScrollbarPart::FORWARD_TRACK ||
+ scrollbar_part == ScrollbarPart::BACK_TRACK);
if (shift_click_on_scrollbar_track || scrollbar_part == ScrollbarPart::THUMB)
return ui::ScrollGranularity::kScrollByPrecisePixel;
@@ -201,17 +205,17 @@ ui::ScrollGranularity ScrollbarController::Granularity(
return ui::ScrollGranularity::kScrollByPixel;
}
-float ScrollbarController::GetScrollDeltaForAbsoluteJump(
- const ScrollbarLayerImplBase* scrollbar) {
+float ScrollbarController::GetScrollDeltaForAbsoluteJump() const {
layer_tree_host_impl_->active_tree()->UpdateScrollbarGeometries();
bool clipped = false;
- const gfx::PointF pointer_position_in_layer = GetScrollbarRelativePosition(
- scrollbar, last_known_pointer_position_, &clipped);
+ const gfx::PointF pointer_position_in_layer =
+ GetScrollbarRelativePosition(last_known_pointer_position_, &clipped);
if (clipped)
return 0;
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
const float pointer_location =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? pointer_position_in_layer.y()
@@ -232,19 +236,18 @@ float ScrollbarController::GetScrollDeltaForAbsoluteJump(
const float delta =
round(std::abs(desired_thumb_origin - current_thumb_origin));
- return delta * GetScrollerToScrollbarRatio(scrollbar);
+ return delta * GetScrollerToScrollbarRatio();
}
int ScrollbarController::GetScrollDeltaForDragPosition(
- const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF pointer_position_in_widget) {
+ const gfx::PointF pointer_position_in_widget) const {
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
const float pointer_delta =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? pointer_position_in_widget.y() - drag_state_->drag_origin.y()
: pointer_position_in_widget.x() - drag_state_->drag_origin.x();
- const float new_offset =
- pointer_delta * GetScrollerToScrollbarRatio(scrollbar);
+ const float new_offset = pointer_delta * GetScrollerToScrollbarRatio();
const float scroll_delta = drag_state_->scroll_position_at_start_ +
new_offset - scrollbar->current_pos();
@@ -276,7 +279,7 @@ InputHandlerPointerResult ScrollbarController::HandlePointerMove(
if (drag_processed_for_current_frame_)
return scroll_result;
- if (SnapToDragOrigin(scrollbar, position_in_widget)) {
+ if (SnapToDragOrigin(position_in_widget)) {
const float delta =
scrollbar->current_pos() - drag_state_->scroll_position_at_start_;
scroll_result.scroll_units = ui::ScrollGranularity::kScrollByPrecisePixel;
@@ -302,7 +305,7 @@ InputHandlerPointerResult ScrollbarController::HandlePointerMove(
// valid ScrollNode.
DCHECK(target_node);
- int delta = GetScrollDeltaForDragPosition(scrollbar, position_in_widget);
+ int delta = GetScrollDeltaForDragPosition(position_in_widget);
if (drag_state_->scroller_length_at_previous_move !=
scrollbar->scroll_layer_length()) {
drag_state_->scroller_displacement = delta;
@@ -339,8 +342,7 @@ InputHandlerPointerResult ScrollbarController::HandlePointerMove(
return scroll_result;
}
-float ScrollbarController::GetScrollerToScrollbarRatio(
- const ScrollbarLayerImplBase* scrollbar) {
+float ScrollbarController::GetScrollerToScrollbarRatio() const {
// Calculating the delta by which the scroller layer should move when
// dragging the thumb depends on the following factors:
// - scrollbar_track_length
@@ -381,6 +383,7 @@ float ScrollbarController::GetScrollerToScrollbarRatio(
// |<- scrollbar_thumb_length ->|
//
layer_tree_host_impl_->active_tree()->UpdateScrollbarGeometries();
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
float scroll_layer_length = scrollbar->scroll_layer_length();
float scrollbar_track_length = scrollbar->TrackLength();
gfx::Rect thumb_rect(scrollbar->ComputeThumbQuadRect());
@@ -388,7 +391,7 @@ float ScrollbarController::GetScrollerToScrollbarRatio(
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? thumb_rect.height()
: thumb_rect.width();
- int viewport_length = GetViewportLength(scrollbar);
+ int viewport_length = GetViewportLength();
return (scroll_layer_length - viewport_length) /
(scrollbar_track_length - scrollbar_thumb_length);
@@ -399,11 +402,18 @@ void ScrollbarController::ResetState() {
drag_state_ = base::nullopt;
autoscroll_state_ = base::nullopt;
captured_scrollbar_metadata_ = base::nullopt;
+ if (cancelable_autoscroll_task_) {
+ cancelable_autoscroll_task_->Cancel();
+ cancelable_autoscroll_task_.reset();
+ }
}
-void ScrollbarController::DidUnregisterScrollbar(ElementId element_id) {
+void ScrollbarController::DidUnregisterScrollbar(
+ ElementId element_id,
+ ScrollbarOrientation orientation) {
if (captured_scrollbar_metadata_.has_value() &&
- captured_scrollbar_metadata_->scroll_element_id == element_id)
+ captured_scrollbar_metadata_->scroll_element_id == element_id &&
+ captured_scrollbar_metadata_->orientation == orientation)
ResetState();
}
@@ -413,12 +423,10 @@ void ScrollbarController::RecomputeAutoscrollStateIfNeeded() {
return;
layer_tree_host_impl_->active_tree()->UpdateScrollbarGeometries();
- const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
- const gfx::Rect thumb_quad = scrollbar->ComputeThumbQuadRect();
bool clipped;
- gfx::PointF scroller_relative_position(GetScrollbarRelativePosition(
- scrollbar, last_known_pointer_position_, &clipped));
+ gfx::PointF scroller_relative_position(
+ GetScrollbarRelativePosition(last_known_pointer_position_, &clipped));
if (clipped)
return;
@@ -429,6 +437,8 @@ void ScrollbarController::RecomputeAutoscrollStateIfNeeded() {
int thumb_start = 0;
int thumb_end = 0;
int pointer_position = 0;
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
+ const gfx::Rect thumb_quad = scrollbar->ComputeThumbQuadRect();
if (scrollbar->orientation() == ScrollbarOrientation::VERTICAL) {
thumb_start = thumb_quad.y();
thumb_end = thumb_quad.y() + thumb_quad.height();
@@ -458,7 +468,7 @@ void ScrollbarController::RecomputeAutoscrollStateIfNeeded() {
const float scroll_layer_length = scrollbar->scroll_layer_length();
if (autoscroll_state_->scroll_layer_length != scroll_layer_length) {
layer_tree_host_impl_->mutator_host()->ScrollAnimationAbort();
- StartAutoScrollAnimation(autoscroll_state_->velocity, scrollbar,
+ StartAutoScrollAnimation(autoscroll_state_->velocity,
autoscroll_state_->pressed_scrollbar_part);
}
}
@@ -466,8 +476,8 @@ void ScrollbarController::RecomputeAutoscrollStateIfNeeded() {
// The animations need to be aborted/restarted based on the pointer location
// (i.e leaving/entering the track/arrows, reaching the track end etc). The
// autoscroll_state_ however, needs to be reset on pointer changes.
- const gfx::RectF scrollbar_part_rect(GetRectForScrollbarPart(
- scrollbar, autoscroll_state_->pressed_scrollbar_part));
+ const gfx::RectF scrollbar_part_rect(
+ GetRectForScrollbarPart(autoscroll_state_->pressed_scrollbar_part));
if (!scrollbar_part_rect.Contains(scroller_relative_position)) {
// Stop animating if pointer moves outside the rect bounds.
layer_tree_host_impl_->mutator_host()->ScrollAnimationAbort();
@@ -475,17 +485,17 @@ void ScrollbarController::RecomputeAutoscrollStateIfNeeded() {
!layer_tree_host_impl_->mutator_host()->IsElementAnimating(
scrollbar->scroll_element_id())) {
// Start animating if pointer re-enters the bounds.
- StartAutoScrollAnimation(autoscroll_state_->velocity, scrollbar,
+ StartAutoScrollAnimation(autoscroll_state_->velocity,
autoscroll_state_->pressed_scrollbar_part);
}
}
// Helper to calculate the autoscroll velocity.
float ScrollbarController::InitialDeltaToAutoscrollVelocity(
- const ScrollbarLayerImplBase* scrollbar,
gfx::ScrollOffset scroll_offset) const {
+ DCHECK(captured_scrollbar_metadata_.has_value());
const float scroll_delta =
- scrollbar->orientation() == ScrollbarOrientation::VERTICAL
+ ScrollbarLayer()->orientation() == ScrollbarOrientation::VERTICAL
? scroll_offset.y()
: scroll_offset.x();
return scroll_delta * kAutoscrollMultiplier;
@@ -493,15 +503,17 @@ float ScrollbarController::InitialDeltaToAutoscrollVelocity(
void ScrollbarController::StartAutoScrollAnimation(
const float velocity,
- const ScrollbarLayerImplBase* scrollbar,
ScrollbarPart pressed_scrollbar_part) {
// Autoscroll and thumb drag are mutually exclusive. Both can't be active at
// the same time.
DCHECK(!drag_state_.has_value());
+ DCHECK(captured_scrollbar_metadata_.has_value());
DCHECK_NE(velocity, 0);
+ DCHECK(ScrollbarLayer());
// scroll_node is set up while handling GSB. If there's no node to scroll, we
// don't need to create any animation for it.
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
ScrollTree& scroll_tree =
layer_tree_host_impl_->active_tree()->property_trees()->scroll_tree;
ScrollNode* scroll_node =
@@ -552,18 +564,13 @@ InputHandlerPointerResult ScrollbarController::HandlePointerUp(
if (autoscroll_state_.has_value())
layer_tree_host_impl_->mutator_host()->ScrollAnimationAbort();
- if (cancelable_autoscroll_task_) {
- cancelable_autoscroll_task_->Cancel();
- cancelable_autoscroll_task_.reset();
- }
-
ResetState();
return scroll_result;
}
// Returns the layer that is hit by the position_in_widget.
LayerImpl* ScrollbarController::GetLayerHitByPoint(
- const gfx::PointF position_in_widget) {
+ const gfx::PointF position_in_widget) const {
LayerTreeImpl* active_tree = layer_tree_host_impl_->active_tree();
gfx::Point viewport_point(position_in_widget.x(), position_in_widget.y());
@@ -575,8 +582,8 @@ LayerImpl* ScrollbarController::GetLayerHitByPoint(
return layer_impl;
}
-int ScrollbarController::GetViewportLength(
- const ScrollbarLayerImplBase* scrollbar) const {
+int ScrollbarController::GetViewportLength() const {
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
const ScrollNode* scroll_node =
layer_tree_host_impl_->active_tree()
->property_trees()
@@ -587,30 +594,51 @@ int ScrollbarController::GetViewportLength(
: scroll_node->container_bounds.width();
}
+int ScrollbarController::GetScrollDeltaForPercentBasedScroll() const {
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
+
+ const ScrollNode* scroll_node =
+ layer_tree_host_impl_->active_tree()
+ ->property_trees()
+ ->scroll_tree.FindNodeFromElementId(scrollbar->scroll_element_id());
+ DCHECK(scroll_node);
+
+ const gfx::Vector2dF scroll_delta =
+ scrollbar->orientation() == ScrollbarOrientation::VERTICAL
+ ? gfx::Vector2dF(0, kPercentDeltaForDirectionalScroll)
+ : gfx::Vector2dF(kPercentDeltaForDirectionalScroll, 0);
+
+ const gfx::Vector2dF pixel_delta =
+ layer_tree_host_impl_->ResolveScrollGranularityToPixels(
+ *scroll_node, scroll_delta,
+ ui::ScrollGranularity::kScrollByPercentage);
+
+ return scrollbar->orientation() == ScrollbarOrientation::VERTICAL
+ ? pixel_delta.y()
+ : pixel_delta.x();
+}
+
int ScrollbarController::GetScrollDeltaForScrollbarPart(
- const ScrollbarLayerImplBase* scrollbar,
const ScrollbarPart scrollbar_part,
- const bool shift_modifier) {
+ const bool jump_key_modifier) const {
int scroll_delta = 0;
switch (scrollbar_part) {
case ScrollbarPart::BACK_BUTTON:
case ScrollbarPart::FORWARD_BUTTON:
if (layer_tree_host_impl_->settings().percent_based_scrolling) {
- scroll_delta =
- kPercentDeltaForDirectionalScroll * GetViewportLength(scrollbar);
+ scroll_delta = GetScrollDeltaForPercentBasedScroll();
} else {
scroll_delta = kPixelsPerLineStep * ScreenSpaceScaleFactor();
}
break;
case ScrollbarPart::BACK_TRACK:
case ScrollbarPart::FORWARD_TRACK: {
- if (shift_modifier) {
- scroll_delta = GetScrollDeltaForAbsoluteJump(scrollbar);
+ if (jump_key_modifier) {
+ scroll_delta = GetScrollDeltaForAbsoluteJump();
break;
}
- scroll_delta =
- GetViewportLength(scrollbar) * kMinFractionToStepWhenPaging;
+ scroll_delta = GetViewportLength() * kMinFractionToStepWhenPaging;
break;
}
default:
@@ -634,9 +662,8 @@ float ScrollbarController::ScreenSpaceScaleFactor() const {
}
gfx::PointF ScrollbarController::GetScrollbarRelativePosition(
- const ScrollbarLayerImplBase* scrollbar,
const gfx::PointF position_in_widget,
- bool* clipped) {
+ bool* clipped) const {
gfx::Transform inverse_screen_space_transform(
gfx::Transform::kSkipInitialization);
@@ -647,7 +674,7 @@ gfx::PointF ScrollbarController::GetScrollbarRelativePosition(
? 1.f / layer_tree_host_impl_->active_tree()->device_scale_factor()
: 1.f;
gfx::Transform scaled_screen_space_transform(
- scrollbar->ScreenSpaceTransform());
+ ScrollbarLayer()->ScreenSpaceTransform());
scaled_screen_space_transform.PostScale(scale, scale);
if (!scaled_screen_space_transform.GetInverse(
&inverse_screen_space_transform))
@@ -659,14 +686,14 @@ gfx::PointF ScrollbarController::GetScrollbarRelativePosition(
// Determines the ScrollbarPart based on the position_in_widget.
ScrollbarPart ScrollbarController::GetScrollbarPartFromPointerDown(
- const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF position_in_widget) {
+ const gfx::PointF position_in_widget) const {
// position_in_widget needs to be transformed and made relative to the
// scrollbar layer because hit testing assumes layer relative coordinates.
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
bool clipped = false;
const gfx::PointF scroller_relative_position(
- GetScrollbarRelativePosition(scrollbar, position_in_widget, &clipped));
+ GetScrollbarRelativePosition(position_in_widget, &clipped));
if (clipped)
return ScrollbarPart::NO_PART;
@@ -676,8 +703,8 @@ ScrollbarPart ScrollbarController::GetScrollbarPartFromPointerDown(
// Determines the corresponding rect for the given scrollbar part.
gfx::Rect ScrollbarController::GetRectForScrollbarPart(
- const ScrollbarLayerImplBase* scrollbar,
- const ScrollbarPart scrollbar_part) {
+ const ScrollbarPart scrollbar_part) const {
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
if (scrollbar_part == ScrollbarPart::BACK_BUTTON)
return scrollbar->BackButtonRect();
if (scrollbar_part == ScrollbarPart::FORWARD_BUTTON)
@@ -692,11 +719,11 @@ gfx::Rect ScrollbarController::GetRectForScrollbarPart(
// Determines the scroll offsets based on the ScrollbarPart and the scrollbar
// orientation.
gfx::ScrollOffset ScrollbarController::GetScrollOffsetForScrollbarPart(
- const ScrollbarLayerImplBase* scrollbar,
const ScrollbarPart scrollbar_part,
- const bool shift_modifier) {
+ const bool jump_key_modifier) const {
+ const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
float scroll_delta =
- GetScrollDeltaForScrollbarPart(scrollbar, scrollbar_part, shift_modifier);
+ GetScrollDeltaForScrollbarPart(scrollbar_part, jump_key_modifier);
// See CreateScrollStateForGesture for more information on how these values
// will be interpreted.
diff --git a/chromium/cc/input/scrollbar_controller.h b/chromium/cc/input/scrollbar_controller.h
index 4177c3464e5..ebe4dde9f09 100644
--- a/chromium/cc/input/scrollbar_controller.h
+++ b/chromium/cc/input/scrollbar_controller.h
@@ -119,24 +119,31 @@ class CC_EXPORT ScrollbarController {
explicit ScrollbarController(LayerTreeHostImpl*);
virtual ~ScrollbarController();
+ // On Mac, the "jump to the spot that's clicked" setting can be dynamically
+ // set via System Preferences. When enabled, the expectation is that regular
+ // clicks on the scrollbar should make the scroller "jump" to the clicked
+ // location rather than animated scrolling. Additionally, when this is enabled
+ // and the user does an Option + click on the scrollbar, the scroller should
+ // *not* jump to that spot (i.e it should be treated as a regular track
+ // click). When this setting is disabled on the Mac, Option + click should
+ // make the scroller jump and a regular click should animate the scroll
+ // offset. On all other platforms, the "jump on click" option is available
+ // (via Shift + click) but is not configurable.
InputHandlerPointerResult HandlePointerDown(
const gfx::PointF position_in_widget,
- const bool shift_modifier);
+ const bool jump_key_modifier);
InputHandlerPointerResult HandlePointerMove(
const gfx::PointF position_in_widget);
InputHandlerPointerResult HandlePointerUp(
const gfx::PointF position_in_widget);
- // "velocity" here is calculated based on the initial scroll delta (See
- // InitialDeltaToAutoscrollVelocity). This value carries a "sign" which is
- // needed to determine whether we should set up the autoscrolling in the
- // forwards or the backwards direction.
- void StartAutoScrollAnimation(float velocity,
- const ScrollbarLayerImplBase* scrollbar,
- ScrollbarPart pressed_scrollbar_part);
- bool ScrollbarScrollIsActive() { return scrollbar_scroll_is_active_; }
- void DidUnregisterScrollbar(ElementId element_id);
- ScrollbarLayerImplBase* ScrollbarLayer();
+ bool AutoscrollTaskIsScheduled() const {
+ return cancelable_autoscroll_task_ != nullptr;
+ }
+ bool ScrollbarScrollIsActive() const { return scrollbar_scroll_is_active_; }
+ void DidUnregisterScrollbar(ElementId element_id,
+ ScrollbarOrientation orientation);
+ ScrollbarLayerImplBase* ScrollbarLayer() const;
void WillBeginImplFrame();
void ResetState();
@@ -187,44 +194,42 @@ class CC_EXPORT ScrollbarController {
ScrollbarOrientation orientation;
};
+ // "velocity" here is calculated based on the initial scroll delta (See
+ // InitialDeltaToAutoscrollVelocity). This value carries a "sign" which is
+ // needed to determine whether we should set up the autoscrolling in the
+ // forwards or the backwards direction.
+ void StartAutoScrollAnimation(float velocity,
+ ScrollbarPart pressed_scrollbar_part);
+
// Returns the DSF based on whether use-zoom-for-dsf is enabled.
float ScreenSpaceScaleFactor() const;
// Helper to convert scroll offset to autoscroll velocity.
- float InitialDeltaToAutoscrollVelocity(
- const ScrollbarLayerImplBase* scrollbar,
- gfx::ScrollOffset scroll_offset) const;
+ float InitialDeltaToAutoscrollVelocity(gfx::ScrollOffset scroll_offset) const;
// Returns the hit tested ScrollbarPart based on the position_in_widget.
ScrollbarPart GetScrollbarPartFromPointerDown(
- const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF position_in_widget);
+ const gfx::PointF position_in_widget) const;
// Returns scroll offsets based on which ScrollbarPart was hit tested.
gfx::ScrollOffset GetScrollOffsetForScrollbarPart(
- const ScrollbarLayerImplBase* scrollbar,
const ScrollbarPart scrollbar_part,
- const bool shift_modifier);
+ const bool jump_key_modifier) const;
// Returns the rect for the ScrollbarPart.
- gfx::Rect GetRectForScrollbarPart(const ScrollbarLayerImplBase* scrollbar,
- const ScrollbarPart scrollbar_part);
+ gfx::Rect GetRectForScrollbarPart(const ScrollbarPart scrollbar_part) const;
- LayerImpl* GetLayerHitByPoint(const gfx::PointF position_in_widget);
- int GetScrollDeltaForScrollbarPart(const ScrollbarLayerImplBase* scrollbar,
- const ScrollbarPart scrollbar_part,
- const bool shift_modifier);
+ LayerImpl* GetLayerHitByPoint(const gfx::PointF position_in_widget) const;
+ int GetScrollDeltaForScrollbarPart(const ScrollbarPart scrollbar_part,
+ const bool jump_key_modifier) const;
// Makes position_in_widget relative to the scrollbar.
- gfx::PointF GetScrollbarRelativePosition(
- const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF position_in_widget,
- bool* clipped);
+ gfx::PointF GetScrollbarRelativePosition(const gfx::PointF position_in_widget,
+ bool* clipped) const;
// Decides if the scroller should snap to the offset that it was originally at
// (i.e the offset before the thumb drag).
- bool SnapToDragOrigin(const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF pointer_position_in_widget);
+ bool SnapToDragOrigin(const gfx::PointF pointer_position_in_widget) const;
// Decides whether a track autoscroll should be aborted (or restarted) due to
// the thumb reaching the pointer or the pointer leaving (or re-entering) the
@@ -233,22 +238,24 @@ class CC_EXPORT ScrollbarController {
// Shift (or "Option" in case of Mac) + click is expected to do a non-animated
// jump to a certain offset.
- float GetScrollDeltaForAbsoluteJump(const ScrollbarLayerImplBase* scrollbar);
+ float GetScrollDeltaForAbsoluteJump() const;
// Determines if the delta needs to be animated.
ui::ScrollGranularity Granularity(const ScrollbarPart scrollbar_part,
- bool shift_modifier);
+ bool jump_key_modifier) const;
// Calculates the delta based on position_in_widget and drag_origin.
int GetScrollDeltaForDragPosition(
- const ScrollbarLayerImplBase* scrollbar,
- const gfx::PointF pointer_position_in_widget);
+ const gfx::PointF pointer_position_in_widget) const;
// Returns the ratio of the scroller length to the scrollbar length. This is
// needed to scale the scroll delta for thumb drag.
- float GetScrollerToScrollbarRatio(const ScrollbarLayerImplBase* scrollbar);
+ float GetScrollerToScrollbarRatio() const;
+
+ int GetViewportLength() const;
- int GetViewportLength(const ScrollbarLayerImplBase* scrollbar) const;
+ // Returns the pixel delta for a percent-based scroll of the scrollbar
+ int GetScrollDeltaForPercentBasedScroll() const;
LayerTreeHostImpl* layer_tree_host_impl_;
diff --git a/chromium/cc/input/touch_action.h b/chromium/cc/input/touch_action.h
index f00d263acea..e873bd02d62 100644
--- a/chromium/cc/input/touch_action.h
+++ b/chromium/cc/input/touch_action.h
@@ -8,7 +8,7 @@
#include <cstdlib>
#include <string>
-#include "base/logging.h"
+#include "base/notreached.h"
namespace cc {