diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index e87890c4da4..6989cdba499 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -83,6 +83,9 @@ class nsISupportsArray; class nsIScriptLoader; class nsIContentSink; class nsIScriptEventManager; +class nsICSSLoader; +class nsIHTMLStyleSheet; +class nsIHTMLCSSStyleSheet; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ @@ -415,6 +418,24 @@ public: virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, PRBool aApplicable) = 0; + /** + * Get this document's CSSLoader. May return null in error + * conditions (OOM) + */ + virtual nsICSSLoader* GetCSSLoader() = 0; + + /** + * Get this document's attribute stylesheet. May return null if + * there isn't one. + */ + virtual nsIHTMLStyleSheet* GetAttributeStyleSheet() const = 0; + + /** + * Get this document's inline style sheet. May return null if there + * isn't one + */ + virtual nsIHTMLCSSStyleSheet* GetInlineStyleSheet() const = 0; + /** * Set the object from which a document can get a script context. * This is the context within which all scripts (during document diff --git a/mozilla/content/base/src/nsContentSink.cpp b/mozilla/content/base/src/nsContentSink.cpp index 3b992cadd17..06dcdf8df93 100644 --- a/mozilla/content/base/src/nsContentSink.cpp +++ b/mozilla/content/base/src/nsContentSink.cpp @@ -38,7 +38,6 @@ #include "nsContentSink.h" #include "nsIScriptLoader.h" #include "nsIDocument.h" -#include "nsIHTMLContentContainer.h" #include "nsICSSLoader.h" #include "nsStyleLinkElement.h" #include "nsINodeInfo.h" @@ -177,10 +176,7 @@ nsContentSink::Init(nsIDocument* aDoc, nsresult rv = loader->AddObserver(proxy); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr htmlContainer(do_QueryInterface(aDoc)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(mCSSLoader)); - } + mCSSLoader = aDoc->GetCSSLoader(); // XXX this presumes HTTP header info is already set in document // XXX if it isn't we need to set it here... diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index adfa9d9542a..5acc85fa812 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -573,6 +573,14 @@ nsDocument::~nsDocument() mNodeInfoManager->DropDocumentReference(); } + if (mAttrStyleSheet) { + mAttrStyleSheet->SetOwningDocument(nsnull); + } + + if (mStyleAttrStyleSheet) { + mStyleAttrStyleSheet->SetOwningDocument(nsnull); + } + delete mHeaderData; delete mBoxObjectTable; delete mXPathDocument; diff --git a/mozilla/content/base/src/nsStyleLinkElement.cpp b/mozilla/content/base/src/nsStyleLinkElement.cpp index af1b6d2bd0b..1aab63c7339 100644 --- a/mozilla/content/base/src/nsStyleLinkElement.cpp +++ b/mozilla/content/base/src/nsStyleLinkElement.cpp @@ -32,7 +32,6 @@ #include "nsIDOMNode.h" #include "nsIDOMStyleSheet.h" #include "nsIDOMText.h" -#include "nsIHTMLContentContainer.h" #include "nsIUnicharInputStream.h" #include "nsNetUtil.h" #include "nsUnicharUtils.h" @@ -239,12 +238,7 @@ nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument, return NS_OK; } - nsCOMPtr htmlContainer(do_QueryInterface(doc)); - nsCOMPtr loader; - - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(loader)); - } + nsICSSLoader* loader = doc->GetCSSLoader(); if (!loader) { return NS_OK; diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 869c9a7adcc..f949f38612b 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -90,7 +90,6 @@ #include "nsILayoutHistoryState.h" #include "nsIFrameManager.h" -#include "nsIHTMLContentContainer.h" #include "nsHTMLParts.h" #include "nsContentUtils.h" #include "nsString.h" @@ -1245,19 +1244,6 @@ nsGenericHTMLElement::ScrollIntoView(PRBool aTop) } -static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument) -{ - nsIHTMLStyleSheet* sheet = nsnull; - - if (aDocument) { - nsCOMPtr container(do_QueryInterface(aDocument)); - - container->GetAttributeStyleSheet(&sheet); - } - - return sheet; -} - PRBool nsGenericHTMLElement::InNavQuirksMode(nsIDocument* aDoc) { @@ -1281,10 +1267,9 @@ nsGenericHTMLElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, if (!doNothing && mDocument && mAttributes) { ReparseStyleAttribute(); - nsIHTMLStyleSheet* sheet = GetAttrStyleSheet(mDocument); + nsIHTMLStyleSheet* sheet = mDocument->GetAttributeStyleSheet(); if (sheet) { mAttributes->SetStyleSheet(sheet); - NS_RELEASE(sheet); } } } @@ -1712,8 +1697,7 @@ nsGenericHTMLElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, // set as string value to avoid another string copy PRBool mapped = HasAttributeDependentStyle(aAttribute); - nsCOMPtr sheet = - dont_AddRef(GetAttrStyleSheet(mDocument)); + nsIHTMLStyleSheet* sheet = mDocument ? mDocument->GetAttributeStyleSheet() : nsnull; if (!mAttributes) { result = NS_NewHTMLAttributes(&mAttributes); @@ -1928,7 +1912,7 @@ nsGenericHTMLElement::SetHTMLAttribute(nsIAtom* aAttribute, } PRBool mapped = HasAttributeDependentStyle(aAttribute); - nsCOMPtr sheet; + nsIHTMLStyleSheet* sheet = nsnull; if (mDocument) { PRBool modification = PR_TRUE; nsAutoString oldValueStr; @@ -1945,7 +1929,8 @@ nsGenericHTMLElement::SetHTMLAttribute(nsIAtom* aAttribute, if (aNotify) { mDocument->AttributeWillChange(this, kNameSpaceID_None, aAttribute); } - sheet = dont_AddRef(GetAttrStyleSheet(mDocument)); + sheet = mDocument->GetAttributeStyleSheet(); + // XXXbz this code is repeated at the end of the method too... seems silly. if (sheet) { if (!mAttributes) { nsresult rv = NS_NewHTMLAttributes(&mAttributes); @@ -2061,8 +2046,7 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, } if (mAttributes) { - nsCOMPtr sheet - = dont_AddRef(GetAttrStyleSheet(mDocument)); + nsIHTMLStyleSheet* sheet = mDocument ? mDocument->GetAttributeStyleSheet() : nsnull; PRInt32 count; result = mAttributes->UnsetAttributeFor(aAttribute, aNameSpaceID, this, sheet, count); @@ -3119,13 +3103,8 @@ nsGenericHTMLElement::ParseStyleAttribute(const nsAString& aValue, nsHTMLValue& } if (isCSS) { - nsCOMPtr cssLoader; + nsICSSLoader* cssLoader = doc->GetCSSLoader(); nsCOMPtr cssParser; - nsCOMPtr htmlContainer(do_QueryInterface(doc)); - - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(cssLoader)); - } if (cssLoader) { result = cssLoader->GetParserFor(nsnull, getter_AddRefs(cssParser)); } diff --git a/mozilla/content/html/content/src/nsHTMLBodyElement.cpp b/mozilla/content/html/content/src/nsHTMLBodyElement.cpp index bb2ef95611a..16418d99353 100644 --- a/mozilla/content/html/content/src/nsHTMLBodyElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLBodyElement.cpp @@ -54,7 +54,6 @@ #include "nsIContentViewer.h" #include "nsIMarkupDocumentViewer.h" #include "nsHTMLAttributes.h" -#include "nsIHTMLContentContainer.h" #include "nsISupportsArray.h" #include "nsIFrame.h" #include "nsIDocShell.h" @@ -522,29 +521,24 @@ void MapAttributesIntoRule(const nsIHTMLMappedAttributes* aAttributes, nsRuleDat nsCOMPtr doc; presShell->GetDocument(getter_AddRefs(doc)); if (doc) { - nsCOMPtr htmlContainer = - do_QueryInterface(doc); - if (htmlContainer) { - nsCOMPtr styleSheet; - htmlContainer->GetAttributeStyleSheet(getter_AddRefs(styleSheet)); - if (styleSheet) { - aAttributes->GetAttribute(nsHTMLAtoms::link, value); - if ((eHTMLUnit_Color == value.GetUnit()) || - (eHTMLUnit_ColorName == value.GetUnit())) { - styleSheet->SetLinkColor(value.GetColorValue()); - } + nsIHTMLStyleSheet* styleSheet = doc->GetAttributeStyleSheet(); + if (styleSheet) { + aAttributes->GetAttribute(nsHTMLAtoms::link, value); + if ((eHTMLUnit_Color == value.GetUnit()) || + (eHTMLUnit_ColorName == value.GetUnit())) { + styleSheet->SetLinkColor(value.GetColorValue()); + } - aAttributes->GetAttribute(nsHTMLAtoms::alink, value); - if ((eHTMLUnit_Color == value.GetUnit()) || - (eHTMLUnit_ColorName == value.GetUnit())) { - styleSheet->SetActiveLinkColor(value.GetColorValue()); - } + aAttributes->GetAttribute(nsHTMLAtoms::alink, value); + if ((eHTMLUnit_Color == value.GetUnit()) || + (eHTMLUnit_ColorName == value.GetUnit())) { + styleSheet->SetActiveLinkColor(value.GetColorValue()); + } - aAttributes->GetAttribute(nsHTMLAtoms::vlink, value); - if ((eHTMLUnit_Color == value.GetUnit()) || - (eHTMLUnit_ColorName == value.GetUnit())) { - styleSheet->SetVisitedLinkColor(value.GetColorValue()); - } + aAttributes->GetAttribute(nsHTMLAtoms::vlink, value); + if ((eHTMLUnit_Color == value.GetUnit()) || + (eHTMLUnit_ColorName == value.GetUnit())) { + styleSheet->SetVisitedLinkColor(value.GetColorValue()); } } } @@ -573,35 +567,13 @@ nsHTMLBodyElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRu return NS_OK; } -static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument) -{ - nsIHTMLStyleSheet* sheet = nsnull; - - if (aDocument) { - nsCOMPtr container(do_QueryInterface(aDocument)); - - if (container) { - container->GetAttributeStyleSheet(&sheet); - } - } - - NS_ASSERTION(nsnull != sheet, "can't get attribute style sheet"); - return sheet; -} - NS_IMETHODIMP nsHTMLBodyElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) { nsGenericHTMLContainerElement::WalkContentStyleRules(aRuleWalker); - if (!mContentStyleRule) { - nsCOMPtr sheet; - - if (mDocument) { // find style sheet - sheet = dont_AddRef(GetAttrStyleSheet(mDocument)); - } - - mContentStyleRule = new BodyRule(this, sheet); + if (!mContentStyleRule && mDocument) { + mContentStyleRule = new BodyRule(this, mDocument->GetAttributeStyleSheet()); NS_IF_ADDREF(mContentStyleRule); } if (aRuleWalker && mContentStyleRule) { diff --git a/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp b/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp index 381e9cd33a4..17cd8523cea 100644 --- a/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp @@ -47,7 +47,6 @@ #include "nsIDOMEventReceiver.h" #include "nsIDocument.h" #include "nsIHTMLStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsHTMLAttributes.h" #include "nsIDOMMutationEvent.h" @@ -149,20 +148,6 @@ nsHTMLUnknownElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) return NS_OK; } -static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument) -{ - nsIHTMLStyleSheet *sheet=nsnull; - - if (aDocument) { - nsCOMPtr container(do_QueryInterface(aDocument)); - - container->GetAttributeStyleSheet(&sheet); - } - - return sheet; -} - - NS_IMETHODIMP nsHTMLUnknownElement::SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, @@ -206,7 +191,8 @@ nsHTMLUnknownElement::SetAttribute(PRInt32 aNameSpaceID, // set as string value to avoid another string copy PRBool mapped = HasAttributeDependentStyle(aAttribute); - nsCOMPtr sheet(dont_AddRef(GetAttrStyleSheet(mDocument))); + nsIHTMLStyleSheet* sheet = + mDocument ? mDocument->GetAttributeStyleSheet() : nsnull; if (!mAttributes) { result = NS_NewHTMLAttributes(&mAttributes); NS_ENSURE_SUCCESS(result, result); diff --git a/mozilla/content/html/document/src/Makefile.in b/mozilla/content/html/document/src/Makefile.in index ff3d4c09547..8d292ef4cdb 100644 --- a/mozilla/content/html/document/src/Makefile.in +++ b/mozilla/content/html/document/src/Makefile.in @@ -72,7 +72,6 @@ CPPSRCS = \ EXPORTS = \ nsIHTMLDocument.h \ - nsIHTMLContentContainer.h \ $(NULL) # we don't want the shared lib, but we want to force the creation of a static lib. diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index a001f0d3545..3f509e014e5 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -309,14 +309,6 @@ nsHTMLDocument::nsHTMLDocument() nsHTMLDocument::~nsHTMLDocument() { - if (mAttrStyleSheet) { - mAttrStyleSheet->SetOwningDocument(nsnull); - } - - if (mStyleAttrStyleSheet) { - mStyleAttrStyleSheet->SetOwningDocument(nsnull); - } - if (--gRefCntRDFService == 0) { NS_IF_RELEASE(gRDF); } @@ -335,7 +327,6 @@ NS_INTERFACE_MAP_BEGIN(nsHTMLDocument) NS_INTERFACE_MAP_ENTRY(nsIHTMLDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLDocument) - NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDocument) NS_INTERFACE_MAP_END_INHERITING(nsDocument) @@ -1170,38 +1161,6 @@ nsHTMLDocument::GetImageMap(const nsAString& aMapName, return NS_OK; } -NS_IMETHODIMP -nsHTMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mAttrStyleSheet; - - if (!*aResult) { - return NS_ERROR_NOT_AVAILABLE; // probably not the right error... - } - - NS_ADDREF(*aResult); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mStyleAttrStyleSheet; - - if (!*aResult) { - return NS_ERROR_NOT_AVAILABLE; // probably not the right error... - } - - NS_ADDREF(*aResult); - - return NS_OK; -} - // subclass hooks for sheet ordering void nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) @@ -1294,21 +1253,18 @@ nsHTMLDocument::SetReferrer(const nsAString& aReferrer) return NS_OK; } -NS_IMETHODIMP -nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader) +nsICSSLoader* +nsHTMLDocument::GetCSSLoader() { if (!mCSSLoader) { - nsresult rv = NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader)); - NS_ENSURE_SUCCESS(rv, rv); + NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader)); + if (mCSSLoader) { + mCSSLoader->SetCaseSensitive(IsXHTML()); + mCSSLoader->SetCompatibilityMode(mCompatMode); + } } - - mCSSLoader->SetCaseSensitive(IsXHTML()); - mCSSLoader->SetCompatibilityMode(mCompatMode); - - aLoader = mCSSLoader; - NS_ADDREF(aLoader); - - return NS_OK; + + return mCSSLoader; } diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 206b5152a7b..a2c720b1db8 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -45,7 +45,6 @@ #include "nsIDOMHTMLBodyElement.h" #include "nsIDOMHTMLMapElement.h" #include "nsIDOMHTMLCollection.h" -#include "nsIHTMLContentContainer.h" #include "nsIParser.h" #include "jsapi.h" #include "rdf.h" @@ -73,8 +72,7 @@ class nsICacheEntryDescriptor; class nsHTMLDocument : public nsDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument, - public nsIDOMNSHTMLDocument, - public nsIHTMLContentContainer + public nsIDOMNSHTMLDocument { public: nsHTMLDocument(); @@ -113,9 +111,7 @@ public: NS_IMETHOD GetImageMap(const nsAString& aMapName, nsIDOMHTMLMapElement** aResult); - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet); - NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aStyleSheet); - NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader); + virtual nsICSSLoader* GetCSSLoader(); virtual void GetBaseTarget(nsAString& aTarget) const; virtual void SetBaseTarget(const nsAString& aTarget); @@ -267,9 +263,6 @@ protected: virtual void RetrieveRelevantHeaders(nsIChannel *aChannel); - nsCOMPtr mAttrStyleSheet; - nsCOMPtr mStyleAttrStyleSheet; - nsString mBaseTarget; nsString mReferrer; diff --git a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp index df780bc102e..225586a99b2 100644 --- a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -41,7 +41,6 @@ #include "nsIParser.h" #include "nsIParserService.h" #include "nsIHTMLContent.h" -#include "nsIHTMLContentContainer.h" #include "nsHTMLAtoms.h" #include "nsHTMLTokens.h" #include "nsGenericHTMLElement.h" diff --git a/mozilla/content/html/document/src/nsIHTMLContentContainer.h b/mozilla/content/html/document/src/nsIHTMLContentContainer.h deleted file mode 100644 index 9dbdd9e6591..00000000000 --- a/mozilla/content/html/document/src/nsIHTMLContentContainer.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsIHTMLContentContainer_h___ -#define nsIHTMLContentContainer_h___ - -#include "nsISupports.h" - -class nsIHTMLStyleSheet; -class nsIHTMLCSSStyleSheet; -class nsICSSLoader; - -/* a6cf90cc-15b3-11d2-932e-00805f8add32 */ -#define NS_IHTMLCONTENTCONTAINER_IID \ - {0xa6cf90cc, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -/** - * Interface implemented by any document class that can container - * HTML content. - * XXX Could do with a better name for this interface. - */ -class nsIHTMLContentContainer : public nsISupports { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLCONTENTCONTAINER_IID) - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet) = 0; - NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aStyleSheet) = 0; - NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader) = 0; -}; - -#endif // nsIHTMLContentContainer_h___ diff --git a/mozilla/content/html/style/src/nsCSSStyleRule.cpp b/mozilla/content/html/style/src/nsCSSStyleRule.cpp index 50edbcbecfd..87da00fadc9 100644 --- a/mozilla/content/html/style/src/nsCSSStyleRule.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleRule.cpp @@ -45,7 +45,6 @@ #include "nsICSSStyleSheet.h" #include "nsICSSParser.h" #include "nsICSSLoader.h" -#include "nsIHTMLContentContainer.h" #include "nsIURL.h" #include "nsIPresContext.h" #include "nsIDocument.h" @@ -986,10 +985,8 @@ DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aURI, sheet->GetURL(*aURI); nsCOMPtr document; sheet->GetOwningDocument(*getter_AddRefs(document)); - nsCOMPtr htmlContainer = - do_QueryInterface(document); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*aCSSLoader); + if (document) { + NS_IF_ADDREF(*aCSSLoader = document->GetCSSLoader()); NS_ASSERTION(*aCSSLoader, "Document with no CSS loader!"); } } diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index c482bb0877d..db4cb31d405 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -59,9 +59,8 @@ #include "nsICSSNameSpaceRule.h" #include "nsICSSMediaRule.h" #include "nsIMediaList.h" -#include "nsIHTMLContent.h" +#include "nsIStyledContent.h" #include "nsIDocument.h" -#include "nsIHTMLContentContainer.h" #include "nsIPresContext.h" #include "nsIEventStateManager.h" #include "nsHTMLAtoms.h" @@ -2617,13 +2616,15 @@ CSSStyleSheetImpl::InsertRule(const nsAString& aRule, if (aIndex > count) return NS_ERROR_DOM_INDEX_SIZE_ERR; + // Hold strong ref to the CSSLoader in case the document update + // kills the document nsCOMPtr loader; - nsCOMPtr css; - nsCOMPtr htmlContainer(do_QueryInterface(mDocument)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(loader)); + if (mDocument) { + loader = mDocument->GetCSSLoader(); + NS_ASSERTION(loader, "Document with no CSS loader!"); } - NS_ASSERTION(loader || !mDocument, "Document with no CSS loader!"); + + nsCOMPtr css; if (loader) { result = loader->GetParserFor(this, getter_AddRefs(css)); } @@ -2856,15 +2857,15 @@ CSSStyleSheetImpl::InsertRuleIntoGroup(const nsAString & aRule, nsICSSGroupRule* return NS_ERROR_INVALID_ARG; } - // get the css parser + // Hold strong ref to the CSSLoader in case the document update + // kills the document nsCOMPtr loader; - nsCOMPtr css; - nsCOMPtr htmlContainer(do_QueryInterface(mDocument)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(loader)); + if (mDocument) { + loader = mDocument->GetCSSLoader(); + NS_ASSERTION(loader, "Document with no CSS loader!"); } - NS_ASSERTION(loader || !mDocument, "Document with no CSS loader!"); + nsCOMPtr css; if (loader) { result = loader->GetParserFor(this, getter_AddRefs(css)); } diff --git a/mozilla/content/html/style/src/nsDOMCSSAttrDeclaration.cpp b/mozilla/content/html/style/src/nsDOMCSSAttrDeclaration.cpp index 8a9a53b1973..9f3a74e84dd 100644 --- a/mozilla/content/html/style/src/nsDOMCSSAttrDeclaration.cpp +++ b/mozilla/content/html/style/src/nsDOMCSSAttrDeclaration.cpp @@ -49,7 +49,6 @@ #include "nsICSSParser.h" #include "nsIURI.h" #include "nsINameSpaceManager.h" -#include "nsIHTMLContentContainer.h" #include "nsStyleConsts.h" MOZ_DECL_CTOR_COUNTER(nsDOMCSSAttributeDeclaration) @@ -155,11 +154,10 @@ nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aBaseURI, nsCOMPtr base = mContent->GetBaseURI(); - nsCOMPtr htmlContainer(do_QueryInterface(doc)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*aCSSLoader); + if (doc) { + NS_IF_ADDREF(*aCSSLoader = doc->GetCSSLoader()); + NS_ASSERTION(*aCSSLoader, "Document with no CSS loader!"); } - NS_ASSERTION(!doc || *aCSSLoader, "Document with no CSS loader!"); nsresult rv = NS_OK; diff --git a/mozilla/content/xbl/src/nsBindingManager.cpp b/mozilla/content/xbl/src/nsBindingManager.cpp index d4e70ec865b..7eab4fcc550 100644 --- a/mozilla/content/xbl/src/nsBindingManager.cpp +++ b/mozilla/content/xbl/src/nsBindingManager.cpp @@ -73,7 +73,6 @@ #include "nsIStyleSheet.h" #include "nsIHTMLStyleSheet.h" #include "nsIHTMLCSSStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsIStyleRuleProcessor.h" #include "nsIWeakReference.h" @@ -1267,12 +1266,10 @@ nsBindingManager::WalkRules(nsStyleSet* aStyleSet, if (parent) { // We cut ourselves off, but we still need to walk the document's attribute sheet // so that inline style continues to work on anonymous content. - nsCOMPtr container( - do_QueryInterface(content->GetDocument())); - if (container) { - nsCOMPtr inlineSheet; - container->GetInlineStyleSheet(getter_AddRefs(inlineSheet)); - nsCOMPtr inlineCSS(do_QueryInterface(inlineSheet)); + nsIDocument* doc = content->GetDocument(); + if (doc) { + nsCOMPtr inlineCSS( + do_QueryInterface(doc->GetInlineStyleSheet())); if (inlineCSS) (*aFunc)(inlineCSS, aData); } diff --git a/mozilla/content/xbl/src/nsXBLResourceLoader.cpp b/mozilla/content/xbl/src/nsXBLResourceLoader.cpp index e5a91ef3d92..dea0346f8f3 100644 --- a/mozilla/content/xbl/src/nsXBLResourceLoader.cpp +++ b/mozilla/content/xbl/src/nsXBLResourceLoader.cpp @@ -52,7 +52,6 @@ #include "nsICSSLoader.h" #include "nsIXBLDocumentInfo.h" #include "nsIURI.h" -#include "nsIHTMLContentContainer.h" #include "nsNetUtil.h" #include "nsXBLAtoms.h" #include "nsIFrameManager.h" @@ -133,8 +132,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult) } else if (curr->mType == nsXBLAtoms::stylesheet) { if (!cssLoader) { - nsCOMPtr htmlContent(do_QueryInterface(doc)); - htmlContent->GetCSSLoader(*getter_AddRefs(cssLoader)); + cssLoader = doc->GetCSSLoader(); } if (!cssLoader) diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index 4168d410285..cdbf82fc6c3 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -70,7 +70,6 @@ #include "nsCRT.h" #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsHTMLAtoms.h" #include "nsContentUtils.h" #include "nsLayoutAtoms.h" @@ -1052,45 +1051,41 @@ MathMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo* aNodeInfo, // this bit of code is to load mathml.css on demand nsIDocument* doc = aNodeInfo->GetDocument(); if (doc) { - nsCOMPtr htmlContainer(do_QueryInterface(doc)); - if (htmlContainer) { - PRBool enabled; - nsCOMPtr cssLoader; - htmlContainer->GetCSSLoader(*getter_AddRefs(cssLoader)); - if (cssLoader && NS_SUCCEEDED(cssLoader->GetEnabled(&enabled)) && enabled) { - PRBool alreadyLoaded = PR_FALSE; - PRInt32 sheetCount = doc->GetNumberOfStyleSheets(PR_TRUE); - for (PRInt32 i = 0; i < sheetCount; i++) { - nsIStyleSheet* sheet = doc->GetStyleSheetAt(i, PR_TRUE); - NS_ASSERTION(sheet, "unexpected null stylesheet in the document"); - if (sheet) { - nsCOMPtr uri; - sheet->GetURL(*getter_AddRefs(uri)); - nsCAutoString uriStr; - uri->GetSpec(uriStr); - if (uriStr.Equals(kMathMLStyleSheetURI)) { - alreadyLoaded = PR_TRUE; - break; - } + nsICSSLoader* cssLoader = doc->GetCSSLoader(); + PRBool enabled; + if (cssLoader && NS_SUCCEEDED(cssLoader->GetEnabled(&enabled)) && enabled) { + PRBool alreadyLoaded = PR_FALSE; + PRInt32 sheetCount = doc->GetNumberOfStyleSheets(PR_TRUE); + for (PRInt32 i = 0; i < sheetCount; i++) { + nsIStyleSheet* sheet = doc->GetStyleSheetAt(i, PR_TRUE); + NS_ASSERTION(sheet, "unexpected null stylesheet in the document"); + if (sheet) { + nsCOMPtr uri; + sheet->GetURL(*getter_AddRefs(uri)); + nsCAutoString uriStr; + uri->GetSpec(uriStr); + if (uriStr.Equals(kMathMLStyleSheetURI)) { + alreadyLoaded = PR_TRUE; + break; } } - if (!alreadyLoaded) { - nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), kMathMLStyleSheetURI); - if (uri) { - nsCOMPtr sheet; - cssLoader->LoadAgentSheet(uri, getter_AddRefs(sheet)); + } + if (!alreadyLoaded) { + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), kMathMLStyleSheetURI); + if (uri) { + nsCOMPtr sheet; + cssLoader->LoadAgentSheet(uri, getter_AddRefs(sheet)); #ifdef NS_DEBUG - nsCAutoString uriStr; - uri->GetSpec(uriStr); - printf("MathML Factory: loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed"); - NS_ASSERTION(uriStr.Equals(kMathMLStyleSheetURI), "resolved URI unexpected"); + nsCAutoString uriStr; + uri->GetSpec(uriStr); + printf("MathML Factory: loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed"); + NS_ASSERTION(uriStr.Equals(kMathMLStyleSheetURI), "resolved URI unexpected"); #endif - if (sheet) { - doc->BeginUpdate(UPDATE_STYLE); - doc->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG); - doc->EndUpdate(UPDATE_STYLE); - } + if (sheet) { + doc->BeginUpdate(UPDATE_STYLE); + doc->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG); + doc->EndUpdate(UPDATE_STYLE); } } } diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index 0ddf38cea62..e847ee23e9d 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -194,16 +194,6 @@ nsXMLDocument::nsXMLDocument() nsXMLDocument::~nsXMLDocument() { - if (mAttrStyleSheet) { - mAttrStyleSheet->SetOwningDocument(nsnull); - } - if (mInlineStyleSheet) { - mInlineStyleSheet->SetOwningDocument(nsnull); - } - if (mCSSLoader) { - mCSSLoader->DropDocumentReference(); - } - // XXX We rather crash than hang mLoopingForSyncLoad = PR_FALSE; } @@ -211,7 +201,6 @@ nsXMLDocument::~nsXMLDocument() // QueryInterface implementation for nsXMLDocument NS_INTERFACE_MAP_BEGIN(nsXMLDocument) - NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIHttpEventSink) NS_INTERFACE_MAP_ENTRY(nsIDOMXMLDocument) @@ -245,13 +234,6 @@ nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) return; } - if (mAttrStyleSheet) { - mAttrStyleSheet->SetOwningDocument(nsnull); - } - if (mInlineStyleSheet) { - mInlineStyleSheet->SetOwningDocument(nsnull); - } - SetDefaultStylesheets(url); mBaseTarget.Truncate(); @@ -596,10 +578,9 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, } // styles - nsCOMPtr cssLoader; - nsresult rv = GetCSSLoader(*getter_AddRefs(cssLoader)); - if (NS_FAILED(rv)) - return rv; + nsICSSLoader* cssLoader = GetCSSLoader(); + if (!cssLoader) + return NS_ERROR_OUT_OF_MEMORY; if (cssLoader) { cssLoader->SetEnabled(PR_FALSE); // Do not load/process styles when loading as data } @@ -699,32 +680,6 @@ nsXMLDocument::EndLoad() nsDocument::EndLoad(); } -NS_IMETHODIMP -nsXMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mAttrStyleSheet; - NS_ENSURE_TRUE(mAttrStyleSheet, NS_ERROR_NOT_AVAILABLE); // probably not the right error... - - NS_ADDREF(*aResult); - - return NS_OK; -} - -NS_IMETHODIMP -nsXMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mInlineStyleSheet; - NS_ENSURE_TRUE(mInlineStyleSheet, NS_ERROR_NOT_AVAILABLE); // probably not the right error... - - NS_ADDREF(*aResult); - - return NS_OK; -} - // subclass hook for sheet ordering void nsXMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) @@ -741,15 +696,15 @@ nsXMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) "Adding attr sheet twice!"); mStyleSheets.InsertObjectAt(aSheet, mCatalogSheetCount); } - else if (aSheet == mInlineStyleSheet) { // always last + else if (aSheet == mStyleAttrStyleSheet) { // always last NS_ASSERTION(mStyleSheets.Count() == 0 || - mStyleSheets[mStyleSheets.Count() - 1] != mInlineStyleSheet, + mStyleSheets[mStyleSheets.Count() - 1] != mStyleAttrStyleSheet, "Adding style attr sheet twice!"); mStyleSheets.AppendObject(aSheet); } else { PRInt32 count = mStyleSheets.Count(); - if (count != 0 && mInlineStyleSheet == mStyleSheets[count - 1]) { + if (count != 0 && mStyleAttrStyleSheet == mStyleSheets[count - 1]) { // keep attr sheet last mStyleSheets.InsertObjectAt(aSheet, count - 1); } @@ -770,7 +725,7 @@ nsXMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) /* Don't count catalog sheets */ - mCatalogSheetCount /* No insertion allowed after StyleAttr stylesheet */ - - (mInlineStyleSheet ? 1: 0) + - (mStyleAttrStyleSheet ? 1: 0) ), "index out of bounds"); // offset w.r.t. catalog style sheets and the attr style sheet @@ -795,7 +750,7 @@ nsXMLDocument::InternalGetNumberOfStyleSheets() const { PRInt32 count = mStyleSheets.Count(); - if (count != 0 && mInlineStyleSheet == mStyleSheets[count - 1]) { + if (count != 0 && mStyleAttrStyleSheet == mStyleSheets[count - 1]) { // subtract the inline style sheet --count; } @@ -1080,17 +1035,25 @@ nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl) return NS_OK; } + // XXXbz this code is very similar to the HTMLDocument code; should merge! + if (mAttrStyleSheet) { + mAttrStyleSheet->SetOwningDocument(nsnull); + } + if (mStyleAttrStyleSheet) { + mStyleAttrStyleSheet->SetOwningDocument(nsnull); + } + nsresult rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aUrl, this); NS_ENSURE_SUCCESS(rv, rv); - rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mInlineStyleSheet), aUrl, + rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), aUrl, this); NS_ENSURE_SUCCESS(rv, rv); // tell the world about our new style sheets AddStyleSheet(mAttrStyleSheet, 0); - AddStyleSheet(mInlineStyleSheet, 0); + AddStyleSheet(mStyleAttrStyleSheet, 0); return rv; } @@ -1107,22 +1070,19 @@ nsXMLDocument::GetBaseTarget(nsAString &aBaseTarget) const aBaseTarget.Assign(mBaseTarget); } -NS_IMETHODIMP -nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader) +nsICSSLoader* +nsXMLDocument::GetCSSLoader() { if (!mCSSLoader) { - nsresult rv = NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader)); - NS_ENSURE_SUCCESS(rv, rv); - - mCSSLoader->SetCaseSensitive(PR_TRUE); - // no quirks in XML - mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards); + NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader)); + if (mCSSLoader) { + mCSSLoader->SetCaseSensitive(PR_TRUE); + // no quirks in XML + mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards); + } } - aLoader = mCSSLoader; - NS_IF_ADDREF(aLoader); - - return NS_OK; + return mCSSLoader; } nsresult diff --git a/mozilla/content/xml/document/src/nsXMLDocument.h b/mozilla/content/xml/document/src/nsXMLDocument.h index 2400cb597d5..8dc777a8902 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.h +++ b/mozilla/content/xml/document/src/nsXMLDocument.h @@ -40,7 +40,6 @@ #define nsXMLDocument_h___ #include "nsDocument.h" -#include "nsIHTMLContentContainer.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIHttpEventSink.h" @@ -56,7 +55,6 @@ class nsICSSLoader; class nsIURI; class nsXMLDocument : public nsDocument, - public nsIHTMLContentContainer, public nsIInterfaceRequestor, public nsIHttpEventSink { @@ -107,10 +105,7 @@ public: NS_IMETHOD GetElementById(const nsAString& aElementId, nsIDOMElement** aReturn); - // nsIHTMLContentContainer - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult); - NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult); - NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader); + virtual nsICSSLoader* GetCSSLoader(); // nsIInterfaceRequestor NS_DECL_NSIINTERFACEREQUESTOR @@ -136,10 +131,6 @@ protected: nsresult SetDefaultStylesheets(nsIURI* aUrl); - // For HTML elements in our content model - // XXX This is not clean, but is there a better way? - nsCOMPtr mAttrStyleSheet; - nsCOMPtr mInlineStyleSheet; // For additional catalog sheets (if any) needed to layout the XML vocabulary // of the document. Catalog sheets are kept at the beginning of our array of // style sheets and this counter is used as an offset to distinguish them diff --git a/mozilla/content/xul/content/src/nsXULAttributes.cpp b/mozilla/content/xul/content/src/nsXULAttributes.cpp index fe939a5acb1..bdbe2720c70 100644 --- a/mozilla/content/xul/content/src/nsXULAttributes.cpp +++ b/mozilla/content/xul/content/src/nsXULAttributes.cpp @@ -59,6 +59,8 @@ #include "nsFixedSizeAllocator.h" #include "nsIContent.h" #include "nsINodeInfo.h" +#include "nsIDocument.h" +#include "nsICSSLoader.h" #include "nsICSSParser.h" #include "nsICSSStyleRule.h" #include "nsIDOMElement.h" @@ -720,18 +722,28 @@ nsresult nsXULAttributes::UpdateStyleRule(nsIURI* aDocURL, const nsAString& aVal { if (aValue.IsEmpty()) { - // XXX: Removing the rule. Is this sufficient? - mStyleRule = nsnull; - return NS_OK; + // Just remove the rule; we'll be getting our style reresolved + mStyleRule = nsnull; + return NS_OK; } + nsIDocument* doc = mContent->GetNodeInfo()->GetDocument(); + + nsICSSLoader* cssLoader = nsnull; + if (doc) { + cssLoader = doc->GetCSSLoader(); + } + + nsCOMPtr css; nsresult result = NS_OK; - nsCOMPtr css(do_CreateInstance(kCSSParserCID, &result)); - if (NS_OK != result) { - return result; + if (cssLoader) { + result = cssLoader->GetParserFor(nsnull, getter_AddRefs(css)); + } else { + css = do_CreateInstance(kCSSParserCID, &result); } - + NS_ENSURE_SUCCESS(result, result); + nsCOMPtr rule; result = css->ParseStyleAttribute(aValue, aDocURL, getter_AddRefs(rule)); @@ -739,6 +751,10 @@ nsresult nsXULAttributes::UpdateStyleRule(nsIURI* aDocURL, const nsAString& aVal mStyleRule = rule; } + if (cssLoader) { + cssLoader->RecycleParser(css); + } + return NS_OK; } diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index 913015d9d60..a860d2e70f7 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -83,7 +83,6 @@ #include "nsIEventListenerManager.h" #include "nsIEventStateManager.h" #include "nsIFastLoadService.h" -#include "nsIHTMLContentContainer.h" #include "nsIHTMLStyleSheet.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" diff --git a/mozilla/content/xul/content/src/nsXULElement.h b/mozilla/content/xul/content/src/nsXULElement.h index fd493ec6007..eb9db8551f0 100644 --- a/mozilla/content/xul/content/src/nsXULElement.h +++ b/mozilla/content/xul/content/src/nsXULElement.h @@ -302,8 +302,13 @@ public: protected: static nsICSSParser* GetCSSParser() { - if (!sCSSParser) + if (!sCSSParser) { CallCreateInstance(kCSSParserCID, &sCSSParser); + if (sCSSParser) { + sCSSParser->SetCaseSensitive(PR_TRUE); + sCSSParser->SetQuirkMode(PR_FALSE); + } + } return sCSSParser; } static nsICSSParser* sCSSParser; diff --git a/mozilla/content/xul/document/src/nsXULContentSink.cpp b/mozilla/content/xul/document/src/nsXULContentSink.cpp index 19f8b3237c0..88158a18936 100644 --- a/mozilla/content/xul/document/src/nsXULContentSink.cpp +++ b/mozilla/content/xul/document/src/nsXULContentSink.cpp @@ -65,7 +65,6 @@ #include "nsIDocumentLoader.h" #include "nsIFormControl.h" #include "nsIHTMLContent.h" -#include "nsIHTMLContentContainer.h" #include "nsIHTMLStyleSheet.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" @@ -597,14 +596,9 @@ XULContentSinkImpl::Init(nsIDocument* aDocument, nsIXULPrototypeDocument* aProto if (NS_FAILED(rv)) return rv; // Get the CSS loader from the document so we can load - // stylesheets. - nsCOMPtr htmlContainer = do_QueryInterface(aDocument); - NS_ASSERTION(htmlContainer != nsnull, "not an HTML container"); - if (! htmlContainer) - return NS_ERROR_UNEXPECTED; - - rv = htmlContainer->GetCSSLoader(*getter_AddRefs(mCSSLoader)); - if (NS_FAILED(rv)) return rv; + // stylesheets + mCSSLoader = aDocument->GetCSSLoader(); + NS_ENSURE_TRUE(mCSSLoader, NS_ERROR_OUT_OF_MEMORY); rv = aPrototype->GetNodeInfoManager(getter_AddRefs(mNodeInfoManager)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 3857f920bf9..e6342064b6f 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -483,7 +483,6 @@ NS_IMPL_RELEASE_INHERITED(nsXULDocument, nsXMLDocument) NS_INTERFACE_MAP_BEGIN(nsXULDocument) NS_INTERFACE_MAP_ENTRY(nsIXULDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMXULDocument) - NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer) NS_INTERFACE_MAP_ENTRY(nsIStreamLoaderObserver) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULDocument) NS_INTERFACE_MAP_END_INHERITING(nsXMLDocument) @@ -530,6 +529,8 @@ nsXULDocument::PrepareStyleSheets(nsIURI* anURL) { nsresult rv; + // XXXbz this is similar to code in nsHTMLDocument and + // nsXMLDocument; move up to nsDocument? // Delete references to style sheets - this should be done in superclass... PRInt32 i = mStyleSheets.Count(); while (--i >= 0) { @@ -548,14 +549,13 @@ nsXULDocument::PrepareStyleSheets(nsIURI* anURL) // Create an inline style sheet for inline content that contains a style // attribute. - rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mInlineStyleSheet), anURL, - this); + rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), anURL, this); if (NS_FAILED(rv)) { NS_ERROR("unable to add inline style sheet"); return rv; } - AddStyleSheet(mInlineStyleSheet, 0); + AddStyleSheet(mStyleAttrStyleSheet, 0); return NS_OK; } @@ -3699,9 +3699,8 @@ nsXULDocument::AddPrototypeSheets() // only system that partially invalidates the XUL cache). // - dwh //XXXbz we hit this code from fastload all the time. Bug 183505. - nsCOMPtr loader; - rv = GetCSSLoader(*getter_AddRefs(loader)); - NS_ENSURE_SUCCESS(rv, rv); + nsICSSLoader* loader = GetCSSLoader(); + NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY); rv = loader->LoadAgentSheet(uri, getter_AddRefs(sheet)); // XXXldb We need to prevent bogus sheets from being held in the // prototype's list, but until then, don't propagate the failure diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp index 80eb60f643a..f9f7ac6ebf6 100644 --- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -67,7 +67,6 @@ #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsIDocumentObserver.h" #include "nsIDocumentStateListener.h" diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index d7005ee5108..694bfa5010d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -78,7 +78,6 @@ #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsIDocumentObserver.h" #include "nsIDocumentStateListener.h" @@ -3862,17 +3861,11 @@ nsHTMLEditor::GetCSSLoader(const nsAString& aURL, nsICSSLoader** aCSSLoader) NS_ENSURE_SUCCESS(rv, rv);; if (!document) return NS_ERROR_NULL_POINTER; - nsCOMPtr container = do_QueryInterface(document); - if (!container) return NS_ERROR_NULL_POINTER; - - nsCOMPtr cssLoader; - nsCOMPtr cssStyleSheet; + NS_IF_ADDREF(*aCSSLoader = document->GetCSSLoader()); + if (!*aCSSLoader) { + return NS_ERROR_NULL_POINTER; + } - rv = container->GetCSSLoader(*getter_AddRefs(cssLoader)); - NS_ENSURE_SUCCESS(rv, rv);; - if (!cssLoader) return NS_ERROR_NULL_POINTER; - *aCSSLoader = cssLoader; - NS_ADDREF(*aCSSLoader); return NS_OK; } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp b/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp index a38293887e5..4cd7591156a 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -53,7 +53,6 @@ #include "nsISelectionController.h" #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsIDocumentObserver.h" #include "TypeInState.h" diff --git a/mozilla/layout/style/nsCSSStyleRule.cpp b/mozilla/layout/style/nsCSSStyleRule.cpp index 50edbcbecfd..87da00fadc9 100644 --- a/mozilla/layout/style/nsCSSStyleRule.cpp +++ b/mozilla/layout/style/nsCSSStyleRule.cpp @@ -45,7 +45,6 @@ #include "nsICSSStyleSheet.h" #include "nsICSSParser.h" #include "nsICSSLoader.h" -#include "nsIHTMLContentContainer.h" #include "nsIURL.h" #include "nsIPresContext.h" #include "nsIDocument.h" @@ -986,10 +985,8 @@ DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aURI, sheet->GetURL(*aURI); nsCOMPtr document; sheet->GetOwningDocument(*getter_AddRefs(document)); - nsCOMPtr htmlContainer = - do_QueryInterface(document); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*aCSSLoader); + if (document) { + NS_IF_ADDREF(*aCSSLoader = document->GetCSSLoader()); NS_ASSERTION(*aCSSLoader, "Document with no CSS loader!"); } } diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index c482bb0877d..db4cb31d405 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -59,9 +59,8 @@ #include "nsICSSNameSpaceRule.h" #include "nsICSSMediaRule.h" #include "nsIMediaList.h" -#include "nsIHTMLContent.h" +#include "nsIStyledContent.h" #include "nsIDocument.h" -#include "nsIHTMLContentContainer.h" #include "nsIPresContext.h" #include "nsIEventStateManager.h" #include "nsHTMLAtoms.h" @@ -2617,13 +2616,15 @@ CSSStyleSheetImpl::InsertRule(const nsAString& aRule, if (aIndex > count) return NS_ERROR_DOM_INDEX_SIZE_ERR; + // Hold strong ref to the CSSLoader in case the document update + // kills the document nsCOMPtr loader; - nsCOMPtr css; - nsCOMPtr htmlContainer(do_QueryInterface(mDocument)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(loader)); + if (mDocument) { + loader = mDocument->GetCSSLoader(); + NS_ASSERTION(loader, "Document with no CSS loader!"); } - NS_ASSERTION(loader || !mDocument, "Document with no CSS loader!"); + + nsCOMPtr css; if (loader) { result = loader->GetParserFor(this, getter_AddRefs(css)); } @@ -2856,15 +2857,15 @@ CSSStyleSheetImpl::InsertRuleIntoGroup(const nsAString & aRule, nsICSSGroupRule* return NS_ERROR_INVALID_ARG; } - // get the css parser + // Hold strong ref to the CSSLoader in case the document update + // kills the document nsCOMPtr loader; - nsCOMPtr css; - nsCOMPtr htmlContainer(do_QueryInterface(mDocument)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*getter_AddRefs(loader)); + if (mDocument) { + loader = mDocument->GetCSSLoader(); + NS_ASSERTION(loader, "Document with no CSS loader!"); } - NS_ASSERTION(loader || !mDocument, "Document with no CSS loader!"); + nsCOMPtr css; if (loader) { result = loader->GetParserFor(this, getter_AddRefs(css)); } diff --git a/mozilla/layout/style/nsDOMCSSAttrDeclaration.cpp b/mozilla/layout/style/nsDOMCSSAttrDeclaration.cpp index 8a9a53b1973..9f3a74e84dd 100644 --- a/mozilla/layout/style/nsDOMCSSAttrDeclaration.cpp +++ b/mozilla/layout/style/nsDOMCSSAttrDeclaration.cpp @@ -49,7 +49,6 @@ #include "nsICSSParser.h" #include "nsIURI.h" #include "nsINameSpaceManager.h" -#include "nsIHTMLContentContainer.h" #include "nsStyleConsts.h" MOZ_DECL_CTOR_COUNTER(nsDOMCSSAttributeDeclaration) @@ -155,11 +154,10 @@ nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aBaseURI, nsCOMPtr base = mContent->GetBaseURI(); - nsCOMPtr htmlContainer(do_QueryInterface(doc)); - if (htmlContainer) { - htmlContainer->GetCSSLoader(*aCSSLoader); + if (doc) { + NS_IF_ADDREF(*aCSSLoader = doc->GetCSSLoader()); + NS_ASSERTION(*aCSSLoader, "Document with no CSS loader!"); } - NS_ASSERTION(!doc || *aCSSLoader, "Document with no CSS loader!"); nsresult rv = NS_OK; diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index 29510320472..be23ef99656 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -79,7 +79,6 @@ #include "nsIStyleSheet.h" #include "nsIHTMLCSSStyleSheet.h" #include "nsIHTMLStyleSheet.h" -#include "nsIHTMLContentContainer.h" #include "nsIPresShell.h" #include "nsIDocShell.h" #include "nsISupportsArray.h" @@ -1566,13 +1565,6 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) NS_ENSURE_SUCCESS(rv, rv); } - // The document sheets just need to be done once; the document will notify - // the presshells and style sets - nsCOMPtr container = do_QueryInterface(document); - nsCOMPtr cssLoader; - rv = container->GetCSSLoader(*getter_AddRefs(cssLoader)); - NS_ENSURE_SUCCESS(rv, rv); - // Build an array of nsIURIs of style sheets we need to load. nsCOMArray oldSheets; nsCOMArray newSheets; @@ -1607,6 +1599,7 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) nsCOMPtr newSheet; // XXX what about chrome sheets that have a title or are disabled? This // only works by sheer dumb luck. + // XXXbz this should really use the document's CSSLoader! LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); // Even if it's null, we put in in there. newSheets.AppendObject(newSheet); diff --git a/mozilla/xpcom/base/IIDS.h b/mozilla/xpcom/base/IIDS.h index e53a4ae9b3d..a90beaea3d6 100644 --- a/mozilla/xpcom/base/IIDS.h +++ b/mozilla/xpcom/base/IIDS.h @@ -761,12 +761,6 @@ nsIXMLContent = { /* a6cf90cb-15b3-11d2-932e-00805f8add32 */ 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }; -nsIHTMLContentContainer = { /* a6cf90cc-15b3-11d2-932e-00805f8add32 */ - 0xa6cf90cc, - 0x15b3, - 0x11d2, - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} - }; nsIDOMNSDocument = { /* a6cf90cd-15b3-11d2-932e-00805f8add32 */ 0xa6cf90cd, 0x15b3,