diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 0f3705de8857..9ab96442e627 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -116,8 +116,8 @@ class Element; } // namespace mozilla #define NS_IDOCUMENT_IID \ -{ 0xeb847679, 0x3b48, 0x411c, \ - { 0xa9, 0xb8, 0x8a, 0xdc, 0xdb, 0xc6, 0x47, 0xb8 } } +{ 0x625fe492, 0x0344, 0x406c, \ + { 0xaf, 0x7f, 0x55, 0xfe, 0xa2, 0x6b, 0x3d, 0x20 } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -1351,11 +1351,6 @@ public: */ virtual void RegisterFileDataUri(nsACString& aUri) = 0; - virtual void SetScrollToRef(nsIURI *aDocumentURI) = 0; - virtual void ScrollToRef() = 0; - virtual void ResetScrolledToRefAlready() = 0; - virtual void SetChangeScrollPosWhenScrollingToRef(PRBool aValue) = 0; - protected: ~nsIDocument() { diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index fcb985da86b1..4f31eea0c4e9 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -291,8 +291,8 @@ nsContentSink::Init(nsIDocument* aDoc, if (mDocShell) { PRUint32 loadType = 0; mDocShell->GetLoadType(&loadType); - mDocument->SetChangeScrollPosWhenScrollingToRef( - (loadType & nsIDocShell::LOAD_CMD_HISTORY) == 0); + mChangeScrollPosWhenScrollingToRef = + ((loadType & nsIDocShell::LOAD_CMD_HISTORY) == 0); } // use this to avoid a circular reference sink->document->scriptloader->sink @@ -1235,7 +1235,54 @@ nsContentSink::ProcessOfflineManifest(const nsAString& aManifestSpec) void nsContentSink::ScrollToRef() { - mDocument->ScrollToRef(); + if (mRef.IsEmpty()) { + return; + } + + if (mScrolledToRefAlready) { + return; + } + + char* tmpstr = ToNewCString(mRef); + if (!tmpstr) { + return; + } + + nsUnescape(tmpstr); + nsCAutoString unescapedRef; + unescapedRef.Assign(tmpstr); + nsMemory::Free(tmpstr); + + nsresult rv = NS_ERROR_FAILURE; + // We assume that the bytes are in UTF-8, as it says in the spec: + // http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1 + NS_ConvertUTF8toUTF16 ref(unescapedRef); + + nsCOMPtr shell = mDocument->GetPrimaryShell(); + if (shell) { + // Check an empty string which might be caused by the UTF-8 conversion + if (!ref.IsEmpty()) { + // Note that GoToAnchor will handle flushing layout as needed. + rv = shell->GoToAnchor(ref, mChangeScrollPosWhenScrollingToRef); + } else { + rv = NS_ERROR_FAILURE; + } + + // If UTF-8 URI failed then try to assume the string as a + // document's charset. + + if (NS_FAILED(rv)) { + const nsACString &docCharset = mDocument->GetDocumentCharacterSet(); + + rv = nsContentUtils::ConvertStringFromCharset(docCharset, unescapedRef, ref); + + if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) + rv = shell->GoToAnchor(ref, mChangeScrollPosWhenScrollingToRef); + } + if (NS_SUCCEEDED(rv)) { + mScrolledToRefAlready = PR_TRUE; + } + } } void @@ -1285,7 +1332,27 @@ nsContentSink::StartLayout(PRBool aIgnorePendingSheets) // If the document we are loading has a reference or it is a // frameset document, disable the scroll bars on the views. - mDocument->SetScrollToRef(mDocumentURI); + if (mDocumentURI) { + nsCAutoString ref; + + // Since all URI's that pass through here aren't URL's we can't + // rely on the nsIURI implementation for providing a way for + // finding the 'ref' part of the URI, we'll haveto revert to + // string routines for finding the data past '#' + + mDocumentURI->GetSpec(ref); + + nsReadingIterator start, end; + + ref.BeginReading(start); + ref.EndReading(end); + + if (FindCharInReadable('#', start, end)) { + ++start; // Skip over the '#' + + mRef = Substring(start, end); + } + } } void @@ -1672,7 +1739,7 @@ nsContentSink::WillBuildModelImpl() mBeginLoadTime = PR_IntervalToMicroseconds(PR_IntervalNow()); } - mDocument->ResetScrolledToRefAlready(); + mScrolledToRefAlready = PR_FALSE; if (mProcessLinkHeaderEvent.get()) { mProcessLinkHeaderEvent.Revoke(); diff --git a/content/base/src/nsContentSink.h b/content/base/src/nsContentSink.h index 24c9749f78cb..3da5502c6968 100644 --- a/content/base/src/nsContentSink.h +++ b/content/base/src/nsContentSink.h @@ -315,6 +315,8 @@ protected: nsCOMArray mScriptElements; + nsCString mRef; // ScrollTo #ref + // back off timer notification after count PRInt32 mBackoffCount; @@ -328,10 +330,12 @@ protected: // Have we already called BeginUpdate for this set of content changes? PRUint8 mBeganUpdate : 1; PRUint8 mLayoutStarted : 1; + PRUint8 mScrolledToRefAlready : 1; PRUint8 mCanInterruptParser : 1; PRUint8 mDynamicLowerValue : 1; PRUint8 mParsing : 1; PRUint8 mDroppedTimer : 1; + PRUint8 mChangeScrollPosWhenScrollingToRef : 1; // If true, we deferred starting layout until sheets load PRUint8 mDeferredLayoutStart : 1; // If true, we deferred notifications until sheets load diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index d343b0ad63ec..92010ce271b0 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -177,7 +177,6 @@ static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID); #include "nsIPropertyBag2.h" #include "nsIDOMPageTransitionEvent.h" #include "nsFrameLoader.h" -#include "nsEscape.h" #ifdef MOZ_MEDIA #include "nsHTMLMediaElement.h" #endif // MOZ_MEDIA @@ -7678,100 +7677,6 @@ nsDocument::RegisterFileDataUri(nsACString& aUri) mFileDataUris.AppendElement(aUri); } -void -nsDocument::SetScrollToRef(nsIURI *aDocumentURI) -{ - if (!aDocumentURI) { - return; - } - - nsCAutoString ref; - - // Since all URI's that pass through here aren't URL's we can't - // rely on the nsIURI implementation for providing a way for - // finding the 'ref' part of the URI, we'll haveto revert to - // string routines for finding the data past '#' - - aDocumentURI->GetSpec(ref); - - nsReadingIterator start, end; - - ref.BeginReading(start); - ref.EndReading(end); - - if (FindCharInReadable('#', start, end)) { - ++start; // Skip over the '#' - - mScrollToRef = Substring(start, end); - } -} - -void -nsDocument::ScrollToRef() -{ - if (mScrolledToRefAlready) { - return; - } - - if (mScrollToRef.IsEmpty()) { - return; - } - - char* tmpstr = ToNewCString(mScrollToRef); - if (!tmpstr) { - return; - } - - nsUnescape(tmpstr); - nsCAutoString unescapedRef; - unescapedRef.Assign(tmpstr); - nsMemory::Free(tmpstr); - - nsresult rv = NS_ERROR_FAILURE; - // We assume that the bytes are in UTF-8, as it says in the spec: - // http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1 - NS_ConvertUTF8toUTF16 ref(unescapedRef); - - nsCOMPtr shell = GetPrimaryShell(); - if (shell) { - // Check an empty string which might be caused by the UTF-8 conversion - if (!ref.IsEmpty()) { - // Note that GoToAnchor will handle flushing layout as needed. - rv = shell->GoToAnchor(ref, mChangeScrollPosWhenScrollingToRef); - } else { - rv = NS_ERROR_FAILURE; - } - - // If UTF-8 URI failed then try to assume the string as a - // document's charset. - - if (NS_FAILED(rv)) { - const nsACString &docCharset = GetDocumentCharacterSet(); - - rv = nsContentUtils::ConvertStringFromCharset(docCharset, unescapedRef, ref); - - if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) { - rv = shell->GoToAnchor(ref, mChangeScrollPosWhenScrollingToRef); - } - } - if (NS_SUCCEEDED(rv)) { - mScrolledToRefAlready = PR_TRUE; - } - } -} - -void -nsDocument::ResetScrolledToRefAlready() -{ - mScrolledToRefAlready = PR_FALSE; -} - -void -nsDocument::SetChangeScrollPosWhenScrollingToRef(PRBool aValue) -{ - mChangeScrollPosWhenScrollingToRef = aValue; -} - void nsIDocument::RegisterFreezableElement(nsIContent* aContent) { diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 401976eb1980..0baa52eddca0 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -930,11 +930,6 @@ public: // Only BlockOnload should call this! void AsyncBlockOnload(); - virtual void SetScrollToRef(nsIURI *aDocumentURI); - virtual void ScrollToRef(); - virtual void ResetScrolledToRefAlready(); - virtual void SetChangeScrollPosWhenScrollingToRef(PRBool aValue); - protected: friend class nsNodeUtils; void RegisterNamedItems(nsIContent *aContent); @@ -1193,10 +1188,6 @@ private: nsCOMPtr mDOMImplementation; - nsCString mScrollToRef; - PRUint8 mScrolledToRefAlready : 1; - PRUint8 mChangeScrollPosWhenScrollingToRef : 1; - #ifdef DEBUG protected: PRBool mWillReparent; diff --git a/content/test/reftest/bug559996-iframe.html b/content/test/reftest/bug559996-iframe.html deleted file mode 100644 index b576d1d22317..000000000000 --- a/content/test/reftest/bug559996-iframe.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -
first
-
second
- - diff --git a/content/test/reftest/bug559996-ref-iframe.html b/content/test/reftest/bug559996-ref-iframe.html deleted file mode 100644 index 2b13b8b343a1..000000000000 --- a/content/test/reftest/bug559996-ref-iframe.html +++ /dev/null @@ -1,8 +0,0 @@ - - - -
first
-
second
- - - diff --git a/content/test/reftest/bug559996-ref.html b/content/test/reftest/bug559996-ref.html deleted file mode 100644 index 4133bf0c6f24..000000000000 --- a/content/test/reftest/bug559996-ref.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/content/test/reftest/bug559996.html b/content/test/reftest/bug559996.html deleted file mode 100644 index 766bb7bfdbe8..000000000000 --- a/content/test/reftest/bug559996.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/content/test/reftest/reftest.list b/content/test/reftest/reftest.list index ad5d4d839e28..47612cb2438d 100644 --- a/content/test/reftest/reftest.list +++ b/content/test/reftest/reftest.list @@ -3,4 +3,3 @@ == bug456008.xhtml bug456008-ref.html == bug439965.html bug439965-ref.html == bug427779.xml bug427779-ref.xml -== bug559996.html bug559996-ref.html diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 41068686d6a2..90205327b33e 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -804,10 +804,6 @@ DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow) } } - if (aDoInitialReflow && mDocument) { - mDocument->ScrollToRef(); - } - return NS_OK; } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index d18e8941b8ee..bd4bf050d61a 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -3555,9 +3555,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) if (!mDocument) { return NS_ERROR_FAILURE; } - - NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now"); - + // Hold a reference to the ESM in case event dispatch tears us down. nsCOMPtr esm = mPresContext->EventStateManager(); @@ -3814,8 +3812,6 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) nsresult PresShell::ScrollToAnchor() { - NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now"); - if (!mLastAnchorScrolledTo) return NS_OK; @@ -4015,8 +4011,6 @@ PresShell::ScrollContentIntoView(nsIContent* aContent, nsCOMPtr currentDoc = content->GetCurrentDoc(); NS_ENSURE_STATE(currentDoc); - NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now"); - mContentToScrollTo = aContent; mContentScrollVPosition = aVPercent; mContentScrollHPosition = aHPercent; @@ -4043,8 +4037,6 @@ PresShell::DoScrollContentIntoView(nsIContent* aContent, PRIntn aVPercent, PRIntn aHPercent) { - NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now"); - nsIFrame* frame = aContent->GetPrimaryFrame(); if (!frame) { mContentToScrollTo = nsnull;