From fe53f95e60eced8e22894e1a1090648d1723a368 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 3 Dec 2002 05:48:14 +0000 Subject: [PATCH] Make the CSSLoader correctly order stylesheets as they are dynamically added and removed via the DOM. Clean up the nsIDocument stylesheet accessors. Clean up nsIDocumentObserver stylesheet stuff a bit. Make style sheets visible in the CSSOM (though not completely accessible) from the moment the load is kicked off. Make us have sheet objects that can be manipulated via CSSOM even for failed loads. Bug 107567, bug 47734, bug 57225, bug 178407. r=sicking, sr=peterv. --- chrome/src/nsChromeRegistry.cpp | 129 +- content/base/public/nsIDocument.h | 81 +- content/base/public/nsIDocumentObserver.h | 152 +- content/base/public/nsIStyleSheet.h | 20 +- .../base/public/nsIStyleSheetLinkingElement.h | 6 +- content/base/src/nsDocument.cpp | 328 ++- content/base/src/nsDocument.h | 26 +- content/base/src/nsDocumentViewer.cpp | 10 +- content/base/src/nsStyleLinkElement.cpp | 89 +- content/base/src/nsStyleLinkElement.h | 2 +- content/base/src/nsStyleSet.cpp | 84 +- content/build/nsContentDLF.cpp | 3 +- .../html/document/src/nsHTMLContentSink.cpp | 52 +- content/html/document/src/nsHTMLDocument.cpp | 50 +- content/html/document/src/nsHTMLDocument.h | 3 + content/html/style/public/nsICSSLoader.h | 27 +- content/html/style/public/nsICSSStyleSheet.h | 2 +- content/html/style/src/nsCSSLoader.cpp | 2267 +++++++++-------- content/html/style/src/nsCSSParser.cpp | 17 +- content/html/style/src/nsCSSStyleSheet.cpp | 133 +- .../html/style/src/nsHTMLCSSStyleSheet.cpp | 23 +- content/html/style/src/nsHTMLStyleSheet.cpp | 23 +- content/xbl/src/nsXBLPrototypeResources.cpp | 3 +- content/xbl/src/nsXBLResourceLoader.cpp | 16 +- content/xml/document/src/nsXMLContentSink.cpp | 44 +- content/xml/document/src/nsXMLContentSink.h | 1 - content/xml/document/src/nsXMLDocument.cpp | 46 +- content/xml/document/src/nsXMLDocument.h | 2 + .../xml/document/src/nsXMLPrettyPrinter.cpp | 6 +- content/xml/document/src/nsXMLPrettyPrinter.h | 2 +- content/xul/document/src/nsXULContentSink.cpp | 3 - content/xul/document/src/nsXULDocument.cpp | 245 +- content/xul/document/src/nsXULDocument.h | 16 +- editor/libeditor/html/nsHTMLEditor.cpp | 25 +- .../inspector/base/src/inCSSValueSearch.cpp | 5 +- .../source/xslt/txMozillaXMLOutput.cpp | 15 +- .../source/xslt/txMozillaXMLOutput.h | 1 - layout/base/nsDocumentViewer.cpp | 10 +- layout/base/nsPresShell.cpp | 60 +- layout/base/public/nsIStyleSet.h | 2 +- layout/build/nsContentDLF.cpp | 3 +- layout/generic/nsGfxScrollFrame.cpp | 6 +- layout/html/base/src/nsGfxScrollFrame.cpp | 6 +- layout/html/base/src/nsPresShell.cpp | 60 +- layout/html/tests/ParseCSS.cpp | 7 +- layout/mathml/base/src/nsMathMLFrame.cpp | 2 + layout/style/nsCSSLoader.cpp | 2267 +++++++++-------- layout/style/nsCSSParser.cpp | 17 +- layout/style/nsCSSStyleSheet.cpp | 133 +- layout/style/nsHTMLCSSStyleSheet.cpp | 23 +- layout/style/nsHTMLStyleSheet.cpp | 23 +- layout/style/nsICSSLoader.h | 27 +- layout/style/nsICSSStyleSheet.h | 2 +- layout/style/nsIStyleSheet.h | 20 +- layout/style/nsStyleSet.cpp | 84 +- rdf/chrome/src/nsChromeRegistry.cpp | 129 +- 56 files changed, 3804 insertions(+), 3034 deletions(-) diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index 9be06450fa4b..339839bed523 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -1389,7 +1389,7 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) if (!document) return NS_OK; - // Deal with the agent sheets first. + // Deal with the agent sheets first. Have to do all the style sets by hand. PRInt32 shellCount = document->GetNumberOfShells(); for (PRInt32 k = 0; k < shellCount; k++) { nsCOMPtr shell; @@ -1434,76 +1434,63 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) styleSet->ReplaceAgentStyleSheets(newAgentSheets); } } - - nsCOMPtr container = do_QueryInterface(document); - nsCOMPtr cssLoader; - rv = container->GetCSSLoader(*getter_AddRefs(cssLoader)); - if (NS_FAILED(rv)) return rv; - - // Build an array of nsIURIs of style sheets we need to load. - nsCOMPtr oldSheets; - rv = NS_NewISupportsArray(getter_AddRefs(oldSheets)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr newSheets; - rv = NS_NewISupportsArray(getter_AddRefs(newSheets)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr attrSheet; - rv = container->GetAttributeStyleSheet(getter_AddRefs(attrSheet)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr inlineSheet; - rv = container->GetInlineStyleSheet(getter_AddRefs(inlineSheet)); - if (NS_FAILED(rv)) return rv; - - PRInt32 count = 0; - document->GetNumberOfStyleSheets(&count); - - // Iterate over the style sheets. - PRUint32 i; - for (i = 0; i < (PRUint32)count; i++) { - // Get the style sheet - nsCOMPtr styleSheet; - document->GetStyleSheetAt(i, getter_AddRefs(styleSheet)); - - // Make sure we aren't the special style sheets that never change. We - // want to skip those. - - nsCOMPtr attr = do_QueryInterface(attrSheet); - nsCOMPtr inl = do_QueryInterface(inlineSheet); - if ((attr.get() != styleSheet.get()) && - (inl.get() != styleSheet.get())) - // Add this sheet to the list of old style sheets. - oldSheets->AppendElement(styleSheet); - } - - // Iterate over our old sheets and kick off a sync load of the new - // sheet if and only if it's a chrome URL. - PRUint32 oldCount; - oldSheets->Count(&oldCount); - for (i = 0; i < oldCount; i++) { - nsCOMPtr supp = getter_AddRefs(oldSheets->ElementAt(i)); - nsCOMPtr sheet(do_QueryInterface(supp)); - nsCOMPtr uri; - rv = sheet->GetURL(*getter_AddRefs(uri)); - if (NS_FAILED(rv)) return rv; - - if (IsChromeURI(uri)) { - // Reload the sheet. - nsCOMPtr newSheet; - LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); - if (newSheet) - newSheets->AppendElement(newSheet); - } - else // Just use the same sheet. - newSheets->AppendElement(sheet); - } - - // Now notify the document that multiple sheets have been added and removed. - document->UpdateStyleSheets(oldSheets, newSheets); } + // 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; + + PRInt32 count = 0; + document->GetNumberOfStyleSheets(PR_FALSE, &count); + + // Iterate over the style sheets. + PRInt32 i; + for (i = 0; i < count; i++) { + // Get the style sheet + nsCOMPtr styleSheet; + document->GetStyleSheetAt(i, PR_FALSE, getter_AddRefs(styleSheet)); + + if (!oldSheets.AppendObject(styleSheet)) { + return NS_ERROR_OUT_OF_MEMORY; + } + } + + // Iterate over our old sheets and kick off a sync load of the new + // sheet if and only if it's a chrome URL. + for (i = 0; i < count; i++) { + nsCOMPtr sheet = oldSheets[i]; + nsCOMPtr uri; + rv = sheet->GetURL(*getter_AddRefs(uri)); + if (NS_FAILED(rv)) return rv; + + if (IsChromeURI(uri)) { + // Reload the sheet. +#ifdef DEBUG + nsCOMPtr oldCSSSheet = do_QueryInterface(sheet); + NS_ASSERTION(oldCSSSheet, "Don't know how to reload a non-CSS sheet"); +#endif + nsCOMPtr newSheet; + // XXX what about chrome sheets that have a title or are disabled? This + // only works by sheer dumb luck. + LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); + // Even if it's null, we put in in there. + newSheets.AppendObject(newSheet); + } + else { + // Just use the same sheet. + newSheets.AppendObject(sheet); + } + } + + // Now notify the document that multiple sheets have been added and removed. + document->UpdateStyleSheets(oldSheets, newSheets); return NS_OK; } @@ -3085,9 +3072,7 @@ nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet* getter_AddRefs(loader)); if (NS_FAILED(rv)) return rv; if (loader) { - PRBool complete; - rv = loader->LoadAgentSheet(aURL, *aSheet, complete, - nsnull); + rv = loader->LoadAgentSheet(aURL, aSheet); if (NS_FAILED(rv)) return rv; } return NS_OK; diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 6500de390285..4f2df3f96c9c 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -43,6 +43,7 @@ #include "nsAString.h" #include "nsString.h" #include "nsChangeHint.h" +#include "nsCOMArray.h" class nsIAtom; class nsIArena; @@ -269,19 +270,79 @@ public: NS_IMETHOD GetChildCount(PRInt32& aCount) = 0; /** - * Get the style sheets owned by this document. + * Accessors to the collection of stylesheets owned by this document. * Style sheets are ordered, most significant last. */ - NS_IMETHOD GetNumberOfStyleSheets(PRInt32* aCount) = 0; - NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsIStyleSheet** aSheet) = 0; - NS_IMETHOD GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex) = 0; - virtual void AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) = 0; - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0; - NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) = 0; - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) = 0; - virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet, - PRBool aDisabled) = 0; + /** + * Get the number of stylesheets + * + * @param aIncludeSpecialSheets if this is set to true, all sheets + * that are document sheets (including "special" sheets like + * attribute sheets and inline style sheets) will be returned. If + * false, only "normal" stylesheets will be returned + * @return the number of stylesheets + * @throws no exceptions + */ + NS_IMETHOD GetNumberOfStyleSheets(PRBool aIncludeSpecialSheets, + PRInt32* aCount) = 0; + + /** + * Get a particular stylesheet + * @param aIndex the index the stylesheet lives at. This is zero-based + * @param aIncludeSpecialSheets see GetNumberOfStyleSheets. If this + * is false, not all sheets will be returnable + * @return the stylesheet at aIndex. Null if aIndex is out of range. + * @throws no exceptions + */ + NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, PRBool aIncludeSpecialSheets, + nsIStyleSheet** aSheet) = 0; + + /** + * Insert a sheet at a particular spot in the stylesheet list (zero-based) + * @param aSheet the sheet to insert + * @param aIndex the index to insert at. This index will be + * adjusted for the "special" sheets. + * @throws no exceptions + */ + NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, + PRInt32 aIndex) = 0; + + /** + * Get the index of a particular stylesheet. This will _always_ + * consider the "special" sheets as part of the sheet list. + * @param aSheet the sheet to get the index of + * @return aIndex the index of the sheet in the full list + */ + NS_IMETHOD GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex) = 0; + + /** + * Replace the stylesheets in aOldSheets with the stylesheets in + * aNewSheets. The two lists must have equal length, and the sheet + * at positon J in the first list will be replaced by the sheet at + * position J in the second list. Some sheets in the second list + * may be null; if so the corresponding sheets in the first list + * will simply be removed. + */ + NS_IMETHOD UpdateStyleSheets(nsCOMArray& aOldSheets, + nsCOMArray& aNewSheets) = 0; + + /** + * Add a stylesheet to the document + */ + virtual void AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) = 0; + + /** + * Remove a stylesheet from the document + */ + virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0; + + /** + * Notify the document that the applicable state of the sheet changed + * and that observers should be notified and style sets updated + */ + virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + PRBool aApplicable) = 0; /** * Set the object from which a document can get a script context. diff --git a/content/base/public/nsIDocumentObserver.h b/content/base/public/nsIDocumentObserver.h index 602005e63d2d..5f9e71a86caf 100644 --- a/content/base/public/nsIDocumentObserver.h +++ b/content/base/public/nsIDocumentObserver.h @@ -235,10 +235,10 @@ public: PRInt32 aIndexInContainer) = 0; /** - * A StyleSheet has just been added to the document. - * This method is called automatically when a StyleSheet gets added - * to the document. The notification is passed on to all of the - * document observers. + * A StyleSheet has just been added to the document. This method is + * called automatically when a StyleSheet gets added to the + * document, even if the stylesheet is not applicable. The + * notification is passed on to all of the document observers. * * @param aDocument The document being observed * @param aStyleSheet the StyleSheet that has been added @@ -247,32 +247,32 @@ public: nsIStyleSheet* aStyleSheet) = 0; /** - * A StyleSheet has just been removed from the document. - * This method is called automatically when a StyleSheet gets removed - * from the document. The notification is passed on to all of the - * document observers. + * A StyleSheet has just been removed from the document. This + * method is called automatically when a StyleSheet gets removed + * from the document, even if the stylesheet is not applicable. The + * notification is passed on to all of the document observers. * * @param aDocument The document being observed * @param aStyleSheet the StyleSheet that has been removed */ NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet) = 0; - + /** - * A StyleSheet has just disabled or enabled. - * This method is called automatically when the disabled state + * A StyleSheet has just changed its applicable state. + * This method is called automatically when the applicable state * of a StyleSheet gets changed. The style sheet passes this * notification to the document. The notification is passed on * to all of the document observers. * * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that has been added - * @param aDisabled PR_TRUE if the sheet is disabled, PR_FALSE if - * it is enabled + * @param aStyleSheet the StyleSheet that has changed state + * @param aApplicable PR_TRUE if the sheet is applicable, PR_FALSE if + * it is not applicable */ - NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - PRBool aDisabled) = 0; + NS_IMETHOD StyleSheetApplicableStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aApplicable) = 0; /** * A StyleRule has just been modified within a style sheet. @@ -331,62 +331,62 @@ public: NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) = 0; }; -#define NS_DECL_NSIDOCUMENTOBSERVER \ - NS_IMETHOD BeginUpdate(nsIDocument* aDocument); \ - NS_IMETHOD EndUpdate(nsIDocument* aDocument); \ - NS_IMETHOD BeginLoad(nsIDocument* aDocument); \ - NS_IMETHOD EndLoad(nsIDocument* aDocument); \ - NS_IMETHOD BeginReflow(nsIDocument* aDocument, \ - nsIPresShell* aShell); \ - NS_IMETHOD EndReflow(nsIDocument* aDocument, \ - nsIPresShell* aShell); \ - NS_IMETHOD ContentChanged(nsIDocument* aDocument, \ - nsIContent* aContent, \ - nsISupports* aSubContent); \ - NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, \ - nsIContent* aContent1, \ - nsIContent* aContent2, \ - PRInt32 aStateMask); \ - NS_IMETHOD AttributeChanged(nsIDocument* aDocument, \ - nsIContent* aContent, \ - PRInt32 aNameSpaceID, \ - nsIAtom* aAttribute, \ - PRInt32 aModType, \ - nsChangeHint aHint); \ - NS_IMETHOD ContentAppended(nsIDocument* aDocument, \ - nsIContent* aContainer, \ - PRInt32 aNewIndexInContainer); \ - NS_IMETHOD ContentInserted(nsIDocument* aDocument, \ - nsIContent* aContainer, \ - nsIContent* aChild, \ - PRInt32 aIndexInContainer); \ - NS_IMETHOD ContentReplaced(nsIDocument* aDocument, \ - nsIContent* aContainer, \ - nsIContent* aOldChild, \ - nsIContent* aNewChild, \ - PRInt32 aIndexInContainer); \ - NS_IMETHOD ContentRemoved(nsIDocument* aDocument, \ - nsIContent* aContainer, \ - nsIContent* aChild, \ - PRInt32 aIndexInContainer); \ - NS_IMETHOD StyleSheetAdded(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet); \ - NS_IMETHOD StyleSheetRemoved(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet); \ - NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - PRBool aDisabled); \ - NS_IMETHOD StyleRuleChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - nsIStyleRule* aStyleRule, \ - nsChangeHint aHint); \ - NS_IMETHOD StyleRuleAdded(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - nsIStyleRule* aStyleRule); \ - NS_IMETHOD StyleRuleRemoved(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - nsIStyleRule* aStyleRule); \ - NS_IMETHOD DocumentWillBeDestroyed(nsIDocument* aDocument); \ +#define NS_DECL_NSIDOCUMENTOBSERVER \ + NS_IMETHOD BeginUpdate(nsIDocument* aDocument); \ + NS_IMETHOD EndUpdate(nsIDocument* aDocument); \ + NS_IMETHOD BeginLoad(nsIDocument* aDocument); \ + NS_IMETHOD EndLoad(nsIDocument* aDocument); \ + NS_IMETHOD BeginReflow(nsIDocument* aDocument, \ + nsIPresShell* aShell); \ + NS_IMETHOD EndReflow(nsIDocument* aDocument, \ + nsIPresShell* aShell); \ + NS_IMETHOD ContentChanged(nsIDocument* aDocument, \ + nsIContent* aContent, \ + nsISupports* aSubContent); \ + NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, \ + nsIContent* aContent1, \ + nsIContent* aContent2, \ + PRInt32 aStateMask); \ + NS_IMETHOD AttributeChanged(nsIDocument* aDocument, \ + nsIContent* aContent, \ + PRInt32 aNameSpaceID, \ + nsIAtom* aAttribute, \ + PRInt32 aModType, \ + nsChangeHint aHint); \ + NS_IMETHOD ContentAppended(nsIDocument* aDocument, \ + nsIContent* aContainer, \ + PRInt32 aNewIndexInContainer); \ + NS_IMETHOD ContentInserted(nsIDocument* aDocument, \ + nsIContent* aContainer, \ + nsIContent* aChild, \ + PRInt32 aIndexInContainer); \ + NS_IMETHOD ContentReplaced(nsIDocument* aDocument, \ + nsIContent* aContainer, \ + nsIContent* aOldChild, \ + nsIContent* aNewChild, \ + PRInt32 aIndexInContainer); \ + NS_IMETHOD ContentRemoved(nsIDocument* aDocument, \ + nsIContent* aContainer, \ + nsIContent* aChild, \ + PRInt32 aIndexInContainer); \ + NS_IMETHOD StyleSheetAdded(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet); \ + NS_IMETHOD StyleSheetRemoved(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet); \ + NS_IMETHOD StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet, \ + PRBool aApplicable); \ + NS_IMETHOD StyleRuleChanged(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet, \ + nsIStyleRule* aStyleRule, \ + nsChangeHint aHint); \ + NS_IMETHOD StyleRuleAdded(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet, \ + nsIStyleRule* aStyleRule); \ + NS_IMETHOD StyleRuleRemoved(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet, \ + nsIStyleRule* aStyleRule); \ + NS_IMETHOD DocumentWillBeDestroyed(nsIDocument* aDocument); \ #define NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(_class) \ @@ -507,9 +507,9 @@ _class::StyleSheetRemoved(nsIDocument* aDocument, \ return NS_OK; \ } \ NS_IMETHODIMP \ -_class::StyleSheetDisabledStateChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - PRBool aDisabled) \ +_class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ + nsIStyleSheet* aStyleSheet, \ + PRBool aApplicable) \ { \ return NS_OK; \ } \ diff --git a/content/base/public/nsIStyleSheet.h b/content/base/public/nsIStyleSheet.h index fcc6ccfb8026..a31423ebc5ca 100644 --- a/content/base/public/nsIStyleSheet.h +++ b/content/base/public/nsIStyleSheet.h @@ -70,9 +70,27 @@ public: NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const = 0; NS_IMETHOD_(PRBool) UseForMedium(nsIAtom* aMedium) const = 0; - NS_IMETHOD GetEnabled(PRBool& aEnabled) const = 0; + /** + * Whether the sheet is applicable. A sheet that is not applicable + * should never be inserted into a style set. A sheet may not be + * applicable for a variety of reasons including being disabled and + * being incomplete. + * + */ + NS_IMETHOD GetApplicable(PRBool& aApplicable) const = 0; + + /** + * Set the stylesheet to be enabled. This may or may not make it + * applicable. + */ NS_IMETHOD SetEnabled(PRBool aEnabled) = 0; + /** + * Whether the sheet is complete. + */ + NS_IMETHOD GetComplete(PRBool& aComplete) const = 0; + NS_IMETHOD SetComplete() = 0; + // style sheet owner info NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const = 0; // may be null NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const = 0; // may be null diff --git a/content/base/public/nsIStyleSheetLinkingElement.h b/content/base/public/nsIStyleSheetLinkingElement.h index b2908caf8398..d8478fa72663 100644 --- a/content/base/public/nsIStyleSheetLinkingElement.h +++ b/content/base/public/nsIStyleSheetLinkingElement.h @@ -88,12 +88,8 @@ public: * @param aOldDocument the document that this element was part * of (nsnull if we're not moving the element * from one document to another). - * @param aDocIndex index of the stylesheet in the document's - * stylesheet list. -1 means we'll look up the - * index from the position of the element. */ - NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument, - PRInt32 aDocIndex) = 0; + NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument) = 0; /** * Tells this element wether to update the stylesheet when the diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 55493531d575..85f545612a2b 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -202,22 +202,17 @@ nsDOMStyleSheetList::GetLength(PRUint32* aLength) // observer notification to figure out if new ones have // been added or removed. if (-1 == mLength) { - PRUint32 count = 0; - PRInt32 i, imax = 0; - mDocument->GetNumberOfStyleSheets(&imax); + mDocument->GetNumberOfStyleSheets(PR_FALSE, &mLength); - for (i = 0; i < imax; i++) { +#ifdef DEBUG + PRInt32 i; + for (i = 0; i < mLength; i++) { nsCOMPtr sheet; - mDocument->GetStyleSheetAt(i, getter_AddRefs(sheet)); - if (!sheet) - continue; + mDocument->GetStyleSheetAt(i, PR_FALSE, getter_AddRefs(sheet)); nsCOMPtr domss(do_QueryInterface(sheet)); - - if (domss) { - count++; - } + NS_ASSERTION(domss, "All \"normal\" sheets implement nsIDOMStyleSheet"); } - mLength = count; +#endif } *aLength = mLength; } @@ -232,25 +227,14 @@ NS_IMETHODIMP nsDOMStyleSheetList::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn) { *aReturn = nsnull; - if (nsnull != mDocument) { - PRUint32 count = 0; - PRInt32 i, imax = 0; - mDocument->GetNumberOfStyleSheets(&imax); - - // XXX Not particularly efficient, but does anyone care? - for (i = 0; (i < imax) && (nsnull == *aReturn); i++) { + if (mDocument) { + PRInt32 count = 0; + mDocument->GetNumberOfStyleSheets(PR_FALSE, &count); + if (aIndex < count) { nsCOMPtr sheet; - mDocument->GetStyleSheetAt(i, getter_AddRefs(sheet)); - if (!sheet) - continue; - nsCOMPtr domss(do_QueryInterface(sheet)); - - if (domss) { - if (count++ == aIndex) { - *aReturn = domss; - NS_IF_ADDREF(*aReturn); - } - } + mDocument->GetStyleSheetAt(aIndex, PR_FALSE, getter_AddRefs(sheet)); + NS_ASSERTION(sheet, "Must have a sheet"); + return CallQueryInterface(sheet, aReturn); } } @@ -782,17 +766,12 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) nsIStyleSheet* sheet = mStyleSheets[indx]; sheet->SetOwningDocument(nsnull); - PRInt32 pscount = mPresShells.Count(); - PRInt32 psindex; - for (psindex = 0; psindex < pscount; psindex++) { - nsCOMPtr shell = - (nsIPresShell*)mPresShells.ElementAt(psindex); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set))) && set) { - set->RemoveDocStyleSheet(sheet); - } + PRBool applicable; + sheet->GetApplicable(applicable); + if (applicable) { + RemoveStyleSheetFromStyleSets(sheet); } - + // XXX Tell observers? } // Release all the sheets @@ -1442,21 +1421,51 @@ nsDocument::GetChildCount(PRInt32& aCount) return NS_OK; } -NS_IMETHODIMP -nsDocument::GetNumberOfStyleSheets(PRInt32* aCount) +PRInt32 +nsDocument::InternalGetNumberOfStyleSheets() { - *aCount = mStyleSheets.Count(); - return NS_OK; + return mStyleSheets.Count(); } NS_IMETHODIMP -nsDocument::GetStyleSheetAt(PRInt32 aIndex, nsIStyleSheet** aSheet) +nsDocument::GetNumberOfStyleSheets(PRBool aIncludeSpecialSheets, + PRInt32* aCount) +{ + if (aIncludeSpecialSheets) { + *aCount = mStyleSheets.Count(); + } else { + *aCount = InternalGetNumberOfStyleSheets(); + } + return NS_OK; +} + +already_AddRefed +nsDocument::InternalGetStyleSheetAt(PRInt32 aIndex) { if (aIndex >= 0 && aIndex < mStyleSheets.Count()) { - *aSheet = mStyleSheets[aIndex]; - NS_ADDREF(*aSheet); + nsIStyleSheet* sheet = mStyleSheets[aIndex]; + NS_ADDREF(sheet); + return sheet; } else { - *aSheet = nsnull; + NS_ERROR("Index out of range"); + return nsnull; + } +} + +NS_IMETHODIMP +nsDocument::GetStyleSheetAt(PRInt32 aIndex, PRBool aIncludeSpecialSheets, + nsIStyleSheet** aSheet) +{ + if (aIncludeSpecialSheets) { + if (aIndex >= 0 && aIndex < mStyleSheets.Count()) { + *aSheet = mStyleSheets[aIndex]; + NS_ADDREF(*aSheet); + } else { + NS_ERROR("Index out of range"); + *aSheet = nsnull; + } + } else { + *aSheet = InternalGetStyleSheetAt(aIndex).get(); } return NS_OK; @@ -1492,26 +1501,23 @@ void nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) { - NS_PRECONDITION(nsnull != aSheet, "null arg"); + NS_PRECONDITION(aSheet, "null arg"); InternalAddStyleSheet(aSheet, aFlags); aSheet->SetOwningDocument(this); - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); - - if (enabled) { + PRBool applicable; + aSheet->GetApplicable(applicable); + + if (applicable) { AddStyleSheetToStyleSets(aSheet); - - // XXX should observers be notified for disabled sheets??? I think not, but I could be wrong - for (PRInt32 indx = 0; indx < mObservers.Count(); ++indx) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx); - observer->StyleSheetAdded(this, aSheet); - // handle the observer removing itself! - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(indx)) { - indx--; - } - } } + + // if an observer removes itself, we're ok (not if it removes others though) + PRInt32 i; + for (i = mObservers.Count() - 1; i >= 0; --i) { + nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i); + observer->StyleSheetAdded(this, aSheet); + } } void nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) @@ -1539,20 +1545,17 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) return; } - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); + if (!mIsGoingAway) { + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + if (applicable) { + RemoveStyleSheetFromStyleSets(aSheet); + } - if (enabled && !mIsGoingAway) { - RemoveStyleSheetFromStyleSets(aSheet); - - // XXX should observers be notified for disabled sheets??? I think not, but I could be wrong - for (PRInt32 indx = 0; indx < mObservers.Count(); ++indx) { + // if an observer removes itself, we're ok (not if it removes others though) + for (PRInt32 indx = mObservers.Count() - 1; indx >= 0; --indx) { nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx); observer->StyleSheetRemoved(this, aSheet); - // handle the observer removing itself! - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(indx)) { - indx--; - } } } @@ -1560,55 +1563,63 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) } NS_IMETHODIMP -nsDocument::UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) +nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, + nsCOMArray& aNewSheets) { - PRUint32 oldCount; - aOldSheets->Count(&oldCount); - nsCOMPtr sheet; - PRUint32 i; - for (i = 0; i < oldCount; i++) { - sheet = do_QueryElementAt(aOldSheets, i); - if (sheet) { - PRBool found = mStyleSheets.RemoveObject(sheet); - NS_ASSERTION(found, "stylesheet not found"); - if (found) { - PRBool enabled = PR_TRUE; - sheet->GetEnabled(enabled); - if (enabled) { - RemoveStyleSheetFromStyleSets(sheet); - } + // XXX Need to set the sheet on the ownernode, if any + NS_PRECONDITION(aOldSheets.Count() == aNewSheets.Count(), + "The lists must be the same length!"); + PRInt32 count = aOldSheets.Count(); - sheet->SetOwningDocument(nsnull); + nsCOMPtr oldSheet; + PRInt32 i; + for (i = 0; i < count; ++i) { + oldSheet = aOldSheets[i]; + + // First remove the old sheet. + NS_ASSERTION(oldSheet, "None of the old sheets should be null"); + PRInt32 oldIndex = mStyleSheets.IndexOf(oldSheet); + NS_ASSERTION(oldIndex != -1, "stylesheet not found"); + mStyleSheets.RemoveObjectAt(oldIndex); + + PRBool applicable = PR_TRUE; + oldSheet->GetApplicable(applicable); + if (applicable) { + RemoveStyleSheetFromStyleSets(oldSheet); + } + // XXX we should really notify here, but right now that would + // force things like a full reframe on every sheet. We really + // need a way to batch this sucker... + + oldSheet->SetOwningDocument(nsnull); + + // Now put the new one in its place. If it's null, just ignore it. + nsIStyleSheet* newSheet = aNewSheets[i]; + if (newSheet) { + mStyleSheets.InsertObjectAt(newSheet, oldIndex); + newSheet->SetOwningDocument(this); + PRBool applicable = PR_TRUE; + newSheet->GetApplicable(applicable); + if (applicable) { + AddStyleSheetToStyleSets(newSheet); } + + // XXX we should be notifying here too. } } - PRUint32 newCount; - aNewSheets->Count(&newCount); - for (i = 0; i < newCount; i++) { - sheet = do_QueryElementAt(aNewSheets, i); - if (sheet) { - InternalAddStyleSheet(sheet, 0); - sheet->SetOwningDocument(this); - - PRBool enabled = PR_TRUE; - sheet->GetEnabled(enabled); - if (enabled) { - AddStyleSheetToStyleSets(sheet); - } + // Now notify so _something_ happens, assuming we did anything + if (oldSheet) { + // if an observer removes itself, we're ok (not if it removes + // others though) + // XXXldb Hopefully the observer doesn't care which sheet you use. + for (PRInt32 indx = mObservers.Count() - 1; indx >= 0; --indx) { + nsIDocumentObserver* observer = + (nsIDocumentObserver*)mObservers.ElementAt(indx); + observer->StyleSheetRemoved(this, oldSheet); } } - - // XXXldb Hopefully the observer doesn't care which sheet you use. - for (PRInt32 indx = 0; indx < mObservers.Count(); ++indx) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx); - observer->StyleSheetRemoved(this, sheet); - // handle the observer removing itself! - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(indx)) { - indx--; - } - } - + return NS_OK; } @@ -1620,77 +1631,54 @@ nsDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) } NS_IMETHODIMP -nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) +nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) { - NS_PRECONDITION(nsnull != aSheet, "null ptr"); + NS_PRECONDITION(aSheet, "null ptr"); InternalInsertStyleSheetAt(aSheet, aIndex); aSheet->SetOwningDocument(this); - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); + PRBool applicable; + aSheet->GetApplicable(applicable); + + if (applicable) { + AddStyleSheetToStyleSets(aSheet); + } - PRInt32 count; - PRInt32 indx; - if (enabled) { - count = mPresShells.Count(); - for (indx = 0; indx < count; ++indx) { - nsCOMPtr shell = - (nsIPresShell*)mPresShells.ElementAt(indx); - nsCOMPtr set; - shell->GetStyleSet(getter_AddRefs(set)); - if (set) { - set->AddDocStyleSheet(aSheet, this); - } - } - } - if (aNotify) { // notify here even if disabled, there may have been others that weren't notified - for (indx = 0; indx < mObservers.Count(); ++indx) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx); - observer->StyleSheetAdded(this, aSheet); - // handle the observer removing itself! - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(indx)) { - indx--; - } - } - } + // if an observer removes itself, we're ok (not if it removes others though) + PRInt32 i; + for (i = mObservers.Count() - 1; i >= 0; --i) { + nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i); + observer->StyleSheetAdded(this, aSheet); + } return NS_OK; } -void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet, - PRBool aDisabled) +void nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + PRBool aApplicable) { NS_PRECONDITION(aSheet, "null arg"); - PRInt32 indx = mStyleSheets.IndexOf(aSheet); + + PRInt32 indx; PRInt32 count; // If we're actually in the document style sheet list - if (-1 != indx) { - count = mPresShells.Count(); - for (indx = 0; indx < count; ++indx) { - nsCOMPtr shell = - (nsIPresShell*)mPresShells.ElementAt(indx); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) { - if (set) { - if (aDisabled) { - set->RemoveDocStyleSheet(aSheet); - } - else { - set->AddDocStyleSheet(aSheet, this); - } - } - } + if (-1 != mStyleSheets.IndexOf(aSheet)) { + if (aApplicable) { + AddStyleSheetToStyleSets(aSheet); + } else { + RemoveStyleSheetFromStyleSets(aSheet); } - } + } - for (indx = 0; indx < mObservers.Count(); ++indx) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx); - observer->StyleSheetDisabledStateChanged(this, aSheet, aDisabled); - // handle the observer removing itself! - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(indx)) { - indx--; - } + // XXX Some (nsHTMLEditor, eg) call this function for sheets that + // are not document sheets! So we have to always notify. + + // if an observer removes itself, we're ok (not if it removes others though) + for (indx = mObservers.Count() - 1; indx >= 0; --indx) { + nsIDocumentObserver* observer = + (nsIDocumentObserver*)mObservers.ElementAt(indx); + observer->StyleSheetApplicableStateChanged(this, aSheet, aApplicable); } } diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 4b1bce335587..2de22881124c 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -62,7 +62,6 @@ #include "nsINodeInfo.h" #include "nsIDOMDocumentEvent.h" #include "nsIDOM3DocumentEvent.h" -#include "nsISupportsArray.h" #include "nsCOMArray.h" #include "nsHashtable.h" #include "nsIWordBreakerFactory.h" @@ -203,9 +202,9 @@ public: nsIStyleSheet* aStyleSheet); NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet); - NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - PRBool aDisabled) { return NS_OK; } + NS_IMETHOD StyleSheetApplicableStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aApplicable) { return NS_OK; } NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule, @@ -429,21 +428,22 @@ public: * Get the style sheets owned by this document. * These are ordered, highest priority last */ - NS_IMETHOD GetNumberOfStyleSheets(PRInt32* aCount); - NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsIStyleSheet** aSheet); + NS_IMETHOD GetNumberOfStyleSheets(PRBool aIncludeSpecialSheets, + PRInt32* aCount); + NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, PRBool aIncludeSpecialSheets, + nsIStyleSheet** aSheet); NS_IMETHOD GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex); virtual void AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags); virtual void RemoveStyleSheet(nsIStyleSheet* aSheet); - NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, - nsISupportsArray* aNewSheets); + NS_IMETHOD UpdateStyleSheets(nsCOMArray& aOldSheets, + nsCOMArray& aNewSheets); virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet); virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet); - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, - PRBool aNotify); - virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet, - PRBool mDisabled); + NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); + virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + PRBool aApplicable); /** * Set the object from which a document can get a script context. @@ -609,6 +609,8 @@ protected: PRUint32 aFlags); virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); + virtual already_AddRefed InternalGetStyleSheetAt(PRInt32 aIndex); + virtual PRInt32 InternalGetNumberOfStyleSheets(); nsDocument(); virtual ~nsDocument(); diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 48857112c51f..764b06408e13 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -1661,21 +1661,21 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, rv = CallCreateInstance(kStyleSetCID, aStyleSet); if (NS_OK == rv) { PRInt32 index = 0; - aDocument->GetNumberOfStyleSheets(&index); + aDocument->GetNumberOfStyleSheets(PR_TRUE, &index); while (0 < index--) { nsCOMPtr sheet; - aDocument->GetStyleSheetAt(index, getter_AddRefs(sheet)); + aDocument->GetStyleSheetAt(index, PR_TRUE, getter_AddRefs(sheet)); /* * GetStyleSheetAt will return all style sheets in the document but * we're only interested in the ones that are enabled. */ - PRBool styleEnabled; - sheet->GetEnabled(styleEnabled); + PRBool styleApplicable; + sheet->GetApplicable(styleApplicable); - if (styleEnabled) { + if (styleApplicable) { (*aStyleSet)->AddDocStyleSheet(sheet, aDocument); } } diff --git a/content/base/src/nsStyleLinkElement.cpp b/content/base/src/nsStyleLinkElement.cpp index 78d62ba62eb3..19dbf1f57103 100644 --- a/content/base/src/nsStyleLinkElement.cpp +++ b/content/base/src/nsStyleLinkElement.cpp @@ -26,6 +26,7 @@ #include "nsHTMLAtoms.h" #include "nsIContent.h" #include "nsICSSLoader.h" +#include "nsICSSStyleSheet.h" #include "nsIDocument.h" #include "nsIDOMComment.h" #include "nsIDOMNode.h" @@ -53,7 +54,16 @@ NS_IMETHODIMP nsStyleLinkElement::SetStyleSheet(nsIStyleSheet* aStyleSheet) { mStyleSheet = aStyleSheet; - + nsCOMPtr cssSheet = do_QueryInterface(aStyleSheet); + if (cssSheet) { + nsCOMPtr node; + CallQueryInterface(this, + NS_STATIC_CAST(nsIDOMNode**, getter_AddRefs(node))); + if (node) { + cssSheet->SetOwningNode(node); + } + } + return NS_OK; } @@ -153,8 +163,7 @@ const PRBool kBlockByDefault=PR_TRUE; #endif NS_IMETHODIMP -nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument, - PRInt32 aDocIndex) +nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument) { if (mDontLoadStyle || !mUpdatesEnabled) { return NS_OK; @@ -255,76 +264,6 @@ nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument, } */ - // The way we determine the stylesheet's position in the cascade is by looking - // at the first of the next siblings that are style linking elements, and - // insert just before that one. I'm not sure this is correct for every case for - // XML documents (it seems to be all right for HTML). The sink should disable - // this search by directly specifying a position. - PRInt32 insertionPoint; - - if (aDocIndex > -1) { - insertionPoint = aDocIndex; - } - else { - // We're not getting them in document order, look for where to insert. - nsCOMPtr parentNode; - nsCOMPtr nextSheet; - PRUint16 nodeType = 0; - nsCOMPtr thisNode(do_QueryInterface(thisContent)); - nsCOMPtr nextNode; - nsCOMPtr nextLink; - - thisNode->GetParentNode(getter_AddRefs(parentNode)); - if (parentNode) - parentNode->GetNodeType(&nodeType); - if (nodeType == nsIDOMNode::DOCUMENT_NODE) { - nsCOMPtr parent(do_QueryInterface(parentNode)); - if (parent) { - PRInt32 index, count; - - parent->GetChildCount(count); - parent->IndexOf(thisContent, index); - while (++index < count) { - parent->ChildAt(index, *getter_AddRefs(nextNode)); - nextLink = do_QueryInterface(nextNode); - if (nextLink) { - nextLink->GetStyleSheet(*getter_AddRefs(nextSheet)); - if (nextSheet) - // Found the first following sibling that is a style linking element. - break; - } - } - } - } - else { - nsCOMPtr parent(do_QueryInterface(parentNode)); - if (parent) { - PRInt32 index, count; - - parent->ChildCount(count); - parent->IndexOf(thisContent, index); - while (++index < count) { - parent->ChildAt(index, *getter_AddRefs(nextNode)); - nextLink = do_QueryInterface(nextNode); - if (nextLink) { - nextLink->GetStyleSheet(*getter_AddRefs(nextSheet)); - if (nextSheet) - // Found the first following sibling that is a style linking element. - break; - } - } - } - } - if (nextSheet) { - PRInt32 sheetIndex = 0; - doc->GetIndexOfStyleSheet(nextSheet, &sheetIndex); - insertionPoint = sheetIndex - 1; - } - else { - doc->GetNumberOfStyleSheets(&insertionPoint); - } - } - if (!isAlternate && !title.IsEmpty()) { // possibly preferred sheet nsAutoString prefStyle; doc->GetHeaderData(nsHTMLAtoms::headerDefaultStyle, prefStyle); @@ -373,13 +312,13 @@ nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument, // Now that we have a url and a unicode input stream, parse the // style sheet. rv = loader->LoadInlineStyle(thisContent, uin, title, media, - kNameSpaceID_Unknown, insertionPoint, + kNameSpaceID_Unknown, ((blockParser) ? parser.get() : nsnull), doneLoading, nsnull); } else { rv = loader->LoadStyleLink(thisContent, uri, title, media, - kNameSpaceID_Unknown, insertionPoint, + kNameSpaceID_Unknown, ((blockParser) ? parser.get() : nsnull), doneLoading, nsnull); } diff --git a/content/base/src/nsStyleLinkElement.h b/content/base/src/nsStyleLinkElement.h index 5354b704d6a1..5760416b883d 100644 --- a/content/base/src/nsStyleLinkElement.h +++ b/content/base/src/nsStyleLinkElement.h @@ -48,7 +48,7 @@ public: NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); NS_IMETHOD InitStyleLinkElement(nsIParser *aParser, PRBool aDontLoadStyle); - NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument = nsnull, PRInt32 aDocIndex = -1); + NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument = nsnull); NS_IMETHOD SetEnableUpdates(PRBool aEnableUpdates); NS_IMETHOD GetCharset(nsAString& aCharset); diff --git a/content/base/src/nsStyleSet.cpp b/content/base/src/nsStyleSet.cpp index db51bbb524d4..1404c2d9bd05 100644 --- a/content/base/src/nsStyleSet.cpp +++ b/content/base/src/nsStyleSet.cpp @@ -568,6 +568,11 @@ StyleSetImpl::GatherRuleProcessors(void) void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mOverrideSheets)) { mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->AppendElement(aSheet); @@ -579,6 +584,11 @@ void StyleSetImpl::InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet, nsIStyleSheet* aAfterSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mOverrideSheets)) { mOverrideSheets->RemoveElement(aSheet); PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet); @@ -591,6 +601,11 @@ void StyleSetImpl::InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet, nsIStyleSheet* aBeforeSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mOverrideSheets)) { mOverrideSheets->RemoveElement(aSheet); PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet); @@ -602,7 +617,11 @@ void StyleSetImpl::InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet, void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); - +#ifdef DEBUG + PRBool complete = PR_TRUE; + aSheet->GetComplete(complete); + NS_ASSERTION(complete, "Incomplete sheet being removed from style set"); +#endif if (nsnull != mOverrideSheets) { mOverrideSheets->RemoveElement(aSheet); ClearOverrideRuleProcessors(); @@ -634,6 +653,11 @@ nsIStyleSheet* StyleSetImpl::GetOverrideStyleSheetAt(PRInt32 aIndex) void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument) { NS_PRECONDITION((nsnull != aSheet) && (nsnull != aDocument), "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mDocSheets)) { mDocSheets->RemoveElement(aSheet); // lowest index last @@ -670,7 +694,11 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen void StyleSetImpl::RemoveDocStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); - +#ifdef DEBUG + PRBool complete = PR_TRUE; + aSheet->GetComplete(complete); + NS_ASSERTION(complete, "Incomplete sheet being removed from style set"); +#endif if (nsnull != mDocSheets) { mDocSheets->RemoveElement(aSheet); ClearDocRuleProcessors(); @@ -702,6 +730,11 @@ nsIStyleSheet* StyleSetImpl::GetDocStyleSheetAt(PRInt32 aIndex) void StyleSetImpl::AppendUserStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mUserSheets)) { mUserSheets->RemoveElement(aSheet); mUserSheets->AppendElement(aSheet); @@ -713,6 +746,11 @@ void StyleSetImpl::InsertUserStyleSheetAfter(nsIStyleSheet* aSheet, nsIStyleSheet* aAfterSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mUserSheets)) { mUserSheets->RemoveElement(aSheet); PRInt32 index = mUserSheets->IndexOf(aAfterSheet); @@ -725,6 +763,11 @@ void StyleSetImpl::InsertUserStyleSheetBefore(nsIStyleSheet* aSheet, nsIStyleSheet* aBeforeSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mUserSheets)) { mUserSheets->RemoveElement(aSheet); PRInt32 index = mUserSheets->IndexOf(aBeforeSheet); @@ -736,7 +779,11 @@ void StyleSetImpl::InsertUserStyleSheetBefore(nsIStyleSheet* aSheet, void StyleSetImpl::RemoveUserStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); - +#ifdef DEBUG + PRBool complete = PR_TRUE; + aSheet->GetComplete(complete); + NS_ASSERTION(complete, "Incomplete sheet being removed from style set"); +#endif if (nsnull != mUserSheets) { mUserSheets->RemoveElement(aSheet); ClearUserRuleProcessors(); @@ -775,6 +822,11 @@ StyleSetImpl::ReplaceUserStyleSheets(nsISupportsArray* aNewUserSheets) void StyleSetImpl::AppendAgentStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mAgentSheets)) { mAgentSheets->RemoveElement(aSheet); mAgentSheets->AppendElement(aSheet); @@ -786,6 +838,11 @@ void StyleSetImpl::InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet, nsIStyleSheet* aAfterSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mAgentSheets)) { mAgentSheets->RemoveElement(aSheet); PRInt32 index = mAgentSheets->IndexOf(aAfterSheet); @@ -798,6 +855,11 @@ void StyleSetImpl::InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet, nsIStyleSheet* aBeforeSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); +#ifdef DEBUG + PRBool applicable = PR_TRUE; + aSheet->GetApplicable(applicable); + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); +#endif if (EnsureArray(mAgentSheets)) { mAgentSheets->RemoveElement(aSheet); PRInt32 index = mAgentSheets->IndexOf(aBeforeSheet); @@ -809,7 +871,11 @@ void StyleSetImpl::InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet, void StyleSetImpl::RemoveAgentStyleSheet(nsIStyleSheet* aSheet) { NS_PRECONDITION(nsnull != aSheet, "null arg"); - +#ifdef DEBUG + PRBool complete = PR_TRUE; + aSheet->GetComplete(complete); + NS_ASSERTION(complete, "Incomplete sheet being removed from style set"); +#endif if (nsnull != mAgentSheets) { mAgentSheets->RemoveElement(aSheet); ClearAgentRuleProcessors(); @@ -870,10 +936,10 @@ NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable) PRUint32 count = 0; if (mAgentRuleProcessors) mAgentRuleProcessors->Count(&count); - PRBool enabledNow; - mQuirkStyleSheet->GetEnabled(enabledNow); - NS_ASSERTION(count == 0 || aEnable == enabledNow, - "enabling/disabling quirk stylesheet too late"); + PRBool applicableNow; + mQuirkStyleSheet->GetApplicable(applicableNow); + NS_ASSERTION(count == 0 || aEnable == applicableNow, + "enabling/disabling quirk stylesheet too late or incomplete quirk stylesheet"); if (count != 0 && aEnable == enabledNow) printf("WARNING: We set the quirks mode too many times.\n"); // we do! #endif @@ -899,7 +965,7 @@ StyleSetImpl::ReplaceAgentStyleSheets(nsISupportsArray* aNewAgentSheets) } NS_IMETHODIMP -StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled) +StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aApplicable) { ClearRuleProcessors(); GatherRuleProcessors(); diff --git a/content/build/nsContentDLF.cpp b/content/build/nsContentDLF.cpp index 7f9ea034404c..a7060a0c9cbf 100644 --- a/content/build/nsContentDLF.cpp +++ b/content/build/nsContentDLF.cpp @@ -701,8 +701,7 @@ nsContentDLF::EnsureUAStyleSheet() NS_NewCSSLoader(getter_AddRefs(cssLoader)); if (!cssLoader) return NS_ERROR_OUT_OF_MEMORY; - PRBool complete; - rv = cssLoader->LoadAgentSheet(uri, gUAStyleSheet, complete, nsnull); + rv = cssLoader->LoadAgentSheet(uri, &gUAStyleSheet); #ifdef DEBUG if (NS_FAILED(rv)) printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv); diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index fcab2aaa38ba..5c6bbba120bd 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -393,7 +393,6 @@ public: nsString mBaseHREF; nsString mBaseTarget; - PRInt32 mStyleSheetCount; nsICSSLoader *mCSSLoader; PRInt32 mInsideNoXXXTag; PRInt32 mInMonolithicContainer; @@ -4810,7 +4809,6 @@ HTMLContentSink::ProcessStyleLink(nsIHTMLContent* aElement, PRBool doneLoading; result = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, kNameSpaceID_Unknown, - mStyleSheetCount++, ((blockParser) ? mParser : nsnull), doneLoading, this); @@ -4918,10 +4916,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) if (ssle) { ssle->SetEnableUpdates(PR_TRUE); - result = ssle->UpdateStyleSheet(nsnull, mStyleSheetCount); - if (NS_SUCCEEDED(result) || (result == NS_ERROR_HTMLPARSER_BLOCK)) { - mStyleSheetCount++; - } + result = ssle->UpdateStyleSheet(nsnull); // look for nsAutoString relVal; @@ -5341,10 +5336,16 @@ NS_IMETHODIMP HTMLContentSink::StyleSheetAdded(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet) { - // Processing of a new style sheet causes recreation of the frame - // model. As a result, all contexts should update their notion of - // how much frame creation has happened. - UpdateAllContexts(); + // We only care when applicable sheets are added + NS_PRECONDITION(aStyleSheet, "Must have a style sheet!"); + PRBool applicable; + aStyleSheet->GetApplicable(applicable); + if (applicable) { + // Processing of a new style sheet causes recreation of the frame + // model. As a result, all contexts should update their notion of + // how much frame creation has happened. + UpdateAllContexts(); + } return NS_OK; } @@ -5353,22 +5354,28 @@ NS_IMETHODIMP HTMLContentSink::StyleSheetRemoved(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet) { - // Removing a style sheet causes recreation of the frame model. - // As a result, all contexts should update their notion of how - // much frame creation has happened. - UpdateAllContexts(); + // We only care when applicable sheets are removed + NS_PRECONDITION(aStyleSheet, "Must have a style sheet!"); + PRBool applicable; + aStyleSheet->GetApplicable(applicable); + if (applicable) { + // Removing a style sheet causes recreation of the frame model. + // As a result, all contexts should update their notion of how + // much frame creation has happened. + UpdateAllContexts(); + } return NS_OK; } NS_IMETHODIMP -HTMLContentSink::StyleSheetDisabledStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - PRBool aDisabled) +HTMLContentSink::StyleSheetApplicableStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aApplicable) { - // Disabling/enabling a style sheet causes recreation of the frame - // model. As a result, all contexts should update their notion of - // how much frame creation has happened. + // Changing a style sheet's applicable state causes recreation of + // the frame model. As a result, all contexts should update their + // notion of how much frame creation has happened. UpdateAllContexts(); return NS_OK; @@ -5723,10 +5730,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) if (ssle) { ssle->SetEnableUpdates(PR_TRUE); - rv = ssle->UpdateStyleSheet(nsnull, mStyleSheetCount); - if (NS_SUCCEEDED(rv) || (rv == NS_ERROR_HTMLPARSER_BLOCK)) { - mStyleSheetCount++; - } + rv = ssle->UpdateStyleSheet(nsnull); } return rv; diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 684afd3c5d57..b49c01fd0398 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1239,16 +1239,22 @@ void nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) { if (aSheet == mAttrStyleSheet) { // always first + NS_ASSERTION(mStyleSheets.Count() == 0 || + mAttrStyleSheet != mStyleSheets[0], + "Adding attr sheet twice!"); mStyleSheets.InsertObjectAt(aSheet, 0); } else if (aSheet == mStyleAttrStyleSheet) { // always last + NS_ASSERTION(mStyleSheets.Count() == 0 || + mStyleSheets[mStyleSheets.Count() - 1] != mStyleAttrStyleSheet, + "Adding style attr sheet twice!"); mStyleSheets.AppendObject(aSheet); } else { - if (mStyleSheets.Count() != 0 && - mStyleAttrStyleSheet == mStyleSheets.ObjectAt(mStyleSheets.Count() - 1)) { + PRInt32 count = mStyleSheets.Count(); + if (count != 0 && mStyleAttrStyleSheet == mStyleSheets[count - 1]) { // keep attr sheet last - mStyleSheets.InsertObjectAt(aSheet, mStyleSheets.Count() - 1); + mStyleSheets.InsertObjectAt(aSheet, count - 1); } else { mStyleSheets.AppendObject(aSheet); @@ -1259,9 +1265,47 @@ nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags) void nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) { + NS_ASSERTION(0 <= aIndex && + aIndex <= ( + mStyleSheets.Count() + /* Don't count Attribute stylesheet */ + - 1 + /* No insertion allowed after StyleAttr stylesheet */ + - ((mStyleAttrStyleSheet && + mStyleSheets.Count() > 0 && + mStyleAttrStyleSheet == + mStyleSheets[mStyleSheets.Count() - 1]) ? 1: 0) + ), + "index out of bounds"); + mStyleSheets.InsertObjectAt(aSheet, aIndex + 1); // offset one for the attr style sheet } +already_AddRefed +nsHTMLDocument::InternalGetStyleSheetAt(PRInt32 aIndex) +{ + PRInt32 count = InternalGetNumberOfStyleSheets(); + if (aIndex >= 0 && aIndex < count) { + nsIStyleSheet* sheet = mStyleSheets[aIndex + 1]; + NS_ADDREF(sheet); + return sheet; + } else { + NS_ERROR("Index out of range"); + return nsnull; + } +} + +PRInt32 +nsHTMLDocument::InternalGetNumberOfStyleSheets() +{ + PRInt32 count = mStyleSheets.Count(); + if (count != 0 && mStyleAttrStyleSheet == mStyleSheets[count - 1]) + --count; + --count; // for the attr sheet + NS_ASSERTION(count >= 0, "Why did we end up with a negative count?"); + return count; +} + NS_IMETHODIMP nsHTMLDocument::GetBaseURL(nsIURI*& aURL) const { diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 474ee5f57bab..0f7d928c70d1 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -204,6 +204,9 @@ protected: PRUint32 aFlags); virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); + virtual already_AddRefed InternalGetStyleSheetAt(PRInt32 aIndex); + virtual PRInt32 InternalGetNumberOfStyleSheets(); + static PRBool MatchLinks(nsIContent *aContent, nsString* aData); static PRBool MatchAnchors(nsIContent *aContent, nsString* aData); static PRBool MatchLayers(nsIContent *aContent, nsString* aData); diff --git a/content/html/style/public/nsICSSLoader.h b/content/html/style/public/nsICSSLoader.h index 65b0071b3227..07e9d300ab19 100644 --- a/content/html/style/public/nsICSSLoader.h +++ b/content/html/style/public/nsICSSLoader.h @@ -77,17 +77,18 @@ public: nsICSSParser** aParser) = 0; NS_IMETHOD RecycleParser(nsICSSParser* aParser) = 0; + // XXX No one uses the aDefaultNameSpaceID params.... do we need them? + // Load an inline style sheet // - if aCompleted is PR_TRUE, the sheet is fully loaded, don't // block for it. // - if aCompleted is PR_FALSE, the sheet is still loading and - // will be inserted in the document when complete + // will be marked complete when complete NS_IMETHOD LoadInlineStyle(nsIContent* aElement, - nsIUnicharInputStream* aIn, + nsIUnicharInputStream* aStream, const nsString& aTitle, const nsString& aMedia, PRInt32 aDefaultNameSpaceID, - PRInt32 aDocIndex, nsIParser* aParserToUnblock, PRBool& aCompleted, nsICSSLoaderObserver* aObserver) = 0; @@ -96,13 +97,12 @@ public: // - if aCompleted is PR_TRUE, the sheet is fully loaded, don't // block for it. // - if aCompleted is PR_FALSE, the sheet is still loading and - // will be inserted in the document when complete + // will be marked complete when complete NS_IMETHOD LoadStyleLink(nsIContent* aElement, nsIURI* aURL, const nsString& aTitle, const nsString& aMedia, PRInt32 aDefaultNameSpaceID, - PRInt32 aDocIndex, nsIParser* aParserToUnblock, PRBool& aCompleted, nsICSSLoaderObserver* aObserver) = 0; @@ -112,18 +112,15 @@ public: nsIURI* aURL, const nsString& aMedia, PRInt32 aDefaultNameSpaceID, - PRInt32 aSheetIndex, nsICSSImportRule* aRule) = 0; - // Load a user agent or user sheet immediately - // (note that @imports mayl come in asynchronously) - // - if aCompleted is PR_TRUE, the sheet is fully loaded - // - if aCompleted is PR_FALSE, the sheet is still loading and - // aCAllback will be called when the sheet is complete - NS_IMETHOD LoadAgentSheet(nsIURI* aURL, - nsICSSStyleSheet*& aSheet, - PRBool& aCompleted, - nsICSSLoaderObserver* aObserver) = 0; + // Load a user agent or user sheet. The sheet is loaded + // synchronously, including @imports from it. + NS_IMETHOD LoadAgentSheet(nsIURI* aURL, nsICSSStyleSheet** aSheet) = 0; + + // Load a user agent or user sheet. The sheet is loaded + // asynchronously and the observer notified when the load finishes. + NS_IMETHOD LoadAgentSheet(nsIURI* aURL, nsICSSLoaderObserver* aObserver) = 0; // stop loading all sheets NS_IMETHOD Stop(void) = 0; diff --git a/content/html/style/public/nsICSSStyleSheet.h b/content/html/style/public/nsICSSStyleSheet.h index f81e36f8c926..6aa406a8ae2f 100644 --- a/content/html/style/public/nsICSSStyleSheet.h +++ b/content/html/style/public/nsICSSStyleSheet.h @@ -75,7 +75,7 @@ public: NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const = 0; NS_IMETHOD Init(nsIURI* aURL) = 0; - NS_IMETHOD SetTitle(const nsString& aTitle) = 0; + NS_IMETHOD SetTitle(const nsAString& aTitle) = 0; NS_IMETHOD AppendMedium(nsIAtom* aMedium) = 0; NS_IMETHOD ClearMedia(void) = 0; NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode) = 0; diff --git a/content/html/style/src/nsCSSLoader.cpp b/content/html/style/src/nsCSSLoader.cpp index 637e20fa71a0..ec0cb65e8562 100644 --- a/content/html/style/src/nsCSSLoader.cpp +++ b/content/html/style/src/nsCSSLoader.cpp @@ -17,7 +17,9 @@ * Copyright (C) 1999 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): + * Boris Zbarsky + * * This Original Code has been modified by IBM Corporation. Modifications made by IBM * described herein are Copyright (c) International Business Machines Corporation, 2000. * Modifications to Mozilla code or documentation identified per MPL Section 3.3 @@ -39,8 +41,6 @@ #include "nsIUnicharStreamLoader.h" #include "nsIUnicharInputStream.h" #include "nsIConverterInputStream.h" -#include "nsICharsetConverterManager.h" -#include "nsIUnicodeDecoder.h" #include "nsICharsetAlias.h" #include "nsUnicharUtils.h" #include "nsHashtable.h" @@ -49,17 +49,16 @@ #include "nsIServiceManager.h" #include "nsNetUtil.h" #include "nsCRT.h" -#include "nsVoidArray.h" -#include "nsISupportsArray.h" +#include "nsCOMArray.h" #include "nsCOMPtr.h" #include "nsIScriptSecurityManager.h" #include "nsITimelineService.h" #include "nsIHttpChannel.h" -#include "nsHTMLAtoms.h" #include "nsIConsoleService.h" #include "nsIScriptError.h" #include "nsIStringBundle.h" #include "nsMimeTypes.h" +#include "nsIAtom.h" #ifdef INCLUDE_XUL #include "nsIXULPrototypeCache.h" @@ -67,12 +66,80 @@ #include "nsIDOMMediaList.h" #include "nsIDOMStyleSheet.h" +#include "nsIDOMCSSStyleSheet.h" +#include "nsIDOMCSSImportRule.h" + +#ifdef MOZ_LOGGING +// #define FORCE_PR_LOG /* Allow logging in the release build */ +#endif /* MOZ_LOGGING */ +#include "prlog.h" + +#ifdef PR_LOGGING +static PRLogModuleInfo *gLoaderLog = PR_NewLogModule("nsCSSLoader"); +#endif /* PR_LOGGING */ + +#define LOG_FORCE(args) PR_LOG(gLoaderLog, PR_LOG_ALWAYS, args) +#define LOG_ERROR(args) PR_LOG(gLoaderLog, PR_LOG_ERROR, args) +#define LOG_WARN(args) PR_LOG(gLoaderLog, PR_LOG_WARNING, args) +#define LOG_DEBUG(args) PR_LOG(gLoaderLog, PR_LOG_DEBUG, args) +#define LOG(args) LOG_DEBUG(args) + +#define LOG_FORCE_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_ALWAYS) +#define LOG_ERROR_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_ERROR) +#define LOG_WARN_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_WARNING) +#define LOG_DEBUG_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_DEBUG) +#define LOG_ENABLED() LOG_DEBUG_ENABLED() + +#ifdef PR_LOGGING +#define LOG_URI(format, uri) \ + PR_BEGIN_MACRO \ + NS_ASSERTION(uri, "Logging null uri"); \ + if (LOG_ENABLED()) { \ + nsCAutoString _logURISpec; \ + uri->GetSpec(_logURISpec); \ + LOG((format, _logURISpec.get())); \ + } \ + PR_END_MACRO +#else // PR_LOGGING +#define LOG_URI(format, uri) +#endif // PR_LOGGING -static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); class CSSLoaderImpl; +/** + * OVERALL ARCHITECTURE + * + * The CSS Loader gets requests to load various sorts of style sheets: + * inline style from