scrollTop value is wrong after page zooming. |
||||
Issue descriptionChrome Version: 62.0.3195.0 OS: All What steps will reproduce the problem? (1) Open a website which has scrollbar(www.yahoo.com). (2) Zoom the page to maybe 70% or 150%. (3) Open JS console. Set |document.scrollElement.scrollTop| to some value. (We test 1001, 2323) What is the expected result? |document.scrollElement.scrollTop| become what we set. What happens instead? It become some different value. ex: At 75% zooming, we set it to 2323 and it become 2322.666748046875. At 50% zooming, we set it to 1001 and it become 1000.
,
Aug 30 2017
,
Aug 30 2017
,
Aug 30 2017
The wrong scrollTop value is caused by truncating to integer in ScrollableArea::ScrollOffsetChanged(). ex: zoom: 110% > document.scrollElement.scrollTop = 1001; Element::setScrollTop(1001.0) ScrollableArea::ScrollOffsetChanged() called with offset.Height() = 1101.1 the offset was truncated to 1101.0 as ShouldUseIntegerScrollOffset() returns true > document.scrollElement.scrollTop; in LocalDOMWindow::scrollY(), view->LayoutViewportScrollableArea()->GetScrollOffset().Height() returns 1101.0 Element::scrollTop() returns 1000.909058
,
Aug 30 2017
,
Aug 30 2017
This is due to a combination of two issues: 1) Scroll offsets need to be aligned to the device pixel grid (or everything will become blurry). 2) Scroll values are exposed as floating point with limited precision. Say you set scrollTop to 1001px at a 75% zoom factor, that translates to ~750.75 device pixels. We can't scroll to that exact offset so instead it is truncated to 750. When you now query the scrollTop value in JS we take the actual offset (750) and adjust it for the zoom factor resulting in 1000px. This might be unexpected but it is working as intended from the browser point of view as we chose to have the return values match the *actual* values rather than the ideal/specified values. This to ensure that one can correctly identify whether something is within the viewport or whether one has scrolled to the bottom/right of a scroller. Hope this helps and thanks for the report. |
||||
►
Sign in to add a comment |
||||
Comment 1 by chungsheng@google.com
, Aug 30 2017