From b7a4fc60e734faeb4dc90a10ffd95c4ad26bf264 Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Wed, 25 Apr 2007 19:33:02 -0700 Subject: [PATCH] Handle restoring scroll position correctly even if InitialReflow comes afterEndLoad. Bug 378606, r+sr=roc --- layout/base/nsPresShell.cpp | 42 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 45a908d04b1..a8ce81631db 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1158,6 +1158,9 @@ protected: // Hide a view if it is a popup void HideViewIfPopup(nsIView* aView); + // Utility method to restore the root scrollframe state + void RestoreRootScrollPosition(); + nsICSSStyleSheet* mPrefStyleSheet; // mStyleSet owns it but we maintain a ref, may be null #ifdef DEBUG PRUint32 mUpdateCount; @@ -2591,6 +2594,12 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) DidCauseReflow(); DidDoReflow(); + // Restore our root scroll position now if we're getting here after EndLoad + // got called, since this is our one chance to do it. + if (!mDocumentLoading) { + RestoreRootScrollPosition(); + } + mViewManager->EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC); if (mViewManager && mCaret && !mViewEventListener) { @@ -3153,22 +3162,11 @@ PresShell::EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType) } void -PresShell::BeginLoad(nsIDocument *aDocument) -{ -#ifdef MOZ_PERF_METRICS - // Reset style resolution stopwatch maintained by style set - MOZ_TIMER_DEBUGLOG(("Reset: Style Resolution: PresShell::BeginLoad(), this=%p\n", (void*)this)); -#endif - mDocumentLoading = PR_TRUE; -} - -void -PresShell::EndLoad(nsIDocument *aDocument) +PresShell::RestoreRootScrollPosition() { - // Restore frame state for the root scroll frame nsCOMPtr historyState = - aDocument->GetLayoutHistoryState(); + mDocument->GetLayoutHistoryState(); // Make sure we don't reenter reflow via the sync paint that happens while // we're scrolling to our restored position. Entering reflow for the // scrollable frame will cause it to reenter ScrollToRestoredPosition(), and @@ -3189,6 +3187,24 @@ PresShell::EndLoad(nsIDocument *aDocument) } --mChangeNestCount; +} + +void +PresShell::BeginLoad(nsIDocument *aDocument) +{ +#ifdef MOZ_PERF_METRICS + // Reset style resolution stopwatch maintained by style set + MOZ_TIMER_DEBUGLOG(("Reset: Style Resolution: PresShell::BeginLoad(), this=%p\n", (void*)this)); +#endif + mDocumentLoading = PR_TRUE; +} + +void +PresShell::EndLoad(nsIDocument *aDocument) +{ + NS_PRECONDITION(aDocument == mDocument, "Wrong document"); + + RestoreRootScrollPosition(); #ifdef MOZ_PERF_METRICS // Dump reflow, style resolution and frame construction times here.