Skip to content

Commit 34d0fa8

Browse files
committed
Bug 1774315 - Don't clamp target scroll position to layer scale. r=mstange
This prevents scrollLeft = <integer> to return scrollLeft = <integer>, which is right now papered by bug 1674687. Differential Revision: https://phabricator.services.mozilla.com/D176306 UltraBlame original commit: 7ece24d43282c6c81fa92a42c2dde242ee848ed6
1 parent 1660eb1 commit 34d0fa8

File tree

12 files changed

+63
-635
lines changed

12 files changed

+63
-635
lines changed

dom/events/test/window_bug1369072.html

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div id="content" style="display: none">
2222
</div>
2323
<pre id="test">
24-
<script type="application/javascript">
24+
<script>
2525

2626
SimpleTest.waitForExplicitFinish();
2727
SimpleTest.waitForFocus(runTests, window);
@@ -31,6 +31,11 @@
3131
window.opener.ok.apply(window.opener, arguments);
3232
}
3333

34+
function info()
35+
{
36+
window.opener.info.apply(window.opener, arguments);
37+
}
38+
3439
function is()
3540
{
3641
window.opener.is.apply(window.opener, arguments);
@@ -89,23 +94,38 @@
8994
{
9095
await resetScroll();
9196

92-
return new Promise(resolve => {
93-
// Wait scroll event
94-
function onScroll() {
95-
SimpleTest.executeSoon(resolve);
96-
}
97-
window.addEventListener("scroll", onScroll, { once: true });
98-
iframe.contentWindow.addEventListener("scroll", onScroll, { once: true });
99-
100-
if (aVertical) {
101-
synthesizeKey("KEY_ArrowDown");
102-
} else {
103-
synthesizeKey("KEY_ArrowRight");
104-
}
105-
});
97+
function promiseScrollOnWindow(win) {
98+
is(win.document.documentElement.scrollTop, 0, "Reset didn't work?");
99+
is(win.document.documentElement.scrollLeft, 0, "Reset didn't work?");
100+
101+
return new Promise(resolve => {
102+
win.addEventListener("scroll", function listener() {
103+
// FIXME(bug 1674687): The first scroll might be fractional (and
104+
// scrollTop / Left will round down to zero until bug 1674687 is
105+
// fixed). So make sure we've scrolled at least a pixel before
106+
// resolving. This can be removed once bug 1674687 is fixed.
107+
if (win.document.documentElement.scrollLeft || win.document.documentElement.scrollTop) {
108+
win.removeEventListener("scroll", listener);
109+
SimpleTest.executeSoon(resolve);
110+
}
111+
});
112+
});
113+
}
114+
115+
let promise = Promise.race([
116+
promiseScrollOnWindow(window),
117+
promiseScrollOnWindow(iframe.contentWindow),
118+
]);
119+
120+
if (aVertical) {
121+
synthesizeKey("KEY_ArrowDown");
122+
} else {
123+
synthesizeKey("KEY_ArrowRight");
124+
}
125+
return promise;
106126
}
107127

108-
// When iframe element has focus and the iframe document isn't scrollable, the parent document should be scrolled instead.
128+
info("When iframe element has focus and the iframe document isn't scrollable, the parent document should be scrolled instead.");
109129
document.body.focus();
110130
iframe.focus();
111131
await tryToScrollWithKey(true);
@@ -114,7 +134,7 @@
114134
ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is not scrollable should cause scrolling the parent document");
115135
await resetScroll();
116136

117-
// When iframe element has focus and the iframe document scrollable, the parent document shouldn't be scrolled.
137+
info("When iframe element has focus and the iframe document scrollable, the parent document shouldn't be scrolled.");
118138
document.body.focus();
119139
div.style.height = "1000px";
120140
div.style.width = "1000px";
@@ -127,7 +147,7 @@
127147
ok(iframe.contentDocument.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable should cause scrolling the iframe document");
128148
await resetScroll();
129149

130-
// If iframe document cannot scroll to specific direction, parent document should be scrolled instead.
150+
info("If iframe document cannot scroll to specific direction, parent document should be scrolled instead.");
131151
div.style.height = "1px";
132152
div.style.width = "1000px";
133153
iframe.focus();
@@ -148,7 +168,7 @@
148168
ok(document.documentElement.scrollLeft > 0, "ArrowRight keydown event at the iframe whose content is scrollable only vertically should cause scrolling the parent document");
149169
await resetScroll();
150170

151-
// Hidden iframe shouldn't consume keyboard events if it was not scrollable.
171+
info("Hidden iframe shouldn't consume keyboard events if it was not scrollable.");
152172
document.body.focus();
153173
anchor.focus();
154174
iframe.style.display = "none";

gfx/layers/apz/test/mochitest/helper_scroll_linked_effect_detector.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
// Setup a scroll-linked effect callback.
5555
await promiseScrollAndEvent(() => {
5656
isnot(window.scrollY, 0, "we've already scrolled some amount");
57-
target.style.top = window.scrollY + "px";
57+
// ceil() makes sure that the non-effective setter below is actually
58+
// non-effective.
59+
target.style.top = Math.ceil(window.scrollY) + "px";
5860
eventTimeStamp = document.timeline.currentTime;
5961
});
6062
is(eventTimeStamp, document.timeline.currentTime,

gfx/layers/apz/test/mochitest/test_bug1151667.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@
4848
var subframe = document.getElementById("subframe");
4949
await promiseNativeWheelAndWaitForScrollEvent(subframe, 100, 150, 0, -10);
5050

51-
is(subframe.scrollTop > 0, true, "We should have scrolled the subframe down");
52-
is(document.documentElement.scrollTop, 0, "We should not have scrolled the page");
51+
while (!subframe.scrollTop) {
52+
is(document.documentElement.scrollTop, 0, "We should not have scrolled the page");
53+
info("Waiting for one more scroll");
54+
// FIXME(bug 1674687): The first scroll might be fractional, and thus still
55+
// round down to zero. Wait for another scroll event.
56+
// Remove this when bug 1674687 is fixed.
57+
await new Promise(r => subframe.addEventListener("scroll", r, { once: true }));
58+
}
59+
is(document.documentElement.scrollTop, 0, "We should still not have scrolled the page");
60+
ok(subframe.scrollTop > 0, "We should have scrolled the subframe down");
5361
}
5462

5563
SimpleTest.waitForExplicitFinish();

layout/generic/nsGfxScrollFrame.cpp

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,87 +2789,26 @@ void nsHTMLScrollFrame::ScrollVisual() {
27892789

27902790

27912791

2792-
2793-
2794-
2795-
2796-
2797-
static nscoord ClampAndAlignWithPixels(nscoord aDesired, nscoord aBoundLower,
2792+
static nscoord ClampScrollPositionAxis(nscoord aDesired, nscoord aBoundLower,
27982793
nscoord aBoundUpper, nscoord aDestLower,
2799-
nscoord aDestUpper,
2800-
nscoord aAppUnitsPerPixel, double aRes,
2801-
nscoord aCurrent) {
2794+
nscoord aDestUpper) {
28022795

28032796

28042797
nscoord destLower = clamped(aDestLower, aBoundLower, aBoundUpper);
28052798
nscoord destUpper = clamped(aDestUpper, aBoundLower, aBoundUpper);
2806-
2807-
nscoord desired = clamped(aDesired, destLower, destUpper);
2808-
2809-
double currentLayerVal = (aRes * aCurrent) / aAppUnitsPerPixel;
2810-
double desiredLayerVal = (aRes * desired) / aAppUnitsPerPixel;
2811-
double delta = desiredLayerVal - currentLayerVal;
2812-
double nearestLayerVal = NS_round(delta) + currentLayerVal;
2813-
2814-
2815-
2816-
nscoord aligned =
2817-
aRes == 0.0
2818-
? 0.0
2819-
: NSToCoordRoundWithClamp(nearestLayerVal * aAppUnitsPerPixel / aRes);
2820-
2821-
2822-
2823-
if (aBoundUpper == destUpper &&
2824-
static_cast<decltype(Abs(desired))>(aBoundUpper - desired) <
2825-
Abs(desired - aligned)) {
2826-
return aBoundUpper;
2827-
}
2828-
2829-
if (aBoundLower == destLower &&
2830-
static_cast<decltype(Abs(desired))>(desired - aBoundLower) <
2831-
Abs(aligned - desired)) {
2832-
return aBoundLower;
2833-
}
2834-
2835-
2836-
if (aligned >= destLower && aligned <= destUpper) {
2837-
return aligned;
2838-
}
2839-
2840-
2841-
double oppositeLayerVal =
2842-
nearestLayerVal + ((nearestLayerVal < desiredLayerVal) ? 1.0 : -1.0);
2843-
nscoord opposite = aRes == 0.0
2844-
? 0.0
2845-
: NSToCoordRoundWithClamp(oppositeLayerVal *
2846-
aAppUnitsPerPixel / aRes);
2847-
if (opposite >= destLower && opposite <= destUpper) {
2848-
return opposite;
2849-
}
2850-
2851-
2852-
return desired;
2799+
return clamped(aDesired, destLower, destUpper);
28532800
}
28542801

28552802

28562803

28572804

28582805

2859-
2860-
static nsPoint ClampAndAlignWithLayerPixels(const nsPoint& aPt,
2861-
const nsRect& aBounds,
2862-
const nsRect& aRange,
2863-
const nsPoint& aCurrent,
2864-
nscoord aAppUnitsPerPixel,
2865-
const MatrixScales& aScale) {
2866-
return nsPoint(
2867-
ClampAndAlignWithPixels(aPt.x, aBounds.x, aBounds.XMost(), aRange.x,
2868-
aRange.XMost(), aAppUnitsPerPixel, aScale.xScale,
2869-
aCurrent.x),
2870-
ClampAndAlignWithPixels(aPt.y, aBounds.y, aBounds.YMost(), aRange.y,
2871-
aRange.YMost(), aAppUnitsPerPixel, aScale.yScale,
2872-
aCurrent.y));
2806+
static nsPoint ClampScrollPosition(const nsPoint& aPt, const nsRect& aBounds,
2807+
const nsRect& aRange) {
2808+
return nsPoint(ClampScrollPositionAxis(aPt.x, aBounds.x, aBounds.XMost(),
2809+
aRange.x, aRange.XMost()),
2810+
ClampScrollPositionAxis(aPt.y, aBounds.y, aBounds.YMost(),
2811+
aRange.y, aRange.YMost()));
28732812
}
28742813

28752814

@@ -2983,11 +2922,7 @@ void nsHTMLScrollFrame::ScrollToImpl(
29832922
}
29842923

29852924
nsPresContext* presContext = PresContext();
2986-
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
2987-
2988-
2989-
MatrixScales scale = GetPaintedLayerScaleForFrame(mScrolledFrame);
2990-
nsPoint curPos = GetScrollPosition();
2925+
const nsPoint curPos = GetScrollPosition();
29912926

29922927

29932928

@@ -2999,8 +2934,7 @@ void nsHTMLScrollFrame::ScrollToImpl(
29992934

30002935

30012936

3002-
nsPoint pt = ClampAndAlignWithLayerPixels(aPt, GetLayoutScrollRange(), aRange,
3003-
curPos, appUnitsPerDevPixel, scale);
2937+
nsPoint pt = ClampScrollPosition(aPt, GetLayoutScrollRange(), aRange);
30042938
if (pt == curPos) {
30052939

30062940

testing/web-platform/meta/css/css-writing-modes/forms/text-input-vertical-overflow-no-scroll.html.ini

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616

1717
[input[type=text\] in sideways-lr: typing characters in input should not cause the page to scroll]
1818
expected:
19-
if (os == "win") and (processor == "x86_64") and debug and not swgl: FAIL
20-
if (os == "win") and (processor == "x86_64") and debug and swgl: [FAIL, PASS]
21-
if (os == "linux") and not debug and (processor == "x86_64") and fission: [FAIL, PASS]
22-
if (os == "win") and (processor == "x86") and debug: [FAIL, PASS]
23-
if (os == "android") and debug and not swgl: PASS
24-
if (os == "linux") and not debug and (processor == "x86"): [FAIL, PASS]
25-
if (os == "linux") and debug: FAIL
2619
if os == "mac": PASS
2720
[PASS, FAIL]
2821

@@ -46,12 +39,6 @@
4639

4740
[input[type=password\] in sideways-lr: typing characters in input should not cause the page to scroll]
4841
expected:
49-
if (os == "win") and not debug and (processor == "x86"): [PASS, FAIL]
50-
if (os == "android") and debug and swgl: [PASS, FAIL]
51-
if (os == "android") and debug and not swgl: PASS
52-
if (os == "linux") and not debug and not fission: [PASS, FAIL]
53-
if (os == "android") and not debug: [PASS, FAIL]
54-
if (os == "linux") and debug: FAIL
5542
if os == "mac": PASS
5643
[FAIL, PASS]
5744

@@ -73,12 +60,6 @@
7360

7461
[input[type=search\] in sideways-lr: typing characters in input should not cause the page to scroll]
7562
expected:
76-
if (os == "win") and not swgl and not debug and (processor == "x86"): [PASS, FAIL]
77-
if (os == "android") and debug and not swgl: PASS
78-
if (os == "android") and debug and swgl: [PASS, FAIL]
79-
if (os == "linux") and debug: FAIL
80-
if (os == "android") and not debug: [PASS, FAIL]
81-
if (os == "win") and swgl: [PASS, FAIL]
8263
if os == "mac": PASS
8364
[FAIL, PASS]
8465

@@ -97,13 +78,6 @@
9778

9879
[input[type=number\] in sideways-lr: typing characters in input should not cause the page to scroll]
9980
expected:
100-
if (os == "linux") and debug and fission and not swgl: FAIL
101-
if (os == "linux") and debug and not fission: FAIL
102-
if (os == "android") and debug and swgl: [PASS, FAIL]
103-
if (os == "android") and debug and not swgl: PASS
104-
if (os == "win") and debug and (processor == "x86"): FAIL
105-
if (os == "win") and not debug and (processor == "x86_64"): [PASS, FAIL]
106-
if (os == "android") and not debug: [PASS, FAIL]
10781
if os == "mac": PASS
10882
[FAIL, PASS]
10983

0 commit comments

Comments
 (0)