summaryrefslogtreecommitdiffstats
path: root/content/renderer/input
diff options
context:
space:
mode:
authorccameron <ccameron@chromium.org>2015-02-19 17:53:04 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-20 01:53:37 +0000
commit3a3650b341657090d19829ee2ac8d218b004c6a0 (patch)
treeac58eeed55258332eabc77c6793d814336195c0b /content/renderer/input
parent8476015c8a209afc3a75dcaf97e09f98d271d7cc (diff)
downloadchromium_src-3a3650b341657090d19829ee2ac8d218b004c6a0.zip
chromium_src-3a3650b341657090d19829ee2ac8d218b004c6a0.tar.gz
chromium_src-3a3650b341657090d19829ee2ac8d218b004c6a0.tar.bz2
Mac: Disable elastic overscroll when pages are not user scrollable
This matches Safari behavior in that pages that have overflow:hidden set on their body do not have the overscroll effect. BUG=456546 Review URL: https://codereview.chromium.org/942623002 Cr-Commit-Position: refs/heads/master@{#317215}
Diffstat (limited to 'content/renderer/input')
-rw-r--r--content/renderer/input/input_scroll_elasticity_controller.cc6
-rw-r--r--content/renderer/input/input_scroll_elasticity_controller_unittest.cc58
2 files changed, 63 insertions, 1 deletions
diff --git a/content/renderer/input/input_scroll_elasticity_controller.cc b/content/renderer/input/input_scroll_elasticity_controller.cc
index 0ab8cb0..00d078f 100644
--- a/content/renderer/input/input_scroll_elasticity_controller.cc
+++ b/content/renderer/input/input_scroll_elasticity_controller.cc
@@ -182,6 +182,12 @@ void InputScrollElasticityController::UpdateVelocity(
void InputScrollElasticityController::Overscroll(
const gfx::Vector2dF& input_delta,
const gfx::Vector2dF& overscroll_delta) {
+ // The effect can be dynamically disabled by setting disallowing user
+ // scrolling. When disabled, disallow active or momentum overscrolling, but
+ // allow any current overscroll to animate back.
+ if (!helper_->IsUserScrollable())
+ return;
+
gfx::Vector2dF adjusted_overscroll_delta =
pending_overscroll_delta_ + overscroll_delta;
pending_overscroll_delta_ = gfx::Vector2dF();
diff --git a/content/renderer/input/input_scroll_elasticity_controller_unittest.cc b/content/renderer/input/input_scroll_elasticity_controller_unittest.cc
index 3adaa05..fa2c7f1 100644
--- a/content/renderer/input/input_scroll_elasticity_controller_unittest.cc
+++ b/content/renderer/input/input_scroll_elasticity_controller_unittest.cc
@@ -23,11 +23,13 @@ enum Phase {
class MockScrollElasticityHelper : public cc::ScrollElasticityHelper {
public:
MockScrollElasticityHelper()
- : set_stretch_amount_count_(0),
+ : is_user_scrollable_(true),
+ set_stretch_amount_count_(0),
request_animate_count_(0) {}
~MockScrollElasticityHelper() override {}
// cc::ScrollElasticityHelper implementation:
+ bool IsUserScrollable() const override { return is_user_scrollable_; }
gfx::Vector2dF StretchAmount() const override { return stretch_amount_; }
void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override {
set_stretch_amount_count_ += 1;
@@ -52,8 +54,12 @@ class MockScrollElasticityHelper : public cc::ScrollElasticityHelper {
scroll_offset_ = scroll_offset;
max_scroll_offset_ = max_scroll_offset;
}
+ void SetUserScrollable(bool is_user_scrollable) {
+ is_user_scrollable_ = is_user_scrollable;
+ }
private:
+ bool is_user_scrollable_;
gfx::Vector2dF stretch_amount_;
int set_stretch_amount_count_;
int request_animate_count_;
@@ -327,5 +333,55 @@ TEST_F(ScrollElasticityControllerTest, ReconcileStretchAndScroll) {
EXPECT_EQ(helper_.ScrollOffset(), gfx::ScrollOffset(7, 8));
}
+// Verify that stretching only happens when the area is user scrollable.
+TEST_F(ScrollElasticityControllerTest, UserScrollableRequiredForStretch) {
+ helper_.SetScrollOffsetAndMaxScrollOffset(gfx::ScrollOffset(0, 0),
+ gfx::ScrollOffset(10, 10));
+ gfx::Vector2dF delta(0, -15);
+
+ // Do an active scroll, and ensure that the stretch amount doesn't change,
+ // and also that the stretch amount isn't even ever changed.
+ helper_.SetUserScrollable(false);
+ SendMouseWheelEvent(PhaseBegan, PhaseNone);
+ SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta);
+ SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta);
+ SendMouseWheelEvent(PhaseEnded, PhaseNone);
+ EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
+ EXPECT_EQ(0, helper_.set_stretch_amount_count());
+ SendMouseWheelEvent(PhaseNone, PhaseBegan);
+ SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta);
+ SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta);
+ SendMouseWheelEvent(PhaseNone, PhaseEnded);
+ EXPECT_EQ(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
+ EXPECT_EQ(0, helper_.set_stretch_amount_count());
+
+ // Re-enable user scrolling and ensure that stretching is re-enabled.
+ helper_.SetUserScrollable(true);
+ SendMouseWheelEvent(PhaseBegan, PhaseNone);
+ SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta);
+ SendMouseWheelEvent(PhaseChanged, PhaseNone, delta, delta);
+ SendMouseWheelEvent(PhaseEnded, PhaseNone);
+ EXPECT_NE(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
+ EXPECT_GT(helper_.set_stretch_amount_count(), 0);
+ SendMouseWheelEvent(PhaseNone, PhaseBegan);
+ SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta);
+ SendMouseWheelEvent(PhaseNone, PhaseChanged, delta, delta);
+ SendMouseWheelEvent(PhaseNone, PhaseEnded);
+ EXPECT_NE(helper_.StretchAmount(), gfx::Vector2dF(0, 0));
+ EXPECT_GT(helper_.set_stretch_amount_count(), 0);
+
+ // Disable user scrolling and tick the timer until the stretch goes back
+ // to zero. Ensure that the return to zero doesn't happen immediately.
+ helper_.SetUserScrollable(false);
+ int ticks_to_zero = 0;
+ while (1) {
+ TickCurrentTimeAndAnimate();
+ if (helper_.StretchAmount().IsZero())
+ break;
+ ticks_to_zero += 1;
+ }
+ EXPECT_GT(ticks_to_zero, 3);
+}
+
} // namespace
} // namespace content