added css loader support

added insert style sheet support
This commit is contained in:
peterl%netscape.com 1999-05-18 23:06:31 +00:00
parent e267a57f71
commit 6c1f985d9f
4 changed files with 42 additions and 66 deletions

View File

@ -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<nsIStyleSet> 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)

View File

@ -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;

View File

@ -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<nsIStyleSet> 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)

View File

@ -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;