diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index 1bbe4288f95..eb673e8ce1c 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -130,28 +130,17 @@ nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIW return NS_OK; } -void nsAccessibilityService::GetOwnerFor(nsIPresShell *aPresShell, - nsIPresShell **aOwnerShell, - nsIContent **aOwnerContent) +void nsAccessibilityService::GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent) { - *aOwnerShell = nsnull; - *aOwnerContent = nsnull; - nsCOMPtr presContext; aPresShell->GetPresContext(getter_AddRefs(presContext)); if (!presContext) return; - - nsCOMPtr doc; - aPresShell->GetDocument(getter_AddRefs(doc)); - - if (!doc) - return; - nsCOMPtr pcContainer; presContext->GetContainer(getter_AddRefs(pcContainer)); if (!pcContainer) return; + nsCOMPtr docShellSupports(do_QueryInterface(pcContainer)); nsCOMPtr treeItem(do_QueryInterface(pcContainer)); if (!treeItem) @@ -177,11 +166,17 @@ void nsAccessibilityService::GetOwnerFor(nsIPresShell *aPresShell, if (!parentDoc) return; - parentDoc->FindContentForSubDocument(doc, aOwnerContent); + nsCOMPtr rootContent; + parentDoc->GetRootContent(getter_AddRefs(rootContent)); - if (*aOwnerContent) { + nsCOMPtr tempContent; + parentPresShell->FindContentForShell(docShellSupports, getter_AddRefs(tempContent)); + + if (tempContent) { + *aOwnerContent = tempContent; *aOwnerShell = parentPresShell; NS_ADDREF(*aOwnerShell); + NS_ADDREF(*aOwnerContent); } } @@ -255,46 +250,46 @@ nsAccessibilityService::CreateIFrameAccessible(nsIDOMNode* aDOMNode, nsIAccessib NS_WARNING("No outer pres shell in CreateHTMLIFrameAccessible!"); return NS_ERROR_FAILURE; } - + nsCOMPtr outerPresContext; outerPresShell->GetPresContext(getter_AddRefs(outerPresContext)); if (!outerPresContext) { NS_WARNING("No outer pres context in CreateHTMLIFrameAccessible!"); return NS_ERROR_FAILURE; } - + nsCOMPtr doc; if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc))) && doc) { - nsCOMPtr sub_doc; - doc->GetSubDocumentFor(content, getter_AddRefs(sub_doc)); - - if (sub_doc) { - nsCOMPtr innerPresShell; - sub_doc->GetShellAt(0, getter_AddRefs(innerPresShell)); - - if (innerPresShell) { - nsCOMPtr innerWeakShell = - do_GetWeakReference(innerPresShell); - - nsCOMPtr innerRootAccessible = - new nsHTMLIFrameRootAccessible(aDOMNode, innerWeakShell); - - if (innerRootAccessible) { - nsHTMLIFrameAccessible* outerRootAccessible = - new nsHTMLIFrameAccessible(aDOMNode, innerRootAccessible, - outerWeakShell, sub_doc); - - if (outerRootAccessible) { - *_retval = outerRootAccessible; - NS_ADDREF(*_retval); - - return NS_OK; + if (outerPresShell) { + nsCOMPtr supps; + outerPresShell->GetSubShellFor(content, getter_AddRefs(supps)); + if (supps) { + nsCOMPtr docShell(do_QueryInterface(supps)); + if (docShell) { + nsCOMPtr innerPresShell; + docShell->GetPresShell(getter_AddRefs(innerPresShell)); + if (innerPresShell) { + nsCOMPtr innerWeakShell(do_GetWeakReference(innerPresShell)); + nsCOMPtr innerDoc; + innerPresShell->GetDocument(getter_AddRefs(innerDoc)); + if (innerDoc) { + nsCOMPtr innerRootAccessible(new nsHTMLIFrameRootAccessible(aDOMNode, innerWeakShell)); + if (innerRootAccessible) { + nsHTMLIFrameAccessible* outerRootAccessible = new nsHTMLIFrameAccessible(aDOMNode, innerRootAccessible, outerWeakShell, innerDoc); + if (outerRootAccessible) { + *_retval = NS_STATIC_CAST(nsIAccessible*, outerRootAccessible); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } + } + } + } } } } } } - return NS_ERROR_FAILURE; } diff --git a/content/base/public/MANIFEST b/content/base/public/MANIFEST index 53d8bd75617..805b3c61427 100644 --- a/content/base/public/MANIFEST +++ b/content/base/public/MANIFEST @@ -27,4 +27,3 @@ nsIStyleSheet.h nsIStyleSheetLinkingElement.h nsITextContent.h nsIContentList.h -nsIFrameLoader.h diff --git a/content/base/public/Makefile.in b/content/base/public/Makefile.in index 497ce3c81b1..3179cbb90aa 100644 --- a/content/base/public/Makefile.in +++ b/content/base/public/Makefile.in @@ -56,7 +56,6 @@ nsIPrivateDOMImplementation.h \ nsIContentSerializer.h \ nsIHTMLToTextSink.h \ nsIContentList.h \ -nsIFrameLoader.h \ $(NULL) XPIDLSRCS = \ diff --git a/content/base/public/makefile.win b/content/base/public/makefile.win index f690b86a59f..74d364afd98 100644 --- a/content/base/public/makefile.win +++ b/content/base/public/makefile.win @@ -48,7 +48,6 @@ EXPORTS = \ nsIContentSerializer.h \ nsIHTMLToTextSink.h \ nsIContentList.h \ - nsIFrameLoader.h \ $(NULL) MODULE=content diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 37c50e58724..cfb53010ba8 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -227,32 +227,13 @@ public: /** * Return the parent document of this document. Will return null - * unless this document is within a compound document and has a - * parent. Note that this parent chain may cross chrome boundaries. + * unless this document is within a compound document and has a parent. */ NS_IMETHOD GetParentDocument(nsIDocument** aParent) = 0; - - /** - * Set the parent document of this document. - */ NS_IMETHOD SetParentDocument(nsIDocument* aParent) = 0; - - /** - * Set the sub document for aContent to aSubDoc. - */ - NS_IMETHOD SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc) = 0; - - /** - * Get the sub document for aContent - */ - NS_IMETHOD GetSubDocumentFor(nsIContent *aContent, - nsIDocument** aSubDoc) = 0; - - /** - * Find the content node for which aDocument is a sub document. - */ - NS_IMETHOD FindContentForSubDocument(nsIDocument *aDocument, - nsIContent **aContent) = 0; + NS_IMETHOD AddSubDocument(nsIDocument* aSubDoc) = 0; + NS_IMETHOD GetNumberOfSubDocuments(PRInt32* aCount) = 0; + NS_IMETHOD GetSubDocumentAt(PRInt32 aIndex, nsIDocument** aSubDoc) = 0; /** * Return the root content object for this document. @@ -392,16 +373,6 @@ public: NS_IMETHOD AddReference(void *aKey, nsISupports *aReference) = 0; NS_IMETHOD RemoveReference(void *aKey, nsISupports **aOldReference) = 0; - - /** - * Set the container (docshell) for this document. - */ - NS_IMETHOD SetContainer(nsISupports *aContainer) = 0; - - /** - * Get the container (docshell) for this document. - */ - NS_IMETHOD GetContainer(nsISupports **aContainer) = 0; }; diff --git a/content/base/public/nsIFrameLoader.h b/content/base/public/nsIFrameLoader.h index 5f6e99f3651..1fcfcc4b1d4 100644 --- a/content/base/public/nsIFrameLoader.h +++ b/content/base/public/nsIFrameLoader.h @@ -43,7 +43,7 @@ #include "nsAString.h" // Forward declarations -class nsIContent; +class nsIDOMElement; class nsIDocShell; class nsIURI; @@ -57,42 +57,18 @@ class nsIURI; { 0x0080d493, 0x96b4, 0x4606, \ {0xa7, 0x43, 0x0f, 0x47, 0xee, 0x87, 0x14, 0xd1} } -// CID for the nsIFrameLoader implementation -#define NS_FRAMELOADER_CID \ -{ 0x712603da, 0xf245, 0x4503, \ - {0xa5, 0x41, 0xb0, 0x49, 0xcb, 0x06, 0x81, 0xae} } - -#define NS_FRAMELOADER_CONTRACTID "@mozilla.org/content/frameloader" class nsIFrameLoader : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFRAMELOADER_IID) - /** - * Initialize the frame loader, hand it the owner content. Note that - * the owner content reference is a weak reference, if the owner - * content is destroyed before the frame loader goes away the owner - * content must call the Destroy() method to clear the owner content - * reference. - */ - NS_IMETHOD Init(nsIContent *aOwner) = 0; + NS_IMETHOD Init(nsIDOMElement *aOwner) = 0; - /** - * Start loading the frame. This method figures out what to load - * from the owner content in the frame loader. - */ - NS_IMETHOD LoadFrame() = 0; + NS_IMETHOD LoadURI(nsIURI *aURI) = 0; - /** - * Get the docshell from the frame loader. - */ NS_IMETHOD GetDocShell(nsIDocShell **aDocShell) = 0; - /** - * Destroy the frame loader and everything inside it. This will - * clear the weak owner content reference. - */ NS_IMETHOD Destroy() = 0; }; @@ -102,9 +78,6 @@ class nsIFrameLoaderOwner : public nsISupports public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFRAMELOADEROWNER_IID) - /** - * Get the frame loader from the frame loader owner. - */ NS_IMETHOD GetFrameLoader(nsIFrameLoader **aFrameLoader) = 0; }; diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index 1571feae676..b2ab0306987 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -55,8 +55,8 @@ REQUIRES = xpcom \ imglib2 \ gfx2 \ uriloader \ - webbrwsr \ - webBrowser_core \ + webbrwsr \ + webBrowser_core \ $(NULL) CPPSRCS = \ @@ -97,11 +97,9 @@ CPPSRCS = \ nsScriptLoader.cpp \ nsStyleLinkElement.cpp \ nsContentAreaDragDrop.cpp \ - nsFrameLoader.cpp \ $(NULL) -# we don't want the shared lib, but we want to force the creation of a -# static lib. +# we don't want the shared lib, but we want to force the creation of a static lib. FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk diff --git a/content/base/src/makefile.win b/content/base/src/makefile.win index 32f25e5a8de..ebda5b315a3 100644 --- a/content/base/src/makefile.win +++ b/content/base/src/makefile.win @@ -43,7 +43,6 @@ REQUIRES = xpcom \ uconv \ chrome \ docshell \ - uriloader \ pref \ xpconnect \ util \ @@ -69,10 +68,10 @@ CPP_OBJS= \ .\$(OBJDIR)\nsCommentNode.obj \ .\$(OBJDIR)\nsGenericDOMDataNode.obj \ .\$(OBJDIR)\nsGenericDOMNodeList.obj \ - .\$(OBJDIR)\nsGenericElement.obj \ - .\$(OBJDIR)\nsContentList.obj \ - .\$(OBJDIR)\nsContentIterator.obj \ - .\$(OBJDIR)\nsContentPolicy.obj \ + .\$(OBJDIR)\nsGenericElement.obj \ + .\$(OBJDIR)\nsContentList.obj \ + .\$(OBJDIR)\nsContentIterator.obj \ + .\$(OBJDIR)\nsContentPolicy.obj \ .\$(OBJDIR)\nsDocument.obj \ .\$(OBJDIR)\nsDocumentEncoder.obj \ .\$(OBJDIR)\nsDocumentFragment.obj \ @@ -80,7 +79,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsDOMAttribute.obj \ .\$(OBJDIR)\nsDOMAttributeMap.obj \ .\$(OBJDIR)\nsDOMDocumentType.obj \ - .\$(OBJDIR)\nsGeneratedIterator.obj \ + .\$(OBJDIR)\nsGeneratedIterator.obj \ .\$(OBJDIR)\nsNameSpaceManager.obj \ .\$(OBJDIR)\nsNodeInfo.obj \ .\$(OBJDIR)\nsNodeInfoManager.obj \ @@ -92,13 +91,12 @@ CPP_OBJS= \ .\$(OBJDIR)\nsTreeWalker.obj \ .\$(OBJDIR)\nsXMLContentSerializer.obj \ .\$(OBJDIR)\nsHTMLContentSerializer.obj \ - .\$(OBJDIR)\nsParserUtils.obj \ - .\$(OBJDIR)\nsPlainTextSerializer.obj \ - .\$(OBJDIR)\nsContentUtils.obj \ - .\$(OBJDIR)\nsScriptLoader.obj \ - .\$(OBJDIR)\nsStyleLinkElement.obj \ - .\$(OBJDIR)\nsContentAreaDragDrop.obj \ - .\$(OBJDIR)\nsFrameLoader.obj \ + .\$(OBJDIR)\nsParserUtils.obj \ + .\$(OBJDIR)\nsPlainTextSerializer.obj \ + .\$(OBJDIR)\nsContentUtils.obj \ + .\$(OBJDIR)\nsScriptLoader.obj \ + .\$(OBJDIR)\nsStyleLinkElement.obj \ + .\$(OBJDIR)\nsContentAreaDragDrop.obj \ $(NULL) LINCS=-I..\..\html\base\src -I..\..\html\style\src \ diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index b5cfc0ed3a8..d3149226a01 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -445,7 +445,7 @@ nsDocumentChildNodes::DropReference() // ================================================================== nsDocument::nsDocument() : mIsGoingAway(PR_FALSE), - mCSSLoader(nsnull), mSubDocuments(nsnull) + mCSSLoader(nsnull) { NS_INIT_REFCNT(); @@ -476,7 +476,6 @@ nsDocument::nsDocument() : mIsGoingAway(PR_FALSE), mObservers.InsertElementAt(observer, 0); } - nsDocument::~nsDocument() { // XXX Inform any remaining observers that we are going away. @@ -502,12 +501,11 @@ nsDocument::~nsDocument() mParentDocument = nsnull; - // Kill the subdocument map, doing this will release its strong - // references, if any. - if (mSubDocuments) { - PL_DHashTableDestroy(mSubDocuments); - - mSubDocuments = nsnull; + // Delete references to sub-documents + indx = mSubDocuments.Count(); + while (--indx >= 0) { + nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(indx); + NS_RELEASE(subdoc); } if (mRootContent) { @@ -673,28 +671,25 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) NS_IF_RELEASE(mPrincipal); mDocumentLoadGroup = nsnull; - // Delete references to sub-documents and kill the subdocument map, - // if any. It holds strong references - if (mSubDocuments) { - PL_DHashTableDestroy(mSubDocuments); - - mSubDocuments = nsnull; + // Delete references to sub-documents + PRInt32 indx = mSubDocuments.Count(); + while (--indx >= 0) { + nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(indx); + NS_RELEASE(subdoc); } mRootContent = nsnull; PRUint32 count, i; mChildren->Count(&count); for (i = 0; i < count; i++) { - nsCOMPtr content = - dont_AddRef(NS_STATIC_CAST(nsIContent *, mChildren->ElementAt(i))); - + nsCOMPtr content(dont_AddRef(NS_STATIC_CAST(nsIContent*,mChildren->ElementAt(i)))); content->SetDocument(nsnull, PR_TRUE, PR_TRUE); - ContentRemoved(nsnull, content, i); + ContentRemoved(nsnull, content, indx); } mChildren->Clear(); // Delete references to style sheets - PRInt32 indx = mStyleSheets.Count(); + indx = mStyleSheets.Count(); while (--indx >= 0) { nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(indx); sheet->SetOwningDocument(nsnull); @@ -728,9 +723,8 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) if (aLoadGroup) { mDocumentLoadGroup = getter_AddRefs(NS_GetWeakReference(aLoadGroup)); - // there was an assertion here that aLoadGroup was not null. This - // is no longer valid nsWebShell::SetDocument does not create a - // load group, and it works just fine. + // there was an assertion here that aLoadGroup was not null. This is no longer valid + // nsWebShell::SetDocument does not create a load group, and it works just fine. } if (NS_OK == rv) @@ -1165,151 +1159,26 @@ nsDocument::SetParentDocument(nsIDocument* aParent) return NS_OK; } -PR_STATIC_CALLBACK(void) -SubDocClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry) -{ - SubDocMapEntry *e = NS_STATIC_CAST(SubDocMapEntry *, entry); - - NS_RELEASE(e->mKey); - NS_IF_RELEASE(e->mSubDocument); -} - -PR_STATIC_CALLBACK(void) -SubDocInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key) -{ - SubDocMapEntry *e = - NS_CONST_CAST(SubDocMapEntry *, - NS_STATIC_CAST(const SubDocMapEntry *, entry)); - - e->mKey = NS_CONST_CAST(nsIContent *, - NS_STATIC_CAST(const nsIContent *, key)); - NS_ADDREF(e->mKey); - - e->mSubDocument = nsnull; -} - NS_IMETHODIMP -nsDocument::SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc) +nsDocument::AddSubDocument(nsIDocument* aSubDoc) { - NS_ENSURE_TRUE(aContent, NS_ERROR_UNEXPECTED); - - if (!aSubDoc) { - // aSubDoc is nsnull, remove the mapping - - if (mSubDocuments) { - SubDocMapEntry *entry = - NS_STATIC_CAST(SubDocMapEntry*, - PL_DHashTableOperate(mSubDocuments, aContent, - PL_DHASH_LOOKUP)); - - if (PL_DHASH_ENTRY_IS_LIVE(entry)) { - entry->mSubDocument->SetParentDocument(nsnull); - - PL_DHashTableRawRemove(mSubDocuments, entry); - } - } - } else { - if (!mSubDocuments) { - // Create a new hashtable - - static PLDHashTableOps hash_table_ops = - { - PL_DHashAllocTable, - PL_DHashFreeTable, - PL_DHashGetKeyStub, - PL_DHashVoidPtrKeyStub, - PL_DHashMatchEntryStub, - PL_DHashMoveEntryStub, - SubDocClearEntry, - PL_DHashFinalizeStub, - SubDocInitEntry - }; - - mSubDocuments = PL_NewDHashTable(&hash_table_ops, nsnull, - sizeof(SubDocMapEntry), 16); - if (!mSubDocuments) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - - // Add a mapping to the hash table - SubDocMapEntry *entry = - NS_STATIC_CAST(SubDocMapEntry*, - PL_DHashTableOperate(mSubDocuments, aContent, - PL_DHASH_ADD)); - - if (!entry) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (entry->mSubDocument) { - entry->mSubDocument->SetParentDocument(nsnull); - - // Release the old sub document - NS_RELEASE(entry->mSubDocument); - } - - entry->mSubDocument = aSubDoc; - NS_ADDREF(entry->mSubDocument); - - aSubDoc->SetParentDocument(this); - } - + NS_ADDREF(aSubDoc); + mSubDocuments.AppendElement(aSubDoc); return NS_OK; } NS_IMETHODIMP -nsDocument::GetSubDocumentFor(nsIContent *aContent, nsIDocument** aSubDoc) +nsDocument::GetNumberOfSubDocuments(PRInt32* aCount) { - *aSubDoc = nsnull; - - if (mSubDocuments) { - SubDocMapEntry *entry = - NS_STATIC_CAST(SubDocMapEntry*, - PL_DHashTableOperate(mSubDocuments, aContent, - PL_DHASH_LOOKUP)); - - if (PL_DHASH_ENTRY_IS_LIVE(entry)) { - *aSubDoc = entry->mSubDocument; - NS_ADDREF(*aSubDoc); - } - } - + *aCount = mSubDocuments.Count(); return NS_OK; } -PR_STATIC_CALLBACK(PLDHashOperator) -FindContentEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr, - PRUint32 number, void *arg) -{ - SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr); - FindContentData *data = NS_STATIC_CAST(FindContentData*, arg); - - if (entry->mSubDocument == data->mSubDocument) { - data->mResult = entry->mKey; - - return PL_DHASH_STOP; - } - - return PL_DHASH_NEXT; -} - NS_IMETHODIMP -nsDocument::FindContentForSubDocument(nsIDocument *aDocument, - nsIContent **aContent) +nsDocument::GetSubDocumentAt(PRInt32 aIndex, nsIDocument** aSubDoc) { - NS_ENSURE_ARG_POINTER(aDocument); - - if (!mSubDocuments) { - *aContent = nsnull; - return NS_OK; - } - - FindContentData data(aDocument); - PL_DHashTableEnumerate(mSubDocuments, FindContentEnumerator, &data); - - *aContent = data.mResult; - NS_IF_ADDREF(*aContent); + *aSubDoc = (nsIDocument*) mSubDocuments.SafeElementAt(aIndex); + NS_IF_ADDREF(*aSubDoc); return NS_OK; } @@ -1871,18 +1740,23 @@ nsDocument::EndLoad() if (docShellAsItem) { docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); - nsCOMPtr parent_doc; + nsCOMPtr doc; - GetDocumentFromDocShellTreeItem(docShellParent, - getter_AddRefs(parent_doc)); + GetDocumentFromDocShellTreeItem(docShellParent, getter_AddRefs(doc)); - if (parent_doc) { - nsCOMPtr target_content; + if (doc) { + nsCOMPtr shell; + doc->GetShellAt(0, getter_AddRefs(shell)); - parent_doc->FindContentForSubDocument(this, - getter_AddRefs(target_content)); + if (shell) { + nsCOMPtr target_content; - target_frame = do_QueryInterface(target_content); + nsCOMPtr docshell_identity(docShell); + shell->FindContentForShell(docshell_identity, + getter_AddRefs(target_content)); + + target_frame = do_QueryInterface(target_content); + } } } } @@ -2271,8 +2145,8 @@ nsDocument::GetDocumentElement(nsIDOMElement** aDocumentElement) nsresult res = NS_OK; - if (mRootContent) { - res = CallQueryInterface(mRootContent, aDocumentElement); + if (nsnull != mRootContent) { + res = mRootContent->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aDocumentElement); NS_ASSERTION(NS_OK == res, "Must be a DOM Element"); } else { *aDocumentElement = nsnull; @@ -3597,25 +3471,6 @@ nsDocument::RemoveReference(void *aKey, nsISupports **aOldReference) return NS_OK; } -NS_IMETHODIMP -nsDocument::SetContainer(nsISupports *aContainer) -{ - mDocumentContainer = dont_AddRef(NS_GetWeakReference(aContainer)); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetContainer(nsISupports **aContainer) -{ - nsCOMPtr container = do_QueryReferent(mDocumentContainer); - - *aContainer = container; - NS_IF_ADDREF(*aContainer); - - return NS_OK; -} - #ifdef IBMBIDI /** * Check if bidi enabled (set depending on the presence of RTL diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 9fb44599c6f..22b2e9d1b42 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -69,8 +69,6 @@ #include "nsScriptLoader.h" #include "nsICSSLoader.h" -#include "pldhash.h" - class nsIEventListenerManager; class nsDOMStyleSheetList; class nsIOutputStream; @@ -214,29 +212,6 @@ protected: void* mScriptObject; }; - -// Helper structs for the content->subdoc map - -class SubDocMapEntry : public PLDHashEntryHdr -{ -public: - // Both of these are strong references - nsIContent *mKey; // must be first, to look like PLDHashEntryStub - nsIDocument *mSubDocument; -}; - -struct FindContentData -{ - FindContentData(nsIDocument *aSubDoc) - : mSubDocument(aSubDoc), mResult(nsnull) - { - } - - nsISupports *mSubDocument; - nsIContent *mResult; -}; - - // Base class for our document implementations. // // Note that this class *implements* nsIDOMXMLDocument, but it's not @@ -392,11 +367,9 @@ public: */ NS_IMETHOD GetParentDocument(nsIDocument** aParent); NS_IMETHOD SetParentDocument(nsIDocument* aParent); - - NS_IMETHOD SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc); - NS_IMETHOD GetSubDocumentFor(nsIContent *aContent, nsIDocument** aSubDoc); - NS_IMETHOD FindContentForSubDocument(nsIDocument *aDocument, - nsIContent **aContent); + NS_IMETHOD AddSubDocument(nsIDocument* aSubDoc); + NS_IMETHOD GetNumberOfSubDocuments(PRInt32* aCount); + NS_IMETHOD GetSubDocumentAt(PRInt32 aIndex, nsIDocument** aSubDoc); /** * Return the root content object for this document. @@ -519,8 +492,6 @@ public: NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager); NS_IMETHOD AddReference(void *aKey, nsISupports *aReference); NS_IMETHOD RemoveReference(void *aKey, nsISupports **aOldReference); - NS_IMETHOD SetContainer(nsISupports *aContainer); - NS_IMETHOD GetContainer(nsISupports **aContainer); // nsIDOMNode NS_DECL_NSIDOMNODE @@ -602,16 +573,13 @@ protected: nsCOMPtr mDocumentBaseURL; nsIPrincipal* mPrincipal; nsWeakPtr mDocumentLoadGroup; - nsWeakPtr mDocumentContainer; - + nsString mCharacterSet; PRInt32 mCharacterSetSource; nsVoidArray mCharSetObservers; nsIDocument* mParentDocument; - - PLDHashTable *mSubDocuments; - + nsVoidArray mSubDocuments; nsVoidArray mPresShells; nsCOMPtr mChildren; // contains owning references nsIContent* mRootContent; // a weak reference to the only element in diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index e00ff6d5cb0..4cbaa876720 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -93,7 +93,6 @@ #include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeOwner.h" #include "nsIDocShell.h" -#include "nsIBaseWindow.h" #include "nsIFrameDebug.h" #include "nsILayoutHistoryState.h" #include "nsLayoutAtoms.h" @@ -146,7 +145,7 @@ static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); // Print Preview #include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants -#include "nsIScrollableView.h" +#include "nsIScrollableView.h" #include "nsIWebBrowserPrint.h" // needed for PrintPreview Navigation constants // Print Progress @@ -170,7 +169,7 @@ static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); #include "nsIWebShell.h" //focus -#include "nsIDOMEventReceiver.h" +#include "nsIDOMEventReceiver.h" #include "nsIDOMFocusListener.h" #include "nsISelectionController.h" @@ -199,7 +198,7 @@ static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); #ifdef DEBUG_PRINTING // XXX NOTE: I am including a header from the layout directory // merely to set up a file pointer for debug logging. This is -// fragile and may break in the future, which means it can be +// fragile and may break in the future, which means it can be // removed if necessary #if defined(XP_PC) #include "../../../layout/html/base/src/nsSimplePageSequence.h" @@ -213,20 +212,20 @@ static const char * gPrintRangeStr[] = {"kRangeAllPages", "kRangeSpecified static PRUint32 gDumpFileNameCnt = 0; static PRUint32 gDumpLOFileNameCnt = 0; -#define PRINT_DEBUG_MSG1(_msg1) fprintf(mPrt->mDebugFD, (_msg1)); -#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mPrt->mDebugFD, (_msg1), (_msg2)); -#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3)); -#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4)); -#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5)); +#define PRINT_DEBUG_MSG1(_msg1) fprintf(mPrt->mDebugFD, (_msg1)); +#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mPrt->mDebugFD, (_msg1), (_msg2)); +#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3)); +#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4)); +#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5)); #define PRINT_DEBUG_FLUSH fflush(mPrt->mDebugFD); #else //-------------- -#define PRT_YESNO(_p) -#define PRINT_DEBUG_MSG1(_msg) -#define PRINT_DEBUG_MSG2(_msg1, _msg2) -#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) -#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) -#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) -#define PRINT_DEBUG_FLUSH +#define PRT_YESNO(_p) +#define PRINT_DEBUG_MSG1(_msg) +#define PRINT_DEBUG_MSG2(_msg1, _msg2) +#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) +#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) +#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) +#define PRINT_DEBUG_FLUSH #endif @@ -252,7 +251,7 @@ public: NS_DECL_ISUPPORTS // nsISelectionListerner interface - NS_DECL_NSISELECTIONLISTENER + NS_DECL_NSISELECTIONLISTENER nsDocViewerSelectionListener() : mDocViewer(NULL) @@ -261,9 +260,9 @@ public: { NS_INIT_REFCNT(); } - + virtual ~nsDocViewerSelectionListener() {} - + nsresult Init(DocumentViewerImpl *aDocViewer); protected: @@ -271,13 +270,13 @@ protected: DocumentViewerImpl* mDocViewer; PRPackedBool mGotSelectionState; PRPackedBool mSelectionWasCollapsed; - + }; /** editor Implementation of the FocusListener interface */ -class nsDocViewerFocusListener : public nsIDOMFocusListener +class nsDocViewerFocusListener : public nsIDOMFocusListener { public: /** default constructor @@ -399,8 +398,8 @@ public: // Listener Helper Methods void OnEndPrinting(); void OnStartPrinting(); - static void DoOnProgressChange(nsVoidArray& aListeners, - PRInt32 aProgess, + static void DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, PRInt32 aMaxProgress, PRBool aDoStartStop = PR_FALSE, PRInt32 aFlag = 0); @@ -417,7 +416,7 @@ public: nsCOMPtr mPrintProgress; nsCOMPtr mPrintProgressParams; PRBool mShowProgressDialog; - + nsCOMPtr mCurrentFocusWin; // cache a pointer to the currently focused window nsVoidArray* mPrintDocList; @@ -473,11 +472,11 @@ class DocumentViewerImpl : public nsIDocumentViewer, friend class nsDocViewerSelectionListener; friend class nsPagePrintTimer; friend class PrintData; - + public: DocumentViewerImpl(); DocumentViewerImpl(nsIPresContext* aPresContext); - + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW // nsISupports interface... @@ -512,24 +511,15 @@ public: nsresult CallChildren(CallChildFunc aFunc, void* aClosure); // Printing Methods - PRBool PrintPage(nsIPresContext* aPresContext, - nsIPrintSettings* aPrintSettings, - PrintObject* aPOect, PRBool& aInRange); + PRBool PrintPage(nsIPresContext* aPresContext,nsIPrintSettings* aPrintSettings,PrintObject* aPOect, PRBool& aInRange); PRBool DonePrintingPages(PrintObject* aPO); - + // helper method - static void GetWebShellTitleAndURL(nsIWebShell* aWebShell, - PRUnichar** aTitle, PRUnichar** aURLStr); + static void GetWebShellTitleAndURL(nsIWebShell * aWebShell, PRUnichar** aTitle, PRUnichar** aURLStr); // This enum tells indicates what the default should be for the title // if the title from the document is null - enum eDocTitleDefault { - eDocTitleDefNone, - eDocTitleDefBlank, - eDocTitleDefDocument, - eDocTitleDefURLDoc - }; - + enum eDocTitleDefault {eDocTitleDefNone, eDocTitleDefBlank, eDocTitleDefDocument, eDocTitleDefURLDoc}; static void GetDisplayTitleAndURL(PrintObject* aPO, nsIPrintSettings* aPrintSettings, const PRUnichar* aBrandName, @@ -549,15 +539,12 @@ private: nsIDeviceContext* aDeviceContext, const nsRect& aBounds, PRBool aDoCreation); - nsresult InitPresentationStuff(PRBool aDoInitialReflow); - - nsresult GetDocumentSelection(nsISelection **aSelection, - nsIPresShell * aPresShell = nsnull); + nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); PRBool IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin); PRBool IsParentAFrameSet(nsIWebShell * aParent); PRBool IsWebShellAFrameSet(nsIWebShell * aParent); - + PRBool IsThereAnIFrameSelected(nsIWebShell* aWebShell, nsIDOMWindowInternal * aDOMWin, PRPackedBool& aDoesContainFrameset); @@ -569,12 +556,11 @@ private: nsresult GetPopupImageNode(nsIDOMNode** aNode); //--------------------------------------------------------------------- - void BuildDocTree(nsIDocShellTreeNode * aParentNode, - nsVoidArray * aDocList, + void BuildDocTree(nsIDocShellTreeNode * aParentNode, + nsVoidArray * aDocList, PrintObject * aPO); - nsresult ReflowDocList(PrintObject * aPO, PRBool aSetPixelScale, - PRBool aDoCalcShrink); - void SetClipRect(PrintObject* aPO, + nsresult ReflowDocList(PrintObject * aPO, PRBool aSetPixelScale, PRBool aDoCalcShrink); + void SetClipRect(PrintObject* aPO, const nsRect& aClipRect, nscoord aOffsetX, nscoord aOffsetY, @@ -589,18 +575,14 @@ private: nsIContent* aContent); void MapContentToWebShells(PrintObject* aRootPO, PrintObject* aPO); nsresult MapSubDocFrameLocations(PrintObject* aPO); - PrintObject* FindPrintObjectByDOMWin(PrintObject* aParentObject, - nsIDOMWindowInternal * aDOMWin); - void GetPresShellAndRootContent(nsIWebShell * aWebShell, - nsIPresShell** aPresShell, - nsIContent** aContent); + PrintObject* FindPrintObjectByDOMWin(PrintObject* aParentObject, nsIDOMWindowInternal * aDOMWin); + void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent); void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages); void DoProgressForAsIsFrames(); void DoProgressForSeparateFrames(); void DoPrintProgress(PRBool aIsForPrinting); - void SetDocAndURLIntoProgress(PrintObject* aPO, - nsIPrintProgressParams* aParams); + void SetDocAndURLIntoProgress(PrintObject* aPO, nsIPrintProgressParams* aParams); nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions, nsIPrintSettings* aPrintSettings, PRUint32 aErrorCode, @@ -618,8 +600,7 @@ private: // nsresult DocumentReadyForPrinting(); //nsresult PrintSelection(nsIDeviceContextSpec * aDevSpec); - nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, - nsIDocument ** aNewDoc); + nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc); static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent); static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent); @@ -629,17 +610,12 @@ private: nsIDOMWindowInternal* aCurrentFocusedDOMWin); nsresult EnablePOsForPrinting(); PrintObject* FindXMostPO(); - void FindXMostFrameSize(nsIPresContext* aPresContext, - nsIRenderingContext* aRC, nsIFrame* aFrame, - nscoord aX, nscoord aY, PRInt32& aMaxWidth); - void FindXMostFrameInList(nsIPresContext* aPresContext, - nsIRenderingContext* aRC, nsIAtom* aList, - nsIFrame* aFrame, nscoord aX, nscoord aY, - PRInt32& aMaxWidth); + void FindXMostFrameSize(nsIPresContext* aPresContext, nsIRenderingContext* aRC, nsIFrame* aFrame, nscoord aX, nscoord aY, PRInt32& aMaxWidth); + void FindXMostFrameInList(nsIPresContext* aPresContext, nsIRenderingContext* aRC, nsIAtom* aList, nsIFrame* aFrame, + nscoord aX, nscoord aY, PRInt32& aMaxWidth); PRBool PrintDocContent(PrintObject* aPO, nsresult& aStatus); - nsresult DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, - PRBool& aDonePrinting); + nsresult DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDonePrinting); void SetPrintAsIs(PrintObject* aPO, PRBool aAsIs = PR_TRUE); void SetPrintPO(PrintObject* aPO, PRBool aPrint); @@ -654,18 +630,15 @@ private: // Timer Methods - nsresult StartPagePrintTimer(nsIPresContext * aPresContext, + nsresult StartPagePrintTimer(nsIPresContext * aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPO, PRUint32 aDelay); void PrepareToStartLoad(void); - - nsresult SyncParentSubDocMap(); - + // Misc - static void ShowPrintErrorDialog(nsresult printerror, - PRBool aIsPrinting = PR_TRUE); + static void ShowPrintErrorDialog(nsresult printerror, PRBool aIsPrinting = PR_TRUE); protected: // IMPORTANT: The ownership implicit in the following member @@ -673,7 +646,7 @@ protected: // for owning pointers and raw COM interface pointers for weak // (ie, non owning) references. If you add any members to this // class, please make the ownership explicit (pinkerton, scc). - + nsISupports* mContainer; // [WEAK] it owns me! nsCOMPtr mDeviceContext; // ??? can't hurt, but... nsIView* mView; // [WEAK] cleaned up by view mgr @@ -691,7 +664,7 @@ protected: nsCOMPtr mSelectionListener; nsCOMPtr mFocusListener; - + nsCOMPtr mPreviousViewer; PRBool mEnableRendering; @@ -766,7 +739,7 @@ public: NS_WARNING("unable to start the timer"); } else { mTimer->Init(this, aUseDelay?mDelay:0, NS_PRIORITY_NORMAL, NS_TYPE_ONE_SHOT); - } + } return result; } @@ -787,7 +760,7 @@ public: if (mDocViewer->DonePrintingPages(mPrintObj)) { initNewTimer = PR_FALSE; } - } + } Stop(); if (initNewTimer) { @@ -800,15 +773,15 @@ public: } } - void Init(DocumentViewerImpl* aDocViewerImpl, + void Init(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPO, - PRUint32 aDelay) + PRUint32 aDelay) { NS_IF_RELEASE(mDocViewer); mDocViewer = aDocViewerImpl; - NS_ADDREF(mDocViewer); + NS_ADDREF(mDocViewer); mPresContext = aPresContext; mPrintSettings = aPrintSettings; @@ -816,11 +789,11 @@ public: mDelay = aDelay; } - nsresult Start(DocumentViewerImpl* aDocViewerImpl, + nsresult Start(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPO, - PRUint32 aDelay) + PRUint32 aDelay) { Init(aDocViewerImpl, aPresContext, aPrintSettings, aPO, aDelay); return StartTimer(PR_FALSE); @@ -870,7 +843,7 @@ static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult) PrintData::PrintData() : mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull), mShowProgressDialog(PR_TRUE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE), - mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE), + mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE), mIsAborted(PR_FALSE), mPreparingForPrint(PR_FALSE), mDocWasToBeDestroyed(PR_FALSE), mShrinkToFit(PR_FALSE), mPrintFrameType(nsIPrintSettings::kFramesAsIs), mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPrinted(0), @@ -896,7 +869,7 @@ PrintData::PrintData() : } -PrintData::~PrintData() +PrintData::~PrintData() { // removed any cached if (mCachedPresObj) { @@ -925,7 +898,7 @@ PrintData::~PrintData() if (!isCancelled && !mIsAborted) { rv = mPrintDC->EndDocument(); } else { - rv = mPrintDC->AbortDocument(); + rv = mPrintDC->AbortDocument(); } if (NS_FAILED(rv)) { DocumentViewerImpl::ShowPrintErrorDialog(rv); @@ -974,8 +947,8 @@ void PrintData::OnEndPrinting() } void -PrintData::DoOnProgressChange(nsVoidArray& aListeners, - PRInt32 aProgess, +PrintData::DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, PRInt32 aMaxProgress, PRBool aDoStartStop, PRInt32 aFlag) @@ -985,7 +958,7 @@ PrintData::DoOnProgressChange(nsVoidArray& aListeners, for (PRInt32 i=0;iOnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress); + wpl->OnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress); if (aDoStartStop) { wpl->OnStateChange(nsnull, nsnull, aFlag, 0); } @@ -996,10 +969,10 @@ PrintData::DoOnProgressChange(nsVoidArray& aListeners, //--------------------------------------------------- //-- PrintObject Class Impl //--------------------------------------------------- -PrintObject::PrintObject() : +PrintObject::PrintObject() : mFrameType(eFrame), mRootView(nsnull), mContent(nsnull), - mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1), + mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1), mRect(0,0,0,0), mReflowRect(0,0,0,0), mParent(nsnull), mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE), mSkippedPageEject(PR_FALSE), mSharedPresShell(PR_FALSE), @@ -1019,7 +992,7 @@ PrintObject::~PrintObject() PrintObject* po = (PrintObject*)mKids[i]; NS_ASSERTION(po, "PrintObject can't be null!"); delete po; - } + } if (mPresShell && !mSharedPresShell) { mPresShell->Destroy(); @@ -1058,14 +1031,16 @@ PRBool DocumentViewerImpl::mIsDoingPrinting = PR_FALSE; nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult) { - *aResult = new DocumentViewerImpl(); - if (!*aResult) { + NS_PRECONDITION(aResult, "null OUT ptr"); + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + DocumentViewerImpl* it = new DocumentViewerImpl(); + if (nsnull == it) { + *aResult = nsnull; return NS_ERROR_OUT_OF_MEMORY; } - - NS_ADDREF(*aResult); - - return NS_OK; + return CallQueryInterface(it, aResult); } // Note: operator new zeros our memory @@ -1079,8 +1054,7 @@ DocumentViewerImpl::DocumentViewerImpl() #endif } -void DocumentViewerImpl::PrepareToStartLoad() -{ +void DocumentViewerImpl::PrepareToStartLoad() { mEnableRendering = PR_TRUE; mStopped = PR_FALSE; mLoaded = PR_FALSE; @@ -1118,14 +1092,12 @@ NS_IMPL_ISUPPORTS6(DocumentViewerImpl, DocumentViewerImpl::~DocumentViewerImpl() { NS_ASSERTION(!mDocument, "User did not call nsIContentViewer::Close"); - if (mDocument) { + if (mDocument) Close(); - } NS_ASSERTION(!mPresShell, "User did not call nsIContentViewer::Destroy"); - if (mPresShell) { + if (mPresShell) Destroy(); - } // XXX(?) Revoke pending invalidate events @@ -1153,10 +1125,10 @@ DocumentViewerImpl::LoadStart(nsISupports *aDoc) nsresult rv; if (!mDocument) { - mDocument = do_QueryInterface(aDoc, &rv); + mDocument = do_QueryInterface(aDoc,&rv); } else if (mDocument == aDoc) { - // Reset the document viewer's state back to what it was + // Reset the document viewer's state back to what it was // when the document load started. PrepareToStartLoad(); } @@ -1164,42 +1136,6 @@ DocumentViewerImpl::LoadStart(nsISupports *aDoc) return rv; } -nsresult -DocumentViewerImpl::SyncParentSubDocMap() -{ - nsCOMPtr item(do_QueryInterface(mContainer)); - nsCOMPtr win(do_GetInterface(item)); - nsCOMPtr pwin(do_QueryInterface(win)); - nsCOMPtr content; - - if (mDocument && pwin) { - nsCOMPtr frame_element; - pwin->GetFrameElementInternal(getter_AddRefs(frame_element)); - - content = do_QueryInterface(frame_element); - } - - if (content) { - nsCOMPtr parent; - item->GetParent(getter_AddRefs(parent)); - - nsCOMPtr parent_win(do_GetInterface(parent)); - - if (parent_win) { - nsCOMPtr dom_doc; - parent_win->GetDocument(getter_AddRefs(dom_doc)); - - nsCOMPtr parent_doc(do_QueryInterface(dom_doc)); - - if (parent_doc) { - return parent_doc->SetSubDocumentFor(content, mDocument); - } - } - } - - return NS_OK; -} - NS_IMETHODIMP DocumentViewerImpl::SetContainer(nsISupports* aContainer) { @@ -1207,12 +1143,7 @@ DocumentViewerImpl::SetContainer(nsISupports* aContainer) if (mPresContext) { mPresContext->SetContainer(aContainer); } - - // We're loading a new document into the window where this document - // viewer lives, sync the parent document's frame element -> sub - // document map - - return SyncParentSubDocMap(); + return NS_OK; } NS_IMETHODIMP @@ -1234,99 +1165,6 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, return InitInternal(aParentWidget, aDeviceContext, aBounds, PR_TRUE); } -nsresult -DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow) -{ - // Create the style set... - nsCOMPtr styleSet; - nsresult rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); - NS_ENSURE_SUCCESS(rv, rv); - - // Now make the shell for the document - rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet, - getter_AddRefs(mPresShell)); - NS_ENSURE_SUCCESS(rv, rv); - - mPresShell->BeginObservingDocument(); - - // Initialize our view manager - nsRect bounds; - mWindow->GetBounds(bounds); - - float p2t; - - mPresContext->GetPixelsToTwips(&p2t); - - nscoord width = NSIntPixelsToTwips(bounds.width, p2t); - nscoord height = NSIntPixelsToTwips(bounds.height, p2t); - - mViewManager->DisableRefresh(); - mViewManager->SetWindowDimensions(width, height); - - // Setup default view manager background color - - // This may be overridden by the docshell with the background color - // for the last document loaded into the docshell - nscolor bgcolor = NS_RGB(0, 0, 0); - mPresContext->GetDefaultBackgroundColor(&bgcolor); - mViewManager->SetDefaultBackgroundColor(bgcolor); - - if (aDoInitialReflow) { - // Initial refllow - mPresShell->InitialReflow(width, height); - - // Now trigger a refresh - if (mEnableRendering) { - mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - } - } - - // now register ourselves as a selection listener, so that we get - // called when the selection changes in the window - nsDocViewerSelectionListener *selectionListener = - new nsDocViewerSelectionListener(); - NS_ENSURE_TRUE(selectionListener, NS_ERROR_OUT_OF_MEMORY); - - selectionListener->Init(this); - - // mSelectionListener is a owning reference - mSelectionListener = selectionListener; - - nsCOMPtr selection; - rv = GetDocumentSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr selPrivate(do_QueryInterface(selection)); - rv = selPrivate->AddSelectionListener(mSelectionListener); - if (NS_FAILED(rv)) - return rv; - - // focus listener - // - // now register ourselves as a focus listener, so that we get called - // when the focus changes in the window - nsDocViewerFocusListener *focusListener; - NS_NEWXPCOM(focusListener, nsDocViewerFocusListener); - NS_ENSURE_TRUE(focusListener, NS_ERROR_OUT_OF_MEMORY); - - focusListener->Init(this); - - // mFocusListener is a strong reference - mFocusListener = focusListener; - - // get the DOM event receiver - nsCOMPtr erP(do_QueryInterface(mDocument)); - NS_WARN_IF_FALSE(erP, "No event receiver in document!"); - - if (erP) { - rv = erP->AddEventListenerByIID(mFocusListener, - NS_GET_IID(nsIDOMFocusListener)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); - } - - return NS_OK; -} - //----------------------------------------------- // This method can be used to initial the "presentation" // The aDoCreation indicates whether it should create @@ -1337,6 +1175,8 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, const nsRect& aBounds, PRBool aDoCreation) { + NS_ASSERTION(aParentWidget != nsnull, "Null aParentWidget"); + #ifdef NS_PRINT_PREVIEW mParentWidget = aParentWidget; // not ref counted #endif @@ -1355,18 +1195,16 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, PRBool makeCX = PR_FALSE; if (aDoCreation) { - if (aParentWidget && !mPresContext) { + if (!mPresContext) { // Create presentation context if (mIsCreatingPrintPreview) { - mPresContext = do_CreateInstance(kPrintPreviewContextCID, &rv); + mPresContext = do_CreateInstance(kPrintPreviewContextCID,&rv); } else { - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); + mPresContext = do_CreateInstance(kGalleyContextCID,&rv); } - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) return rv; mPresContext->Init(aDeviceContext); - #ifdef NS_PRINT_PREVIEW makeCX = !mIsDoingPrintPreview; // needs to be true except when we are already in PP #else @@ -1375,52 +1213,142 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, } } - if (aDoCreation && mPresContext) { - // Create the ViewManager and Root View... - - // We must do this before we tell the script global object about - // this new document since doing that will cause us to re-enter - // into nsHTMLFrameInnerFrame code through reflows caused by - // FlushPendingNotifications() calls down the road... - - rv = MakeWindow(aParentWidget, aBounds); - NS_ENSURE_SUCCESS(rv, rv); - Hide(); - } - nsCOMPtr requestor(do_QueryInterface(mContainer)); if (requestor) { - if (mPresContext) { - nsCOMPtr linkHandler; - requestor->GetInterface(NS_GET_IID(nsILinkHandler), - getter_AddRefs(linkHandler)); - mPresContext->SetContainer(mContainer); - mPresContext->SetLinkHandler(linkHandler); - } + nsCOMPtr linkHandler; + requestor->GetInterface(NS_GET_IID(nsILinkHandler), + getter_AddRefs(linkHandler)); + mPresContext->SetContainer(mContainer); + mPresContext->SetLinkHandler(linkHandler); if (!mIsDoingPrintPreview) { // Set script-context-owner in the document + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), + getter_AddRefs(owner)); - nsCOMPtr global; - requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObject), - getter_AddRefs(global)); + if (owner) { + nsCOMPtr global; + owner->GetScriptGlobalObject(getter_AddRefs(global)); - if (global) { - mDocument->SetScriptGlobalObject(global); - nsCOMPtr domdoc(do_QueryInterface(mDocument)); + if (global) { + mDocument->SetScriptGlobalObject(global); + nsCOMPtr domdoc(do_QueryInterface(mDocument)); - if (domdoc) { - global->SetNewDocument(domdoc, PR_TRUE); + if (domdoc) { + global->SetNewDocument(domdoc, PR_TRUE); + } } } } } - if (aDoCreation && mPresContext) { - // The ViewManager and Root View was created above (in - // MakeWindow())... + if (aDoCreation) { + // Create the ViewManager and Root View... + rv = MakeWindow(aParentWidget, aBounds); + Hide(); - rv = InitPresentationStuff(!makeCX); + if (NS_FAILED(rv)) return rv; + + // Create the style set... + nsIStyleSet* styleSet; + rv = CreateStyleSet(mDocument, &styleSet); + if (NS_FAILED(rv)) return rv; + + // Now make the shell for the document + rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet, + getter_AddRefs(mPresShell)); + NS_RELEASE(styleSet); + if (NS_FAILED(rv)) return rv; + + mPresShell->BeginObservingDocument(); + + // Initialize our view manager + nsRect bounds; + mWindow->GetBounds(bounds); + nscoord width = bounds.width; + nscoord height = bounds.height; + float p2t; + mPresContext->GetPixelsToTwips(&p2t); + width = NSIntPixelsToTwips(width, p2t); + height = NSIntPixelsToTwips(height, p2t); + mViewManager->DisableRefresh(); + mViewManager->SetWindowDimensions(width, height); + + /* Setup default view manager background color */ + /* This may be overridden by the docshell with the background color for the + last document loaded into the docshell */ + nscolor bgcolor = NS_RGB(0, 0, 0); + mPresContext->GetDefaultBackgroundColor(&bgcolor); + mViewManager->SetDefaultBackgroundColor(bgcolor); + + if (!makeCX) { + // Make shell an observer for next time + // XXX - we observe the docuement always, see above after preshell is created + // mPresShell->BeginObservingDocument(); + + //XXX I don't think this should be done *here*; and why paint nothing + //(which turns out to cause black flashes!)??? + // Resize-reflow this time + mPresShell->InitialReflow(width, height); + + // Now trigger a refresh + if (mEnableRendering) { + mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); + } + } + } else { + mPresShell->BeginObservingDocument(); + } + // now register ourselves as a selection listener, so that we get called + // when the selection changes in the window + nsDocViewerSelectionListener *selectionListener; + NS_NEWXPCOM(selectionListener, nsDocViewerSelectionListener); + if (!selectionListener) return NS_ERROR_OUT_OF_MEMORY; + selectionListener->Init(this); + + // this is the owning reference. The nsCOMPtr will take care of releasing + // our ref to the listener on destruction. + NS_ADDREF(selectionListener); + mSelectionListener = do_QueryInterface(selectionListener); + NS_RELEASE(selectionListener); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr selection; + rv = GetDocumentSelection(getter_AddRefs(selection)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr selPrivate(do_QueryInterface(selection)); + rv = selPrivate->AddSelectionListener(mSelectionListener); + if (NS_FAILED(rv)) return rv; + + //focus listener + // now register ourselves as a focus listener, so that we get called + // when the focus changes in the window + nsDocViewerFocusListener *focusListener; + NS_NEWXPCOM(focusListener, nsDocViewerFocusListener); + if (!focusListener) return NS_ERROR_OUT_OF_MEMORY; + focusListener->Init(this); + + // this is the owning reference. The nsCOMPtr will take care of releasing + // our ref to the listener on destruction. + NS_ADDREF(focusListener); + mFocusListener = do_QueryInterface(focusListener); + NS_RELEASE(focusListener); + if (NS_FAILED(rv)) + return rv; + + if(mDocument) + { + // get the DOM event receiver + nsCOMPtr erP (do_QueryInterface(mDocument, &rv)); + if(NS_FAILED(rv)) + return rv; + if(!erP) + return NS_ERROR_FAILURE; + + rv = erP->AddEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); } return rv; @@ -1446,14 +1374,14 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) rv = mDocument->GetScriptGlobalObject(getter_AddRefs(global)); // Fail if no ScriptGlobalObject is available... - NS_ENSURE_TRUE(global, NS_ERROR_NULL_POINTER); + NS_ASSERTION(global, "nsIScriptGlobalObject not set for document!"); + if (!global) return NS_ERROR_NULL_POINTER; mLoaded = PR_TRUE; - /* We need to protect ourself against auto-destruction in case the - window is closed while processing the OnLoad event. See bug - http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more - explanation. + /* We need to protect ourself against auto-destruction in case the window is closed + while processing the OnLoad event. + See bug http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more explanation. */ NS_ADDREF_THIS(); @@ -1469,14 +1397,11 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) #ifdef MOZ_TIMELINE // if navigator.xul's load is complete, the main nav window is visible // mark that point. - if (mDocument) { //printf("DEBUG: getting uri from document (%p)\n", mDocument.get()); - nsCOMPtr uri; mDocument->GetDocumentURL(getter_AddRefs(uri)); - - if (uri) { + if (uri.get() != nsnull) { //printf("DEBUG: getting spec fro uri (%p)\n", uri.get()); nsCAutoString spec; uri->GetSpec(spec); @@ -1489,12 +1414,11 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) } else { // XXX: Should fire error event to the document... } - + // Now that the document has loaded, we can tell the presshell // to unsuppress painting. - if (mPresShell && !mStopped) { + if (mPresShell && !mStopped) mPresShell->UnsuppressPainting(); - } NS_RELEASE_THIS(); @@ -1546,9 +1470,11 @@ DocumentViewerImpl::Close() // for an object that can be switched in and out so that we don't need // to disable scripts during paint suppression. + nsresult rv; + if (mDocument) { #ifdef NS_PRINT_PREVIEW - // Turn scripting back on + // Turn scripting back on // after PrintPreview had turned it off if (mPrtPreview) { TurnScriptingOn(PR_TRUE); @@ -1559,28 +1485,20 @@ DocumentViewerImpl::Close() // in the DocViewer Init nsCOMPtr globalObject; mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { globalObject->SetNewDocument(nsnull, PR_TRUE); } - // out of band cleanup of webshell mDocument->SetScriptGlobalObject(nsnull); - if (mFocusListener) { // get the DOM event receiver - nsCOMPtr erP(do_QueryInterface(mDocument)); - NS_WARN_IF_FALSE(erP, "No event receiver in document!"); - - if (erP) { - erP->RemoveEventListenerByIID(mFocusListener, - NS_GET_IID(nsIDOMFocusListener)); - } + nsCOMPtr erP( do_QueryInterface(mDocument, &rv) ); + if(NS_SUCCEEDED(rv) && erP) + erP->RemoveEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); } - } + } mDocument = nsnull; - return NS_OK; } @@ -1640,19 +1558,15 @@ DocumentViewerImpl::Destroy() if (mPresShell) { // Break circular reference (or something) mPresShell->EndObservingDocument(); - nsCOMPtr selection; - GetDocumentSelection(getter_AddRefs(selection)); - + nsresult rv = GetDocumentSelection(getter_AddRefs(selection)); nsCOMPtr selPrivate(do_QueryInterface(selection)); - - if (selPrivate && mSelectionListener) + if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) selPrivate->RemoveSelectionListener(mSelectionListener); - mPresShell->Destroy(); mPresShell = nsnull; } - + return NS_OK; } @@ -1687,17 +1601,15 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) // Assumptions: // // 1) this document viewer has been initialized with a call to Init(). - // 2) the stylesheets associated with the document have been added - // to the document. + // 2) the stylesheets associated with the document have been added to the document. - // XXX Right now, this method assumes that the layout of the current - // document hasn't started yet. More cleanup will probably be - // necessary to make this method work for the case when layout *has* - // occurred for the current document. + // XXX Right now, this method assumes that the layout of the current document + // hasn't started yet. More cleanup will probably be necessary to make this + // method work for the case when layout *has* occurred for the current document. // That work can happen when and if it is needed. - + nsresult rv; - if (!aDocument) + if (nsnull == aDocument) return NS_ERROR_NULL_POINTER; nsCOMPtr newDoc = do_QueryInterface(aDocument, &rv); @@ -1707,50 +1619,46 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) mDocument = newDoc; // 1) Set the script global object on the new document - nsCOMPtr global(do_GetInterface(mContainer)); - - if (global) { - mDocument->SetScriptGlobalObject(global); - global->SetNewDocument(aDocument, PR_TRUE); - - rv = SyncParentSubDocMap(); - NS_ENSURE_SUCCESS(rv, rv); - } - - // 2) Replace the current pres shell with a new shell for the new document - - if (mPresShell) { - mPresShell->EndObservingDocument(); - mPresShell->Destroy(); - - mPresShell = nsnull; - } - - // And if we're already given a prescontext... - if (mPresContext) { - // 3) Create a new style set for the document - - nsCOMPtr styleSet; - rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); - if (NS_FAILED(rv)) - return rv; - - rv = newDoc->CreateShell(mPresContext, mViewManager, styleSet, - getter_AddRefs(mPresShell)); - if (NS_FAILED(rv)) return rv; - - mPresShell->BeginObservingDocument(); - - // 4) Register the focus listener on the new document - - nsCOMPtr erP = do_QueryInterface(mDocument, &rv); - NS_WARN_IF_FALSE(erP, "No event receiver in document!"); - - if (erP) { - rv = erP->AddEventListenerByIID(mFocusListener, - NS_GET_IID(nsIDOMFocusListener)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); + nsCOMPtr requestor(do_QueryInterface(mContainer)); + if (requestor) { + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), + getter_AddRefs(owner)); + if (nsnull != owner) { + nsCOMPtr global; + rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); + if (NS_SUCCEEDED(rv) && (nsnull != global)) { + mDocument->SetScriptGlobalObject(global); + global->SetNewDocument(aDocument, PR_TRUE); + } } + } + + // 2) Create a new style set for the document + nsCOMPtr styleSet; + rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); + if (NS_FAILED(rv)) return rv; + + // 3) Replace the current pres shell with a new shell for the new document + mPresShell->EndObservingDocument(); + mPresShell->Destroy(); + + mPresShell = nsnull; + rv = newDoc->CreateShell(mPresContext, mViewManager, styleSet, + getter_AddRefs(mPresShell)); + if (NS_FAILED(rv)) return rv; + + mPresShell->BeginObservingDocument(); + + // 4) Register the focus listener on the new document + if(mDocument) + { + nsCOMPtr erP = do_QueryInterface(mDocument, &rv); + if(NS_FAILED(rv) || !erP) + return rv ? rv : NS_ERROR_FAILURE; + + rv = erP->AddEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); } return rv; @@ -1767,7 +1675,7 @@ DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) } return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::GetDocument(nsIDocument*& aResult) { @@ -1775,7 +1683,7 @@ DocumentViewerImpl::GetDocument(nsIDocument*& aResult) NS_IF_ADDREF(aResult); return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::GetPresShell(nsIPresShell*& aResult) { @@ -1783,7 +1691,7 @@ DocumentViewerImpl::GetPresShell(nsIPresShell*& aResult) NS_IF_ADDREF(aResult); return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::GetPresContext(nsIPresContext*& aResult) { @@ -1825,7 +1733,7 @@ DocumentViewerImpl::SetPreviousViewer(nsIContentViewer* aViewer) "can't set previous viewer when there already is one"); // In a multiple chaining situation (which occurs when running a thrashing - // test like i-bench or jrgm's tests with no delay), we can build up a + // test like i-bench or jrgm's tests with no delay), we can build up a // whole chain of viewers. In order to avoid this, we always set our previous // viewer to the MOST previous viewer in the chain, and then dump the intermediate // link from the chain. This ensures that at most only 2 documents are alive @@ -1848,7 +1756,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetBounds(const nsRect& aBounds) { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); - + NS_PRECONDITION(mWindow, "null window"); if (mWindow) { // Don't have the widget repaint. Layout will generate repaint requests // during reflow @@ -1873,6 +1781,7 @@ NS_IMETHODIMP DocumentViewerImpl::Show(void) { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); + NS_PRECONDITION(mWindow, "null window"); // We don't need the previous viewer anymore since we're not // displaying it. @@ -1887,114 +1796,6 @@ DocumentViewerImpl::Show(void) if (mWindow) { mWindow->Show(PR_TRUE); } - - if (mDocument && !mPresShell && !mWindow && !mDeviceContext) { - nsresult rv; - - nsCOMPtr base_win(do_QueryInterface(mContainer)); - NS_ENSURE_TRUE(base_win, NS_ERROR_UNEXPECTED); - - base_win->GetParentWidget(&mParentWidget); - NS_ENSURE_TRUE(mParentWidget, NS_ERROR_UNEXPECTED); - - if (!mDeviceContext) { - mDeviceContext = dont_AddRef(mParentWidget->GetDeviceContext()); - } - -#ifdef NS_PRINT_PREVIEW - // Clear PrintPreview Alternate Device - if (mDeviceContext) { - mDeviceContext->SetAltDevice(nsnull); - } -#endif - - PRBool makeCX = PR_FALSE; - - // Create presentation context - if (mIsCreatingPrintPreview) { - NS_ERROR("Whoa, we should not get here!"); - - return NS_ERROR_UNEXPECTED; - } - - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - mPresContext->Init(mDeviceContext); - - nsRect tbounds; - mParentWidget->GetBounds(tbounds); - - float p2t; - mPresContext->GetPixelsToTwips(&p2t); - tbounds *= p2t; - - // Create the view manager - mViewManager = do_CreateInstance(kViewManagerCID); - NS_ENSURE_TRUE(mViewManager, NS_ERROR_NOT_AVAILABLE); - - // Initialize the view manager with an offset. This allows the - // viewmanager to manage a coordinate space offset from (0,0) - rv = mViewManager->Init(mDeviceContext); - if (NS_FAILED(rv)) - return rv; - - rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y); - if (NS_FAILED(rv)) - return rv; - - // Reset the bounds offset so the root view is set to 0,0. The - // offset is specified in nsIViewManager::Init above. - // Besides, layout will reset the root view to (0,0) during reflow, - // so changing it to 0,0 eliminates placing the root view in the - // wrong place initially. - tbounds.x = 0; - tbounds.y = 0; - - // Create a child window of the parent that is our "root - // view/window" Create a view - rv = CallCreateInstance(kViewCID, &mView); - if (NS_FAILED(rv)) - return rv; - rv = mView->Init(mViewManager, tbounds, nsnull); - if (NS_FAILED(rv)) - return rv; - - rv = mView->CreateWidget(kWidgetCID, nsnull, - mParentWidget->GetNativeData(NS_NATIVE_WIDGET), - PR_TRUE, PR_FALSE); - - if (NS_FAILED(rv)) - return rv; - - // Setup hierarchical relationship in view manager - mViewManager->SetRootView(mView); - - mView->GetWidget(*getter_AddRefs(mWindow)); - - if (mPresContext && mContainer) { - nsCOMPtr linkHandler(do_GetInterface(mContainer)); - - if (linkHandler) { - mPresContext->SetLinkHandler(linkHandler); - } - - mPresContext->SetContainer(mContainer); - } - - if (mPresContext) { - Hide(); - - rv = InitPresentationStuff(PR_TRUE); - } - - // If we get here the document load has already started and the - // window is shown because some JS on the page caused it to be - // shown... - - mPresShell->UnsuppressPainting(); - } - return NS_OK; } @@ -2006,48 +1807,6 @@ DocumentViewerImpl::Hide(void) if (mWindow) { mWindow->Show(PR_FALSE); } - - if (!mPresShell) { - return NS_OK; - } - - // Avoid leaking the old viewer. - if (mPreviousViewer) { - mPreviousViewer->Destroy(); - mPreviousViewer = nsnull; - } - - if (mDeviceContext) - mDeviceContext->FlushFontCache(); - - // Break circular reference (or something) - mPresShell->EndObservingDocument(); - nsCOMPtr selection; - - GetDocumentSelection(getter_AddRefs(selection)); - - nsCOMPtr selPrivate(do_QueryInterface(selection)); - - if (selPrivate && mSelectionListener) - selPrivate->RemoveSelectionListener(mSelectionListener); - - mPresShell->Destroy(); - - mPresShell = nsnull; - mPresContext = nsnull; - mViewManager = nsnull; - mView = nsnull; - mWindow = nsnull; - mDeviceContext = nsnull; - mView = nsnull; - mParentWidget = nsnull; - - nsCOMPtr base_win(do_QueryInterface(mContainer)); - - if (base_win) { - base_win->SetParentWidget(nsnull); - } - return NS_OK; } @@ -2073,7 +1832,7 @@ DocumentViewerImpl::FindFrameSetWithIID(nsIContent * aParentContent, const nsIID } /** --------------------------------------------------- - * Helper function + * Helper function */ static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell) @@ -2100,10 +1859,10 @@ GetPresShellFor(nsIDocShell* aDocShell) #include "process.h" #include "direct.h" -#define MY_FINDFIRST(a,b) FindFirstFile(a,b) -#define MY_FINDNEXT(a,b) FindNextFile(a,b) -#define ISDIR(a) (a.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) -#define MY_FINDCLOSE(a) FindClose(a) +#define MY_FINDFIRST(a,b) FindFirstFile(a,b) +#define MY_FINDNEXT(a,b) FindNextFile(a,b) +#define ISDIR(a) (a.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) +#define MY_FINDCLOSE(a) FindClose(a) #define MY_FILENAME(a) a.cFileName #define MY_FILESIZE(a) (a.nFileSizeHigh * MAXDWORD) + a.nFileSizeLow @@ -2178,10 +1937,10 @@ static void RootFrameList(nsIPresContext* aPresContext, FILE* out, PRInt32 aInde /** --------------------------------------------------- * Dumps Frames for Printing */ -static void DumpFrames(FILE* out, - nsIPresContext* aPresContext, - nsIRenderingContext * aRendContext, - nsIFrame * aFrame, +static void DumpFrames(FILE* out, + nsIPresContext* aPresContext, + nsIRenderingContext * aRendContext, + nsIFrame * aFrame, PRInt32 aLevel) { NS_ASSERTION(out, "Pointer is null!"); @@ -2349,16 +2108,16 @@ static void DumpPrintObjectsList(nsVoidArray * aDocList, FILE* aFD = nsnull) } } - fprintf(fd, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], + fprintf(fd, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mWebShell, po->mSeqFrame, - po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); + po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); if (fd != nsnull && fd != stdout) { - fprintf(stdout, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], + fprintf(stdout, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mWebShell, po->mSeqFrame, - po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); + po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); } - } -} + } +} static void DumpPrintObjectsTree(PrintObject * aPO, int aLevel= 0, FILE* aFD = nsnull) { NS_ASSERTION(aPO, "Pointer is null!"); @@ -2375,12 +2134,11 @@ static void DumpPrintObjectsTree(PrintObject * aPO, int aLevel= 0, FILE* aFD = n NS_ASSERTION(po, "PrintObject can't be null!"); for (PRInt32 k=0;kmFrameType], po, po->mWebShell, po->mSeqFrame, - po->mPageFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); - } + po->mPageFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); + } } - -static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, - char *& aURLStr) + +static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, char *& aURLStr) { aDocStr = nsnull; aURLStr = nsnull; @@ -2388,9 +2146,7 @@ static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, PRUnichar * mozillaDoc = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document")); PRUnichar * docTitleStr; PRUnichar * docURLStr; - DocumentViewerImpl::GetDisplayTitleAndURL(aPO, nsnull, mozillaDoc, - &docTitleStr, &docURLStr, - DocumentViewerImpl::eDocTitleDefURLDoc); + DocumentViewerImpl::GetDisplayTitleAndURL(aPO, nsnull, mozillaDoc, &docTitleStr, &docURLStr, DocumentViewerImpl::eDocTitleDefURLDoc); if (docTitleStr) { nsAutoString strDocTitle(docTitleStr); @@ -2409,7 +2165,7 @@ static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, } } -static void DumpPrintObjectsTreeLayout(PrintObject * aPO, +static void DumpPrintObjectsTreeLayout(PrintObject * aPO, nsIDeviceContext * aDC, int aLevel= 0, FILE * aFD = nsnull) { @@ -2433,7 +2189,7 @@ static void DumpPrintObjectsTreeLayout(PrintObject * aPO, } for (PRInt32 k=0;kmFrameType], aPO, aPO->mWebShell, aPO->mSeqFrame, - aPO->mPageFrame, aPO->mPageNum, aPO->mRect.x, aPO->mRect.y, aPO->mRect.width, aPO->mRect.height); + aPO->mPageFrame, aPO->mPageNum, aPO->mRect.x, aPO->mRect.y, aPO->mRect.width, aPO->mRect.height); if (aPO->IsPrintable()) { char * docStr; char * urlStr; @@ -2454,7 +2210,7 @@ static void DumpPrintObjectsTreeLayout(PrintObject * aPO, if (aLevel == 0 && fd) { fclose(fd); } -} +} static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList, FILE* aFD = nsnull) { @@ -2472,7 +2228,7 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList, FILE* #else #define DUMP_DOC_LIST(_title) #define DUMP_DOC_TREE -#define DUMP_DOC_TREELAYOUT +#define DUMP_DOC_TREELAYOUT #endif //--------------------------------------------------------------- @@ -2482,7 +2238,7 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList, FILE* //--------------------------------------------------------------- /** --------------------------------------------------- - * Giving a child frame it searches "up" the tree until it + * Giving a child frame it searches "up" the tree until it * finds a "Page" frame. */ static nsIFrame * GetPageFrame(nsIFrame * aFrame) @@ -2507,7 +2263,7 @@ static nsIFrame * FindFrameByType(nsIPresContext* aPresContext, nsIFrame * aParentFrame, nsIAtom * aType, nsRect& aRect, - nsRect& aChildRect) + nsRect& aChildRect) { NS_ASSERTION(aPresContext, "Pointer is null!"); NS_ASSERTION(aParentFrame, "Pointer is null!"); @@ -2634,7 +2390,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, seqFrame->GetRect(rect); // start out with the sequence frame and search the entire frame tree - // capturing the the starting and ending child frames of the selection + // capturing the the starting and ending child frames of the selection // and their rects FindSelectionBounds(aPresContext, aRC, seqFrame, rect, startFrame, aStartRect, endFrame, aEndRect); @@ -2643,7 +2399,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, printf("End Frame: %p\n", endFrame); #endif - // initial the page numbers here + // initial the page numbers here // in case we don't find and frames aStartPageNum = -1; aEndPageNum = -1; @@ -2659,7 +2415,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, // Check to see if start should be same as end if // the end frame comes back null if (endFrame == nsnull) { - // XXX the "GetPageFrame" step could be integrated into + // XXX the "GetPageFrame" step could be integrated into // the FindSelectionBounds step, but walking up to find // the parent of a child frame isn't expensive and it makes // FindSelectionBounds a little easier to understand @@ -2699,7 +2455,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, while (page != nsnull) { if (page == startPageFrame) { aStartPageNum = pageNum; - } + } if (page == endPageFrame) { aEndPageNum = pageNum; } @@ -2719,7 +2475,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, } //------------------------------------------------------- -PRBool +PRBool DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) { NS_ASSERTION(aParent, "Pointer is null!"); @@ -2728,8 +2484,8 @@ DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) nsCOMPtr parentAsItem(do_QueryInterface(aParent)); if (!parentAsItem) return PR_FALSE; - // When it is the top level document we need to check - // to see if it contains a frameset. If it does, then + // When it is the top level document we need to check + // to see if it contains a frameset. If it does, then // we only want to print the doc's children and not the document itself // For anything else we always print all the children and the document // for example, if the doc contains an IFRAME we eant to print the child @@ -2738,10 +2494,10 @@ DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) // XXX we really need to search the frame tree, and not the content // but there is no way to distinguish between IFRAMEs and FRAMEs // with the GetFrameType call. - // Bug 53459 has been files so we can eventually distinguish + // Bug 53459 has been files so we can eventually distinguish // between IFRAME frames and FRAME frames PRBool isFrameSet = PR_FALSE; - // only check to see if there is a frameset if there is + // only check to see if there is a frameset if there is // NO parent doc for this doc. meaning this parent is the root doc nsCOMPtr shell; mPresContext->GetShell(getter_AddRefs(shell)); @@ -2762,7 +2518,7 @@ DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) } //------------------------------------------------------- -PRBool +PRBool DocumentViewerImpl::IsWebShellAFrameSet(nsIWebShell * aWebShell) { NS_ASSERTION(aWebShell, "Pointer is null!"); @@ -2781,8 +2537,8 @@ DocumentViewerImpl::IsWebShellAFrameSet(nsIWebShell * aWebShell) //------------------------------------------------------- void -DocumentViewerImpl::GetWebShellTitleAndURL(nsIWebShell * aWebShell, - PRUnichar** aTitle, +DocumentViewerImpl::GetWebShellTitleAndURL(nsIWebShell * aWebShell, + PRUnichar** aTitle, PRUnichar** aURLStr) { NS_ASSERTION(aWebShell, "Pointer is null!"); @@ -2878,7 +2634,7 @@ DocumentViewerImpl::GetDisplayTitleAndURL(PrintObject* aPO, case eDocTitleDefDocument: if (aBrandName) *aTitle = nsCRT::strdup(aBrandName); break; - case eDocTitleDefURLDoc: + case eDocTitleDefURLDoc: if (*aURLStr) { *aTitle = nsCRT::strdup(*aURLStr); } else { @@ -3014,12 +2770,12 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { DoProgressForSeparateFrames(); - } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || + } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) { PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, curPage, endPage); } - // Set Clip when Printing "AsIs" or + // Set Clip when Printing "AsIs" or // when printing an IFrame for SelectedFrame or EachFrame PRBool setClip = PR_FALSE; switch (mPrt->mPrintFrameType) { @@ -3044,7 +2800,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, } break; - } //switch + } //switch if (setClip) { // Always set the clip x,y to zero because it isn't going to have any margins @@ -3058,7 +2814,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // fail and the failure is passed back here. // Returning PR_TRUE means we are done printing. // - // When rv == NS_ERROR_ABORT, it means we want out of the + // When rv == NS_ERROR_ABORT, it means we want out of the // print job without displaying any error messages nsresult rv = mPageSeqFrame->PrintNextPage(aPresContext); if (NS_FAILED(rv)) { @@ -3067,7 +2823,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, mPrt->mIsAborted = PR_TRUE; } return PR_TRUE; - } + } // Now see if any of the SubDocs are on this page if (aPO->mPrintAsIs) { @@ -3133,9 +2889,9 @@ PrintObject * DocumentViewerImpl::FindPrintObjectByWS(PrintObject* aPO, nsIWebSh //------------------------------------------------------- // Recursively build a list of of sub documents to be printed // that mirrors the document tree -void -DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, - nsVoidArray * aDocList, +void +DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, + nsVoidArray * aDocList, PrintObject * aPO) { NS_ASSERTION(aParentNode, "Pointer is null!"); @@ -3143,7 +2899,7 @@ DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, NS_ASSERTION(aPO, "Pointer is null!"); // Get the Doc and Title String - GetWebShellTitleAndURL(aPO->mWebShell, &aPO->mDocTitle, &aPO->mDocURL); + GetWebShellTitleAndURL(aPO->mWebShell, &aPO->mDocTitle, &aPO->mDocURL); PRInt32 childWebshellCount; aParentNode->GetChildCount(&childWebshellCount); @@ -3152,14 +2908,6 @@ DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, nsCOMPtr child; aParentNode->GetChildAt(i, getter_AddRefs(child)); nsCOMPtr childAsShell(do_QueryInterface(child)); - - nsCOMPtr presShell; - childAsShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - continue; - } - nsCOMPtr viewer; childAsShell->GetContentViewer(getter_AddRefs(viewer)); if (viewer) { @@ -3190,7 +2938,7 @@ DocumentViewerImpl::SetPrintAsIs(PrintObject* aPO, PRBool aAsIs) aPO->mPrintAsIs = aAsIs; for (PRInt32 i=0;imKids.Count();i++) { SetPrintAsIs((PrintObject*)aPO->mKids[i], aAsIs); - } + } } //------------------------------------------------------- @@ -3204,7 +2952,7 @@ DocumentViewerImpl::SetPrintPO(PrintObject* aPO, PRBool aPrint) aPO->mDontPrint = !aPrint; for (PRInt32 i=0;imKids.Count();i++) { SetPrintPO((PrintObject*)aPO->mKids[i], aPrint); - } + } } //------------------------------------------------------- @@ -3214,7 +2962,7 @@ DocumentViewerImpl::SetPrintPO(PrintObject* aPO, PRBool aPrint) // NOTE: This MUST be done after the sub-doc has been laid out // This is called by "MapSubDocFrameLocations" // -nsresult +nsresult DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell, PrintObject* aPO) { @@ -3225,7 +2973,7 @@ DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell, // Find that frame for the sub-doc's content element // in the parent document - // if it comes back null it probably has the style + // if it comes back null it probably has the style // set to "display:none" nsIFrame * frame; aPresShell->GetPrimaryFrameFor(aPO->mContent, &frame); @@ -3255,9 +3003,9 @@ DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell, rect.y += rr.y; nsIFrame * temp = parent; temp->GetParent(&parent); - // Keep a pointer to the Seq and Page frames + // Keep a pointer to the Seq and Page frames nsIPageSequenceFrame * sqf = nsnull; - if (parent != nsnull && + if (parent != nsnull && NS_SUCCEEDED(CallQueryInterface(parent, &sqf)) && sqf) { pageFrame = temp; seqFrame = parent; @@ -3321,17 +3069,17 @@ DocumentViewerImpl::MapSubDocFrameLocations(PrintObject* aPO) // // This "maps" or figures out which sub-doc represents a // given Frame or IFrame in it's parent sub-doc. -// +// // So the Mcontent pointer in the child sub-doc points to the // content in the it's parent document, that caused it to be printed. // This is used later to (after reflow) to find the absolute location -// of the sub-doc on it's parent's page frame so it can be +// of the sub-doc on it's parent's page frame so it can be // printed in the correct location. // // This method recursvely "walks" the content for a document finding // all the Frames and IFrames, then sets the "mFrameType" data member // which tells us what type of PO we have -void +void DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, nsIPresShell* aPresShell, nsIContent* aContent) @@ -3340,38 +3088,19 @@ DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, NS_ASSERTION(aPresShell, "Pointer is null!"); NS_ASSERTION(aContent, "Pointer is null!"); - nsCOMPtr doc; - aContent->GetDocument(*getter_AddRefs(doc)); - - if (!doc) { - NS_ERROR("No document!"); - - return; - } - - nsCOMPtr subDoc; - doc->GetSubDocumentFor(aContent, getter_AddRefs(subDoc)); - - if (subDoc) { - nsCOMPtr container; - subDoc->GetContainer(getter_AddRefs(container)); - - nsCOMPtr presShell; - subDoc->GetShellAt(0, getter_AddRefs(presShell)); - - nsCOMPtr webShell(do_QueryInterface(container)); - - if (presShell && webShell) { + nsCOMPtr supps; + aPresShell->GetSubShellFor(aContent, getter_AddRefs(supps)); + if (supps) { + nsCOMPtr webShell(do_QueryInterface(supps)); + if (webShell) { PrintObject * po = FindPrintObjectByWS(aRootObject, webShell); NS_ASSERTION(po, "PO can't be null!"); - if (po) { + if (po != nsnull) { po->mContent = aContent; - // Now, "type" the PO - nsCOMPtr frameSet = - do_QueryInterface(aContent); - + // Now, "type" the PO + nsCOMPtr frameSet(do_QueryInterface(aContent)); if (frameSet) { po->mFrameType = eFrameSet; } else { @@ -3379,11 +3108,8 @@ DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, if (frame) { po->mFrameType = eFrame; } else { - nsCOMPtr objElement = - do_QueryInterface(aContent); - nsCOMPtr iFrame = - do_QueryInterface(aContent); - + nsCOMPtr objElement(do_QueryInterface(aContent)); + nsCOMPtr iFrame(do_QueryInterface(aContent)); if (iFrame || objElement) { po->mFrameType = eIFrame; po->mPrintAsIs = PR_TRUE; @@ -3409,11 +3135,11 @@ DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, //------------------------------------------------------- // The walks the PO tree and for each document it walks the content -// tree looking for any content that are sub-shells +// tree looking for any content that are sub-shells // -// It then sets the mContent pointer in the "found" PO object back to the +// It then sets the mContent pointer in the "found" PO object back to the // the document that contained it. -void +void DocumentViewerImpl::MapContentToWebShells(PrintObject* aRootPO, PrintObject* aPO) { @@ -3431,16 +3157,16 @@ DocumentViewerImpl::MapContentToWebShells(PrintObject* aRootPO, // Continue recursively walking the chilren of this PO for (PRInt32 i=0;imKids.Count();i++) { MapContentToWebShells(aRootPO, (PrintObject*)aPO->mKids[i]); - } + } } //------------------------------------------------------- // This gets ref counted copies of the PresShell and Root Content // for a given nsIWebShell -void -DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell, - nsIPresShell** aPresShell, +void +DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell, + nsIPresShell** aPresShell, nsIContent** aContent) { NS_ASSERTION(aWebShell, "Pointer is null!"); @@ -3466,8 +3192,8 @@ DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell, //------------------------------------------------------- // Recursively sets the clip rect on all thchildren -void -DocumentViewerImpl::SetClipRect(PrintObject* aPO, +void +DocumentViewerImpl::SetClipRect(PrintObject* aPO, const nsRect& aClipRect, nscoord aOffsetX, nscoord aOffsetY, @@ -3481,8 +3207,8 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, nscoord height = (aPO->mRect.y+aPO->mRect.height) > aClipRect.height?aClipRect.height-aPO->mRect.y:aPO->mRect.height; aPO->mClipRect.SetRect(aPO->mRect.x, aPO->mRect.y, width, height); - } - + } + PRBool doClip = aDoingSetClip; if (aPO->mFrameType == eFrame) { @@ -3523,7 +3249,7 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, PRInt32 cnt = aPO->mKids.Count(); for (PRInt32 i=0;imKids[i], clipRect, + SetClipRect((PrintObject *)aPO->mKids[i], clipRect, aOffsetX+aPO->mRect.x, aOffsetY+aPO->mRect.y, doClip); } } @@ -3531,12 +3257,12 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, //------------------------------------------------------- // Recursively reflow each sub-doc and then calc // all the frame locations of the sub-docs -nsresult +nsresult DocumentViewerImpl::ReflowDocList(PrintObject* aPO, PRBool aSetPixelScale, PRBool aDoCalcShrink) { NS_ASSERTION(aPO, "Pointer is null!"); - // Here is where we set the shrinkage value into the DC + // Here is where we set the shrinkage value into the DC // and this is what actually makes it shrink if (aSetPixelScale && aPO->mFrameType != eIFrame) { float ratio; @@ -3548,7 +3274,7 @@ DocumentViewerImpl::ReflowDocList(PrintObject* aPO, PRBool aSetPixelScale, PRBoo mPrt->mPrintDC->SetCanonicalPixelScale(ratio*mPrt->mOrigDCScale); } - // Reflow the PO + // Reflow the PO if (NS_FAILED(ReflowPrintObject(aPO, aDoCalcShrink))) { return NS_ERROR_FAILURE; } @@ -3628,8 +3354,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) return rv; } - rv = document->CreateShell(aPO->mPresContext, aPO->mViewManager, - aPO->mStyleSet, getter_AddRefs(aPO->mPresShell)); + rv = document->CreateShell(aPO->mPresContext, aPO->mViewManager, aPO->mStyleSet, getter_AddRefs(aPO->mPresShell)); if (NS_FAILED(rv)) { return rv; } @@ -3639,7 +3364,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) PRInt32 width, height; if (aPO->mContent == nsnull || !aPO->mPrintAsIs || - (aPO->mPrintAsIs && aPO->mParent && !aPO->mParent->mPrintAsIs) || + (aPO->mPrintAsIs && aPO->mParent != nsnull && !aPO->mParent->mPrintAsIs) || (aPO->mFrameType == eIFrame && aPO == mPrt->mSelectedPO)) { width = pageWidth; height = pageHeight; @@ -3650,25 +3375,22 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) PRINT_DEBUG_MSG5("In DV::ReflowPrintObject PO: %p (%9s) Setting w,h to %d,%d\n", aPO, gFrameTypesStr[aPO->mFrameType], width, height); - nsCOMPtr domWinIntl = - do_QueryInterface(mPrt->mPrintDocDW); + nsCOMPtr domWinIntl(do_QueryInterface(mPrt->mPrintDocDW)); // XXX - Hack Alert - // OK, so ther eis a selection, we will print the entire selection + // OK, so ther eis a selection, we will print the entire selection // on one page and then crop the page. - // This means you can never print any selection that is longer than - // one page put it keeps it from page breaking in the middle of your - // print of the selection (see also nsSimplePageSequence.cpp) + // This means you can never print any selection that is longer than one page + // put it keeps it from page breaking in the middle of your print of the selection + // (see also nsSimplePageSequence.cpp) PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; if (mPrt->mPrintSettings != nsnull) { mPrt->mPrintSettings->GetPrintRange(&printRangeType); } - if (printRangeType == nsIPrintSettings::kRangeSelection && - IsThereARangeSelection(domWinIntl)) { + if (printRangeType == nsIPrintSettings::kRangeSelection && IsThereARangeSelection(domWinIntl)) { height = NS_UNCONSTRAINEDSIZE; } - nsRect tbounds = nsRect(0, 0, width, height); // Create a child window of the parent that is our "root view/window" @@ -3682,7 +3404,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) } #ifdef NS_PRINT_PREVIEW - // Here we decide whether we need scrollbars and + // Here we decide whether we need scrollbars and // what the parent will be of the widget if (mIsCreatingPrintPreview) { PRBool canCreateScrollbars = PR_FALSE; @@ -3694,17 +3416,16 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) NS_ASSERTION(frameMan, "No Frame manager!"); nsIFrame* frame; frameMan->GetPrimaryFrameFor(aPO->mContent, &frame); - if (frame && (aPO->mFrameType == eIFrame || aPO->mFrameType == eFrame)) { + if (frame != nsnull && (aPO->mFrameType == eIFrame || aPO->mFrameType == eFrame)) { frame->FirstChild(aPO->mParent->mPresContext, nsnull, &frame); } - - if (frame) { + if (frame != nsnull) { nsIView* view = nsnull; frame->GetView(aPO->mParent->mPresContext, &view); - if (view) { + if (view != nsnull) { nsCOMPtr w2; view->GetWidget(*getter_AddRefs(w2)); - if (w2) { + if (nsnull != w2) { widget = w2; } canCreateScrollbars = PR_FALSE; @@ -3755,9 +3476,9 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) // initialize it with the default/generic case nsRect adjRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height); - // XXX This is an arbitray height, + // XXX This is an arbitray height, // but reflow somethimes gets upset when using max int - // basically, we want to reflow a single page that is large + // basically, we want to reflow a single page that is large // enough to fit any atomic object like an IFrame const PRInt32 kFivePagesHigh = 5; @@ -3849,7 +3570,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) nsRect rect; child->GetRect(rect); - // Create a RenderingContext and set the PresContext + // Create a RenderingContext and set the PresContext // appropriately if we are printing selection nsCOMPtr rc; if (nsIPrintSettings::kRangeSelection == printRangeType) { @@ -3932,7 +3653,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) //------------------------------------------------------- // Given a DOMWindow it recursively finds the PO object that matches -PrintObject* +PrintObject* DocumentViewerImpl::FindPrintObjectByDOMWin(PrintObject* aPO, nsIDOMWindowInternal * aDOMWin) { NS_ASSERTION(aPO, "Pointer is null!"); @@ -3966,11 +3687,12 @@ DocumentViewerImpl::GetDOMWinForWebShell(nsIWebShell* aWebShell) NS_ASSERTION(aWebShell, "Pointer is null!"); nsCOMPtr domWin = do_GetInterface(aWebShell); + if (!domWin) return nsnull; nsCOMPtr domWinInt(do_QueryInterface(domWin)); if (!domWinInt) return nsnull; - nsIDOMWindowInternal * dw = domWinInt.get(); + nsIDOMWindowInternal * dw = NS_STATIC_CAST(nsIDOMWindowInternal *, domWinInt.get()); NS_ADDREF(dw); return dw; @@ -3988,10 +3710,10 @@ DocumentViewerImpl::EnablePOsForPrinting() return NS_ERROR_FAILURE; } - mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; + mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); - PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; @@ -4009,13 +3731,13 @@ DocumentViewerImpl::EnablePOsForPrinting() // then set the mPrintFrameType as if it were the selected frame if (printRangeType == nsIPrintSettings::kRangeSelection) { mPrt->mPrintFrameType = nsIPrintSettings::kSelectedFrame; - printHowEnable = nsIPrintSettings::kFrameEnableNone; + printHowEnable = nsIPrintSettings::kFrameEnableNone; } // This tells us that the "Frame" UI has turned off, // so therefore there are no FrameSets/Frames/IFrames to be printed // - // This means there are not FrameSets, + // This means there are not FrameSets, // but the document could contain an IFrame if (printHowEnable == nsIPrintSettings::kFrameEnableNone) { @@ -4041,7 +3763,7 @@ DocumentViewerImpl::EnablePOsForPrinting() PRINT_DEBUG_MSG2("PrintRange: %s \n", gPrintRangeStr[printRangeType]); return NS_OK; } - + // This means we are either printed a selected IFrame or // we are printing the current selection if (printRangeType == nsIPrintSettings::kRangeSelection) { @@ -4058,12 +3780,12 @@ DocumentViewerImpl::EnablePOsForPrinting() // Now, only enable this POs (the selected PO) and all of its children SetPrintPO(po, PR_TRUE); - // check to see if we have a range selection, + // check to see if we have a range selection, // as oppose to a insert selection - // this means if the user just clicked on the IFrame then + // this means if the user just clicked on the IFrame then // there will not be a selection so we want the entire page to print // - // XXX this is sort of a hack right here to make the page + // XXX this is sort of a hack right here to make the page // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { @@ -4105,12 +3827,12 @@ DocumentViewerImpl::EnablePOsForPrinting() // Now, only enable this POs (the selected PO) and all of its children SetPrintPO(po, PR_TRUE); - // check to see if we have a range selection, + // check to see if we have a range selection, // as oppose to a insert selection - // this means if the user just clicked on the IFrame then + // this means if the user just clicked on the IFrame then // there will not be a selection so we want the entire page to print // - // XXX this is sort of a hack right here to make the page + // XXX this is sort of a hack right here to make the page // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { @@ -4141,9 +3863,9 @@ DocumentViewerImpl::EnablePOsForPrinting() PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCurrentFocusWin); if (po != nsnull) { mPrt->mSelectedPO = po; - // NOTE: Calling this sets the "po" and + // NOTE: Calling this sets the "po" and // we don't want to do this for documents that have no children, - // because then the "DoEndPage" gets called and it shouldn't + // because then the "DoEndPage" gets called and it shouldn't if (po->mKids.Count() > 0) { // Makes sure that itself, and all of its children are printed "AsIs" SetPrintAsIs(po); @@ -4154,10 +3876,10 @@ DocumentViewerImpl::EnablePOsForPrinting() } } return NS_OK; - } - - // If we are print each subdoc separately, - // then don't print any of the FraneSet Docs + } + + // If we are print each subdoc separately, + // then don't print any of the FraneSet Docs if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { SetPrintPO(mPrt->mPrintObject, PR_TRUE); PRInt32 cnt = mPrt->mPrintDocList->Count(); @@ -4175,11 +3897,11 @@ DocumentViewerImpl::EnablePOsForPrinting() //--------------------------------------------------- // Find the Frame in a Frame List that is XMost -void -DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, +void +DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, nsIRenderingContext* aRC, nsIAtom* aList, - nsIFrame* aFrame, + nsIFrame* aFrame, nscoord aX, nscoord aY, PRInt32& aMaxWidth) @@ -4188,7 +3910,7 @@ DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, aFrame->FirstChild(aPresContext, aList, &child); while (child) { PRBool isVisible = PR_TRUE; - // If the aRC is nsnull, then we skip the more expensive check and + // If the aRC is nsnull, then we skip the more expensive check and // just check visibility if (aRC) { child->IsVisibleForPainting(aPresContext, *aRC, PR_TRUE, &isVisible); @@ -4241,10 +3963,10 @@ DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, //--------------------------------------------------- // Find the Frame that is XMost -void -DocumentViewerImpl::FindXMostFrameSize(nsIPresContext* aPresContext, +void +DocumentViewerImpl::FindXMostFrameSize(nsIPresContext* aPresContext, nsIRenderingContext* aRC, - nsIFrame* aFrame, + nsIFrame* aFrame, nscoord aX, nscoord aY, PRInt32& aMaxWidth) @@ -4259,15 +3981,15 @@ DocumentViewerImpl::FindXMostFrameSize(nsIPresContext* aPresContext, FindXMostFrameInList(aPresContext, aRC, childListName, aFrame, aX, aY, aMaxWidth); NS_IF_RELEASE(childListName); aFrame->GetAdditionalChildListName(childListIndex++, &childListName); - } while (childListName); + } while (childListName); } //------------------------------------------------------- -// Return the PrintObject with that is XMost (The widest frameset frame) AND -// contains the XMost (widest) layout frame -PrintObject* +// Return the PrintObject with that is XMost (The widest frameset frame) AND +// contains the XMost (widest) layout frame +PrintObject* DocumentViewerImpl::FindXMostPO() { nscoord xMostForPO = 0; @@ -4375,7 +4097,7 @@ DocumentViewerImpl::SetupToPrintContent(nsIWebShell* aParent, PRINT_DEBUG_MSG1("\n-------------------------------------------------------\n\n"); // Set up the clipping rectangle for all documents - // When frames are being printed as part of a frame set and also IFrames, + // When frames are being printed as part of a frame set and also IFrames, // they are reflowed with a very large page height. We need to setup the // clipping so they do not rpint over top of anything else PRINT_DEBUG_MSG1("SetClipRect-------------------------------------------------------\n"); @@ -4410,7 +4132,7 @@ DocumentViewerImpl::SetupToPrintContent(nsIWebShell* aParent, // This will print the webshell document // when it completes asynchronously in the DonePrintingPages method - // it will check to see if there are more webshells to be printed and + // it will check to see if there are more webshells to be printed and // then PrintDocContent will be called again. nsresult rv = NS_OK; @@ -4467,7 +4189,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (aPO->mFrameType == eFrame) { switch (mPrt->mPrintFrameType) { - case nsIPrintSettings::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; break; @@ -4516,7 +4238,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a skipPageEjectOnly = aPO->mPrintAsIs; } - // That we are all configured, + // That we are all configured, // let's set everything up to print if (skipPageEjectOnly) { pageSequence->SkipPageEnd(); @@ -4550,8 +4272,8 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } } - PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s skipAllPageAdjustments: %s doOffsetting: %s doAddInParentsOffset: %s\n", - PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments), + PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s skipAllPageAdjustments: %s doOffsetting: %s doAddInParentsOffset: %s\n", + PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments), PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset)); // mPrt->mDebugFilePtr this is onlu non-null when compiled for debugging @@ -4565,7 +4287,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { fdbg->DumpRegressionData(poPresContext, mPrt->mDebugFilePtr, 0, PR_TRUE); } - fclose(mPrt->mDebugFilePtr); + fclose(mPrt->mDebugFilePtr); #endif } else { nsIFrame* rootFrame; @@ -4586,10 +4308,9 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (!skipSetTitle) { PRUnichar * docTitleStr; PRUnichar * docURLStr; - GetDisplayTitleAndURL(aPO, mPrt->mPrintSettings, mPrt->mBrandName, - &docTitleStr, &docURLStr, eDocTitleDefBlank); + GetDisplayTitleAndURL(aPO, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefBlank); - // Set them down into the PrintOptions so + // Set them down into the PrintOptions so // they can used by the DeviceContext if (docTitleStr) { mPrt->mPrintOptions->SetTitle(docTitleStr); @@ -4623,8 +4344,8 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (NS_SUCCEEDED(rvv) && selectionPS) { } - rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence, - &startFrame, startPageNum, startRect, + rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence, + &startFrame, startPageNum, startRect, &endFrame, endPageNum, endRect); if (NS_SUCCEEDED(rv)) { mPrt->mPrintSettings->SetStartPageRange(startPageNum); @@ -4795,7 +4516,7 @@ DocumentViewerImpl::PrintDocContent(PrintObject* aPO, nsresult& aStatus) if (!aPO->mHasBeenPrinted && aPO->IsPrintable()) { PRBool donePrinting; // donePrinting is only valid when when doing synchronous printing - aStatus = DoPrint(aPO, PR_FALSE, donePrinting); + aStatus = DoPrint(aPO, PR_FALSE, donePrinting); if (donePrinting) { return PR_TRUE; } @@ -4807,8 +4528,8 @@ DocumentViewerImpl::PrintDocContent(PrintObject* aPO, nsresult& aStatus) if (printed || NS_FAILED(aStatus)) { return PR_TRUE; } - } - return PR_FALSE; + } + return PR_FALSE; } NS_IMETHODIMP @@ -4819,11 +4540,11 @@ DocumentViewerImpl::SetEnableRendering(PRBool aOn) if (mViewManager) { if (aOn) { mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - nsIView* view; - mViewManager->GetRootView(view); // views are not refCounted - if (view) { + nsIView* view; + mViewManager->GetRootView(view); // views are not refCounted + if (view) { mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); - } + } } else { mViewManager->DisableRefresh(); @@ -4883,7 +4604,7 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, } } - nsCOMPtr chromeRegistry = + nsCOMPtr chromeRegistry = do_GetService("@mozilla.org/chrome/chrome-registry;1", &rv); if (NS_SUCCEEDED(rv) && chromeRegistry) { nsCOMPtr sheets; @@ -4939,7 +4660,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, nsCOMPtr dx; mPresContext->GetDeviceContext(getter_AddRefs(dx)); - + nsRect tbounds = aBounds; float p2t; mPresContext->GetPixelsToTwips(&p2t); @@ -4954,11 +4675,11 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; - // Reset the bounds offset so the root view is set to 0,0. The - // offset is specified in nsIViewManager::Init above. - // Besides, layout will reset the root view to (0,0) during reflow, - // so changing it to 0,0 eliminates placing the root view in the - // wrong place initially. + // Reset the bounds offset so the root view is set to 0,0. The offset is + // specified in nsIViewManager::Init above. + // Besides, layout will reset the root view to (0,0) during reflow, + // so changing it to 0,0 eliminates placing + // the root view in the wrong place initially. tbounds.x = 0; tbounds.y = 0; @@ -4973,7 +4694,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, nsIView* containerView = nsnull; if (NS_SUCCEEDED(aParentWidget->GetClientData(clientData))) { nsISupports* data = (nsISupports*)clientData; - + if (nsnull != data) { data->QueryInterface(NS_GET_IID(nsIView), (void **)&containerView); } @@ -4997,7 +4718,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, // // If the parent container is a chrome shell, or a frameset, then we won't hook into its view // tree. This will improve performance a little bit (especially given scrolling/painting perf bugs) - // but is really just for peace of mind. This check can be removed if we want to support fancy + // but is really just for peace of mind. This check can be removed if we want to support fancy // chrome effects like transparent controls floating over content, transparent Web browsers, and // things like that, and the perf bugs are fixed. nsCOMPtr container(do_QueryInterface(mContainer)); @@ -5054,8 +4775,8 @@ nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection, nsI nsCOMPtr selcon; selcon = do_QueryInterface(aPresShell); - if (selcon) - return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); + if (selcon) + return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); return NS_ERROR_FAILURE; } @@ -5067,13 +4788,13 @@ DocumentViewerImpl::CreateDocumentViewerUsing(nsIPresContext* aPresContext, // XXX better error return NS_ERROR_NULL_POINTER; } - if (!aPresContext) { + if (nsnull == aPresContext) { return NS_ERROR_NULL_POINTER; } // Create new viewer DocumentViewerImpl* viewer = new DocumentViewerImpl(aPresContext); - if (!viewer) { + if (nsnull == viewer) { return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(viewer); @@ -5084,7 +4805,7 @@ DocumentViewerImpl::CreateDocumentViewerUsing(nsIPresContext* aPresContext, // Bind the new viewer to the old document nsresult rv = viewer->LoadStart(mDocument); - + aResult = viewer; return rv; @@ -5133,7 +4854,7 @@ nsresult DocumentViewerImpl::DocumentReadyForPrinting() return rv; } -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::SetTransformMediator(nsITransformMediator* aMediator) { NS_ASSERTION(nsnull == mTransformMediator, "nsXMLDocument::SetTransformMediator(): \ @@ -5185,7 +4906,7 @@ NS_IMETHODIMP DocumentViewerImpl::SelectAll() nsCOMPtr htmldoc = do_QueryInterface(mDocument); nsCOMPtr bodyNode; - + if (htmldoc) { nsCOMPtrbodyElement; @@ -5200,8 +4921,8 @@ NS_IMETHODIMP DocumentViewerImpl::SelectAll() mDocument->GetRootContent(getter_AddRefs(rootContent)); bodyNode = do_QueryInterface(rootContent); } - if (!bodyNode) return NS_ERROR_FAILURE; - + if (!bodyNode) return NS_ERROR_FAILURE; + rv = selection->RemoveAllRanges(); if (NS_FAILED(rv)) return rv; @@ -5254,10 +4975,10 @@ NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable) nsresult rv; rv = GetDocumentSelection(getter_AddRefs(selection)); if (NS_FAILED(rv)) return rv; - + PRBool isCollapsed; selection->GetIsCollapsed(&isCollapsed); - + *aCopyable = !isCollapsed; return NS_OK; } @@ -5342,7 +5063,7 @@ nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpe if (NS_FAILED(rv)) { return rv; } rv = htmlElement->AppendChildTo(bodyElement, PR_FALSE, PR_FALSE); if (NS_FAILED(rv)) { return rv; } - + // load the document into the docshell nsCOMPtr domDoc = do_QueryInterface(doc); if (!domDoc) { return NS_ERROR_NULL_POINTER; } @@ -5360,8 +5081,8 @@ nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpe } //------------------------------------------------------ -PRBool -DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, +PRBool +DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, nsIDOMWindowInternal * aDOMWin, PRPackedBool& aIsParentFrameSet) { @@ -5377,7 +5098,7 @@ DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, // if so, it means the selected frame is either the main webshell // or an IFRAME if (aDOMWin != nsnull) { - // Get the main webshell's DOMWin to see if it matches + // Get the main webshell's DOMWin to see if it matches // the frame that is selected nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(aWebShell)); if (aDOMWin != nsnull && domWin != aDOMWin) { @@ -5391,7 +5112,7 @@ DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, //------------------------------------------------------ -PRBool +PRBool DocumentViewerImpl::IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin) { nsCOMPtr presShell; @@ -5426,7 +5147,7 @@ DocumentViewerImpl::IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin) //------------------------------------------------------- // Recursively walks the PrintObject tree and installs the DocViewer // as an event processor and it shows the window -nsresult +nsresult DocumentViewerImpl::ShowDocList(PrintObject* aPO, PRBool aShow) { NS_ASSERTION(aPO, "Pointer is null!"); @@ -5485,7 +5206,7 @@ DocumentViewerImpl::InstallPrintPreviewListener() //---------------------------------------------------------------------- static nsresult GetSeqFrameAndCountPages(PrintObject* aPO, - nsIFrame*& aSeqFrame, + nsIFrame*& aSeqFrame, PRInt32& aCount) { NS_ENSURE_ARG_POINTER(aPO); @@ -5632,7 +5353,7 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) } /* readonly attribute boolean isFramesetDocument; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) { nsCOMPtr webContainer(do_QueryInterface(mContainer)); @@ -5681,7 +5402,7 @@ DocumentViewerImpl::GetIsFramesetFrameSelected(PRBool *aIsFramesetFrameSelected) } /* readonly attribute long printPreviewNumPages; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) { NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages); @@ -5698,7 +5419,7 @@ DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) } /* void exitPrintPreview (); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::ExitPrintPreview() { if (mIsDoingPrintPreview) { @@ -5744,7 +5465,7 @@ DocumentViewerImpl::InstallNewPresentation() nsCOMPtr selection; nsresult rv = GetDocumentSelection(getter_AddRefs(selection)); nsCOMPtr selPrivate(do_QueryInterface(selection)); - if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) + if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) selPrivate->RemoveSelectionListener(mSelectionListener); // We need to destroy the PreShell if there is an existing PP @@ -5780,7 +5501,7 @@ DocumentViewerImpl::InstallNewPresentation() // This is the new code for selecting the appropriate Frame of a Frameset // for Print Preview. But it can't be turned on yet -#if 0 +#if 0 // If it is a Frameset then choose the selected one // or select the one with the largest area if (mPrt->mPrintObject->mFrameType == eFrameSet) { @@ -5898,7 +5619,7 @@ DocumentViewerImpl::ReturnToGalleyPresentation() nsCOMPtr selection; nsresult rv = GetDocumentSelection(getter_AddRefs(selection)); nsCOMPtr selPrivate(do_QueryInterface(selection)); - if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) + if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) selPrivate->RemoveSelectionListener(mSelectionListener); mPresShell->Destroy(); } @@ -5959,7 +5680,7 @@ DocumentViewerImpl::ReturnToGalleyPresentation() // This method checks to see if there is at least one printer defined // and if so, it sets the first printer in the list as the default name // in the PrintSettings which is then used for Printer Preview -nsresult +nsresult DocumentViewerImpl::CheckForPrinters(nsIPrintOptions* aPrintOptions, nsIPrintSettings* aPrintSettings, PRUint32 aErrorCode, @@ -5977,7 +5698,7 @@ DocumentViewerImpl::CheckForPrinters(nsIPrintOptions* aPrintOptions, simpEnum->HasMoreElements(&fndPrinter); if (fndPrinter) { // For now, it assumes the first item in the list - // is the default printer, but only set the + // is the default printer, but only set the // printer name if there isn't one nsCOMPtr supps; simpEnum->GetNext(getter_AddRefs(supps)); @@ -6104,36 +5825,23 @@ DocumentViewerImpl::CheckDocumentForPPCaching() * See documentation above in the nsIContentViewerfile class definition * @update 11/01/01 rods * - * For a full and detailed understanding of the issues with - * PrintPreview: See the design spec that is attached to Bug 107562 + * For a full and detailed understanding of the issues with + * PrintPreview: See the design spec that is attached to Bug 107562 */ NS_IMETHODIMP DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) { - nsCOMPtr docShell(do_QueryInterface(mContainer)); - NS_ASSERTION(docShell, "This has to be a docshell"); - - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - // A frame that's not displayed can't be printed! - - return NS_OK; - } - - + // Get the webshell for this documentviewer + nsCOMPtr webContainer(do_QueryInterface(mContainer)); + // Get the DocShell and see if it is busy + // We can't Print or Print Preview this document if it is still busy + nsCOMPtr docShell(do_QueryInterface(webContainer)); + NS_ASSERTION(docShell.get(), "This has to be a docshell"); PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE; - - if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) || - busyFlags != nsIDocShell::BUSY_FLAGS_NONE) { + if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) || busyFlags != nsIDocShell::BUSY_FLAGS_NONE) { ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP, PR_FALSE); return NS_ERROR_FAILURE; } - - // Get the webshell for this documentviewer - nsCOMPtr webContainer(do_QueryInterface(mContainer)); - nsresult rv = NS_OK; #if defined(XP_PC) && defined(DEBUG_rods) && defined(DEBUG_PRINTING) @@ -6164,13 +5872,12 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) mOldPrtPreview->mCachedPresObj = nsnull; } - // You have to have both a PrintOptions and a PrintSetting to call - // CheckForPrinters. - // The user can pass in a null PrintSettings, but you can only - // create one if you have a PrintOptions. So we we might as check - // to if we have a PrintOptions first, because we can't do anything - // below without it then inside we check to se if the printSettings - // is null to know if we need to create on. + // You have to have both a PrintOptions and a PrintSetting to call CheckForPrinters. + // The user can pass in a null PrintSettings, + // but you can only create one if you have a PrintOptions. + // So we we might as check to if we have a PrintOptions first, + // because we can't do anything below without it + // then inside we check to se if the printSettings is null to know if we need to create on. mPrt->mPrintSettings = aPrintSettings; mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) { @@ -6187,7 +5894,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) return NS_ERROR_FAILURE; } } - + // Let's print ... mIsCreatingPrintPreview = PR_TRUE; mIsDoingPrintPreview = PR_TRUE; @@ -6224,7 +5931,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject); mPrt->mIsParentAFrameSet = IsParentAFrameSet(webContainer); - mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet ? eFrameSet : eDoc; + mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet?eFrameSet:eDoc; // Build the "tree" of PrintObjects nsCOMPtr parentAsNode(do_QueryInterface(webContainer)); @@ -6234,8 +5941,8 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) // in the parent document MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject); - // Get whether the doc contains a frameset - // Also, check to see if the currently focus webshell + // Get whether the doc contains a frameset + // Also, check to see if the currently focus webshell // is a child of this webshell mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet); @@ -6262,7 +5969,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) #ifdef DEBUG_PRINTING if (mPrt->mPrintSettings) { - PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); @@ -6290,7 +5997,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) nsCOMPtr dx; nsresult rv = factory->CreateDeviceContextSpec(mWindow, aPrintSettings, *getter_AddRefs(devspec), doSilent); if (NS_SUCCEEDED(rv)) { - rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); + rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); if (NS_SUCCEEDED(rv)) { mDeviceContext->SetAltDevice(ppDC); if (mPrt->mPrintSettings != nsnull) { @@ -6317,7 +6024,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) mPrt->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); } - mPrt->mPrintDC = mDeviceContext; + mPrt->mPrintDC = mDeviceContext; // Get the Original PixelScale incase we need to start changing it mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); @@ -6347,8 +6054,8 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) } /* cleanup done, let's fire-up an error dialog to notify the user - * what went wrong... - */ + * what went wrong... + */ ShowPrintErrorDialog(rv, PR_FALSE); TurnScriptingOn(PR_TRUE); mIsCreatingPrintPreview = PR_FALSE; @@ -6357,7 +6064,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) } - // At this point we are done preparing everything + // At this point we are done preparing everything // before it is to be created // Noew create the new Presentation and display it @@ -6454,7 +6161,7 @@ DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting) */ NS_IMETHODIMP DocumentViewerImpl::Print(PRBool aSilent, - FILE * aDebugFile, + FILE * aDebugFile, nsIPrintSettings* aPrintSettings) { nsCOMPtr printSettings; @@ -6478,7 +6185,7 @@ DocumentViewerImpl::Print(PRBool aSilent, return Print(printSettings, nsnull); - + } /** --------------------------------------------------- @@ -6497,17 +6204,6 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr docShell(do_QueryInterface(mContainer)); - NS_ASSERTION(docShell, "This has to be a docshell"); - - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - // A frame that's not displayed can't be printed! - - return NS_OK; - } if (mIsDoingPrintPreview) { PRBool okToPrint = PR_FALSE; @@ -6522,7 +6218,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, } // if we are printing another URL, then exit - // the reason we check here is because this method can be called while + // the reason we check here is because this method can be called while // another is still in here (the printing dialog is a good example). // the only time we can print more than one job at a time is the regression tests if (mIsDoingPrinting) { @@ -6531,7 +6227,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, ShowPrintErrorDialog(rv); return rv; } - + mPrt = new PrintData(); if (mPrt == nsnull) { return NS_ERROR_OUT_OF_MEMORY; @@ -6570,7 +6266,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener); NS_ADDREF(aWebProgressListener); } - + // Get the currently focused window and cache it // because the Print Dialog will "steal" focus and later when you try // to get the currently focused windows it will be NULL @@ -6612,8 +6308,8 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject); - // Get whether the doc contains a frameset - // Also, check to see if the currently focus webshell + // Get whether the doc contains a frameset + // Also, check to see if the currently focus webshell // is a child of this webshell mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet); @@ -6635,7 +6331,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, #ifdef DEBUG_PRINTING if (mPrt->mPrintSettings) { - PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); @@ -6654,7 +6350,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, /* create factory (incl. create print dialog) */ nsCOMPtr factory = do_CreateInstance(kDeviceContextSpecFactoryCID, &rv); - + if (NS_SUCCEEDED(rv)) { #ifdef DEBUG_dcone printf("PRINT JOB STARTING\n"); @@ -6776,7 +6472,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); } else { - // First find out from the PrinService what options are available + // First find out from the PrinService what options are available // to us for Printing FrameSets PRInt16 howToEnableFrameUI; mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); @@ -6821,14 +6517,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, PRUnichar * docTitleStr; PRUnichar * docURLStr; - GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, - mPrt->mBrandName, &docTitleStr, &docURLStr, - eDocTitleDefURLDoc); + GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); // BeginDocument may pass back a FAILURE code - // i.e. On Windows, if you are printing to a file and hit "Cancel" + // i.e. On Windows, if you are printing to a file and hit "Cancel" // to the "File Name" dialog, this comes back as an error - // Don't start printing when regression test are executed + // Don't start printing when regression test are executed rv = mPrt->mDebugFilePtr ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr); PRINT_DEBUG_MSG1("****************** Begin Document ************************\n"); @@ -6841,12 +6535,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, // Print listener setup... if (mPrt != nsnull) { - mPrt->OnStartPrinting(); + mPrt->OnStartPrinting(); } // // The mIsPrinting flag is set when the ImageGroup observer is - // notified that images must be loaded as a result of the + // notified that images must be loaded as a result of the // InitialReflow... // if(!mIsPrinting || mPrt->mDebugFilePtr) { @@ -6859,18 +6553,20 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, } } } - } + } } else { mPrt->mPrintSettings->SetIsCancelled(PR_TRUE); mPrt->mPrintOptions->SetIsCancelled(PR_TRUE); } - - // Set that we are once again in print preview + + // Set that we are once again in print preview if ( mIsDoingPrintPreview == PR_TRUE) { aPrintSettings->SetIsPrintPreview(PR_TRUE); } } + + /* cleaup on failure + notify user */ if (NS_FAILED(rv)) { /* cleanup... */ @@ -6878,7 +6574,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPagePrintTimer->Stop(); NS_RELEASE(mPagePrintTimer); } - + if (mPrt) { delete mPrt; mPrt = nsnull; @@ -6886,16 +6582,16 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mIsDoingPrinting = PR_FALSE; /* cleanup done, let's fire-up an error dialog to notify the user - * what went wrong... - * - * When rv == NS_ERROR_ABORT, it means we want out of the + * what went wrong... + * + * When rv == NS_ERROR_ABORT, it means we want out of the * print job without displaying any error messages */ if (rv != NS_ERROR_ABORT) { ShowPrintErrorDialog(rv); } } - + return rv; } @@ -6904,19 +6600,19 @@ void DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) { nsresult rv; - + static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); nsCOMPtr stringBundleService = do_GetService(kCStringBundleServiceCID); - - if (!stringBundleService) { + + if (!stringBundleService) { NS_WARNING("ERROR: Failed to get StringBundle Service instance.\n"); return; } nsCOMPtr myStringBundle; - rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); - if (NS_FAILED(rv)) + rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); + if (NS_FAILED(rv)) return; - + nsXPIDLString msg, title; nsAutoString stringName; @@ -6957,7 +6653,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin default: NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_FAILURE) -#undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG +#undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG } myStringBundle->GetStringFromName(stringName.get(), getter_Copies(msg)); @@ -6969,7 +6665,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin if (!msg) return; - + nsCOMPtr wwatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv); if (NS_FAILED(rv)) return; @@ -6980,22 +6676,27 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin nsCOMPtr parent = do_QueryInterface(active, &rv); if (NS_FAILED(rv)) return; - - nsCOMPtr dialog; - parent->GetPrompter(getter_AddRefs(dialog)); + + nsCOMPtr dialog; + parent->GetPrompter(getter_AddRefs(dialog)); if (!dialog) return; - + dialog->Alert(title, msg); } // nsIContentViewerFile interface NS_IMETHODIMP -DocumentViewerImpl::GetPrintable(PRBool *aPrintable) +DocumentViewerImpl::GetPrintable(PRBool *aPrintable) { NS_ENSURE_ARG_POINTER(aPrintable); - *aPrintable = !mIsDoingPrinting; + + if(mIsDoingPrinting==PR_TRUE){ + *aPrintable = PR_FALSE; + } else { + *aPrintable = PR_TRUE; + } return NS_OK; } @@ -7006,7 +6707,7 @@ DocumentViewerImpl::GetPrintable(PRBool *aPrintable) //***************************************************************************** // nsIMarkupDocumentViewer -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) { @@ -7015,25 +6716,25 @@ NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) nsCOMPtr presShell; NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); - // Get the nsIContent interface, because that's what we need to + // Get the nsIContent interface, because that's what we need to // get the primary frame - + nsCOMPtr content(do_QueryInterface(aNode)); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); // Get the primary frame - nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their + nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their // own special little world. NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame), NS_ERROR_FAILURE); // tell the pres shell to scroll to the frame - NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, - NS_PRESSHELL_SCROLL_TOP, - NS_PRESSHELL_SCROLL_ANYWHERE), - NS_ERROR_FAILURE); - return NS_OK; + NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, + NS_PRESSHELL_SCROLL_TOP, + NS_PRESSHELL_SCROLL_ANYWHERE), + NS_ERROR_FAILURE); + return NS_OK; } NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins) @@ -7059,17 +6760,17 @@ DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure) PRInt32 i; PRInt32 n; docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) + for (i=0; i < n; i++) { nsCOMPtr child; docShellNode->GetChildAt(i, getter_AddRefs(child)); nsCOMPtr childAsShell(do_QueryInterface(child)); NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) + if (childAsShell) { nsCOMPtr childCV; childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) + if (childCV) { nsCOMPtr markupCV = do_QueryInterface(childCV); if (markupCV) { @@ -7120,7 +6821,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) return NS_OK; } -// XXX: SEMANTIC CHANGE! +// XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aDefaultCharacterSet) NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) @@ -7128,18 +6829,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCha NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); NS_ENSURE_STATE(mContainer); - if (mDefaultCharacterSet.IsEmpty()) + if (mDefaultCharacterSet.IsEmpty()) { nsXPIDLString defCharset; nsCOMPtr webShell; webShell = do_QueryInterface(mContainer); if (webShell) - { + { nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); if (prefs) prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset)); - } + } if (!defCharset.IsEmpty()) mDefaultCharacterSet.Assign(defCharset.get()); @@ -7164,7 +6865,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefau (void*) aDefaultCharacterSet); } -// XXX: SEMANTIC CHANGE! +// XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aForceCharacterSet) NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet) @@ -7194,7 +6895,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCh return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet); } -// XXX: SEMANTIC CHANGE! +// XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aHintCharacterSet) NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) @@ -7279,7 +6980,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetBidiTextDirection(PRUint8* aTextDirection) #endif return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::SetBidiTextType(PRUint8 aTextType) { #ifdef IBMBIDI @@ -7435,9 +7136,9 @@ NS_IMETHODIMP DocumentViewerImpl::SetBidiOptions(PRUint32 aBidiOptions) #ifdef IBMBIDI if (mPresContext) { #if 1 - // forcing reflow will cause bug 80352. Temp turn off force reflow and + // forcing reflow will cause bug 80352. Temp turn off force reflow and // wait for simon@softel.co.il to find the real solution - mPresContext->SetBidi(aBidiOptions, PR_FALSE); + mPresContext->SetBidi(aBidiOptions, PR_FALSE); #else mPresContext->SetBidi(aBidiOptions, PR_TRUE); // force reflow #endif @@ -7472,7 +7173,7 @@ NS_IMETHODIMP DocumentViewerImpl::SizeToContent() nsCOMPtr docShellParent; docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); - // It's only valid to access this from a top frame. Doesn't work from + // It's only valid to access this from a top frame. Doesn't work from // sub-frames. NS_ENSURE_TRUE(!docShellParent, NS_ERROR_FAILURE); @@ -7561,7 +7262,7 @@ DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode) // get the internal dom window nsCOMPtr internalWin(do_QueryInterface(global, &rv)); NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(internalWin, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(internalWin, NS_ERROR_FAILURE); // get the private dom window nsCOMPtr privateWin(do_QueryInterface(internalWin, &rv)); @@ -7733,20 +7434,20 @@ NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocumen if (!mGotSelectionState || mSelectionWasCollapsed != selectionCollapsed) { nsCOMPtr theDoc; - mDocViewer->GetDocument(*getter_AddRefs(theDoc)); + mDocViewer->GetDocument(*getter_AddRefs(theDoc)); if (!theDoc) return NS_ERROR_FAILURE; - + nsCOMPtr scriptGlobalObject; theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); nsCOMPtr domWindow = do_QueryInterface(scriptGlobalObject); if (!domWindow) return NS_ERROR_FAILURE; - + domWindow->UpdateCommands(NS_LITERAL_STRING("select")); mGotSelectionState = PR_TRUE; mSelectionWasCollapsed = selectionCollapsed; - } - + } + return NS_OK; } @@ -7783,7 +7484,7 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) selCon->GetDisplaySelection( &selectionStatus); //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. + //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_DISABLED || selectionStatus == nsISelectionController::SELECTION_HIDDEN) { @@ -7797,7 +7498,7 @@ NS_IMETHODIMP nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; - if(!mDocViewer) + if(!mDocViewer) return NS_ERROR_FAILURE; nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref @@ -7807,7 +7508,7 @@ nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) selCon = do_QueryInterface(shell); PRInt16 selectionStatus; selCon->GetDisplaySelection(&selectionStatus); - + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_ON) @@ -7827,7 +7528,7 @@ nsDocViewerFocusListener::Init(DocumentViewerImpl *aDocViewer) } -PRBool +PRBool DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) { PRBool found = PR_FALSE; @@ -7868,7 +7569,7 @@ DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) //---------------------------------------------------------------------------------- -void +void DocumentViewerImpl::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) { for (PRInt32 i = aCount - 1; i >= 0; i--) { @@ -7881,8 +7582,8 @@ DocumentViewerImpl::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) //---------------------------------------------------------------------------------- // Enumerate all the documents for their titles -NS_IMETHODIMP -DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, +NS_IMETHODIMP +DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, PRUnichar*** aResult) { NS_ENSURE_ARG(aCount); @@ -7890,12 +7591,12 @@ DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, *aCount = 0; *aResult = nsnull; - + PRInt32 numDocs = mPrt->mPrintDocList->Count(); PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numDocs * sizeof(PRUnichar*)); - if (!array) + if (!array) return NS_ERROR_OUT_OF_MEMORY; - + for (PRInt32 i=0;imPrintDocList->ElementAt(i); NS_ASSERTION(po, "PrintObject can't be null!"); @@ -7928,7 +7629,7 @@ DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, } /* readonly attribute nsIPrintSettings newPrintSettings; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) { NS_ENSURE_ARG_POINTER(aNewPrintSettings); @@ -7943,7 +7644,7 @@ DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) } /* readonly attribute wstring defaultPrinterName; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName) { NS_ENSURE_ARG_POINTER(aDefaultPrinterName); @@ -7957,7 +7658,7 @@ DocumentViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName) } /* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings) { NS_ENSURE_ARG_POINTER(aPrintSettings); @@ -7979,7 +7680,7 @@ DocumentViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, } /* readonly attribute nsIPrintSettings globalPrintSettings; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings) { NS_ENSURE_ARG_POINTER(aGlobalPrintSettings); @@ -8002,7 +7703,7 @@ DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) } /* readonly attribute nsIPrintSettings currentPrintSettings; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings) { NS_ENSURE_ARG_POINTER(aCurrentPrintSettings); @@ -8021,7 +7722,7 @@ DocumentViewerImpl::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSet } /* void cancel (); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::Cancel() { nsresult rv; @@ -8033,7 +7734,7 @@ DocumentViewerImpl::Cancel() } /* void initPrintSettingsFromPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags) { nsresult rv; @@ -8045,7 +7746,7 @@ DocumentViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, } /* void savePrintSettingsToPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags) { nsresult rv; @@ -8058,7 +7759,7 @@ DocumentViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, P /** --------------------------------------------------- * Get the Focused Frame for a documentviewer - * + * */ nsIDOMWindowInternal* DocumentViewerImpl::FindFocusedDOMWindowInternal() @@ -8069,7 +7770,7 @@ DocumentViewerImpl::FindFocusedDOMWindowInternal() nsCOMPtr focusController; nsIDOMWindowInternal * domWin = nsnull; - this->GetDocument(*getter_AddRefs(theDoc)); + this->GetDocument(*getter_AddRefs(theDoc)); if(theDoc){ theDoc->GetScriptGlobalObject(getter_AddRefs(theSGO)); if(theSGO){ @@ -8095,7 +7796,7 @@ DocumentViewerImpl::FindFocusedDOMWindowInternal() /*=============== Timer Related Code ======================*/ nsresult -DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, +DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPOect, PRUint32 aDelay) diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index fc75c957693..1a4e5c9f97d 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -40,14 +40,13 @@ #include "nsIFrameLoader.h" #include "nsIDOMHTMLIFrameElement.h" #include "nsIDOMHTMLFrameElement.h" +#include "nsIDOMEventListener.h" +#include "nsIDOMEventTarget.h" #include "nsIDOMWindow.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIContent.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" -#include "nsIDOMWindow.h" -#include "nsPIDOMWindow.h" #include "nsIWebNavigation.h" #include "nsIChromeEventHandler.h" #include "nsIDocShell.h" @@ -57,6 +56,9 @@ #include "nsIDocShellLoadInfo.h" #include "nsIBaseWindow.h" #include "nsIWebShell.h" +#include "nsIWebProgressListener.h" +#include "nsIWebProgress.h" +#include "nsWeakReference.h" #include "nsIScriptSecurityManager.h" #include "nsICodebasePrincipal.h" @@ -64,17 +66,10 @@ #include "nsIURI.h" #include "nsNetUtil.h" -#include "nsHTMLAtoms.h" -#include "nsINameSpaceManager.h" - - -// Bug 8065: Limit content frame depth to some reasonable level. This -// does not count chrome frames when determining depth, nor does it -// prevent chrome recursion. -#define MAX_DEPTH_CONTENT_FRAMES 25 - - -class nsFrameLoader : public nsIFrameLoader +class nsFrameLoader : public nsIFrameLoader, + public nsIDOMEventListener, + public nsIWebProgressListener, + public nsSupportsWeakReference { public: nsFrameLoader(); @@ -84,19 +79,26 @@ public: NS_DECL_ISUPPORTS // nsIFrameLoader - NS_IMETHOD Init(nsIContent *aOwner); - NS_IMETHOD LoadFrame(); + NS_IMETHOD Init(nsIDOMElement *aOwner); + NS_IMETHOD LoadURI(nsIURI *aURI); NS_IMETHOD GetDocShell(nsIDocShell **aDocShell); NS_IMETHOD Destroy(); + // nsIDOMEventListener + NS_DECL_NSIDOMEVENTLISTENER + + // nsIWebProgressListener + NS_DECL_NSIWEBPROGRESSLISTENER + protected: nsresult GetPresContext(nsIPresContext **aPresContext); nsresult EnsureDocShell(); - void GetURL(nsAString& aURL); nsCOMPtr mDocShell; - nsIContent *mOwnerContent; // WEAK + nsCOMPtr mOwnerElement; + + nsCOMPtr mURI; }; nsresult @@ -110,22 +112,26 @@ NS_NewFrameLoader(nsIFrameLoader **aFrameLoader) return NS_OK; } + nsFrameLoader::nsFrameLoader() - : mOwnerContent(nsnull) { NS_INIT_ISUPPORTS(); } nsFrameLoader::~nsFrameLoader() { - Destroy(); + nsCOMPtr treeOwnerAsWin(do_QueryInterface(mDocShell)); + + if (treeOwnerAsWin) { + treeOwnerAsWin->Destroy(); + } } // QueryInterface implementation for nsFrameLoader NS_INTERFACE_MAP_BEGIN(nsFrameLoader) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIFrameLoader) - NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END @@ -133,49 +139,27 @@ NS_IMPL_ADDREF(nsFrameLoader); NS_IMPL_RELEASE(nsFrameLoader); NS_IMETHODIMP -nsFrameLoader::Init(nsIContent *aOwner) +nsFrameLoader::Init(nsIDOMElement *aOwner) { - mOwnerContent = aOwner; // WEAK + mOwnerElement = aOwner; return NS_OK; } NS_IMETHODIMP -nsFrameLoader::LoadFrame() +nsFrameLoader::LoadURI(nsIURI *aURI) { - NS_ENSURE_TRUE(mOwnerContent, NS_ERROR_NOT_INITIALIZED); + mURI = aURI; nsresult rv = EnsureDocShell(); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr doc; - mOwnerContent->GetDocument(*getter_AddRefs(doc)); - NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); - nsAutoString src; - GetURL(src); + // Prevent recursion - src.Trim(" \t\n\r"); - if (src.IsEmpty()) { - // about:blank will be synthesized into a frame if not URL is - // loaded into it (bug 35986) - return NS_OK; - } + // mCreatingViewer=PR_TRUE; - // Make an absolute URI - nsCOMPtr base_uri; - doc->GetBaseURL(*getter_AddRefs(base_uri)); - - nsAutoString doc_charset; - doc->GetDocumentCharacterSet(doc_charset); - - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), src, - doc_charset.IsEmpty() ? nsnull : - NS_ConvertUCS2toUTF8(doc_charset).get(), base_uri); - NS_ENSURE_SUCCESS(rv, rv); // Check for security nsCOMPtr secMan = @@ -213,21 +197,31 @@ nsFrameLoader::LoadFrame() loadInfo->SetInheritOwner(PR_TRUE); - referrer = base_uri; + nsCOMPtr dom_doc; + mOwnerElement->GetOwnerDocument(getter_AddRefs(dom_doc)); + nsCOMPtr doc(do_QueryInterface(dom_doc)); + + if (doc) { + doc->GetBaseURL(*getter_AddRefs(referrer)); + } } loadInfo->SetReferrer(referrer); // Check if we are allowed to load absURL - rv = secMan->CheckLoadURI(referrer, uri, + rv = secMan->CheckLoadURI(referrer, mURI, nsIScriptSecurityManager::STANDARD); if (NS_FAILED(rv)) { return rv; // We're not } - // Kick off the load... - rv = mDocShell->LoadURI(uri, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, - PR_FALSE); + nsCOMPtr webProgress(do_GetInterface(mDocShell)); + + if (webProgress) { + webProgress->AddProgressListener(this); + } + + rv = mDocShell->LoadURI(mURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL"); return rv; @@ -247,25 +241,12 @@ nsFrameLoader::GetDocShell(nsIDocShell **aDocShell) NS_IMETHODIMP nsFrameLoader::Destroy() { - if (mOwnerContent) { - nsCOMPtr doc; + return NS_OK; +} - mOwnerContent->GetDocument(*getter_AddRefs(doc)); - - if (doc) { - doc->SetSubDocumentFor(mOwnerContent, nsnull); - } - - mOwnerContent = nsnull; - } - - nsCOMPtr base_win(do_QueryInterface(mDocShell)); - - if (base_win) { - base_win->Destroy(); - } - - mDocShell = nsnull; +NS_IMETHODIMP +nsFrameLoader::HandleEvent(nsIDOMEvent *aEvent) +{ return NS_OK; } @@ -275,8 +256,10 @@ nsFrameLoader::GetPresContext(nsIPresContext **aPresContext) { *aPresContext = nsnull; - nsCOMPtr doc; - mOwnerContent->GetDocument(*getter_AddRefs(doc)); + nsCOMPtr dom_doc; + mOwnerElement->GetOwnerDocument(getter_AddRefs(dom_doc)); + + nsCOMPtr doc(do_QueryInterface(dom_doc)); while (doc) { nsCOMPtr presShell; @@ -304,15 +287,16 @@ nsFrameLoader::EnsureDocShell() return NS_OK; } - nsCOMPtr presContext; - GetPresContext(getter_AddRefs(presContext)); - NS_ENSURE_TRUE(presContext, NS_ERROR_UNEXPECTED); +#if 0 + + + // Bug 8065: Don't exceed some maximum depth in content frames // (MAX_DEPTH_CONTENT_FRAMES) PRInt32 depth = 0; nsCOMPtr parentAsSupports; - presContext->GetContainer(getter_AddRefs(parentAsSupports)); + aPresContext->GetContainer(getter_AddRefs(parentAsSupports)); if (parentAsSupports) { nsCOMPtr parentAsItem = @@ -337,16 +321,32 @@ nsFrameLoader::EnsureDocShell() } } } +#endif - // Create the docshell... mDocShell = do_CreateInstance("@mozilla.org/webshell;1"); NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); - // Get the frame name and tell the docshell about it. +#if 0 + // notify the pres shell that a docshell has been created + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + + if (presShell) { + nsCOMPtr subShellAsSupports(do_QueryInterface(mDocShell)); + NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE); + + presShell->SetSubShellFor(mContent, subShellAsSupports); + + // We need to be able to get back to the presShell to unset the + // subshell at destruction + mPresShellWeak = getter_AddRefs(NS_GetWeakReference(presShell)); + } +#endif + nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); nsAutoString frameName; - mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, frameName); + mOwnerElement->GetAttribute(NS_LITERAL_STRING("name"), frameName); if (!frameName.IsEmpty()) { docShellAsItem->SetName(frameName.get()); @@ -356,148 +356,178 @@ nsFrameLoader::EnsureDocShell() // child. If it's not a web-shell then some things will not operate // properly. + + nsCOMPtr presContext; + GetPresContext(getter_AddRefs(presContext)); + + + + + + + + + + + + // what if !presContext ? + + + + + + + + + nsCOMPtr container; presContext->GetContainer(getter_AddRefs(container)); - nsCOMPtr parentAsNode(do_QueryInterface(container)); - if (parentAsNode) { - nsCOMPtr parentAsItem = - do_QueryInterface(parentAsNode); + if (container) { + nsCOMPtr parentAsNode(do_QueryInterface(container)); + if (parentAsNode) { + nsCOMPtr parentAsItem = + do_QueryInterface(parentAsNode); - PRInt32 parentType; - parentAsItem->GetItemType(&parentType); + PRInt32 parentType; + parentAsItem->GetItemType(&parentType); - nsAutoString value; - PRBool isContent; + nsAutoString value, valuePiece; + PRBool isContent; - isContent = PR_FALSE; + isContent = PR_FALSE; + mOwnerElement->GetAttribute(NS_LITERAL_STRING("type"), value); - if (mOwnerContent->IsContentOfType(nsIContent::eXUL)) { - mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, value); - } + if (!value.IsEmpty()) { + // we accept "content" and "content-xxx" values. + // at time of writing, we expect "xxx" to be "primary", but + // someday it might be an integer expressing priority - if (!value.IsEmpty()) { - // we accept "content" and "content-xxx" values. - // at time of writing, we expect "xxx" to be "primary", but - // someday it might be an integer expressing priority - if (value.Length() >= 7) { - ToLowerCase(value); - nsAutoString::const_iterator start, end; - value.BeginReading(start); - value.EndReading(end); - nsAutoString::const_iterator iter(start); - iter.advance(7); + // string iterators! - const nsAString& valuePiece = Substring(start, iter); - if (valuePiece.Equals(NS_LITERAL_STRING("content")) && - (iter == end || *iter == '-')) { + value.Left(valuePiece, 7); + if (valuePiece.EqualsIgnoreCase("content") && + (value.Length() == 7 || + value.Mid(valuePiece, 7, 1) == 1 && + valuePiece.EqualsWithConversion("-"))) { isContent = PR_TRUE; } } - } - if (isContent) { - // The web shell's type is content. - - docShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent); - } else { - // Inherit our type from our parent webshell. If it is - // chrome, we'll be chrome. If it is content, we'll be - // content. - - docShellAsItem->SetItemType(parentType); - } - - parentAsNode->AddChild(docShellAsItem); - - if (isContent) { - nsCOMPtr parentTreeOwner; - parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); - - if(parentTreeOwner) { - // value is lowercased above. - PRBool is_primary = value.Equals(NS_LITERAL_STRING("content-primary")); - - parentTreeOwner->ContentShellAdded(docShellAsItem, is_primary, - value.get()); + if (isContent) { + // The web shell's type is content. + docShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent); + } else { + // Inherit our type from our parent webshell. If it is + // chrome, we'll be chrome. If it is content, we'll be + // content. + docShellAsItem->SetItemType(parentType); } + + parentAsNode->AddChild(docShellAsItem); + + if (isContent) { + nsCOMPtr parentTreeOwner; + parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); + if(parentTreeOwner) { + PRBool is_primary = value.EqualsIgnoreCase("content-primary"); + + parentTreeOwner->ContentShellAdded(docShellAsItem, is_primary, + value.get()); + } + } + + // connect the container... + nsCOMPtr webShell(do_QueryInterface(mDocShell)); + nsCOMPtr outerContainer = + do_QueryInterface(container); + + if (outerContainer) { + webShell->SetContainer(outerContainer); + } + + // Make sure all shells have links back to the content element + // in the nearest enclosing chrome shell. + nsCOMPtr chromeEventHandler; + + if (parentType == nsIDocShellTreeItem::typeChrome) { + // Our parent shell is a chrome shell. It is therefore our nearest + // enclosing chrome shell. + chromeEventHandler = do_QueryInterface(mOwnerElement); + NS_WARN_IF_FALSE(chromeEventHandler, + "This mContent should implement this."); + } else { + nsCOMPtr parentShell(do_QueryInterface(parentAsNode)); + + // Our parent shell is a content shell. Get the chrome info from + // it and use that for our shell as well. + parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler)); + } + + + + // Should this be in the layout code? + + mDocShell->SetChromeEventHandler(chromeEventHandler); } - - // connect the container... - nsCOMPtr webShell(do_QueryInterface(mDocShell)); - nsCOMPtr outerContainer = - do_QueryInterface(container); - - if (outerContainer) { - webShell->SetContainer(outerContainer); - } - - // Make sure all shells have links back to the content element - // in the nearest enclosing chrome shell. - nsCOMPtr chromeEventHandler; - - if (parentType == nsIDocShellTreeItem::typeChrome) { - // Our parent shell is a chrome shell. It is therefore our nearest - // enclosing chrome shell. - - chromeEventHandler = do_QueryInterface(mOwnerContent); - NS_WARN_IF_FALSE(chromeEventHandler, - "This mContent should implement this."); - } else { - nsCOMPtr parentShell(do_QueryInterface(parentAsNode)); - - // Our parent shell is a content shell. Get the chrome event - // handler from it and use that for our shell as well. - - parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler)); - } - - mDocShell->SetChromeEventHandler(chromeEventHandler); } - // This is nasty, this code (the do_GetInterface(mDocShell) below) - // *must* come *after* the above call to - // mDocShell->SetChromeEventHandler() for the global window to get - // the right chrome event handler. - - // Tell the window about the frame that hosts it. - nsCOMPtr frame_element(do_QueryInterface(mOwnerContent)); - NS_ASSERTION(frame_element, "frame loader owner element not a DOM element!"); - - nsCOMPtr win(do_GetInterface(mDocShell)); - nsCOMPtr win_private(do_QueryInterface(win)); - NS_ENSURE_TRUE(win_private, NS_ERROR_UNEXPECTED); - - win_private->SetFrameElementInternal(frame_element); - - nsCOMPtr base_win(do_QueryInterface(mDocShell)); - NS_ENSURE_TRUE(base_win, NS_ERROR_UNEXPECTED); - - // This is kinda whacky, this call doesn't really create anything, - // but it must be called to make sure things are properly - // initialized - - base_win->Create(); - return NS_OK; } -void -nsFrameLoader::GetURL(nsAString& aURI) +NS_IMETHODIMP +nsFrameLoader::OnStateChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aStateFlags, PRUint32 aStatus) { - aURI.Truncate(); + if (!((~aStateFlags) & (nsIWebProgressListener::STATE_IS_DOCUMENT | + nsIWebProgressListener::STATE_TRANSFERRING))) { + nsCOMPtr win(do_GetInterface(mDocShell)); + nsCOMPtr eventTarget(do_QueryInterface(win)); - nsCOMPtr type; - mOwnerContent->GetTag(*getter_AddRefs(type)); - - if (type == nsHTMLAtoms::object) { - mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::data, aURI); - } else { - mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, aURI); + if (eventTarget) { + eventTarget->AddEventListener(NS_LITERAL_STRING("load"), this, + PR_FALSE); + } } + + return NS_OK; +} + +NS_IMETHODIMP +nsFrameLoader::OnProgressChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsFrameLoader::OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsIURI *location) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsFrameLoader::OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsresult aStatus, + const PRUnichar *aMessage) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsFrameLoader::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, PRInt32 state) +{ + return NS_OK; } diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 5d3758df8f0..89d652f6549 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -1620,8 +1620,8 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, PRBool intermediateCapture = PR_FALSE; //Capturing stage evaluation - if (NS_EVENT_FLAG_BUBBLE != aFlags && aEvent->message != NS_PAGE_LOAD && - aEvent->message != NS_SCRIPT_LOAD && + if (NS_EVENT_FLAG_BUBBLE != aFlags && aEvent->message != NS_PAGE_LOAD + && aEvent->message != NS_SCRIPT_LOAD && aEvent->message != NS_IMAGE_ERROR && aEvent->message != NS_IMAGE_LOAD) { //Initiate capturing phase. Special case first call to document if (parent) { diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index c015fb4d281..e5b9a3b83ab 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -91,16 +91,15 @@ private: // objects for each of these instance variables, we put them off // in a side structure that's only allocated when the content is // accessed through the DOM. -struct nsDOMSlots -{ +typedef struct { nsChildContentList *mChildNodes; nsDOMCSSDeclaration *mStyle; nsDOMAttributeMap* mAttributeMap; nsVoidArray *mRangeList; nsIEventListenerManager* mListenerManager; - nsIContent* mBindingParent; // The nearest enclosing content node with a - // binding that created us. [Weak] -}; + nsIContent* mBindingParent; // The nearest enclosing content node with a binding + // that created us. [Weak] +} nsDOMSlots; class nsNode3Tearoff : public nsIDOM3Node diff --git a/content/build/nsContentDLF.cpp b/content/build/nsContentDLF.cpp index 98026f58e1d..5dbb7e3668c 100644 --- a/content/build/nsContentDLF.cpp +++ b/content/build/nsContentDLF.cpp @@ -416,8 +416,6 @@ nsContentDLF::CreateDocument(const char* aCommand, break; docv->SetUAStyleSheet(gUAStyleSheet); - doc->SetContainer(aContainer); - // Initialize the document to begin loading the data. An // nsIStreamListener connected to the parser is returned in // aDocListener. @@ -514,9 +512,6 @@ nsContentDLF::CreateRDFDocument(const char* aCommand, * An nsIStreamListener connected to the parser is returned in * aDocListener. */ - - doc->SetContainer(aContainer); - rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE); if (NS_SUCCEEDED(rv)) { /* diff --git a/content/build/nsContentModule.cpp b/content/build/nsContentModule.cpp index d56125bf1b6..730b123a1b8 100644 --- a/content/build/nsContentModule.cpp +++ b/content/build/nsContentModule.cpp @@ -97,7 +97,6 @@ #include "nsISelection.h" #include "nsITextContent.h" #include "nsIXBLService.h" -#include "nsIFrameLoader.h" #include "nsLayoutAtoms.h" #include "nsPlainTextSerializer.h" #include "nsRange.h" @@ -276,7 +275,6 @@ extern nsresult NS_NewXBLService(nsIXBLService** aResult); extern nsresult NS_NewBindingManager(nsIBindingManager** aResult); extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult); extern nsresult NS_NewContentPolicy(nsIContentPolicy** aResult); -extern nsresult NS_NewFrameLoader(nsIFrameLoader** aResult); #ifdef MOZ_XUL extern nsresult NS_NewXULElementFactory(nsIElementFactory** aResult); @@ -344,7 +342,6 @@ MAKE_CTOR(CreatePlainTextSerializer, nsIContentSerializer, NS_NewPla MAKE_CTOR(CreateXBLService, nsIXBLService, NS_NewXBLService) MAKE_CTOR(CreateBindingManager, nsIBindingManager, NS_NewBindingManager) MAKE_CTOR(CreateContentPolicy, nsIContentPolicy, NS_NewContentPolicy) -MAKE_CTOR(CreateFrameLoader, nsIFrameLoader, NS_NewFrameLoader) MAKE_CTOR(CreateNodeInfoManager, nsINodeInfoManager, NS_NewNodeInfoManager) MAKE_CTOR(CreateComputedDOMStyle, nsIComputedDOMStyle, NS_NewComputedDOMStyle) #ifdef MOZ_XUL @@ -731,11 +728,6 @@ static const nsModuleComponentInfo gComponents[] = { NS_CONTENTPOLICY_CONTRACTID, CreateContentPolicy }, - { "Frame Loader", - NS_FRAMELOADER_CID, - NS_FRAMELOADER_CONTRACTID, - CreateFrameLoader }, - { "NodeInfoManager", NS_NODEINFOMANAGER_CID, NS_NODEINFOMANAGER_CONTRACTID, diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index c271e77053b..552e27b4605 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1531,36 +1531,39 @@ nsEventStateManager::GetParentScrollingView(nsMouseScrollEvent *aEvent, { if (!aEvent) return NS_ERROR_FAILURE; if (!aPresContext) return NS_ERROR_FAILURE; + + nsCOMPtr shell; + aPresContext->GetContainer(getter_AddRefs(shell)); + if (!shell) return NS_ERROR_FAILURE; + + nsCOMPtr treeItem = do_QueryInterface(shell); + if (!treeItem) return NS_ERROR_FAILURE; - nsCOMPtr doc; - - { - nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); - NS_ASSERTION(presShell, "No presshell in prescontext!"); - - presShell->GetDocument(getter_AddRefs(doc)); - } - - NS_ASSERTION(doc, "No document in prescontext!"); - - nsCOMPtr parentDoc; - doc->GetParentDocument(getter_AddRefs(parentDoc)); - - if (!parentDoc) { - return NS_OK; - } + /* get our docshell's parent */ + nsCOMPtr parent; + treeItem->GetParent(getter_AddRefs(parent)); + if (!parent) return NS_ERROR_FAILURE; + + nsCOMPtr pDocShell = do_QueryInterface(parent); + if (!pDocShell) return NS_ERROR_FAILURE; nsCOMPtr pPresShell; - parentDoc->GetShellAt(0, getter_AddRefs(pPresShell)); - NS_ENSURE_TRUE(pPresShell, NS_ERROR_FAILURE); + pDocShell->GetPresShell(getter_AddRefs(pPresShell)); + if (!pPresShell) return NS_ERROR_FAILURE; - /* now find the content node in our parent docshell's document that - corresponds to our docshell */ + nsCOMPtr parentDoc; + pPresShell->GetDocument(getter_AddRefs(parentDoc)); + + nsCOMPtr rootContent; + parentDoc->GetRootContent(getter_AddRefs(rootContent)); + + nsCOMPtr ourDS = do_QueryInterface(shell); + + /* now find the content node in our parent docshell's document that corresponds + to our docshell */ nsCOMPtr frameContent; - - parentDoc->FindContentForSubDocument(doc, getter_AddRefs(frameContent)); - NS_ENSURE_TRUE(frameContent, NS_ERROR_FAILURE); + pPresShell->FindContentForShell(ourDS, getter_AddRefs(frameContent)); + if (!frameContent) return NS_ERROR_FAILURE; /* get this content node's frame, and use it as the new event target, @@ -1568,7 +1571,6 @@ nsEventStateManager::GetParentScrollingView(nsMouseScrollEvent *aEvent, Note that we don't actually need to translate the event coordinates because they are not used by DoWheelScroll(). */ - nsIFrame* frameFrame = nsnull; pPresShell->GetPrimaryFrameFor(frameContent, &frameFrame); if (!frameFrame) return NS_ERROR_FAILURE; @@ -2743,7 +2745,7 @@ nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart) nsCOMPtr pcContainer; mPresContext->GetContainer(getter_AddRefs(pcContainer)); NS_ASSERTION(pcContainer, "no container for presContext"); - + nsCOMPtr docShell(do_QueryInterface(pcContainer)); PRBool docHasFocus = PR_FALSE; @@ -2836,32 +2838,19 @@ nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart) // Check to see if the next focused element has a subshell. // This is the case for an IFRAME or FRAME element. If it // does, we send focus into the subshell. + nsCOMPtr shellObject; + presShell->GetSubShellFor(nextFocus, getter_AddRefs(shellObject)); + if (shellObject) { + nsCOMPtr subShell = do_QueryInterface(shellObject); + if (subShell) { + SetContentState(nsnull, NS_EVENT_STATE_FOCUS); - nsCOMPtr sub_shell; - - nsCOMPtr doc, sub_doc; - nextFocus->GetDocument(*getter_AddRefs(doc)); - - if (doc) { - doc->GetSubDocumentFor(nextFocus, getter_AddRefs(sub_doc)); - - if (sub_doc) { - nsCOMPtr container; - sub_doc->GetContainer(getter_AddRefs(container)); - - sub_shell = do_QueryInterface(container); + nsIFrame* nextFocusFrame = nsnull; + presShell->GetPrimaryFrameFor(nextFocus, &nextFocusFrame); + presShell->ScrollFrameIntoView(nextFocusFrame, NS_PRESSHELL_SCROLL_ANYWHERE, + NS_PRESSHELL_SCROLL_ANYWHERE); + TabIntoDocument(subShell, aForward); } - } - - if (sub_shell) { - SetContentState(nsnull, NS_EVENT_STATE_FOCUS); - - nsIFrame* nextFocusFrame = nsnull; - presShell->GetPrimaryFrameFor(nextFocus, &nextFocusFrame); - presShell->ScrollFrameIntoView(nextFocusFrame, - NS_PRESSHELL_SCROLL_ANYWHERE, - NS_PRESSHELL_SCROLL_ANYWHERE); - TabIntoDocument(sub_shell, aForward); } else { // there is no subshell, so just focus nextFocus #ifdef DEBUG_DOCSHELL_FOCUS @@ -2938,28 +2927,23 @@ nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart) if (parentDS) { nsCOMPtr parentShell; parentDS->GetPresShell(getter_AddRefs(parentShell)); - - nsCOMPtr docContent; - nsCOMPtr parent_doc; - - parentShell->GetDocument(getter_AddRefs(parent_doc)); - - parent_doc->FindContentForSubDocument(mDocument, - getter_AddRefs(docContent)); - + + nsCOMPtr shellContent; + parentShell->FindContentForShell(docShell, getter_AddRefs(shellContent)); + nsCOMPtr parentPC; parentShell->GetPresContext(getter_AddRefs(parentPC)); - + nsCOMPtr parentESM; parentPC->GetEventStateManager(getter_AddRefs(parentESM)); - + SetContentState(nsnull, NS_EVENT_STATE_FOCUS); #ifdef DEBUG_DOCSHELL_FOCUS printf("popping out focus to parent docshell\n"); #endif parentESM->MoveCaretToFocus(); - parentESM->ShiftFocus(aForward, docContent); + parentESM->ShiftFocus(aForward, shellContent); } } else { PRBool tookFocus = PR_FALSE; @@ -4663,14 +4647,6 @@ PRBool nsEventStateManager::IsIFrameDoc(nsIDocShell* aDocShell) { NS_ASSERTION(aDocShell, "docshell is null"); - - nsCOMPtr presShell; - aDocShell->GetPresShell(getter_AddRefs(presShell)); - - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc, "No document in presshell!"); - nsCOMPtr treeItem = do_QueryInterface(aDocShell); nsCOMPtr parentItem; treeItem->GetParent(getter_AddRefs(parentItem)); @@ -4678,17 +4654,12 @@ nsEventStateManager::IsIFrameDoc(nsIDocShell* aDocShell) return PR_FALSE; nsCOMPtr parentDS = do_QueryInterface(parentItem); - nsCOMPtr parentPresShell; - parentDS->GetPresShell(getter_AddRefs(parentPresShell)); - NS_ASSERTION(parentPresShell, "presshell is null"); - - nsCOMPtr parentDoc; - parentPresShell->GetDocument(getter_AddRefs(parentDoc)); - + nsCOMPtr parentShell; + parentDS->GetPresShell(getter_AddRefs(parentShell)); + NS_ASSERTION(parentShell, "presshell is null"); + nsCOMPtr docContent; - - parentDoc->FindContentForSubDocument(doc, getter_AddRefs(docContent)); - + parentShell->FindContentForShell(aDocShell, getter_AddRefs(docContent)); if (!docContent) return PR_FALSE; diff --git a/content/html/content/src/makefile.win b/content/html/content/src/makefile.win index 5d4fe888565..48fe2267239 100644 --- a/content/html/content/src/makefile.win +++ b/content/html/content/src/makefile.win @@ -32,10 +32,10 @@ REQUIRES = xpcom \ webshell \ htmlparser \ necko \ + uriloader \ view \ pref \ docshell \ - uriloader \ xpconnect \ caps \ editor \ diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index dd7e810891a..05f6ed48178 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -2335,12 +2335,12 @@ nsGenericHTMLElement::GetBaseURL(const nsHTMLValue& aBaseHref, baseHref.Trim(" \t\n\r"); nsIURI* url = nsnull; - result = NS_NewURI(&url, baseHref, nsnull, docBaseURL); - + { + result = NS_NewURI(&url, baseHref, nsnull, docBaseURL); + } NS_IF_RELEASE(docBaseURL); *aBaseURL = url; } - return result; } @@ -4575,6 +4575,32 @@ nsGenericHTMLElement::SetElementFocus(PRBool aDoFocus) return RemoveFocus(presContext); } +nsresult +nsGenericHTMLElement::HandleFrameOnloadEvent(nsIDOMEvent* aEvent) +{ + NS_ENSURE_TRUE(aEvent, NS_OK); + + nsAutoString type; + aEvent->GetType(type); + + if (!type.EqualsIgnoreCase("load")) { + return NS_OK; + } + + nsCOMPtr ctx; + + GetPresContext(this, getter_AddRefs(ctx)); + NS_ENSURE_TRUE(ctx, NS_OK); + + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + + event.eventStructType = NS_EVENT; + event.message = NS_PAGE_LOAD; + + return HandleDOMEvent(ctx, &event, nsnull, NS_EVENT_FLAG_INIT, &status); +} + // static nsresult nsGenericHTMLElement::SetProtocolInHrefString(const nsAString &aHref, diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 204ebf84274..f9bd9042635 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -465,6 +465,8 @@ public: protected: nsresult SetElementFocus(PRBool aDoFocus); + nsresult HandleFrameOnloadEvent(nsIDOMEvent* aEvent); + PRBool IsEventName(nsIAtom* aName); }; diff --git a/content/html/content/src/nsHTMLFrameElement.cpp b/content/html/content/src/nsHTMLFrameElement.cpp index f517094295c..53af3188dc0 100644 --- a/content/html/content/src/nsHTMLFrameElement.cpp +++ b/content/html/content/src/nsHTMLFrameElement.cpp @@ -37,6 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMNSHTMLFrameElement.h" +#include "nsIDOMEventListener.h" #include "nsIDOMEventReceiver.h" #include "nsIDOMWindow.h" #include "nsIScriptGlobalObject.h" @@ -48,14 +49,14 @@ #include "nsIDOMDocument.h" #include "nsIWebNavigation.h" #include "nsIChromeEventHandler.h" -#include "nsIDocShell.h" #include "nsDOMError.h" class nsHTMLFrameElement : public nsGenericHTMLLeafElement, public nsIDOMHTMLFrameElement, public nsIDOMNSHTMLFrameElement, - public nsIChromeEventHandler + public nsIChromeEventHandler, + public nsIDOMEventListener { public: nsHTMLFrameElement(); @@ -82,6 +83,9 @@ public: // nsIChromeEventHandler NS_DECL_NSICHROMEEVENTHANDLER + // nsIDOMEventListener + NS_DECL_NSIDOMEVENTLISTENER + NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAString& aValue, nsHTMLValue& aResult); @@ -139,6 +143,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFrameElement, NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFrameElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement) NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFrameElement) NS_HTML_CONTENT_INTERFACE_MAP_END @@ -186,21 +191,33 @@ NS_IMETHODIMP nsHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument) { NS_ENSURE_ARG_POINTER(aContentDocument); + *aContentDocument = nsnull; - if (!mDocument) { - return NS_OK; - } + NS_ENSURE_TRUE(mDocument, NS_OK); - nsCOMPtr content_document; + nsCOMPtr presShell; - mDocument->GetSubDocumentFor(this, getter_AddRefs(content_document)); + mDocument->GetShellAt(0, getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_OK); - if (!content_document) { - return NS_OK; - } + nsCOMPtr tmp; - return CallQueryInterface(content_document, aContentDocument); + presShell->GetSubShellFor(this, getter_AddRefs(tmp)); + NS_ENSURE_TRUE(tmp, NS_OK); + + nsCOMPtr webNav = do_QueryInterface(tmp); + NS_ENSURE_TRUE(webNav, NS_OK); + + nsCOMPtr domDoc; + + webNav->GetDocument(getter_AddRefs(domDoc)); + + *aContentDocument = domDoc; + + NS_IF_ADDREF(*aContentDocument); + + return NS_OK; } NS_IMETHODIMP @@ -312,3 +329,8 @@ nsHTMLFrameElement::HandleChromeEvent(nsIPresContext* aPresContext, return HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags,aEventStatus); } +nsresult +nsHTMLFrameElement::HandleEvent(nsIDOMEvent *aEvent) +{ + return HandleFrameOnloadEvent(aEvent); +} diff --git a/content/html/content/src/nsHTMLIFrameElement.cpp b/content/html/content/src/nsHTMLIFrameElement.cpp index 7fb5d1daa2f..161391af067 100644 --- a/content/html/content/src/nsHTMLIFrameElement.cpp +++ b/content/html/content/src/nsHTMLIFrameElement.cpp @@ -37,10 +37,11 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIDOMHTMLIFrameElement.h" #include "nsIDOMNSHTMLFrameElement.h" +#include "nsIDOMEventListener.h" #include "nsIDOMEventReceiver.h" #include "nsIDOMWindow.h" #include "nsIScriptGlobalObject.h" -#include "nsIFrameLoader.h" +#include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsIStyleContext.h" @@ -53,14 +54,12 @@ #include "nsIChromeEventHandler.h" #include "nsDOMError.h" #include "nsRuleNode.h" -#include "nsIDocShell.h" -#include "nsIInterfaceRequestorUtils.h" class nsHTMLIFrameElement : public nsGenericHTMLContainerElement, public nsIDOMHTMLIFrameElement, public nsIDOMNSHTMLFrameElement, public nsIChromeEventHandler, - public nsIFrameLoaderOwner + public nsIDOMEventListener { public: nsHTMLIFrameElement(); @@ -87,11 +86,8 @@ public: // nsIChromeEventHandler NS_DECL_NSICHROMEEVENTHANDLER - // nsIFrameLoaderOwner - NS_IMETHOD GetFrameLoader(nsIFrameLoader **aFrameLoader); - - // nsIContent - NS_IMETHOD SetParent(nsIContent *aParent); + // nsIDOMEventListener + NS_DECL_NSIDOMEVENTLISTENER NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAString& aValue, @@ -105,14 +101,6 @@ public: #ifdef DEBUG NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; #endif - -protected: - // This doesn't really ensure a frame loade in all cases, only when - // it makes sense. - nsresult EnsureFrameLoader(); - nsresult LoadSrc(); - - nsCOMPtr mFrameLoader; }; nsresult @@ -148,9 +136,6 @@ nsHTMLIFrameElement::nsHTMLIFrameElement() nsHTMLIFrameElement::~nsHTMLIFrameElement() { - if (mFrameLoader) { - mFrameLoader->Destroy(); - } } @@ -163,7 +148,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLIFrameElement, NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLIFrameElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement) NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler) - NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLIFrameElement) NS_HTML_CONTENT_INTERFACE_MAP_END @@ -204,123 +189,71 @@ NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight) NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth) NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name) NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling) +NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Src, src) NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width) -NS_IMETHODIMP -nsHTMLIFrameElement::GetSrc(nsAString& aSrc) -{ - nsGenericHTMLContainerElement::GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, - aSrc); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLIFrameElement::SetSrc(const nsAString& aSrc) -{ - SetAttribute(NS_LITERAL_STRING("src"), aSrc); - - return LoadSrc(); -} NS_IMETHODIMP nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument) { NS_ENSURE_ARG_POINTER(aContentDocument); + *aContentDocument = nsnull; - nsresult rv = EnsureFrameLoader(); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(mDocument, NS_OK); - if (!mFrameLoader) { - return NS_OK; - } + nsCOMPtr presShell; - nsCOMPtr doc_shell; - mFrameLoader->GetDocShell(getter_AddRefs(doc_shell)); + mDocument->GetShellAt(0, getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_OK); - nsCOMPtr win(do_GetInterface(doc_shell)); + nsCOMPtr tmp; - if (!win) { - return NS_OK; - } + presShell->GetSubShellFor(this, getter_AddRefs(tmp)); + NS_ENSURE_TRUE(tmp, NS_OK); - return win->GetDocument(aContentDocument); + nsCOMPtr webNav = do_QueryInterface(tmp); + NS_ENSURE_TRUE(webNav, NS_OK); + + nsCOMPtr domDoc; + + webNav->GetDocument(getter_AddRefs(domDoc)); + + *aContentDocument = domDoc; + + NS_IF_ADDREF(*aContentDocument); + + return NS_OK; } NS_IMETHODIMP nsHTMLIFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow) { NS_ENSURE_ARG_POINTER(aContentWindow); + *aContentWindow = nsnull; - nsresult rv = EnsureFrameLoader(); + nsCOMPtr content_doc; + + nsresult rv = GetContentDocument(getter_AddRefs(content_doc)); NS_ENSURE_SUCCESS(rv, rv); - if (!mFrameLoader) { + nsCOMPtr doc(do_QueryInterface(content_doc)); + + if (!doc) { return NS_OK; } - nsCOMPtr doc_shell; - mFrameLoader->GetDocShell(getter_AddRefs(doc_shell)); + nsCOMPtr globalObj; + doc->GetScriptGlobalObject(getter_AddRefs(globalObj)); - nsCOMPtr win(do_GetInterface(doc_shell)); + nsCOMPtr window (do_QueryInterface(globalObj)); - *aContentWindow = win; + *aContentWindow = window; NS_IF_ADDREF(*aContentWindow); return NS_OK; } -nsresult -nsHTMLIFrameElement::EnsureFrameLoader() -{ - if (mFrameLoader || !mParent) { - return NS_OK; - } - - nsresult rv = NS_NewFrameLoader(getter_AddRefs(mFrameLoader)); - NS_ENSURE_SUCCESS(rv, rv); - - mFrameLoader->Init(this); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLIFrameElement::GetFrameLoader(nsIFrameLoader **aFrameLoader) -{ - *aFrameLoader = mFrameLoader; - NS_IF_ADDREF(*aFrameLoader); - - return NS_OK; -} - -nsresult -nsHTMLIFrameElement::LoadSrc() -{ - nsresult rv = EnsureFrameLoader(); - NS_ENSURE_SUCCESS(rv, rv); - - if (!mFrameLoader) { - return NS_OK; - } - - rv = mFrameLoader->LoadFrame(); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL"); - - return rv; -} - - -NS_IMETHODIMP -nsHTMLIFrameElement::SetParent(nsIContent *aParent) -{ - nsresult rv = nsGenericHTMLContainerElement::SetParent(aParent); - NS_ENSURE_SUCCESS(rv, rv); - - return LoadSrc(); -} - NS_IMETHODIMP nsHTMLIFrameElement::StringToAttribute(nsIAtom* aAttribute, const nsAString& aValue, @@ -433,7 +366,7 @@ MapAttributesIntoRule(const nsIHTMLMappedAttributes* aAttributes, if (aData->mPositionData->mHeight.GetUnit() == eCSSUnit_Null) { aAttributes->GetAttribute(nsHTMLAtoms::height, value); if (value.GetUnit() == eHTMLUnit_Pixel) - aData->mPositionData->mHeight.SetFloatValue((float)value.GetPixelValue(), eCSSUnit_Pixel); + aData->mPositionData->mHeight.SetFloatValue((float)value.GetPixelValue(), eCSSUnit_Pixel); else if (value.GetUnit() == eHTMLUnit_Percent) aData->mPositionData->mHeight.SetPercentValue(value.GetPercentValue()); } @@ -444,8 +377,7 @@ MapAttributesIntoRule(const nsIHTMLMappedAttributes* aAttributes, } NS_IMETHODIMP -nsHTMLIFrameElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, - PRInt32 aModType, +nsHTMLIFrameElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, PRInt32 aModType, PRInt32& aHint) const { if ((aAttribute == nsHTMLAtoms::width) || @@ -487,15 +419,20 @@ nsHTMLIFrameElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const //***************************************************************************** // nsHTMLIFrameElement::nsIChromeEventHandler -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP nsHTMLIFrameElement::HandleChromeEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, + PRUint32 aFlags, nsEventStatus* aEventStatus) { return HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags,aEventStatus); } +nsresult +nsHTMLIFrameElement::HandleEvent(nsIDOMEvent *aEvent) +{ + return HandleFrameOnloadEvent(aEvent); +} diff --git a/content/html/content/src/nsHTMLObjectElement.cpp b/content/html/content/src/nsHTMLObjectElement.cpp index 898df0ab117..27aa9de2798 100644 --- a/content/html/content/src/nsHTMLObjectElement.cpp +++ b/content/html/content/src/nsHTMLObjectElement.cpp @@ -190,18 +190,30 @@ nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument) *aContentDocument = nsnull; - if (!mDocument) { - return NS_OK; - } + NS_ENSURE_TRUE(mDocument, NS_OK); - nsCOMPtr sub_doc; - mDocument->GetSubDocumentFor(this, getter_AddRefs(sub_doc)); + nsCOMPtr presShell; - if (!sub_doc) { - return NS_OK; - } + mDocument->GetShellAt(0, getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_OK); - return CallQueryInterface(sub_doc, aContentDocument); + nsCOMPtr tmp; + + presShell->GetSubShellFor(this, getter_AddRefs(tmp)); + if (!tmp) return NS_OK; + + nsCOMPtr webNav = do_QueryInterface(tmp); + NS_ENSURE_TRUE(webNav, NS_OK); + + nsCOMPtr domDoc; + + webNav->GetDocument(getter_AddRefs(domDoc)); + + *aContentDocument = domDoc; + + NS_IF_ADDREF(*aContentDocument); + + return NS_OK; } NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp index 898df0ab117..27aa9de2798 100644 --- a/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -190,18 +190,30 @@ nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument) *aContentDocument = nsnull; - if (!mDocument) { - return NS_OK; - } + NS_ENSURE_TRUE(mDocument, NS_OK); - nsCOMPtr sub_doc; - mDocument->GetSubDocumentFor(this, getter_AddRefs(sub_doc)); + nsCOMPtr presShell; - if (!sub_doc) { - return NS_OK; - } + mDocument->GetShellAt(0, getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_OK); - return CallQueryInterface(sub_doc, aContentDocument); + nsCOMPtr tmp; + + presShell->GetSubShellFor(this, getter_AddRefs(tmp)); + if (!tmp) return NS_OK; + + nsCOMPtr webNav = do_QueryInterface(tmp); + NS_ENSURE_TRUE(webNav, NS_OK); + + nsCOMPtr domDoc; + + webNav->GetDocument(getter_AddRefs(domDoc)); + + *aContentDocument = domDoc; + + NS_IF_ADDREF(*aContentDocument); + + return NS_OK; } NS_IMETHODIMP diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 9a990bf71c4..c4a2b63a701 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -1503,7 +1503,7 @@ SinkContext::CloseContainer(const nsIParserNode& aNode) // Flush any collected text content. Release the last text // node to indicate that no more should be added to it. FlushTextAndRelease(); - + SINK_TRACE_NODE(SINK_TRACE_CALLS, "SinkContext::CloseContainer", aNode, mStackPos-1, mSink); @@ -1604,8 +1604,7 @@ SinkContext::CloseContainer(const nsIParserNode& aNode) case eHTMLTag_select: { - nsCOMPtr select = do_QueryInterface(content); - + nsCOMPtr select = do_QueryInterface(content, &result); if (select) { result = select->DoneAddingChildren(); } @@ -3815,57 +3814,43 @@ HTMLContentSink::DidProcessAToken(void) PRInt32 oldMaxTokenProcessingTime = GetMaxTokenProcessingTime(); #endif - // There is both a high frequency interrupt mode and a low - // frequency interupt mode controlled by the flag - // NS_SINK_FLAG_DYNAMIC_LOWER_VALUE The high frequency mode - // interupts the parser frequently to provide UI responsiveness at - // the expense of page load time. The low frequency mode - // interrupts the parser and samples the system clock infrequently - // to provide fast page load time. When the user moves the mouse, - // clicks or types the mode switches to the high frequency - // interrupt mode. If the user stops moving the mouse or typing - // for a duration of time (mDynamicIntervalSwitchThreshold) it - // switches to low frequency interrupt mode. + // There is both a high frequency interrupt mode and a low frequency + // interupt mode controlled by the flag NS_SINK_FLAG_DYNAMIC_LOWER_VALUE + // The high frequency mode interupts the parser frequently to provide + // UI responsiveness at the expense of page load time. The low frequency mode + // interrupts the parser and samples the system clock infrequently to provide fast + // page load time. When the user moves the mouse, clicks or types the mode switches + // to the high frequency interrupt mode. If the user stops moving the mouse or typing + // for a duration of time (mDynamicIntervalSwitchThreshold) it switches to low + // frequency interrupt mode. // Get the current user event time nsCOMPtr shell; mDocument->GetShellAt(0, getter_AddRefs(shell)); - - if (!shell) { - // If there's no pres shell in the document, return early since - // we're not laying anything out here. - - return NS_OK; - } - + NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE); nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); PRUint32 eventTime; nsresult rv = vm->GetLastUserEventTime(eventTime); NS_ENSURE_TRUE(NS_SUCCEEDED(rv), NS_ERROR_FAILURE); + if ((!(mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE)) && (mLastSampledUserEventTime == eventTime)) { - // The magic value of NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE - // was selected by empirical testing. It provides reasonable - // user response and prevents us from sampling the clock too - // frequently. + // The magic value of NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE was selected by + // empirical testing. It provides reasonable + // user response and prevents us from sampling the clock too frequently. if (mDeflectedCount < NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE) { mDeflectedCount++; - - // return early to prevent sampling the clock. Note: This - // prevents us from switching to higher frequency (better UI - // responsive) mode, so limit ourselves to doing for no more - // than NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE tokens. - - return NS_OK; + return NS_OK; // return early to prevent sampling the clock. Note: This prevents + // us from switching to higher frequency (better UI responsive) mode, so + // limit ourselves to doing for no more than + // NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE tokens. } else { - // reset count and drop through to the code which samples the - // clock and does the dynamic switch between the high - // frequency and low frequency interruption of the parser. - - mDeflectedCount = 0; + mDeflectedCount = 0; // reset count and drop through to the code which samples the clock and + // does the dynamic switch between the high frequency and low frequency + // interruption of the parser. } } @@ -3873,49 +3858,48 @@ PRInt32 oldMaxTokenProcessingTime = GetMaxTokenProcessingTime(); PRUint32 currentTime = PR_IntervalToMicroseconds(PR_IntervalNow()); - // Get the last user event time and compare it with the current - // time to determine if the lower value for content notification - // and max token processing should be used. But only consider - // using the lower value if the document has already been loading - // for 2 seconds. 2 seconds was chosen because it is greater than - // the default 3/4 of second that is used to determine when to - // switch between the modes and it gives the document a little - // time to create windows. This is important because on some - // systems (Windows, for example) when a window is created and the - // mouse is over it, a mouse move event is sent, which will kick - // us into interactive mode otherwise. It also supresses reaction - // to pressing the ENTER key in the URL bar... + // Get the last user event time and compare it with + // the current time to determine if the lower value + // for content notification and max token processing + // should be used. But only consider using the lower + // value if the document has already been loading + // for 2 seconds. 2 seconds was chosen because it is + // greater than the default 3/4 of second that is used + // to determine when to switch between the modes and it + // gives the document a little time to create windows. + // This is important because on some systems (Windows, + // for example) when a window is created and the mouse + // is over it, a mouse move event is sent, which will kick + // us into interactive mode otherwise. It also supresses + // reaction to pressing the ENTER key in the URL bar... PRUint32 delayBeforeLoweringThreshold = NS_STATIC_CAST(PRUint32, ((2 * mDynamicIntervalSwitchThreshold) + NS_DELAY_FOR_WINDOW_CREATION)); - - if ((currentTime - mBeginLoadTime) > delayBeforeLoweringThreshold) { - if ((currentTime - eventTime) < - NS_STATIC_CAST(PRUint32, mDynamicIntervalSwitchThreshold)) { - // lower the dynamic values to favor application - // responsiveness over page load time. - - mFlags |= NS_SINK_FLAG_DYNAMIC_LOWER_VALUE; - } else { - // raise the content notification and MaxTokenProcessing time - // to favor overall page load speed over responsiveness - - mFlags &= ~NS_SINK_FLAG_DYNAMIC_LOWER_VALUE; + if (((currentTime - mBeginLoadTime) > delayBeforeLoweringThreshold) && mDocument) { + if ((currentTime - eventTime) < NS_STATIC_CAST(PRUint32, mDynamicIntervalSwitchThreshold)) { + // lower the dynamic values to favor + // application responsiveness over page load + // time. + mFlags |= NS_SINK_FLAG_DYNAMIC_LOWER_VALUE; + } + else { + // raise the content notification and + // MaxTokenProcessing time to favor overall + // page load speed over responsiveness + mFlags &= ~NS_SINK_FLAG_DYNAMIC_LOWER_VALUE; } } #ifdef NS_DEBUG - PRInt32 newMaxTokenProcessingTime = GetMaxTokenProcessingTime(); +PRInt32 newMaxTokenProcessingTime = GetMaxTokenProcessingTime(); - if (newMaxTokenProcessingTime != oldMaxTokenProcessingTime) { -// printf("Changed dynamic interval : MaxTokenProcessingTime %d\n", -// GetMaxTokenProcessingTime()); - } + if (newMaxTokenProcessingTime != oldMaxTokenProcessingTime) { +// printf("Changed dynamic interval : MaxTokenProcessingTime %d\n", GetMaxTokenProcessingTime()); + } #endif - if ((currentTime - mDelayTimerStart) > - NS_STATIC_CAST(PRUint32, GetMaxTokenProcessingTime())) { - return NS_ERROR_HTMLPARSER_INTERRUPTED; - } + if ((currentTime - mDelayTimerStart) > NS_STATIC_CAST(PRUint32, GetMaxTokenProcessingTime())) { + return NS_ERROR_HTMLPARSER_INTERRUPTED; + } } return NS_OK; @@ -4162,7 +4146,7 @@ nsresult HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) { nsresult rv = NS_OK; - if (mCurrentMap) { + if (nsnull != mCurrentMap) { nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); nsIHTMLContent* area; rv = CreateContentObject(aNode, nodeType, nsnull, nsnull, &area); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index e7c9c1682c1..5351bc9e9f8 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1477,7 +1477,7 @@ nsHTMLDocument::FlushPendingNotifications(PRBool aFlushReflows, } } - if (isSafeToFlush && mParser) { + if ((isSafeToFlush) && (mParser)) { nsCOMPtr sink; // XXX Ack! Parser doesn't addref sink before passing it back @@ -3750,33 +3750,34 @@ nsHTMLDocument::ResolveName(const nsAString& aName, PRBool nsHTMLDocument::GetBodyContent() { - nsCOMPtr root; + nsCOMPtr root; - GetRootContent(getter_AddRefs(root)); + GetDocumentElement(getter_AddRefs(root)); if (!root) { return PR_FALSE; } - PRInt32 i, child_count; - root->ChildCount(child_count); + NS_NAMED_LITERAL_STRING(bodyStr, "BODY"); + nsCOMPtr child; + root->GetFirstChild(getter_AddRefs(child)); - for (i = 0; i < child_count; i++) { - nsCOMPtr child; + while (child) { + nsCOMPtr domElement(do_QueryInterface(child)); - root->ChildAt(i, *getter_AddRefs(child)); - NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED); + if (domElement) { + nsAutoString tagName; + domElement->GetTagName(tagName); - nsCOMPtr ni; - child->GetNodeInfo(*getter_AddRefs(ni)); + ToUpperCase(tagName); + if (bodyStr.Equals(tagName)) { + mBodyContent = child; - if (ni && ni->Equals(nsHTMLAtoms::body) && - (ni->NamespaceEquals(kNameSpaceID_None) || - ni->NamespaceEquals(kNameSpaceID_HTML))) { - mBodyContent = do_QueryInterface(child); - - return PR_TRUE; + return PR_TRUE; + } } + nsIDOMNode *tmpNode = child; + tmpNode->GetNextSibling(getter_AddRefs(child)); } return PR_FALSE; diff --git a/content/html/style/src/nsCSSStyleSheet.cpp b/content/html/style/src/nsCSSStyleSheet.cpp index 264fc37440e..0bdc6d98e1f 100644 --- a/content/html/style/src/nsCSSStyleSheet.cpp +++ b/content/html/style/src/nsCSSStyleSheet.cpp @@ -2657,7 +2657,7 @@ CSSStyleSheetImpl::SetDisabled(PRBool aDisabled) PRBool oldState = mDisabled; mDisabled = aDisabled; - if (mDocument && (mDisabled != oldState)) { + if ((nsnull != mDocument) && (mDisabled != oldState)) { mDocument->SetStyleSheetDisabledState(this, mDisabled); } diff --git a/content/macbuild/content.xml b/content/macbuild/content.xml index 755f6ba7cb6..e9e8b57a950 100644 --- a/content/macbuild/content.xml +++ b/content/macbuild/content.xml @@ -2310,13 +2310,6 @@ Text Debug - - Name - nsFrameLoader.cpp - MacOS - Text - Debug - Name UnicharUtilsStatic.o @@ -3452,11 +3445,6 @@ nsContentAreaDragDrop.cpp MacOS - - Name - nsFrameLoader.cpp - MacOS - Name UnicharUtilsStatic.o @@ -5811,13 +5799,6 @@ Text Debug - - Name - nsFrameLoader.cpp - MacOS - Text - Debug - Name UnicharUtilsStaticDebug.o @@ -6953,11 +6934,6 @@ nsContentAreaDragDrop.cpp MacOS - - Name - nsFrameLoader.cpp - MacOS - Name UnicharUtilsStaticDebug.o @@ -7286,12 +7262,6 @@ nsContentAreaDragDrop.cpp MacOS - - content.shlb - Name - nsFrameLoader.cpp - MacOS - build diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 881cc60d8c6..ce5e26270ca 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -445,8 +445,6 @@ nsXULDocument::nsXULDocument(void) #ifdef IBMBIDI mBidiEnabled = PR_FALSE; #endif // IBMBIDI - - mSubDocuments = nsnull; } nsIFastLoadService* nsXULDocument::gFastLoadService = nsnull; @@ -474,11 +472,14 @@ nsXULDocument::~nsXULDocument() observer->DocumentWillBeDestroyed(this); } - // Delete references to sub-documents and kill the subdocument map, - // if any. It holds strong references - if (mSubDocuments) { - PL_DHashTableDestroy(mSubDocuments); - mSubDocuments = nsnull; + // mParentDocument is never refcounted + // Delete references to sub-documents + { + i = mSubDocuments.Count(); + while (--i >= 0) { + nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(i); + NS_RELEASE(subdoc); + } } // Delete references to style sheets but only if we aren't a popup document. @@ -525,8 +526,7 @@ nsXULDocument::~nsXULDocument() NS_IF_RELEASE(gXMLElementFactory); if (gNameSpaceManager) { - nsServiceManager::ReleaseService(kNameSpaceManagerCID, - gNameSpaceManager); + nsServiceManager::ReleaseService(kNameSpaceManagerCID, gNameSpaceManager); gNameSpaceManager = nsnull; } @@ -1122,154 +1122,27 @@ nsXULDocument::SetParentDocument(nsIDocument* aParent) return NS_OK; } -PR_STATIC_CALLBACK(void) -SubDocClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry) -{ - SubDocMapEntry *e = NS_STATIC_CAST(SubDocMapEntry *, entry); - - NS_RELEASE(e->mKey); - NS_IF_RELEASE(e->mSubDocument); -} - -PR_STATIC_CALLBACK(void) -SubDocInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key) -{ - SubDocMapEntry *e = - NS_CONST_CAST(SubDocMapEntry *, - NS_STATIC_CAST(const SubDocMapEntry *, entry)); - - e->mKey = NS_CONST_CAST(nsIContent *, - NS_STATIC_CAST(const nsIContent *, key)); - NS_ADDREF(e->mKey); - - e->mSubDocument = nsnull; -} - NS_IMETHODIMP -nsXULDocument::SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc) +nsXULDocument::AddSubDocument(nsIDocument* aSubDoc) { - NS_ENSURE_TRUE(aContent, NS_ERROR_UNEXPECTED); - - if (!aSubDoc) { - // aSubDoc is nsnull, remove the mapping - - if (mSubDocuments) { - SubDocMapEntry *entry = - NS_STATIC_CAST(SubDocMapEntry*, - PL_DHashTableOperate(mSubDocuments, aContent, - PL_DHASH_LOOKUP)); - - if (PL_DHASH_ENTRY_IS_LIVE(entry)) { - entry->mSubDocument->SetParentDocument(nsnull); - - PL_DHashTableRawRemove(mSubDocuments, entry); - } - } - } else { - if (!mSubDocuments) { - // Create a new hashtable - - static PLDHashTableOps hash_table_ops = - { - PL_DHashAllocTable, - PL_DHashFreeTable, - PL_DHashGetKeyStub, - PL_DHashVoidPtrKeyStub, - PL_DHashMatchEntryStub, - PL_DHashMoveEntryStub, - SubDocClearEntry, - PL_DHashFinalizeStub, - SubDocInitEntry - }; - - mSubDocuments = PL_NewDHashTable(&hash_table_ops, nsnull, - sizeof(SubDocMapEntry), 16); - if (!mSubDocuments) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - - // Add a mapping to the hash table - SubDocMapEntry *entry = - NS_STATIC_CAST(SubDocMapEntry*, - PL_DHashTableOperate(mSubDocuments, aContent, - PL_DHASH_ADD)); - - if (!entry) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (entry->mSubDocument) { - entry->mSubDocument->SetParentDocument(nsnull); - - // Release the old sub document - NS_RELEASE(entry->mSubDocument); - } - - entry->mSubDocument = aSubDoc; - NS_ADDREF(entry->mSubDocument); - - aSubDoc->SetParentDocument(this); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsXULDocument::GetSubDocumentFor(nsIContent *aContent, nsIDocument** aSubDoc) -{ - *aSubDoc = nsnull; - - if (mSubDocuments) { - SubDocMapEntry *entry = - NS_STATIC_CAST(SubDocMapEntry*, - PL_DHashTableOperate(mSubDocuments, aContent, - PL_DHASH_LOOKUP)); - - if (PL_DHASH_ENTRY_IS_BUSY(entry)) { - *aSubDoc = entry->mSubDocument; - NS_ADDREF(*aSubDoc); - } - } - - return NS_OK; -} - -PR_STATIC_CALLBACK(PLDHashOperator) -FindContentEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr, - PRUint32 number, void *arg) -{ - SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr); - FindContentData *data = NS_STATIC_CAST(FindContentData*, arg); - - if (entry->mSubDocument == data->mSubDocument) { - data->mResult = NS_CONST_CAST(nsIContent *, entry->mKey); - - return PL_DHASH_STOP; - } - - return PL_DHASH_NEXT; -} - -NS_IMETHODIMP -nsXULDocument::FindContentForSubDocument(nsIDocument *aDocument, - nsIContent **aContent) -{ - NS_ENSURE_ARG_POINTER(aDocument); - - if (!mSubDocuments) { - *aContent = nsnull; - + NS_ADDREF(aSubDoc); + mSubDocuments.AppendElement(aSubDoc); return NS_OK; - } +} - FindContentData data(aDocument); - PL_DHashTableEnumerate(mSubDocuments, FindContentEnumerator, &data); +NS_IMETHODIMP +nsXULDocument::GetNumberOfSubDocuments(PRInt32 *aCount) +{ + *aCount = mSubDocuments.Count(); + return NS_OK; +} - *aContent = data.mResult; - NS_IF_ADDREF(*aContent); - - return NS_OK; +NS_IMETHODIMP +nsXULDocument::GetSubDocumentAt(PRInt32 aIndex, nsIDocument** aSubDoc) +{ + *aSubDoc = (nsIDocument*) mSubDocuments.SafeElementAt(aIndex); + NS_IF_ADDREF(*aSubDoc); + return NS_OK; } NS_IMETHODIMP @@ -2531,25 +2404,6 @@ nsXULDocument::RemoveReference(void *aKey, nsISupports **aOldReference) return NS_OK; } -NS_IMETHODIMP -nsXULDocument::SetContainer(nsISupports *aContainer) -{ - mDocumentContainer = dont_AddRef(NS_GetWeakReference(aContainer)); - - return NS_OK; -} - -NS_IMETHODIMP -nsXULDocument::GetContainer(nsISupports **aContainer) -{ - nsCOMPtr container = do_QueryReferent(mDocumentContainer); - - *aContainer = container; - NS_IF_ADDREF(*aContainer); - - return NS_OK; -} - void nsXULDocument::SetDisplaySelection(PRInt8 aToggle) { diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 3acb9a613fb..3d11bb9094c 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -222,12 +222,11 @@ public: NS_IMETHOD SetParentDocument(nsIDocument* aParent); - NS_IMETHOD SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc); + NS_IMETHOD AddSubDocument(nsIDocument* aSubDoc); - NS_IMETHOD GetSubDocumentFor(nsIContent *aContent, nsIDocument** aSubDoc); + NS_IMETHOD GetNumberOfSubDocuments(PRInt32* aCount); - NS_IMETHOD FindContentForSubDocument(nsIDocument *aDocument, - nsIContent **aContent); + NS_IMETHOD GetSubDocumentAt(PRInt32 aIndex, nsIDocument** aSubDoc); NS_IMETHOD GetRootContent(nsIContent** aRoot); @@ -334,8 +333,6 @@ public: NS_IMETHOD AddReference(void *aKey, nsISupports *aReference); NS_IMETHOD RemoveReference(void *aKey, nsISupports **aOldReference); - NS_IMETHOD SetContainer(nsISupports *aContainer); - NS_IMETHOD GetContainer(nsISupports **aContainer); virtual void SetDisplaySelection(PRInt8 aToggle); @@ -565,7 +562,6 @@ protected: nsCOMPtr mDocumentURL; // [OWNER] ??? compare with loader nsCOMPtr mDocumentBaseURL; nsWeakPtr mDocumentLoadGroup; // [WEAK] leads to loader - nsWeakPtr mDocumentContainer; // [WEAK] leads to container nsCOMPtr mDocumentPrincipal; // [OWNER] nsCOMPtr mRootContent; // [OWNER] nsIDocument* mParentDocument; // [WEAK] @@ -594,7 +590,7 @@ protected: nsCOMPtr mLocalStore; nsCOMPtr mLineBreaker; // [OWNER] nsCOMPtr mWordBreaker; // [OWNER] - PLDHashTable *mSubDocuments; // [OWNER] of subelements + nsVoidArray mSubDocuments; // [OWNER] of subelements PRPackedBool mIsPopup; PRPackedBool mIsFastLoad; PRPackedBool mApplyingPersistedAttrs; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 0d2f685e0a6..df86b1ada7b 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1158,14 +1158,6 @@ nsDocShell::SetChromeEventHandler(nsIChromeEventHandler * aChromeEventHandler) { // Weak reference. Don't addref. mChromeEventHandler = aChromeEventHandler; - - NS_ASSERTION(!mScriptGlobal, - "SetChromeEventHandler() called after the script global " - "object was created! This means that the script global " - "object in this docshell won't get the right chrome event " - "handler. You really don't want to see this assert, FIX " - "YOUR CODE!"); - return NS_OK; } @@ -2449,6 +2441,7 @@ nsDocShell::Stop(PRUint32 aStopFlags) if (nsIWebNavigation::STOP_CONTENT & aStopFlags) { if (mContentViewer) mContentViewer->Stop(); + } if (nsIWebNavigation::STOP_NETWORK & aStopFlags) { @@ -2657,6 +2650,7 @@ nsDocShell::InitWindow(nativeWindow parentNativeWindow, NS_IMETHODIMP nsDocShell::Create() { + NS_ENSURE_STATE(!mContentViewer); mPrefs = do_GetService(NS_PREF_CONTRACTID); //GlobalHistory is now set in SetGlobalHistory // mGlobalHistory = do_GetService(NS_GLOBALHISTORY_CONTRACTID); @@ -2841,6 +2835,8 @@ nsDocShell::GetParentWidget(nsIWidget ** parentWidget) NS_IMETHODIMP nsDocShell::SetParentWidget(nsIWidget * aParentWidget) { + NS_ENSURE_STATE(!mContentViewer); + mParentWidget = aParentWidget; return NS_OK; @@ -3964,7 +3960,6 @@ nsDocShell::CreateAboutBlankContentViewer() // generate (about:blank) document to load docFactory->CreateBlankDocument(loadGroup, getter_AddRefs(blankDoc)); if (blankDoc) { - blankDoc->SetContainer(NS_STATIC_CAST(nsIDocShell *, this)); // create a content viewer for us and the new document docFactory->CreateInstanceForDocument(NS_ISUPPORTS_CAST(nsIDocShell *, this), @@ -4306,13 +4301,13 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) nsCOMPtr widget; NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(widget)), NS_ERROR_FAILURE); - - if (widget) { - NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE); + if (!widget) { + NS_ERROR("GetMainWidget coughed up a null widget"); + return NS_ERROR_FAILURE; } nsRect bounds(x, y, cx, cy); - + NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE); if (NS_FAILED(mContentViewer->Init(widget, mDeviceContext, bounds))) { mContentViewer = nsnull; NS_ERROR("ContentViewer Initialization failed"); @@ -4335,7 +4330,7 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) focusController->SetSuppressFocus(PR_FALSE, "Win32-Only Link Traversal Issue"); - if (bgSet && widget) { + if (bgSet) { // Stuff the bgcolor from the last view manager into the new // view manager. This improves page load continuity. nsCOMPtr docviewer = diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index 814d19bd5c2..96a696364a4 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -1254,7 +1254,7 @@ NS_IMETHODIMP nsWebShell::Create() // Set the webshell as the default IContentViewerContainer for the loader... mDocLoader->SetContainer(shellAsContainer); - return nsDocShell::Create(); + return nsDocShell::Create(); } NS_IMETHODIMP nsWebShell::Destroy() diff --git a/dom/public/base/nsPIDOMWindow.h b/dom/public/base/nsPIDOMWindow.h index 426785c766d..4818d3d93d9 100644 --- a/dom/public/base/nsPIDOMWindow.h +++ b/dom/public/base/nsPIDOMWindow.h @@ -46,7 +46,6 @@ #include "nsIDOMLocation.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIDocument.h" -#include "nsIDOMElement.h" class nsIDocShell; class nsIDOMWindowInternal; @@ -67,7 +66,7 @@ public: NS_IMETHOD GetObjectProperty(const PRUnichar* aProperty, nsISupports** aObject) = 0; - + // This is private because activate/deactivate events are not part // of the DOM spec. NS_IMETHOD Activate() = 0; @@ -85,12 +84,6 @@ public: NS_IMETHOD GetExtantDocument(nsIDOMDocument** aDocument) = 0; NS_IMETHOD ReallyCloseWindow() = 0; - - // Internal getter/setter for the frame element, this version of the - // getter crosses chrome boundaries whereas the public scriptable - // one doesn't for security reasons. - NS_IMETHOD GetFrameElementInternal(nsIDOMElement** aFrameElement) = 0; - NS_IMETHOD SetFrameElementInternal(nsIDOMElement* aFrameElement) = 0; }; #endif // nsPIDOMWindow_h__ diff --git a/dom/public/idl/base/nsIDOMWindowInternal.idl b/dom/public/idl/base/nsIDOMWindowInternal.idl index 3489a71b15a..d549ea82980 100644 --- a/dom/public/idl/base/nsIDOMWindowInternal.idl +++ b/dom/public/idl/base/nsIDOMWindowInternal.idl @@ -185,6 +185,4 @@ interface nsIDOMWindowInternal : nsIDOMWindow // Ascii base64 data to binary data and vice versa... DOMString atob(in DOMString aAsciiString); DOMString btoa(in DOMString aBase64Data); - - readonly attribute nsIDOMElement frameElement; }; diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 33161dfcf9a..b4cd26942cb 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -185,8 +185,7 @@ GlobalWindowImpl::GlobalWindowImpl() : mLastMouseButtonAction(LL_ZERO), mFullScreen(PR_FALSE), mOriginalPos(nsnull), mOriginalSize(nsnull), mGlobalObjectOwner(nsnull), - mDocShell(nsnull), mMutationBits(0), mChromeEventHandler(nsnull), - mFrameElement(nsnull) + mDocShell(nsnull), mMutationBits(0), mChromeEventHandler(nsnull) { NS_INIT_REFCNT(); // We could have failed the first time through trying @@ -717,38 +716,6 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, } } - if (aEvent->message == NS_PAGE_LOAD) { - nsCOMPtr content(do_QueryInterface(mFrameElement)); - - nsCOMPtr parent; - GetParentInternal(getter_AddRefs(parent)); - - nsCOMPtr treeItem(do_QueryInterface(mDocShell)); - - PRInt32 itemType = nsIDocShellTreeItem::typeChrome; - - if (treeItem) { - treeItem->GetItemType(&itemType); - } - - if (content && parent && itemType != nsIDocShellTreeItem::typeChrome) { - // If we're not in chrome, or at a chrome boundary, fire the - // onload event for the frame element. - - nsCOMPtr ctx; - mDocShell->GetPresContext(getter_AddRefs(ctx)); - NS_ENSURE_TRUE(ctx, NS_OK); - - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_LOAD; - - return content->HandleDOMEvent(ctx, &event, nsnull, NS_EVENT_FLAG_INIT, - &status); - } - } if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created an event, @@ -2846,53 +2813,6 @@ GlobalWindowImpl::ReallyCloseWindow() return NS_OK; } -NS_IMETHODIMP -GlobalWindowImpl::GetFrameElement(nsIDOMElement** aFrameElement) -{ - *aFrameElement = nsnull; - - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellTI(do_QueryInterface(docShell)); - - if (!docShellTI) { - return NS_OK; - } - - nsCOMPtr parent; - docShellTI->GetSameTypeParent(getter_AddRefs(parent)); - - if (!parent || parent == docShellTI) { - // We're at a chrome boundary, don't expose the chrome iframe - // element to content code. - - return NS_OK; - } - - *aFrameElement = mFrameElement; - NS_IF_ADDREF(*aFrameElement); - - return NS_OK; -} - -NS_IMETHODIMP -GlobalWindowImpl::GetFrameElementInternal(nsIDOMElement** aFrameElement) -{ - *aFrameElement = mFrameElement; - NS_IF_ADDREF(*aFrameElement); - - return NS_OK; -} - -NS_IMETHODIMP -GlobalWindowImpl::SetFrameElementInternal(nsIDOMElement* aFrameElement) -{ - mFrameElement = aFrameElement; - - return NS_OK; -} - NS_IMETHODIMP GlobalWindowImpl::UpdateCommands(const nsAString& anAction) { @@ -4852,7 +4772,6 @@ nsGlobalChromeWindow::GetWindowState(PRUint16* aWindowState) break; case nsSizeMode_Normal: *aWindowState = nsIDOMChromeWindow::STATE_NORMAL; - break; default: NS_WARNING("Illegal window state for this chrome window"); break; diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 30deefc688a..8e071502b01 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -188,9 +188,6 @@ public: NS_IMETHOD ReallyCloseWindow(); - NS_IMETHOD GetFrameElementInternal(nsIDOMElement** aFrameElement); - NS_IMETHOD SetFrameElementInternal(nsIDOMElement* aFrameElement); - // nsIDOMViewCSS NS_DECL_NSIDOMVIEWCSS @@ -305,8 +302,6 @@ protected: nsCOMPtr mPkcs11; nsCOMPtr mDocumentPrincipal; - nsIDOMElement* mFrameElement; // WEAK - friend class nsDOMScriptableHelper; static nsIXPConnect *sXPConnect; }; diff --git a/dom/src/events/nsJSEventListener.cpp b/dom/src/events/nsJSEventListener.cpp index 28f1c42c4a5..7ccbf6f760a 100644 --- a/dom/src/events/nsJSEventListener.cpp +++ b/dom/src/events/nsJSEventListener.cpp @@ -151,11 +151,9 @@ nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) nsEvent* event; priv->GetInternalNSEvent(&event); if (event->message == NS_SCRIPT_ERROR) { - nsScriptErrorEvent *scriptEvent = - NS_STATIC_CAST(nsScriptErrorEvent*, event); - + nsScriptErrorEvent *scriptEvent = NS_STATIC_CAST(nsScriptErrorEvent*, event); argv = ::JS_PushArguments(cx, &stackPtr, "WWi", scriptEvent->errorMsg, - scriptEvent->fileName, scriptEvent->lineNr); + scriptEvent->fileName, scriptEvent->lineNr); NS_ENSURE_TRUE(argv, NS_ERROR_OUT_OF_MEMORY); argc = 3; handledScriptError = PR_TRUE; diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 1f404c662a4..52ddd146361 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -261,8 +261,6 @@ nsEditor::~nsEditor() IMETextTxn::ClassShutdown(); PR_AtomicDecrement(&gInstanceCount); - - NS_IF_RELEASE(mViewManager); } @@ -306,6 +304,7 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, nsIContent *aRoot ps->GetViewManager(&mViewManager); if (!mViewManager) {return NS_ERROR_NULL_POINTER;} + mViewManager->Release(); //we want a weak link mUpdateCount=0; InsertTextTxn::ClassInit(); diff --git a/extensions/inspector/base/src/inLayoutUtils.cpp b/extensions/inspector/base/src/inLayoutUtils.cpp index b3de7a49420..12a7a733330 100644 --- a/extensions/inspector/base/src/inLayoutUtils.cpp +++ b/extensions/inspector/base/src/inLayoutUtils.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -253,12 +253,22 @@ inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode) nsCOMPtr doc; content->GetDocument(*getter_AddRefs(doc)); if (doc) { - nsCOMPtr sub_doc; - doc->GetSubDocumentFor(content, getter_AddRefs(sub_doc)); - - nsCOMPtr domdoc(do_QueryInterface(sub_doc)); - - return domdoc; + nsCOMPtr shell; + doc->GetShellAt(0, getter_AddRefs(shell)); + if (shell) { + nsCOMPtr supports; + shell->GetSubShellFor(content, getter_AddRefs(supports)); + nsCOMPtr docShell = do_QueryInterface(supports); + if (docShell) { + nsCOMPtr contentViewer; + docShell->GetContentViewer(getter_AddRefs(contentViewer)); + if (contentViewer) { + nsCOMPtr domdoc; + contentViewer->GetDOMDocument(getter_AddRefs(domdoc)); + return domdoc; + } + } + } } } @@ -269,7 +279,6 @@ nsIDOMNode* inLayoutUtils::GetContainerFor(nsIDOMDocument* aDoc) { nsCOMPtr container; - nsCOMPtr doc(do_QueryInterface(aDoc)); // get the doc shell for this document and look for the parent doc shell nsCOMPtr win = inLayoutUtils::GetWindowFor(aDoc); @@ -288,17 +297,9 @@ inLayoutUtils::GetContainerFor(nsIDOMDocument* aDoc) nsCOMPtr presShell; parentDocShell->GetPresShell(getter_AddRefs(presShell)); - nsCOMPtr parent_doc; - presShell->GetDocument(getter_AddRefs(parent_doc)); - - nsCOMPtr node; - - if (parent_doc) { - nsCOMPtr content; - parent_doc->FindContentForSubDocument(doc, getter_AddRefs(content)); - - node = do_QueryInterface(content); - } + nsCOMPtr content; + presShell->FindContentForShell(docShell, getter_AddRefs(content)); + nsCOMPtr node = do_QueryInterface(content); return node; } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index e00ff6d5cb0..4cbaa876720 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -93,7 +93,6 @@ #include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeOwner.h" #include "nsIDocShell.h" -#include "nsIBaseWindow.h" #include "nsIFrameDebug.h" #include "nsILayoutHistoryState.h" #include "nsLayoutAtoms.h" @@ -146,7 +145,7 @@ static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); // Print Preview #include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants -#include "nsIScrollableView.h" +#include "nsIScrollableView.h" #include "nsIWebBrowserPrint.h" // needed for PrintPreview Navigation constants // Print Progress @@ -170,7 +169,7 @@ static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); #include "nsIWebShell.h" //focus -#include "nsIDOMEventReceiver.h" +#include "nsIDOMEventReceiver.h" #include "nsIDOMFocusListener.h" #include "nsISelectionController.h" @@ -199,7 +198,7 @@ static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); #ifdef DEBUG_PRINTING // XXX NOTE: I am including a header from the layout directory // merely to set up a file pointer for debug logging. This is -// fragile and may break in the future, which means it can be +// fragile and may break in the future, which means it can be // removed if necessary #if defined(XP_PC) #include "../../../layout/html/base/src/nsSimplePageSequence.h" @@ -213,20 +212,20 @@ static const char * gPrintRangeStr[] = {"kRangeAllPages", "kRangeSpecified static PRUint32 gDumpFileNameCnt = 0; static PRUint32 gDumpLOFileNameCnt = 0; -#define PRINT_DEBUG_MSG1(_msg1) fprintf(mPrt->mDebugFD, (_msg1)); -#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mPrt->mDebugFD, (_msg1), (_msg2)); -#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3)); -#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4)); -#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5)); +#define PRINT_DEBUG_MSG1(_msg1) fprintf(mPrt->mDebugFD, (_msg1)); +#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mPrt->mDebugFD, (_msg1), (_msg2)); +#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3)); +#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4)); +#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mPrt->mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5)); #define PRINT_DEBUG_FLUSH fflush(mPrt->mDebugFD); #else //-------------- -#define PRT_YESNO(_p) -#define PRINT_DEBUG_MSG1(_msg) -#define PRINT_DEBUG_MSG2(_msg1, _msg2) -#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) -#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) -#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) -#define PRINT_DEBUG_FLUSH +#define PRT_YESNO(_p) +#define PRINT_DEBUG_MSG1(_msg) +#define PRINT_DEBUG_MSG2(_msg1, _msg2) +#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) +#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) +#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) +#define PRINT_DEBUG_FLUSH #endif @@ -252,7 +251,7 @@ public: NS_DECL_ISUPPORTS // nsISelectionListerner interface - NS_DECL_NSISELECTIONLISTENER + NS_DECL_NSISELECTIONLISTENER nsDocViewerSelectionListener() : mDocViewer(NULL) @@ -261,9 +260,9 @@ public: { NS_INIT_REFCNT(); } - + virtual ~nsDocViewerSelectionListener() {} - + nsresult Init(DocumentViewerImpl *aDocViewer); protected: @@ -271,13 +270,13 @@ protected: DocumentViewerImpl* mDocViewer; PRPackedBool mGotSelectionState; PRPackedBool mSelectionWasCollapsed; - + }; /** editor Implementation of the FocusListener interface */ -class nsDocViewerFocusListener : public nsIDOMFocusListener +class nsDocViewerFocusListener : public nsIDOMFocusListener { public: /** default constructor @@ -399,8 +398,8 @@ public: // Listener Helper Methods void OnEndPrinting(); void OnStartPrinting(); - static void DoOnProgressChange(nsVoidArray& aListeners, - PRInt32 aProgess, + static void DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, PRInt32 aMaxProgress, PRBool aDoStartStop = PR_FALSE, PRInt32 aFlag = 0); @@ -417,7 +416,7 @@ public: nsCOMPtr mPrintProgress; nsCOMPtr mPrintProgressParams; PRBool mShowProgressDialog; - + nsCOMPtr mCurrentFocusWin; // cache a pointer to the currently focused window nsVoidArray* mPrintDocList; @@ -473,11 +472,11 @@ class DocumentViewerImpl : public nsIDocumentViewer, friend class nsDocViewerSelectionListener; friend class nsPagePrintTimer; friend class PrintData; - + public: DocumentViewerImpl(); DocumentViewerImpl(nsIPresContext* aPresContext); - + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW // nsISupports interface... @@ -512,24 +511,15 @@ public: nsresult CallChildren(CallChildFunc aFunc, void* aClosure); // Printing Methods - PRBool PrintPage(nsIPresContext* aPresContext, - nsIPrintSettings* aPrintSettings, - PrintObject* aPOect, PRBool& aInRange); + PRBool PrintPage(nsIPresContext* aPresContext,nsIPrintSettings* aPrintSettings,PrintObject* aPOect, PRBool& aInRange); PRBool DonePrintingPages(PrintObject* aPO); - + // helper method - static void GetWebShellTitleAndURL(nsIWebShell* aWebShell, - PRUnichar** aTitle, PRUnichar** aURLStr); + static void GetWebShellTitleAndURL(nsIWebShell * aWebShell, PRUnichar** aTitle, PRUnichar** aURLStr); // This enum tells indicates what the default should be for the title // if the title from the document is null - enum eDocTitleDefault { - eDocTitleDefNone, - eDocTitleDefBlank, - eDocTitleDefDocument, - eDocTitleDefURLDoc - }; - + enum eDocTitleDefault {eDocTitleDefNone, eDocTitleDefBlank, eDocTitleDefDocument, eDocTitleDefURLDoc}; static void GetDisplayTitleAndURL(PrintObject* aPO, nsIPrintSettings* aPrintSettings, const PRUnichar* aBrandName, @@ -549,15 +539,12 @@ private: nsIDeviceContext* aDeviceContext, const nsRect& aBounds, PRBool aDoCreation); - nsresult InitPresentationStuff(PRBool aDoInitialReflow); - - nsresult GetDocumentSelection(nsISelection **aSelection, - nsIPresShell * aPresShell = nsnull); + nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); PRBool IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin); PRBool IsParentAFrameSet(nsIWebShell * aParent); PRBool IsWebShellAFrameSet(nsIWebShell * aParent); - + PRBool IsThereAnIFrameSelected(nsIWebShell* aWebShell, nsIDOMWindowInternal * aDOMWin, PRPackedBool& aDoesContainFrameset); @@ -569,12 +556,11 @@ private: nsresult GetPopupImageNode(nsIDOMNode** aNode); //--------------------------------------------------------------------- - void BuildDocTree(nsIDocShellTreeNode * aParentNode, - nsVoidArray * aDocList, + void BuildDocTree(nsIDocShellTreeNode * aParentNode, + nsVoidArray * aDocList, PrintObject * aPO); - nsresult ReflowDocList(PrintObject * aPO, PRBool aSetPixelScale, - PRBool aDoCalcShrink); - void SetClipRect(PrintObject* aPO, + nsresult ReflowDocList(PrintObject * aPO, PRBool aSetPixelScale, PRBool aDoCalcShrink); + void SetClipRect(PrintObject* aPO, const nsRect& aClipRect, nscoord aOffsetX, nscoord aOffsetY, @@ -589,18 +575,14 @@ private: nsIContent* aContent); void MapContentToWebShells(PrintObject* aRootPO, PrintObject* aPO); nsresult MapSubDocFrameLocations(PrintObject* aPO); - PrintObject* FindPrintObjectByDOMWin(PrintObject* aParentObject, - nsIDOMWindowInternal * aDOMWin); - void GetPresShellAndRootContent(nsIWebShell * aWebShell, - nsIPresShell** aPresShell, - nsIContent** aContent); + PrintObject* FindPrintObjectByDOMWin(PrintObject* aParentObject, nsIDOMWindowInternal * aDOMWin); + void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent); void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages); void DoProgressForAsIsFrames(); void DoProgressForSeparateFrames(); void DoPrintProgress(PRBool aIsForPrinting); - void SetDocAndURLIntoProgress(PrintObject* aPO, - nsIPrintProgressParams* aParams); + void SetDocAndURLIntoProgress(PrintObject* aPO, nsIPrintProgressParams* aParams); nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions, nsIPrintSettings* aPrintSettings, PRUint32 aErrorCode, @@ -618,8 +600,7 @@ private: // nsresult DocumentReadyForPrinting(); //nsresult PrintSelection(nsIDeviceContextSpec * aDevSpec); - nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, - nsIDocument ** aNewDoc); + nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc); static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent); static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent); @@ -629,17 +610,12 @@ private: nsIDOMWindowInternal* aCurrentFocusedDOMWin); nsresult EnablePOsForPrinting(); PrintObject* FindXMostPO(); - void FindXMostFrameSize(nsIPresContext* aPresContext, - nsIRenderingContext* aRC, nsIFrame* aFrame, - nscoord aX, nscoord aY, PRInt32& aMaxWidth); - void FindXMostFrameInList(nsIPresContext* aPresContext, - nsIRenderingContext* aRC, nsIAtom* aList, - nsIFrame* aFrame, nscoord aX, nscoord aY, - PRInt32& aMaxWidth); + void FindXMostFrameSize(nsIPresContext* aPresContext, nsIRenderingContext* aRC, nsIFrame* aFrame, nscoord aX, nscoord aY, PRInt32& aMaxWidth); + void FindXMostFrameInList(nsIPresContext* aPresContext, nsIRenderingContext* aRC, nsIAtom* aList, nsIFrame* aFrame, + nscoord aX, nscoord aY, PRInt32& aMaxWidth); PRBool PrintDocContent(PrintObject* aPO, nsresult& aStatus); - nsresult DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, - PRBool& aDonePrinting); + nsresult DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDonePrinting); void SetPrintAsIs(PrintObject* aPO, PRBool aAsIs = PR_TRUE); void SetPrintPO(PrintObject* aPO, PRBool aPrint); @@ -654,18 +630,15 @@ private: // Timer Methods - nsresult StartPagePrintTimer(nsIPresContext * aPresContext, + nsresult StartPagePrintTimer(nsIPresContext * aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPO, PRUint32 aDelay); void PrepareToStartLoad(void); - - nsresult SyncParentSubDocMap(); - + // Misc - static void ShowPrintErrorDialog(nsresult printerror, - PRBool aIsPrinting = PR_TRUE); + static void ShowPrintErrorDialog(nsresult printerror, PRBool aIsPrinting = PR_TRUE); protected: // IMPORTANT: The ownership implicit in the following member @@ -673,7 +646,7 @@ protected: // for owning pointers and raw COM interface pointers for weak // (ie, non owning) references. If you add any members to this // class, please make the ownership explicit (pinkerton, scc). - + nsISupports* mContainer; // [WEAK] it owns me! nsCOMPtr mDeviceContext; // ??? can't hurt, but... nsIView* mView; // [WEAK] cleaned up by view mgr @@ -691,7 +664,7 @@ protected: nsCOMPtr mSelectionListener; nsCOMPtr mFocusListener; - + nsCOMPtr mPreviousViewer; PRBool mEnableRendering; @@ -766,7 +739,7 @@ public: NS_WARNING("unable to start the timer"); } else { mTimer->Init(this, aUseDelay?mDelay:0, NS_PRIORITY_NORMAL, NS_TYPE_ONE_SHOT); - } + } return result; } @@ -787,7 +760,7 @@ public: if (mDocViewer->DonePrintingPages(mPrintObj)) { initNewTimer = PR_FALSE; } - } + } Stop(); if (initNewTimer) { @@ -800,15 +773,15 @@ public: } } - void Init(DocumentViewerImpl* aDocViewerImpl, + void Init(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPO, - PRUint32 aDelay) + PRUint32 aDelay) { NS_IF_RELEASE(mDocViewer); mDocViewer = aDocViewerImpl; - NS_ADDREF(mDocViewer); + NS_ADDREF(mDocViewer); mPresContext = aPresContext; mPrintSettings = aPrintSettings; @@ -816,11 +789,11 @@ public: mDelay = aDelay; } - nsresult Start(DocumentViewerImpl* aDocViewerImpl, + nsresult Start(DocumentViewerImpl* aDocViewerImpl, nsIPresContext* aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPO, - PRUint32 aDelay) + PRUint32 aDelay) { Init(aDocViewerImpl, aPresContext, aPrintSettings, aPO, aDelay); return StartTimer(PR_FALSE); @@ -870,7 +843,7 @@ static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult) PrintData::PrintData() : mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull), mShowProgressDialog(PR_TRUE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE), - mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE), + mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE), mIsAborted(PR_FALSE), mPreparingForPrint(PR_FALSE), mDocWasToBeDestroyed(PR_FALSE), mShrinkToFit(PR_FALSE), mPrintFrameType(nsIPrintSettings::kFramesAsIs), mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPrinted(0), @@ -896,7 +869,7 @@ PrintData::PrintData() : } -PrintData::~PrintData() +PrintData::~PrintData() { // removed any cached if (mCachedPresObj) { @@ -925,7 +898,7 @@ PrintData::~PrintData() if (!isCancelled && !mIsAborted) { rv = mPrintDC->EndDocument(); } else { - rv = mPrintDC->AbortDocument(); + rv = mPrintDC->AbortDocument(); } if (NS_FAILED(rv)) { DocumentViewerImpl::ShowPrintErrorDialog(rv); @@ -974,8 +947,8 @@ void PrintData::OnEndPrinting() } void -PrintData::DoOnProgressChange(nsVoidArray& aListeners, - PRInt32 aProgess, +PrintData::DoOnProgressChange(nsVoidArray& aListeners, + PRInt32 aProgess, PRInt32 aMaxProgress, PRBool aDoStartStop, PRInt32 aFlag) @@ -985,7 +958,7 @@ PrintData::DoOnProgressChange(nsVoidArray& aListeners, for (PRInt32 i=0;iOnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress); + wpl->OnProgressChange(nsnull, nsnull, aProgess, aMaxProgress, aProgess, aMaxProgress); if (aDoStartStop) { wpl->OnStateChange(nsnull, nsnull, aFlag, 0); } @@ -996,10 +969,10 @@ PrintData::DoOnProgressChange(nsVoidArray& aListeners, //--------------------------------------------------- //-- PrintObject Class Impl //--------------------------------------------------- -PrintObject::PrintObject() : +PrintObject::PrintObject() : mFrameType(eFrame), mRootView(nsnull), mContent(nsnull), - mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1), + mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1), mRect(0,0,0,0), mReflowRect(0,0,0,0), mParent(nsnull), mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE), mSkippedPageEject(PR_FALSE), mSharedPresShell(PR_FALSE), @@ -1019,7 +992,7 @@ PrintObject::~PrintObject() PrintObject* po = (PrintObject*)mKids[i]; NS_ASSERTION(po, "PrintObject can't be null!"); delete po; - } + } if (mPresShell && !mSharedPresShell) { mPresShell->Destroy(); @@ -1058,14 +1031,16 @@ PRBool DocumentViewerImpl::mIsDoingPrinting = PR_FALSE; nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult) { - *aResult = new DocumentViewerImpl(); - if (!*aResult) { + NS_PRECONDITION(aResult, "null OUT ptr"); + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + DocumentViewerImpl* it = new DocumentViewerImpl(); + if (nsnull == it) { + *aResult = nsnull; return NS_ERROR_OUT_OF_MEMORY; } - - NS_ADDREF(*aResult); - - return NS_OK; + return CallQueryInterface(it, aResult); } // Note: operator new zeros our memory @@ -1079,8 +1054,7 @@ DocumentViewerImpl::DocumentViewerImpl() #endif } -void DocumentViewerImpl::PrepareToStartLoad() -{ +void DocumentViewerImpl::PrepareToStartLoad() { mEnableRendering = PR_TRUE; mStopped = PR_FALSE; mLoaded = PR_FALSE; @@ -1118,14 +1092,12 @@ NS_IMPL_ISUPPORTS6(DocumentViewerImpl, DocumentViewerImpl::~DocumentViewerImpl() { NS_ASSERTION(!mDocument, "User did not call nsIContentViewer::Close"); - if (mDocument) { + if (mDocument) Close(); - } NS_ASSERTION(!mPresShell, "User did not call nsIContentViewer::Destroy"); - if (mPresShell) { + if (mPresShell) Destroy(); - } // XXX(?) Revoke pending invalidate events @@ -1153,10 +1125,10 @@ DocumentViewerImpl::LoadStart(nsISupports *aDoc) nsresult rv; if (!mDocument) { - mDocument = do_QueryInterface(aDoc, &rv); + mDocument = do_QueryInterface(aDoc,&rv); } else if (mDocument == aDoc) { - // Reset the document viewer's state back to what it was + // Reset the document viewer's state back to what it was // when the document load started. PrepareToStartLoad(); } @@ -1164,42 +1136,6 @@ DocumentViewerImpl::LoadStart(nsISupports *aDoc) return rv; } -nsresult -DocumentViewerImpl::SyncParentSubDocMap() -{ - nsCOMPtr item(do_QueryInterface(mContainer)); - nsCOMPtr win(do_GetInterface(item)); - nsCOMPtr pwin(do_QueryInterface(win)); - nsCOMPtr content; - - if (mDocument && pwin) { - nsCOMPtr frame_element; - pwin->GetFrameElementInternal(getter_AddRefs(frame_element)); - - content = do_QueryInterface(frame_element); - } - - if (content) { - nsCOMPtr parent; - item->GetParent(getter_AddRefs(parent)); - - nsCOMPtr parent_win(do_GetInterface(parent)); - - if (parent_win) { - nsCOMPtr dom_doc; - parent_win->GetDocument(getter_AddRefs(dom_doc)); - - nsCOMPtr parent_doc(do_QueryInterface(dom_doc)); - - if (parent_doc) { - return parent_doc->SetSubDocumentFor(content, mDocument); - } - } - } - - return NS_OK; -} - NS_IMETHODIMP DocumentViewerImpl::SetContainer(nsISupports* aContainer) { @@ -1207,12 +1143,7 @@ DocumentViewerImpl::SetContainer(nsISupports* aContainer) if (mPresContext) { mPresContext->SetContainer(aContainer); } - - // We're loading a new document into the window where this document - // viewer lives, sync the parent document's frame element -> sub - // document map - - return SyncParentSubDocMap(); + return NS_OK; } NS_IMETHODIMP @@ -1234,99 +1165,6 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, return InitInternal(aParentWidget, aDeviceContext, aBounds, PR_TRUE); } -nsresult -DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow) -{ - // Create the style set... - nsCOMPtr styleSet; - nsresult rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); - NS_ENSURE_SUCCESS(rv, rv); - - // Now make the shell for the document - rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet, - getter_AddRefs(mPresShell)); - NS_ENSURE_SUCCESS(rv, rv); - - mPresShell->BeginObservingDocument(); - - // Initialize our view manager - nsRect bounds; - mWindow->GetBounds(bounds); - - float p2t; - - mPresContext->GetPixelsToTwips(&p2t); - - nscoord width = NSIntPixelsToTwips(bounds.width, p2t); - nscoord height = NSIntPixelsToTwips(bounds.height, p2t); - - mViewManager->DisableRefresh(); - mViewManager->SetWindowDimensions(width, height); - - // Setup default view manager background color - - // This may be overridden by the docshell with the background color - // for the last document loaded into the docshell - nscolor bgcolor = NS_RGB(0, 0, 0); - mPresContext->GetDefaultBackgroundColor(&bgcolor); - mViewManager->SetDefaultBackgroundColor(bgcolor); - - if (aDoInitialReflow) { - // Initial refllow - mPresShell->InitialReflow(width, height); - - // Now trigger a refresh - if (mEnableRendering) { - mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - } - } - - // now register ourselves as a selection listener, so that we get - // called when the selection changes in the window - nsDocViewerSelectionListener *selectionListener = - new nsDocViewerSelectionListener(); - NS_ENSURE_TRUE(selectionListener, NS_ERROR_OUT_OF_MEMORY); - - selectionListener->Init(this); - - // mSelectionListener is a owning reference - mSelectionListener = selectionListener; - - nsCOMPtr selection; - rv = GetDocumentSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr selPrivate(do_QueryInterface(selection)); - rv = selPrivate->AddSelectionListener(mSelectionListener); - if (NS_FAILED(rv)) - return rv; - - // focus listener - // - // now register ourselves as a focus listener, so that we get called - // when the focus changes in the window - nsDocViewerFocusListener *focusListener; - NS_NEWXPCOM(focusListener, nsDocViewerFocusListener); - NS_ENSURE_TRUE(focusListener, NS_ERROR_OUT_OF_MEMORY); - - focusListener->Init(this); - - // mFocusListener is a strong reference - mFocusListener = focusListener; - - // get the DOM event receiver - nsCOMPtr erP(do_QueryInterface(mDocument)); - NS_WARN_IF_FALSE(erP, "No event receiver in document!"); - - if (erP) { - rv = erP->AddEventListenerByIID(mFocusListener, - NS_GET_IID(nsIDOMFocusListener)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); - } - - return NS_OK; -} - //----------------------------------------------- // This method can be used to initial the "presentation" // The aDoCreation indicates whether it should create @@ -1337,6 +1175,8 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, const nsRect& aBounds, PRBool aDoCreation) { + NS_ASSERTION(aParentWidget != nsnull, "Null aParentWidget"); + #ifdef NS_PRINT_PREVIEW mParentWidget = aParentWidget; // not ref counted #endif @@ -1355,18 +1195,16 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, PRBool makeCX = PR_FALSE; if (aDoCreation) { - if (aParentWidget && !mPresContext) { + if (!mPresContext) { // Create presentation context if (mIsCreatingPrintPreview) { - mPresContext = do_CreateInstance(kPrintPreviewContextCID, &rv); + mPresContext = do_CreateInstance(kPrintPreviewContextCID,&rv); } else { - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); + mPresContext = do_CreateInstance(kGalleyContextCID,&rv); } - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) return rv; mPresContext->Init(aDeviceContext); - #ifdef NS_PRINT_PREVIEW makeCX = !mIsDoingPrintPreview; // needs to be true except when we are already in PP #else @@ -1375,52 +1213,142 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, } } - if (aDoCreation && mPresContext) { - // Create the ViewManager and Root View... - - // We must do this before we tell the script global object about - // this new document since doing that will cause us to re-enter - // into nsHTMLFrameInnerFrame code through reflows caused by - // FlushPendingNotifications() calls down the road... - - rv = MakeWindow(aParentWidget, aBounds); - NS_ENSURE_SUCCESS(rv, rv); - Hide(); - } - nsCOMPtr requestor(do_QueryInterface(mContainer)); if (requestor) { - if (mPresContext) { - nsCOMPtr linkHandler; - requestor->GetInterface(NS_GET_IID(nsILinkHandler), - getter_AddRefs(linkHandler)); - mPresContext->SetContainer(mContainer); - mPresContext->SetLinkHandler(linkHandler); - } + nsCOMPtr linkHandler; + requestor->GetInterface(NS_GET_IID(nsILinkHandler), + getter_AddRefs(linkHandler)); + mPresContext->SetContainer(mContainer); + mPresContext->SetLinkHandler(linkHandler); if (!mIsDoingPrintPreview) { // Set script-context-owner in the document + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), + getter_AddRefs(owner)); - nsCOMPtr global; - requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObject), - getter_AddRefs(global)); + if (owner) { + nsCOMPtr global; + owner->GetScriptGlobalObject(getter_AddRefs(global)); - if (global) { - mDocument->SetScriptGlobalObject(global); - nsCOMPtr domdoc(do_QueryInterface(mDocument)); + if (global) { + mDocument->SetScriptGlobalObject(global); + nsCOMPtr domdoc(do_QueryInterface(mDocument)); - if (domdoc) { - global->SetNewDocument(domdoc, PR_TRUE); + if (domdoc) { + global->SetNewDocument(domdoc, PR_TRUE); + } } } } } - if (aDoCreation && mPresContext) { - // The ViewManager and Root View was created above (in - // MakeWindow())... + if (aDoCreation) { + // Create the ViewManager and Root View... + rv = MakeWindow(aParentWidget, aBounds); + Hide(); - rv = InitPresentationStuff(!makeCX); + if (NS_FAILED(rv)) return rv; + + // Create the style set... + nsIStyleSet* styleSet; + rv = CreateStyleSet(mDocument, &styleSet); + if (NS_FAILED(rv)) return rv; + + // Now make the shell for the document + rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet, + getter_AddRefs(mPresShell)); + NS_RELEASE(styleSet); + if (NS_FAILED(rv)) return rv; + + mPresShell->BeginObservingDocument(); + + // Initialize our view manager + nsRect bounds; + mWindow->GetBounds(bounds); + nscoord width = bounds.width; + nscoord height = bounds.height; + float p2t; + mPresContext->GetPixelsToTwips(&p2t); + width = NSIntPixelsToTwips(width, p2t); + height = NSIntPixelsToTwips(height, p2t); + mViewManager->DisableRefresh(); + mViewManager->SetWindowDimensions(width, height); + + /* Setup default view manager background color */ + /* This may be overridden by the docshell with the background color for the + last document loaded into the docshell */ + nscolor bgcolor = NS_RGB(0, 0, 0); + mPresContext->GetDefaultBackgroundColor(&bgcolor); + mViewManager->SetDefaultBackgroundColor(bgcolor); + + if (!makeCX) { + // Make shell an observer for next time + // XXX - we observe the docuement always, see above after preshell is created + // mPresShell->BeginObservingDocument(); + + //XXX I don't think this should be done *here*; and why paint nothing + //(which turns out to cause black flashes!)??? + // Resize-reflow this time + mPresShell->InitialReflow(width, height); + + // Now trigger a refresh + if (mEnableRendering) { + mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); + } + } + } else { + mPresShell->BeginObservingDocument(); + } + // now register ourselves as a selection listener, so that we get called + // when the selection changes in the window + nsDocViewerSelectionListener *selectionListener; + NS_NEWXPCOM(selectionListener, nsDocViewerSelectionListener); + if (!selectionListener) return NS_ERROR_OUT_OF_MEMORY; + selectionListener->Init(this); + + // this is the owning reference. The nsCOMPtr will take care of releasing + // our ref to the listener on destruction. + NS_ADDREF(selectionListener); + mSelectionListener = do_QueryInterface(selectionListener); + NS_RELEASE(selectionListener); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr selection; + rv = GetDocumentSelection(getter_AddRefs(selection)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr selPrivate(do_QueryInterface(selection)); + rv = selPrivate->AddSelectionListener(mSelectionListener); + if (NS_FAILED(rv)) return rv; + + //focus listener + // now register ourselves as a focus listener, so that we get called + // when the focus changes in the window + nsDocViewerFocusListener *focusListener; + NS_NEWXPCOM(focusListener, nsDocViewerFocusListener); + if (!focusListener) return NS_ERROR_OUT_OF_MEMORY; + focusListener->Init(this); + + // this is the owning reference. The nsCOMPtr will take care of releasing + // our ref to the listener on destruction. + NS_ADDREF(focusListener); + mFocusListener = do_QueryInterface(focusListener); + NS_RELEASE(focusListener); + if (NS_FAILED(rv)) + return rv; + + if(mDocument) + { + // get the DOM event receiver + nsCOMPtr erP (do_QueryInterface(mDocument, &rv)); + if(NS_FAILED(rv)) + return rv; + if(!erP) + return NS_ERROR_FAILURE; + + rv = erP->AddEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); } return rv; @@ -1446,14 +1374,14 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) rv = mDocument->GetScriptGlobalObject(getter_AddRefs(global)); // Fail if no ScriptGlobalObject is available... - NS_ENSURE_TRUE(global, NS_ERROR_NULL_POINTER); + NS_ASSERTION(global, "nsIScriptGlobalObject not set for document!"); + if (!global) return NS_ERROR_NULL_POINTER; mLoaded = PR_TRUE; - /* We need to protect ourself against auto-destruction in case the - window is closed while processing the OnLoad event. See bug - http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more - explanation. + /* We need to protect ourself against auto-destruction in case the window is closed + while processing the OnLoad event. + See bug http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more explanation. */ NS_ADDREF_THIS(); @@ -1469,14 +1397,11 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) #ifdef MOZ_TIMELINE // if navigator.xul's load is complete, the main nav window is visible // mark that point. - if (mDocument) { //printf("DEBUG: getting uri from document (%p)\n", mDocument.get()); - nsCOMPtr uri; mDocument->GetDocumentURL(getter_AddRefs(uri)); - - if (uri) { + if (uri.get() != nsnull) { //printf("DEBUG: getting spec fro uri (%p)\n", uri.get()); nsCAutoString spec; uri->GetSpec(spec); @@ -1489,12 +1414,11 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) } else { // XXX: Should fire error event to the document... } - + // Now that the document has loaded, we can tell the presshell // to unsuppress painting. - if (mPresShell && !mStopped) { + if (mPresShell && !mStopped) mPresShell->UnsuppressPainting(); - } NS_RELEASE_THIS(); @@ -1546,9 +1470,11 @@ DocumentViewerImpl::Close() // for an object that can be switched in and out so that we don't need // to disable scripts during paint suppression. + nsresult rv; + if (mDocument) { #ifdef NS_PRINT_PREVIEW - // Turn scripting back on + // Turn scripting back on // after PrintPreview had turned it off if (mPrtPreview) { TurnScriptingOn(PR_TRUE); @@ -1559,28 +1485,20 @@ DocumentViewerImpl::Close() // in the DocViewer Init nsCOMPtr globalObject; mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { globalObject->SetNewDocument(nsnull, PR_TRUE); } - // out of band cleanup of webshell mDocument->SetScriptGlobalObject(nsnull); - if (mFocusListener) { // get the DOM event receiver - nsCOMPtr erP(do_QueryInterface(mDocument)); - NS_WARN_IF_FALSE(erP, "No event receiver in document!"); - - if (erP) { - erP->RemoveEventListenerByIID(mFocusListener, - NS_GET_IID(nsIDOMFocusListener)); - } + nsCOMPtr erP( do_QueryInterface(mDocument, &rv) ); + if(NS_SUCCEEDED(rv) && erP) + erP->RemoveEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); } - } + } mDocument = nsnull; - return NS_OK; } @@ -1640,19 +1558,15 @@ DocumentViewerImpl::Destroy() if (mPresShell) { // Break circular reference (or something) mPresShell->EndObservingDocument(); - nsCOMPtr selection; - GetDocumentSelection(getter_AddRefs(selection)); - + nsresult rv = GetDocumentSelection(getter_AddRefs(selection)); nsCOMPtr selPrivate(do_QueryInterface(selection)); - - if (selPrivate && mSelectionListener) + if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) selPrivate->RemoveSelectionListener(mSelectionListener); - mPresShell->Destroy(); mPresShell = nsnull; } - + return NS_OK; } @@ -1687,17 +1601,15 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) // Assumptions: // // 1) this document viewer has been initialized with a call to Init(). - // 2) the stylesheets associated with the document have been added - // to the document. + // 2) the stylesheets associated with the document have been added to the document. - // XXX Right now, this method assumes that the layout of the current - // document hasn't started yet. More cleanup will probably be - // necessary to make this method work for the case when layout *has* - // occurred for the current document. + // XXX Right now, this method assumes that the layout of the current document + // hasn't started yet. More cleanup will probably be necessary to make this + // method work for the case when layout *has* occurred for the current document. // That work can happen when and if it is needed. - + nsresult rv; - if (!aDocument) + if (nsnull == aDocument) return NS_ERROR_NULL_POINTER; nsCOMPtr newDoc = do_QueryInterface(aDocument, &rv); @@ -1707,50 +1619,46 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) mDocument = newDoc; // 1) Set the script global object on the new document - nsCOMPtr global(do_GetInterface(mContainer)); - - if (global) { - mDocument->SetScriptGlobalObject(global); - global->SetNewDocument(aDocument, PR_TRUE); - - rv = SyncParentSubDocMap(); - NS_ENSURE_SUCCESS(rv, rv); - } - - // 2) Replace the current pres shell with a new shell for the new document - - if (mPresShell) { - mPresShell->EndObservingDocument(); - mPresShell->Destroy(); - - mPresShell = nsnull; - } - - // And if we're already given a prescontext... - if (mPresContext) { - // 3) Create a new style set for the document - - nsCOMPtr styleSet; - rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); - if (NS_FAILED(rv)) - return rv; - - rv = newDoc->CreateShell(mPresContext, mViewManager, styleSet, - getter_AddRefs(mPresShell)); - if (NS_FAILED(rv)) return rv; - - mPresShell->BeginObservingDocument(); - - // 4) Register the focus listener on the new document - - nsCOMPtr erP = do_QueryInterface(mDocument, &rv); - NS_WARN_IF_FALSE(erP, "No event receiver in document!"); - - if (erP) { - rv = erP->AddEventListenerByIID(mFocusListener, - NS_GET_IID(nsIDOMFocusListener)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); + nsCOMPtr requestor(do_QueryInterface(mContainer)); + if (requestor) { + nsCOMPtr owner; + requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), + getter_AddRefs(owner)); + if (nsnull != owner) { + nsCOMPtr global; + rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); + if (NS_SUCCEEDED(rv) && (nsnull != global)) { + mDocument->SetScriptGlobalObject(global); + global->SetNewDocument(aDocument, PR_TRUE); + } } + } + + // 2) Create a new style set for the document + nsCOMPtr styleSet; + rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); + if (NS_FAILED(rv)) return rv; + + // 3) Replace the current pres shell with a new shell for the new document + mPresShell->EndObservingDocument(); + mPresShell->Destroy(); + + mPresShell = nsnull; + rv = newDoc->CreateShell(mPresContext, mViewManager, styleSet, + getter_AddRefs(mPresShell)); + if (NS_FAILED(rv)) return rv; + + mPresShell->BeginObservingDocument(); + + // 4) Register the focus listener on the new document + if(mDocument) + { + nsCOMPtr erP = do_QueryInterface(mDocument, &rv); + if(NS_FAILED(rv) || !erP) + return rv ? rv : NS_ERROR_FAILURE; + + rv = erP->AddEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); } return rv; @@ -1767,7 +1675,7 @@ DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) } return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::GetDocument(nsIDocument*& aResult) { @@ -1775,7 +1683,7 @@ DocumentViewerImpl::GetDocument(nsIDocument*& aResult) NS_IF_ADDREF(aResult); return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::GetPresShell(nsIPresShell*& aResult) { @@ -1783,7 +1691,7 @@ DocumentViewerImpl::GetPresShell(nsIPresShell*& aResult) NS_IF_ADDREF(aResult); return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::GetPresContext(nsIPresContext*& aResult) { @@ -1825,7 +1733,7 @@ DocumentViewerImpl::SetPreviousViewer(nsIContentViewer* aViewer) "can't set previous viewer when there already is one"); // In a multiple chaining situation (which occurs when running a thrashing - // test like i-bench or jrgm's tests with no delay), we can build up a + // test like i-bench or jrgm's tests with no delay), we can build up a // whole chain of viewers. In order to avoid this, we always set our previous // viewer to the MOST previous viewer in the chain, and then dump the intermediate // link from the chain. This ensures that at most only 2 documents are alive @@ -1848,7 +1756,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetBounds(const nsRect& aBounds) { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); - + NS_PRECONDITION(mWindow, "null window"); if (mWindow) { // Don't have the widget repaint. Layout will generate repaint requests // during reflow @@ -1873,6 +1781,7 @@ NS_IMETHODIMP DocumentViewerImpl::Show(void) { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); + NS_PRECONDITION(mWindow, "null window"); // We don't need the previous viewer anymore since we're not // displaying it. @@ -1887,114 +1796,6 @@ DocumentViewerImpl::Show(void) if (mWindow) { mWindow->Show(PR_TRUE); } - - if (mDocument && !mPresShell && !mWindow && !mDeviceContext) { - nsresult rv; - - nsCOMPtr base_win(do_QueryInterface(mContainer)); - NS_ENSURE_TRUE(base_win, NS_ERROR_UNEXPECTED); - - base_win->GetParentWidget(&mParentWidget); - NS_ENSURE_TRUE(mParentWidget, NS_ERROR_UNEXPECTED); - - if (!mDeviceContext) { - mDeviceContext = dont_AddRef(mParentWidget->GetDeviceContext()); - } - -#ifdef NS_PRINT_PREVIEW - // Clear PrintPreview Alternate Device - if (mDeviceContext) { - mDeviceContext->SetAltDevice(nsnull); - } -#endif - - PRBool makeCX = PR_FALSE; - - // Create presentation context - if (mIsCreatingPrintPreview) { - NS_ERROR("Whoa, we should not get here!"); - - return NS_ERROR_UNEXPECTED; - } - - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - mPresContext->Init(mDeviceContext); - - nsRect tbounds; - mParentWidget->GetBounds(tbounds); - - float p2t; - mPresContext->GetPixelsToTwips(&p2t); - tbounds *= p2t; - - // Create the view manager - mViewManager = do_CreateInstance(kViewManagerCID); - NS_ENSURE_TRUE(mViewManager, NS_ERROR_NOT_AVAILABLE); - - // Initialize the view manager with an offset. This allows the - // viewmanager to manage a coordinate space offset from (0,0) - rv = mViewManager->Init(mDeviceContext); - if (NS_FAILED(rv)) - return rv; - - rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y); - if (NS_FAILED(rv)) - return rv; - - // Reset the bounds offset so the root view is set to 0,0. The - // offset is specified in nsIViewManager::Init above. - // Besides, layout will reset the root view to (0,0) during reflow, - // so changing it to 0,0 eliminates placing the root view in the - // wrong place initially. - tbounds.x = 0; - tbounds.y = 0; - - // Create a child window of the parent that is our "root - // view/window" Create a view - rv = CallCreateInstance(kViewCID, &mView); - if (NS_FAILED(rv)) - return rv; - rv = mView->Init(mViewManager, tbounds, nsnull); - if (NS_FAILED(rv)) - return rv; - - rv = mView->CreateWidget(kWidgetCID, nsnull, - mParentWidget->GetNativeData(NS_NATIVE_WIDGET), - PR_TRUE, PR_FALSE); - - if (NS_FAILED(rv)) - return rv; - - // Setup hierarchical relationship in view manager - mViewManager->SetRootView(mView); - - mView->GetWidget(*getter_AddRefs(mWindow)); - - if (mPresContext && mContainer) { - nsCOMPtr linkHandler(do_GetInterface(mContainer)); - - if (linkHandler) { - mPresContext->SetLinkHandler(linkHandler); - } - - mPresContext->SetContainer(mContainer); - } - - if (mPresContext) { - Hide(); - - rv = InitPresentationStuff(PR_TRUE); - } - - // If we get here the document load has already started and the - // window is shown because some JS on the page caused it to be - // shown... - - mPresShell->UnsuppressPainting(); - } - return NS_OK; } @@ -2006,48 +1807,6 @@ DocumentViewerImpl::Hide(void) if (mWindow) { mWindow->Show(PR_FALSE); } - - if (!mPresShell) { - return NS_OK; - } - - // Avoid leaking the old viewer. - if (mPreviousViewer) { - mPreviousViewer->Destroy(); - mPreviousViewer = nsnull; - } - - if (mDeviceContext) - mDeviceContext->FlushFontCache(); - - // Break circular reference (or something) - mPresShell->EndObservingDocument(); - nsCOMPtr selection; - - GetDocumentSelection(getter_AddRefs(selection)); - - nsCOMPtr selPrivate(do_QueryInterface(selection)); - - if (selPrivate && mSelectionListener) - selPrivate->RemoveSelectionListener(mSelectionListener); - - mPresShell->Destroy(); - - mPresShell = nsnull; - mPresContext = nsnull; - mViewManager = nsnull; - mView = nsnull; - mWindow = nsnull; - mDeviceContext = nsnull; - mView = nsnull; - mParentWidget = nsnull; - - nsCOMPtr base_win(do_QueryInterface(mContainer)); - - if (base_win) { - base_win->SetParentWidget(nsnull); - } - return NS_OK; } @@ -2073,7 +1832,7 @@ DocumentViewerImpl::FindFrameSetWithIID(nsIContent * aParentContent, const nsIID } /** --------------------------------------------------- - * Helper function + * Helper function */ static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell) @@ -2100,10 +1859,10 @@ GetPresShellFor(nsIDocShell* aDocShell) #include "process.h" #include "direct.h" -#define MY_FINDFIRST(a,b) FindFirstFile(a,b) -#define MY_FINDNEXT(a,b) FindNextFile(a,b) -#define ISDIR(a) (a.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) -#define MY_FINDCLOSE(a) FindClose(a) +#define MY_FINDFIRST(a,b) FindFirstFile(a,b) +#define MY_FINDNEXT(a,b) FindNextFile(a,b) +#define ISDIR(a) (a.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) +#define MY_FINDCLOSE(a) FindClose(a) #define MY_FILENAME(a) a.cFileName #define MY_FILESIZE(a) (a.nFileSizeHigh * MAXDWORD) + a.nFileSizeLow @@ -2178,10 +1937,10 @@ static void RootFrameList(nsIPresContext* aPresContext, FILE* out, PRInt32 aInde /** --------------------------------------------------- * Dumps Frames for Printing */ -static void DumpFrames(FILE* out, - nsIPresContext* aPresContext, - nsIRenderingContext * aRendContext, - nsIFrame * aFrame, +static void DumpFrames(FILE* out, + nsIPresContext* aPresContext, + nsIRenderingContext * aRendContext, + nsIFrame * aFrame, PRInt32 aLevel) { NS_ASSERTION(out, "Pointer is null!"); @@ -2349,16 +2108,16 @@ static void DumpPrintObjectsList(nsVoidArray * aDocList, FILE* aFD = nsnull) } } - fprintf(fd, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], + fprintf(fd, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mWebShell, po->mSeqFrame, - po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); + po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); if (fd != nsnull && fd != stdout) { - fprintf(stdout, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], + fprintf(stdout, "%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mWebShell, po->mSeqFrame, - po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); + po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); } - } -} + } +} static void DumpPrintObjectsTree(PrintObject * aPO, int aLevel= 0, FILE* aFD = nsnull) { NS_ASSERTION(aPO, "Pointer is null!"); @@ -2375,12 +2134,11 @@ static void DumpPrintObjectsTree(PrintObject * aPO, int aLevel= 0, FILE* aFD = n NS_ASSERTION(po, "PrintObject can't be null!"); for (PRInt32 k=0;kmFrameType], po, po->mWebShell, po->mSeqFrame, - po->mPageFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); - } + po->mPageFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height); + } } - -static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, - char *& aURLStr) + +static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, char *& aURLStr) { aDocStr = nsnull; aURLStr = nsnull; @@ -2388,9 +2146,7 @@ static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, PRUnichar * mozillaDoc = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document")); PRUnichar * docTitleStr; PRUnichar * docURLStr; - DocumentViewerImpl::GetDisplayTitleAndURL(aPO, nsnull, mozillaDoc, - &docTitleStr, &docURLStr, - DocumentViewerImpl::eDocTitleDefURLDoc); + DocumentViewerImpl::GetDisplayTitleAndURL(aPO, nsnull, mozillaDoc, &docTitleStr, &docURLStr, DocumentViewerImpl::eDocTitleDefURLDoc); if (docTitleStr) { nsAutoString strDocTitle(docTitleStr); @@ -2409,7 +2165,7 @@ static void GetDocTitleAndURL(PrintObject* aPO, char *& aDocStr, } } -static void DumpPrintObjectsTreeLayout(PrintObject * aPO, +static void DumpPrintObjectsTreeLayout(PrintObject * aPO, nsIDeviceContext * aDC, int aLevel= 0, FILE * aFD = nsnull) { @@ -2433,7 +2189,7 @@ static void DumpPrintObjectsTreeLayout(PrintObject * aPO, } for (PRInt32 k=0;kmFrameType], aPO, aPO->mWebShell, aPO->mSeqFrame, - aPO->mPageFrame, aPO->mPageNum, aPO->mRect.x, aPO->mRect.y, aPO->mRect.width, aPO->mRect.height); + aPO->mPageFrame, aPO->mPageNum, aPO->mRect.x, aPO->mRect.y, aPO->mRect.width, aPO->mRect.height); if (aPO->IsPrintable()) { char * docStr; char * urlStr; @@ -2454,7 +2210,7 @@ static void DumpPrintObjectsTreeLayout(PrintObject * aPO, if (aLevel == 0 && fd) { fclose(fd); } -} +} static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList, FILE* aFD = nsnull) { @@ -2472,7 +2228,7 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList, FILE* #else #define DUMP_DOC_LIST(_title) #define DUMP_DOC_TREE -#define DUMP_DOC_TREELAYOUT +#define DUMP_DOC_TREELAYOUT #endif //--------------------------------------------------------------- @@ -2482,7 +2238,7 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList, FILE* //--------------------------------------------------------------- /** --------------------------------------------------- - * Giving a child frame it searches "up" the tree until it + * Giving a child frame it searches "up" the tree until it * finds a "Page" frame. */ static nsIFrame * GetPageFrame(nsIFrame * aFrame) @@ -2507,7 +2263,7 @@ static nsIFrame * FindFrameByType(nsIPresContext* aPresContext, nsIFrame * aParentFrame, nsIAtom * aType, nsRect& aRect, - nsRect& aChildRect) + nsRect& aChildRect) { NS_ASSERTION(aPresContext, "Pointer is null!"); NS_ASSERTION(aParentFrame, "Pointer is null!"); @@ -2634,7 +2390,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, seqFrame->GetRect(rect); // start out with the sequence frame and search the entire frame tree - // capturing the the starting and ending child frames of the selection + // capturing the the starting and ending child frames of the selection // and their rects FindSelectionBounds(aPresContext, aRC, seqFrame, rect, startFrame, aStartRect, endFrame, aEndRect); @@ -2643,7 +2399,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, printf("End Frame: %p\n", endFrame); #endif - // initial the page numbers here + // initial the page numbers here // in case we don't find and frames aStartPageNum = -1; aEndPageNum = -1; @@ -2659,7 +2415,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, // Check to see if start should be same as end if // the end frame comes back null if (endFrame == nsnull) { - // XXX the "GetPageFrame" step could be integrated into + // XXX the "GetPageFrame" step could be integrated into // the FindSelectionBounds step, but walking up to find // the parent of a child frame isn't expensive and it makes // FindSelectionBounds a little easier to understand @@ -2699,7 +2455,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, while (page != nsnull) { if (page == startPageFrame) { aStartPageNum = pageNum; - } + } if (page == endPageFrame) { aEndPageNum = pageNum; } @@ -2719,7 +2475,7 @@ static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, } //------------------------------------------------------- -PRBool +PRBool DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) { NS_ASSERTION(aParent, "Pointer is null!"); @@ -2728,8 +2484,8 @@ DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) nsCOMPtr parentAsItem(do_QueryInterface(aParent)); if (!parentAsItem) return PR_FALSE; - // When it is the top level document we need to check - // to see if it contains a frameset. If it does, then + // When it is the top level document we need to check + // to see if it contains a frameset. If it does, then // we only want to print the doc's children and not the document itself // For anything else we always print all the children and the document // for example, if the doc contains an IFRAME we eant to print the child @@ -2738,10 +2494,10 @@ DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) // XXX we really need to search the frame tree, and not the content // but there is no way to distinguish between IFRAMEs and FRAMEs // with the GetFrameType call. - // Bug 53459 has been files so we can eventually distinguish + // Bug 53459 has been files so we can eventually distinguish // between IFRAME frames and FRAME frames PRBool isFrameSet = PR_FALSE; - // only check to see if there is a frameset if there is + // only check to see if there is a frameset if there is // NO parent doc for this doc. meaning this parent is the root doc nsCOMPtr shell; mPresContext->GetShell(getter_AddRefs(shell)); @@ -2762,7 +2518,7 @@ DocumentViewerImpl::IsParentAFrameSet(nsIWebShell * aParent) } //------------------------------------------------------- -PRBool +PRBool DocumentViewerImpl::IsWebShellAFrameSet(nsIWebShell * aWebShell) { NS_ASSERTION(aWebShell, "Pointer is null!"); @@ -2781,8 +2537,8 @@ DocumentViewerImpl::IsWebShellAFrameSet(nsIWebShell * aWebShell) //------------------------------------------------------- void -DocumentViewerImpl::GetWebShellTitleAndURL(nsIWebShell * aWebShell, - PRUnichar** aTitle, +DocumentViewerImpl::GetWebShellTitleAndURL(nsIWebShell * aWebShell, + PRUnichar** aTitle, PRUnichar** aURLStr) { NS_ASSERTION(aWebShell, "Pointer is null!"); @@ -2878,7 +2634,7 @@ DocumentViewerImpl::GetDisplayTitleAndURL(PrintObject* aPO, case eDocTitleDefDocument: if (aBrandName) *aTitle = nsCRT::strdup(aBrandName); break; - case eDocTitleDefURLDoc: + case eDocTitleDefURLDoc: if (*aURLStr) { *aTitle = nsCRT::strdup(*aURLStr); } else { @@ -3014,12 +2770,12 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { DoProgressForSeparateFrames(); - } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || + } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) { PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, curPage, endPage); } - // Set Clip when Printing "AsIs" or + // Set Clip when Printing "AsIs" or // when printing an IFrame for SelectedFrame or EachFrame PRBool setClip = PR_FALSE; switch (mPrt->mPrintFrameType) { @@ -3044,7 +2800,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, } break; - } //switch + } //switch if (setClip) { // Always set the clip x,y to zero because it isn't going to have any margins @@ -3058,7 +2814,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, // fail and the failure is passed back here. // Returning PR_TRUE means we are done printing. // - // When rv == NS_ERROR_ABORT, it means we want out of the + // When rv == NS_ERROR_ABORT, it means we want out of the // print job without displaying any error messages nsresult rv = mPageSeqFrame->PrintNextPage(aPresContext); if (NS_FAILED(rv)) { @@ -3067,7 +2823,7 @@ DocumentViewerImpl::PrintPage(nsIPresContext* aPresContext, mPrt->mIsAborted = PR_TRUE; } return PR_TRUE; - } + } // Now see if any of the SubDocs are on this page if (aPO->mPrintAsIs) { @@ -3133,9 +2889,9 @@ PrintObject * DocumentViewerImpl::FindPrintObjectByWS(PrintObject* aPO, nsIWebSh //------------------------------------------------------- // Recursively build a list of of sub documents to be printed // that mirrors the document tree -void -DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, - nsVoidArray * aDocList, +void +DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, + nsVoidArray * aDocList, PrintObject * aPO) { NS_ASSERTION(aParentNode, "Pointer is null!"); @@ -3143,7 +2899,7 @@ DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, NS_ASSERTION(aPO, "Pointer is null!"); // Get the Doc and Title String - GetWebShellTitleAndURL(aPO->mWebShell, &aPO->mDocTitle, &aPO->mDocURL); + GetWebShellTitleAndURL(aPO->mWebShell, &aPO->mDocTitle, &aPO->mDocURL); PRInt32 childWebshellCount; aParentNode->GetChildCount(&childWebshellCount); @@ -3152,14 +2908,6 @@ DocumentViewerImpl::BuildDocTree(nsIDocShellTreeNode * aParentNode, nsCOMPtr child; aParentNode->GetChildAt(i, getter_AddRefs(child)); nsCOMPtr childAsShell(do_QueryInterface(child)); - - nsCOMPtr presShell; - childAsShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - continue; - } - nsCOMPtr viewer; childAsShell->GetContentViewer(getter_AddRefs(viewer)); if (viewer) { @@ -3190,7 +2938,7 @@ DocumentViewerImpl::SetPrintAsIs(PrintObject* aPO, PRBool aAsIs) aPO->mPrintAsIs = aAsIs; for (PRInt32 i=0;imKids.Count();i++) { SetPrintAsIs((PrintObject*)aPO->mKids[i], aAsIs); - } + } } //------------------------------------------------------- @@ -3204,7 +2952,7 @@ DocumentViewerImpl::SetPrintPO(PrintObject* aPO, PRBool aPrint) aPO->mDontPrint = !aPrint; for (PRInt32 i=0;imKids.Count();i++) { SetPrintPO((PrintObject*)aPO->mKids[i], aPrint); - } + } } //------------------------------------------------------- @@ -3214,7 +2962,7 @@ DocumentViewerImpl::SetPrintPO(PrintObject* aPO, PRBool aPrint) // NOTE: This MUST be done after the sub-doc has been laid out // This is called by "MapSubDocFrameLocations" // -nsresult +nsresult DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell, PrintObject* aPO) { @@ -3225,7 +2973,7 @@ DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell, // Find that frame for the sub-doc's content element // in the parent document - // if it comes back null it probably has the style + // if it comes back null it probably has the style // set to "display:none" nsIFrame * frame; aPresShell->GetPrimaryFrameFor(aPO->mContent, &frame); @@ -3255,9 +3003,9 @@ DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell, rect.y += rr.y; nsIFrame * temp = parent; temp->GetParent(&parent); - // Keep a pointer to the Seq and Page frames + // Keep a pointer to the Seq and Page frames nsIPageSequenceFrame * sqf = nsnull; - if (parent != nsnull && + if (parent != nsnull && NS_SUCCEEDED(CallQueryInterface(parent, &sqf)) && sqf) { pageFrame = temp; seqFrame = parent; @@ -3321,17 +3069,17 @@ DocumentViewerImpl::MapSubDocFrameLocations(PrintObject* aPO) // // This "maps" or figures out which sub-doc represents a // given Frame or IFrame in it's parent sub-doc. -// +// // So the Mcontent pointer in the child sub-doc points to the // content in the it's parent document, that caused it to be printed. // This is used later to (after reflow) to find the absolute location -// of the sub-doc on it's parent's page frame so it can be +// of the sub-doc on it's parent's page frame so it can be // printed in the correct location. // // This method recursvely "walks" the content for a document finding // all the Frames and IFrames, then sets the "mFrameType" data member // which tells us what type of PO we have -void +void DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, nsIPresShell* aPresShell, nsIContent* aContent) @@ -3340,38 +3088,19 @@ DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, NS_ASSERTION(aPresShell, "Pointer is null!"); NS_ASSERTION(aContent, "Pointer is null!"); - nsCOMPtr doc; - aContent->GetDocument(*getter_AddRefs(doc)); - - if (!doc) { - NS_ERROR("No document!"); - - return; - } - - nsCOMPtr subDoc; - doc->GetSubDocumentFor(aContent, getter_AddRefs(subDoc)); - - if (subDoc) { - nsCOMPtr container; - subDoc->GetContainer(getter_AddRefs(container)); - - nsCOMPtr presShell; - subDoc->GetShellAt(0, getter_AddRefs(presShell)); - - nsCOMPtr webShell(do_QueryInterface(container)); - - if (presShell && webShell) { + nsCOMPtr supps; + aPresShell->GetSubShellFor(aContent, getter_AddRefs(supps)); + if (supps) { + nsCOMPtr webShell(do_QueryInterface(supps)); + if (webShell) { PrintObject * po = FindPrintObjectByWS(aRootObject, webShell); NS_ASSERTION(po, "PO can't be null!"); - if (po) { + if (po != nsnull) { po->mContent = aContent; - // Now, "type" the PO - nsCOMPtr frameSet = - do_QueryInterface(aContent); - + // Now, "type" the PO + nsCOMPtr frameSet(do_QueryInterface(aContent)); if (frameSet) { po->mFrameType = eFrameSet; } else { @@ -3379,11 +3108,8 @@ DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, if (frame) { po->mFrameType = eFrame; } else { - nsCOMPtr objElement = - do_QueryInterface(aContent); - nsCOMPtr iFrame = - do_QueryInterface(aContent); - + nsCOMPtr objElement(do_QueryInterface(aContent)); + nsCOMPtr iFrame(do_QueryInterface(aContent)); if (iFrame || objElement) { po->mFrameType = eIFrame; po->mPrintAsIs = PR_TRUE; @@ -3409,11 +3135,11 @@ DocumentViewerImpl::MapContentForPO(PrintObject* aRootObject, //------------------------------------------------------- // The walks the PO tree and for each document it walks the content -// tree looking for any content that are sub-shells +// tree looking for any content that are sub-shells // -// It then sets the mContent pointer in the "found" PO object back to the +// It then sets the mContent pointer in the "found" PO object back to the // the document that contained it. -void +void DocumentViewerImpl::MapContentToWebShells(PrintObject* aRootPO, PrintObject* aPO) { @@ -3431,16 +3157,16 @@ DocumentViewerImpl::MapContentToWebShells(PrintObject* aRootPO, // Continue recursively walking the chilren of this PO for (PRInt32 i=0;imKids.Count();i++) { MapContentToWebShells(aRootPO, (PrintObject*)aPO->mKids[i]); - } + } } //------------------------------------------------------- // This gets ref counted copies of the PresShell and Root Content // for a given nsIWebShell -void -DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell, - nsIPresShell** aPresShell, +void +DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell, + nsIPresShell** aPresShell, nsIContent** aContent) { NS_ASSERTION(aWebShell, "Pointer is null!"); @@ -3466,8 +3192,8 @@ DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell, //------------------------------------------------------- // Recursively sets the clip rect on all thchildren -void -DocumentViewerImpl::SetClipRect(PrintObject* aPO, +void +DocumentViewerImpl::SetClipRect(PrintObject* aPO, const nsRect& aClipRect, nscoord aOffsetX, nscoord aOffsetY, @@ -3481,8 +3207,8 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, nscoord height = (aPO->mRect.y+aPO->mRect.height) > aClipRect.height?aClipRect.height-aPO->mRect.y:aPO->mRect.height; aPO->mClipRect.SetRect(aPO->mRect.x, aPO->mRect.y, width, height); - } - + } + PRBool doClip = aDoingSetClip; if (aPO->mFrameType == eFrame) { @@ -3523,7 +3249,7 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, PRInt32 cnt = aPO->mKids.Count(); for (PRInt32 i=0;imKids[i], clipRect, + SetClipRect((PrintObject *)aPO->mKids[i], clipRect, aOffsetX+aPO->mRect.x, aOffsetY+aPO->mRect.y, doClip); } } @@ -3531,12 +3257,12 @@ DocumentViewerImpl::SetClipRect(PrintObject* aPO, //------------------------------------------------------- // Recursively reflow each sub-doc and then calc // all the frame locations of the sub-docs -nsresult +nsresult DocumentViewerImpl::ReflowDocList(PrintObject* aPO, PRBool aSetPixelScale, PRBool aDoCalcShrink) { NS_ASSERTION(aPO, "Pointer is null!"); - // Here is where we set the shrinkage value into the DC + // Here is where we set the shrinkage value into the DC // and this is what actually makes it shrink if (aSetPixelScale && aPO->mFrameType != eIFrame) { float ratio; @@ -3548,7 +3274,7 @@ DocumentViewerImpl::ReflowDocList(PrintObject* aPO, PRBool aSetPixelScale, PRBoo mPrt->mPrintDC->SetCanonicalPixelScale(ratio*mPrt->mOrigDCScale); } - // Reflow the PO + // Reflow the PO if (NS_FAILED(ReflowPrintObject(aPO, aDoCalcShrink))) { return NS_ERROR_FAILURE; } @@ -3628,8 +3354,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) return rv; } - rv = document->CreateShell(aPO->mPresContext, aPO->mViewManager, - aPO->mStyleSet, getter_AddRefs(aPO->mPresShell)); + rv = document->CreateShell(aPO->mPresContext, aPO->mViewManager, aPO->mStyleSet, getter_AddRefs(aPO->mPresShell)); if (NS_FAILED(rv)) { return rv; } @@ -3639,7 +3364,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) PRInt32 width, height; if (aPO->mContent == nsnull || !aPO->mPrintAsIs || - (aPO->mPrintAsIs && aPO->mParent && !aPO->mParent->mPrintAsIs) || + (aPO->mPrintAsIs && aPO->mParent != nsnull && !aPO->mParent->mPrintAsIs) || (aPO->mFrameType == eIFrame && aPO == mPrt->mSelectedPO)) { width = pageWidth; height = pageHeight; @@ -3650,25 +3375,22 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) PRINT_DEBUG_MSG5("In DV::ReflowPrintObject PO: %p (%9s) Setting w,h to %d,%d\n", aPO, gFrameTypesStr[aPO->mFrameType], width, height); - nsCOMPtr domWinIntl = - do_QueryInterface(mPrt->mPrintDocDW); + nsCOMPtr domWinIntl(do_QueryInterface(mPrt->mPrintDocDW)); // XXX - Hack Alert - // OK, so ther eis a selection, we will print the entire selection + // OK, so ther eis a selection, we will print the entire selection // on one page and then crop the page. - // This means you can never print any selection that is longer than - // one page put it keeps it from page breaking in the middle of your - // print of the selection (see also nsSimplePageSequence.cpp) + // This means you can never print any selection that is longer than one page + // put it keeps it from page breaking in the middle of your print of the selection + // (see also nsSimplePageSequence.cpp) PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; if (mPrt->mPrintSettings != nsnull) { mPrt->mPrintSettings->GetPrintRange(&printRangeType); } - if (printRangeType == nsIPrintSettings::kRangeSelection && - IsThereARangeSelection(domWinIntl)) { + if (printRangeType == nsIPrintSettings::kRangeSelection && IsThereARangeSelection(domWinIntl)) { height = NS_UNCONSTRAINEDSIZE; } - nsRect tbounds = nsRect(0, 0, width, height); // Create a child window of the parent that is our "root view/window" @@ -3682,7 +3404,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) } #ifdef NS_PRINT_PREVIEW - // Here we decide whether we need scrollbars and + // Here we decide whether we need scrollbars and // what the parent will be of the widget if (mIsCreatingPrintPreview) { PRBool canCreateScrollbars = PR_FALSE; @@ -3694,17 +3416,16 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) NS_ASSERTION(frameMan, "No Frame manager!"); nsIFrame* frame; frameMan->GetPrimaryFrameFor(aPO->mContent, &frame); - if (frame && (aPO->mFrameType == eIFrame || aPO->mFrameType == eFrame)) { + if (frame != nsnull && (aPO->mFrameType == eIFrame || aPO->mFrameType == eFrame)) { frame->FirstChild(aPO->mParent->mPresContext, nsnull, &frame); } - - if (frame) { + if (frame != nsnull) { nsIView* view = nsnull; frame->GetView(aPO->mParent->mPresContext, &view); - if (view) { + if (view != nsnull) { nsCOMPtr w2; view->GetWidget(*getter_AddRefs(w2)); - if (w2) { + if (nsnull != w2) { widget = w2; } canCreateScrollbars = PR_FALSE; @@ -3755,9 +3476,9 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) // initialize it with the default/generic case nsRect adjRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height); - // XXX This is an arbitray height, + // XXX This is an arbitray height, // but reflow somethimes gets upset when using max int - // basically, we want to reflow a single page that is large + // basically, we want to reflow a single page that is large // enough to fit any atomic object like an IFrame const PRInt32 kFivePagesHigh = 5; @@ -3849,7 +3570,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) nsRect rect; child->GetRect(rect); - // Create a RenderingContext and set the PresContext + // Create a RenderingContext and set the PresContext // appropriately if we are printing selection nsCOMPtr rc; if (nsIPrintSettings::kRangeSelection == printRangeType) { @@ -3932,7 +3653,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink) //------------------------------------------------------- // Given a DOMWindow it recursively finds the PO object that matches -PrintObject* +PrintObject* DocumentViewerImpl::FindPrintObjectByDOMWin(PrintObject* aPO, nsIDOMWindowInternal * aDOMWin) { NS_ASSERTION(aPO, "Pointer is null!"); @@ -3966,11 +3687,12 @@ DocumentViewerImpl::GetDOMWinForWebShell(nsIWebShell* aWebShell) NS_ASSERTION(aWebShell, "Pointer is null!"); nsCOMPtr domWin = do_GetInterface(aWebShell); + if (!domWin) return nsnull; nsCOMPtr domWinInt(do_QueryInterface(domWin)); if (!domWinInt) return nsnull; - nsIDOMWindowInternal * dw = domWinInt.get(); + nsIDOMWindowInternal * dw = NS_STATIC_CAST(nsIDOMWindowInternal *, domWinInt.get()); NS_ADDREF(dw); return dw; @@ -3988,10 +3710,10 @@ DocumentViewerImpl::EnablePOsForPrinting() return NS_ERROR_FAILURE; } - mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; + mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); - PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages; @@ -4009,13 +3731,13 @@ DocumentViewerImpl::EnablePOsForPrinting() // then set the mPrintFrameType as if it were the selected frame if (printRangeType == nsIPrintSettings::kRangeSelection) { mPrt->mPrintFrameType = nsIPrintSettings::kSelectedFrame; - printHowEnable = nsIPrintSettings::kFrameEnableNone; + printHowEnable = nsIPrintSettings::kFrameEnableNone; } // This tells us that the "Frame" UI has turned off, // so therefore there are no FrameSets/Frames/IFrames to be printed // - // This means there are not FrameSets, + // This means there are not FrameSets, // but the document could contain an IFrame if (printHowEnable == nsIPrintSettings::kFrameEnableNone) { @@ -4041,7 +3763,7 @@ DocumentViewerImpl::EnablePOsForPrinting() PRINT_DEBUG_MSG2("PrintRange: %s \n", gPrintRangeStr[printRangeType]); return NS_OK; } - + // This means we are either printed a selected IFrame or // we are printing the current selection if (printRangeType == nsIPrintSettings::kRangeSelection) { @@ -4058,12 +3780,12 @@ DocumentViewerImpl::EnablePOsForPrinting() // Now, only enable this POs (the selected PO) and all of its children SetPrintPO(po, PR_TRUE); - // check to see if we have a range selection, + // check to see if we have a range selection, // as oppose to a insert selection - // this means if the user just clicked on the IFrame then + // this means if the user just clicked on the IFrame then // there will not be a selection so we want the entire page to print // - // XXX this is sort of a hack right here to make the page + // XXX this is sort of a hack right here to make the page // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { @@ -4105,12 +3827,12 @@ DocumentViewerImpl::EnablePOsForPrinting() // Now, only enable this POs (the selected PO) and all of its children SetPrintPO(po, PR_TRUE); - // check to see if we have a range selection, + // check to see if we have a range selection, // as oppose to a insert selection - // this means if the user just clicked on the IFrame then + // this means if the user just clicked on the IFrame then // there will not be a selection so we want the entire page to print // - // XXX this is sort of a hack right here to make the page + // XXX this is sort of a hack right here to make the page // not try to reposition itself when printing selection nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(po->mWebShell)); if (!IsThereARangeSelection(domWin)) { @@ -4141,9 +3863,9 @@ DocumentViewerImpl::EnablePOsForPrinting() PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCurrentFocusWin); if (po != nsnull) { mPrt->mSelectedPO = po; - // NOTE: Calling this sets the "po" and + // NOTE: Calling this sets the "po" and // we don't want to do this for documents that have no children, - // because then the "DoEndPage" gets called and it shouldn't + // because then the "DoEndPage" gets called and it shouldn't if (po->mKids.Count() > 0) { // Makes sure that itself, and all of its children are printed "AsIs" SetPrintAsIs(po); @@ -4154,10 +3876,10 @@ DocumentViewerImpl::EnablePOsForPrinting() } } return NS_OK; - } - - // If we are print each subdoc separately, - // then don't print any of the FraneSet Docs + } + + // If we are print each subdoc separately, + // then don't print any of the FraneSet Docs if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { SetPrintPO(mPrt->mPrintObject, PR_TRUE); PRInt32 cnt = mPrt->mPrintDocList->Count(); @@ -4175,11 +3897,11 @@ DocumentViewerImpl::EnablePOsForPrinting() //--------------------------------------------------- // Find the Frame in a Frame List that is XMost -void -DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, +void +DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, nsIRenderingContext* aRC, nsIAtom* aList, - nsIFrame* aFrame, + nsIFrame* aFrame, nscoord aX, nscoord aY, PRInt32& aMaxWidth) @@ -4188,7 +3910,7 @@ DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, aFrame->FirstChild(aPresContext, aList, &child); while (child) { PRBool isVisible = PR_TRUE; - // If the aRC is nsnull, then we skip the more expensive check and + // If the aRC is nsnull, then we skip the more expensive check and // just check visibility if (aRC) { child->IsVisibleForPainting(aPresContext, *aRC, PR_TRUE, &isVisible); @@ -4241,10 +3963,10 @@ DocumentViewerImpl::FindXMostFrameInList(nsIPresContext* aPresContext, //--------------------------------------------------- // Find the Frame that is XMost -void -DocumentViewerImpl::FindXMostFrameSize(nsIPresContext* aPresContext, +void +DocumentViewerImpl::FindXMostFrameSize(nsIPresContext* aPresContext, nsIRenderingContext* aRC, - nsIFrame* aFrame, + nsIFrame* aFrame, nscoord aX, nscoord aY, PRInt32& aMaxWidth) @@ -4259,15 +3981,15 @@ DocumentViewerImpl::FindXMostFrameSize(nsIPresContext* aPresContext, FindXMostFrameInList(aPresContext, aRC, childListName, aFrame, aX, aY, aMaxWidth); NS_IF_RELEASE(childListName); aFrame->GetAdditionalChildListName(childListIndex++, &childListName); - } while (childListName); + } while (childListName); } //------------------------------------------------------- -// Return the PrintObject with that is XMost (The widest frameset frame) AND -// contains the XMost (widest) layout frame -PrintObject* +// Return the PrintObject with that is XMost (The widest frameset frame) AND +// contains the XMost (widest) layout frame +PrintObject* DocumentViewerImpl::FindXMostPO() { nscoord xMostForPO = 0; @@ -4375,7 +4097,7 @@ DocumentViewerImpl::SetupToPrintContent(nsIWebShell* aParent, PRINT_DEBUG_MSG1("\n-------------------------------------------------------\n\n"); // Set up the clipping rectangle for all documents - // When frames are being printed as part of a frame set and also IFrames, + // When frames are being printed as part of a frame set and also IFrames, // they are reflowed with a very large page height. We need to setup the // clipping so they do not rpint over top of anything else PRINT_DEBUG_MSG1("SetClipRect-------------------------------------------------------\n"); @@ -4410,7 +4132,7 @@ DocumentViewerImpl::SetupToPrintContent(nsIWebShell* aParent, // This will print the webshell document // when it completes asynchronously in the DonePrintingPages method - // it will check to see if there are more webshells to be printed and + // it will check to see if there are more webshells to be printed and // then PrintDocContent will be called again. nsresult rv = NS_OK; @@ -4467,7 +4189,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (aPO->mFrameType == eFrame) { switch (mPrt->mPrintFrameType) { - case nsIPrintSettings::kFramesAsIs: + case nsIPrintSettings::kFramesAsIs: skipAllPageAdjustments = PR_TRUE; doOffsetting = PR_TRUE; break; @@ -4516,7 +4238,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a skipPageEjectOnly = aPO->mPrintAsIs; } - // That we are all configured, + // That we are all configured, // let's set everything up to print if (skipPageEjectOnly) { pageSequence->SkipPageEnd(); @@ -4550,8 +4272,8 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a } } - PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s skipAllPageAdjustments: %s doOffsetting: %s doAddInParentsOffset: %s\n", - PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments), + PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s skipAllPageAdjustments: %s doOffsetting: %s doAddInParentsOffset: %s\n", + PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments), PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset)); // mPrt->mDebugFilePtr this is onlu non-null when compiled for debugging @@ -4565,7 +4287,7 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { fdbg->DumpRegressionData(poPresContext, mPrt->mDebugFilePtr, 0, PR_TRUE); } - fclose(mPrt->mDebugFilePtr); + fclose(mPrt->mDebugFilePtr); #endif } else { nsIFrame* rootFrame; @@ -4586,10 +4308,9 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (!skipSetTitle) { PRUnichar * docTitleStr; PRUnichar * docURLStr; - GetDisplayTitleAndURL(aPO, mPrt->mPrintSettings, mPrt->mBrandName, - &docTitleStr, &docURLStr, eDocTitleDefBlank); + GetDisplayTitleAndURL(aPO, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefBlank); - // Set them down into the PrintOptions so + // Set them down into the PrintOptions so // they can used by the DeviceContext if (docTitleStr) { mPrt->mPrintOptions->SetTitle(docTitleStr); @@ -4623,8 +4344,8 @@ DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& a if (NS_SUCCEEDED(rvv) && selectionPS) { } - rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence, - &startFrame, startPageNum, startRect, + rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence, + &startFrame, startPageNum, startRect, &endFrame, endPageNum, endRect); if (NS_SUCCEEDED(rv)) { mPrt->mPrintSettings->SetStartPageRange(startPageNum); @@ -4795,7 +4516,7 @@ DocumentViewerImpl::PrintDocContent(PrintObject* aPO, nsresult& aStatus) if (!aPO->mHasBeenPrinted && aPO->IsPrintable()) { PRBool donePrinting; // donePrinting is only valid when when doing synchronous printing - aStatus = DoPrint(aPO, PR_FALSE, donePrinting); + aStatus = DoPrint(aPO, PR_FALSE, donePrinting); if (donePrinting) { return PR_TRUE; } @@ -4807,8 +4528,8 @@ DocumentViewerImpl::PrintDocContent(PrintObject* aPO, nsresult& aStatus) if (printed || NS_FAILED(aStatus)) { return PR_TRUE; } - } - return PR_FALSE; + } + return PR_FALSE; } NS_IMETHODIMP @@ -4819,11 +4540,11 @@ DocumentViewerImpl::SetEnableRendering(PRBool aOn) if (mViewManager) { if (aOn) { mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - nsIView* view; - mViewManager->GetRootView(view); // views are not refCounted - if (view) { + nsIView* view; + mViewManager->GetRootView(view); // views are not refCounted + if (view) { mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); - } + } } else { mViewManager->DisableRefresh(); @@ -4883,7 +4604,7 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, } } - nsCOMPtr chromeRegistry = + nsCOMPtr chromeRegistry = do_GetService("@mozilla.org/chrome/chrome-registry;1", &rv); if (NS_SUCCEEDED(rv) && chromeRegistry) { nsCOMPtr sheets; @@ -4939,7 +4660,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, nsCOMPtr dx; mPresContext->GetDeviceContext(getter_AddRefs(dx)); - + nsRect tbounds = aBounds; float p2t; mPresContext->GetPixelsToTwips(&p2t); @@ -4954,11 +4675,11 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; - // Reset the bounds offset so the root view is set to 0,0. The - // offset is specified in nsIViewManager::Init above. - // Besides, layout will reset the root view to (0,0) during reflow, - // so changing it to 0,0 eliminates placing the root view in the - // wrong place initially. + // Reset the bounds offset so the root view is set to 0,0. The offset is + // specified in nsIViewManager::Init above. + // Besides, layout will reset the root view to (0,0) during reflow, + // so changing it to 0,0 eliminates placing + // the root view in the wrong place initially. tbounds.x = 0; tbounds.y = 0; @@ -4973,7 +4694,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, nsIView* containerView = nsnull; if (NS_SUCCEEDED(aParentWidget->GetClientData(clientData))) { nsISupports* data = (nsISupports*)clientData; - + if (nsnull != data) { data->QueryInterface(NS_GET_IID(nsIView), (void **)&containerView); } @@ -4997,7 +4718,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, // // If the parent container is a chrome shell, or a frameset, then we won't hook into its view // tree. This will improve performance a little bit (especially given scrolling/painting perf bugs) - // but is really just for peace of mind. This check can be removed if we want to support fancy + // but is really just for peace of mind. This check can be removed if we want to support fancy // chrome effects like transparent controls floating over content, transparent Web browsers, and // things like that, and the perf bugs are fixed. nsCOMPtr container(do_QueryInterface(mContainer)); @@ -5054,8 +4775,8 @@ nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection, nsI nsCOMPtr selcon; selcon = do_QueryInterface(aPresShell); - if (selcon) - return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); + if (selcon) + return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); return NS_ERROR_FAILURE; } @@ -5067,13 +4788,13 @@ DocumentViewerImpl::CreateDocumentViewerUsing(nsIPresContext* aPresContext, // XXX better error return NS_ERROR_NULL_POINTER; } - if (!aPresContext) { + if (nsnull == aPresContext) { return NS_ERROR_NULL_POINTER; } // Create new viewer DocumentViewerImpl* viewer = new DocumentViewerImpl(aPresContext); - if (!viewer) { + if (nsnull == viewer) { return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(viewer); @@ -5084,7 +4805,7 @@ DocumentViewerImpl::CreateDocumentViewerUsing(nsIPresContext* aPresContext, // Bind the new viewer to the old document nsresult rv = viewer->LoadStart(mDocument); - + aResult = viewer; return rv; @@ -5133,7 +4854,7 @@ nsresult DocumentViewerImpl::DocumentReadyForPrinting() return rv; } -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::SetTransformMediator(nsITransformMediator* aMediator) { NS_ASSERTION(nsnull == mTransformMediator, "nsXMLDocument::SetTransformMediator(): \ @@ -5185,7 +4906,7 @@ NS_IMETHODIMP DocumentViewerImpl::SelectAll() nsCOMPtr htmldoc = do_QueryInterface(mDocument); nsCOMPtr bodyNode; - + if (htmldoc) { nsCOMPtrbodyElement; @@ -5200,8 +4921,8 @@ NS_IMETHODIMP DocumentViewerImpl::SelectAll() mDocument->GetRootContent(getter_AddRefs(rootContent)); bodyNode = do_QueryInterface(rootContent); } - if (!bodyNode) return NS_ERROR_FAILURE; - + if (!bodyNode) return NS_ERROR_FAILURE; + rv = selection->RemoveAllRanges(); if (NS_FAILED(rv)) return rv; @@ -5254,10 +4975,10 @@ NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable) nsresult rv; rv = GetDocumentSelection(getter_AddRefs(selection)); if (NS_FAILED(rv)) return rv; - + PRBool isCollapsed; selection->GetIsCollapsed(&isCollapsed); - + *aCopyable = !isCollapsed; return NS_OK; } @@ -5342,7 +5063,7 @@ nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpe if (NS_FAILED(rv)) { return rv; } rv = htmlElement->AppendChildTo(bodyElement, PR_FALSE, PR_FALSE); if (NS_FAILED(rv)) { return rv; } - + // load the document into the docshell nsCOMPtr domDoc = do_QueryInterface(doc); if (!domDoc) { return NS_ERROR_NULL_POINTER; } @@ -5360,8 +5081,8 @@ nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpe } //------------------------------------------------------ -PRBool -DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, +PRBool +DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, nsIDOMWindowInternal * aDOMWin, PRPackedBool& aIsParentFrameSet) { @@ -5377,7 +5098,7 @@ DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, // if so, it means the selected frame is either the main webshell // or an IFRAME if (aDOMWin != nsnull) { - // Get the main webshell's DOMWin to see if it matches + // Get the main webshell's DOMWin to see if it matches // the frame that is selected nsCOMPtr domWin = getter_AddRefs(GetDOMWinForWebShell(aWebShell)); if (aDOMWin != nsnull && domWin != aDOMWin) { @@ -5391,7 +5112,7 @@ DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, //------------------------------------------------------ -PRBool +PRBool DocumentViewerImpl::IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin) { nsCOMPtr presShell; @@ -5426,7 +5147,7 @@ DocumentViewerImpl::IsThereARangeSelection(nsIDOMWindowInternal * aDOMWin) //------------------------------------------------------- // Recursively walks the PrintObject tree and installs the DocViewer // as an event processor and it shows the window -nsresult +nsresult DocumentViewerImpl::ShowDocList(PrintObject* aPO, PRBool aShow) { NS_ASSERTION(aPO, "Pointer is null!"); @@ -5485,7 +5206,7 @@ DocumentViewerImpl::InstallPrintPreviewListener() //---------------------------------------------------------------------- static nsresult GetSeqFrameAndCountPages(PrintObject* aPO, - nsIFrame*& aSeqFrame, + nsIFrame*& aSeqFrame, PRInt32& aCount) { NS_ENSURE_ARG_POINTER(aPO); @@ -5632,7 +5353,7 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) } /* readonly attribute boolean isFramesetDocument; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) { nsCOMPtr webContainer(do_QueryInterface(mContainer)); @@ -5681,7 +5402,7 @@ DocumentViewerImpl::GetIsFramesetFrameSelected(PRBool *aIsFramesetFrameSelected) } /* readonly attribute long printPreviewNumPages; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) { NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages); @@ -5698,7 +5419,7 @@ DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages) } /* void exitPrintPreview (); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::ExitPrintPreview() { if (mIsDoingPrintPreview) { @@ -5744,7 +5465,7 @@ DocumentViewerImpl::InstallNewPresentation() nsCOMPtr selection; nsresult rv = GetDocumentSelection(getter_AddRefs(selection)); nsCOMPtr selPrivate(do_QueryInterface(selection)); - if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) + if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) selPrivate->RemoveSelectionListener(mSelectionListener); // We need to destroy the PreShell if there is an existing PP @@ -5780,7 +5501,7 @@ DocumentViewerImpl::InstallNewPresentation() // This is the new code for selecting the appropriate Frame of a Frameset // for Print Preview. But it can't be turned on yet -#if 0 +#if 0 // If it is a Frameset then choose the selected one // or select the one with the largest area if (mPrt->mPrintObject->mFrameType == eFrameSet) { @@ -5898,7 +5619,7 @@ DocumentViewerImpl::ReturnToGalleyPresentation() nsCOMPtr selection; nsresult rv = GetDocumentSelection(getter_AddRefs(selection)); nsCOMPtr selPrivate(do_QueryInterface(selection)); - if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) + if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener) selPrivate->RemoveSelectionListener(mSelectionListener); mPresShell->Destroy(); } @@ -5959,7 +5680,7 @@ DocumentViewerImpl::ReturnToGalleyPresentation() // This method checks to see if there is at least one printer defined // and if so, it sets the first printer in the list as the default name // in the PrintSettings which is then used for Printer Preview -nsresult +nsresult DocumentViewerImpl::CheckForPrinters(nsIPrintOptions* aPrintOptions, nsIPrintSettings* aPrintSettings, PRUint32 aErrorCode, @@ -5977,7 +5698,7 @@ DocumentViewerImpl::CheckForPrinters(nsIPrintOptions* aPrintOptions, simpEnum->HasMoreElements(&fndPrinter); if (fndPrinter) { // For now, it assumes the first item in the list - // is the default printer, but only set the + // is the default printer, but only set the // printer name if there isn't one nsCOMPtr supps; simpEnum->GetNext(getter_AddRefs(supps)); @@ -6104,36 +5825,23 @@ DocumentViewerImpl::CheckDocumentForPPCaching() * See documentation above in the nsIContentViewerfile class definition * @update 11/01/01 rods * - * For a full and detailed understanding of the issues with - * PrintPreview: See the design spec that is attached to Bug 107562 + * For a full and detailed understanding of the issues with + * PrintPreview: See the design spec that is attached to Bug 107562 */ NS_IMETHODIMP DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) { - nsCOMPtr docShell(do_QueryInterface(mContainer)); - NS_ASSERTION(docShell, "This has to be a docshell"); - - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - // A frame that's not displayed can't be printed! - - return NS_OK; - } - - + // Get the webshell for this documentviewer + nsCOMPtr webContainer(do_QueryInterface(mContainer)); + // Get the DocShell and see if it is busy + // We can't Print or Print Preview this document if it is still busy + nsCOMPtr docShell(do_QueryInterface(webContainer)); + NS_ASSERTION(docShell.get(), "This has to be a docshell"); PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE; - - if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) || - busyFlags != nsIDocShell::BUSY_FLAGS_NONE) { + if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) || busyFlags != nsIDocShell::BUSY_FLAGS_NONE) { ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP, PR_FALSE); return NS_ERROR_FAILURE; } - - // Get the webshell for this documentviewer - nsCOMPtr webContainer(do_QueryInterface(mContainer)); - nsresult rv = NS_OK; #if defined(XP_PC) && defined(DEBUG_rods) && defined(DEBUG_PRINTING) @@ -6164,13 +5872,12 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) mOldPrtPreview->mCachedPresObj = nsnull; } - // You have to have both a PrintOptions and a PrintSetting to call - // CheckForPrinters. - // The user can pass in a null PrintSettings, but you can only - // create one if you have a PrintOptions. So we we might as check - // to if we have a PrintOptions first, because we can't do anything - // below without it then inside we check to se if the printSettings - // is null to know if we need to create on. + // You have to have both a PrintOptions and a PrintSetting to call CheckForPrinters. + // The user can pass in a null PrintSettings, + // but you can only create one if you have a PrintOptions. + // So we we might as check to if we have a PrintOptions first, + // because we can't do anything below without it + // then inside we check to se if the printSettings is null to know if we need to create on. mPrt->mPrintSettings = aPrintSettings; mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) { @@ -6187,7 +5894,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) return NS_ERROR_FAILURE; } } - + // Let's print ... mIsCreatingPrintPreview = PR_TRUE; mIsDoingPrintPreview = PR_TRUE; @@ -6224,7 +5931,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject); mPrt->mIsParentAFrameSet = IsParentAFrameSet(webContainer); - mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet ? eFrameSet : eDoc; + mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet?eFrameSet:eDoc; // Build the "tree" of PrintObjects nsCOMPtr parentAsNode(do_QueryInterface(webContainer)); @@ -6234,8 +5941,8 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) // in the parent document MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject); - // Get whether the doc contains a frameset - // Also, check to see if the currently focus webshell + // Get whether the doc contains a frameset + // Also, check to see if the currently focus webshell // is a child of this webshell mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet); @@ -6262,7 +5969,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) #ifdef DEBUG_PRINTING if (mPrt->mPrintSettings) { - PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); @@ -6290,7 +5997,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) nsCOMPtr dx; nsresult rv = factory->CreateDeviceContextSpec(mWindow, aPrintSettings, *getter_AddRefs(devspec), doSilent); if (NS_SUCCEEDED(rv)) { - rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); + rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); if (NS_SUCCEEDED(rv)) { mDeviceContext->SetAltDevice(ppDC); if (mPrt->mPrintSettings != nsnull) { @@ -6317,7 +6024,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) mPrt->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); } - mPrt->mPrintDC = mDeviceContext; + mPrt->mPrintDC = mDeviceContext; // Get the Original PixelScale incase we need to start changing it mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); @@ -6347,8 +6054,8 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) } /* cleanup done, let's fire-up an error dialog to notify the user - * what went wrong... - */ + * what went wrong... + */ ShowPrintErrorDialog(rv, PR_FALSE); TurnScriptingOn(PR_TRUE); mIsCreatingPrintPreview = PR_FALSE; @@ -6357,7 +6064,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) } - // At this point we are done preparing everything + // At this point we are done preparing everything // before it is to be created // Noew create the new Presentation and display it @@ -6454,7 +6161,7 @@ DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting) */ NS_IMETHODIMP DocumentViewerImpl::Print(PRBool aSilent, - FILE * aDebugFile, + FILE * aDebugFile, nsIPrintSettings* aPrintSettings) { nsCOMPtr printSettings; @@ -6478,7 +6185,7 @@ DocumentViewerImpl::Print(PRBool aSilent, return Print(printSettings, nsnull); - + } /** --------------------------------------------------- @@ -6497,17 +6204,6 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr docShell(do_QueryInterface(mContainer)); - NS_ASSERTION(docShell, "This has to be a docshell"); - - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - // A frame that's not displayed can't be printed! - - return NS_OK; - } if (mIsDoingPrintPreview) { PRBool okToPrint = PR_FALSE; @@ -6522,7 +6218,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, } // if we are printing another URL, then exit - // the reason we check here is because this method can be called while + // the reason we check here is because this method can be called while // another is still in here (the printing dialog is a good example). // the only time we can print more than one job at a time is the regression tests if (mIsDoingPrinting) { @@ -6531,7 +6227,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, ShowPrintErrorDialog(rv); return rv; } - + mPrt = new PrintData(); if (mPrt == nsnull) { return NS_ERROR_OUT_OF_MEMORY; @@ -6570,7 +6266,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener); NS_ADDREF(aWebProgressListener); } - + // Get the currently focused window and cache it // because the Print Dialog will "steal" focus and later when you try // to get the currently focused windows it will be NULL @@ -6612,8 +6308,8 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject); - // Get whether the doc contains a frameset - // Also, check to see if the currently focus webshell + // Get whether the doc contains a frameset + // Also, check to see if the currently focus webshell // is a child of this webshell mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet); @@ -6635,7 +6331,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, #ifdef DEBUG_PRINTING if (mPrt->mPrintSettings) { - PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; + PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val); @@ -6654,7 +6350,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, /* create factory (incl. create print dialog) */ nsCOMPtr factory = do_CreateInstance(kDeviceContextSpecFactoryCID, &rv); - + if (NS_SUCCEEDED(rv)) { #ifdef DEBUG_dcone printf("PRINT JOB STARTING\n"); @@ -6776,7 +6472,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); } else { - // First find out from the PrinService what options are available + // First find out from the PrinService what options are available // to us for Printing FrameSets PRInt16 howToEnableFrameUI; mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); @@ -6821,14 +6517,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, PRUnichar * docTitleStr; PRUnichar * docURLStr; - GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, - mPrt->mBrandName, &docTitleStr, &docURLStr, - eDocTitleDefURLDoc); + GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); // BeginDocument may pass back a FAILURE code - // i.e. On Windows, if you are printing to a file and hit "Cancel" + // i.e. On Windows, if you are printing to a file and hit "Cancel" // to the "File Name" dialog, this comes back as an error - // Don't start printing when regression test are executed + // Don't start printing when regression test are executed rv = mPrt->mDebugFilePtr ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr); PRINT_DEBUG_MSG1("****************** Begin Document ************************\n"); @@ -6841,12 +6535,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, // Print listener setup... if (mPrt != nsnull) { - mPrt->OnStartPrinting(); + mPrt->OnStartPrinting(); } // // The mIsPrinting flag is set when the ImageGroup observer is - // notified that images must be loaded as a result of the + // notified that images must be loaded as a result of the // InitialReflow... // if(!mIsPrinting || mPrt->mDebugFilePtr) { @@ -6859,18 +6553,20 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, } } } - } + } } else { mPrt->mPrintSettings->SetIsCancelled(PR_TRUE); mPrt->mPrintOptions->SetIsCancelled(PR_TRUE); } - - // Set that we are once again in print preview + + // Set that we are once again in print preview if ( mIsDoingPrintPreview == PR_TRUE) { aPrintSettings->SetIsPrintPreview(PR_TRUE); } } + + /* cleaup on failure + notify user */ if (NS_FAILED(rv)) { /* cleanup... */ @@ -6878,7 +6574,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPagePrintTimer->Stop(); NS_RELEASE(mPagePrintTimer); } - + if (mPrt) { delete mPrt; mPrt = nsnull; @@ -6886,16 +6582,16 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mIsDoingPrinting = PR_FALSE; /* cleanup done, let's fire-up an error dialog to notify the user - * what went wrong... - * - * When rv == NS_ERROR_ABORT, it means we want out of the + * what went wrong... + * + * When rv == NS_ERROR_ABORT, it means we want out of the * print job without displaying any error messages */ if (rv != NS_ERROR_ABORT) { ShowPrintErrorDialog(rv); } } - + return rv; } @@ -6904,19 +6600,19 @@ void DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) { nsresult rv; - + static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); nsCOMPtr stringBundleService = do_GetService(kCStringBundleServiceCID); - - if (!stringBundleService) { + + if (!stringBundleService) { NS_WARNING("ERROR: Failed to get StringBundle Service instance.\n"); return; } nsCOMPtr myStringBundle; - rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); - if (NS_FAILED(rv)) + rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); + if (NS_FAILED(rv)) return; - + nsXPIDLString msg, title; nsAutoString stringName; @@ -6957,7 +6653,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin default: NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG(NS_ERROR_FAILURE) -#undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG +#undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG } myStringBundle->GetStringFromName(stringName.get(), getter_Copies(msg)); @@ -6969,7 +6665,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin if (!msg) return; - + nsCOMPtr wwatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv); if (NS_FAILED(rv)) return; @@ -6980,22 +6676,27 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin nsCOMPtr parent = do_QueryInterface(active, &rv); if (NS_FAILED(rv)) return; - - nsCOMPtr dialog; - parent->GetPrompter(getter_AddRefs(dialog)); + + nsCOMPtr dialog; + parent->GetPrompter(getter_AddRefs(dialog)); if (!dialog) return; - + dialog->Alert(title, msg); } // nsIContentViewerFile interface NS_IMETHODIMP -DocumentViewerImpl::GetPrintable(PRBool *aPrintable) +DocumentViewerImpl::GetPrintable(PRBool *aPrintable) { NS_ENSURE_ARG_POINTER(aPrintable); - *aPrintable = !mIsDoingPrinting; + + if(mIsDoingPrinting==PR_TRUE){ + *aPrintable = PR_FALSE; + } else { + *aPrintable = PR_TRUE; + } return NS_OK; } @@ -7006,7 +6707,7 @@ DocumentViewerImpl::GetPrintable(PRBool *aPrintable) //***************************************************************************** // nsIMarkupDocumentViewer -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) { @@ -7015,25 +6716,25 @@ NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) nsCOMPtr presShell; NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); - // Get the nsIContent interface, because that's what we need to + // Get the nsIContent interface, because that's what we need to // get the primary frame - + nsCOMPtr content(do_QueryInterface(aNode)); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); // Get the primary frame - nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their + nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their // own special little world. NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame), NS_ERROR_FAILURE); // tell the pres shell to scroll to the frame - NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, - NS_PRESSHELL_SCROLL_TOP, - NS_PRESSHELL_SCROLL_ANYWHERE), - NS_ERROR_FAILURE); - return NS_OK; + NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, + NS_PRESSHELL_SCROLL_TOP, + NS_PRESSHELL_SCROLL_ANYWHERE), + NS_ERROR_FAILURE); + return NS_OK; } NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins) @@ -7059,17 +6760,17 @@ DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure) PRInt32 i; PRInt32 n; docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) + for (i=0; i < n; i++) { nsCOMPtr child; docShellNode->GetChildAt(i, getter_AddRefs(child)); nsCOMPtr childAsShell(do_QueryInterface(child)); NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) + if (childAsShell) { nsCOMPtr childCV; childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) + if (childCV) { nsCOMPtr markupCV = do_QueryInterface(childCV); if (markupCV) { @@ -7120,7 +6821,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) return NS_OK; } -// XXX: SEMANTIC CHANGE! +// XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aDefaultCharacterSet) NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) @@ -7128,18 +6829,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCha NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); NS_ENSURE_STATE(mContainer); - if (mDefaultCharacterSet.IsEmpty()) + if (mDefaultCharacterSet.IsEmpty()) { nsXPIDLString defCharset; nsCOMPtr webShell; webShell = do_QueryInterface(mContainer); if (webShell) - { + { nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); if (prefs) prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset)); - } + } if (!defCharset.IsEmpty()) mDefaultCharacterSet.Assign(defCharset.get()); @@ -7164,7 +6865,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefau (void*) aDefaultCharacterSet); } -// XXX: SEMANTIC CHANGE! +// XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aForceCharacterSet) NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet) @@ -7194,7 +6895,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCh return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet); } -// XXX: SEMANTIC CHANGE! +// XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aHintCharacterSet) NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) @@ -7279,7 +6980,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetBidiTextDirection(PRUint8* aTextDirection) #endif return NS_OK; } - + NS_IMETHODIMP DocumentViewerImpl::SetBidiTextType(PRUint8 aTextType) { #ifdef IBMBIDI @@ -7435,9 +7136,9 @@ NS_IMETHODIMP DocumentViewerImpl::SetBidiOptions(PRUint32 aBidiOptions) #ifdef IBMBIDI if (mPresContext) { #if 1 - // forcing reflow will cause bug 80352. Temp turn off force reflow and + // forcing reflow will cause bug 80352. Temp turn off force reflow and // wait for simon@softel.co.il to find the real solution - mPresContext->SetBidi(aBidiOptions, PR_FALSE); + mPresContext->SetBidi(aBidiOptions, PR_FALSE); #else mPresContext->SetBidi(aBidiOptions, PR_TRUE); // force reflow #endif @@ -7472,7 +7173,7 @@ NS_IMETHODIMP DocumentViewerImpl::SizeToContent() nsCOMPtr docShellParent; docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); - // It's only valid to access this from a top frame. Doesn't work from + // It's only valid to access this from a top frame. Doesn't work from // sub-frames. NS_ENSURE_TRUE(!docShellParent, NS_ERROR_FAILURE); @@ -7561,7 +7262,7 @@ DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode) // get the internal dom window nsCOMPtr internalWin(do_QueryInterface(global, &rv)); NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(internalWin, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(internalWin, NS_ERROR_FAILURE); // get the private dom window nsCOMPtr privateWin(do_QueryInterface(internalWin, &rv)); @@ -7733,20 +7434,20 @@ NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocumen if (!mGotSelectionState || mSelectionWasCollapsed != selectionCollapsed) { nsCOMPtr theDoc; - mDocViewer->GetDocument(*getter_AddRefs(theDoc)); + mDocViewer->GetDocument(*getter_AddRefs(theDoc)); if (!theDoc) return NS_ERROR_FAILURE; - + nsCOMPtr scriptGlobalObject; theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); nsCOMPtr domWindow = do_QueryInterface(scriptGlobalObject); if (!domWindow) return NS_ERROR_FAILURE; - + domWindow->UpdateCommands(NS_LITERAL_STRING("select")); mGotSelectionState = PR_TRUE; mSelectionWasCollapsed = selectionCollapsed; - } - + } + return NS_OK; } @@ -7783,7 +7484,7 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) selCon->GetDisplaySelection( &selectionStatus); //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. + //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_DISABLED || selectionStatus == nsISelectionController::SELECTION_HIDDEN) { @@ -7797,7 +7498,7 @@ NS_IMETHODIMP nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; - if(!mDocViewer) + if(!mDocViewer) return NS_ERROR_FAILURE; nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref @@ -7807,7 +7508,7 @@ nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) selCon = do_QueryInterface(shell); PRInt16 selectionStatus; selCon->GetDisplaySelection(&selectionStatus); - + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_ON) @@ -7827,7 +7528,7 @@ nsDocViewerFocusListener::Init(DocumentViewerImpl *aDocViewer) } -PRBool +PRBool DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) { PRBool found = PR_FALSE; @@ -7868,7 +7569,7 @@ DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) //---------------------------------------------------------------------------------- -void +void DocumentViewerImpl::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) { for (PRInt32 i = aCount - 1; i >= 0; i--) { @@ -7881,8 +7582,8 @@ DocumentViewerImpl::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) //---------------------------------------------------------------------------------- // Enumerate all the documents for their titles -NS_IMETHODIMP -DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, +NS_IMETHODIMP +DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, PRUnichar*** aResult) { NS_ENSURE_ARG(aCount); @@ -7890,12 +7591,12 @@ DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, *aCount = 0; *aResult = nsnull; - + PRInt32 numDocs = mPrt->mPrintDocList->Count(); PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numDocs * sizeof(PRUnichar*)); - if (!array) + if (!array) return NS_ERROR_OUT_OF_MEMORY; - + for (PRInt32 i=0;imPrintDocList->ElementAt(i); NS_ASSERTION(po, "PrintObject can't be null!"); @@ -7928,7 +7629,7 @@ DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, } /* readonly attribute nsIPrintSettings newPrintSettings; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) { NS_ENSURE_ARG_POINTER(aNewPrintSettings); @@ -7943,7 +7644,7 @@ DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) } /* readonly attribute wstring defaultPrinterName; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName) { NS_ENSURE_ARG_POINTER(aDefaultPrinterName); @@ -7957,7 +7658,7 @@ DocumentViewerImpl::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName) } /* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings) { NS_ENSURE_ARG_POINTER(aPrintSettings); @@ -7979,7 +7680,7 @@ DocumentViewerImpl::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, } /* readonly attribute nsIPrintSettings globalPrintSettings; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings) { NS_ENSURE_ARG_POINTER(aGlobalPrintSettings); @@ -8002,7 +7703,7 @@ DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) } /* readonly attribute nsIPrintSettings currentPrintSettings; */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings) { NS_ENSURE_ARG_POINTER(aCurrentPrintSettings); @@ -8021,7 +7722,7 @@ DocumentViewerImpl::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSet } /* void cancel (); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::Cancel() { nsresult rv; @@ -8033,7 +7734,7 @@ DocumentViewerImpl::Cancel() } /* void initPrintSettingsFromPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags) { nsresult rv; @@ -8045,7 +7746,7 @@ DocumentViewerImpl::InitPrintSettingsFromPrefs(nsIPrintSettings *aPrintSettings, } /* void savePrintSettingsToPrefs (in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); */ -NS_IMETHODIMP +NS_IMETHODIMP DocumentViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, PRBool aUsePrinterNamePrefix, PRUint32 aFlags) { nsresult rv; @@ -8058,7 +7759,7 @@ DocumentViewerImpl::SavePrintSettingsToPrefs(nsIPrintSettings *aPrintSettings, P /** --------------------------------------------------- * Get the Focused Frame for a documentviewer - * + * */ nsIDOMWindowInternal* DocumentViewerImpl::FindFocusedDOMWindowInternal() @@ -8069,7 +7770,7 @@ DocumentViewerImpl::FindFocusedDOMWindowInternal() nsCOMPtr focusController; nsIDOMWindowInternal * domWin = nsnull; - this->GetDocument(*getter_AddRefs(theDoc)); + this->GetDocument(*getter_AddRefs(theDoc)); if(theDoc){ theDoc->GetScriptGlobalObject(getter_AddRefs(theSGO)); if(theSGO){ @@ -8095,7 +7796,7 @@ DocumentViewerImpl::FindFocusedDOMWindowInternal() /*=============== Timer Related Code ======================*/ nsresult -DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, +DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, nsIPrintSettings* aPrintSettings, PrintObject* aPOect, PRUint32 aDelay) diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 8293f2fc5b2..e018c206ce5 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -265,6 +265,28 @@ public: NS_IMETHOD GetLayoutObjectFor(nsIContent* aContent, nsISupports** aResult) const = 0; + /** + * Returns the object that acts as a subshell for aContent. + * For example, for an html frame aResult will be an nsIDocShell. + */ + NS_IMETHOD GetSubShellFor(nsIContent* aContent, + nsISupports** aResult) const = 0; + + /** + * Establish a relationship between aContent and aSubShell. + * aSubShell will be returned from GetSubShellFor(aContent, ...); + */ + NS_IMETHOD SetSubShellFor(nsIContent* aContent, + nsISupports* aSubShell) = 0; + + /** + * Find the content in the map that has aSubShell set + * as its subshell. If there is more than one mapping for + * aSubShell, the result is undefined. + */ + NS_IMETHOD FindContentForShell(nsISupports* aSubShell, + nsIContent** aContent) const = 0; + /** * Gets the placeholder frame associated with the specified frame. This is * a helper frame that forwards the request to the frame manager. diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 4aab8ffa77a..2a41450dfc7 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -166,6 +166,9 @@ #include "nsIContentViewer.h" #include "nsIDocumentViewer.h" +// SubShell map +#include "pldhash.h" + #ifdef IBMBIDI #include "nsIBidiKeyboard.h" #endif // IBMBIDI @@ -806,6 +809,14 @@ DummyLayoutRequest::Cancel(nsresult status) // ---------------------------------------------------------------------------- +class SubShellMapEntry : public PLDHashEntryHdr { + public: + nsIContent *key; // must be first, to look like PLDHashEntryStub + nsISupports *subShell; +}; + +// ---------------------------------------------------------------------------- + class PresShell : public nsIPresShell, public nsIViewObserver, private nsIDocumentObserver, public nsIFocusTracker, public nsISelectionController, @@ -866,6 +877,12 @@ public: nsIStyleContext** aStyleContext) const; NS_IMETHOD GetLayoutObjectFor(nsIContent* aContent, nsISupports** aResult) const; + NS_IMETHOD GetSubShellFor(nsIContent* aContent, + nsISupports** aResult) const; + NS_IMETHOD SetSubShellFor(nsIContent* aContent, + nsISupports* aSubShell); + NS_IMETHOD FindContentForShell(nsISupports* aSubShell, + nsIContent** aContent) const; NS_IMETHOD GetPlaceholderFrameFor(nsIFrame* aFrame, nsIFrame** aPlaceholderFrame) const; NS_IMETHOD AppendReflowCommand(nsHTMLReflowCommand* aReflowCommand); @@ -1218,6 +1235,9 @@ protected: static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell); // A callback for the timer. + // subshell map + PLDHashTable* mSubShellMap; // map of content/subshell pairs + MOZ_TIMER_DECLARE(mReflowWatch) // Used for measuring time spent in reflow MOZ_TIMER_DECLARE(mFrameCreationWatch) // Used for measuring time spent in frame creation @@ -1655,6 +1675,13 @@ PresShell::Destroy() // Clobber weak leaks in case of re-entrancy during tear down mHistoryState = nsnull; + // kill subshell map, if any. It holds only weak references + if (mSubShellMap) + { + PL_DHashTableDestroy(mSubShellMap); + mSubShellMap = nsnull; + } + // release current event content and any content on event stack NS_IF_RELEASE(mCurrentEventContent); @@ -5502,6 +5529,94 @@ PresShell::GetLayoutObjectFor(nsIContent* aContent, return result; } + +NS_IMETHODIMP +PresShell::GetSubShellFor(nsIContent* aContent, + nsISupports** aResult) const +{ + NS_ENSURE_ARG_POINTER(aContent); + + if (mSubShellMap) { + SubShellMapEntry *entry = NS_STATIC_CAST(SubShellMapEntry*, + PL_DHashTableOperate(mSubShellMap, aContent, PL_DHASH_LOOKUP)); + if (PL_DHASH_ENTRY_IS_BUSY(entry)) { + NS_ADDREF(*aResult = entry->subShell); + return NS_OK; + } + } + + *aResult = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +PresShell::SetSubShellFor(nsIContent* aContent, + nsISupports* aSubShell) +{ + NS_ENSURE_ARG_POINTER(aContent); + + // If aSubShell is NULL, then remove the mapping + if (!aSubShell) { + if (mSubShellMap) + PL_DHashTableOperate(mSubShellMap, aContent, PL_DHASH_REMOVE); + } else { + // Create a new hashtable if necessary + if (!mSubShellMap) { + mSubShellMap = PL_NewDHashTable(PL_DHashGetStubOps(), nsnull, + sizeof(SubShellMapEntry), 16); + if (!mSubShellMap) + return NS_ERROR_OUT_OF_MEMORY; + } + + // Add a mapping to the hash table + SubShellMapEntry *entry = NS_STATIC_CAST(SubShellMapEntry*, + PL_DHashTableOperate(mSubShellMap, aContent, PL_DHASH_ADD)); + entry->key = aContent; + entry->subShell = aSubShell; + } + return NS_OK; +} + +struct FindContentData { + FindContentData(nsISupports *aSubShell) + : subShell(aSubShell), result(nsnull) {} + + nsISupports *subShell; + nsIContent *result; +}; + +PR_STATIC_CALLBACK(PLDHashOperator) +FindContentEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr, + PRUint32 number, void *arg) +{ + SubShellMapEntry *entry = NS_STATIC_CAST(SubShellMapEntry*, hdr); + FindContentData *data = NS_STATIC_CAST(FindContentData*, arg); + + if (entry->subShell == data->subShell) { + data->result = entry->key; + return PL_DHASH_STOP; + } + return PL_DHASH_NEXT; +} + +NS_IMETHODIMP +PresShell::FindContentForShell(nsISupports* aSubShell, + nsIContent** aContent) const +{ + NS_ENSURE_ARG_POINTER(aSubShell); + + if (!mSubShellMap) { + *aContent = nsnull; + return NS_OK; + } + + FindContentData data(aSubShell); + PL_DHashTableEnumerate(mSubShellMap, FindContentEnumerator, &data); + NS_IF_ADDREF(*aContent = data.result); + + return NS_OK; +} + NS_IMETHODIMP PresShell::GetPlaceholderFrameFor(nsIFrame* aFrame, nsIFrame** aResult) const diff --git a/layout/base/public/nsIPresShell.h b/layout/base/public/nsIPresShell.h index 8293f2fc5b2..e018c206ce5 100644 --- a/layout/base/public/nsIPresShell.h +++ b/layout/base/public/nsIPresShell.h @@ -265,6 +265,28 @@ public: NS_IMETHOD GetLayoutObjectFor(nsIContent* aContent, nsISupports** aResult) const = 0; + /** + * Returns the object that acts as a subshell for aContent. + * For example, for an html frame aResult will be an nsIDocShell. + */ + NS_IMETHOD GetSubShellFor(nsIContent* aContent, + nsISupports** aResult) const = 0; + + /** + * Establish a relationship between aContent and aSubShell. + * aSubShell will be returned from GetSubShellFor(aContent, ...); + */ + NS_IMETHOD SetSubShellFor(nsIContent* aContent, + nsISupports* aSubShell) = 0; + + /** + * Find the content in the map that has aSubShell set + * as its subshell. If there is more than one mapping for + * aSubShell, the result is undefined. + */ + NS_IMETHOD FindContentForShell(nsISupports* aSubShell, + nsIContent** aContent) const = 0; + /** * Gets the placeholder frame associated with the specified frame. This is * a helper frame that forwards the request to the frame manager. diff --git a/layout/build/nsContentDLF.cpp b/layout/build/nsContentDLF.cpp index 98026f58e1d..5dbb7e3668c 100644 --- a/layout/build/nsContentDLF.cpp +++ b/layout/build/nsContentDLF.cpp @@ -416,8 +416,6 @@ nsContentDLF::CreateDocument(const char* aCommand, break; docv->SetUAStyleSheet(gUAStyleSheet); - doc->SetContainer(aContainer); - // Initialize the document to begin loading the data. An // nsIStreamListener connected to the parser is returned in // aDocListener. @@ -514,9 +512,6 @@ nsContentDLF::CreateRDFDocument(const char* aCommand, * An nsIStreamListener connected to the parser is returned in * aDocListener. */ - - doc->SetContainer(aContainer); - rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE); if (NS_SUCCEEDED(rv)) { /* diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index d4133180f3a..0970e11314c 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -72,7 +72,6 @@ #include "nsFrameSetFrame.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLIFrameElement.h" -#include "nsIFrameLoader.h" #include "nsLayoutAtoms.h" #include "nsIChromeEventHandler.h" #include "nsIScriptSecurityManager.h" @@ -89,10 +88,9 @@ #include "nsIDOMEventTarget.h" #include "nsIDOMEventListener.h" #include "nsIDOMWindow.h" -#include "nsIDOMDocument.h" #include "nsIRenderingContext.h" -// For Accessibility +// For Accessibility #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" #endif @@ -100,12 +98,19 @@ class nsHTMLFrame; +static NS_DEFINE_IID(kIFramesetFrameIID, NS_IFRAMESETFRAME_IID); +static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID); static NS_DEFINE_CID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); -/****************************************************************************** - * FrameLoadingInfo - *****************************************************************************/ +// Bug 8065: Limit content frame depth to some reasonable level. +// This does not count chrome frames when determining depth, +// nor does it prevent chrome recursion. +#define MAX_DEPTH_CONTENT_FRAMES 25 + +/******************************************************************************* + * FrameLoadingInfo + ******************************************************************************/ class FrameLoadingInfo : public nsISupports { public: @@ -122,9 +127,9 @@ public: }; -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameOuterFrame - *****************************************************************************/ + ******************************************************************************/ #define nsHTMLFrameOuterFrameSuper nsHTMLContainerFrame class nsHTMLFrameOuterFrame : public nsHTMLFrameOuterFrameSuper { @@ -136,7 +141,7 @@ public: NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif - // nsISupports + // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD GetFrameType(nsIAtom** aType) const; @@ -162,7 +167,7 @@ public: nsIContent* aChild, PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRInt32 aModType, + PRInt32 aModType, PRInt32 aHint); #ifdef ACCESSIBILITY @@ -182,10 +187,11 @@ protected: nsCOMPtr mPresContext; }; -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameInnerFrame - *****************************************************************************/ + ******************************************************************************/ class nsHTMLFrameInnerFrame : public nsLeafFrame, + public nsIWebProgressListener, public nsSupportsWeakReference { public: @@ -195,6 +201,8 @@ public: NS_IMETHOD_(nsrefcnt) AddRef(void) { return 2; } NS_IMETHOD_(nsrefcnt) Release(void) { return 1; } + NS_DECL_NSIWEBPROGRESSLISTENER + #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif @@ -228,9 +236,7 @@ public: nsIStyleContext* aContext, nsIFrame* aPrevInFlow); - void GetParentContent(nsIContent** aContent); - nsresult GetDocShell(nsIDocShell **aDocShell); - + NS_IMETHOD GetParentContent(nsIContent*& aContent); PRBool GetURL(nsIContent* aContent, nsString& aResult); PRBool GetName(nsIContent* aContent, nsString& aResult); PRInt32 GetScrolling(nsIContent* aContent); @@ -238,10 +244,13 @@ public: PRInt32 GetMarginWidth(nsIPresContext* aPresContext, nsIContent* aContent); PRInt32 GetMarginHeight(nsIPresContext* aPresContext, nsIContent* aContent); + nsresult ReloadURL(nsIPresContext* aPresContext); + friend class nsHTMLFrameOuterFrame; protected: - nsresult ShowDocShell(nsIPresContext* aPresContext); + nsresult CreateDocShell(nsIPresContext* aPresContext); + nsresult DoLoadURL(nsIPresContext* aPresContext); nsresult CreateViewAndWidget(nsIPresContext* aPresContext, nsIWidget** aWidget); @@ -251,18 +260,15 @@ protected: const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize); - nsresult ReloadURL(); - - nsCOMPtr mFrameLoader; - PRPackedBool mOwnsFrameLoader; - - PRPackedBool mCreatingViewer; + nsCOMPtr mSubShell; + nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell + PRBool mCreatingViewer; }; -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameOuterFrame - *****************************************************************************/ + ******************************************************************************/ nsHTMLFrameOuterFrame::nsHTMLFrameOuterFrame() : nsHTMLContainerFrame() { @@ -342,7 +348,7 @@ nsHTMLFrameOuterFrame::Init(nsIPresContext* aPresContext, view->GetWidget(*getter_AddRefs(widget)); if (!widget) - view->CreateWidget(kCChildCID); + view->CreateWidget(kCChildCID); } nsCOMPtr shell; @@ -380,7 +386,7 @@ nsHTMLFrameOuterFrame::GetSkipSides() const return 0; } -void +void nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize) @@ -415,7 +421,7 @@ nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext, } PRBool nsHTMLFrameOuterFrame::IsInline() -{ +{ return mIsInline; } @@ -456,7 +462,7 @@ NS_IMETHODIMP nsHTMLFrameOuterFrame::GetFrameType(nsIAtom** aType) const { NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer"); - *aType = nsLayoutAtoms::htmlFrameOuterFrame; + *aType = nsLayoutAtoms::htmlFrameOuterFrame; NS_ADDREF(*aType); return NS_OK; } @@ -469,7 +475,7 @@ nsHTMLFrameOuterFrame::Reflow(nsIPresContext* aPresContext, { DO_GLOBAL_REFLOW_COUNT("nsHTMLFrameOuterFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); - //printf("OuterFrame::Reflow %X (%d,%d) \n", this, aReflowState.availableWidth, aReflowState.availableHeight); + //printf("OuterFrame::Reflow %X (%d,%d) \n", this, aReflowState.availableWidth, aReflowState.availableHeight); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("enter nsHTMLFrameOuterFrame::Reflow: maxSize=%d,%d reason=%d", aReflowState.availableWidth, aReflowState.availableHeight, aReflowState.reason)); @@ -544,40 +550,37 @@ nsHTMLFrameOuterFrame::AttributeChanged(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRInt32 aModType, + PRInt32 aModType, PRInt32 aHint) { nsCOMPtr type; aChild->GetTag(*getter_AddRefs(type)); - if ((type != nsHTMLAtoms::object && aAttribute == nsHTMLAtoms::src) || - (type == nsHTMLAtoms::object && aAttribute == nsHTMLAtoms::data)) { - nsHTMLFrameInnerFrame* firstChild = - NS_STATIC_CAST(nsHTMLFrameInnerFrame*, mFrames.FirstChild()); - + if (((nsHTMLAtoms::src == aAttribute) && (nsHTMLAtoms::object != type)) || + ((nsHTMLAtoms::data == aAttribute) && (nsHTMLAtoms::object == type))) { + nsHTMLFrameInnerFrame* firstChild = NS_STATIC_CAST(nsHTMLFrameInnerFrame*, + mFrames.FirstChild()); if (firstChild) { - firstChild->ReloadURL(); + firstChild->ReloadURL(aPresContext); } } // If the noResize attribute changes, dis/allow frame to be resized - else if (aAttribute == nsHTMLAtoms::noresize) { + else if (nsHTMLAtoms::noresize == aAttribute) { nsCOMPtr parentContent; mContent->GetParent(*getter_AddRefs(parentContent)); nsCOMPtr parentTag; parentContent->GetTag(*getter_AddRefs(parentTag)); - if (parentTag == nsHTMLAtoms::frameset) { + if (nsHTMLAtoms::frameset == parentTag) { nsIFrame* parentFrame = nsnull; GetParent(&parentFrame); if (parentFrame) { - // There is no interface for nsHTMLFramesetFrame so QI'ing to - // concrete class, yay! + // There is no interface for kIFramesetFrameIID + // so QI'ing to concrete class, yay! nsHTMLFramesetFrame* framesetFrame = nsnull; - parentFrame->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), - (void **)&framesetFrame); - + parentFrame->QueryInterface(kIFramesetFrameIID, (void **)&framesetFrame); if (framesetFrame) { framesetFrame->RecalculateBorderResize(); } @@ -586,45 +589,37 @@ nsHTMLFrameOuterFrame::AttributeChanged(nsIPresContext* aPresContext, } else if (aAttribute == nsHTMLAtoms::type) { nsHTMLFrameInnerFrame* firstChild = NS_STATIC_CAST(nsHTMLFrameInnerFrame*, - mFrames.FirstChild()); - if (!firstChild || !firstChild->mFrameLoader) + mFrames.FirstChild()); + if (!firstChild) return NS_OK; nsAutoString value; aChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, value); - + // Notify our enclosing chrome that the primary content shell // has changed. - - nsCOMPtr docShell; - firstChild->mFrameLoader->GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - + nsCOMPtr docShell(do_QueryInterface(firstChild->mSubShell)); + nsCOMPtr docShellAsItem(do_QueryInterface(firstChild->mSubShell)); + // If our container is a web-shell, inform it that it has a new // child. If it's not a web-shell then some things will not operate // properly. nsCOMPtr container; aPresContext->GetContainer(getter_AddRefs(container)); - - nsCOMPtr parentAsNode(do_QueryInterface(container)); - - if (parentAsNode) { - nsCOMPtr parentAsItem = - do_QueryInterface(parentAsNode); - - nsCOMPtr parentTreeOwner; - parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); - if (parentTreeOwner) { - PRBool is_primary_content = - value.EqualsIgnoreCase("content-primary"); - - parentTreeOwner->ContentShellAdded(docShellAsItem, is_primary_content, - value.get()); + if (container) { + nsCOMPtr parentAsNode(do_QueryInterface(container)); + if (parentAsNode) { + nsCOMPtr parentAsItem(do_QueryInterface(parentAsNode)); + + nsCOMPtr parentTreeOwner; + parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); + if (parentTreeOwner) + parentTreeOwner->ContentShellAdded(docShellAsItem, + value.EqualsIgnoreCase("content-primary") ? PR_TRUE : PR_FALSE, + value.get()); } } } - return NS_OK; } @@ -643,50 +638,49 @@ NS_NewHTMLFrameOuterFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) return NS_OK; } -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameInnerFrame - *****************************************************************************/ + ******************************************************************************/ nsHTMLFrameInnerFrame::nsHTMLFrameInnerFrame() - : nsLeafFrame(), mOwnsFrameLoader(PR_FALSE), mCreatingViewer(PR_FALSE) + : nsLeafFrame() { + mCreatingViewer = PR_FALSE; + mPresShellWeak = nsnull; } nsHTMLFrameInnerFrame::~nsHTMLFrameInnerFrame() { - //printf("nsHTMLFrameInnerFrame destructor %X \n", this); + //printf("nsHTMLFrameInnerFrame destructor %X \n", this); - if (mFrameLoader) { - // Get the content viewer through the docshell, but don't call - // GetDocShell() since we don't want to create one if we don't - // have one. + nsCOMPtr win(do_GetInterface(mSubShell)); + nsCOMPtr eventTarget(do_QueryInterface(win)); + nsCOMPtr eventListener(do_QueryInterface(mContent)); - nsCOMPtr docShell; - mFrameLoader->GetDocShell(getter_AddRefs(docShell)); + if (eventTarget && eventListener) { + eventTarget->RemoveEventListener(NS_LITERAL_STRING("load"), eventListener, + PR_FALSE); + } - nsCOMPtr content_viewer; - docShell->GetContentViewer(getter_AddRefs(content_viewer)); - - if (content_viewer) { - // Hide the content viewer now that the frame is going away... - - content_viewer->Hide(); + if(mSubShell) { + // notify the pres shell that a docshell has been destroyed + if (mPresShellWeak) { + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + if (ps) { + ps->SetSubShellFor(mContent, nsnull); + } } + mSubShell->Destroy(); } - - if (mFrameLoader && mOwnsFrameLoader) { - // We own this frame loader, and we're going away, so destroy our - // frame loader. - - mFrameLoader->Destroy(); - } + mSubShell = nsnull; // This is the location it was released before... + // Not sure if there is ordering depending on this. } PRBool nsHTMLFrameInnerFrame::GetURL(nsIContent* aContent, nsString& aResult) { - aResult.SetLength(0); + aResult.SetLength(0); nsCOMPtr type; aContent->GetTag(*getter_AddRefs(type)); - + if (type.get() == nsHTMLAtoms::object) { if (NS_CONTENT_ATTR_HAS_VALUE == (aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::data, aResult))) if (aResult.Length() > 0) @@ -701,7 +695,7 @@ PRBool nsHTMLFrameInnerFrame::GetURL(nsIContent* aContent, nsString& aResult) PRBool nsHTMLFrameInnerFrame::GetName(nsIContent* aContent, nsString& aResult) { - aResult.SetLength(0); + aResult.SetLength(0); if (NS_CONTENT_ATTR_HAS_VALUE == (aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, aResult))) { if (aResult.Length() > 0) { @@ -740,7 +734,7 @@ PRInt32 nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent) returnValue = NS_STYLE_OVERFLOW_AUTO; break; } - } + } } // Check style for overflow @@ -814,6 +808,12 @@ nsHTMLFrameInnerFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); + if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) { + nsISupports *tmp = NS_STATIC_CAST(nsIWebProgressListener *, this); + *aInstancePtr = tmp; + return NS_OK; + } + if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference))) { nsISupports *tmp = NS_STATIC_CAST(nsISupportsWeakReference *, this); *aInstancePtr = tmp; @@ -823,6 +823,60 @@ nsHTMLFrameInnerFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) return nsLeafFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnStateChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aStateFlags, PRUint32 aStatus) +{ + if (!((~aStateFlags) & (nsIWebProgressListener::STATE_IS_DOCUMENT | + nsIWebProgressListener::STATE_TRANSFERRING))) { + nsCOMPtr win(do_GetInterface(mSubShell)); + nsCOMPtr eventTarget(do_QueryInterface(win)); + nsCOMPtr eventListener(do_QueryInterface(mContent)); + + if (eventTarget && eventListener) { + eventTarget->AddEventListener(NS_LITERAL_STRING("load"), eventListener, + PR_FALSE); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnProgressChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsIURI *location) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsresult aStatus, + const PRUnichar *aMessage) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, PRInt32 state) +{ + return NS_OK; +} + #ifdef DEBUG NS_IMETHODIMP nsHTMLFrameInnerFrame::GetFrameName(nsAString& aResult) const { @@ -834,7 +888,7 @@ NS_IMETHODIMP nsHTMLFrameInnerFrame::GetFrameType(nsIAtom** aType) const { NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer"); - *aType = nsLayoutAtoms::htmlFrameInnerFrame; + *aType = nsLayoutAtoms::htmlFrameInnerFrame; NS_ADDREF(*aType); return NS_OK; } @@ -846,90 +900,33 @@ nsHTMLFrameInnerFrame::Paint(nsIPresContext* aPresContext, nsFramePaintLayer aWhichLayer, PRUint32 aFlags) { - //printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, - //aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); if there is - //not web shell paint based on our background color, otherwise let - //the web shell paint the sub document + //printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); + // if there is not web shell paint based on our background color, + // otherwise let the web shell paint the sub document - // isPaginated is a temporary fix for Bug 75737 and this should all - // be fixed correctly by Bug 75739 + // isPaginated is a temporary fix for Bug 75737 + // and this should all be fixed correctly by Bug 75739 PRBool isPaginated; aPresContext->IsPaginated(&isPaginated); - - if (!isPaginated) { - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - - if (!docShell) { - const nsStyleBackground* color = - (const nsStyleBackground*)mStyleContext-> - GetStyleData(eStyleStruct_Background); - - aRenderingContext.SetColor(color->mBackgroundColor); - aRenderingContext.FillRect(mRect); - } + if (!mSubShell && !isPaginated) { + const nsStyleBackground* color = + (const nsStyleBackground*)mStyleContext->GetStyleData(eStyleStruct_Background); + aRenderingContext.SetColor(color->mBackgroundColor); + aRenderingContext.FillRect(mRect); } - DO_GLOBAL_REFLOW_COUNT_DSP("nsHTMLFrameInnerFrame", &aRenderingContext); - return NS_OK; } -void -nsHTMLFrameInnerFrame::GetParentContent(nsIContent** aContent) +NS_IMETHODIMP +nsHTMLFrameInnerFrame::GetParentContent(nsIContent*& aContent) { - *aContent = nsnull; - - nsIFrame* parent = nsnull; - GetParent(&parent); - - if (parent) { - parent->GetContent(aContent); + nsHTMLFrameOuterFrame* parent; + nsresult rv = GetParent((nsIFrame**)&parent); + if (NS_SUCCEEDED(rv) && parent) { + rv = parent->GetContent(&aContent); } -} - -nsresult -nsHTMLFrameInnerFrame::GetDocShell(nsIDocShell **aDocShell) -{ - *aDocShell = nsnull; - - nsCOMPtr content; - GetParentContent(getter_AddRefs(content)); - - if (!content) { - // Hmm, no content in this frame (or in the parent, really), - // that's odd, not much to be done here then. - - return NS_OK; - } - - if (!mFrameLoader) { - nsCOMPtr frame_loader_owner = - do_QueryInterface(content); - - if (frame_loader_owner) { - frame_loader_owner->GetFrameLoader(getter_AddRefs(mFrameLoader)); - } - - if (!mFrameLoader) { - nsresult rv = NS_OK; - - // No frame loader available from the content, create our own... - mFrameLoader = do_CreateInstance(NS_FRAMELOADER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - // ... remember that we own this frame loader... - mOwnsFrameLoader = PR_TRUE; - - // ... initialize it... - mFrameLoader->Init(content); - - // ... and tell it to start loading. - mFrameLoader->LoadFrame(); - } - } - - return mFrameLoader->GetDocShell(aDocShell); + return rv; } NS_IMETHODIMP @@ -955,100 +952,287 @@ nsHTMLFrameInnerFrame::DidReflow(nsIPresContext* aPresContext, if (newVis != oldVis) { nsCOMPtr vm; view->GetViewManager(*getter_AddRefs(vm)); - if (vm) { + if (vm != nsnull) { vm->SetViewVisibility(view, newVis); } } } } - + return rv; } nsresult -nsHTMLFrameInnerFrame::ShowDocShell(nsIPresContext* aPresContext) +nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext) { - nsCOMPtr docShell; - nsresult rv = GetDocShell(getter_AddRefs(docShell)); - NS_ENSURE_SUCCESS(rv, rv); + nsresult rv; + nsCOMPtr parentContent; + GetParentContent(*getter_AddRefs(parentContent)); - // Make sure there's a document in the docshell. - nsCOMPtr win(do_GetInterface(docShell)); - NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED); + // Bug 8065: Don't exceed some maximum depth in content frames (MAX_DEPTH_CONTENT_FRAMES) + PRInt32 depth = 0; + nsCOMPtr parentAsSupports; + aPresContext->GetContainer(getter_AddRefs(parentAsSupports)); + if (parentAsSupports) { + nsCOMPtr parentAsItem(do_QueryInterface(parentAsSupports)); + while (parentAsItem) { + depth++; + if (MAX_DEPTH_CONTENT_FRAMES < depth) + return NS_ERROR_UNEXPECTED; // Too deep, give up! (silently?) - nsCOMPtr dom_doc; - - // This will synchronously create a document if there is no - // document in the window yet. - - win->GetDocument(getter_AddRefs(dom_doc)); - - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - - if (presShell) { - // The docshell is already showing, nothing left to do... - - return NS_OK; + // Only count depth on content, not chrome. + // If we wanted to limit total depth, skip the following check: + PRInt32 parentType; + parentAsItem->GetItemType(&parentType); + if (nsIDocShellTreeItem::typeContent == parentType) { + nsIDocShellTreeItem* temp = parentAsItem; + temp->GetParent(getter_AddRefs(parentAsItem)); + } else { + break; // we have exited content, stop counting, depth is OK! + } + } } - nsCOMPtr docShellTreeItem(do_QueryInterface(docShell)); + mSubShell = do_CreateInstance(kWebShellCID); + NS_ENSURE_TRUE(mSubShell, NS_ERROR_FAILURE); - nsCOMPtr parentDocShellTreeItem; - docShellTreeItem->GetParent(getter_AddRefs(parentDocShellTreeItem)); - - nsCOMPtr parentDocShell = - do_QueryInterface(parentDocShellTreeItem); - - nsCOMPtr parentPresShell; - parentDocShell->GetPresShell(getter_AddRefs(parentPresShell)); - - nsCOMPtr content; - GetParentContent(getter_AddRefs(content)); - - // pass along marginwidth, marginheight, scrolling so sub document - // can use it - docShell->SetMarginWidth(GetMarginWidth(aPresContext, content)); - docShell->SetMarginHeight(GetMarginHeight(aPresContext, content)); + // notify the pres shell that a docshell has been created + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + if (presShell) + { + nsCOMPtr subShellAsSupports(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE); + presShell->SetSubShellFor(mContent, subShellAsSupports); + //We need to be able to get back to the presShell to unset the subshell at destruction + mPresShellWeak = getter_AddRefs(NS_GetWeakReference(presShell)); + } + + nsCOMPtr docShell(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + // pass along marginwidth, marginheight, scrolling so sub document can use it + docShell->SetMarginWidth(GetMarginWidth(aPresContext, parentContent)); + docShell->SetMarginHeight(GetMarginHeight(aPresContext, parentContent)); // Current and initial scrolling is set so that all succeeding docs // will use the scrolling value set here, regardless if scrolling is // set by viewing a particular document (e.g. XUL turns off scrolling) - nsCOMPtr scrollableContainer(do_QueryInterface(docShell)); - + nsCOMPtr scrollableContainer(do_QueryInterface(mSubShell)); if (scrollableContainer) { scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y, - GetScrolling(content)); + GetScrolling(parentContent)); scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X, - GetScrolling(content)); + GetScrolling(parentContent)); } - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem(do_QueryInterface(mSubShell)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); + nsString frameName; + if (GetName(parentContent, frameName)) { + docShellAsItem->SetName(frameName.get()); + } + + // If our container is a web-shell, inform it that it has a new + // child. If it's not a web-shell then some things will not operate + // properly. + nsCOMPtr container; + aPresContext->GetContainer(getter_AddRefs(container)); + if (container) { + nsCOMPtr parentAsNode(do_QueryInterface(container)); + if (parentAsNode) { + nsCOMPtr parentAsItem(do_QueryInterface(parentAsNode)); + PRInt32 parentType; + parentAsItem->GetItemType(&parentType); + + nsIAtom* typeAtom = NS_NewAtom("type"); + nsAutoString value, valuePiece; + PRBool isContent; + + isContent = PR_FALSE; + if (NS_SUCCEEDED(parentContent->GetAttr(kNameSpaceID_None, + typeAtom, value))) { + + // we accept "content" and "content-xxx" values. + // at time of writing, we expect "xxx" to be "primary", but + // someday it might be an integer expressing priority + value.Left(valuePiece, 7); + if (valuePiece.EqualsIgnoreCase("content") && + (value.Length() == 7 || + value.Mid(valuePiece, 7, 1) == 1 && valuePiece.Equals(NS_LITERAL_STRING("-")))) + isContent = PR_TRUE; + } + NS_IF_RELEASE(typeAtom); + if (isContent) { + // The web shell's type is content. + docShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent); + } else { + // Inherit our type from our parent webshell. If it is + // chrome, we'll be chrome. If it is content, we'll be + // content. + docShellAsItem->SetItemType(parentType); + } + + parentAsNode->AddChild(docShellAsItem); + + if (isContent) { + nsCOMPtr parentTreeOwner; + parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); + if(parentTreeOwner) + parentTreeOwner->ContentShellAdded(docShellAsItem, + value.EqualsIgnoreCase("content-primary") ? PR_TRUE : PR_FALSE, + value.get()); + } + // connect the container... + nsCOMPtr webShell(do_QueryInterface(mSubShell)); + nsCOMPtr outerContainer(do_QueryInterface(container)); + if (outerContainer) + webShell->SetContainer(outerContainer); + + + // Make sure all shells have links back to the content element in the + // nearest enclosing chrome shell. + nsCOMPtr parentShell(do_QueryInterface(parentAsNode)); + nsCOMPtr chromeEventHandler; + if (parentType == nsIDocShellTreeItem::typeChrome) { + // Our parent shell is a chrome shell. It is therefore our nearest + // enclosing chrome shell. + chromeEventHandler = do_QueryInterface(mContent); + NS_WARN_IF_FALSE(chromeEventHandler, "This mContent should implement this."); + } + else { + // Our parent shell is a content shell. Get the chrome info from + // it and use that for our shell as well. + parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler)); + } + + docShell->SetChromeEventHandler(chromeEventHandler); + } + } nsCOMPtr widget; - rv = CreateViewAndWidget(aPresContext, getter_AddRefs(widget)); if (NS_FAILED(rv)) { return rv; } - nsCOMPtr baseWindow(do_QueryInterface(docShell)); + mSubShell->InitWindow(nsnull, widget, 0, 0, 10, 10); + mSubShell->Create(); - if (baseWindow) { - baseWindow->InitWindow(nsnull, widget, 0, 0, 10, 10); - - // This is kinda whacky, this "Create()" calldoesn't really create - // anything, one starts to wonder why this was named "Create"... - - baseWindow->Create(); - - baseWindow->SetVisibility(PR_TRUE); - } + mSubShell->SetVisibility(PR_TRUE); return NS_OK; } +nsresult +nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext) +{ + // Bug 8065: Preventing frame nesting recursion - if the frames are + // too deep we don't create a mSubShell, so this isn't an assert: + if (!mSubShell) return NS_OK; + + // Prevent recursion + mCreatingViewer=PR_TRUE; + + // Get the URL to load + nsCOMPtr parentContent; + nsresult rv = GetParentContent(*getter_AddRefs(parentContent)); + NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && parentContent, rv); + + nsAutoString url; + GetURL(parentContent, url); + url.Trim(" \t\n\r"); + if (url.IsEmpty()) // Load about:blank into a frame if not URL is specified (bug 35986) + url = NS_LITERAL_STRING("about:blank"); + + // Make an absolute URL + nsCOMPtr baseURL; + nsCOMPtr htmlContent = do_QueryInterface(parentContent, &rv); + nsCOMPtr doc; + if (NS_SUCCEEDED(rv) && htmlContent) { + htmlContent->GetBaseURL(*getter_AddRefs(baseURL)); + (void) htmlContent->GetDocument(*getter_AddRefs(doc)); + } + else { + rv = parentContent->GetDocument(*getter_AddRefs(doc)); + if (NS_SUCCEEDED(rv) && doc) { + doc->GetBaseURL(*getter_AddRefs(baseURL)); + } + } + if (!baseURL) return NS_ERROR_NULL_POINTER; + + nsAutoString docCharset; + if (doc) + (void) doc->GetDocumentCharacterSet(docCharset); + + nsAutoString absURL; + rv = NS_MakeAbsoluteURI(absURL, url, baseURL); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), absURL, + docCharset.IsEmpty() ? nsnull : NS_ConvertUCS2toUTF8(docCharset).get()); + + // Check for security + nsCOMPtr secMan = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + // Get base URL + nsCOMPtr baseURI; + rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI)); + + // Get docshell and create load info + nsCOMPtr docShell(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + nsCOMPtr loadInfo; + docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); + NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); + + // Get referring URL + nsCOMPtr referrer; + nsCOMPtr principal; + rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal)); + NS_ENSURE_SUCCESS(rv, rv); + // If we were called from script, get the referring URL from the script + if (principal) { + nsCOMPtr codebase = do_QueryInterface(principal); + if (codebase) { + rv = codebase->GetURI(getter_AddRefs(referrer)); + NS_ENSURE_SUCCESS(rv, rv); + } + // Pass the script principal to the docshell + nsCOMPtr owner = do_QueryInterface(principal); + loadInfo->SetOwner(owner); + } + if (!referrer) { // We're not being called form script, tell the docshell + // to inherit an owner from the current document. + loadInfo->SetInheritOwner(PR_TRUE); + referrer = baseURI; + } + + loadInfo->SetReferrer(referrer); + + // Check if we are allowed to load absURL + nsCOMPtr newURI; + rv = NS_NewURI(getter_AddRefs(newURI), absURL, nsnull, baseURI); + NS_ENSURE_SUCCESS(rv, rv); + rv = secMan->CheckLoadURI(referrer, newURI, nsIScriptSecurityManager::STANDARD); + if (NS_FAILED(rv)) + return rv; // We're not + + nsCOMPtr webProgress(do_GetInterface(mSubShell)); + + if (webProgress) { + webProgress->AddProgressListener(this); + } + + rv = docShell->LoadURI(uri, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, PR_FALSE); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL"); + + return rv; +} + + nsresult nsHTMLFrameInnerFrame::CreateViewAndWidget(nsIPresContext* aPresContext, nsIWidget** aWidget) @@ -1058,29 +1242,28 @@ nsHTMLFrameInnerFrame::CreateViewAndWidget(nsIPresContext* aPresContext, nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + if (!presShell) return NS_ERROR_FAILURE; float t2p; aPresContext->GetTwipsToPixels(&t2p); // create, init, set the parent of the view nsIView* view; - nsresult rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, - NS_GET_IID(nsIView), - (void **)&view); - if (NS_FAILED(rv)) { - NS_ERROR("Could not create view for nsHTMLFrame"); + nsresult rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, NS_GET_IID(nsIView), + (void **)&view); + if (NS_OK != rv) { + NS_ASSERTION(0, "Could not create view for nsHTMLFrame"); return rv; } nsIView* parView; nsPoint origin; - GetOffsetFromView(aPresContext, origin, &parView); + GetOffsetFromView(aPresContext, origin, &parView); nsRect viewBounds(origin.x, origin.y, 10, 10); nsCOMPtr viewMan; - presShell->GetViewManager(getter_AddRefs(viewMan)); + presShell->GetViewManager(getter_AddRefs(viewMan)); rv = view->Init(viewMan, viewBounds, parView); // XXX put it at the end of the document order until we can do better viewMan->InsertChild(parView, view, nsnull, PR_TRUE); @@ -1109,39 +1292,41 @@ nsHTMLFrameInnerFrame::Init(nsIPresContext* aPresContext, nsIStyleContext* aContext, nsIFrame* aPrevInFlow) { - nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, - aPrevInFlow); + nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); if (NS_FAILED(rv)) return rv; // determine if we are a printcontext PRBool shouldCreateDoc = PR_TRUE; - nsCOMPtr thePrinterContext(do_QueryInterface(aPresContext)); - - if (thePrinterContext) { + nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); + if (thePrinterContext) { // we are printing shouldCreateDoc = PR_FALSE; } - // for print preview we want to create the view and widget but + // for print preview we want to create the view and widget but // we do not want to load the document, it is alerady loaded. - nsCOMPtr thePrintPreviewContext = - do_QueryInterface(aPresContext); - - if (thePrintPreviewContext) { + nsCOMPtr thePrintPreviewContext = do_QueryInterface(aPresContext); + if (thePrintPreviewContext) { nsCOMPtr widget; rv = CreateViewAndWidget(aPresContext, getter_AddRefs(widget)); - if (NS_FAILED(rv)) { return rv; } - // we are in PrintPreview shouldCreateDoc = PR_FALSE; } - - if (shouldCreateDoc) { - ShowDocShell(aPresContext); + + if (!mCreatingViewer && shouldCreateDoc) { + // create the web shell + // we do this even if the size is not positive (bug 11762) + // we do this even if there is no src (bug 16218) + if (!mSubShell) + rv = CreateDocShell(aPresContext); + // Whether or not we had to create a webshell, load the document + if (NS_SUCCEEDED(rv)) { + DoLoadURL(aPresContext); + } } return NS_OK; @@ -1162,55 +1347,41 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext, nsresult rv = NS_OK; - // use the max size set in aReflowState by the nsHTMLFrameOuterFrame - // as our size + // use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size GetDesiredSize(aPresContext, aReflowState, aDesiredSize); aStatus = NS_FRAME_COMPLETE; - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr baseWindow(do_QueryInterface(docShell)); - // resize the sub document - if (baseWindow) { + if(mSubShell) { float t2p; aPresContext->GetTwipsToPixels(&t2p); PRInt32 x = 0; PRInt32 y = 0; - baseWindow->GetPositionAndSize(&x, &y, nsnull, nsnull); - PRInt32 cx = NSToCoordRound(aDesiredSize.width * t2p); + mSubShell->GetPositionAndSize(&x, &y, nsnull, nsnull); + PRInt32 cx = NSToCoordRound(aDesiredSize.width * t2p); PRInt32 cy = NSToCoordRound(aDesiredSize.height * t2p); - baseWindow->SetPositionAndSize(x, y, cx, cy, PR_FALSE); + mSubShell->SetPositionAndSize(x, y, cx, cy, PR_FALSE); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x", - aDesiredSize.width, aDesiredSize.height, aStatus)); + ("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x", + aDesiredSize.width, aDesiredSize.height, aStatus)); } - + return rv; } // load a new url nsresult -nsHTMLFrameInnerFrame::ReloadURL() +nsHTMLFrameInnerFrame::ReloadURL(nsIPresContext* aPresContext) { - if (!mOwnsFrameLoader || !mFrameLoader) { - // If we don't own the frame loader, we're not in charge of what's - // loaded into it. - - return NS_OK; - } - - return mFrameLoader->LoadFrame(); + return DoLoadURL(aPresContext); } - -void +void nsHTMLFrameInnerFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize) @@ -1220,28 +1391,19 @@ nsHTMLFrameInnerFrame::GetDesiredSize(nsIPresContext* aPresContext, aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; - // For unknown reasons, the maxElementSize for the InnerFrame is - // used, but the maxElementSize for the OuterFrame is ignored, make - // sure to get it right here! - + // For unknown reasons, the maxElementSize for the InnerFrame is used, but the + // maxElementSize for the OuterFrame is ignored, make sure to get it right here! if (aDesiredSize.maxElementSize) { if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) || - (eStyleUnit_Percent == - aReflowState.mStylePosition->mWidth.GetUnit())) { - // percent width springy down to 0 px - - aDesiredSize.maxElementSize->width = 0; + (eStyleUnit_Percent == aReflowState.mStylePosition->mWidth.GetUnit())) { + aDesiredSize.maxElementSize->width = 0; // percent width springy down to 0 px } else { aDesiredSize.maxElementSize->width = aDesiredSize.width; } - if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) || - (eStyleUnit_Percent == - aReflowState.mStylePosition->mHeight.GetUnit())) { - // percent height springy down to 0px - - aDesiredSize.maxElementSize->height = 0; + (eStyleUnit_Percent == aReflowState.mStylePosition->mHeight.GetUnit())) { + aDesiredSize.maxElementSize->height = 0; // percent height springy down to 0px } else { aDesiredSize.maxElementSize->height = aDesiredSize.height; @@ -1249,9 +1411,9 @@ nsHTMLFrameInnerFrame::GetDesiredSize(nsIPresContext* aPresContext, } } -/****************************************************************************** +/******************************************************************************* * FrameLoadingInfo - *****************************************************************************/ + ******************************************************************************/ FrameLoadingInfo::FrameLoadingInfo(const nsSize& aSize) { NS_INIT_REFCNT(); diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index eecf2c845bc..a1a4b002844 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -63,6 +63,7 @@ #define ALL_VIS 0x000F #define NONE_VIS 0x0000 +static NS_DEFINE_IID(kIFramesetFrameIID, NS_IFRAMESETFRAME_IID); static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); /******************************************************************************* @@ -251,7 +252,7 @@ nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; - } else if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) { + } else if (aIID.Equals(kIFramesetFrameIID)) { *aInstancePtr = (void*)this; return NS_OK; } else if (aIID.Equals(NS_GET_IID(nsIObserver))) { @@ -326,8 +327,7 @@ nsHTMLFramesetFrame::Init(nsIPresContext* aPresContext, mTopLevelFrameset = (nsHTMLFramesetFrame*)this; while (parentFrame) { nsHTMLFramesetFrame* frameset; - rv = parentFrame->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), - (void**)&frameset); + rv = parentFrame->QueryInterface(kIFramesetFrameIID, (void**)&frameset); if (NS_SUCCEEDED(rv)) { mTopLevelFrameset = frameset; parentFrame->GetParent((nsIFrame**)&parentFrame); @@ -1404,7 +1404,7 @@ PRBool nsHTMLFramesetFrame::ChildIsFrameset(nsIFrame* aChild) { nsIFrame* childFrame = nsnull; - aChild->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), (void**)&childFrame); + aChild->QueryInterface(kIFramesetFrameIID, (void**)&childFrame); if (childFrame) { return PR_TRUE; } diff --git a/layout/generic/nsFrameSetFrame.h b/layout/generic/nsFrameSetFrame.h index 88000505dff..fe786185fd8 100644 --- a/layout/generic/nsFrameSetFrame.h +++ b/layout/generic/nsFrameSetFrame.h @@ -57,8 +57,7 @@ struct nsGUIEvent; class nsHTMLFramesetFrame; #define NS_IFRAMESETFRAME_IID \ -{ 0xf47deac0, 0x4200, 0x11d2, \ - { 0x80, 0x3c, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } } +{ 0xf47deac0, 0x4200, 0x11d2, { 0x80, 0x3c, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } } #define NO_COLOR 0xFFFFFFFA @@ -116,10 +115,8 @@ struct nsFramesetDrag { class nsHTMLFramesetFrame : public nsHTMLContainerFrame, public nsIObserver { -public: - // Woohoo, concrete class with an IID! - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFRAMESETFRAME_IID) +public: nsHTMLFramesetFrame(); virtual ~nsHTMLFramesetFrame(); diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 4aab8ffa77a..2a41450dfc7 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -166,6 +166,9 @@ #include "nsIContentViewer.h" #include "nsIDocumentViewer.h" +// SubShell map +#include "pldhash.h" + #ifdef IBMBIDI #include "nsIBidiKeyboard.h" #endif // IBMBIDI @@ -806,6 +809,14 @@ DummyLayoutRequest::Cancel(nsresult status) // ---------------------------------------------------------------------------- +class SubShellMapEntry : public PLDHashEntryHdr { + public: + nsIContent *key; // must be first, to look like PLDHashEntryStub + nsISupports *subShell; +}; + +// ---------------------------------------------------------------------------- + class PresShell : public nsIPresShell, public nsIViewObserver, private nsIDocumentObserver, public nsIFocusTracker, public nsISelectionController, @@ -866,6 +877,12 @@ public: nsIStyleContext** aStyleContext) const; NS_IMETHOD GetLayoutObjectFor(nsIContent* aContent, nsISupports** aResult) const; + NS_IMETHOD GetSubShellFor(nsIContent* aContent, + nsISupports** aResult) const; + NS_IMETHOD SetSubShellFor(nsIContent* aContent, + nsISupports* aSubShell); + NS_IMETHOD FindContentForShell(nsISupports* aSubShell, + nsIContent** aContent) const; NS_IMETHOD GetPlaceholderFrameFor(nsIFrame* aFrame, nsIFrame** aPlaceholderFrame) const; NS_IMETHOD AppendReflowCommand(nsHTMLReflowCommand* aReflowCommand); @@ -1218,6 +1235,9 @@ protected: static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell); // A callback for the timer. + // subshell map + PLDHashTable* mSubShellMap; // map of content/subshell pairs + MOZ_TIMER_DECLARE(mReflowWatch) // Used for measuring time spent in reflow MOZ_TIMER_DECLARE(mFrameCreationWatch) // Used for measuring time spent in frame creation @@ -1655,6 +1675,13 @@ PresShell::Destroy() // Clobber weak leaks in case of re-entrancy during tear down mHistoryState = nsnull; + // kill subshell map, if any. It holds only weak references + if (mSubShellMap) + { + PL_DHashTableDestroy(mSubShellMap); + mSubShellMap = nsnull; + } + // release current event content and any content on event stack NS_IF_RELEASE(mCurrentEventContent); @@ -5502,6 +5529,94 @@ PresShell::GetLayoutObjectFor(nsIContent* aContent, return result; } + +NS_IMETHODIMP +PresShell::GetSubShellFor(nsIContent* aContent, + nsISupports** aResult) const +{ + NS_ENSURE_ARG_POINTER(aContent); + + if (mSubShellMap) { + SubShellMapEntry *entry = NS_STATIC_CAST(SubShellMapEntry*, + PL_DHashTableOperate(mSubShellMap, aContent, PL_DHASH_LOOKUP)); + if (PL_DHASH_ENTRY_IS_BUSY(entry)) { + NS_ADDREF(*aResult = entry->subShell); + return NS_OK; + } + } + + *aResult = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +PresShell::SetSubShellFor(nsIContent* aContent, + nsISupports* aSubShell) +{ + NS_ENSURE_ARG_POINTER(aContent); + + // If aSubShell is NULL, then remove the mapping + if (!aSubShell) { + if (mSubShellMap) + PL_DHashTableOperate(mSubShellMap, aContent, PL_DHASH_REMOVE); + } else { + // Create a new hashtable if necessary + if (!mSubShellMap) { + mSubShellMap = PL_NewDHashTable(PL_DHashGetStubOps(), nsnull, + sizeof(SubShellMapEntry), 16); + if (!mSubShellMap) + return NS_ERROR_OUT_OF_MEMORY; + } + + // Add a mapping to the hash table + SubShellMapEntry *entry = NS_STATIC_CAST(SubShellMapEntry*, + PL_DHashTableOperate(mSubShellMap, aContent, PL_DHASH_ADD)); + entry->key = aContent; + entry->subShell = aSubShell; + } + return NS_OK; +} + +struct FindContentData { + FindContentData(nsISupports *aSubShell) + : subShell(aSubShell), result(nsnull) {} + + nsISupports *subShell; + nsIContent *result; +}; + +PR_STATIC_CALLBACK(PLDHashOperator) +FindContentEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr, + PRUint32 number, void *arg) +{ + SubShellMapEntry *entry = NS_STATIC_CAST(SubShellMapEntry*, hdr); + FindContentData *data = NS_STATIC_CAST(FindContentData*, arg); + + if (entry->subShell == data->subShell) { + data->result = entry->key; + return PL_DHASH_STOP; + } + return PL_DHASH_NEXT; +} + +NS_IMETHODIMP +PresShell::FindContentForShell(nsISupports* aSubShell, + nsIContent** aContent) const +{ + NS_ENSURE_ARG_POINTER(aSubShell); + + if (!mSubShellMap) { + *aContent = nsnull; + return NS_OK; + } + + FindContentData data(aSubShell); + PL_DHashTableEnumerate(mSubShellMap, FindContentEnumerator, &data); + NS_IF_ADDREF(*aContent = data.result); + + return NS_OK; +} + NS_IMETHODIMP PresShell::GetPlaceholderFrameFor(nsIFrame* aFrame, nsIFrame** aResult) const diff --git a/layout/html/document/src/nsFrameFrame.cpp b/layout/html/document/src/nsFrameFrame.cpp index d4133180f3a..0970e11314c 100644 --- a/layout/html/document/src/nsFrameFrame.cpp +++ b/layout/html/document/src/nsFrameFrame.cpp @@ -72,7 +72,6 @@ #include "nsFrameSetFrame.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLIFrameElement.h" -#include "nsIFrameLoader.h" #include "nsLayoutAtoms.h" #include "nsIChromeEventHandler.h" #include "nsIScriptSecurityManager.h" @@ -89,10 +88,9 @@ #include "nsIDOMEventTarget.h" #include "nsIDOMEventListener.h" #include "nsIDOMWindow.h" -#include "nsIDOMDocument.h" #include "nsIRenderingContext.h" -// For Accessibility +// For Accessibility #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" #endif @@ -100,12 +98,19 @@ class nsHTMLFrame; +static NS_DEFINE_IID(kIFramesetFrameIID, NS_IFRAMESETFRAME_IID); +static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID); static NS_DEFINE_CID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); -/****************************************************************************** - * FrameLoadingInfo - *****************************************************************************/ +// Bug 8065: Limit content frame depth to some reasonable level. +// This does not count chrome frames when determining depth, +// nor does it prevent chrome recursion. +#define MAX_DEPTH_CONTENT_FRAMES 25 + +/******************************************************************************* + * FrameLoadingInfo + ******************************************************************************/ class FrameLoadingInfo : public nsISupports { public: @@ -122,9 +127,9 @@ public: }; -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameOuterFrame - *****************************************************************************/ + ******************************************************************************/ #define nsHTMLFrameOuterFrameSuper nsHTMLContainerFrame class nsHTMLFrameOuterFrame : public nsHTMLFrameOuterFrameSuper { @@ -136,7 +141,7 @@ public: NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif - // nsISupports + // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD GetFrameType(nsIAtom** aType) const; @@ -162,7 +167,7 @@ public: nsIContent* aChild, PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRInt32 aModType, + PRInt32 aModType, PRInt32 aHint); #ifdef ACCESSIBILITY @@ -182,10 +187,11 @@ protected: nsCOMPtr mPresContext; }; -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameInnerFrame - *****************************************************************************/ + ******************************************************************************/ class nsHTMLFrameInnerFrame : public nsLeafFrame, + public nsIWebProgressListener, public nsSupportsWeakReference { public: @@ -195,6 +201,8 @@ public: NS_IMETHOD_(nsrefcnt) AddRef(void) { return 2; } NS_IMETHOD_(nsrefcnt) Release(void) { return 1; } + NS_DECL_NSIWEBPROGRESSLISTENER + #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif @@ -228,9 +236,7 @@ public: nsIStyleContext* aContext, nsIFrame* aPrevInFlow); - void GetParentContent(nsIContent** aContent); - nsresult GetDocShell(nsIDocShell **aDocShell); - + NS_IMETHOD GetParentContent(nsIContent*& aContent); PRBool GetURL(nsIContent* aContent, nsString& aResult); PRBool GetName(nsIContent* aContent, nsString& aResult); PRInt32 GetScrolling(nsIContent* aContent); @@ -238,10 +244,13 @@ public: PRInt32 GetMarginWidth(nsIPresContext* aPresContext, nsIContent* aContent); PRInt32 GetMarginHeight(nsIPresContext* aPresContext, nsIContent* aContent); + nsresult ReloadURL(nsIPresContext* aPresContext); + friend class nsHTMLFrameOuterFrame; protected: - nsresult ShowDocShell(nsIPresContext* aPresContext); + nsresult CreateDocShell(nsIPresContext* aPresContext); + nsresult DoLoadURL(nsIPresContext* aPresContext); nsresult CreateViewAndWidget(nsIPresContext* aPresContext, nsIWidget** aWidget); @@ -251,18 +260,15 @@ protected: const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize); - nsresult ReloadURL(); - - nsCOMPtr mFrameLoader; - PRPackedBool mOwnsFrameLoader; - - PRPackedBool mCreatingViewer; + nsCOMPtr mSubShell; + nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell + PRBool mCreatingViewer; }; -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameOuterFrame - *****************************************************************************/ + ******************************************************************************/ nsHTMLFrameOuterFrame::nsHTMLFrameOuterFrame() : nsHTMLContainerFrame() { @@ -342,7 +348,7 @@ nsHTMLFrameOuterFrame::Init(nsIPresContext* aPresContext, view->GetWidget(*getter_AddRefs(widget)); if (!widget) - view->CreateWidget(kCChildCID); + view->CreateWidget(kCChildCID); } nsCOMPtr shell; @@ -380,7 +386,7 @@ nsHTMLFrameOuterFrame::GetSkipSides() const return 0; } -void +void nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize) @@ -415,7 +421,7 @@ nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext, } PRBool nsHTMLFrameOuterFrame::IsInline() -{ +{ return mIsInline; } @@ -456,7 +462,7 @@ NS_IMETHODIMP nsHTMLFrameOuterFrame::GetFrameType(nsIAtom** aType) const { NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer"); - *aType = nsLayoutAtoms::htmlFrameOuterFrame; + *aType = nsLayoutAtoms::htmlFrameOuterFrame; NS_ADDREF(*aType); return NS_OK; } @@ -469,7 +475,7 @@ nsHTMLFrameOuterFrame::Reflow(nsIPresContext* aPresContext, { DO_GLOBAL_REFLOW_COUNT("nsHTMLFrameOuterFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); - //printf("OuterFrame::Reflow %X (%d,%d) \n", this, aReflowState.availableWidth, aReflowState.availableHeight); + //printf("OuterFrame::Reflow %X (%d,%d) \n", this, aReflowState.availableWidth, aReflowState.availableHeight); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("enter nsHTMLFrameOuterFrame::Reflow: maxSize=%d,%d reason=%d", aReflowState.availableWidth, aReflowState.availableHeight, aReflowState.reason)); @@ -544,40 +550,37 @@ nsHTMLFrameOuterFrame::AttributeChanged(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRInt32 aModType, + PRInt32 aModType, PRInt32 aHint) { nsCOMPtr type; aChild->GetTag(*getter_AddRefs(type)); - if ((type != nsHTMLAtoms::object && aAttribute == nsHTMLAtoms::src) || - (type == nsHTMLAtoms::object && aAttribute == nsHTMLAtoms::data)) { - nsHTMLFrameInnerFrame* firstChild = - NS_STATIC_CAST(nsHTMLFrameInnerFrame*, mFrames.FirstChild()); - + if (((nsHTMLAtoms::src == aAttribute) && (nsHTMLAtoms::object != type)) || + ((nsHTMLAtoms::data == aAttribute) && (nsHTMLAtoms::object == type))) { + nsHTMLFrameInnerFrame* firstChild = NS_STATIC_CAST(nsHTMLFrameInnerFrame*, + mFrames.FirstChild()); if (firstChild) { - firstChild->ReloadURL(); + firstChild->ReloadURL(aPresContext); } } // If the noResize attribute changes, dis/allow frame to be resized - else if (aAttribute == nsHTMLAtoms::noresize) { + else if (nsHTMLAtoms::noresize == aAttribute) { nsCOMPtr parentContent; mContent->GetParent(*getter_AddRefs(parentContent)); nsCOMPtr parentTag; parentContent->GetTag(*getter_AddRefs(parentTag)); - if (parentTag == nsHTMLAtoms::frameset) { + if (nsHTMLAtoms::frameset == parentTag) { nsIFrame* parentFrame = nsnull; GetParent(&parentFrame); if (parentFrame) { - // There is no interface for nsHTMLFramesetFrame so QI'ing to - // concrete class, yay! + // There is no interface for kIFramesetFrameIID + // so QI'ing to concrete class, yay! nsHTMLFramesetFrame* framesetFrame = nsnull; - parentFrame->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), - (void **)&framesetFrame); - + parentFrame->QueryInterface(kIFramesetFrameIID, (void **)&framesetFrame); if (framesetFrame) { framesetFrame->RecalculateBorderResize(); } @@ -586,45 +589,37 @@ nsHTMLFrameOuterFrame::AttributeChanged(nsIPresContext* aPresContext, } else if (aAttribute == nsHTMLAtoms::type) { nsHTMLFrameInnerFrame* firstChild = NS_STATIC_CAST(nsHTMLFrameInnerFrame*, - mFrames.FirstChild()); - if (!firstChild || !firstChild->mFrameLoader) + mFrames.FirstChild()); + if (!firstChild) return NS_OK; nsAutoString value; aChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, value); - + // Notify our enclosing chrome that the primary content shell // has changed. - - nsCOMPtr docShell; - firstChild->mFrameLoader->GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - + nsCOMPtr docShell(do_QueryInterface(firstChild->mSubShell)); + nsCOMPtr docShellAsItem(do_QueryInterface(firstChild->mSubShell)); + // If our container is a web-shell, inform it that it has a new // child. If it's not a web-shell then some things will not operate // properly. nsCOMPtr container; aPresContext->GetContainer(getter_AddRefs(container)); - - nsCOMPtr parentAsNode(do_QueryInterface(container)); - - if (parentAsNode) { - nsCOMPtr parentAsItem = - do_QueryInterface(parentAsNode); - - nsCOMPtr parentTreeOwner; - parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); - if (parentTreeOwner) { - PRBool is_primary_content = - value.EqualsIgnoreCase("content-primary"); - - parentTreeOwner->ContentShellAdded(docShellAsItem, is_primary_content, - value.get()); + if (container) { + nsCOMPtr parentAsNode(do_QueryInterface(container)); + if (parentAsNode) { + nsCOMPtr parentAsItem(do_QueryInterface(parentAsNode)); + + nsCOMPtr parentTreeOwner; + parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); + if (parentTreeOwner) + parentTreeOwner->ContentShellAdded(docShellAsItem, + value.EqualsIgnoreCase("content-primary") ? PR_TRUE : PR_FALSE, + value.get()); } } } - return NS_OK; } @@ -643,50 +638,49 @@ NS_NewHTMLFrameOuterFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) return NS_OK; } -/****************************************************************************** +/******************************************************************************* * nsHTMLFrameInnerFrame - *****************************************************************************/ + ******************************************************************************/ nsHTMLFrameInnerFrame::nsHTMLFrameInnerFrame() - : nsLeafFrame(), mOwnsFrameLoader(PR_FALSE), mCreatingViewer(PR_FALSE) + : nsLeafFrame() { + mCreatingViewer = PR_FALSE; + mPresShellWeak = nsnull; } nsHTMLFrameInnerFrame::~nsHTMLFrameInnerFrame() { - //printf("nsHTMLFrameInnerFrame destructor %X \n", this); + //printf("nsHTMLFrameInnerFrame destructor %X \n", this); - if (mFrameLoader) { - // Get the content viewer through the docshell, but don't call - // GetDocShell() since we don't want to create one if we don't - // have one. + nsCOMPtr win(do_GetInterface(mSubShell)); + nsCOMPtr eventTarget(do_QueryInterface(win)); + nsCOMPtr eventListener(do_QueryInterface(mContent)); - nsCOMPtr docShell; - mFrameLoader->GetDocShell(getter_AddRefs(docShell)); + if (eventTarget && eventListener) { + eventTarget->RemoveEventListener(NS_LITERAL_STRING("load"), eventListener, + PR_FALSE); + } - nsCOMPtr content_viewer; - docShell->GetContentViewer(getter_AddRefs(content_viewer)); - - if (content_viewer) { - // Hide the content viewer now that the frame is going away... - - content_viewer->Hide(); + if(mSubShell) { + // notify the pres shell that a docshell has been destroyed + if (mPresShellWeak) { + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + if (ps) { + ps->SetSubShellFor(mContent, nsnull); + } } + mSubShell->Destroy(); } - - if (mFrameLoader && mOwnsFrameLoader) { - // We own this frame loader, and we're going away, so destroy our - // frame loader. - - mFrameLoader->Destroy(); - } + mSubShell = nsnull; // This is the location it was released before... + // Not sure if there is ordering depending on this. } PRBool nsHTMLFrameInnerFrame::GetURL(nsIContent* aContent, nsString& aResult) { - aResult.SetLength(0); + aResult.SetLength(0); nsCOMPtr type; aContent->GetTag(*getter_AddRefs(type)); - + if (type.get() == nsHTMLAtoms::object) { if (NS_CONTENT_ATTR_HAS_VALUE == (aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::data, aResult))) if (aResult.Length() > 0) @@ -701,7 +695,7 @@ PRBool nsHTMLFrameInnerFrame::GetURL(nsIContent* aContent, nsString& aResult) PRBool nsHTMLFrameInnerFrame::GetName(nsIContent* aContent, nsString& aResult) { - aResult.SetLength(0); + aResult.SetLength(0); if (NS_CONTENT_ATTR_HAS_VALUE == (aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, aResult))) { if (aResult.Length() > 0) { @@ -740,7 +734,7 @@ PRInt32 nsHTMLFrameInnerFrame::GetScrolling(nsIContent* aContent) returnValue = NS_STYLE_OVERFLOW_AUTO; break; } - } + } } // Check style for overflow @@ -814,6 +808,12 @@ nsHTMLFrameInnerFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); + if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) { + nsISupports *tmp = NS_STATIC_CAST(nsIWebProgressListener *, this); + *aInstancePtr = tmp; + return NS_OK; + } + if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference))) { nsISupports *tmp = NS_STATIC_CAST(nsISupportsWeakReference *, this); *aInstancePtr = tmp; @@ -823,6 +823,60 @@ nsHTMLFrameInnerFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) return nsLeafFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnStateChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aStateFlags, PRUint32 aStatus) +{ + if (!((~aStateFlags) & (nsIWebProgressListener::STATE_IS_DOCUMENT | + nsIWebProgressListener::STATE_TRANSFERRING))) { + nsCOMPtr win(do_GetInterface(mSubShell)); + nsCOMPtr eventTarget(do_QueryInterface(win)); + nsCOMPtr eventListener(do_QueryInterface(mContent)); + + if (eventTarget && eventListener) { + eventTarget->AddEventListener(NS_LITERAL_STRING("load"), eventListener, + PR_FALSE); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnProgressChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsIURI *location) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsresult aStatus, + const PRUnichar *aMessage) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLFrameInnerFrame::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, PRInt32 state) +{ + return NS_OK; +} + #ifdef DEBUG NS_IMETHODIMP nsHTMLFrameInnerFrame::GetFrameName(nsAString& aResult) const { @@ -834,7 +888,7 @@ NS_IMETHODIMP nsHTMLFrameInnerFrame::GetFrameType(nsIAtom** aType) const { NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer"); - *aType = nsLayoutAtoms::htmlFrameInnerFrame; + *aType = nsLayoutAtoms::htmlFrameInnerFrame; NS_ADDREF(*aType); return NS_OK; } @@ -846,90 +900,33 @@ nsHTMLFrameInnerFrame::Paint(nsIPresContext* aPresContext, nsFramePaintLayer aWhichLayer, PRUint32 aFlags) { - //printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, - //aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); if there is - //not web shell paint based on our background color, otherwise let - //the web shell paint the sub document + //printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); + // if there is not web shell paint based on our background color, + // otherwise let the web shell paint the sub document - // isPaginated is a temporary fix for Bug 75737 and this should all - // be fixed correctly by Bug 75739 + // isPaginated is a temporary fix for Bug 75737 + // and this should all be fixed correctly by Bug 75739 PRBool isPaginated; aPresContext->IsPaginated(&isPaginated); - - if (!isPaginated) { - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - - if (!docShell) { - const nsStyleBackground* color = - (const nsStyleBackground*)mStyleContext-> - GetStyleData(eStyleStruct_Background); - - aRenderingContext.SetColor(color->mBackgroundColor); - aRenderingContext.FillRect(mRect); - } + if (!mSubShell && !isPaginated) { + const nsStyleBackground* color = + (const nsStyleBackground*)mStyleContext->GetStyleData(eStyleStruct_Background); + aRenderingContext.SetColor(color->mBackgroundColor); + aRenderingContext.FillRect(mRect); } - DO_GLOBAL_REFLOW_COUNT_DSP("nsHTMLFrameInnerFrame", &aRenderingContext); - return NS_OK; } -void -nsHTMLFrameInnerFrame::GetParentContent(nsIContent** aContent) +NS_IMETHODIMP +nsHTMLFrameInnerFrame::GetParentContent(nsIContent*& aContent) { - *aContent = nsnull; - - nsIFrame* parent = nsnull; - GetParent(&parent); - - if (parent) { - parent->GetContent(aContent); + nsHTMLFrameOuterFrame* parent; + nsresult rv = GetParent((nsIFrame**)&parent); + if (NS_SUCCEEDED(rv) && parent) { + rv = parent->GetContent(&aContent); } -} - -nsresult -nsHTMLFrameInnerFrame::GetDocShell(nsIDocShell **aDocShell) -{ - *aDocShell = nsnull; - - nsCOMPtr content; - GetParentContent(getter_AddRefs(content)); - - if (!content) { - // Hmm, no content in this frame (or in the parent, really), - // that's odd, not much to be done here then. - - return NS_OK; - } - - if (!mFrameLoader) { - nsCOMPtr frame_loader_owner = - do_QueryInterface(content); - - if (frame_loader_owner) { - frame_loader_owner->GetFrameLoader(getter_AddRefs(mFrameLoader)); - } - - if (!mFrameLoader) { - nsresult rv = NS_OK; - - // No frame loader available from the content, create our own... - mFrameLoader = do_CreateInstance(NS_FRAMELOADER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - // ... remember that we own this frame loader... - mOwnsFrameLoader = PR_TRUE; - - // ... initialize it... - mFrameLoader->Init(content); - - // ... and tell it to start loading. - mFrameLoader->LoadFrame(); - } - } - - return mFrameLoader->GetDocShell(aDocShell); + return rv; } NS_IMETHODIMP @@ -955,100 +952,287 @@ nsHTMLFrameInnerFrame::DidReflow(nsIPresContext* aPresContext, if (newVis != oldVis) { nsCOMPtr vm; view->GetViewManager(*getter_AddRefs(vm)); - if (vm) { + if (vm != nsnull) { vm->SetViewVisibility(view, newVis); } } } } - + return rv; } nsresult -nsHTMLFrameInnerFrame::ShowDocShell(nsIPresContext* aPresContext) +nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext) { - nsCOMPtr docShell; - nsresult rv = GetDocShell(getter_AddRefs(docShell)); - NS_ENSURE_SUCCESS(rv, rv); + nsresult rv; + nsCOMPtr parentContent; + GetParentContent(*getter_AddRefs(parentContent)); - // Make sure there's a document in the docshell. - nsCOMPtr win(do_GetInterface(docShell)); - NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED); + // Bug 8065: Don't exceed some maximum depth in content frames (MAX_DEPTH_CONTENT_FRAMES) + PRInt32 depth = 0; + nsCOMPtr parentAsSupports; + aPresContext->GetContainer(getter_AddRefs(parentAsSupports)); + if (parentAsSupports) { + nsCOMPtr parentAsItem(do_QueryInterface(parentAsSupports)); + while (parentAsItem) { + depth++; + if (MAX_DEPTH_CONTENT_FRAMES < depth) + return NS_ERROR_UNEXPECTED; // Too deep, give up! (silently?) - nsCOMPtr dom_doc; - - // This will synchronously create a document if there is no - // document in the window yet. - - win->GetDocument(getter_AddRefs(dom_doc)); - - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - - if (presShell) { - // The docshell is already showing, nothing left to do... - - return NS_OK; + // Only count depth on content, not chrome. + // If we wanted to limit total depth, skip the following check: + PRInt32 parentType; + parentAsItem->GetItemType(&parentType); + if (nsIDocShellTreeItem::typeContent == parentType) { + nsIDocShellTreeItem* temp = parentAsItem; + temp->GetParent(getter_AddRefs(parentAsItem)); + } else { + break; // we have exited content, stop counting, depth is OK! + } + } } - nsCOMPtr docShellTreeItem(do_QueryInterface(docShell)); + mSubShell = do_CreateInstance(kWebShellCID); + NS_ENSURE_TRUE(mSubShell, NS_ERROR_FAILURE); - nsCOMPtr parentDocShellTreeItem; - docShellTreeItem->GetParent(getter_AddRefs(parentDocShellTreeItem)); - - nsCOMPtr parentDocShell = - do_QueryInterface(parentDocShellTreeItem); - - nsCOMPtr parentPresShell; - parentDocShell->GetPresShell(getter_AddRefs(parentPresShell)); - - nsCOMPtr content; - GetParentContent(getter_AddRefs(content)); - - // pass along marginwidth, marginheight, scrolling so sub document - // can use it - docShell->SetMarginWidth(GetMarginWidth(aPresContext, content)); - docShell->SetMarginHeight(GetMarginHeight(aPresContext, content)); + // notify the pres shell that a docshell has been created + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + if (presShell) + { + nsCOMPtr subShellAsSupports(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE); + presShell->SetSubShellFor(mContent, subShellAsSupports); + //We need to be able to get back to the presShell to unset the subshell at destruction + mPresShellWeak = getter_AddRefs(NS_GetWeakReference(presShell)); + } + + nsCOMPtr docShell(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + // pass along marginwidth, marginheight, scrolling so sub document can use it + docShell->SetMarginWidth(GetMarginWidth(aPresContext, parentContent)); + docShell->SetMarginHeight(GetMarginHeight(aPresContext, parentContent)); // Current and initial scrolling is set so that all succeeding docs // will use the scrolling value set here, regardless if scrolling is // set by viewing a particular document (e.g. XUL turns off scrolling) - nsCOMPtr scrollableContainer(do_QueryInterface(docShell)); - + nsCOMPtr scrollableContainer(do_QueryInterface(mSubShell)); if (scrollableContainer) { scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y, - GetScrolling(content)); + GetScrolling(parentContent)); scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X, - GetScrolling(content)); + GetScrolling(parentContent)); } - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem(do_QueryInterface(mSubShell)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); + nsString frameName; + if (GetName(parentContent, frameName)) { + docShellAsItem->SetName(frameName.get()); + } + + // If our container is a web-shell, inform it that it has a new + // child. If it's not a web-shell then some things will not operate + // properly. + nsCOMPtr container; + aPresContext->GetContainer(getter_AddRefs(container)); + if (container) { + nsCOMPtr parentAsNode(do_QueryInterface(container)); + if (parentAsNode) { + nsCOMPtr parentAsItem(do_QueryInterface(parentAsNode)); + PRInt32 parentType; + parentAsItem->GetItemType(&parentType); + + nsIAtom* typeAtom = NS_NewAtom("type"); + nsAutoString value, valuePiece; + PRBool isContent; + + isContent = PR_FALSE; + if (NS_SUCCEEDED(parentContent->GetAttr(kNameSpaceID_None, + typeAtom, value))) { + + // we accept "content" and "content-xxx" values. + // at time of writing, we expect "xxx" to be "primary", but + // someday it might be an integer expressing priority + value.Left(valuePiece, 7); + if (valuePiece.EqualsIgnoreCase("content") && + (value.Length() == 7 || + value.Mid(valuePiece, 7, 1) == 1 && valuePiece.Equals(NS_LITERAL_STRING("-")))) + isContent = PR_TRUE; + } + NS_IF_RELEASE(typeAtom); + if (isContent) { + // The web shell's type is content. + docShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent); + } else { + // Inherit our type from our parent webshell. If it is + // chrome, we'll be chrome. If it is content, we'll be + // content. + docShellAsItem->SetItemType(parentType); + } + + parentAsNode->AddChild(docShellAsItem); + + if (isContent) { + nsCOMPtr parentTreeOwner; + parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner)); + if(parentTreeOwner) + parentTreeOwner->ContentShellAdded(docShellAsItem, + value.EqualsIgnoreCase("content-primary") ? PR_TRUE : PR_FALSE, + value.get()); + } + // connect the container... + nsCOMPtr webShell(do_QueryInterface(mSubShell)); + nsCOMPtr outerContainer(do_QueryInterface(container)); + if (outerContainer) + webShell->SetContainer(outerContainer); + + + // Make sure all shells have links back to the content element in the + // nearest enclosing chrome shell. + nsCOMPtr parentShell(do_QueryInterface(parentAsNode)); + nsCOMPtr chromeEventHandler; + if (parentType == nsIDocShellTreeItem::typeChrome) { + // Our parent shell is a chrome shell. It is therefore our nearest + // enclosing chrome shell. + chromeEventHandler = do_QueryInterface(mContent); + NS_WARN_IF_FALSE(chromeEventHandler, "This mContent should implement this."); + } + else { + // Our parent shell is a content shell. Get the chrome info from + // it and use that for our shell as well. + parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler)); + } + + docShell->SetChromeEventHandler(chromeEventHandler); + } + } nsCOMPtr widget; - rv = CreateViewAndWidget(aPresContext, getter_AddRefs(widget)); if (NS_FAILED(rv)) { return rv; } - nsCOMPtr baseWindow(do_QueryInterface(docShell)); + mSubShell->InitWindow(nsnull, widget, 0, 0, 10, 10); + mSubShell->Create(); - if (baseWindow) { - baseWindow->InitWindow(nsnull, widget, 0, 0, 10, 10); - - // This is kinda whacky, this "Create()" calldoesn't really create - // anything, one starts to wonder why this was named "Create"... - - baseWindow->Create(); - - baseWindow->SetVisibility(PR_TRUE); - } + mSubShell->SetVisibility(PR_TRUE); return NS_OK; } +nsresult +nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext) +{ + // Bug 8065: Preventing frame nesting recursion - if the frames are + // too deep we don't create a mSubShell, so this isn't an assert: + if (!mSubShell) return NS_OK; + + // Prevent recursion + mCreatingViewer=PR_TRUE; + + // Get the URL to load + nsCOMPtr parentContent; + nsresult rv = GetParentContent(*getter_AddRefs(parentContent)); + NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && parentContent, rv); + + nsAutoString url; + GetURL(parentContent, url); + url.Trim(" \t\n\r"); + if (url.IsEmpty()) // Load about:blank into a frame if not URL is specified (bug 35986) + url = NS_LITERAL_STRING("about:blank"); + + // Make an absolute URL + nsCOMPtr baseURL; + nsCOMPtr htmlContent = do_QueryInterface(parentContent, &rv); + nsCOMPtr doc; + if (NS_SUCCEEDED(rv) && htmlContent) { + htmlContent->GetBaseURL(*getter_AddRefs(baseURL)); + (void) htmlContent->GetDocument(*getter_AddRefs(doc)); + } + else { + rv = parentContent->GetDocument(*getter_AddRefs(doc)); + if (NS_SUCCEEDED(rv) && doc) { + doc->GetBaseURL(*getter_AddRefs(baseURL)); + } + } + if (!baseURL) return NS_ERROR_NULL_POINTER; + + nsAutoString docCharset; + if (doc) + (void) doc->GetDocumentCharacterSet(docCharset); + + nsAutoString absURL; + rv = NS_MakeAbsoluteURI(absURL, url, baseURL); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), absURL, + docCharset.IsEmpty() ? nsnull : NS_ConvertUCS2toUTF8(docCharset).get()); + + // Check for security + nsCOMPtr secMan = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + // Get base URL + nsCOMPtr baseURI; + rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI)); + + // Get docshell and create load info + nsCOMPtr docShell(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + nsCOMPtr loadInfo; + docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); + NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); + + // Get referring URL + nsCOMPtr referrer; + nsCOMPtr principal; + rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal)); + NS_ENSURE_SUCCESS(rv, rv); + // If we were called from script, get the referring URL from the script + if (principal) { + nsCOMPtr codebase = do_QueryInterface(principal); + if (codebase) { + rv = codebase->GetURI(getter_AddRefs(referrer)); + NS_ENSURE_SUCCESS(rv, rv); + } + // Pass the script principal to the docshell + nsCOMPtr owner = do_QueryInterface(principal); + loadInfo->SetOwner(owner); + } + if (!referrer) { // We're not being called form script, tell the docshell + // to inherit an owner from the current document. + loadInfo->SetInheritOwner(PR_TRUE); + referrer = baseURI; + } + + loadInfo->SetReferrer(referrer); + + // Check if we are allowed to load absURL + nsCOMPtr newURI; + rv = NS_NewURI(getter_AddRefs(newURI), absURL, nsnull, baseURI); + NS_ENSURE_SUCCESS(rv, rv); + rv = secMan->CheckLoadURI(referrer, newURI, nsIScriptSecurityManager::STANDARD); + if (NS_FAILED(rv)) + return rv; // We're not + + nsCOMPtr webProgress(do_GetInterface(mSubShell)); + + if (webProgress) { + webProgress->AddProgressListener(this); + } + + rv = docShell->LoadURI(uri, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, PR_FALSE); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL"); + + return rv; +} + + nsresult nsHTMLFrameInnerFrame::CreateViewAndWidget(nsIPresContext* aPresContext, nsIWidget** aWidget) @@ -1058,29 +1242,28 @@ nsHTMLFrameInnerFrame::CreateViewAndWidget(nsIPresContext* aPresContext, nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + if (!presShell) return NS_ERROR_FAILURE; float t2p; aPresContext->GetTwipsToPixels(&t2p); // create, init, set the parent of the view nsIView* view; - nsresult rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, - NS_GET_IID(nsIView), - (void **)&view); - if (NS_FAILED(rv)) { - NS_ERROR("Could not create view for nsHTMLFrame"); + nsresult rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, NS_GET_IID(nsIView), + (void **)&view); + if (NS_OK != rv) { + NS_ASSERTION(0, "Could not create view for nsHTMLFrame"); return rv; } nsIView* parView; nsPoint origin; - GetOffsetFromView(aPresContext, origin, &parView); + GetOffsetFromView(aPresContext, origin, &parView); nsRect viewBounds(origin.x, origin.y, 10, 10); nsCOMPtr viewMan; - presShell->GetViewManager(getter_AddRefs(viewMan)); + presShell->GetViewManager(getter_AddRefs(viewMan)); rv = view->Init(viewMan, viewBounds, parView); // XXX put it at the end of the document order until we can do better viewMan->InsertChild(parView, view, nsnull, PR_TRUE); @@ -1109,39 +1292,41 @@ nsHTMLFrameInnerFrame::Init(nsIPresContext* aPresContext, nsIStyleContext* aContext, nsIFrame* aPrevInFlow) { - nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, - aPrevInFlow); + nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); if (NS_FAILED(rv)) return rv; // determine if we are a printcontext PRBool shouldCreateDoc = PR_TRUE; - nsCOMPtr thePrinterContext(do_QueryInterface(aPresContext)); - - if (thePrinterContext) { + nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); + if (thePrinterContext) { // we are printing shouldCreateDoc = PR_FALSE; } - // for print preview we want to create the view and widget but + // for print preview we want to create the view and widget but // we do not want to load the document, it is alerady loaded. - nsCOMPtr thePrintPreviewContext = - do_QueryInterface(aPresContext); - - if (thePrintPreviewContext) { + nsCOMPtr thePrintPreviewContext = do_QueryInterface(aPresContext); + if (thePrintPreviewContext) { nsCOMPtr widget; rv = CreateViewAndWidget(aPresContext, getter_AddRefs(widget)); - if (NS_FAILED(rv)) { return rv; } - // we are in PrintPreview shouldCreateDoc = PR_FALSE; } - - if (shouldCreateDoc) { - ShowDocShell(aPresContext); + + if (!mCreatingViewer && shouldCreateDoc) { + // create the web shell + // we do this even if the size is not positive (bug 11762) + // we do this even if there is no src (bug 16218) + if (!mSubShell) + rv = CreateDocShell(aPresContext); + // Whether or not we had to create a webshell, load the document + if (NS_SUCCEEDED(rv)) { + DoLoadURL(aPresContext); + } } return NS_OK; @@ -1162,55 +1347,41 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext, nsresult rv = NS_OK; - // use the max size set in aReflowState by the nsHTMLFrameOuterFrame - // as our size + // use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size GetDesiredSize(aPresContext, aReflowState, aDesiredSize); aStatus = NS_FRAME_COMPLETE; - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr baseWindow(do_QueryInterface(docShell)); - // resize the sub document - if (baseWindow) { + if(mSubShell) { float t2p; aPresContext->GetTwipsToPixels(&t2p); PRInt32 x = 0; PRInt32 y = 0; - baseWindow->GetPositionAndSize(&x, &y, nsnull, nsnull); - PRInt32 cx = NSToCoordRound(aDesiredSize.width * t2p); + mSubShell->GetPositionAndSize(&x, &y, nsnull, nsnull); + PRInt32 cx = NSToCoordRound(aDesiredSize.width * t2p); PRInt32 cy = NSToCoordRound(aDesiredSize.height * t2p); - baseWindow->SetPositionAndSize(x, y, cx, cy, PR_FALSE); + mSubShell->SetPositionAndSize(x, y, cx, cy, PR_FALSE); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x", - aDesiredSize.width, aDesiredSize.height, aStatus)); + ("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x", + aDesiredSize.width, aDesiredSize.height, aStatus)); } - + return rv; } // load a new url nsresult -nsHTMLFrameInnerFrame::ReloadURL() +nsHTMLFrameInnerFrame::ReloadURL(nsIPresContext* aPresContext) { - if (!mOwnsFrameLoader || !mFrameLoader) { - // If we don't own the frame loader, we're not in charge of what's - // loaded into it. - - return NS_OK; - } - - return mFrameLoader->LoadFrame(); + return DoLoadURL(aPresContext); } - -void +void nsHTMLFrameInnerFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize) @@ -1220,28 +1391,19 @@ nsHTMLFrameInnerFrame::GetDesiredSize(nsIPresContext* aPresContext, aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; - // For unknown reasons, the maxElementSize for the InnerFrame is - // used, but the maxElementSize for the OuterFrame is ignored, make - // sure to get it right here! - + // For unknown reasons, the maxElementSize for the InnerFrame is used, but the + // maxElementSize for the OuterFrame is ignored, make sure to get it right here! if (aDesiredSize.maxElementSize) { if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) || - (eStyleUnit_Percent == - aReflowState.mStylePosition->mWidth.GetUnit())) { - // percent width springy down to 0 px - - aDesiredSize.maxElementSize->width = 0; + (eStyleUnit_Percent == aReflowState.mStylePosition->mWidth.GetUnit())) { + aDesiredSize.maxElementSize->width = 0; // percent width springy down to 0 px } else { aDesiredSize.maxElementSize->width = aDesiredSize.width; } - if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) || - (eStyleUnit_Percent == - aReflowState.mStylePosition->mHeight.GetUnit())) { - // percent height springy down to 0px - - aDesiredSize.maxElementSize->height = 0; + (eStyleUnit_Percent == aReflowState.mStylePosition->mHeight.GetUnit())) { + aDesiredSize.maxElementSize->height = 0; // percent height springy down to 0px } else { aDesiredSize.maxElementSize->height = aDesiredSize.height; @@ -1249,9 +1411,9 @@ nsHTMLFrameInnerFrame::GetDesiredSize(nsIPresContext* aPresContext, } } -/****************************************************************************** +/******************************************************************************* * FrameLoadingInfo - *****************************************************************************/ + ******************************************************************************/ FrameLoadingInfo::FrameLoadingInfo(const nsSize& aSize) { NS_INIT_REFCNT(); diff --git a/layout/html/document/src/nsFrameSetFrame.cpp b/layout/html/document/src/nsFrameSetFrame.cpp index eecf2c845bc..a1a4b002844 100644 --- a/layout/html/document/src/nsFrameSetFrame.cpp +++ b/layout/html/document/src/nsFrameSetFrame.cpp @@ -63,6 +63,7 @@ #define ALL_VIS 0x000F #define NONE_VIS 0x0000 +static NS_DEFINE_IID(kIFramesetFrameIID, NS_IFRAMESETFRAME_IID); static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); /******************************************************************************* @@ -251,7 +252,7 @@ nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; - } else if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) { + } else if (aIID.Equals(kIFramesetFrameIID)) { *aInstancePtr = (void*)this; return NS_OK; } else if (aIID.Equals(NS_GET_IID(nsIObserver))) { @@ -326,8 +327,7 @@ nsHTMLFramesetFrame::Init(nsIPresContext* aPresContext, mTopLevelFrameset = (nsHTMLFramesetFrame*)this; while (parentFrame) { nsHTMLFramesetFrame* frameset; - rv = parentFrame->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), - (void**)&frameset); + rv = parentFrame->QueryInterface(kIFramesetFrameIID, (void**)&frameset); if (NS_SUCCEEDED(rv)) { mTopLevelFrameset = frameset; parentFrame->GetParent((nsIFrame**)&parentFrame); @@ -1404,7 +1404,7 @@ PRBool nsHTMLFramesetFrame::ChildIsFrameset(nsIFrame* aChild) { nsIFrame* childFrame = nsnull; - aChild->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), (void**)&childFrame); + aChild->QueryInterface(kIFramesetFrameIID, (void**)&childFrame); if (childFrame) { return PR_TRUE; } diff --git a/layout/html/document/src/nsFrameSetFrame.h b/layout/html/document/src/nsFrameSetFrame.h index 88000505dff..fe786185fd8 100644 --- a/layout/html/document/src/nsFrameSetFrame.h +++ b/layout/html/document/src/nsFrameSetFrame.h @@ -57,8 +57,7 @@ struct nsGUIEvent; class nsHTMLFramesetFrame; #define NS_IFRAMESETFRAME_IID \ -{ 0xf47deac0, 0x4200, 0x11d2, \ - { 0x80, 0x3c, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } } +{ 0xf47deac0, 0x4200, 0x11d2, { 0x80, 0x3c, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } } #define NO_COLOR 0xFFFFFFFA @@ -116,10 +115,8 @@ struct nsFramesetDrag { class nsHTMLFramesetFrame : public nsHTMLContainerFrame, public nsIObserver { -public: - // Woohoo, concrete class with an IID! - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFRAMESETFRAME_IID) +public: nsHTMLFramesetFrame(); virtual ~nsHTMLFramesetFrame(); diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index 264fc37440e..0bdc6d98e1f 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -2657,7 +2657,7 @@ CSSStyleSheetImpl::SetDisabled(PRBool aDisabled) PRBool oldState = mDisabled; mDisabled = aDisabled; - if (mDocument && (mDisabled != oldState)) { + if ((nsnull != mDocument) && (mDisabled != oldState)) { mDocument->SetStyleSheetDisabledState(this, mDisabled); } diff --git a/layout/xul/base/src/nsBrowserBoxObject.cpp b/layout/xul/base/src/nsBrowserBoxObject.cpp index 868e2563339..0bd87006df5 100644 --- a/layout/xul/base/src/nsBrowserBoxObject.cpp +++ b/layout/xul/base/src/nsBrowserBoxObject.cpp @@ -38,9 +38,9 @@ #include "nsCOMPtr.h" #include "nsIBrowserBoxObject.h" #include "nsBoxObject.h" +#include "nsIPresShell.h" #include "nsIFrame.h" #include "nsIDocShell.h" -#include "nsIDocument.h" #include "nsXPIDLString.h" class nsBrowserBoxObject : public nsIBrowserBoxObject, public nsBoxObject @@ -91,27 +91,15 @@ nsBrowserBoxObject::~nsBrowserBoxObject() NS_IMETHODIMP nsBrowserBoxObject::GetDocShell(nsIDocShell** aResult) { *aResult = nsnull; - if (!mPresShell) return NS_OK; - nsCOMPtr doc, sub_doc; - mPresShell->GetDocument(getter_AddRefs(doc)); - - doc->GetSubDocumentFor(mContent, getter_AddRefs(sub_doc)); - - if (!sub_doc) { + nsCOMPtr subShell; + mPresShell->GetSubShellFor(mContent, getter_AddRefs(subShell)); + if(!subShell) return NS_OK; - } - nsCOMPtr container; - sub_doc->GetContainer(getter_AddRefs(container)); - - if (!container) { - return NS_OK; - } - - return CallQueryInterface(container, aResult); + return CallQueryInterface(subShell, aResult); //Addref happens here. } // Creation Routine /////////////////////////////////////////////////////////////////////// diff --git a/layout/xul/base/src/nsEditorBoxObject.cpp b/layout/xul/base/src/nsEditorBoxObject.cpp index 7e48b0b6d11..ff597efeb25 100644 --- a/layout/xul/base/src/nsEditorBoxObject.cpp +++ b/layout/xul/base/src/nsEditorBoxObject.cpp @@ -38,7 +38,7 @@ #include "nsCOMPtr.h" #include "nsIEditorBoxObject.h" #include "nsBoxObject.h" -#include "nsIDocument.h" +#include "nsIPresShell.h" #include "nsIFrame.h" #include "nsIEditorShell.h" #include "nsIComponentManager.h" @@ -128,27 +128,15 @@ NS_IMETHODIMP nsEditorBoxObject::GetEditorShell(nsIEditorShell** aResult) NS_IMETHODIMP nsEditorBoxObject::GetDocShell(nsIDocShell** aResult) { *aResult = nsnull; - if (!mPresShell) return NS_OK; - nsCOMPtr doc, sub_doc; - mPresShell->GetDocument(getter_AddRefs(doc)); - - doc->GetSubDocumentFor(mContent, getter_AddRefs(sub_doc)); - - if (!sub_doc) { + nsCOMPtr subShell; + mPresShell->GetSubShellFor(mContent, getter_AddRefs(subShell)); + if(!subShell) return NS_OK; - } - nsCOMPtr container; - sub_doc->GetContainer(getter_AddRefs(container)); - - if (!container) { - return NS_OK; - } - - return CallQueryInterface(container, aResult); + return CallQueryInterface(subShell, aResult); //Addref happens here. } // Creation Routine /////////////////////////////////////////////////////////////////////// diff --git a/layout/xul/base/src/nsIFrameBoxObject.cpp b/layout/xul/base/src/nsIFrameBoxObject.cpp index 8179e508870..4f8dbe35690 100644 --- a/layout/xul/base/src/nsIFrameBoxObject.cpp +++ b/layout/xul/base/src/nsIFrameBoxObject.cpp @@ -38,7 +38,6 @@ #include "nsCOMPtr.h" #include "nsIIFrameBoxObject.h" #include "nsBoxObject.h" -#include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsIDocShell.h" @@ -88,27 +87,15 @@ nsIFrameBoxObject::~nsIFrameBoxObject() NS_IMETHODIMP nsIFrameBoxObject::GetDocShell(nsIDocShell** aResult) { *aResult = nsnull; - if (!mPresShell) return NS_OK; - nsCOMPtr doc, sub_doc; - mPresShell->GetDocument(getter_AddRefs(doc)); - - doc->GetSubDocumentFor(mContent, getter_AddRefs(sub_doc)); - - if (!sub_doc) { + nsCOMPtr subShell; + mPresShell->GetSubShellFor(mContent, getter_AddRefs(subShell)); + if(!subShell) return NS_OK; - } - nsCOMPtr container; - sub_doc->GetContainer(getter_AddRefs(container)); - - if (!container) { - return NS_OK; - } - - return CallQueryInterface(container, aResult); + return CallQueryInterface(subShell, aResult); //Addref happens here. } // Creation Routine /////////////////////////////////////////////////////////////////////// diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index 6771143f506..dfe2a08af83 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -804,7 +804,7 @@ nsDocLoaderImpl::GetDOMWindow(nsIDOMWindow **aResult) *aResult = window; NS_IF_ADDREF(*aResult); } else { - rv = NS_ERROR_FAILURE; + rv = NS_ERROR_FAILURE; } return rv;