- Revision
- 186160
- Author
- [email protected]
- Date
- 2015-06-30 18:51:16 -0700 (Tue, 30 Jun 2015)
Log Message
scroll-snap-points do not work very well with mechanical scroll wheel events
https://bugs.webkit.org/show_bug.cgi?id=142501
<rdar://problem/20093511>
Patch by Wenson Hsieh <[email protected]> on 2015-06-30
Reviewed by Brent Fulgham.
Source/WebCore:
Stateless scroll events generated by scrolling with a mechanical mouse wheel now trigger scroll
snapping after a fixed delay.
Test: platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html
* platform/cocoa/ScrollController.h: Added member to track stateless scrolling.
* platform/cocoa/ScrollController.mm: Added constant for delay for stateless scroll snapping.
(WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Triggers timer upon stateless scroll events.
(WebCore::ScrollController::horizontalScrollSnapTimerFired): Timer now handles stateless scrolling updates.
(WebCore::ScrollController::verticalScrollSnapTimerFired): See above.
(WebCore::ScrollController::beginScrollSnapAnimation): Handles stateless scroll snapping.
LayoutTests:
* platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt: Added.
* platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (186159 => 186160)
--- trunk/LayoutTests/ChangeLog 2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/LayoutTests/ChangeLog 2015-07-01 01:51:16 UTC (rev 186160)
@@ -1,3 +1,14 @@
+2015-06-30 Wenson Hsieh <[email protected]>
+
+ scroll-snap-points do not work very well with mechanical scroll wheel events
+ https://bugs.webkit.org/show_bug.cgi?id=142501
+ <rdar://problem/20093511>
+
+ Reviewed by Brent Fulgham.
+
+ * platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt: Added.
+ * platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html: Added.
+
2015-06-30 Chris Dumez <[email protected]>
Unreviewed, rebaseline editing/style/unbold-in-bold.html on WK2.
Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt (0 => 186160)
--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt 2015-07-01 01:51:16 UTC (rev 186160)
@@ -0,0 +1,9 @@
+Tests that the scroll-snap feature works properly in overflow regions when using a mechanical mouse wheel.
+ PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS div honored snap points.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html (0 => 186160)
--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html 2015-07-01 01:51:16 UTC (rev 186160)
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <style>
+ .gallery {
+ width: 400px;
+ height: 400px;
+ display: inline-block;
+ overflow-x: hidden;
+ overflow-y: auto;
+ -webkit-scroll-snap-points-y: repeat(400px);
+ -webkit-scroll-snap-type: mandatory;
+ }
+ .colorBox {
+ height: 400px;
+ width: 400px;
+ }
+ #item0, #item2 { background-color: red; }
+ #item1 { background-color: green; }
+ </style>
+ <script src=""
+ <script>
+ function finishTest()
+ {
+ finishJSTest();
+ testRunner.notifyDone();
+ }
+
+ function locationInWindowCoordinates(element)
+ {
+ var position = {};
+ position.x = element.offsetLeft;
+ position.y = element.offsetTop;
+
+ while (element.offsetParent) {
+ position.x = position.x + element.offsetParent.offsetLeft;
+ position.y = position.y + element.offsetParent.offsetTop;
+ if (element == document.getElementsByTagName("body")[0])
+ break;
+
+ element = element.offsetParent;
+ }
+
+ return position;
+ }
+
+ function scrollSnapTest()
+ {
+ var divTarget = document.getElementById("target");
+ var windowPosition = locationInWindowCoordinates(divTarget);
+
+ var startPosX = windowPosition.x + 0.5 * divTarget.clientWidth;
+ var startPosY = windowPosition.y + 0.5 * divTarget.clientHeight;
+ eventSender.mouseMoveTo(startPosX, startPosY);
+ // Each unit of stateless scroll is scaled by 10 pixels.
+ eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, "none", "none", false);
+ eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, "none", "none", false);
+ eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, "none", "none", false);
+ // Wait for the snapping to finish.
+ setTimeout(function() {
+ if (divTarget.scrollTop != 400)
+ testFailed("div did not snap to the green region. Expected 400, but got " + divTarget.scrollTop + ".");
+ else
+ testPassed("div honored snap points.");
+
+ finishTest();
+ }, 2000);
+ }
+
+
+ function onLoad()
+ {
+ if (window.eventSender) {
+ window.jsTestIsAsync = true;
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+
+ eventSender.monitorWheelEvents();
+ setTimeout(scrollSnapTest, 0);
+ } else {
+ var messageLocationH = document.getElementById("item0");
+ var message = document.createElement("div");
+ message.innerHTML = "This test is better run under DumpRenderTree. To manually<br/>"
+ + "test it, place the mouse pointer inside the red region at the<br/>"
+ + "top of the page, and then, using a mechanical mouse wheel,<br/>"
+ + "scroll so that the green region takes up more of the<br/>"
+ + "container than the surrounding red regions. After a brief<br/>"
+ + "pause, the target should scroll so that the green region is<br/>"
+ + "fully visible, and no red is visible.";
+ messageLocationH.appendChild(message);
+ }
+ }
+ </script>
+ </head>
+ <body _onload_="onLoad();">
+ <div style="position: relative; width: 400px">
+ <div>Tests that the scroll-snap feature works properly in overflow regions when using a mechanical mouse wheel.</div>
+ <div class="gallery" id="target">
+ <div id="item0" class="colorBox"></div>
+ <div id="item1" class="colorBox"></div>
+ <div id="item2" class="colorBox"></div>
+ </div>
+ <div id="console"></div>
+ </div>
+ <script src=""
+ </body>
+</html>
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (186159 => 186160)
--- trunk/Source/WebCore/ChangeLog 2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/Source/WebCore/ChangeLog 2015-07-01 01:51:16 UTC (rev 186160)
@@ -1,3 +1,23 @@
+2015-06-30 Wenson Hsieh <[email protected]>
+
+ scroll-snap-points do not work very well with mechanical scroll wheel events
+ https://bugs.webkit.org/show_bug.cgi?id=142501
+ <rdar://problem/20093511>
+
+ Reviewed by Brent Fulgham.
+
+ Stateless scroll events generated by scrolling with a mechanical mouse wheel now trigger scroll
+ snapping after a fixed delay.
+
+ Test: platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html
+
+ * platform/cocoa/ScrollController.h: Added member to track stateless scrolling.
+ * platform/cocoa/ScrollController.mm: Added constant for delay for stateless scroll snapping.
+ (WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Triggers timer upon stateless scroll events.
+ (WebCore::ScrollController::horizontalScrollSnapTimerFired): Timer now handles stateless scrolling updates.
+ (WebCore::ScrollController::verticalScrollSnapTimerFired): See above.
+ (WebCore::ScrollController::beginScrollSnapAnimation): Handles stateless scroll snapping.
+
2015-06-30 Simon Fraser <[email protected]>
Try to fix Gtk and EFL builds.
Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.h (186159 => 186160)
--- trunk/Source/WebCore/platform/cocoa/ScrollController.h 2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.h 2015-07-01 01:51:16 UTC (rev 186160)
@@ -188,6 +188,7 @@
#endif
#if ENABLE(CSS_SCROLL_SNAP)
+ bool m_expectingStatelessScrollSnap { false };
std::unique_ptr<ScrollSnapAnimatorState> m_horizontalScrollSnapState;
std::unique_ptr<ScrollSnapAnimatorState> m_verticalScrollSnapState;
#if PLATFORM(MAC)
Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.mm (186159 => 186160)
--- trunk/Source/WebCore/platform/cocoa/ScrollController.mm 2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.mm 2015-07-01 01:51:16 UTC (rev 186160)
@@ -86,6 +86,8 @@
static const float maxTargetWheelDelta = 7;
static const float minTargetWheelDelta = 3.5;
+
+static const double statelessScrollSnapDelay = 0.5;
#endif
#if PLATFORM(MAC)
@@ -583,6 +585,11 @@
endScrollSnapAnimation(axis, ScrollSnapState::UserInteraction);
snapState.clearInitialWheelDeltaWindow();
snapState.m_shouldOverrideWheelEvent = false;
+ m_expectingStatelessScrollSnap = true;
+ if (axis == ScrollEventAxis::Vertical)
+ m_verticalScrollSnapTimer.startOneShot(statelessScrollSnapDelay);
+ else
+ m_horizontalScrollSnapTimer.startOneShot(statelessScrollSnapDelay);
break;
case WheelEventStatus::Unknown:
@@ -668,12 +675,18 @@
void ScrollController::horizontalScrollSnapTimerFired()
{
- scrollSnapAnimationUpdate(ScrollEventAxis::Horizontal);
+ if (m_expectingStatelessScrollSnap)
+ beginScrollSnapAnimation(ScrollEventAxis::Horizontal, ScrollSnapState::Snapping);
+ else
+ scrollSnapAnimationUpdate(ScrollEventAxis::Horizontal);
}
void ScrollController::verticalScrollSnapTimerFired()
{
- scrollSnapAnimationUpdate(ScrollEventAxis::Vertical);
+ if (m_expectingStatelessScrollSnap)
+ beginScrollSnapAnimation(ScrollEventAxis::Vertical, ScrollSnapState::Snapping);
+ else
+ scrollSnapAnimationUpdate(ScrollEventAxis::Vertical);
}
void ScrollController::scrollSnapAnimationUpdate(ScrollEventAxis axis)
@@ -768,7 +781,10 @@
void ScrollController::beginScrollSnapAnimation(ScrollEventAxis axis, ScrollSnapState newState)
{
ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);
-
+ if (m_expectingStatelessScrollSnap) {
+ m_expectingStatelessScrollSnap = false;
+ stopScrollSnapTimer(axis);
+ }
ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
LayoutUnit offset = m_client.scrollOffsetOnAxis(axis);