gecko-dev/layout
Markus Stange ebb461c874 Bug 1012752 - Snap scrolled area to layer pixels. r=tnikkel
We want the maximum scroll position to be aligned with layer pixels. That way
we don't have to re-rasterize the scrolled contents once scrolling hits the
edge of the scrollable area.

Here's how we determine the maximum scroll position: We get the scroll port
rect, snapped to layer pixels. Then we get the scrolled rect and also snap
that to layer pixels. The maximum scroll position is set to the difference
between right/bottom edges of these rectangles.
Now the scrollable area is computed by adding this maximum scroll position
to the unsnapped scroll port size.
The underlying idea here is: Pretend we have overflow:visible so that the
scrolled contents start at (0, 0) relative to the scroll port and spill over
the scroll port edges. When these contents are rendered, their rendering is
snapped to layer pixels. We want those exact pixels to be accessible by
scrolling.

This way of computing the snapped scrollable area ensures that, if you scroll
to the maximum scroll position, the right/bottom edges of the rendered
scrolled contents line up exactly with the right/bottom edges of the scroll
port. The scrolled contents are neither cut off nor are they moved too far.
(This is something that no other browser engine gets completely right, see the
testcase in bug 1012752.)

There are also a few disadvantages to this solution. We snap to layer pixels,
and the size of a layer pixel can depend on the zoom level, the document
resolution, the current screen's scale factor, and CSS transforms. The snap
origin is the position of the reference frame. So a change to any of these
things can influence the scrollable area and the maximum scroll position.
This patch does not make us adjust the current scroll position in the event
that the maximum scroll position changes such that the current scroll position
would be out of range, unless there's a reflow of the scrolled contents. This
means that we can sometimes render a slightly inconsistent state where the
current scroll position exceeds the maximum scroll position. We can fix this
once it turns out to be a problem; I doubt that it will be a problem because
none of the other browsers seems to prevent this problem either.

The size of the scrollable area is exposed through the DOM properties
scrollWidth and scrollHeight. At the moment, these are integer properties, so
their value is rounded to the nearest CSS pixel. Before this patch, the
returned value would always be within 0.5 CSS pixels of the value that layout
computed for the content's scrollable overflow based on the CSS styles of the
contents.
Now that scrollWidth and scrollHeight also depend on pixel snapping, their
values can deviate by up to one layer pixel from what the page might expect
based on the styles of the contents. This change requires a few changes to
existing tests.
The fact that scrollWidth and scrollHeight can change based on the position of
the scrollable element and the zoom level / resolution may surprise some web
pages. However, this also seems to happen in Edge. Edge seems to always round
scrollWidth and scrollHeight upwards, possibly to their equivalent of layout
device pixels.

MozReview-Commit-ID: 3LFV7Lio4tG

--HG--
extra : rebase_source : 3e4e0b60493397e61283aa1d7fd93d7c197dec29
extra : source : d43c2d5e87f31ff47d7f3ada66c3f5f27cef84a9
2016-08-04 23:51:58 -04:00
..
base Bug 1012752 - Snap scrolled area to layer pixels. r=tnikkel 2016-08-04 23:51:58 -04:00
build Introduce gfxVars for sharing graphics variables across processes. (bug 1288259 part 2, r=jrmuizel,billm) 2016-08-04 11:33:42 -07:00
doc Bug 906116 - part3.3: Replace NS_STYLE_HINT_FRAMECHANGE with nsChangeHint_ReconstructFrame. r=dbaron 2016-07-06 13:06:14 +08:00
forms Bug 1194027, add a flag to select elements to indicate if the parent process has the popup open, r=mrbkap 2016-08-03 07:45:46 -04:00
generic Bug 1012752 - Snap scrolled area to layer pixels. r=tnikkel 2016-08-04 23:51:58 -04:00
inspector Bug 1289007 - part1: parse and compute initial-letter property. r=heycam 2016-07-28 15:23:36 +08:00
ipc Bug 1286877 - do not set c-basic-offset for python-mode; r=gps 2016-07-14 10:16:42 -06:00
mathml Backed out changeset c0bf6e0b8f1d (bug 1173199) for build bustage CLOSED TREE 2016-07-28 11:48:20 -07:00
media Bug 1286877 - do not set c-basic-offset for python-mode; r=gps 2016-07-14 10:16:42 -06:00
printing Bug 1287446: Check and add nsIPrintProgressParams and print progress listener separately in nsPrintEngine::ShowPrintProgress. r=tnikkel 2016-08-03 09:50:24 +01:00
reftests Bug 1012752 - Snap scrolled area to layer pixels. r=tnikkel 2016-08-04 23:51:58 -04:00
style merge mozilla-inbound to mozilla-central a=merge 2016-08-04 15:55:50 +02:00
svg Bug 1058040, part 5 - Move the code from nsSVGUtils::SetupContextPaint and nsSVGUtils::GetContextPaint into SVGContextPaint. r=dholbert 2016-07-25 17:34:18 +01:00
tables Bug 1288992 Part 0 - Drop the nonsensical comment for nsTableFrame::ReflowChildren. r=dholbert 2016-07-27 11:22:15 +08:00
tools Bug 1286877 - do not set c-basic-offset for python-mode; r=gps 2016-07-14 10:16:42 -06:00
xul Bug 1159301, clear the mouse capture whenever a menu is opened, r=tn 2016-08-03 07:45:45 -04:00
moz.build Bug 1286877 - do not set c-basic-offset for python-mode; r=gps 2016-07-14 10:16:42 -06:00