From 59b39390f6f1ea41292a01861f863066aa8d8cac Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Fri, 5 Oct 2001 10:39:01 +0000 Subject: [PATCH] Checkin makes scrolling to anchors faster by attempting to scroll to the named element from the content sink's timer routine rather than waiting until page loading completes. b=58661 r=heikki@netscape.com sr=jst@netscape.com a=asa@mozilla.org git-svn-id: svn://10.0.0.236/trunk@104653 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLContentSink.cpp | 34 +++++++++++++++++-- mozilla/layout/base/nsPresShell.cpp | 5 +-- mozilla/layout/html/base/src/nsPresShell.cpp | 5 +-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index c5261eb92ab..f560c84be24 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -370,7 +370,6 @@ public: nsIWebShell* mWebShell; nsIParser* mParser; - PRBool mNotifyOnTimer; // Do we notify based on time? PRInt32 mBackoffCount; // back off timer notification after count PRInt32 mNotificationInterval; // Notification interval in microseconds PRTime mLastNotificationTime; // Time of last notification @@ -385,8 +384,11 @@ public: nsString* mTitle; nsString mUnicodeXferBuf; + PRPackedBool mNotifyOnTimer; // Do we notify based on time? PRPackedBool mLayoutStarted; PRPackedBool mIsDemotingContainer; + PRPackedBool mScrolledToRefAlready; + PRPackedBool mNeedToBlockParser; PRInt32 mInScript; PRInt32 mInNotification; @@ -398,7 +400,6 @@ public: SinkContext* mHeadContext; PRInt32 mNumOpenIFRAMES; nsSupportsArray mScriptElements; - PRBool mNeedToBlockParser; nsCOMPtr mDummyParserRequest; nsCString mRef; @@ -423,6 +424,7 @@ public: void StartLayout(); void ScrollToRef(); + void TryToScrollToRef(); void AddBaseTagInfo(nsIHTMLContent* aContent); @@ -2357,6 +2359,7 @@ HTMLContentSink::HTMLContentSink() { mNeedToBlockParser = PR_FALSE; mDummyParserRequest = nsnull; mBeginLoadTime = 0; + mScrolledToRefAlready = PR_FALSE; } HTMLContentSink::~HTMLContentSink() @@ -2536,7 +2539,9 @@ HTMLContentSink::Init(nsIDocument* aDoc, mNotifyOnTimer = PR_TRUE; if (prefs) { - prefs->GetBoolPref("content.notify.ontimer", &mNotifyOnTimer); + PRBool result = mNotifyOnTimer; + prefs->GetBoolPref("content.notify.ontimer", &result); + mNotifyOnTimer = result; } mBackoffCount = -1; // never @@ -2677,6 +2682,7 @@ HTMLContentSink::WillBuildModel(void) } mBeginLoadTime = PR_IntervalToMicroseconds(PR_IntervalNow()); } + mScrolledToRefAlready = PR_FALSE; // Notify document that the load is beginning mDocument->BeginLoad(); return NS_OK; @@ -2793,6 +2799,10 @@ HTMLContentSink::Notify(nsITimer *timer) if (mCurrentContext) { mCurrentContext->FlushTags(PR_TRUE); } + + // Now try and scroll to the reference + TryToScrollToRef(); + mNotificationTimer = 0; MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Notify()\n")); MOZ_TIMER_STOP(mWatch); @@ -3996,6 +4006,20 @@ nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocC return rv; } +void +HTMLContentSink::TryToScrollToRef() +{ + if (mRef.IsEmpty()) { + return; + } + + if (mScrolledToRefAlready) { + return; + } + + ScrollToRef(); +} + void HTMLContentSink::ScrollToRef() { @@ -4043,6 +4067,10 @@ HTMLContentSink::ScrollToRef() rv = shell->GoToAnchor(ref); } } + + if (NS_SUCCEEDED(rv)) { + mScrolledToRefAlready = PR_TRUE; + } } } } diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index d5949ed1713..bfd560a63c6 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -3905,8 +3905,9 @@ PresShell::GoToAnchor(const nsString& aAnchorName) nsCOMPtr prefs(do_GetService(kPrefServiceCID,&rv)); if (NS_SUCCEEDED(rv) && prefs) { PRBool selectAnchor; - rv = prefs->GetBoolPref("layout.selectanchor",&selectAnchor); - if (NS_SUCCEEDED(rv) && selectAnchor) { + nsresult rvPref; + rvPref = prefs->GetBoolPref("layout.selectanchor",&selectAnchor); + if (NS_SUCCEEDED(rvPref) && selectAnchor) { rv = SelectContent(content); } } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index d5949ed1713..bfd560a63c6 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -3905,8 +3905,9 @@ PresShell::GoToAnchor(const nsString& aAnchorName) nsCOMPtr prefs(do_GetService(kPrefServiceCID,&rv)); if (NS_SUCCEEDED(rv) && prefs) { PRBool selectAnchor; - rv = prefs->GetBoolPref("layout.selectanchor",&selectAnchor); - if (NS_SUCCEEDED(rv) && selectAnchor) { + nsresult rvPref; + rvPref = prefs->GetBoolPref("layout.selectanchor",&selectAnchor); + if (NS_SUCCEEDED(rvPref) && selectAnchor) { rv = SelectContent(content); } }