From c2ec1d4ec6a7943b08b8401929165b58b776bf5a Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 6 Aug 2002 05:08:47 +0000 Subject: [PATCH] dynamically adding @import rules does not trigger all the updates it should. Bug 160065, r=peterv, sr=dbaron git-svn-id: svn://10.0.0.236/trunk@126440 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/public/nsICSSStyleSheet.h | 3 + .../content/html/style/src/nsCSSLoader.cpp | 18 ++-- mozilla/content/html/style/src/nsCSSRules.cpp | 9 +- .../html/style/src/nsCSSStyleSheet.cpp | 87 ++++++++++++++++--- mozilla/layout/style/nsCSSLoader.cpp | 18 ++-- mozilla/layout/style/nsCSSRules.cpp | 9 +- mozilla/layout/style/nsCSSStyleSheet.cpp | 87 ++++++++++++++++--- mozilla/layout/style/nsICSSStyleSheet.h | 3 + 8 files changed, 200 insertions(+), 34 deletions(-) diff --git a/mozilla/content/html/style/public/nsICSSStyleSheet.h b/mozilla/content/html/style/public/nsICSSStyleSheet.h index 2bdb9658a0f..f81e36f8c92 100644 --- a/mozilla/content/html/style/public/nsICSSStyleSheet.h +++ b/mozilla/content/html/style/public/nsICSSStyleSheet.h @@ -47,6 +47,7 @@ class nsINameSpace; class nsICSSStyleRuleProcessor; class nsIMediaList; class nsICSSGroupRule; +class nsICSSImportRule; // IID for the nsICSSStyleSheet interface {8f83b0f0-b21a-11d1-8031-006008159b5a} #define NS_ICSS_STYLE_SHEET_IID \ @@ -79,6 +80,8 @@ public: NS_IMETHOD ClearMedia(void) = 0; NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode) = 0; + NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule) = 0; + // get head of namespace chain for sheet NS_IMETHOD GetNameSpace(nsINameSpace*& aNameSpace) const = 0; // set default namespace for sheet (may be overridden by @namespace) diff --git a/mozilla/content/html/style/src/nsCSSLoader.cpp b/mozilla/content/html/style/src/nsCSSLoader.cpp index e07e508250d..e9d4fe74177 100644 --- a/mozilla/content/html/style/src/nsCSSLoader.cpp +++ b/mozilla/content/html/style/src/nsCSSLoader.cpp @@ -877,7 +877,7 @@ CSSLoaderImpl::Cleanup(URLKey& aKey, SheetLoadData* aLoadData) do { if (data->mParentData) { if (0 == --(data->mParentData->mPendingChildren)) { // all children are done, handle parent - NS_ASSERTION(data->mParentSheet, "bug"); + NS_ASSERTION(data->mParentSheet, "Parent load data exists, but parent sheet does not"); if (! data->mSyncLoad) { SheetComplete(data->mParentSheet, data->mParentData); } @@ -977,7 +977,16 @@ CSSLoaderImpl::SheetComplete(nsICSSStyleSheet* aSheet, SheetLoadData* aLoadData) if (data->mParentSheet) { // is child sheet InsertChildSheet(aSheet, data->mParentSheet, data->mSheetIndex); if (data->mParentRule) { // we have the @import rule that loaded this sheet - data->mParentRule->SetSheet(aSheet); + data->mParentRule->SetSheet(aSheet); + if (!data->mParentData) { + // No parent load data; this must be an @import rule being + // inserted via the DOM. Let the parent sheet know that + // it's done. + nsCOMPtr loaderObserver(do_QueryInterface(data->mParentSheet)); + if (loaderObserver) { + loaderObserver->StyleSheetLoaded(aSheet, PR_TRUE); + } + } } } else if (data->mIsAgent) { // is agent sheet @@ -1628,8 +1637,8 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet, } if (sheet) { // already have one loaded and unmodified - nsICSSStyleSheet* clone = nsnull; - result = sheet->Clone(clone); + nsCOMPtr clone; + result = sheet->Clone(*getter_AddRefs(clone)); if (NS_SUCCEEDED(result)) { result = SetMedia(clone, aMedia); if (NS_SUCCEEDED(result)) { @@ -1638,7 +1647,6 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet, aParentRule->SetSheet(clone); } } - NS_RELEASE(clone); } } else { diff --git a/mozilla/content/html/style/src/nsCSSRules.cpp b/mozilla/content/html/style/src/nsCSSRules.cpp index 719b68c7869..6a9f7ad17f3 100644 --- a/mozilla/content/html/style/src/nsCSSRules.cpp +++ b/mozilla/content/html/style/src/nsCSSRules.cpp @@ -445,17 +445,23 @@ CSSImportRuleImpl::CSSImportRuleImpl(const CSSImportRuleImpl& aCopy) if (aCopy.mChildSheet) { aCopy.mChildSheet->Clone(*getter_AddRefs(mChildSheet)); + if (mChildSheet) { + mChildSheet->SetOwnerRule(this); + } } NS_NewMediaList(getter_AddRefs(mMedia)); if (aCopy.mMedia && mMedia) { - mMedia->AppendElement(aCopy.mMedia); + mMedia->AppendElement(aCopy.mMedia); } } CSSImportRuleImpl::~CSSImportRuleImpl(void) { + if (mChildSheet) { + mChildSheet->SetOwnerRule(nsnull); + } } NS_IMPL_ADDREF_INHERITED(CSSImportRuleImpl, nsCSSRule); @@ -594,6 +600,7 @@ CSSImportRuleImpl::SetSheet(nsICSSStyleSheet* aSheet) // set the new sheet mChildSheet = aSheet; + aSheet->SetOwnerRule(this); // set our medialist to be the same as the sheet's medialist nsCOMPtr sheet(do_QueryInterface(mChildSheet, &rv)); diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index 7ae6649d68b..a7ecbb6e5a8 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -80,6 +80,7 @@ #include "nsIDOMStyleSheetList.h" #include "nsIDOMCSSStyleSheet.h" #include "nsIDOMCSSStyleRule.h" +#include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSRuleList.h" #include "nsIDOMMediaList.h" #include "nsIDOMNode.h" @@ -87,6 +88,7 @@ #include "nsIPresShell.h" #include "nsICSSParser.h" #include "nsICSSLoader.h" +#include "nsICSSLoaderObserver.h" #include "nsRuleWalker.h" #include "nsCSSAtoms.h" #include "nsINameSpaceManager.h" @@ -815,7 +817,8 @@ class CSSRuleListImpl; class DOMMediaListImpl; class CSSStyleSheetImpl : public nsICSSStyleSheet, - public nsIDOMCSSStyleSheet + public nsIDOMCSSStyleSheet, + public nsICSSLoaderObserver { public: void* operator new(size_t size) CPP_THROW_NEW; @@ -850,6 +853,7 @@ public: NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const; NS_IMETHOD SetOwningDocument(nsIDocument* aDocument); NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode); + NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule); NS_IMETHOD GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor, nsIStyleRuleProcessor* aPrevProcessor); @@ -888,6 +892,8 @@ public: NS_IMETHOD IsModified(PRBool* aSheetModified) const; NS_IMETHOD SetModified(PRBool aModified); + NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify); + nsresult EnsureUniqueInner(void); #ifdef DEBUG @@ -924,12 +930,13 @@ protected: DOMMediaListImpl* mMedia; CSSStyleSheetImpl* mFirstChild; CSSStyleSheetImpl* mNext; - nsICSSStyleSheet* mParent; + nsICSSStyleSheet* mParent; // weak ref + nsICSSImportRule* mOwnerRule; // weak ref CSSImportsCollectionImpl* mImportsCollection; CSSRuleListImpl* mRuleCollection; nsIDocument* mDocument; - nsIDOMNode* mOwningNode; + nsIDOMNode* mOwningNode; // weak ref PRBool mDisabled; PRBool mDirty; // has been modified @@ -1765,6 +1772,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl() mFirstChild(nsnull), mNext(nsnull), mParent(nsnull), + mOwnerRule(nsnull), mImportsCollection(nsnull), mRuleCollection(nsnull), mDocument(nsnull), @@ -1785,6 +1793,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy) mFirstChild(nsnull), mNext(nsnull), mParent(aCopy.mParent), + mOwnerRule(aCopy.mOwnerRule), mImportsCollection(nsnull), // re-created lazily mRuleCollection(nsnull), // re-created lazily mDocument(aCopy.mDocument), @@ -1866,6 +1875,7 @@ NS_INTERFACE_MAP_BEGIN(CSSStyleSheetImpl) NS_INTERFACE_MAP_ENTRY(nsIStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleSheet) NS_INTERFACE_MAP_END @@ -2109,6 +2119,13 @@ CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode) return NS_OK; } +NS_IMETHODIMP +CSSStyleSheetImpl::SetOwnerRule(nsICSSImportRule* aOwnerRule) +{ // not ref counted + mOwnerRule = aOwnerRule; + return NS_OK; +} + NS_IMETHODIMP CSSStyleSheetImpl::ContainsStyleSheet(nsIURI* aURL, PRBool& aContains, nsIStyleSheet** aTheChild /*=nsnull*/) { @@ -2767,13 +2784,12 @@ CSSStyleSheetImpl::GetMedia(nsIDOMMediaList** aMedia) NS_IMETHODIMP CSSStyleSheetImpl::GetOwnerRule(nsIDOMCSSRule** aOwnerRule) { - NS_ENSURE_ARG_POINTER(aOwnerRule); + if (mOwnerRule) { + return CallQueryInterface(mOwnerRule, aOwnerRule); + } + *aOwnerRule = nsnull; - - // TBI: This should return the owner rule once the style system knows about - // owning rules... - - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -2976,8 +2992,20 @@ CSSStyleSheetImpl::InsertRule(const nsAString& aRule, else { CheckRuleForAttributes(cssRule); } - - if (mDocument) { + + // We don't notify immediately for @import rules, but rather when + // the sheet the rule is importing is loaded + PRBool notify = PR_TRUE; + if (type == nsICSSRule::IMPORT_RULE) { + nsCOMPtr importRule(do_QueryInterface(cssRule)); + NS_ASSERTION(importRule, "Rule which has type IMPORT_RULE and does not implement nsIDOMCSSImportRule!"); + nsCOMPtr childSheet; + importRule->GetStyleSheet(getter_AddRefs(childSheet)); + if (!childSheet) { + notify = PR_FALSE; + } + } + if (mDocument && notify) { result = mDocument->StyleRuleAdded(this, cssRule); NS_ENSURE_SUCCESS(result, result); } @@ -3168,6 +3196,43 @@ CSSStyleSheetImpl::InsertRuleIntoGroup(const nsAString & aRule, nsICSSGroupRule* return NS_OK; } +// nsICSSLoaderObserver implementation +NS_IMETHODIMP +CSSStyleSheetImpl::StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify) +{ +#ifdef DEBUG + nsCOMPtr styleSheet(do_QueryInterface(aSheet)); + NS_ASSERTION(styleSheet, "Sheet not implementing nsIStyleSheet!\n"); + nsCOMPtr parentSheet; + aSheet->GetParentSheet(*getter_AddRefs(parentSheet)); + nsCOMPtr thisSheet; + QueryInterface(NS_GET_IID(nsIStyleSheet), getter_AddRefs(thisSheet)); + NS_ASSERTION(thisSheet == parentSheet, "We are being notified of a sheet load for a sheet that is not our child!\n"); +#endif + + if (mDocument && aNotify) { + nsCOMPtr domSheet(do_QueryInterface(aSheet)); + NS_ENSURE_TRUE(domSheet, NS_ERROR_UNEXPECTED); + + nsCOMPtr ownerRule; + domSheet->GetOwnerRule(getter_AddRefs(ownerRule)); + NS_ENSURE_TRUE(ownerRule, NS_ERROR_UNEXPECTED); + + nsresult rv = mDocument->BeginUpdate(); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr styleRule(do_QueryInterface(ownerRule)); + + rv = mDocument->StyleRuleAdded(this, styleRule); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDocument->EndUpdate(); + NS_ENSURE_SUCCESS(rv, rv); + } + + return NS_OK; +} + // XXX for backwards compatibility and convenience NS_EXPORT nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL) diff --git a/mozilla/layout/style/nsCSSLoader.cpp b/mozilla/layout/style/nsCSSLoader.cpp index e07e508250d..e9d4fe74177 100644 --- a/mozilla/layout/style/nsCSSLoader.cpp +++ b/mozilla/layout/style/nsCSSLoader.cpp @@ -877,7 +877,7 @@ CSSLoaderImpl::Cleanup(URLKey& aKey, SheetLoadData* aLoadData) do { if (data->mParentData) { if (0 == --(data->mParentData->mPendingChildren)) { // all children are done, handle parent - NS_ASSERTION(data->mParentSheet, "bug"); + NS_ASSERTION(data->mParentSheet, "Parent load data exists, but parent sheet does not"); if (! data->mSyncLoad) { SheetComplete(data->mParentSheet, data->mParentData); } @@ -977,7 +977,16 @@ CSSLoaderImpl::SheetComplete(nsICSSStyleSheet* aSheet, SheetLoadData* aLoadData) if (data->mParentSheet) { // is child sheet InsertChildSheet(aSheet, data->mParentSheet, data->mSheetIndex); if (data->mParentRule) { // we have the @import rule that loaded this sheet - data->mParentRule->SetSheet(aSheet); + data->mParentRule->SetSheet(aSheet); + if (!data->mParentData) { + // No parent load data; this must be an @import rule being + // inserted via the DOM. Let the parent sheet know that + // it's done. + nsCOMPtr loaderObserver(do_QueryInterface(data->mParentSheet)); + if (loaderObserver) { + loaderObserver->StyleSheetLoaded(aSheet, PR_TRUE); + } + } } } else if (data->mIsAgent) { // is agent sheet @@ -1628,8 +1637,8 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet, } if (sheet) { // already have one loaded and unmodified - nsICSSStyleSheet* clone = nsnull; - result = sheet->Clone(clone); + nsCOMPtr clone; + result = sheet->Clone(*getter_AddRefs(clone)); if (NS_SUCCEEDED(result)) { result = SetMedia(clone, aMedia); if (NS_SUCCEEDED(result)) { @@ -1638,7 +1647,6 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet, aParentRule->SetSheet(clone); } } - NS_RELEASE(clone); } } else { diff --git a/mozilla/layout/style/nsCSSRules.cpp b/mozilla/layout/style/nsCSSRules.cpp index 719b68c7869..6a9f7ad17f3 100644 --- a/mozilla/layout/style/nsCSSRules.cpp +++ b/mozilla/layout/style/nsCSSRules.cpp @@ -445,17 +445,23 @@ CSSImportRuleImpl::CSSImportRuleImpl(const CSSImportRuleImpl& aCopy) if (aCopy.mChildSheet) { aCopy.mChildSheet->Clone(*getter_AddRefs(mChildSheet)); + if (mChildSheet) { + mChildSheet->SetOwnerRule(this); + } } NS_NewMediaList(getter_AddRefs(mMedia)); if (aCopy.mMedia && mMedia) { - mMedia->AppendElement(aCopy.mMedia); + mMedia->AppendElement(aCopy.mMedia); } } CSSImportRuleImpl::~CSSImportRuleImpl(void) { + if (mChildSheet) { + mChildSheet->SetOwnerRule(nsnull); + } } NS_IMPL_ADDREF_INHERITED(CSSImportRuleImpl, nsCSSRule); @@ -594,6 +600,7 @@ CSSImportRuleImpl::SetSheet(nsICSSStyleSheet* aSheet) // set the new sheet mChildSheet = aSheet; + aSheet->SetOwnerRule(this); // set our medialist to be the same as the sheet's medialist nsCOMPtr sheet(do_QueryInterface(mChildSheet, &rv)); diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index 7ae6649d68b..a7ecbb6e5a8 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -80,6 +80,7 @@ #include "nsIDOMStyleSheetList.h" #include "nsIDOMCSSStyleSheet.h" #include "nsIDOMCSSStyleRule.h" +#include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSRuleList.h" #include "nsIDOMMediaList.h" #include "nsIDOMNode.h" @@ -87,6 +88,7 @@ #include "nsIPresShell.h" #include "nsICSSParser.h" #include "nsICSSLoader.h" +#include "nsICSSLoaderObserver.h" #include "nsRuleWalker.h" #include "nsCSSAtoms.h" #include "nsINameSpaceManager.h" @@ -815,7 +817,8 @@ class CSSRuleListImpl; class DOMMediaListImpl; class CSSStyleSheetImpl : public nsICSSStyleSheet, - public nsIDOMCSSStyleSheet + public nsIDOMCSSStyleSheet, + public nsICSSLoaderObserver { public: void* operator new(size_t size) CPP_THROW_NEW; @@ -850,6 +853,7 @@ public: NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const; NS_IMETHOD SetOwningDocument(nsIDocument* aDocument); NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode); + NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule); NS_IMETHOD GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor, nsIStyleRuleProcessor* aPrevProcessor); @@ -888,6 +892,8 @@ public: NS_IMETHOD IsModified(PRBool* aSheetModified) const; NS_IMETHOD SetModified(PRBool aModified); + NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify); + nsresult EnsureUniqueInner(void); #ifdef DEBUG @@ -924,12 +930,13 @@ protected: DOMMediaListImpl* mMedia; CSSStyleSheetImpl* mFirstChild; CSSStyleSheetImpl* mNext; - nsICSSStyleSheet* mParent; + nsICSSStyleSheet* mParent; // weak ref + nsICSSImportRule* mOwnerRule; // weak ref CSSImportsCollectionImpl* mImportsCollection; CSSRuleListImpl* mRuleCollection; nsIDocument* mDocument; - nsIDOMNode* mOwningNode; + nsIDOMNode* mOwningNode; // weak ref PRBool mDisabled; PRBool mDirty; // has been modified @@ -1765,6 +1772,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl() mFirstChild(nsnull), mNext(nsnull), mParent(nsnull), + mOwnerRule(nsnull), mImportsCollection(nsnull), mRuleCollection(nsnull), mDocument(nsnull), @@ -1785,6 +1793,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy) mFirstChild(nsnull), mNext(nsnull), mParent(aCopy.mParent), + mOwnerRule(aCopy.mOwnerRule), mImportsCollection(nsnull), // re-created lazily mRuleCollection(nsnull), // re-created lazily mDocument(aCopy.mDocument), @@ -1866,6 +1875,7 @@ NS_INTERFACE_MAP_BEGIN(CSSStyleSheetImpl) NS_INTERFACE_MAP_ENTRY(nsIStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleSheet) NS_INTERFACE_MAP_END @@ -2109,6 +2119,13 @@ CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode) return NS_OK; } +NS_IMETHODIMP +CSSStyleSheetImpl::SetOwnerRule(nsICSSImportRule* aOwnerRule) +{ // not ref counted + mOwnerRule = aOwnerRule; + return NS_OK; +} + NS_IMETHODIMP CSSStyleSheetImpl::ContainsStyleSheet(nsIURI* aURL, PRBool& aContains, nsIStyleSheet** aTheChild /*=nsnull*/) { @@ -2767,13 +2784,12 @@ CSSStyleSheetImpl::GetMedia(nsIDOMMediaList** aMedia) NS_IMETHODIMP CSSStyleSheetImpl::GetOwnerRule(nsIDOMCSSRule** aOwnerRule) { - NS_ENSURE_ARG_POINTER(aOwnerRule); + if (mOwnerRule) { + return CallQueryInterface(mOwnerRule, aOwnerRule); + } + *aOwnerRule = nsnull; - - // TBI: This should return the owner rule once the style system knows about - // owning rules... - - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -2976,8 +2992,20 @@ CSSStyleSheetImpl::InsertRule(const nsAString& aRule, else { CheckRuleForAttributes(cssRule); } - - if (mDocument) { + + // We don't notify immediately for @import rules, but rather when + // the sheet the rule is importing is loaded + PRBool notify = PR_TRUE; + if (type == nsICSSRule::IMPORT_RULE) { + nsCOMPtr importRule(do_QueryInterface(cssRule)); + NS_ASSERTION(importRule, "Rule which has type IMPORT_RULE and does not implement nsIDOMCSSImportRule!"); + nsCOMPtr childSheet; + importRule->GetStyleSheet(getter_AddRefs(childSheet)); + if (!childSheet) { + notify = PR_FALSE; + } + } + if (mDocument && notify) { result = mDocument->StyleRuleAdded(this, cssRule); NS_ENSURE_SUCCESS(result, result); } @@ -3168,6 +3196,43 @@ CSSStyleSheetImpl::InsertRuleIntoGroup(const nsAString & aRule, nsICSSGroupRule* return NS_OK; } +// nsICSSLoaderObserver implementation +NS_IMETHODIMP +CSSStyleSheetImpl::StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify) +{ +#ifdef DEBUG + nsCOMPtr styleSheet(do_QueryInterface(aSheet)); + NS_ASSERTION(styleSheet, "Sheet not implementing nsIStyleSheet!\n"); + nsCOMPtr parentSheet; + aSheet->GetParentSheet(*getter_AddRefs(parentSheet)); + nsCOMPtr thisSheet; + QueryInterface(NS_GET_IID(nsIStyleSheet), getter_AddRefs(thisSheet)); + NS_ASSERTION(thisSheet == parentSheet, "We are being notified of a sheet load for a sheet that is not our child!\n"); +#endif + + if (mDocument && aNotify) { + nsCOMPtr domSheet(do_QueryInterface(aSheet)); + NS_ENSURE_TRUE(domSheet, NS_ERROR_UNEXPECTED); + + nsCOMPtr ownerRule; + domSheet->GetOwnerRule(getter_AddRefs(ownerRule)); + NS_ENSURE_TRUE(ownerRule, NS_ERROR_UNEXPECTED); + + nsresult rv = mDocument->BeginUpdate(); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr styleRule(do_QueryInterface(ownerRule)); + + rv = mDocument->StyleRuleAdded(this, styleRule); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDocument->EndUpdate(); + NS_ENSURE_SUCCESS(rv, rv); + } + + return NS_OK; +} + // XXX for backwards compatibility and convenience NS_EXPORT nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL) diff --git a/mozilla/layout/style/nsICSSStyleSheet.h b/mozilla/layout/style/nsICSSStyleSheet.h index 2bdb9658a0f..f81e36f8c92 100644 --- a/mozilla/layout/style/nsICSSStyleSheet.h +++ b/mozilla/layout/style/nsICSSStyleSheet.h @@ -47,6 +47,7 @@ class nsINameSpace; class nsICSSStyleRuleProcessor; class nsIMediaList; class nsICSSGroupRule; +class nsICSSImportRule; // IID for the nsICSSStyleSheet interface {8f83b0f0-b21a-11d1-8031-006008159b5a} #define NS_ICSS_STYLE_SHEET_IID \ @@ -79,6 +80,8 @@ public: NS_IMETHOD ClearMedia(void) = 0; NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode) = 0; + NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule) = 0; + // get head of namespace chain for sheet NS_IMETHOD GetNameSpace(nsINameSpace*& aNameSpace) const = 0; // set default namespace for sheet (may be overridden by @namespace)