diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index f3cb2add4353..efde7a8a7b71 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -82,7 +82,6 @@ #include "nsIHTMLContentContainer.h" #include "nsIPresShell.h" #include "nsIDocShell.h" -#include "nsIStyleSet.h" #include "nsISupportsArray.h" #include "nsIDocumentObserver.h" #ifdef MOZ_XUL @@ -1534,44 +1533,37 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) for (PRUint32 k = 0; k < shellCount; k++) { nsIPresShell *shell = document->GetShellAt(k); - nsCOMPtr styleSet; - rv = shell->GetStyleSet(getter_AddRefs(styleSet)); - if (NS_FAILED(rv)) return rv; - if (styleSet) { - // Reload only the chrome URL agent style sheets. - nsCOMPtr agents; - rv = NS_NewISupportsArray(getter_AddRefs(agents)); + // Reload only the chrome URL agent style sheets. + nsCOMArray agentSheets; + rv = shell->GetAgentStyleSheets(agentSheets); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMArray newAgentSheets; + for (PRInt32 l = 0; l < agentSheets.Count(); ++l) { + nsIStyleSheet *sheet = agentSheets[l]; + + nsCOMPtr uri; + rv = sheet->GetURL(*getter_AddRefs(uri)); if (NS_FAILED(rv)) return rv; - nsCOMPtr newAgentSheets; - rv = NS_NewISupportsArray(getter_AddRefs(newAgentSheets)); - if (NS_FAILED(rv)) return rv; - - PRInt32 bc = styleSet->GetNumberOfAgentStyleSheets(); - for (PRInt32 l = 0; l < bc; l++) { - nsCOMPtr sheet = getter_AddRefs(styleSet->GetAgentStyleSheetAt(l)); - nsCOMPtr uri; - rv = sheet->GetURL(*getter_AddRefs(uri)); + if (IsChromeURI(uri)) { + // Reload the sheet. + nsCOMPtr newSheet; + rv = LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); if (NS_FAILED(rv)) return rv; - - if (IsChromeURI(uri)) { - // Reload the sheet. - nsCOMPtr newSheet; - rv = LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); - if (NS_FAILED(rv)) return rv; - if (newSheet) { - rv = newAgentSheets->AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; - if (NS_FAILED(rv)) return rv; - } - } - else { // Just use the same sheet. - rv = newAgentSheets->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE; + if (newSheet) { + rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } - - styleSet->ReplaceAgentStyleSheets(newAgentSheets); + else { // Just use the same sheet. + rv = newAgentSheets.AppendObject(sheet) ? NS_OK : NS_ERROR_FAILURE; + if (NS_FAILED(rv)) return rv; + } } + + rv = shell->SetAgentStyleSheets(newAgentSheets); + NS_ENSURE_SUCCESS(rv, rv); } // The document sheets just need to be done once; the document will notify diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 07d0994638cf..a671217a5837 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -53,6 +53,7 @@ #include "nsILoadGroup.h" #include "nsReadableUtils.h" #include "nsCRT.h" +#include // for FILE definition class nsIAtom; class nsIContent; @@ -61,7 +62,7 @@ class nsIPresShell; class nsIStreamListener; class nsIStreamObserver; -class nsIStyleSet; +class nsStyleSet; class nsIStyleSheet; class nsIStyleRule; class nsIViewManager; @@ -253,7 +254,7 @@ public: */ NS_IMETHOD CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, + nsStyleSet* aStyleSet, nsIPresShell** aInstancePtrResult) = 0; NS_IMETHOD_(PRBool) DeleteShell(nsIPresShell* aShell) = 0; NS_IMETHOD_(PRUint32) GetNumberOfShells() const = 0; diff --git a/content/base/public/nsIStyleRuleProcessor.h b/content/base/public/nsIStyleRuleProcessor.h index 1b83de5f8ab5..b853d14048dd 100644 --- a/content/base/public/nsIStyleRuleProcessor.h +++ b/content/base/public/nsIStyleRuleProcessor.h @@ -175,6 +175,10 @@ class nsIStyleRuleProcessor : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID) + // Shorthand for: + // nsCOMArray::nsCOMArrayEnumFunc + typedef PRBool (* PR_CALLBACK EnumFunc)(nsIStyleRuleProcessor*, void*); + // populate rule node tree with nsIStyleRule* // rules are ordered, those with higher precedence are farthest from the root of the tree NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData, diff --git a/content/base/public/nsIStyleRuleSupplier.h b/content/base/public/nsIStyleRuleSupplier.h index e2e75a9d68a1..80d727637127 100644 --- a/content/base/public/nsIStyleRuleSupplier.h +++ b/content/base/public/nsIStyleRuleSupplier.h @@ -10,15 +10,15 @@ { 0x2d77a45b, 0x4f3a, 0x4203, { 0xa7, 0xd2, 0xf4, 0xb8, 0x4d, 0xc, 0x1e, 0xe4 } } class nsIContent; -class nsIStyleSet; +class nsStyleSet; class nsIStyleRuleSupplier : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLERULESUPPLIER_IID) NS_IMETHOD UseDocumentRules(nsIContent* aContent, PRBool* aResult)=0; - NS_IMETHOD WalkRules(nsIStyleSet* aStyleSet, - nsISupportsArrayEnumFunc aFunc, + NS_IMETHOD WalkRules(nsStyleSet* aStyleSet, + nsIStyleRuleProcessor::EnumFunc aFunc, RuleProcessorData* aData)=0; }; diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index 3e7beb8cb32c..9cc0de833b5b 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -60,6 +60,8 @@ REQUIRES = xpcom \ prefetch \ $(NULL) +EXPORTS = nsStyleSet.h + CPPSRCS = \ nsContentSink.cpp \ nsPrintEngine.cpp \ @@ -125,3 +127,5 @@ INCLUDES += \ -I$(srcdir)/../../base/src \ -I$(srcdir)/../../../layout/html/base/src \ $(NULL) + +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index eeac5cc62592..d783714c8a90 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -77,7 +77,7 @@ #include "nsIScrollableView.h" #include "nsIPresShell.h" #include "nsIPresContext.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" #include "nsContentUtils.h" #include "nsNodeInfoManager.h" #include "nsIXBLService.h" @@ -1050,7 +1050,7 @@ nsDocument::SetHeaderData(nsIAtom* aHeaderField, const nsAString& aData) NS_IMETHODIMP nsDocument::CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, + nsStyleSet* aStyleSet, nsIPresShell** aInstancePtrResult) { // Don't add anything here. Add it to |doCreateShell| instead. @@ -1062,7 +1062,7 @@ nsDocument::CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, nsresult nsDocument::doCreateShell(nsIPresContext* aContext, - nsIViewManager* aViewManager, nsIStyleSet* aStyleSet, + nsIViewManager* aViewManager, nsStyleSet* aStyleSet, nsCompatibility aCompatMode, nsIPresShell** aInstancePtrResult) { @@ -1339,13 +1339,8 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) PRInt32 count = mPresShells.Count(); PRInt32 indx; for (indx = 0; indx < count; ++indx) { - nsCOMPtr shell = (nsIPresShell *)mPresShells.ElementAt(indx); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) { - if (set) { - set->AddDocStyleSheet(aSheet, this); - } - } + NS_STATIC_CAST(nsIPresShell*, mPresShells.ElementAt(indx))->StyleSet()-> + AddDocStyleSheet(aSheet, this); } } @@ -1379,13 +1374,8 @@ nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) PRInt32 count = mPresShells.Count(); PRInt32 indx; for (indx = 0; indx < count; ++indx) { - nsCOMPtr shell = (nsIPresShell *)mPresShells.ElementAt(indx); - nsCOMPtr set; - shell->GetStyleSet(getter_AddRefs(set)); - - if (set) { - set->RemoveDocStyleSheet(aSheet); - } + NS_STATIC_CAST(nsIPresShell*, mPresShells.ElementAt(indx))->StyleSet()-> + RemoveStyleSheet(nsStyleSet::eDocSheet, aSheet); } } @@ -1527,6 +1517,16 @@ nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet, } else { RemoveStyleSheetFromStyleSets(aSheet); } + } else { + // We still need to notify the style set of the state change, because + // this will invalidate some of the rule processor data. + + PRInt32 count = mPresShells.Count(); + PRInt32 indx; + for (indx = 0; indx < count; ++indx) { + NS_STATIC_CAST(nsIPresShell*, mPresShells.ElementAt(indx))->StyleSet()-> + StyleSheetApplicableStateChanged(); + } } // We have to always notify, since this will be called for sheets @@ -1647,6 +1647,14 @@ nsDocument::RemoveObserver(nsIDocumentObserver* aObserver) void nsDocument::BeginUpdate(nsUpdateType aUpdateType) { + if (aUpdateType & UPDATE_STYLE) { + PRInt32 shellCount = mPresShells.Count(); + for (PRInt32 j = 0; j < shellCount; ++j) { + NS_STATIC_CAST(nsIPresShell*, mPresShells.ElementAt(j))->StyleSet()-> + BeginUpdate(); + } + } + PRInt32 i; for (i = mObservers.Count() - 1; i >= 0; --i) { nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; @@ -1657,6 +1665,14 @@ nsDocument::BeginUpdate(nsUpdateType aUpdateType) void nsDocument::EndUpdate(nsUpdateType aUpdateType) { + if (aUpdateType & UPDATE_STYLE) { + PRInt32 shellCount = mPresShells.Count(); + for (PRInt32 j = 0; j < shellCount; ++j) { + NS_STATIC_CAST(nsIPresShell*, mPresShells.ElementAt(j))->StyleSet()-> + EndUpdate(); + } + } + PRInt32 i; for (i = mObservers.Count() - 1; i >= 0; --i) { nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index d9d0ffd3ecf3..dbdcf470ceaa 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -97,6 +97,7 @@ class nsIDTD; class nsXPathDocumentTearoff; class nsIRadioVisitor; class nsIFormControl; +class nsStyleSet; struct nsRadioGroupStruct; @@ -329,7 +330,7 @@ public: */ NS_IMETHOD CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, + nsStyleSet* aStyleSet, nsIPresShell** aInstancePtrResult); NS_IMETHOD_(PRBool) DeleteShell(nsIPresShell* aShell); NS_IMETHOD_(PRUint32) GetNumberOfShells() const; @@ -540,7 +541,7 @@ protected: virtual void RetrieveRelevantHeaders(nsIChannel *aChannel); nsresult doCreateShell(nsIPresContext* aContext, - nsIViewManager* aViewManager, nsIStyleSet* aStyleSet, + nsIViewManager* aViewManager, nsStyleSet* aStyleSet, nsCompatibility aCompatMode, nsIPresShell** aInstancePtrResult); diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index adccf2c3e5fb..3e01343df941 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -53,7 +53,7 @@ #include "nsIDocument.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" #include "nsIStyleSheet.h" #include "nsICSSStyleSheet.h" #include "nsIFrame.h" @@ -195,7 +195,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsBidiUtils.h" static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); -static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); #ifdef NS_DEBUG @@ -640,8 +639,8 @@ nsresult DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow) { // Create the style set... - nsCOMPtr styleSet; - nsresult rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); + nsStyleSet *styleSet; + nsresult rv = CreateStyleSet(mDocument, &styleSet); NS_ENSURE_SUCCESS(rv, rv); // Now make the shell for the document @@ -1192,8 +1191,8 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) if (mPresContext) { // 3) Create a new style set for the document - nsCOMPtr styleSet; - rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); + nsStyleSet *styleSet; + rv = CreateStyleSet(mDocument, &styleSet); if (NS_FAILED(rv)) return rv; @@ -1587,79 +1586,83 @@ DocumentViewerImpl::ForceRefresh() nsresult DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, - nsIStyleSet** aStyleSet) + nsStyleSet** aStyleSet) { // this should eventually get expanded to allow for creating // different sets for different media - nsresult rv; - if (!mUAStyleSheet) { NS_WARNING("unable to load UA style sheet"); } - rv = CallCreateInstance(kStyleSetCID, aStyleSet); - if (NS_OK == rv) { - PRInt32 index = aDocument->GetNumberOfStyleSheets(PR_TRUE); + nsStyleSet *styleSet = new nsStyleSet(); + if (!styleSet) { + return NS_ERROR_OUT_OF_MEMORY; + } - while (0 < index--) { - nsIStyleSheet *sheet = aDocument->GetStyleSheetAt(index, PR_TRUE); + PRInt32 index = aDocument->GetNumberOfStyleSheets(PR_TRUE); - /* - * GetStyleSheetAt will return all style sheets in the document but - * we're only interested in the ones that are enabled. - */ + styleSet->BeginUpdate(); - PRBool styleApplicable; - sheet->GetApplicable(styleApplicable); + while (0 < index--) { + nsIStyleSheet *sheet = aDocument->GetStyleSheetAt(index, PR_TRUE); - if (styleApplicable) { - (*aStyleSet)->AddDocStyleSheet(sheet, aDocument); - } - } + /* + * GetStyleSheetAt will return all style sheets in the document but + * we're only interested in the ones that are enabled. + */ - nsCOMPtr chromeRegistry = - do_GetService("@mozilla.org/chrome/chrome-registry;1"); + PRBool styleApplicable; + sheet->GetApplicable(styleApplicable); - if (chromeRegistry) { - nsCOMPtr sheets; - - // Now handle the user sheets. - nsCOMPtr docShell(do_QueryInterface(mContainer)); - PRInt32 shellType; - docShell->GetItemType(&shellType); - PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); - sheets = nsnull; - chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); - if(sheets){ - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - // Insert the user sheets at the front of the user sheet list - // so that they are most significant user sheets. - for(PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); - (*aStyleSet)->InsertUserStyleSheetBefore(sheet, nsnull); - } - } - - // Append chrome sheets (scrollbars + forms). - nsCOMPtr ds(do_QueryInterface(mContainer)); - chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets)); - if(sheets){ - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - for(PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); - (*aStyleSet)->AppendAgentStyleSheet(sheet); - } - } - } - - if (mUAStyleSheet) { - (*aStyleSet)->AppendAgentStyleSheet(mUAStyleSheet); + if (styleApplicable) { + styleSet->AddDocStyleSheet(sheet, aDocument); } } + + nsCOMPtr chromeRegistry = + do_GetService("@mozilla.org/chrome/chrome-registry;1"); + + if (chromeRegistry) { + nsCOMPtr sheets; + + // Now handle the user sheets. + nsCOMPtr docShell(do_QueryInterface(mContainer)); + PRInt32 shellType; + docShell->GetItemType(&shellType); + PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); + chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); + if (sheets) { + nsCOMPtr sheet; + PRUint32 count; + sheets->Count(&count); + // Insert the user sheets at the front of the user sheet list + // so that they are most significant user sheets. + for (PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); + styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet); + } + } + + // Append chrome sheets (scrollbars + forms). + nsCOMPtr ds(do_QueryInterface(mContainer)); + chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets)); + if (sheets) { + nsCOMPtr sheet; + PRUint32 count; + sheets->Count(&count); + for (PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); + styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet); + } + } + } + + if (mUAStyleSheet) { + styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet); + } + + styleSet->EndUpdate(); + *aStyleSet = styleSet; return NS_OK; } diff --git a/content/base/src/nsIDocumentViewerPrint.h b/content/base/src/nsIDocumentViewerPrint.h index 4c516a4b02c4..2aca4a8c07e7 100644 --- a/content/base/src/nsIDocumentViewerPrint.h +++ b/content/base/src/nsIDocumentViewerPrint.h @@ -46,7 +46,7 @@ class nsPrintObject; class nsISelection; class nsIPresShell; class nsIDocument; -class nsIStyleSet; +class nsStyleSet; class nsIContent; class nsIWebShell; @@ -72,7 +72,7 @@ public: virtual PRBool GetIsCreatingPrintPreview() = 0; - virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet) = 0; + virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsStyleSet** aStyleSet) = 0; virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull) = 0; @@ -97,7 +97,7 @@ public: virtual void SetIsPrintPreview(PRBool aIsPrintPreview); \ virtual PRBool GetIsPrintPreview(); \ virtual PRBool GetIsCreatingPrintPreview(); \ - virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); \ + virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsStyleSet** aStyleSet); \ virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); \ virtual void IncrementDestroyRefCount(); \ virtual void ReturnToGalleyPresentation(); \ diff --git a/content/base/src/nsPrintEngine.cpp b/content/base/src/nsPrintEngine.cpp index eaf1e7b95c47..5d878eb2184b 100644 --- a/content/base/src/nsPrintEngine.cpp +++ b/content/base/src/nsPrintEngine.cpp @@ -2608,7 +2608,8 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // init it with the DC (aPO->mPresContext)->Init(mPrt->mPrintDocDC); - mDocViewerPrint->CreateStyleSet(aPO->mDocument, getter_AddRefs(aPO->mStyleSet)); + rv = mDocViewerPrint->CreateStyleSet(aPO->mDocument, &aPO->mStyleSet); + NS_ENSURE_SUCCESS(rv, rv); aPO->mViewManager = do_CreateInstance(kViewManagerCID, &rv); if (NS_FAILED(rv)) { diff --git a/content/base/src/nsPrintObject.cpp b/content/base/src/nsPrintObject.cpp index ae2db653aa9a..97c91c7d5e5a 100644 --- a/content/base/src/nsPrintObject.cpp +++ b/content/base/src/nsPrintObject.cpp @@ -42,7 +42,7 @@ //-- nsPrintObject Class Impl //--------------------------------------------------- nsPrintObject::nsPrintObject() : - mFrameType(eFrame), + mFrameType(eFrame), mStyleSet(nsnull), mRootView(nsnull), mContent(nsnull), mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1), mRect(0,0,0,0), mReflowRect(0,0,0,0), diff --git a/content/base/src/nsPrintObject.h b/content/base/src/nsPrintObject.h index 0a5568d27a71..06cd9638010f 100644 --- a/content/base/src/nsPrintObject.h +++ b/content/base/src/nsPrintObject.h @@ -39,10 +39,11 @@ // Interfaces #include "nsCOMPtr.h" +#include "nsAutoPtr.h" #include "nsIContent.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" #include "nsIViewManager.h" #include "nsIWebShell.h" #include "nsIDocShell.h" @@ -80,7 +81,7 @@ public: PrintObjectType mFrameType; nsCOMPtr mPresContext; - nsCOMPtr mStyleSet; + nsStyleSet *mStyleSet; nsCOMPtr mPresShell; nsCOMPtr mViewManager; nsCOMPtr mWindow; diff --git a/content/base/src/nsRuleNode.cpp b/content/base/src/nsRuleNode.cpp index 5c525cbd3ebd..54972c6ad12f 100644 --- a/content/base/src/nsRuleNode.cpp +++ b/content/base/src/nsRuleNode.cpp @@ -53,6 +53,7 @@ #include "nsITheme.h" #include "pldhash.h" #include "nsStyleContext.h" +#include "nsStyleSet.h" /* * For storage of an |nsRuleNode|'s children in a linked list. @@ -4330,9 +4331,8 @@ nsRuleNode::GetStyleData(nsStyleStructID aSID, // this works fine even if |this| is a rule node that has been // destroyed (leftover from a previous rule tree) but is somehow still // used. - nsCOMPtr set; - mPresContext->PresShell()->GetStyleSet(getter_AddRefs(set)); - return set->GetDefaultStyleData()->GetStyleData(aSID); + return mPresContext->PresShell()->StyleSet()-> + DefaultStyleData()->GetStyleData(aSID); } void @@ -4358,7 +4358,7 @@ PRBool nsRuleNode::Sweep() { // If we're not marked, then we have to delete ourself. - if (!(mDependentBits & NS_RULE_NODE_GC_MARK)) { + if (!(mDependentBits & NS_RULE_NODE_GC_MARK) && !IsRoot()) { Destroy(); return PR_TRUE; } diff --git a/content/base/src/nsStyleContext.cpp b/content/base/src/nsStyleContext.cpp index 7511921bc660..50869b22eeb9 100644 --- a/content/base/src/nsStyleContext.cpp +++ b/content/base/src/nsStyleContext.cpp @@ -46,7 +46,7 @@ #include "nsCRT.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" #include "nsIPresShell.h" #include "nsLayoutAtoms.h" #include "prenv.h" @@ -94,9 +94,8 @@ nsStyleContext::~nsStyleContext() nsIPresContext *presContext = mRuleNode->GetPresContext(); - nsCOMPtr set; - presContext->PresShell()->GetStyleSet(getter_AddRefs(set)); - set->NotifyStyleContextDestroyed(presContext, this); + presContext->PresShell()->StyleSet()-> + NotifyStyleContextDestroyed(presContext, this); if (mParent) { mParent->RemoveChild(this); diff --git a/content/base/src/nsStyleSet.cpp b/content/base/src/nsStyleSet.cpp index 85de976e1a2f..460ac7e944e0 100644 --- a/content/base/src/nsStyleSet.cpp +++ b/content/base/src/nsStyleSet.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Daniel Glazman + * Brian Ryner * * * Alternatively, the contents of this file may be used under the terms of @@ -36,890 +37,268 @@ * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -#include "nsCOMPtr.h" -#include "nsIStyleSet.h" -#include "nsIStyleSheet.h" -#include "nsIStyleRuleProcessor.h" -#include "nsIStyleRule.h" -#include "nsICSSStyleRule.h" -#include "nsISupportsArray.h" -#include "nsIFrame.h" -#include "nsIPresContext.h" -#include "nsIPresShell.h" -#include "nsIContent.h" +#include "nsStyleSet.h" +#include "nsNetUtil.h" +#include "nsICSSStyleSheet.h" #include "nsIDocument.h" -#include "nsIStyleFrameConstruction.h" +#include "nsRuleWalker.h" +#include "nsStyleContext.h" +#include "nsICSSStyleRule.h" #include "nsCSSAnonBoxes.h" #include "nsCSSPseudoElements.h" -#include "nsTimer.h" -#include "nsICSSStyleSheet.h" -#include "nsNetUtil.h" -#include "nsIStyleRuleSupplier.h" -#include "nsRuleNode.h" -#include "nsRuleWalker.h" -#include "nsIHTMLDocument.h" -#include "nsIDOMHTMLBodyElement.h" -#include "nsHashtable.h" +#include "nsIContent.h" +#include "nsIFrame.h" -#ifdef MOZ_PERF_METRICS - #include "nsITimeRecorder.h" - #define STYLESET_START_TIMER(a) \ - StartTimer(a) - #define STYLESET_STOP_TIMER(a) \ - StopTimer(a) -#else - #define STYLESET_START_TIMER(a) ((void)0) - #define STYLESET_STOP_TIMER(a) ((void)0) -#endif +nsIURI *nsStyleSet::gQuirkURI = 0; -// ===================================================== -// nsRuleNodeList -// A class that represents a chain of rule nodes - -struct nsRuleNodeList -{ - nsRuleNodeList(nsRuleNode* aRuleNode, nsRuleNodeList* aNext = nsnull) - :mRuleNode(aRuleNode), mNext(aNext) - {}; - - void* operator new(size_t sz, nsIPresContext* aContext) CPP_THROW_NEW { - void* result = nsnull; - aContext->AllocateFromShell(sz, &result); - return result; - }; - - void Destroy() { - if (mNext) - mNext->Destroy(); - mRuleNode->GetPresContext()->FreeToShell(sizeof(nsRuleNodeList), this); - }; - - nsRuleNode* mRuleNode; - nsRuleNodeList* mNext; -}; - -// ===================================================== - -class StyleSetImpl : public nsIStyleSet -#ifdef MOZ_PERF_METRICS - , public nsITimeRecorder -#endif -{ -public: - StyleSetImpl(); - - NS_DECL_ISUPPORTS - - virtual void AppendOverrideStyleSheet(nsIStyleSheet* aSheet); - virtual void InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet, - nsIStyleSheet* aAfterSheet); - virtual void InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet, - nsIStyleSheet* aBeforeSheet); - virtual void RemoveOverrideStyleSheet(nsIStyleSheet* aSheet); - virtual PRInt32 GetNumberOfOverrideStyleSheets(); - virtual nsIStyleSheet* GetOverrideStyleSheetAt(PRInt32 aIndex); - - virtual void AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument); - virtual void RemoveDocStyleSheet(nsIStyleSheet* aSheet); - virtual PRInt32 GetNumberOfDocStyleSheets(); - virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex); - - virtual void AppendUserStyleSheet(nsIStyleSheet* aSheet); - virtual void InsertUserStyleSheetAfter(nsIStyleSheet* aSheet, - nsIStyleSheet* aAfterSheet); - virtual void InsertUserStyleSheetBefore(nsIStyleSheet* aSheet, - nsIStyleSheet* aBeforeSheet); - virtual void RemoveUserStyleSheet(nsIStyleSheet* aSheet); - virtual PRInt32 GetNumberOfUserStyleSheets(); - virtual nsIStyleSheet* GetUserStyleSheetAt(PRInt32 aIndex); - virtual void ReplaceUserStyleSheets(nsISupportsArray* aNewSheets); - - virtual void AppendAgentStyleSheet(nsIStyleSheet* aSheet); - virtual void InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet, - nsIStyleSheet* aAfterSheet); - virtual void InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet, - nsIStyleSheet* aBeforeSheet); - virtual void RemoveAgentStyleSheet(nsIStyleSheet* aSheet); - virtual PRInt32 GetNumberOfAgentStyleSheets(); - virtual nsIStyleSheet* GetAgentStyleSheetAt(PRInt32 aIndex); - virtual void ReplaceAgentStyleSheets(nsISupportsArray* aNewSheets); - - NS_IMETHOD EnableQuirkStyleSheet(PRBool aEnable); - - NS_IMETHOD NotifyStyleSheetStateChanged(PRBool aDisabled); - - virtual already_AddRefed - ResolveStyleFor(nsIPresContext* aPresContext, - nsIContent* aContent, - nsStyleContext* aParentContext); - - virtual already_AddRefed - ResolveStyleForNonElement(nsIPresContext* aPresContext, - nsStyleContext* aParentContext); - - virtual already_AddRefed - ResolvePseudoStyleFor(nsIPresContext* aPresContext, - nsIContent* aParentContent, - nsIAtom* aPseudoTag, - nsStyleContext* aParentContext, - nsICSSPseudoComparator* aComparator = nsnull); - - virtual already_AddRefed - ProbePseudoStyleFor(nsIPresContext* aPresContext, - nsIContent* aParentContent, - nsIAtom* aPseudoTag, - nsStyleContext* aParentContext); - - NS_IMETHOD BeginShutdown(nsIPresContext* aPresContext); - NS_IMETHOD Shutdown(nsIPresContext* aPresContext); - NS_IMETHOD NotifyStyleContextDestroyed(nsIPresContext* aPresContext, - nsStyleContext* aStyleContext); - - // For getting the cached default data in case we hit out-of-memory. - // To be used only by nsRuleNode. - virtual nsCachedStyleData* GetDefaultStyleData(); - - virtual nsresult GetRuleTree(nsRuleNode** aResult); - - virtual nsresult ClearStyleData(nsIPresContext* aPresContext); - - virtual nsresult GetStyleFrameConstruction(nsIStyleFrameConstruction** aResult) { - *aResult = mFrameConstructor; - NS_IF_ADDREF(*aResult); - return NS_OK; - } - - virtual already_AddRefed - ReParentStyleContext(nsIPresContext* aPresContext, - nsStyleContext* aStyleContext, - nsStyleContext* aNewParentContext); - - NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext, - nsIContent* aContent, - PRInt32 aStateMask, - PRBool* aResult); - - NS_IMETHOD HasAttributeDependentStyle(nsIPresContext* aPresContext, - nsIContent* aContent, - nsIAtom* aAtribute, - PRInt32 aModType, - PRBool* aResult); - - NS_IMETHOD ConstructRootFrame(nsIPresContext* aPresContext, - nsIContent* aContent, - nsIFrame*& aFrameSubTree); - NS_IMETHOD ReconstructDocElementHierarchy(nsIPresContext* aPresContext); - NS_IMETHOD ContentAppended(nsIPresContext* aPresContext, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer); - NS_IMETHOD ContentInserted(nsIPresContext* aPresContext, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer); - NS_IMETHOD ContentReplaced(nsIPresContext* aPresContext, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer); - NS_IMETHOD ContentRemoved(nsIPresContext* aPresContext, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer); - - NS_IMETHOD ContentChanged(nsIPresContext* aPresContext, - nsIContent* aContent, - nsISupports* aSubContent); - NS_IMETHOD ContentStatesChanged(nsIPresContext* aPresContext, - nsIContent* aContent1, - nsIContent* aContent2, - PRInt32 aStateMask); - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType); - - // Notification that we were unable to render a replaced element. - NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, - nsIFrame* aFrame); - - // Request to create a continuing frame - NS_IMETHOD CreateContinuingFrame(nsIPresContext* aPresContext, - nsIFrame* aFrame, - nsIFrame* aParentFrame, - nsIFrame** aContinuingFrame); - - // Request to find the primary frame associated with a given content object. - // This is typically called by the pres shell when there is no mapping in - // the pres shell hash table - NS_IMETHOD FindPrimaryFrameFor(nsIPresContext* aPresContext, - nsIFrameManager* aFrameManager, - nsIContent* aContent, - nsIFrame** aFrame, - nsFindFrameHint* aHint); - - // Get the XBL insertion point for a child - NS_IMETHOD GetInsertionPoint(nsIPresShell* aPresShell, - nsIFrame* aParentFrame, - nsIContent* aChildContent, - nsIFrame** aInsertionPoint); - - // APIs for registering objects that can supply additional - // rules during processing. - NS_IMETHOD SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier); - NS_IMETHOD GetStyleRuleSupplier(nsIStyleRuleSupplier** aSupplier); - -#ifdef DEBUG - virtual void List(FILE* out = stdout, PRInt32 aIndent = 0); -#endif - virtual void ResetUniqueStyleItems(void); - -#ifdef MOZ_PERF_METRICS - NS_DECL_NSITIMERECORDER -#endif - -private: - static nsrefcnt gInstances; - static nsIURI *gQuirkURI; - - // These are not supported and are not implemented! - StyleSetImpl(const StyleSetImpl& aCopy); - StyleSetImpl& operator=(const StyleSetImpl& aCopy); - -protected: - virtual ~StyleSetImpl(); - PRBool EnsureArray(nsCOMPtr &aArray); - void RecycleArray(nsCOMPtr &aArray); - - void EnsureRuleWalker(nsIPresContext* aPresContext); - - // Returns false on out-of-memory. - PRBool BuildDefaultStyleData(nsIPresContext* aPresContext); - - void ClearRuleProcessors(void); - void ClearAgentRuleProcessors(void); - void ClearUserRuleProcessors(void); - void ClearDocRuleProcessors(void); - void ClearOverrideRuleProcessors(void); - - nsresult GatherRuleProcessors(void); - - void AddImportantRules(nsRuleNode* aCurrLevelNode, nsRuleNode* aLastPrevLevelNode); - - // Enumerate the rules in a way that cares about the order of the - // rules. - void FileRules(nsISupportsArrayEnumFunc aCollectorFunc, - RuleProcessorData* aData); - - // Enumerate all the rules in a way that doesn't care about the order - // of the rules and break out if the enumeration is halted. - void WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, - RuleProcessorData* aData); - - already_AddRefed GetContext(nsIPresContext* aPresContext, - nsStyleContext* aParentContext, - nsIAtom* aPseudoTag); - -#ifdef DEBUG - void List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets); - void ListContexts(nsIFrame* aRootFrame, FILE* out, PRInt32 aIndent); -#endif - - nsCOMPtr mOverrideSheets; // most significant first - nsCOMPtr mDocSheets; // " " - nsCOMPtr mUserSheets; // " " - nsCOMPtr mAgentSheets; // " " - - nsCOMPtr mAgentRuleProcessors; // least significant first - nsCOMPtr mUserRuleProcessors; // " " - nsCOMPtr mDocRuleProcessors; // " " - nsCOMPtr mOverrideRuleProcessors; // " " - - nsCOMPtr mRecycler; - - nsIStyleFrameConstruction* mFrameConstructor; - nsIStyleSheet* mQuirkStyleSheet; // cached instance for enabling/disabling - - nsCOMPtr mStyleRuleSupplier; - - // To be used only in case of emergency, such as being out of memory - // or operating on a deleted rule node. The latter should never - // happen, of course. - nsCachedStyleData mDefaultStyleData; - - nsRuleNode* mRuleTree; // This is the root of our rule tree. It is a lexicographic tree of - // matched rules that style contexts use to look up properties. - nsRuleWalker* mRuleWalker; // This is an instance of a rule walker that can be used - // to navigate through our tree. - - PRBool mInShutdown; - PRInt32 mDestroyedCount; - nsVoidArray mRoots; // style contexts with no parent - - MOZ_TIMER_DECLARE(mStyleResolutionWatch) - -#ifdef MOZ_PERF_METRICS - PRBool mTimerEnabled; // true if timing is enabled, false if disabled -#endif - -}; - -nsrefcnt StyleSetImpl::gInstances = 0; -nsIURI *StyleSetImpl::gQuirkURI = 0; - -StyleSetImpl::StyleSetImpl() - : mFrameConstructor(nsnull), - mQuirkStyleSheet(nsnull), - mRuleTree(nsnull), +nsStyleSet::nsStyleSet() + : mRuleTree(nsnull), mRuleWalker(nsnull), + mDestroyedCount(0), + mBatching(PR_FALSE), mInShutdown(PR_FALSE), - mDestroyedCount(0) -#ifdef MOZ_PERF_METRICS - ,mTimerEnabled(PR_FALSE) -#endif + mDirty(0) { - if (gInstances++ == 0) - { - static const char kQuirk_href[] = "resource://gre/res/quirk.css"; - NS_NewURI (&gQuirkURI, NS_LITERAL_CSTRING(kQuirk_href)); - NS_ASSERTION (gQuirkURI != 0, "Cannot allocate nsStyleSetImpl::gQuirkURI"); - } -} - -StyleSetImpl::~StyleSetImpl() -{ - NS_IF_RELEASE(mFrameConstructor); - NS_IF_RELEASE(mQuirkStyleSheet); - if (--gInstances == 0) - { - NS_IF_RELEASE (gQuirkURI); - } -} - -#ifndef MOZ_PERF_METRICS -NS_IMPL_ISUPPORTS1(StyleSetImpl, nsIStyleSet) -#else -NS_IMPL_ISUPPORTS2(StyleSetImpl, nsIStyleSet, nsITimeRecorder) -#endif - -PRBool StyleSetImpl::EnsureArray(nsCOMPtr &aArray) -{ - if (nsnull == aArray) { - aArray = mRecycler; - mRecycler = nsnull; - if (nsnull == aArray) { - if (NS_OK != NS_NewISupportsArray(getter_AddRefs(aArray))) { - return PR_FALSE; - } - } - } - return PR_TRUE; -} - -void -StyleSetImpl::RecycleArray(nsCOMPtr &aArray) -{ - if (!mRecycler) { - mRecycler = aArray; // take ref - mRecycler->Clear(); - aArray = nsnull; - } - else { // already have a recycled array - aArray = nsnull; - } -} - -void -StyleSetImpl::ClearRuleProcessors(void) -{ - ClearAgentRuleProcessors(); - ClearUserRuleProcessors(); - ClearDocRuleProcessors(); - ClearOverrideRuleProcessors(); -} - -void -StyleSetImpl::ClearAgentRuleProcessors(void) -{ - if (mAgentRuleProcessors) - RecycleArray(mAgentRuleProcessors); -} - -void -StyleSetImpl::ClearUserRuleProcessors(void) -{ - if (mUserRuleProcessors) - RecycleArray(mUserRuleProcessors); -} - -void -StyleSetImpl::ClearDocRuleProcessors(void) -{ - if (mDocRuleProcessors) - RecycleArray(mDocRuleProcessors); -} - -void -StyleSetImpl::ClearOverrideRuleProcessors(void) -{ - if (mOverrideRuleProcessors) - RecycleArray(mOverrideRuleProcessors); -} - -struct RuleProcessorEnumData { - RuleProcessorEnumData(nsISupportsArray* aRuleProcessors) - : mRuleProcessors(aRuleProcessors), - mPrevProcessor(nsnull) - {} - - nsISupportsArray* mRuleProcessors; - nsIStyleRuleProcessor* mPrevProcessor; -}; - -static PRBool -EnumRuleProcessor(nsISupports* aSheet, void* aData) -{ - nsIStyleSheet* sheet = (nsIStyleSheet*)aSheet; - RuleProcessorEnumData* data = (RuleProcessorEnumData*)aData; - - nsIStyleRuleProcessor* processor = nsnull; - nsresult result = sheet->GetStyleRuleProcessor(processor, data->mPrevProcessor); - if (NS_SUCCEEDED(result) && processor) { - if (processor != data->mPrevProcessor) { - data->mRuleProcessors->AppendElement(processor); - data->mPrevProcessor = processor; // ref is held by array - } - NS_RELEASE(processor); - } - return PR_TRUE; } nsresult -StyleSetImpl::GatherRuleProcessors(void) +nsStyleSet::Init(nsIPresContext *aPresContext) { - nsresult result = NS_ERROR_OUT_OF_MEMORY; - if (mAgentSheets && !mAgentRuleProcessors) { - if (EnsureArray(mAgentRuleProcessors)) { - RuleProcessorEnumData data(mAgentRuleProcessors); - mAgentSheets->EnumerateBackwards(EnumRuleProcessor, &data); - PRUint32 count; - mAgentRuleProcessors->Count(&count); - if (0 == count) { - RecycleArray(mAgentRuleProcessors); - } - } else return result; + if (!gQuirkURI) { + static const char kQuirk_href[] = "resource://gre/res/quirk.css"; + NS_NewURI(&gQuirkURI, kQuirk_href); + NS_ENSURE_TRUE(gQuirkURI, NS_ERROR_OUT_OF_MEMORY); } - if (mUserSheets && !mUserRuleProcessors) { - if (EnsureArray(mUserRuleProcessors)) { - RuleProcessorEnumData data(mUserRuleProcessors); - mUserSheets->EnumerateBackwards(EnumRuleProcessor, &data); - PRUint32 count; - mUserRuleProcessors->Count(&count); - if (0 == count) { - RecycleArray(mUserRuleProcessors); - } - } else return result; + if (!BuildDefaultStyleData(aPresContext)) + return NS_ERROR_FAILURE; + + mRuleTree = nsRuleNode::CreateRootNode(aPresContext); + if (!mRuleTree) { + mDefaultStyleData.Destroy(0, aPresContext); + return NS_ERROR_OUT_OF_MEMORY; } - if (mDocSheets && !mDocRuleProcessors) { - if (EnsureArray(mDocRuleProcessors)) { - RuleProcessorEnumData data(mDocRuleProcessors); - mDocSheets->EnumerateBackwards(EnumRuleProcessor, &data); - PRUint32 count; - mDocRuleProcessors->Count(&count); - if (0 == count) { - RecycleArray(mDocRuleProcessors); - } - } else return result; - } - - if (mOverrideSheets && !mOverrideRuleProcessors) { - if (EnsureArray(mOverrideRuleProcessors)) { - RuleProcessorEnumData data(mOverrideRuleProcessors); - mOverrideSheets->EnumerateBackwards(EnumRuleProcessor, &data); - PRUint32 count; - mOverrideRuleProcessors->Count(&count); - if (0 == count) { - RecycleArray(mOverrideRuleProcessors); - } - } else return result; + mRuleWalker = new nsRuleWalker(mRuleTree); + if (!mRuleWalker) { + mRuleTree->Destroy(); + mDefaultStyleData.Destroy(0, aPresContext); + return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; } +struct RuleProcessorEnumData { + RuleProcessorEnumData(nsCOMArray *aRuleProcessors) + : mRuleProcessors(aRuleProcessors), + mPrevProcessor(nsnull) + {} -// ----- Override sheets + nsCOMArray* mRuleProcessors; + nsIStyleRuleProcessor* mPrevProcessor; +}; -void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet) +static PRBool +EnumRuleProcessor(nsIStyleSheet *aSheet, void* aData) { - 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); - ClearOverrideRuleProcessors(); + RuleProcessorEnumData* data = (RuleProcessorEnumData*)aData; + + nsCOMPtr processor; + nsresult result = aSheet->GetStyleRuleProcessor(*getter_AddRefs(processor), + data->mPrevProcessor); + if (NS_SUCCEEDED(result) && processor) { + if (processor != data->mPrevProcessor) { + if (!data->mRuleProcessors->AppendObject(processor)) + return PR_FALSE; + data->mPrevProcessor = processor; // ref is held by array + } } + return PR_TRUE; } -void StyleSetImpl::InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet, - nsIStyleSheet* aAfterSheet) +nsresult +nsStyleSet::GatherRuleProcessors(PRInt32 aType) { - 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); - mOverrideSheets->InsertElementAt(aSheet, ++index); - ClearOverrideRuleProcessors(); + mRuleProcessors[aType].Clear(); + if (mSheets[aType].Count()) { + RuleProcessorEnumData data(&mRuleProcessors[aType]); + if (!mSheets[aType].EnumerateBackwards(EnumRuleProcessor, &data)) + return NS_ERROR_OUT_OF_MEMORY; } + + return NS_OK; } -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"); +#define CHECK_APPLICABLE \ +PR_BEGIN_MACRO \ + PRBool applicable = PR_TRUE; \ + aSheet->GetApplicable(applicable); \ + NS_ASSERTION(applicable, "Inapplicable sheet being placed in style set"); \ +PR_END_MACRO +#else +#define CHECK_APPLICABLE #endif - if (EnsureArray(mOverrideSheets)) { - mOverrideSheets->RemoveElement(aSheet); - PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet); - mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); - ClearOverrideRuleProcessors(); - } + +nsresult +nsStyleSet::AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet) +{ + NS_PRECONDITION(aSheet, "null arg"); + CHECK_APPLICABLE; + mSheets[aType].RemoveObject(aSheet); + if (!mSheets[aType].AppendObject(aSheet)) + return NS_ERROR_OUT_OF_MEMORY; + + if (!mBatching) + return GatherRuleProcessors(aType); + + mDirty |= 1 << aType; + return NS_OK; } -void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet) +nsresult +nsStyleSet::PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet) { - NS_PRECONDITION(nsnull != aSheet, "null arg"); + NS_PRECONDITION(aSheet, "null arg"); + CHECK_APPLICABLE; + mSheets[aType].RemoveObject(aSheet); + if (!mSheets[aType].InsertObjectAt(aSheet, 0)) + return NS_ERROR_OUT_OF_MEMORY; + + if (!mBatching) + return GatherRuleProcessors(aType); + + mDirty |= 1 << aType; + return NS_OK; +} + +nsresult +nsStyleSet::RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet) +{ + NS_PRECONDITION(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(); - } + mSheets[aType].RemoveObject(aSheet); + if (!mBatching) + return GatherRuleProcessors(aType); + + mDirty |= 1 << aType; + return NS_OK; } -PRInt32 StyleSetImpl::GetNumberOfOverrideStyleSheets() +nsresult +nsStyleSet::ReplaceSheets(sheetType aType, + const nsCOMArray &aNewSheets) { - if (nsnull != mOverrideSheets) { - PRUint32 cnt; - nsresult rv = mOverrideSheets->Count(&cnt); - if (NS_FAILED(rv)) return 0; // XXX error? - return cnt; + mSheets[aType].Clear(); + for (PRInt32 i = 0; i < aNewSheets.Count(); ++i) { + if (!mSheets[aType].AppendObject(aNewSheets.ObjectAt(i))) + return NS_ERROR_OUT_OF_MEMORY; } - return 0; -} -nsIStyleSheet* StyleSetImpl::GetOverrideStyleSheetAt(PRInt32 aIndex) -{ - nsIStyleSheet* sheet = nsnull; - if (nsnull != mOverrideSheets) { - sheet = (nsIStyleSheet*)mOverrideSheets->ElementAt(aIndex); - } - return sheet; + if (!mBatching) + return GatherRuleProcessors(aType); + + mDirty |= 1 << aType; + return NS_OK; } // -------- Doc Sheets -void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument) +nsresult +nsStyleSet::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 - PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet); - PRUint32 count; - nsresult rv = mDocSheets->Count(&count); - if (NS_FAILED(rv)) return; // XXX error? - PRUint32 index; - for (index = 0; index < count; index++) { - nsIStyleSheet* sheet = (nsIStyleSheet*)mDocSheets->ElementAt(index); - PRInt32 sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet); - if (sheetDocIndex < newDocIndex) { - mDocSheets->InsertElementAt(aSheet, index); - index = count; // break loop - } - NS_RELEASE(sheet); + CHECK_APPLICABLE; + + nsCOMArray& docSheets = mSheets[eDocSheet]; + + docSheets.RemoveObject(aSheet); + // lowest index last + PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet); + PRInt32 count = docSheets.Count(); + for (PRInt32 index = 0; index < count; index++) { + nsIStyleSheet* sheet = docSheets.ObjectAt(index); + PRInt32 sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet); + if (sheetDocIndex < newDocIndex) { + if (!docSheets.InsertObjectAt(aSheet, index)) + return NS_ERROR_OUT_OF_MEMORY; + + index = count; // break loop } - PRUint32 cnt; - rv = mDocSheets->Count(&cnt); - if (NS_FAILED(rv)) return; // XXX error? - if (cnt == count) { // didn't insert it - mDocSheets->AppendElement(aSheet); + } + if (docSheets.Count() == count) { // didn't insert it + if (!docSheets.AppendObject(aSheet)) + return NS_ERROR_OUT_OF_MEMORY; + } + if (!mBatching) + return GatherRuleProcessors(eDocSheet); + + mDirty |= 1 << eDocSheet; + return NS_OK; +} + +#undef CHECK_APPLICABLE + +// Batching +void +nsStyleSet::BeginUpdate() +{ + mBatching = 1; +} + +nsresult +nsStyleSet::EndUpdate() +{ + for (int i = 0; i < eSheetTypeCount; ++i) { + if (mDirty & 1 << i) { + nsresult rv = GatherRuleProcessors(i); + NS_ENSURE_SUCCESS(rv, rv); } - - if (nsnull == mFrameConstructor) { - CallQueryInterface(aSheet, &mFrameConstructor); - } - ClearDocRuleProcessors(); } -} -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(); - } -} - -PRInt32 StyleSetImpl::GetNumberOfDocStyleSheets() -{ - if (nsnull != mDocSheets) { - PRUint32 cnt; - nsresult rv = mDocSheets->Count(&cnt); - if (NS_FAILED(rv)) return 0; // XXX error? - return cnt; - } - return 0; -} - -nsIStyleSheet* StyleSetImpl::GetDocStyleSheetAt(PRInt32 aIndex) -{ - nsIStyleSheet* sheet = nsnull; - if (nsnull != mDocSheets) { - sheet = (nsIStyleSheet*)mDocSheets->ElementAt(aIndex); - } - return sheet; -} - -// ------ user sheets - -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); - ClearUserRuleProcessors(); - } -} - -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); - mUserSheets->InsertElementAt(aSheet, ++index); - ClearUserRuleProcessors(); - } -} - -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); - mUserSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); - ClearUserRuleProcessors(); - } -} - -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(); - } -} - -PRInt32 StyleSetImpl::GetNumberOfUserStyleSheets() -{ - if (nsnull != mUserSheets) { - PRUint32 cnt; - nsresult rv = mUserSheets->Count(&cnt); - if (NS_FAILED(rv)) return 0; // XXX error? - return cnt; - } - return 0; -} - -nsIStyleSheet* StyleSetImpl::GetUserStyleSheetAt(PRInt32 aIndex) -{ - nsIStyleSheet* sheet = nsnull; - if (nsnull != mUserSheets) { - sheet = (nsIStyleSheet*)mUserSheets->ElementAt(aIndex); - } - return sheet; + mDirty = 0; + mBatching = 0; + return NS_OK; } void -StyleSetImpl::ReplaceUserStyleSheets(nsISupportsArray* aNewUserSheets) +nsStyleSet::EnableQuirkStyleSheet(PRBool aEnable) { - ClearUserRuleProcessors(); - mUserSheets = aNewUserSheets; -} - -// ------ agent sheets - -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); - ClearAgentRuleProcessors(); - } -} - -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); - mAgentSheets->InsertElementAt(aSheet, ++index); - ClearAgentRuleProcessors(); - } -} - -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); - mAgentSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); - ClearAgentRuleProcessors(); - } -} - -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(); - } -} - -PRInt32 StyleSetImpl::GetNumberOfAgentStyleSheets() -{ - if (nsnull != mAgentSheets) { - PRUint32 cnt; - nsresult rv = mAgentSheets->Count(&cnt); - if (NS_FAILED(rv)) return 0; // XXX error? - return cnt; - } - return 0; -} - -NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable) -{ - nsresult rv = NS_OK; - if (nsnull == mQuirkStyleSheet) { + if (!mQuirkStyleSheet) { // first find the quirk sheet: // - run through all of the agent sheets and check for a CSSStyleSheet that // has the URL we want - PRUint32 i, nSheets = GetNumberOfAgentStyleSheets(); - for (i=0; i< nSheets; i++) { - nsCOMPtr sheet; - sheet = getter_AddRefs(GetAgentStyleSheetAt(i)); - if (sheet) { - nsCOMPtr cssSheet = do_QueryInterface(sheet); - if (cssSheet) { - nsCOMPtr quirkSheet; - PRBool bHasSheet = PR_FALSE; - NS_ASSERTION(gQuirkURI != nsnull, "StyleSetImpl::gQuirkStyleSet is not initialized!"); - if (gQuirkURI != nsnull - && NS_SUCCEEDED(cssSheet->ContainsStyleSheet(gQuirkURI, bHasSheet, - getter_AddRefs(quirkSheet))) - && bHasSheet) { - NS_ASSERTION(quirkSheet, "QuirkSheet must be set: ContainsStyleSheet is hosed"); - // cache the sheet for faster lookup next time - mQuirkStyleSheet = quirkSheet.get(); - // addref for our cached reference - NS_ADDREF(mQuirkStyleSheet); - // only one quirk style sheet can exist, so stop looking - break; - } - } + PRInt32 nSheets = mSheets[eAgentSheet].Count(); + for (PRInt32 i = 0; i < nSheets; ++i) { + nsIStyleSheet *sheet = mSheets[eAgentSheet].ObjectAt(i); + NS_ASSERTION(sheet, "mAgentSheets should not contain null sheets"); + + nsICSSStyleSheet *cssSheet = NS_STATIC_CAST(nsICSSStyleSheet*, sheet); + NS_ASSERTION(nsCOMPtr(do_QueryInterface(sheet)) == cssSheet, + "Agent sheet must be a CSSStyleSheet"); + + nsCOMPtr quirkSheet; + PRBool bHasSheet = PR_FALSE; + if (NS_SUCCEEDED(cssSheet->ContainsStyleSheet(gQuirkURI, bHasSheet, + getter_AddRefs(quirkSheet))) + && bHasSheet) { + NS_ASSERTION(quirkSheet, "QuirkSheet must be set: ContainsStyleSheet is hosed"); + // cache the sheet for faster lookup next time + mQuirkStyleSheet = quirkSheet; + // only one quirk style sheet can exist, so stop looking + break; } } } NS_ASSERTION(mQuirkStyleSheet, "no quirk stylesheet"); if (mQuirkStyleSheet) { -#if defined(DEBUG_warren) || defined(DEBUG_attinasi) - printf( "%s Quirk StyleSheet\n", aEnable ? "Enabling" : "Disabling" ); -#endif #ifdef DEBUG_dbaron_off // XXX Make this |DEBUG| once it stops firing. - PRUint32 count = 0; - if (mAgentRuleProcessors) - mAgentRuleProcessors->Count(&count); + PRInt32 count = mRuleProcessors[eAgentSheet].Count() PRBool applicableNow; mQuirkStyleSheet->GetApplicable(applicableNow); NS_ASSERTION(count == 0 || aEnable == applicableNow, @@ -929,34 +308,8 @@ NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable) #endif mQuirkStyleSheet->SetEnabled(aEnable); } - return rv; } -nsIStyleSheet* StyleSetImpl::GetAgentStyleSheetAt(PRInt32 aIndex) -{ - nsIStyleSheet* sheet = nsnull; - if (nsnull != mAgentSheets) { - sheet = (nsIStyleSheet*)mAgentSheets->ElementAt(aIndex); - } - return sheet; -} - -void -StyleSetImpl::ReplaceAgentStyleSheets(nsISupportsArray* aNewAgentSheets) -{ - ClearAgentRuleProcessors(); - mAgentSheets = aNewAgentSheets; -} - -NS_IMETHODIMP -StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aApplicable) -{ - ClearRuleProcessors(); - GatherRuleProcessors(); - return NS_OK; -} - - struct RulesMatchingData : public ElementRuleProcessorData { RulesMatchingData(nsIPresContext* aPresContext, nsIAtom* aMedium, @@ -970,12 +323,11 @@ struct RulesMatchingData : public ElementRuleProcessorData { }; static PRBool -EnumRulesMatching(nsISupports* aProcessor, void* aData) +EnumRulesMatching(nsIStyleRuleProcessor* aProcessor, void* aData) { - nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor; RulesMatchingData* data = (RulesMatchingData*)aData; - processor->RulesMatching(data, data->mMedium); + aProcessor->RulesMatching(data, data->mMedium); return PR_TRUE; } @@ -986,9 +338,9 @@ EnumRulesMatching(nsISupports* aProcessor, void* aData) * |aParentContext| could itself be a shared context.) */ already_AddRefed -StyleSetImpl::GetContext(nsIPresContext* aPresContext, - nsStyleContext* aParentContext, - nsIAtom* aPseudoTag) +nsStyleSet::GetContext(nsIPresContext* aPresContext, + nsStyleContext* aParentContext, + nsIAtom* aPseudoTag) { nsStyleContext* result = nsnull; nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode(); @@ -1014,8 +366,8 @@ StyleSetImpl::GetContext(nsIPresContext* aPresContext, } void -StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode, - nsRuleNode* aLastPrevLevelNode) +nsStyleSet::AddImportantRules(nsRuleNode* aCurrLevelNode, + nsRuleNode* aLastPrevLevelNode) { if (!aCurrLevelNode || aCurrLevelNode == aLastPrevLevelNode) return; @@ -1033,8 +385,8 @@ StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode, // Enumerate the rules in a way that cares about the order of the rules. void -StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc, - RuleProcessorData* aData) +nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc, + RuleProcessorData* aData) { // Cascading order: @@ -1050,14 +402,14 @@ StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc, // [most important] nsRuleNode* lastAgentRN = nsnull; - if (mAgentRuleProcessors) { - mAgentRuleProcessors->EnumerateForwards(aCollectorFunc, aData); + if (mRuleProcessors[eAgentSheet].Count()) { + mRuleProcessors[eAgentSheet].EnumerateForwards(aCollectorFunc, aData); lastAgentRN = mRuleWalker->GetCurrentNode(); } nsRuleNode* lastUserRN = lastAgentRN; - if (mUserRuleProcessors) { - mUserRuleProcessors->EnumerateForwards(aCollectorFunc, aData); + if (mRuleProcessors[eUserSheet].Count()) { + mRuleProcessors[eUserSheet].EnumerateForwards(aCollectorFunc, aData); lastUserRN = mRuleWalker->GetCurrentNode(); } @@ -1068,14 +420,14 @@ StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc, mStyleRuleSupplier->WalkRules(this, aCollectorFunc, aData); mStyleRuleSupplier->UseDocumentRules(aData->mContent, &useRuleProcessors); } - if (mDocRuleProcessors && useRuleProcessors) { - mDocRuleProcessors->EnumerateForwards(aCollectorFunc, aData); + if (mRuleProcessors[eDocSheet].Count()) { + mRuleProcessors[eDocSheet].EnumerateForwards(aCollectorFunc, aData); } lastDocRN = mRuleWalker->GetCurrentNode(); nsRuleNode* lastOvrRN = lastDocRN; - if (mOverrideRuleProcessors) { - mOverrideRuleProcessors->EnumerateForwards(aCollectorFunc, aData); + if (mRuleProcessors[eOverrideSheet].Count()) { + mRuleProcessors[eOverrideSheet].EnumerateForwards(aCollectorFunc, aData); lastOvrRN = mRuleWalker->GetCurrentNode(); } @@ -1089,18 +441,18 @@ StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc, // Enumerate all the rules in a way that doesn't care about the order // of the rules and break out if the enumeration is halted. void -StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, - RuleProcessorData* aData) +nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc, + RuleProcessorData* aData) { // Walk the agent rules first. - if (mAgentRuleProcessors) - if (!mAgentRuleProcessors->EnumerateForwards(aFunc, aData)) - return; + if (mRuleProcessors[eAgentSheet].Count() && + !mRuleProcessors[eAgentSheet].EnumerateForwards(aFunc, aData)) + return; // Walk the user rules next. - if (mUserRuleProcessors) - if (!mUserRuleProcessors->EnumerateForwards(aFunc, aData)) - return; + if (mRuleProcessors[eUserSheet].Count() && + !mRuleProcessors[eUserSheet].EnumerateForwards(aFunc, aData)) + return; PRBool useRuleProcessors = PR_TRUE; if (mStyleRuleSupplier) { @@ -1111,32 +463,16 @@ StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, } // Now walk the doc rules. - if (mDocRuleProcessors && useRuleProcessors) - if (!mDocRuleProcessors->EnumerateForwards(aFunc, aData)) - return; + if (mRuleProcessors[eDocSheet].Count() && useRuleProcessors && + !mRuleProcessors[eDocSheet].EnumerateForwards(aFunc, aData)) + return; // Walk the override rules last. - if (mOverrideRuleProcessors) - mOverrideRuleProcessors->EnumerateForwards(aFunc, aData); + if (mRuleProcessors[eOverrideSheet].Count()) + mRuleProcessors[eOverrideSheet].EnumerateForwards(aFunc, aData); } -void StyleSetImpl::EnsureRuleWalker(nsIPresContext* aPresContext) -{ - if (mRuleWalker) - return; - - if (!mDefaultStyleData.mResetData && !BuildDefaultStyleData(aPresContext)) { - mDefaultStyleData.Destroy(0, aPresContext); - return; - } - - mRuleTree = nsRuleNode::CreateRootNode(aPresContext); - if (!mRuleTree) - return; - mRuleWalker = new nsRuleWalker(mRuleTree); -} - -PRBool StyleSetImpl::BuildDefaultStyleData(nsIPresContext* aPresContext) +PRBool nsStyleSet::BuildDefaultStyleData(nsIPresContext* aPresContext) { NS_ASSERTION(!mDefaultStyleData.mResetData && !mDefaultStyleData.mInheritedData, @@ -1170,13 +506,10 @@ PRBool StyleSetImpl::BuildDefaultStyleData(nsIPresContext* aPresContext) } already_AddRefed -StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext, - nsIContent* aContent, - nsStyleContext* aParentContext) +nsStyleSet::ResolveStyleFor(nsIPresContext* aPresContext, + nsIContent* aContent, + nsStyleContext* aParentContext) { - MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolveStyleFor(), this=%p\n", this)); - STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION); - nsStyleContext* result = nsnull; NS_ASSERTION(aContent, "must have content"); @@ -1185,56 +518,43 @@ StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext, "content must be element"); if (aContent && aPresContext) { - GatherRuleProcessors(); - if (mAgentRuleProcessors || - mUserRuleProcessors || - mDocRuleProcessors || - mOverrideRuleProcessors) { - EnsureRuleWalker(aPresContext); - NS_ENSURE_TRUE(mRuleWalker, nsnull); + if (mRuleProcessors[eAgentSheet].Count() || + mRuleProcessors[eUserSheet].Count() || + mRuleProcessors[eDocSheet].Count() || + mRuleProcessors[eOverrideSheet].Count()) { nsCOMPtr medium; aPresContext->GetMedium(getter_AddRefs(medium)); RulesMatchingData data(aPresContext, medium, aContent, mRuleWalker); FileRules(EnumRulesMatching, &data); result = GetContext(aPresContext, aParentContext, nsnull).get(); - + // Now reset the walker back to the root of the tree. mRuleWalker->Reset(); } } - MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolveStyleFor(), this=%p\n", this)); - STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION); return result; } already_AddRefed -StyleSetImpl::ResolveStyleForNonElement(nsIPresContext* aPresContext, - nsStyleContext* aParentContext) +nsStyleSet::ResolveStyleForNonElement(nsIPresContext* aPresContext, + nsStyleContext* aParentContext) { - MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this)); - STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION); - nsStyleContext* result = nsnull; NS_ASSERTION(aPresContext, "must have pres context"); if (aPresContext) { - GatherRuleProcessors(); - if (mAgentRuleProcessors || - mUserRuleProcessors || - mDocRuleProcessors || - mOverrideRuleProcessors) { - EnsureRuleWalker(aPresContext); - NS_ENSURE_TRUE(mRuleWalker, nsnull); + if (mRuleProcessors[eAgentSheet].Count() || + mRuleProcessors[eUserSheet].Count() || + mRuleProcessors[eDocSheet].Count() || + mRuleProcessors[eOverrideSheet].Count()) { result = GetContext(aPresContext, aParentContext, nsCSSAnonBoxes::mozNonElement).get(); NS_ASSERTION(mRuleWalker->AtRoot(), "rule walker must be at root"); } } - MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this)); - STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION); return result; } @@ -1246,8 +566,8 @@ struct PseudoRulesMatchingData : public PseudoRuleProcessorData { nsIAtom* aPseudoTag, nsICSSPseudoComparator* aComparator, nsRuleWalker* aRuleWalker) - : PseudoRuleProcessorData(aPresContext, aParentContent, aPseudoTag, aComparator, - aRuleWalker), + : PseudoRuleProcessorData(aPresContext, aParentContent, aPseudoTag, + aComparator, aRuleWalker), mMedium(aMedium) { } @@ -1255,25 +575,21 @@ struct PseudoRulesMatchingData : public PseudoRuleProcessorData { }; static PRBool -EnumPseudoRulesMatching(nsISupports* aProcessor, void* aData) +EnumPseudoRulesMatching(nsIStyleRuleProcessor* aProcessor, void* aData) { - nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor; PseudoRulesMatchingData* data = (PseudoRulesMatchingData*)aData; - processor->RulesMatching(data, data->mMedium); + aProcessor->RulesMatching(data, data->mMedium); return PR_TRUE; } already_AddRefed -StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContext, - nsIContent* aParentContent, - nsIAtom* aPseudoTag, - nsStyleContext* aParentContext, - nsICSSPseudoComparator* aComparator) +nsStyleSet::ResolvePseudoStyleFor(nsIPresContext* aPresContext, + nsIContent* aParentContent, + nsIAtom* aPseudoTag, + nsStyleContext* aParentContext, + nsICSSPseudoComparator* aComparator) { - MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolvePseudoStyleFor(), this=%p\n", this)); - STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION); - nsStyleContext* result = nsnull; NS_ASSERTION(aPseudoTag, "must have pseudo tag"); @@ -1283,40 +599,32 @@ StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContext, "content (if non-null) must be element"); if (aPseudoTag && aPresContext) { - GatherRuleProcessors(); - if (mAgentRuleProcessors || - mUserRuleProcessors || - mDocRuleProcessors || - mOverrideRuleProcessors) { + if (mRuleProcessors[eAgentSheet].Count() || + mRuleProcessors[eUserSheet].Count() || + mRuleProcessors[eDocSheet].Count() || + mRuleProcessors[eOverrideSheet].Count()) { nsCOMPtr medium; aPresContext->GetMedium(getter_AddRefs(medium)); - EnsureRuleWalker(aPresContext); - NS_ENSURE_TRUE(mRuleWalker, nsnull); PseudoRulesMatchingData data(aPresContext, medium, aParentContent, aPseudoTag, aComparator, mRuleWalker); FileRules(EnumPseudoRulesMatching, &data); result = GetContext(aPresContext, aParentContext, aPseudoTag).get(); - + // Now reset the walker back to the root of the tree. mRuleWalker->Reset(); } } - MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolvePseudoStyleFor(), this=%p\n", this)); - STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION); return result; } already_AddRefed -StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext, +nsStyleSet::ProbePseudoStyleFor(nsIPresContext* aPresContext, nsIContent* aParentContent, nsIAtom* aPseudoTag, nsStyleContext* aParentContext) { - MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ProbePseudoStyleFor(), this=%p\n", this)); - STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION); - nsStyleContext* result = nsnull; NS_ASSERTION(aPseudoTag, "must have pseudo tag"); @@ -1326,22 +634,19 @@ StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext, "content (if non-null) must be element"); if (aPseudoTag && aPresContext) { - GatherRuleProcessors(); - if (mAgentRuleProcessors || - mUserRuleProcessors || - mDocRuleProcessors || - mOverrideRuleProcessors) { + if (mRuleProcessors[eAgentSheet].Count() || + mRuleProcessors[eUserSheet].Count() || + mRuleProcessors[eDocSheet].Count() || + mRuleProcessors[eOverrideSheet].Count()) { nsCOMPtr medium; aPresContext->GetMedium(getter_AddRefs(medium)); - EnsureRuleWalker(aPresContext); - NS_ENSURE_TRUE(mRuleWalker, nsnull); PseudoRulesMatchingData data(aPresContext, medium, aParentContent, aPseudoTag, nsnull, mRuleWalker); FileRules(EnumPseudoRulesMatching, &data); if (!mRuleWalker->AtRoot()) result = GetContext(aPresContext, aParentContext, aPseudoTag).get(); - + // Now reset the walker back to the root of the tree. mRuleWalker->Reset(); } @@ -1363,50 +668,36 @@ StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext, } } - MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ProbePseudoStyleFor(), this=%p\n", this)); - STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION); return result; } -PRBool PR_CALLBACK DeleteRuleNodeLists(nsHashKey* aKey, void* aData, void* aClosure) +void +nsStyleSet::BeginShutdown(nsIPresContext* aPresContext) { - nsRuleNodeList* ruleNodeList = (nsRuleNodeList*)aData; - ruleNodeList->Destroy(); - return PR_TRUE; -} - -NS_IMETHODIMP -StyleSetImpl::BeginShutdown(nsIPresContext* aPresContext) -{ - mInShutdown = PR_TRUE; + mInShutdown = 1; mRoots.Clear(); // no longer valid, since we won't keep it up to date - return NS_OK; } -NS_IMETHODIMP -StyleSetImpl::Shutdown(nsIPresContext* aPresContext) +void +nsStyleSet::Shutdown(nsIPresContext* aPresContext) { delete mRuleWalker; mRuleWalker = nsnull; - if (mRuleTree) - { - mRuleTree->Destroy(); - mRuleTree = nsnull; - } + + mRuleTree->Destroy(); + mRuleTree = nsnull; mDefaultStyleData.Destroy(0, aPresContext); - - return NS_OK; } static const PRInt32 kGCInterval = 1000; -NS_IMETHODIMP -StyleSetImpl::NotifyStyleContextDestroyed(nsIPresContext* aPresContext, - nsStyleContext* aStyleContext) +void +nsStyleSet::NotifyStyleContextDestroyed(nsIPresContext* aPresContext, + nsStyleContext* aStyleContext) { if (mInShutdown) - return NS_OK; + return; if (!aStyleContext->GetParent()) { mRoots.RemoveElement(aStyleContext); @@ -1424,48 +715,47 @@ StyleSetImpl::NotifyStyleContextDestroyed(nsIPresContext* aPresContext, } // Sweep the rule tree. - if (mRuleTree->Sweep()) { - // On the rare occasion that we have no style contexts, the root - // will be destroyed, so delete it. - mRuleTree = nsnull; - delete mRuleWalker; - mRuleWalker = nsnull; - } + NS_ASSERTION(mRuleWalker->AtRoot(), "Rule walker should be at root"); +#ifdef DEBUG + PRBool deleted = +#endif + mRuleTree->Sweep(); + + NS_ASSERTION(deleted, "Root not must not be gc'd"); } - - return NS_OK; } -nsresult -StyleSetImpl::GetRuleTree(nsRuleNode** aResult) +void +nsStyleSet::ClearStyleData(nsIPresContext* aPresContext) { - *aResult = mRuleTree; - return NS_OK; -} - -nsCachedStyleData* -StyleSetImpl::GetDefaultStyleData() -{ - return &mDefaultStyleData; -} - -nsresult -StyleSetImpl::ClearStyleData(nsIPresContext* aPresContext) -{ - if (mRuleTree) - mRuleTree->ClearStyleData(); + mRuleTree->ClearStyleData(); for (PRInt32 i = mRoots.Count() - 1; i >= 0; --i) { NS_STATIC_CAST(nsStyleContext*,mRoots[i])->ClearStyleData(aPresContext); } +} - return NS_OK; +nsresult +nsStyleSet::StyleSheetApplicableStateChanged() +{ + nsresult rv = NS_OK; + + for (PRInt32 i = 0; i < eSheetTypeCount; ++i) { + if (!mBatching) { + rv = GatherRuleProcessors(i); + NS_ENSURE_SUCCESS(rv, rv); + } else { + mDirty |= 1 << i; + } + } + + return rv; } already_AddRefed -StyleSetImpl::ReParentStyleContext(nsIPresContext* aPresContext, - nsStyleContext* aStyleContext, - nsStyleContext* aNewParentContext) +nsStyleSet::ReParentStyleContext(nsIPresContext* aPresContext, + nsStyleContext* aStyleContext, + nsStyleContext* aNewParentContext) { NS_ASSERTION(aPresContext, "must have pres context"); NS_ASSERTION(aStyleContext, "must have style context"); @@ -1479,8 +769,6 @@ StyleSetImpl::ReParentStyleContext(nsIPresContext* aPresContext, nsIAtom* pseudoTag = aStyleContext->GetPseudoType(); nsRuleNode* ruleNode = aStyleContext->GetRuleNode(); - EnsureRuleWalker(aPresContext); - NS_ENSURE_TRUE(mRuleWalker, nsnull); mRuleWalker->SetCurrentNode(ruleNode); already_AddRefed result = @@ -1503,15 +791,15 @@ struct StatefulData : public StateRuleProcessorData { PRBool mHasStyle; }; -static PRBool SheetHasStatefulStyle(nsISupports* aProcessor, void *aData) +static PRBool SheetHasStatefulStyle(nsIStyleRuleProcessor* aProcessor, + void *aData) { - nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor; StatefulData* data = (StatefulData*)aData; PRBool hasStyle; - processor->HasStateDependentStyle(data, data->mMedium, &hasStyle); + aProcessor->HasStateDependentStyle(data, data->mMedium, &hasStyle); if (hasStyle) { data->mHasStyle = PR_TRUE; - // Stop iteration. Note that StyleSetImpl::WalkRuleProcessors uses + // Stop iteration. Note that nsStyleSet::WalkRuleProcessors uses // this to stop its own iteration in some cases, but not all (the // style rule supplier case). Since this optimization is only for // the case where we have a lot more work to do, it's not worth the @@ -1522,29 +810,26 @@ static PRBool SheetHasStatefulStyle(nsISupports* aProcessor, void *aData) } // Test if style is dependent on content state -NS_IMETHODIMP -StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext, - nsIContent* aContent, - PRInt32 aStateMask, - PRBool* aResult) +PRBool +nsStyleSet::HasStateDependentStyle(nsIPresContext* aPresContext, + nsIContent* aContent, + PRInt32 aStateMask) { - GatherRuleProcessors(); + PRBool result = PR_FALSE; if (aContent->IsContentOfType(nsIContent::eELEMENT) && - (mAgentRuleProcessors || - mUserRuleProcessors || - mDocRuleProcessors || - mOverrideRuleProcessors)) { + (mRuleProcessors[eAgentSheet].Count() || + mRuleProcessors[eUserSheet].Count() || + mRuleProcessors[eDocSheet].Count() || + mRuleProcessors[eOverrideSheet].Count())) { nsCOMPtr medium; aPresContext->GetMedium(getter_AddRefs(medium)); StatefulData data(aPresContext, medium, aContent, aStateMask); WalkRuleProcessors(SheetHasStatefulStyle, &data); - *aResult = data.mHasStyle; - } else { - *aResult = PR_FALSE; + result = data.mHasStyle; } - return NS_OK; + return result; } struct AttributeData : public AttributeRuleProcessorData { @@ -1558,15 +843,15 @@ struct AttributeData : public AttributeRuleProcessorData { PRBool mHasStyle; }; -static PRBool SheetHasAttributeStyle(nsISupports* aProcessor, void *aData) +static PRBool +SheetHasAttributeStyle(nsIStyleRuleProcessor* aProcessor, void *aData) { - nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor; AttributeData* data = (AttributeData*)aData; PRBool hasStyle; - processor->HasAttributeDependentStyle(data, data->mMedium, &hasStyle); + aProcessor->HasAttributeDependentStyle(data, data->mMedium, &hasStyle); if (hasStyle) { data->mHasStyle = PR_TRUE; - // Stop iteration. Note that StyleSetImpl::WalkRuleProcessors uses + // Stop iteration. Note that nsStyleSet::WalkRuleProcessors uses // this to stop its own iteration in some cases, but not all (the // style rule supplier case). Since this optimization is only for // the case where we have a lot more work to do, it's not worth the @@ -1577,355 +862,25 @@ static PRBool SheetHasAttributeStyle(nsISupports* aProcessor, void *aData) } // Test if style is dependent on content state -NS_IMETHODIMP -StyleSetImpl::HasAttributeDependentStyle(nsIPresContext* aPresContext, - nsIContent* aContent, - nsIAtom* aAttribute, - PRInt32 aModType, - PRBool* aResult) +PRBool +nsStyleSet::HasAttributeDependentStyle(nsIPresContext* aPresContext, + nsIContent* aContent, + nsIAtom* aAttribute, + PRInt32 aModType) { - GatherRuleProcessors(); + PRBool result = PR_FALSE; if (aContent->IsContentOfType(nsIContent::eELEMENT) && - (mAgentRuleProcessors || - mUserRuleProcessors || - mDocRuleProcessors || - mOverrideRuleProcessors)) { + (mRuleProcessors[eAgentSheet].Count() || + mRuleProcessors[eUserSheet].Count() || + mRuleProcessors[eDocSheet].Count() || + mRuleProcessors[eOverrideSheet].Count())) { nsCOMPtr medium; aPresContext->GetMedium(getter_AddRefs(medium)); AttributeData data(aPresContext, medium, aContent, aAttribute, aModType); WalkRuleProcessors(SheetHasAttributeStyle, &data); - *aResult = data.mHasStyle; - } else { - *aResult = PR_FALSE; + result = data.mHasStyle; } - return NS_OK; -} - - -NS_IMETHODIMP StyleSetImpl::ConstructRootFrame(nsIPresContext* aPresContext, - nsIContent* aDocElement, - nsIFrame*& aFrameSubTree) -{ - return mFrameConstructor->ConstructRootFrame(aPresContext->PresShell(), - aPresContext, aDocElement, - aFrameSubTree); -} - -NS_IMETHODIMP -StyleSetImpl::ReconstructDocElementHierarchy(nsIPresContext* aPresContext) -{ - return mFrameConstructor->ReconstructDocElementHierarchy(aPresContext); -} - -NS_IMETHODIMP StyleSetImpl::ContentAppended(nsIPresContext* aPresContext, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) -{ - return mFrameConstructor->ContentAppended(aPresContext, - aContainer, aNewIndexInContainer); -} - -NS_IMETHODIMP StyleSetImpl::ContentInserted(nsIPresContext* aPresContext, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - return mFrameConstructor->ContentInserted(aPresContext, aContainer, nsnull, - aChild, aIndexInContainer, - nsnull, PR_FALSE); -} - -NS_IMETHODIMP StyleSetImpl::ContentReplaced(nsIPresContext* aPresContext, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) -{ - return mFrameConstructor->ContentReplaced(aPresContext, aContainer, - aOldChild, aNewChild, aIndexInContainer); -} - -NS_IMETHODIMP StyleSetImpl::ContentRemoved(nsIPresContext* aPresContext, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - return mFrameConstructor->ContentRemoved(aPresContext, aContainer, - aChild, aIndexInContainer, PR_FALSE); -} - -NS_IMETHODIMP -StyleSetImpl::ContentChanged(nsIPresContext* aPresContext, - nsIContent* aContent, - nsISupports* aSubContent) -{ - return mFrameConstructor->ContentChanged(aPresContext, - aContent, aSubContent); -} - -NS_IMETHODIMP -StyleSetImpl::ContentStatesChanged(nsIPresContext* aPresContext, - nsIContent* aContent1, - nsIContent* aContent2, - PRInt32 aStateMask) -{ - return mFrameConstructor->ContentStatesChanged(aPresContext, aContent1, - aContent2, aStateMask); -} - - -NS_IMETHODIMP -StyleSetImpl::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType) -{ - return mFrameConstructor->AttributeChanged(aPresContext, aContent, - aNameSpaceID, aAttribute, - aModType); -} - -NS_IMETHODIMP -StyleSetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, - nsIFrame* aFrame) -{ - return mFrameConstructor-> - CantRenderReplacedElement(aPresContext->PresShell(), aPresContext, aFrame); -} - -NS_IMETHODIMP -StyleSetImpl::CreateContinuingFrame(nsIPresContext* aPresContext, - nsIFrame* aFrame, - nsIFrame* aParentFrame, - nsIFrame** aContinuingFrame) -{ - return mFrameConstructor->CreateContinuingFrame(aPresContext->PresShell(), - aPresContext, aFrame, - aParentFrame, - aContinuingFrame); -} - -// Request to find the primary frame associated with a given content object. -// This is typically called by the pres shell when there is no mapping in -// the pres shell hash table -NS_IMETHODIMP -StyleSetImpl::FindPrimaryFrameFor(nsIPresContext* aPresContext, - nsIFrameManager* aFrameManager, - nsIContent* aContent, - nsIFrame** aFrame, - nsFindFrameHint* aHint) -{ - return mFrameConstructor->FindPrimaryFrameFor(aPresContext, aFrameManager, - aContent, aFrame, aHint); -} - -NS_IMETHODIMP -StyleSetImpl::GetInsertionPoint(nsIPresShell* aPresShell, - nsIFrame* aParentFrame, - nsIContent* aChildContent, - nsIFrame** aInsertionPoint) -{ - return mFrameConstructor->GetInsertionPoint(aPresShell, aParentFrame, - aChildContent, aInsertionPoint); -} - -#ifdef DEBUG -void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets) -{ - PRUint32 cnt = 0; - if (aSheets) { - nsresult rv = aSheets->Count(&cnt); - if (NS_FAILED(rv)) return; // XXX error? - } - - for (PRInt32 index = 0; index < (PRInt32)cnt; index++) { - nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index); - sheet->List(out, aIndent); - fputs("\n", out); - NS_RELEASE(sheet); - } -} -#endif - -// APIs for registering objects that can supply additional -// rules during processing. -NS_IMETHODIMP -StyleSetImpl::SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier) -{ - mStyleRuleSupplier = aSupplier; - return NS_OK; -} - -NS_IMETHODIMP -StyleSetImpl::GetStyleRuleSupplier(nsIStyleRuleSupplier** aSupplier) -{ - *aSupplier = mStyleRuleSupplier; - NS_IF_ADDREF(*aSupplier); - return NS_OK; -} - - -#ifdef DEBUG -void StyleSetImpl::List(FILE* out, PRInt32 aIndent) -{ -// List(out, aIndent, mOverrideSheets); - List(out, aIndent, mDocSheets); -// List(out, aIndent, mUserSheets); -// List(out, aIndent, mAgentSheets); -} - - -void StyleSetImpl::ListContexts(nsIFrame* aRootFrame, FILE* out, PRInt32 aIndent) -{ - nsStyleContext* sc = aRootFrame->GetStyleContext(); - if (sc) - sc->List(out, aIndent); -} -#endif - - -nsresult -NS_NewStyleSet(nsIStyleSet** aInstancePtrResult) -{ - StyleSetImpl *it = new StyleSetImpl(); - if (!it) - return NS_ERROR_OUT_OF_MEMORY; - - return CallQueryInterface(it, aInstancePtrResult); -} - -// nsITimeRecorder implementation - -#ifdef MOZ_PERF_METRICS - -NS_IMETHODIMP -StyleSetImpl::EnableTimer(PRUint32 aTimerID) -{ - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - mTimerEnabled = PR_TRUE; - } - else - rv = NS_ERROR_NOT_IMPLEMENTED; - - return rv; -} - -NS_IMETHODIMP -StyleSetImpl::DisableTimer(PRUint32 aTimerID) -{ - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - mTimerEnabled = PR_FALSE; - } - else - rv = NS_ERROR_NOT_IMPLEMENTED; - - return rv; -} - -NS_IMETHODIMP -StyleSetImpl::IsTimerEnabled(PRBool *aIsEnabled, PRUint32 aTimerID) -{ - NS_ASSERTION(aIsEnabled, "aIsEnabled parameter cannot be null" ); - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - if (*aIsEnabled) { - *aIsEnabled = mTimerEnabled; - } - } - else { - rv = NS_ERROR_NOT_IMPLEMENTED; - } - - return rv; -} - -NS_IMETHODIMP -StyleSetImpl::ResetTimer(PRUint32 aTimerID) -{ - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - MOZ_TIMER_RESET(mStyleResolutionWatch); - } - else - rv = NS_ERROR_NOT_IMPLEMENTED; - - return rv; -} - -NS_IMETHODIMP -StyleSetImpl::StartTimer(PRUint32 aTimerID) -{ - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - // only do it if enabled - if (mTimerEnabled) { - MOZ_TIMER_START(mStyleResolutionWatch); - } else { -#ifdef NOISY_DEBUG - printf( "Attempt to start timer while disabled - ignoring\n" ); -#endif - } - } - else - rv = NS_ERROR_NOT_IMPLEMENTED; - - return rv; -} - -NS_IMETHODIMP -StyleSetImpl::StopTimer(PRUint32 aTimerID) -{ - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - // only do it if enabled - if (mTimerEnabled) { - MOZ_TIMER_STOP(mStyleResolutionWatch); - } else { -#ifdef NOISY_DEBUG - printf( "Attempt to stop timer while disabled - ignoring\n" ); -#endif - } - } - else - rv = NS_ERROR_NOT_IMPLEMENTED; - - return rv; -} - -NS_IMETHODIMP -StyleSetImpl::PrintTimer(PRUint32 aTimerID) -{ - nsresult rv = NS_OK; - - if (NS_TIMER_STYLE_RESOLUTION == aTimerID) { - MOZ_TIMER_PRINT(mStyleResolutionWatch); - } - else - rv = NS_ERROR_NOT_IMPLEMENTED; - - return rv; -} - -#endif - -//----------------------------------------------------------------------------- - -// static -nsUniqueStyleItems *nsUniqueStyleItems ::mInstance = nsnull; - -void StyleSetImpl::ResetUniqueStyleItems(void) -{ - UNIQUE_STYLE_ITEMS(uniqueItems); - uniqueItems->Clear(); + return result; } diff --git a/content/base/src/nsStyleSet.h b/content/base/src/nsStyleSet.h new file mode 100644 index 000000000000..31cd29049f5b --- /dev/null +++ b/content/base/src/nsStyleSet.h @@ -0,0 +1,245 @@ +/* -*- 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): + * Daniel Glazman + * Brian Ryner + * + * + * 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 nsStyleSet_h_ +#define nsStyleSet_h_ + +#include "nsIStyleRuleProcessor.h" +#include "nsICSSStyleSheet.h" +#include "nsVoidArray.h" +#include "nsIStyleRuleSupplier.h" +#include "nsRuleNode.h" + +class nsIURI; + +class nsStyleSet +{ + public: + nsStyleSet(); + + // Initialize the object. You must check the return code and not use + // the nsStyleSet if Init() fails. + + nsresult Init(nsIPresContext *aPresContext); + + // For getting the cached default data in case we hit out-of-memory. + // To be used only by nsRuleNode. + nsCachedStyleData* DefaultStyleData() { return &mDefaultStyleData; } + + // clear out all of the computed style data + void ClearStyleData(nsIPresContext *aPresContext); + + // notification that a style sheet (of any type) has become enabled + // or disabled + nsresult StyleSheetApplicableStateChanged(); + + // enable / disable the Quirk style sheet + void EnableQuirkStyleSheet(PRBool aEnable); + + // get a style context for a non-pseudo frame. + already_AddRefed + ResolveStyleFor(nsIPresContext* aPresContext, + nsIContent* aContent, + nsStyleContext* aParentContext); + + // Get a style context for a non-element (which no rules will match). + // Eventually, this should go away and we shouldn't even create style + // contexts for such content nodes. However, not doing any rule + // matching for them is a first step. + // + // XXX This is temporary. It should go away when we stop creating + // style contexts for text nodes and placeholder frames. (We also use + // it once to create a style context for the nsFirstLetterFrame that + // represents everything except the first letter.) + // + already_AddRefed + ResolveStyleForNonElement(nsIPresContext* aPresContext, + nsStyleContext* aParentContext); + + // get a style context for a pseudo-element (i.e., + // |aPseudoTag == nsCOMPtr(do_GetAtom(":first-line"))|; + already_AddRefed + ResolvePseudoStyleFor(nsIPresContext* aPresContext, + nsIContent* aParentContent, + nsIAtom* aPseudoTag, + nsStyleContext* aParentContext, + nsICSSPseudoComparator* aComparator = nsnull); + + // This funtions just like ResolvePseudoStyleFor except that it will + // return nsnull if there are no explicit style rules for that + // pseudo element. + already_AddRefed + ProbePseudoStyleFor(nsIPresContext* aPresContext, + nsIContent* aParentContent, + nsIAtom* aPseudoTag, + nsStyleContext* aParentContext); + + // Begin ignoring style context destruction, to avoid lots of unnecessary + // work on document teardown. + void BeginShutdown(nsIPresContext* aPresContext); + + // Free all of the data associated with this style set. + void Shutdown(nsIPresContext* aPresContext); + + // Notification that a style context is being destroyed. + void NotifyStyleContextDestroyed(nsIPresContext* aPresContext, + nsStyleContext* aStyleContext); + + // Get a new style context that lives in a different parent + // The new context will be the same as the old if the new parent is the + // same as the old parent. + already_AddRefed + ReParentStyleContext(nsIPresContext* aPresContext, + nsStyleContext* aStyleContext, + nsStyleContext* aNewParentContext); + + // Test if style is dependent on content state + PRBool HasStateDependentStyle(nsIPresContext* aPresContext, + nsIContent* aContent, + PRInt32 aStateMask); + + // Test if style is dependent on the presence of an attribute. + PRBool HasAttributeDependentStyle(nsIPresContext* aPresContext, + nsIContent* aContent, + nsIAtom* aAttribute, + PRInt32 aModType); + + // APIs for registering objects that can supply additional + // rules during processing. + void SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier) + { + mStyleRuleSupplier = aSupplier; + } + + nsIStyleRuleSupplier* GetStyleRuleSupplier() const + { + return mStyleRuleSupplier; + } + + // Free global data at module shutdown + static void FreeGlobals() { NS_IF_RELEASE(gQuirkURI); } + + // APIs to manipulate the style sheet lists + enum sheetType { + eAgentSheet, + eUserSheet, + eDocSheet, + eOverrideSheet, // override sheets are ordered most significant first + eSheetTypeCount + }; + + nsresult AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet); + nsresult PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet); + nsresult RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet); + nsresult ReplaceSheets(sheetType aType, + const nsCOMArray &aNewSheets); + + PRInt32 SheetCount(sheetType aType) const { + return mSheets[aType].Count(); + } + + nsIStyleSheet* StyleSheetAt(sheetType aType, PRInt32 aIndex) const { + return mSheets[aType].ObjectAt(aIndex); + } + + nsresult AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument); + + void BeginUpdate(); + nsresult EndUpdate(); + + private: + // Not to be implemented + nsStyleSet(const nsStyleSet& aCopy); + nsStyleSet& operator=(const nsStyleSet& aCopy); + + // Returns false on out-of-memory. + PRBool BuildDefaultStyleData(nsIPresContext* aPresContext); + + // Update the rule processor list after a change to the style sheet list. + nsresult GatherRuleProcessors(PRInt32 aType); + + void AddImportantRules(nsRuleNode* aCurrLevelNode, + nsRuleNode* aLastPrevLevelNode); + + // Enumerate the rules in a way that cares about the order of the + // rules. + void FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc, + RuleProcessorData* aData); + + // Enumerate all the rules in a way that doesn't care about the order + // of the rules and break out if the enumeration is halted. + void WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc, + RuleProcessorData* aData); + + already_AddRefed GetContext(nsIPresContext* aPresContext, + nsStyleContext* aParentContext, + nsIAtom* aPseudoTag); + + static nsIURI *gQuirkURI; + + nsCOMArray mSheets[eSheetTypeCount]; + + nsCOMArray mRuleProcessors[eSheetTypeCount]; + + // cached instance for enabling/disabling + nsCOMPtr mQuirkStyleSheet; + + nsCOMPtr mStyleRuleSupplier; + + // To be used only in case of emergency, such as being out of memory + // or operating on a deleted rule node. The latter should never + // happen, of course. + nsCachedStyleData mDefaultStyleData; + + nsRuleNode* mRuleTree; // This is the root of our rule tree. It is a + // lexicographic tree of matched rules that style + // contexts use to look up properties. + nsRuleWalker* mRuleWalker; // This is an instance of a rule walker that can + // be used to navigate through our tree. + + PRInt32 mDestroyedCount; // used to batch style context GC + nsVoidArray mRoots; // style contexts with no parent + + unsigned mBatching : 1; + unsigned mInShutdown : 1; + unsigned mDirty : 6; // one dirty bit is used per sheet type +}; + +#endif diff --git a/content/events/src/Makefile.in b/content/events/src/Makefile.in index 7eca37114974..dc1f97eb455e 100644 --- a/content/events/src/Makefile.in +++ b/content/events/src/Makefile.in @@ -63,3 +63,4 @@ LOCAL_INCLUDES = -I$(srcdir)/../../html/base/src \ -I$(srcdir)/../../xul/content/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/html/content/src/Makefile.in b/content/html/content/src/Makefile.in index 6c496775ae88..d5f8143480df 100644 --- a/content/html/content/src/Makefile.in +++ b/content/html/content/src/Makefile.in @@ -133,3 +133,4 @@ INCLUDES += \ -I$(srcdir)/../../base/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp index 852dd22d9cfe..58614a9513bd 100644 --- a/content/html/content/src/nsHTMLBodyElement.cpp +++ b/content/html/content/src/nsHTMLBodyElement.cpp @@ -60,7 +60,6 @@ #include "nsIDocShell.h" #include "nsIFrameManager.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #include "nsIView.h" #include "nsLayoutAtoms.h" #include "nsRuleWalker.h" diff --git a/content/html/document/src/Makefile.in b/content/html/document/src/Makefile.in index 0d213b8ab3c2..ff3d4c095470 100644 --- a/content/html/document/src/Makefile.in +++ b/content/html/document/src/Makefile.in @@ -85,3 +85,5 @@ INCLUDES += \ -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../content/src \ $(NULL) + +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 2215b50e93b2..986578ef8a6d 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -51,7 +51,6 @@ #include "nsHTMLParts.h" #include "nsIHTMLStyleSheet.h" #include "nsIHTMLCSSStyleSheet.h" -#include "nsIStyleSet.h" #include "nsHTMLAtoms.h" #include "nsLayoutAtoms.h" #include "nsIPresShell.h" @@ -455,7 +454,7 @@ nsHTMLDocument::BaseResetToURI(nsIURI *aURL) NS_IMETHODIMP nsHTMLDocument::CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, + nsStyleSet* aStyleSet, nsIPresShell** aInstancePtrResult) { return doCreateShell(aContext, aViewManager, aStyleSet, mCompatMode, diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 9d89a4bfd557..e493215947ae 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -91,7 +91,7 @@ public: NS_IMETHOD CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, + nsStyleSet* aStyleSet, nsIPresShell** aInstancePtrResult); NS_IMETHOD StartDocumentLoad(const char* aCommand, diff --git a/content/html/style/src/Makefile.in b/content/html/style/src/Makefile.in index 7ac393970f38..eeca6fe95db3 100644 --- a/content/html/style/src/Makefile.in +++ b/content/html/style/src/Makefile.in @@ -119,3 +119,5 @@ LOCAL_INCLUDES += \ -I$(srcdir)/../../../svg/content/src \ -I$(srcdir)/../../../svg/base/src endif + +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/html/style/src/nsCSSDeclaration.cpp b/content/html/style/src/nsCSSDeclaration.cpp index 3d923b016e62..1c9c18b6148d 100644 --- a/content/html/style/src/nsCSSDeclaration.cpp +++ b/content/html/style/src/nsCSSDeclaration.cpp @@ -51,7 +51,6 @@ #include "nsStyleConsts.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #define B_BORDER_TOP_STYLE 0x001 #define B_BORDER_LEFT_STYLE 0x002 diff --git a/content/html/style/src/nsCSSParser.cpp b/content/html/style/src/nsCSSParser.cpp index ad41080b5f05..1cc584e68f37 100644 --- a/content/html/style/src/nsCSSParser.cpp +++ b/content/html/style/src/nsCSSParser.cpp @@ -48,7 +48,6 @@ #include "nsICSSMediaRule.h" #include "nsICSSNameSpaceRule.h" #include "nsIUnicharInputStream.h" -#include "nsIStyleSet.h" #include "nsICSSStyleSheet.h" #include "nsCSSDeclaration.h" #include "nsStyleConsts.h" diff --git a/content/html/style/src/nsCSSRules.cpp b/content/html/style/src/nsCSSRules.cpp index 60d67c30d348..585f3c9d8cb1 100644 --- a/content/html/style/src/nsCSSRules.cpp +++ b/content/html/style/src/nsCSSRules.cpp @@ -50,7 +50,6 @@ #include "nsICSSStyleSheet.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #include "nsIDOMCSSStyleSheet.h" #include "nsIDOMCSSRule.h" #include "nsIDOMCSSImportRule.h" diff --git a/content/html/style/src/nsCSSStruct.cpp b/content/html/style/src/nsCSSStruct.cpp index aa1c8f8761c2..b2ffbd191812 100644 --- a/content/html/style/src/nsCSSStruct.cpp +++ b/content/html/style/src/nsCSSStruct.cpp @@ -50,7 +50,6 @@ #include "nsStyleConsts.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #define CSS_IF_DELETE(ptr) if (nsnull != ptr) { delete ptr; ptr = nsnull; } diff --git a/content/html/style/src/nsCSSStyleRule.cpp b/content/html/style/src/nsCSSStyleRule.cpp index 37934bd6548b..50edbcbecfd8 100644 --- a/content/html/style/src/nsCSSStyleRule.cpp +++ b/content/html/style/src/nsCSSStyleRule.cpp @@ -68,8 +68,6 @@ #include "nsUnicharUtils.h" #include "nsCSSPseudoElements.h" -#include "nsIStyleSet.h" - #include "nsContentUtils.h" #include "nsContentErrors.h" diff --git a/content/html/style/src/nsCSSStyleSheet.cpp b/content/html/style/src/nsCSSStyleSheet.cpp index a9a14ad2c24d..69bf06a58042 100644 --- a/content/html/style/src/nsCSSStyleSheet.cpp +++ b/content/html/style/src/nsCSSStyleSheet.cpp @@ -96,7 +96,6 @@ #include "nsITextContent.h" #include "prlog.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #include "nsStyleUtil.h" #include "nsQuickSort.h" #include "nsContentUtils.h" diff --git a/content/html/style/src/nsHTMLAttributes.cpp b/content/html/style/src/nsHTMLAttributes.cpp index 0679269a69f5..95f71099a231 100644 --- a/content/html/style/src/nsHTMLAttributes.cpp +++ b/content/html/style/src/nsHTMLAttributes.cpp @@ -52,7 +52,6 @@ #include "nsCOMPtr.h" #include "nsUnicharUtils.h" -#include "nsIStyleSet.h" #include "nsRuleWalker.h" MOZ_DECL_CTOR_COUNTER(HTMLAttribute) diff --git a/content/html/style/src/nsHTMLCSSStyleSheet.cpp b/content/html/style/src/nsHTMLCSSStyleSheet.cpp index 07b5d8a82c86..0821eaa5f048 100644 --- a/content/html/style/src/nsHTMLCSSStyleSheet.cpp +++ b/content/html/style/src/nsHTMLCSSStyleSheet.cpp @@ -52,7 +52,6 @@ #include "nsIDocument.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #include "nsRuleWalker.h" /* diff --git a/content/html/style/src/nsHTMLStyleSheet.cpp b/content/html/style/src/nsHTMLStyleSheet.cpp index c277792eec2e..72b229efd1c4 100644 --- a/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/content/html/style/src/nsHTMLStyleSheet.cpp @@ -59,10 +59,6 @@ #include "nsRuleWalker.h" -#include "nsIStyleSet.h" - -static NS_DEFINE_CID(kCSSFrameConstructorCID, NS_CSSFRAMECONSTRUCTOR_CID); - class HTMLColorRule : public nsIStyleRule { public: HTMLColorRule(nsIHTMLStyleSheet* aSheet); @@ -687,49 +683,7 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl() PL_DHashTableFinish(&mMappedAttrTable); } -NS_IMPL_ADDREF(HTMLStyleSheetImpl) -NS_IMPL_RELEASE(HTMLStyleSheetImpl) - -nsresult HTMLStyleSheetImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(aInstancePtrResult, "null out param"); - - if (aIID.Equals(NS_GET_IID(nsIHTMLStyleSheet))) { - *aInstancePtrResult = NS_STATIC_CAST(nsIHTMLStyleSheet*, this); - } else if (aIID.Equals(NS_GET_IID(nsIStyleSheet))) { - *aInstancePtrResult = NS_STATIC_CAST(nsIStyleSheet *, this); - } else if (aIID.Equals(NS_GET_IID(nsIStyleRuleProcessor))) { - *aInstancePtrResult = NS_STATIC_CAST(nsIStyleRuleProcessor *, this); - } else if (aIID.Equals(NS_GET_IID(nsIStyleFrameConstruction))) { - // XXX this breaks XPCOM rules since it isn't a proper delegate - // This is a temporary method of connecting the constructor for - // now - nsresult rv; - nsCOMPtr constructor = - do_CreateInstance(kCSSFrameConstructorCID, &rv); - - if (NS_SUCCEEDED(rv)) { - rv = constructor->Init(mDocument); - - if (NS_SUCCEEDED(rv)) { - rv = constructor->QueryInterface(aIID, aInstancePtrResult); - } - } - - return rv; - } else if (aIID.Equals(NS_GET_IID(nsISupports))) { - *aInstancePtrResult = NS_STATIC_CAST(nsIHTMLStyleSheet *, this); - } else { - *aInstancePtrResult = nsnull; - - return NS_NOINTERFACE; - } - - NS_ADDREF_THIS(); - - return NS_OK; -} +NS_IMPL_ISUPPORTS3(HTMLStyleSheetImpl, nsIHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor) NS_IMETHODIMP HTMLStyleSheetImpl::GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor, diff --git a/content/shared/public/nsStyleStruct.h b/content/shared/public/nsStyleStruct.h index 78dfdee93502..bac4ff250584 100644 --- a/content/shared/public/nsStyleStruct.h +++ b/content/shared/public/nsStyleStruct.h @@ -47,7 +47,6 @@ #include "nsStyleCoord.h" #include "nsStyleConsts.h" #include "nsChangeHint.h" -#include "nsIStyleSet.h" #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsCOMPtr.h" diff --git a/content/shared/src/Makefile.in b/content/shared/src/Makefile.in index b9dff9889f7c..e5468e6face5 100644 --- a/content/shared/src/Makefile.in +++ b/content/shared/src/Makefile.in @@ -66,3 +66,5 @@ endif FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk + +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/shared/src/nsStyleStruct.cpp b/content/shared/src/nsStyleStruct.cpp index 413f7efeec35..c6ddbd8acd37 100644 --- a/content/shared/src/nsStyleStruct.cpp +++ b/content/shared/src/nsStyleStruct.cpp @@ -48,7 +48,6 @@ #include "nsCRT.h" #include "nsCOMPtr.h" -#include "nsIStyleSet.h" #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsLayoutAtoms.h" diff --git a/content/svg/content/src/Makefile.in b/content/svg/content/src/Makefile.in index 517cde76cf1e..6f3230ddba07 100644 --- a/content/svg/content/src/Makefile.in +++ b/content/svg/content/src/Makefile.in @@ -99,3 +99,5 @@ INCLUDES += \ -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../../../layout/svg/base/src \ $(NULL) + +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/svg/document/src/Makefile.in b/content/svg/document/src/Makefile.in index f52acd991141..c26fb4b933e9 100644 --- a/content/svg/document/src/Makefile.in +++ b/content/svg/document/src/Makefile.in @@ -61,3 +61,4 @@ INCLUDES += \ -I$(srcdir)/../../../base/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/xbl/public/nsIXBLBinding.h b/content/xbl/public/nsIXBLBinding.h index 36ca1d983340..3cd468f161ec 100644 --- a/content/xbl/public/nsIXBLBinding.h +++ b/content/xbl/public/nsIXBLBinding.h @@ -48,6 +48,7 @@ #include "nsISupports.h" #include "nsISupportsArray.h" +#include "nsIStyleRuleProcessor.h" class nsIContent; class nsIDocument; @@ -121,7 +122,7 @@ public: NS_IMETHOD GetFirstStyleBinding(nsIXBLBinding** aResult) = 0; NS_IMETHOD InheritsStyle(PRBool* aResult)=0; - NS_IMETHOD WalkRules(nsISupportsArrayEnumFunc aFunc, void* aData)=0; + NS_IMETHOD WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData)=0; NS_IMETHOD MarkForDeath()=0; NS_IMETHOD MarkedForDeath(PRBool* aResult)=0; diff --git a/content/xbl/src/Makefile.in b/content/xbl/src/Makefile.in index 920a771f571a..004cdc902f5e 100644 --- a/content/xbl/src/Makefile.in +++ b/content/xbl/src/Makefile.in @@ -91,3 +91,4 @@ LOCAL_INCLUDES = \ -I$(srcdir)/../../xul/content/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index 12afb819c1f7..efc9736ed94d 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -76,7 +76,6 @@ #include "nsIHTMLContentContainer.h" #include "nsIStyleRuleProcessor.h" -#include "nsIStyleSet.h" #include "nsIWeakReference.h" #include "jsapi.h" @@ -359,8 +358,8 @@ public: // nsIStyleRuleSupplier NS_IMETHOD UseDocumentRules(nsIContent* aContent, PRBool* aResult); - NS_IMETHOD WalkRules(nsIStyleSet* aStyleSet, - nsISupportsArrayEnumFunc aFunc, + NS_IMETHOD WalkRules(nsStyleSet* aStyleSet, + nsIStyleRuleProcessor::EnumFunc aFunc, RuleProcessorData* aData); // nsIDocumentObserver @@ -379,7 +378,8 @@ protected: } nsIContent* GetOutermostStyleScope(nsIContent* aContent); - void WalkRules(nsISupportsArrayEnumFunc aFunc, RuleProcessorData* aData, + void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, + RuleProcessorData* aData, nsIContent* aParent, nsIContent* aCurrContent); nsresult GetNestedInsertionPoint(nsIContent* aParent, nsIContent* aChild, nsIContent** aResult); @@ -1232,7 +1232,7 @@ nsBindingManager::GetOutermostStyleScope(nsIContent* aContent) } void -nsBindingManager::WalkRules(nsISupportsArrayEnumFunc aFunc, +nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, RuleProcessorData* aData, nsIContent* aParent, nsIContent* aCurrContent) { @@ -1250,8 +1250,8 @@ nsBindingManager::WalkRules(nsISupportsArrayEnumFunc aFunc, } NS_IMETHODIMP -nsBindingManager::WalkRules(nsIStyleSet* aStyleSet, - nsISupportsArrayEnumFunc aFunc, +nsBindingManager::WalkRules(nsStyleSet* aStyleSet, + nsIStyleRuleProcessor::EnumFunc aFunc, RuleProcessorData* aData) { nsIContent *content = aData->mContent; @@ -1275,7 +1275,7 @@ nsBindingManager::WalkRules(nsIStyleSet* aStyleSet, container->GetInlineStyleSheet(getter_AddRefs(inlineSheet)); nsCOMPtr inlineCSS(do_QueryInterface(inlineSheet)); if (inlineCSS) - (*aFunc)((nsISupports*)(inlineCSS.get()), aData); + (*aFunc)(inlineCSS, aData); } } diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 45c8c42df929..fe817589fd84 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -1063,7 +1063,7 @@ nsXBLBinding::InheritsStyle(PRBool* aResult) } NS_IMETHODIMP -nsXBLBinding::WalkRules(nsISupportsArrayEnumFunc aFunc, void* aData) +nsXBLBinding::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData) { nsresult rv = NS_OK; if (mNextBinding) { @@ -1072,7 +1072,7 @@ nsXBLBinding::WalkRules(nsISupportsArrayEnumFunc aFunc, void* aData) return rv; } - nsCOMPtr rules = mPrototypeBinding->GetRuleProcessors(); + nsCOMArray *rules = mPrototypeBinding->GetRuleProcessors(); if (rules) rules->EnumerateForwards(aFunc, aData); diff --git a/content/xbl/src/nsXBLBinding.h b/content/xbl/src/nsXBLBinding.h index 4614d6093bc3..46af78e44a04 100644 --- a/content/xbl/src/nsXBLBinding.h +++ b/content/xbl/src/nsXBLBinding.h @@ -112,7 +112,7 @@ class nsXBLBinding: public nsIXBLBinding NS_IMETHOD GetFirstStyleBinding(nsIXBLBinding** aResult); NS_IMETHOD InheritsStyle(PRBool* aResult); - NS_IMETHOD WalkRules(nsISupportsArrayEnumFunc aFunc, void* aData); + NS_IMETHOD WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData); NS_IMETHOD MarkForDeath(); NS_IMETHOD MarkedForDeath(PRBool* aResult); diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index a508d22f13dc..bffe0d6b72b1 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -927,14 +927,13 @@ nsXBLPrototypeBinding::SetInitialAttributes(nsIContent* aBoundElement, nsIConten } } -already_AddRefed +nsCOMArray* nsXBLPrototypeBinding::GetRuleProcessors() { - nsISupportsArray* result; - if (mResources) { - result = mResources->mRuleProcessors; - NS_IF_ADDREF(result); - } else + nsCOMArray *result; + if (mResources) + result = &mResources->mRuleProcessors; + else result = nsnull; return result; } diff --git a/content/xbl/src/nsXBLPrototypeBinding.h b/content/xbl/src/nsXBLPrototypeBinding.h index 0e9fe6c37d2d..843cb4559325 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.h +++ b/content/xbl/src/nsXBLPrototypeBinding.h @@ -119,7 +119,7 @@ public: void SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent); - already_AddRefed GetRuleProcessors(); + nsCOMArray* GetRuleProcessors(); already_AddRefed GetStyleSheets(); PRBool HasInsertionPoints() { return mInsertionPointTable != nsnull; } diff --git a/content/xbl/src/nsXBLPrototypeResources.cpp b/content/xbl/src/nsXBLPrototypeResources.cpp index a5d1ac12c9c6..d1b7cbfdc3ff 100644 --- a/content/xbl/src/nsXBLPrototypeResources.cpp +++ b/content/xbl/src/nsXBLPrototypeResources.cpp @@ -113,7 +113,7 @@ nsXBLPrototypeResources::FlushSkinSheets() // We have scoped stylesheets. Reload any chrome stylesheets we // encounter. (If they aren't skin sheets, it doesn't matter, since // they'll still be in the chrome cache. - mRuleProcessors->Clear(); + mRuleProcessors.Clear(); nsresult rv; nsCOMPtr loader = do_CreateInstance(kCSSLoaderCID, &rv); @@ -147,7 +147,7 @@ nsXBLPrototypeResources::FlushSkinSheets() nsCOMPtr processor; newSheet->GetStyleRuleProcessor(*getter_AddRefs(processor), prevProcessor); if (processor != prevProcessor) { - mRuleProcessors->AppendElement(processor); + mRuleProcessors.AppendObject(processor); prevProcessor = processor; } } diff --git a/content/xbl/src/nsXBLPrototypeResources.h b/content/xbl/src/nsXBLPrototypeResources.h index 3458ac4f2ca4..b3a01432cc90 100644 --- a/content/xbl/src/nsXBLPrototypeResources.h +++ b/content/xbl/src/nsXBLPrototypeResources.h @@ -43,6 +43,8 @@ #include "nsCOMPtr.h" #include "nsICSSLoaderObserver.h" #include "nsISupportsArray.h" +#include "nsIStyleRuleProcessor.h" +#include "nsCOMArray.h" class nsIContent; class nsIAtom; @@ -69,7 +71,7 @@ public: // MEMBER VARIABLES nsXBLResourceLoader* mLoader; // A loader object. Exists only long enough to load resources, and then it dies. nsCOMPtr mStyleSheetList; // A list of loaded stylesheets for this binding. - nsCOMPtr mRuleProcessors; // The list of stylesheets converted to rule processors. + nsCOMArray mRuleProcessors; // The list of stylesheets converted to rule processors. }; #endif diff --git a/content/xbl/src/nsXBLResourceLoader.cpp b/content/xbl/src/nsXBLResourceLoader.cpp index 7034d67beb68..d9d0ee182b91 100644 --- a/content/xbl/src/nsXBLResourceLoader.cpp +++ b/content/xbl/src/nsXBLResourceLoader.cpp @@ -201,7 +201,7 @@ nsXBLResourceLoader::StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify) if (mPendingSheets == 0) { // All stylesheets are loaded. nsCOMPtr prevProcessor; - NS_NewISupportsArray(getter_AddRefs(mResources->mRuleProcessors)); + mResources->mRuleProcessors.Clear(); PRUint32 count; mResources->mStyleSheetList->Count(&count); for (PRUint32 i = 0; i < count; i++) { @@ -211,7 +211,7 @@ nsXBLResourceLoader::StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify) nsCOMPtr processor; sheet->GetStyleRuleProcessor(*getter_AddRefs(processor), prevProcessor); if (processor != prevProcessor) { - mResources->mRuleProcessors->AppendElement(processor); + mResources->mRuleProcessors.AppendObject(processor); prevProcessor = processor; } } diff --git a/content/xml/content/src/Makefile.in b/content/xml/content/src/Makefile.in index 0835c494225b..d26ac43464a7 100644 --- a/content/xml/content/src/Makefile.in +++ b/content/xml/content/src/Makefile.in @@ -70,3 +70,4 @@ libs:: install:: $(SYSINSTALL) $(IFLAGS1) $(EXPORT_RESOURCE_CONTENT) $(DESTDIR)$(mozappdir)/res/dtd +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/xml/document/src/Makefile.in b/content/xml/document/src/Makefile.in index f1bf9132e57f..e8a2c91232a7 100644 --- a/content/xml/document/src/Makefile.in +++ b/content/xml/document/src/Makefile.in @@ -73,3 +73,4 @@ LOCAL_INCLUDES = \ -I$(srcdir)/../../../xul/content/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 1525e302c966..6888e420adae 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -55,7 +55,6 @@ #include "nsHTMLParts.h" #include "nsIHTMLStyleSheet.h" #include "nsIHTMLCSSStyleSheet.h" -#include "nsIStyleSet.h" #include "nsIComponentManager.h" #include "nsIDOMComment.h" #include "nsIDOMElement.h" diff --git a/content/xul/content/src/Makefile.in b/content/xul/content/src/Makefile.in index c8485c0a8906..ee3e478ee388 100644 --- a/content/xul/content/src/Makefile.in +++ b/content/xul/content/src/Makefile.in @@ -72,3 +72,4 @@ LOCAL_INCLUDES = \ -I$(srcdir)/../../../html/style/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/xul/document/src/Makefile.in b/content/xul/document/src/Makefile.in index 878854eca755..b0acbe2267e7 100644 --- a/content/xul/document/src/Makefile.in +++ b/content/xul/document/src/Makefile.in @@ -80,3 +80,4 @@ LOCAL_INCLUDES = -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../../xml/document/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/content/xul/templates/src/Makefile.in b/content/xul/templates/src/Makefile.in index 55f666044ed9..6ce8617010d8 100644 --- a/content/xul/templates/src/Makefile.in +++ b/content/xul/templates/src/Makefile.in @@ -82,3 +82,4 @@ LOCAL_INCLUDES = -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../content/src \ $(NULL) +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/editor/libeditor/base/nsStyleSheetTxns.cpp b/editor/libeditor/base/nsStyleSheetTxns.cpp index 0ad5a30d2604..bbdf91ebcd9b 100644 --- a/editor/libeditor/base/nsStyleSheetTxns.cpp +++ b/editor/libeditor/base/nsStyleSheetTxns.cpp @@ -41,7 +41,6 @@ #include "nsIPresShell.h" #include "nsICSSStyleSheet.h" -#include "nsIStyleSet.h" #include "nsIDocument.h" #include "nsIDocumentObserver.h" #include "nsISelectionController.h" @@ -49,7 +48,31 @@ #include "nsStyleSheetTxns.h" +static void +AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet) +{ + nsCOMPtr domDoc; + aEditor->GetDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc = do_QueryInterface(domDoc); + if (doc) { + doc->BeginUpdate(UPDATE_STYLE); + doc->AddStyleSheet(aSheet, 0); + doc->EndUpdate(UPDATE_STYLE); + } +} +static void +RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet) +{ + nsCOMPtr domDoc; + aEditor->GetDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc = do_QueryInterface(domDoc); + if (doc) { + doc->BeginUpdate(UPDATE_STYLE); + doc->RemoveStyleSheet(aSheet); + doc->EndUpdate(UPDATE_STYLE); + } +} AddStyleSheetTxn::AddStyleSheetTxn() : EditTxn() @@ -83,33 +106,8 @@ AddStyleSheetTxn::DoTransaction() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selCon; - mEditor->GetSelectionController(getter_AddRefs(selCon)); - - nsCOMPtr presShell = do_QueryInterface(selCon); - if (!presShell) - return NS_ERROR_UNEXPECTED; - - // although we don't need styleSet here; we need it in Undo - nsCOMPtr styleSet; - nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet)); - if (NS_FAILED(rv)) return rv; - if (!styleSet) return NS_OK; - - nsCOMPtr styleSheet = do_QueryInterface(mSheet); - if (styleSheet) - { - nsCOMPtr document; - rv = presShell->GetDocument(getter_AddRefs(document)); - - if (NS_SUCCEEDED(rv) && document) { - document->BeginUpdate(UPDATE_STYLE); - document->AddStyleSheet(styleSheet, 0); - document->EndUpdate(UPDATE_STYLE); - } - } - - return rv; + AddStyleSheet(mEditor, mSheet); + return NS_OK; } NS_IMETHODIMP @@ -118,34 +116,8 @@ AddStyleSheetTxn::UndoTransaction() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selCon; - mEditor->GetSelectionController(getter_AddRefs(selCon)); - - nsCOMPtr presShell = do_QueryInterface(selCon); - if (!presShell) - return NS_ERROR_UNEXPECTED; - - nsCOMPtr styleSet; - nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet)); - - if (NS_SUCCEEDED(rv) && styleSet) - { - styleSet->RemoveDocStyleSheet(mSheet); - - nsCOMPtr observer = do_QueryInterface(presShell); - nsCOMPtr styleSheet = do_QueryInterface(mSheet); - nsCOMPtr document; - - rv = presShell->GetDocument(getter_AddRefs(document)); - - if (NS_SUCCEEDED(rv) && document && observer && styleSheet) { - observer->BeginUpdate(document, UPDATE_STYLE); - rv = observer->StyleSheetRemoved(document, styleSheet); - observer->EndUpdate(document, UPDATE_STYLE); - } - } - - return rv; + RemoveStyleSheet(mEditor, mSheet); + return NS_OK; } NS_IMETHODIMP @@ -208,35 +180,9 @@ RemoveStyleSheetTxn::DoTransaction() { if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr selCon; - mEditor->GetSelectionController(getter_AddRefs(selCon)); - nsCOMPtr presShell = do_QueryInterface(selCon); - if (!presShell) - return NS_ERROR_UNEXPECTED; - - nsCOMPtr styleSet; - nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet)); - - if (NS_SUCCEEDED(rv) && styleSet) - { - styleSet->RemoveDocStyleSheet(mSheet); - - nsCOMPtr observer = do_QueryInterface(presShell); - nsCOMPtr styleSheet = do_QueryInterface(mSheet); - nsCOMPtr document; - - rv = presShell->GetDocument(getter_AddRefs(document)); - - if (NS_SUCCEEDED(rv) && document && observer && styleSheet) { - observer->BeginUpdate(document, UPDATE_STYLE); - rv = observer->StyleSheetRemoved(document, styleSheet); - observer->EndUpdate(document, UPDATE_STYLE); - } - } - - return rv; + RemoveStyleSheet(mEditor, mSheet); + return NS_OK; } NS_IMETHODIMP @@ -244,35 +190,9 @@ RemoveStyleSheetTxn::UndoTransaction() { if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr selCon; - mEditor->GetSelectionController(getter_AddRefs(selCon)); - nsCOMPtr presShell = do_QueryInterface(selCon); - if (!presShell) - return NS_ERROR_UNEXPECTED; - - // although we don't really use styleSet here, we will in Do above - nsCOMPtr styleSet; - nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet)); - - if (NS_SUCCEEDED(rv) && styleSet) - { - nsCOMPtr styleSheet = do_QueryInterface(mSheet); - if (styleSheet) - { - nsCOMPtr document; - rv = presShell->GetDocument(getter_AddRefs(document)); - - if (NS_SUCCEEDED(rv) && document) { - document->BeginUpdate(UPDATE_STYLE); - document->AddStyleSheet(styleSheet, 0); - document->EndUpdate(UPDATE_STYLE); - } - } - } - - return rv; + AddStyleSheet(mEditor, mSheet); + return NS_OK; } NS_IMETHODIMP diff --git a/editor/libeditor/html/nsHTMLDataTransfer.cpp b/editor/libeditor/html/nsHTMLDataTransfer.cpp index 4cc660d3923c..80eb60f643a8 100644 --- a/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -68,7 +68,6 @@ #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" #include "nsIHTMLContentContainer.h" -#include "nsIStyleSet.h" #include "nsIDocumentObserver.h" #include "nsIDocumentStateListener.h" diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index b8e0ff419772..9099a492626e 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -123,7 +123,6 @@ // Misc #include "TextEditorTest.h" #include "nsEditorUtils.h" -#include "nsIStyleSet.h" #include "nsIPref.h" #include "nsITextContent.h" #include "nsWSRunObject.h" @@ -3675,37 +3674,21 @@ nsHTMLEditor::AddOverrideStyleSheet(const nsAString& aURL) if (!sheet) return NS_ERROR_NULL_POINTER; - nsCOMPtr styleSheet; - styleSheet = do_QueryInterface(sheet); - nsCOMPtr styleSet; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - rv = ps->GetStyleSet(getter_AddRefs(styleSet)); - NS_ENSURE_SUCCESS(rv, rv); - if (!styleSet) - return NS_ERROR_NULL_POINTER; // Add the override style sheet // (This checks if already exists) - styleSet->AppendOverrideStyleSheet(styleSheet); + ps->AddOverrideStyleSheet(sheet); // Save doc pointer to be able to use nsIStyleSheet::SetEnabled() - nsCOMPtr document; - rv = ps->GetDocument(getter_AddRefs(document)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *document = ps->GetDocument(); if (!document) return NS_ERROR_NULL_POINTER; - styleSheet->SetOwningDocument(document); + sheet->SetOwningDocument(document); - // This notifies document observers to recompute style data - // (this doesn't affect style sheet because it is not a doc sheet) - // XXXbz this is a major misuse of the API.... - document->BeginUpdate(UPDATE_STYLE); - document->SetStyleSheetApplicableState(styleSheet, PR_TRUE); - document->EndUpdate(UPDATE_STYLE); + ps->ReconstructStyleData(); // Save as the last-loaded sheet mLastOverrideStyleSheetURL = aURL; @@ -3747,27 +3730,8 @@ nsHTMLEditor::RemoveOverrideStyleSheet(const nsAString &aURL) nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr document; - rv = ps->GetDocument(getter_AddRefs(document)); - NS_ENSURE_SUCCESS(rv, rv);; - if (!document) return NS_ERROR_NULL_POINTER; - - nsCOMPtr styleSet; - rv = ps->GetStyleSet(getter_AddRefs(styleSet)); - NS_ENSURE_SUCCESS(rv, rv); - if (!styleSet) return NS_ERROR_NULL_POINTER; - - nsCOMPtr styleSheet = do_QueryInterface(sheet); - if (!styleSheet) return NS_ERROR_NULL_POINTER; - - styleSet->RemoveOverrideStyleSheet(styleSheet); - - // This notifies document observers to recompute style data - // (this doesn't affect style sheet because it is not a doc sheet) - // XXXbz this is a major misuse of the API.... - document->BeginUpdate(UPDATE_STYLE); - document->SetStyleSheetApplicableState(styleSheet, PR_FALSE); - document->EndUpdate(UPDATE_STYLE); + ps->RemoveOverrideStyleSheet(sheet); + ps->ReconstructStyleData(); // Remove it from our internal list return RemoveStyleSheetFromList(aURL); diff --git a/extensions/inspector/base/src/Makefile.in b/extensions/inspector/base/src/Makefile.in index 075c94eeef37..e2217ad443e6 100644 --- a/extensions/inspector/base/src/Makefile.in +++ b/extensions/inspector/base/src/Makefile.in @@ -39,6 +39,7 @@ REQUIRES = xpcom \ necko \ docshell \ view \ + webshell \ $(NULL) CPPSRCS= \ diff --git a/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp b/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp index 73ede66b5748..206e16f4cd69 100644 --- a/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp +++ b/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp @@ -57,7 +57,6 @@ #include "nsIPresShell.h" #include "nsIViewManager.h" -#include "nsIStyleSet.h" #include "nsIFrame.h" #include "nsIFrameDebug.h" @@ -127,18 +126,6 @@ document(nsIDocShell *aDocShell) return result; } -static already_AddRefed -style_set(nsIDocShell *aDocShell) -{ - nsCOMPtr shell(pres_shell(aDocShell)); - if (!shell) - return nsnull; - nsIStyleSet *result = nsnull; - shell->GetStyleSet(&result); - return result; -} - - nsLayoutDebuggingTools::nsLayoutDebuggingTools() : mPaintFlashing(PR_FALSE), mPaintDumping(PR_FALSE), @@ -522,11 +509,11 @@ nsLayoutDebuggingTools::DumpStyleSheets() { #ifdef DEBUG FILE *out = stdout; - nsCOMPtr styleSet(style_set(mDocShell)); - if (styleSet) - styleSet->List(out); + nsCOMPtr shell(pres_shell(mDocShell)); + if (shell) + shell->ListStyleSheets(out); else - fputs("null style set\n", out); + fputs("null pres shell\n", out); #endif return NS_OK; } @@ -538,18 +525,12 @@ nsLayoutDebuggingTools::DumpStyleContexts() FILE *out = stdout; nsCOMPtr shell(pres_shell(mDocShell)); if (shell) { - nsCOMPtr styleSet; - shell->GetStyleSet(getter_AddRefs(styleSet)); - if (!styleSet) { - fputs("null style set\n", out); + nsIFrame* root; + shell->GetRootFrame(&root); + if (!root) { + fputs("null root frame\n", out); } else { - nsIFrame* root; - shell->GetRootFrame(&root); - if (!root) { - fputs("null root frame\n", out); - } else { - styleSet->ListContexts(root, out); - } + shell->ListStyleContexts(root, out); } } else { fputs("null pres shell\n", out); diff --git a/extensions/layout-debug/src/nsRegressionTester.cpp b/extensions/layout-debug/src/nsRegressionTester.cpp index 4d0b7676491a..6128faa848ea 100644 --- a/extensions/layout-debug/src/nsRegressionTester.cpp +++ b/extensions/layout-debug/src/nsRegressionTester.cpp @@ -66,7 +66,6 @@ #include "nsIPrefService.h" #include "nsIViewManager.h" #include "nsIView.h" -#include "nsIStyleSet.h" diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index a9042d59d15d..4cf42fa2e602 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -61,7 +61,7 @@ #include "nsIStyleFrameConstruction.h" #include "nsHTMLParts.h" #include "nsIPresShell.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" #include "nsIViewManager.h" #include "nsIScrollableView.h" #include "nsStyleConsts.h" @@ -1228,25 +1228,8 @@ GetChildListNameFor(nsIPresContext* aPresContext, //---------------------------------------------------------------------- -nsresult NS_CreateCSSFrameConstructor(nsICSSFrameConstructor **aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - - nsCSSFrameConstructor *c = new nsCSSFrameConstructor(); - if (!c) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(c); - nsresult rv = CallQueryInterface(c, aResult); - NS_RELEASE(c); - - return rv; -} - nsCSSFrameConstructor::nsCSSFrameConstructor(void) - : nsIStyleFrameConstruction(), - mDocument(nsnull), + : mDocument(nsnull), mInitialContainingBlock(nsnull), mFixedContainingBlock(nsnull), mDocElementContainingBlock(nsnull), @@ -3556,9 +3539,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, nsIBindingManager *bindingManager = mDocument->GetBindingManager(); if (bindingManager) { nsCOMPtr ruleSupplier(do_QueryInterface(bindingManager)); - nsCOMPtr set; - aPresShell->GetStyleSet(getter_AddRefs(set)); - set->SetStyleRuleSupplier(ruleSupplier); + aPresShell->StyleSet()->SetStyleRuleSupplier(ruleSupplier); } // --------- BUILD VIEWPORT ----------- @@ -9973,134 +9954,129 @@ nsCSSFrameConstructor::ContentStatesChanged(nsIPresContext* aPresContext, NS_ASSERTION(shell, "couldn't get pres shell"); if (shell) { - nsCOMPtr styleSet; - shell->GetStyleSet(getter_AddRefs(styleSet)); + nsStyleSet *styleSet = shell->StyleSet(); - NS_ASSERTION(styleSet, "couldn't get style set"); - if (styleSet) { // test if any style rules exist which are dependent on content state - // Detect if one is the ancestor of the other, and skip if so. - if (aContent1 && aContent2) { - if (aContent1 == aContent2) - aContent2 = nsnull; - else if (IsAncestorOf(aContent1, aContent2)) - aContent2 = nsnull; - else if (IsAncestorOf(aContent2, aContent1)) { + // test if any style rules exist which are dependent on content state + // Detect if one is the ancestor of the other, and skip if so. + if (aContent1 && aContent2) { + if (aContent1 == aContent2) + aContent2 = nsnull; + else if (IsAncestorOf(aContent1, aContent2)) + aContent2 = nsnull; + else if (IsAncestorOf(aContent2, aContent1)) { + aContent1 = nsnull; + } + } + + nsIFrame* primaryFrame1 = nsnull; + nsIFrame* primaryFrame2 = nsnull; + PRUint8 app1 = 0; + PRUint8 app2 = 0; + + if (aContent1) { + shell->GetPrimaryFrameFor(aContent1, &primaryFrame1); + if (primaryFrame1) { + app1 = primaryFrame1->GetStyleDisplay()->mAppearance; + } + + // XXXldb Why check app1 here when you could just do the code + // below |if (app1)| above and avoid the extra style reresolution? + if (!app1) { + if (!styleSet->HasStateDependentStyle(aPresContext, aContent1, + aStateMask)) + { + primaryFrame1 = nsnull; aContent1 = nsnull; } } + } - nsIFrame* primaryFrame1 = nsnull; - nsIFrame* primaryFrame2 = nsnull; - PRUint8 app1 = 0; - PRUint8 app2 = 0; - - if (aContent1) { - shell->GetPrimaryFrameFor(aContent1, &primaryFrame1); - if (primaryFrame1) { - app1 = primaryFrame1->GetStyleDisplay()->mAppearance; - } - - // XXXldb Why check app1 here when you could just do the code - // below |if (app1)| above and avoid the extra style reresolution? - if (!app1) { - PRBool depends = PR_FALSE; - styleSet->HasStateDependentStyle(aPresContext, aContent1, - aStateMask, &depends); - if (!depends) { - primaryFrame1 = nsnull; - aContent1 = nsnull; - } - } - } - - if (aContent2) { - shell->GetPrimaryFrameFor(aContent2, &primaryFrame2); - if (primaryFrame2) { - app2 = primaryFrame2->GetStyleDisplay()->mAppearance; - } - - // XXXldb Why check app2 here when you could just do the code - // below |if (app2)| above and avoid the extra style reresolution? - if (!app2) { - PRBool depends = PR_FALSE; - styleSet->HasStateDependentStyle(aPresContext, aContent2, - aStateMask, &depends); - if (!depends) { - primaryFrame2 = nsnull; - aContent2 = nsnull; - } - } - } - - nsCOMPtr frameManager; - shell->GetFrameManager(getter_AddRefs(frameManager)); - - if (primaryFrame1) { - nsStyleChangeList changeList; - nsChangeHint frameChange = NS_STYLE_HINT_NONE; - frameManager->ComputeStyleChangeFor(primaryFrame1, - kNameSpaceID_Unknown, nsnull, - changeList, NS_STYLE_HINT_NONE, - frameChange); - - if (app1) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); - PRBool repaint = PR_FALSE; - if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame1, app1)) - theme->WidgetStateChanged(primaryFrame1, app1, nsnull, &repaint); - if (repaint) - ApplyRenderingChangeToTree(aPresContext, primaryFrame1, nsnull, nsChangeHint_RepaintFrame); - } - - if (frameChange & nsChangeHint_ReconstructDoc) { - return ReconstructDocElementHierarchy(aPresContext); - // No need to worry about anything else. - } - else if (frameChange & nsChangeHint_ReconstructFrame) { - result = RecreateFramesForContent(aPresContext, aContent1); - changeList.Clear(); - } else { - ProcessRestyledFrames(changeList, aPresContext); - } - } - + if (aContent2) { + shell->GetPrimaryFrameFor(aContent2, &primaryFrame2); if (primaryFrame2) { - nsStyleChangeList changeList; - nsChangeHint frameChange = NS_STYLE_HINT_NONE; - frameManager->ComputeStyleChangeFor(primaryFrame2, - kNameSpaceID_Unknown, nsnull, - changeList, NS_STYLE_HINT_NONE, frameChange); - if (app2) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); - PRBool repaint = PR_FALSE; - if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame2, app2)) - theme->WidgetStateChanged(primaryFrame2, app2, nsnull, &repaint); - if (repaint) - ApplyRenderingChangeToTree(aPresContext, primaryFrame2, nsnull, nsChangeHint_RepaintFrame); - } + app2 = primaryFrame2->GetStyleDisplay()->mAppearance; + } - // max change needed for top level frames - if (frameChange & nsChangeHint_ReconstructDoc) { - result = ReconstructDocElementHierarchy(aPresContext); - changeList.Clear(); - } else if (frameChange & nsChangeHint_ReconstructFrame) { - result = RecreateFramesForContent(aPresContext, aContent2); - changeList.Clear(); - } else { - // process any children that need it - ProcessRestyledFrames(changeList, aPresContext); + // XXXldb Why check app2 here when you could just do the code + // below |if (app2)| above and avoid the extra style reresolution? + if (!app2) { + if (!styleSet->HasStateDependentStyle(aPresContext, aContent2, + aStateMask)) + { + primaryFrame2 = nsnull; + aContent2 = nsnull; } } - - // no frames, reconstruct for content - if (!primaryFrame1 && aContent1) { - result = MaybeRecreateFramesForContent(aPresContext, aContent1); + } + + nsCOMPtr frameManager; + shell->GetFrameManager(getter_AddRefs(frameManager)); + + if (primaryFrame1) { + nsStyleChangeList changeList; + nsChangeHint frameChange = NS_STYLE_HINT_NONE; + frameManager->ComputeStyleChangeFor(primaryFrame1, + kNameSpaceID_Unknown, nsnull, + changeList, NS_STYLE_HINT_NONE, + frameChange); + + if (app1) { + nsCOMPtr theme; + aPresContext->GetTheme(getter_AddRefs(theme)); + PRBool repaint = PR_FALSE; + if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame1, app1)) + theme->WidgetStateChanged(primaryFrame1, app1, nsnull, &repaint); + if (repaint) + ApplyRenderingChangeToTree(aPresContext, primaryFrame1, nsnull, nsChangeHint_RepaintFrame); } - if (!primaryFrame2 && aContent2) { - result = MaybeRecreateFramesForContent(aPresContext, aContent2); + + if (frameChange & nsChangeHint_ReconstructDoc) { + return ReconstructDocElementHierarchy(aPresContext); + // No need to worry about anything else. } + else if (frameChange & nsChangeHint_ReconstructFrame) { + result = RecreateFramesForContent(aPresContext, aContent1); + changeList.Clear(); + } else { + ProcessRestyledFrames(changeList, aPresContext); + } + } + + if (primaryFrame2) { + nsStyleChangeList changeList; + nsChangeHint frameChange = NS_STYLE_HINT_NONE; + frameManager->ComputeStyleChangeFor(primaryFrame2, + kNameSpaceID_Unknown, nsnull, + changeList, NS_STYLE_HINT_NONE, frameChange); + if (app2) { + nsCOMPtr theme; + aPresContext->GetTheme(getter_AddRefs(theme)); + PRBool repaint = PR_FALSE; + if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame2, app2)) + theme->WidgetStateChanged(primaryFrame2, app2, nsnull, &repaint); + if (repaint) + ApplyRenderingChangeToTree(aPresContext, primaryFrame2, nsnull, nsChangeHint_RepaintFrame); + } + + // max change needed for top level frames + if (frameChange & nsChangeHint_ReconstructDoc) { + result = ReconstructDocElementHierarchy(aPresContext); + changeList.Clear(); + } else if (frameChange & nsChangeHint_ReconstructFrame) { + result = RecreateFramesForContent(aPresContext, aContent2); + changeList.Clear(); + } else { + // process any children that need it + ProcessRestyledFrames(changeList, aPresContext); + } + } + + // no frames, reconstruct for content + if (!primaryFrame1 && aContent1) { + result = MaybeRecreateFramesForContent(aPresContext, aContent1); + } + if (!primaryFrame2 && aContent2) { + result = MaybeRecreateFramesForContent(aPresContext, aContent2); } } return result; @@ -10615,7 +10591,7 @@ nsCSSFrameConstructor::CantRenderReplacedElement(nsIPresShell* aPresShell, } nsresult -nsCSSFrameConstructor::CreateContinuingOuterTableFrame(nsIPresShell* aPresShell, +nsCSSFrameConstructor::CreateContinuingOuterTableFrame(nsIPresShell* aPresShell, nsIPresContext* aPresContext, nsIFrame* aFrame, nsIFrame* aParentFrame, @@ -10644,7 +10620,7 @@ nsCSSFrameConstructor::CreateContinuingOuterTableFrame(nsIPresShell* aPresShell, nsIFrame* continuingTableFrame; // It's the inner table frame, so create a continuing frame - CreateContinuingFrame(aPresShell, aPresContext, childFrame, newFrame, &continuingTableFrame); + CreateContinuingFrame(aPresContext, childFrame, newFrame, &continuingTableFrame); newChildFrames.AddChild(continuingTableFrame); } else { // XXX remove this code and the above checks. We don't want to replicate @@ -10766,12 +10742,12 @@ nsCSSFrameConstructor::CreateContinuingTableFrame(nsIPresShell* aPresShell, } NS_IMETHODIMP -nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, - nsIPresContext* aPresContext, +nsCSSFrameConstructor::CreateContinuingFrame(nsIPresContext* aPresContext, nsIFrame* aFrame, nsIFrame* aParentFrame, nsIFrame** aContinuingFrame) { + nsIPresShell* shell = aPresContext->PresShell(); nsStyleContext* styleContext = aFrame->GetStyleContext(); nsIFrame* newFrame = nsnull; nsresult rv = NS_OK; @@ -10781,7 +10757,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, nsIContent* content = aFrame->GetContent(); if (nsLayoutAtoms::textFrame == frameType) { - rv = NS_NewContinuingTextFrame(aPresShell, &newFrame); + rv = NS_NewContinuingTextFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10789,7 +10765,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::inlineFrame == frameType) { - rv = NS_NewInlineFrame(aPresShell, &newFrame); + rv = NS_NewInlineFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10797,7 +10773,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::blockFrame == frameType) { - rv = NS_NewBlockFrame(aPresShell, &newFrame); + rv = NS_NewBlockFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10805,7 +10781,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::areaFrame == frameType) { - rv = NS_NewAreaFrame(aPresShell, &newFrame, 0); + rv = NS_NewAreaFrame(shell, &newFrame, 0); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); @@ -10814,7 +10790,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::positionedInlineFrame == frameType) { - rv = NS_NewPositionedInlineFrame(aPresShell, &newFrame); + rv = NS_NewPositionedInlineFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10823,18 +10799,18 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } else if (nsLayoutAtoms::pageFrame == frameType) { nsIFrame* pageContentFrame; - rv = ConstructPageFrame(aPresShell, aPresContext, aParentFrame, aFrame, + rv = ConstructPageFrame(shell, aPresContext, aParentFrame, aFrame, newFrame, pageContentFrame); } else if (nsLayoutAtoms::tableOuterFrame == frameType) { - rv = CreateContinuingOuterTableFrame(aPresShell, aPresContext, aFrame, aParentFrame, + rv = CreateContinuingOuterTableFrame(shell, aPresContext, aFrame, aParentFrame, content, styleContext, &newFrame); } else if (nsLayoutAtoms::tableFrame == frameType) { - rv = CreateContinuingTableFrame(aPresShell, aPresContext, aFrame, aParentFrame, + rv = CreateContinuingTableFrame(shell, aPresContext, aFrame, aParentFrame, content, styleContext, &newFrame); } else if (nsLayoutAtoms::tableRowGroupFrame == frameType) { - rv = NS_NewTableRowGroupFrame(aPresShell, &newFrame); + rv = NS_NewTableRowGroupFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10842,7 +10818,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::tableRowFrame == frameType) { - rv = NS_NewTableRowFrame(aPresShell, &newFrame); + rv = NS_NewTableRowFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10858,7 +10834,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, if (IS_TABLE_CELL(cellFrame->GetType())) { nsIFrame* continuingCellFrame; - CreateContinuingFrame(aPresShell, aPresContext, cellFrame, newFrame, &continuingCellFrame); + CreateContinuingFrame(aPresContext, cellFrame, newFrame, &continuingCellFrame); newChildList.AddChild(continuingCellFrame); } cellFrame = cellFrame->GetNextSibling(); @@ -10869,7 +10845,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (IS_TABLE_CELL(frameType)) { - rv = NS_NewTableCellFrame(aPresShell, IsBorderCollapse(aParentFrame), &newFrame); + rv = NS_NewTableCellFrame(shell, IsBorderCollapse(aParentFrame), &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10879,14 +10855,14 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, nsIFrame* areaFrame; nsIFrame* continuingAreaFrame; aFrame->FirstChild(aPresContext, nsnull, &areaFrame); - CreateContinuingFrame(aPresShell, aPresContext, areaFrame, newFrame, &continuingAreaFrame); + CreateContinuingFrame(aPresContext, areaFrame, newFrame, &continuingAreaFrame); // Set the table cell's initial child list newFrame->SetInitialChildList(aPresContext, nsnull, continuingAreaFrame); } } else if (nsLayoutAtoms::lineFrame == frameType) { - rv = NS_NewFirstLineFrame(aPresShell, &newFrame); + rv = NS_NewFirstLineFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10894,7 +10870,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::letterFrame == frameType) { - rv = NS_NewFirstLetterFrame(aPresShell, &newFrame); + rv = NS_NewFirstLetterFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); // XXXbz should we be passing in a non-null aContentParentFrame? @@ -10902,7 +10878,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, } } else if (nsLayoutAtoms::imageFrame == frameType) { - rv = NS_NewImageFrame(aPresShell, &newFrame); + rv = NS_NewImageFrame(shell, &newFrame); if (NS_SUCCEEDED(rv)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); } @@ -10910,14 +10886,14 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, // create a continuing out of flow frame nsIFrame* oofFrame = ((nsPlaceholderFrame*)aFrame)->GetOutOfFlowFrame(); nsIFrame* oofContFrame; - CreateContinuingFrame(aPresShell, aPresContext, oofFrame, aParentFrame, &oofContFrame); + CreateContinuingFrame(aPresContext, oofFrame, aParentFrame, &oofContFrame); if (!oofContFrame) return NS_ERROR_NULL_POINTER; // create a continuing placeholder frame nsCOMPtr frameManager; - aPresShell->GetFrameManager(getter_AddRefs(frameManager)); + shell->GetFrameManager(getter_AddRefs(frameManager)); NS_ASSERTION(frameManager, "no frame manager"); - CreatePlaceholderFrameFor(aPresShell, aPresContext, frameManager, content, + CreatePlaceholderFrameFor(shell, aPresContext, frameManager, content, oofContFrame, styleContext, aParentFrame, &newFrame); if (!newFrame) return NS_ERROR_NULL_POINTER; @@ -10982,7 +10958,7 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsIPresShell* aPresShell, // Iterate the fixed frames and replicate each for (nsIFrame* fixed = firstFixed; fixed; fixed = fixed->GetNextSibling()) { - rv = ConstructFrame(aPresShell, aPresContext, state, fixed->GetContent(), + rv = ConstructFrame(shell, aPresContext, state, fixed->GetContent(), newFrame, fixedPlaceholders); if (NS_FAILED(rv)) return rv; @@ -12071,7 +12047,7 @@ nsCSSFrameConstructor::CreateFloatingLetterFrame( nsIFrame* nextTextFrame = nsnull; if (NeedFirstLetterContinuation(aTextContent)) { // Create continuation - CreateContinuingFrame(aPresShell, aPresContext, aTextFrame, aParentFrame, + CreateContinuingFrame(aPresContext, aTextFrame, aParentFrame, &nextTextFrame); // Repair the continuations style context diff --git a/layout/base/nsCSSFrameConstructor.h b/layout/base/nsCSSFrameConstructor.h index f4daf31683c3..c67c3b46761d 100644 --- a/layout/base/nsCSSFrameConstructor.h +++ b/layout/base/nsCSSFrameConstructor.h @@ -149,8 +149,7 @@ public: nsIFrame* aFrame); // Request to create a continuing frame - NS_IMETHOD CreateContinuingFrame(nsIPresShell* aPresShell, - nsIPresContext* aPresContext, + NS_IMETHOD CreateContinuingFrame(nsIPresContext* aPresContext, nsIFrame* aFrame, nsIFrame* aParentFrame, nsIFrame** aContinuingFrame); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index adccf2c3e5fb..3e01343df941 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -53,7 +53,7 @@ #include "nsIDocument.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" #include "nsIStyleSheet.h" #include "nsICSSStyleSheet.h" #include "nsIFrame.h" @@ -195,7 +195,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsBidiUtils.h" static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); -static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); #ifdef NS_DEBUG @@ -640,8 +639,8 @@ nsresult DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow) { // Create the style set... - nsCOMPtr styleSet; - nsresult rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); + nsStyleSet *styleSet; + nsresult rv = CreateStyleSet(mDocument, &styleSet); NS_ENSURE_SUCCESS(rv, rv); // Now make the shell for the document @@ -1192,8 +1191,8 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) if (mPresContext) { // 3) Create a new style set for the document - nsCOMPtr styleSet; - rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); + nsStyleSet *styleSet; + rv = CreateStyleSet(mDocument, &styleSet); if (NS_FAILED(rv)) return rv; @@ -1587,79 +1586,83 @@ DocumentViewerImpl::ForceRefresh() nsresult DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, - nsIStyleSet** aStyleSet) + nsStyleSet** aStyleSet) { // this should eventually get expanded to allow for creating // different sets for different media - nsresult rv; - if (!mUAStyleSheet) { NS_WARNING("unable to load UA style sheet"); } - rv = CallCreateInstance(kStyleSetCID, aStyleSet); - if (NS_OK == rv) { - PRInt32 index = aDocument->GetNumberOfStyleSheets(PR_TRUE); + nsStyleSet *styleSet = new nsStyleSet(); + if (!styleSet) { + return NS_ERROR_OUT_OF_MEMORY; + } - while (0 < index--) { - nsIStyleSheet *sheet = aDocument->GetStyleSheetAt(index, PR_TRUE); + PRInt32 index = aDocument->GetNumberOfStyleSheets(PR_TRUE); - /* - * GetStyleSheetAt will return all style sheets in the document but - * we're only interested in the ones that are enabled. - */ + styleSet->BeginUpdate(); - PRBool styleApplicable; - sheet->GetApplicable(styleApplicable); + while (0 < index--) { + nsIStyleSheet *sheet = aDocument->GetStyleSheetAt(index, PR_TRUE); - if (styleApplicable) { - (*aStyleSet)->AddDocStyleSheet(sheet, aDocument); - } - } + /* + * GetStyleSheetAt will return all style sheets in the document but + * we're only interested in the ones that are enabled. + */ - nsCOMPtr chromeRegistry = - do_GetService("@mozilla.org/chrome/chrome-registry;1"); + PRBool styleApplicable; + sheet->GetApplicable(styleApplicable); - if (chromeRegistry) { - nsCOMPtr sheets; - - // Now handle the user sheets. - nsCOMPtr docShell(do_QueryInterface(mContainer)); - PRInt32 shellType; - docShell->GetItemType(&shellType); - PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); - sheets = nsnull; - chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); - if(sheets){ - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - // Insert the user sheets at the front of the user sheet list - // so that they are most significant user sheets. - for(PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); - (*aStyleSet)->InsertUserStyleSheetBefore(sheet, nsnull); - } - } - - // Append chrome sheets (scrollbars + forms). - nsCOMPtr ds(do_QueryInterface(mContainer)); - chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets)); - if(sheets){ - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - for(PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); - (*aStyleSet)->AppendAgentStyleSheet(sheet); - } - } - } - - if (mUAStyleSheet) { - (*aStyleSet)->AppendAgentStyleSheet(mUAStyleSheet); + if (styleApplicable) { + styleSet->AddDocStyleSheet(sheet, aDocument); } } + + nsCOMPtr chromeRegistry = + do_GetService("@mozilla.org/chrome/chrome-registry;1"); + + if (chromeRegistry) { + nsCOMPtr sheets; + + // Now handle the user sheets. + nsCOMPtr docShell(do_QueryInterface(mContainer)); + PRInt32 shellType; + docShell->GetItemType(&shellType); + PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); + chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); + if (sheets) { + nsCOMPtr sheet; + PRUint32 count; + sheets->Count(&count); + // Insert the user sheets at the front of the user sheet list + // so that they are most significant user sheets. + for (PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); + styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet); + } + } + + // Append chrome sheets (scrollbars + forms). + nsCOMPtr ds(do_QueryInterface(mContainer)); + chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets)); + if (sheets) { + nsCOMPtr sheet; + PRUint32 count; + sheets->Count(&count); + for (PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); + styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet); + } + } + } + + if (mUAStyleSheet) { + styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet); + } + + styleSet->EndUpdate(); + *aStyleSet = styleSet; return NS_OK; } diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index d8da0bfd0e8f..2909f6d4d7ff 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -33,7 +33,8 @@ #include "nsIFrame.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIStyleSet.h" +#include "nsStyleSet.h" +#include "nsIStyleFrameConstruction.h" #include "nsStyleContext.h" #include "nsStyleChangeList.h" #include "nsIEventQueueService.h" @@ -273,7 +274,7 @@ public: NS_DECL_ISUPPORTS // nsIFrameManager - NS_IMETHOD Init(nsIPresShell* aPresShell, nsIStyleSet* aStyleSet); + NS_IMETHOD Init(nsIPresShell* aPresShell, nsStyleSet* aStyleSet); NS_IMETHOD Destroy(); // Gets and sets the root frame @@ -392,10 +393,9 @@ private: nsIPresContext* GetPresContext() const { return mPresShell->GetPresContext(); } - nsIStyleSet* GetStyleSet() const { return mStyleSet; } nsIPresShell* mPresShell; // weak link, because the pres shell owns us - nsIStyleSet* mStyleSet; // weak link. pres shell holds a reference + nsStyleSet* mStyleSet; // weak link. pres shell holds a reference nsIFrame* mRootFrame; PLDHashTable mPrimaryFrameMap; PLDHashTable mPlaceholderMap; @@ -454,7 +454,7 @@ NS_IMPL_ISUPPORTS1(FrameManager, nsIFrameManager) NS_IMETHODIMP FrameManager::Init(nsIPresShell* aPresShell, - nsIStyleSet* aStyleSet) + nsStyleSet* aStyleSet) { NS_ASSERTION(aPresShell, "null aPresShell"); NS_ASSERTION(aStyleSet, "null aStyleSet"); @@ -596,16 +596,13 @@ FrameManager::GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aResult) // very fast in the embedded hash table. // This would almost completely remove the lookup penalty for things // like