Bug 1562757 - Call ScrollToVisual for the pres shell of the given scrollable frame in ScrollToShowRect. r=botond

We should also check IsRootContentDocumentCrossProcess instead of
IsRootContentDocument there, it will be fixed in bug 1562505.

The test case in this commit is almost copied-n-pasted from
helper_scroll_into_view_bug1516056.html.

Differential Revision: https://phabricator.services.mozilla.com/D36556

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-07-04 08:48:47 +00:00
parent 41873b4380
commit c9de23aa09
3 changed files with 75 additions and 13 deletions

View File

@ -0,0 +1,69 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=2.0">
<title>Test for bug 1562757: "scroll into view" in iframe respects bounds on layout scroll position</title>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
#iframe {
width: 100px;
height: 100px;
margin-left: 50%;
margin-right: 50%;
background: cyan;
display: block;
}
</style>
</head>
<body>
<iframe id="iframe" scrolling="no" frameborder="no" srcdoc="<div id='target' style='width:100px;height:100px;'></div>"></iframe>
<script>
let vv = window.visualViewport;
function getVisualScrollRange() {
let rootScroller = document.scrollingElement;
return {
width: rootScroller.scrollWidth - vv.width,
height: rootScroller.scrollHeight - vv.height,
};
}
function getVisualViewportRect() {
return {
x: vv.pageLeft,
y: vv.pageTop,
w: vv.width,
h: vv.height,
};
}
function* test(testDriver) {
SimpleTest.is(window.scrollMaxX, 0, "page should have a zero horizontal layout scroll range");
SimpleTest.is(window.scrollMaxY, 0, "page should have a zero vertical layout scroll range");
let visualScrollRange = getVisualScrollRange();
SimpleTest.ok(visualScrollRange.width > 0, "page should have a nonzero horizontal visual scroll range");
SimpleTest.ok(visualScrollRange.height > 0, "page should have a nonzero vertical visual scroll range");
let target = iframe.contentDocument.getElementById("target");
// Scroll target element into view. Wait until any visual scrolling is done before doing checks.
vv.addEventListener("scroll", testDriver, { once: true });
target.scrollIntoView();
yield; // wait for visual viewport "scroll" event
yield waitForApzFlushedRepaints(testDriver);
// Test that scrollIntoView() respected the layout scroll range.
SimpleTest.is(window.scrollX, 0, "page should not layout-scroll with a zero layout scroll range");
SimpleTest.is(window.scrollY, 0, "page should not layout-scroll with a zero layout scroll range");
// Test that scrollIntoView() did perform visual scrolling.
let vvRect = getVisualViewportRect();
let targetBounds = iframe.getBoundingClientRect();
// set property names expected by rectContains()
targetBounds.w = targetBounds.width;
targetBounds.h = targetBounds.height;
assertRectContainment(vvRect, "visual viewport", targetBounds, "iframe having the target element bounding rect");
}
waitUntilApzStable().then(runContinuation(test)).then(subtestDone);
</script>
</body>
</html>

View File

@ -66,6 +66,7 @@ var subtests = [
{"file": "helper_onetouchpinch_nested.html", "prefs": onetouchpinch_prefs},
{"file": "helper_visual_smooth_scroll.html", "prefs": prefs},
{"file": "helper_scroll_into_view_bug1516056.html", "prefs": prefs},
{"file": "helper_scroll_into_view_bug1562757.html", "prefs": prefs},
{"file": "helper_fixed_pos_displayport.html", "prefs": prefs},
];

View File

@ -3336,15 +3336,8 @@ static nscoord ComputeWhereToScroll(WhereToScroll aWhereToScroll,
* visual viewport.
*
* This needs to work even if aRect has a width or height of zero.
*
* Note that, since we are performing a layout scroll, it's possible that
* this fnction will sometimes be unsuccessful; the content will move as
* fast as it can on the screen using layout viewport scrolling, and then
* stop there, even if it could get closer to the desired position by
* moving the visual viewport within the layout viewport.
*/
static void ScrollToShowRect(PresShell* aPresShell,
nsIScrollableFrame* aFrameAsScrollable,
static void ScrollToShowRect(nsIScrollableFrame* aFrameAsScrollable,
const nsRect& aRect, ScrollAxis aVertical,
ScrollAxis aHorizontal, ScrollFlags aScrollFlags) {
nsPoint scrollPt = aFrameAsScrollable->GetVisualViewportOffset();
@ -3423,9 +3416,9 @@ static void ScrollToShowRect(PresShell* aPresShell,
// the visual viewport in scenarios where there is not enough layout
// scroll range.
if (aFrameAsScrollable->IsRootScrollFrameOfDocument() &&
aPresShell->GetPresContext()->IsRootContentDocument()) {
aPresShell->ScrollToVisual(scrollPt, FrameMetrics::eMainThread,
scrollMode);
frame->PresShell()->GetPresContext()->IsRootContentDocument()) {
frame->PresShell()->ScrollToVisual(scrollPt, FrameMetrics::eMainThread,
scrollMode);
}
}
}
@ -3593,8 +3586,7 @@ bool PresShell::ScrollFrameRectIntoView(nsIFrame* aFrame, const nsRect& aRect,
{
AutoWeakFrame wf(container);
ScrollToShowRect(this, sf, targetRect, aVertical, aHorizontal,
aScrollFlags);
ScrollToShowRect(sf, targetRect, aVertical, aHorizontal, aScrollFlags);
if (!wf.IsAlive()) {
return didScroll;
}