Bug 1516722 - Don't let ScrollToVisual clobber further layout scrolling in the same transaction. r=kats

Test coverage for this is provided in the web platform test
html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-samedoc.html.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Botond Ballo 2019-05-07 03:03:56 +00:00
parent 5c7f1d92a6
commit 5101ae966a

View File

@ -2703,6 +2703,27 @@ void ScrollFrameHelper::ScrollToImpl(nsPoint aPt, const nsRect& aRange,
return;
}
// If we are scrolling the RCD-RSF, and a visual scroll update is pending,
// cancel it; otherwise, it will clobber this scroll.
if (IsRootScrollFrameOfDocument() && presContext->IsRootContentDocument()) {
PresShell* ps = presContext->GetPresShell();
if (const auto& visualScrollUpdate = ps->GetPendingVisualScrollUpdate()) {
if (visualScrollUpdate->mVisualScrollOffset != aPt) {
// Only clobber if the scroll was originated by the main thread.
// Respect the priority of origins (an "eRestore" layout scroll should
// not clobber an "eMainThread" visual scroll.)
bool shouldClobber =
aOrigin == nsGkAtoms::other ||
(aOrigin == nsGkAtoms::restore &&
visualScrollUpdate->mUpdateType == FrameMetrics::eRestore);
if (shouldClobber) {
ps->AcknowledgePendingVisualScrollUpdate();
ps->ClearPendingVisualScrollUpdate();
}
}
}
}
bool needFrameVisibilityUpdate = mLastUpdateFramesPos == nsPoint(-1, -1);
nsPoint dist(std::abs(pt.x - mLastUpdateFramesPos.x),