Bug 1543485 - Also update the code in ScrollToImpl() that proactively updates the callback transform and main thread visual viewport offset. r=kats

Differential Revision: https://phabricator.services.mozilla.com/D87692
This commit is contained in:
Botond Ballo 2020-08-21 01:24:59 +00:00
parent 27cd351633
commit a621152a3c

View File

@ -3027,22 +3027,17 @@ void ScrollFrameHelper::ScrollToImpl(nsPoint aPt, const nsRect& aRange,
}
// If the new scroll offset is going to clobber APZ's scroll offset, for
// the RCD-RSF this will have the effect of resetting the visual viewport
// offset to be the same as the new scroll (= layout viewport) offset.
// The APZ callback transform, which reflects the difference between these
// offsets, will subsequently be cleared. However, if we wait for APZ to
// clear it, the main thread could end up using the old value and get
// incorrect results, so just clear it now.
// the RCD-RSF this will have the effect of updating the visual viewport
// offset in a way that keeps the relative offset between the layout and
// visual viewports constant. This will cause APZ to send us a new visual
// viewport offset, but instead of waiting for that, just set the value
// we expect APZ will set ourselves, to minimize the chances of
// inconsistencies from querying a stale value.
if (mIsRoot && nsLayoutUtils::CanScrollOriginClobberApz(mLastScrollOrigin)) {
content->SetProperty(nsGkAtoms::apzCallbackTransform, new CSSPoint(),
nsINode::DeleteProperty<CSSPoint>);
// Similarly, update the main thread's view of the visual viewport
// offset. Otherwise, if we perform calculations that depend on this
// offset (e.g. by using nsIDOMWindowUtils.getVisualViewportOffset()
// in chrome JS code) before it's updated by the next APZ repaint,
// we could get incorrect results.
presContext->PresShell()->SetVisualViewportOffset(pt, curPos);
nsPoint relativeOffset =
presContext->PresShell()->GetVisualViewportOffset() - curPos;
presContext->PresShell()->SetVisualViewportOffset(pt + relativeOffset,
curPos);
}
ScrollVisual();