Bug 1566783 - Make sure to clear mLastAnchorScrolledTo after calling PresShell::ScrollToAnchor(). r=dholbert

Seems we can leave this node alive for too long if the user scrolls between
domcontentloaded (where GoToAnchor is called) and onload (where ScrollToAnchor()
is called).

Though it seems we can leave it for too long if we don't end up calling
ScrollToAnchor(), the documentation of the method claims that it's cleared
unconditionally.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-07-20 15:09:07 +00:00
Родитель 937b1f9834
Коммит dcd7223f09
1 изменённых файлов: 6 добавлений и 8 удалений

Просмотреть файл

@ -3184,22 +3184,20 @@ nsresult PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll,
}
nsresult PresShell::ScrollToAnchor() {
if (!mLastAnchorScrolledTo) {
nsCOMPtr<nsIContent> lastAnchor = mLastAnchorScrolledTo.forget();
if (!lastAnchor) {
return NS_OK;
}
NS_ASSERTION(mDidInitialize, "should have done initial reflow by now");
NS_ASSERTION(mDidInitialize, "should have done initial reflow by now");
nsIScrollableFrame* rootScroll = GetRootScrollFrameAsScrollable();
if (!rootScroll ||
mLastAnchorScrollPositionY != rootScroll->GetScrollPosition().y) {
return NS_OK;
}
nsCOMPtr<nsIContent> lastAnchorScrollTo = mLastAnchorScrolledTo;
nsresult rv = ScrollContentIntoView(
lastAnchorScrollTo, ScrollAxis(kScrollToTop, WhenToScroll::Always),
ScrollAxis(), ScrollFlags::AnchorScrollFlags);
mLastAnchorScrolledTo = nullptr;
return rv;
return ScrollContentIntoView(lastAnchor,
ScrollAxis(kScrollToTop, WhenToScroll::Always),
ScrollAxis(), ScrollFlags::AnchorScrollFlags);
}
/*