From 77dcc5b017488cf47aa309c6f2c4340bb7fb7623 Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Tue, 18 May 1999 23:06:31 +0000 Subject: [PATCH] added css loader support added insert style sheet support git-svn-id: svn://10.0.0.236/trunk@32140 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLDocument.cpp | 48 +++++++------------ .../html/document/src/nsHTMLDocument.h | 6 ++- .../html/document/src/nsHTMLDocument.cpp | 48 +++++++------------ .../layout/html/document/src/nsHTMLDocument.h | 6 ++- 4 files changed, 42 insertions(+), 66 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index ec4f0cb3216..61b7ecd2a07 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -53,6 +53,7 @@ #include "nsIDOMHTMLBodyElement.h" #include "nsINameSpaceManager.h" #include "nsGenericDOMNodeList.h" +#include "nsICSSLoader.h" #ifdef PCB_USE_PROTOCOL_CONNECTION // beard: how else would we get the referrer to a URL? @@ -118,6 +119,7 @@ nsHTMLDocument::nsHTMLDocument() mParser = nsnull; nsHTMLAtoms::AddrefAtoms(); mDTDMode = eDTDMode_NoQuirks; + mCSSLoader = nsnull; // Find/Search Init mSearchStr = nsnull; @@ -168,6 +170,7 @@ nsHTMLDocument::~nsHTMLDocument() NS_RELEASE(map); } NS_IF_RELEASE(mForms); + NS_IF_RELEASE(mCSSLoader); // XXX don't bother doing this until the dll is unloaded??? // nsHTMLAtoms::ReleaseAtoms(); @@ -503,39 +506,10 @@ void nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass h } } -NS_IMETHODIMP -nsHTMLDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) +void +nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) { - NS_PRECONDITION(nsnull != aSheet, "null ptr"); mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset one for the attr style sheet - - NS_ADDREF(aSheet); - aSheet->SetOwningDocument(this); - - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); - - PRInt32 count; - PRInt32 index; - if (enabled) { - count = mPresShells.Count(); - for (index = 0; index < count; index++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index); - nsCOMPtr set; - shell->GetStyleSet(getter_AddRefs(set)); - if (set) { - set->AddDocStyleSheet(aSheet, this); - } - } - } - if (aNotify) { // notify here even if disabled, there may have been others that weren't notified - count = mObservers.Count(); - for (index = 0; index < count; index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetAdded(this, aSheet); - } - } - return NS_OK; } @@ -604,6 +578,18 @@ nsHTMLDocument:: SetBaseTarget(const nsString& aTarget) return NS_OK; } +NS_IMETHODIMP +nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader) +{ + nsresult result = NS_OK; + if (! mCSSLoader) { + result = NS_NewCSSLoader(this, &mCSSLoader); + } + aLoader = mCSSLoader; + NS_IF_ADDREF(aLoader); + return result; +} + NS_IMETHODIMP nsHTMLDocument::GetDTDMode(nsDTDMode& aMode) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index bf0c972bf1d..b285496b3da 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -34,6 +34,7 @@ class nsIHTMLStyleSheet; class nsIHTMLCSSStyleSheet; class nsIParser; class BlockText; +class nsICSSLoader; class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, @@ -68,8 +69,7 @@ public: NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet); NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aStyleSheet); - - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify); + NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader); NS_IMETHOD GetBaseURL(nsIURL*& aURL) const; NS_IMETHOD SetBaseURL(const nsString& aURLSpec); @@ -165,6 +165,7 @@ protected: nsIContent *MatchName(nsIContent *aContent, const nsString& aName); virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); + virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); static PRBool MatchLinks(nsIContent *aContent, nsString* aData); static PRBool MatchAnchors(nsIContent *aContent, nsString* aData); static PRBool MatchLayers(nsIContent *aContent, nsString* aData); @@ -186,6 +187,7 @@ protected: nsString* mBaseTarget; nsDTDMode mDTDMode; nsVoidArray mImageMaps; + nsICSSLoader* mCSSLoader; nsContentList *mImages; nsContentList *mApplets; diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index ec4f0cb3216..61b7ecd2a07 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -53,6 +53,7 @@ #include "nsIDOMHTMLBodyElement.h" #include "nsINameSpaceManager.h" #include "nsGenericDOMNodeList.h" +#include "nsICSSLoader.h" #ifdef PCB_USE_PROTOCOL_CONNECTION // beard: how else would we get the referrer to a URL? @@ -118,6 +119,7 @@ nsHTMLDocument::nsHTMLDocument() mParser = nsnull; nsHTMLAtoms::AddrefAtoms(); mDTDMode = eDTDMode_NoQuirks; + mCSSLoader = nsnull; // Find/Search Init mSearchStr = nsnull; @@ -168,6 +170,7 @@ nsHTMLDocument::~nsHTMLDocument() NS_RELEASE(map); } NS_IF_RELEASE(mForms); + NS_IF_RELEASE(mCSSLoader); // XXX don't bother doing this until the dll is unloaded??? // nsHTMLAtoms::ReleaseAtoms(); @@ -503,39 +506,10 @@ void nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass h } } -NS_IMETHODIMP -nsHTMLDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) +void +nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) { - NS_PRECONDITION(nsnull != aSheet, "null ptr"); mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset one for the attr style sheet - - NS_ADDREF(aSheet); - aSheet->SetOwningDocument(this); - - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); - - PRInt32 count; - PRInt32 index; - if (enabled) { - count = mPresShells.Count(); - for (index = 0; index < count; index++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index); - nsCOMPtr set; - shell->GetStyleSet(getter_AddRefs(set)); - if (set) { - set->AddDocStyleSheet(aSheet, this); - } - } - } - if (aNotify) { // notify here even if disabled, there may have been others that weren't notified - count = mObservers.Count(); - for (index = 0; index < count; index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetAdded(this, aSheet); - } - } - return NS_OK; } @@ -604,6 +578,18 @@ nsHTMLDocument:: SetBaseTarget(const nsString& aTarget) return NS_OK; } +NS_IMETHODIMP +nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader) +{ + nsresult result = NS_OK; + if (! mCSSLoader) { + result = NS_NewCSSLoader(this, &mCSSLoader); + } + aLoader = mCSSLoader; + NS_IF_ADDREF(aLoader); + return result; +} + NS_IMETHODIMP nsHTMLDocument::GetDTDMode(nsDTDMode& aMode) diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.h b/mozilla/layout/html/document/src/nsHTMLDocument.h index bf0c972bf1d..b285496b3da 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsHTMLDocument.h @@ -34,6 +34,7 @@ class nsIHTMLStyleSheet; class nsIHTMLCSSStyleSheet; class nsIParser; class BlockText; +class nsICSSLoader; class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, @@ -68,8 +69,7 @@ public: NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet); NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aStyleSheet); - - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify); + NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader); NS_IMETHOD GetBaseURL(nsIURL*& aURL) const; NS_IMETHOD SetBaseURL(const nsString& aURLSpec); @@ -165,6 +165,7 @@ protected: nsIContent *MatchName(nsIContent *aContent, const nsString& aName); virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); + virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); static PRBool MatchLinks(nsIContent *aContent, nsString* aData); static PRBool MatchAnchors(nsIContent *aContent, nsString* aData); static PRBool MatchLayers(nsIContent *aContent, nsString* aData); @@ -186,6 +187,7 @@ protected: nsString* mBaseTarget; nsDTDMode mDTDMode; nsVoidArray mImageMaps; + nsICSSLoader* mCSSLoader; nsContentList *mImages; nsContentList *mApplets;