From 2709b267b2dbf4b58d2fd23e759dbd8d12081fea Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Wed, 2 Dec 1998 00:39:10 +0000 Subject: [PATCH] added inline style sheet support for contained HTML git-svn-id: svn://10.0.0.236/trunk@15589 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xml/document/src/nsXMLDocument.cpp | 43 ++++++++++++++++++- .../content/xml/document/src/nsXMLDocument.h | 4 ++ .../layout/xml/document/src/nsXMLDocument.cpp | 43 ++++++++++++++++++- .../layout/xml/document/src/nsXMLDocument.h | 4 ++ 4 files changed, 90 insertions(+), 4 deletions(-) diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index b7eec8d213d..97cc4344ac8 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -32,6 +32,8 @@ #include "nsIHTMLContent.h" #include "nsHTMLParts.h" #include "nsIHTMLStyleSheet.h" +#include "nsIHTMLCSSStyleSheet.h" +#include "nsIStyleSet.h" #include "nsRepository.h" #include "nsIDOMComment.h" #include "nsIDOMElement.h" @@ -62,6 +64,7 @@ nsXMLDocument::nsXMLDocument() mParser = nsnull; mNameSpaces = nsnull; mAttrStyleSheet = nsnull; + mInlineStyleSheet = nsnull; mProlog = nsnull; mEpilog = nsnull; @@ -89,6 +92,10 @@ nsXMLDocument::~nsXMLDocument() mAttrStyleSheet->SetOwningDocument(nsnull); NS_RELEASE(mAttrStyleSheet); } + if (nsnull != mInlineStyleSheet) { + mInlineStyleSheet->SetOwningDocument(nsnull); + NS_RELEASE(mInlineStyleSheet); + } if (nsnull != mProlog) { delete mProlog; } @@ -143,6 +150,10 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl, mAttrStyleSheet->SetOwningDocument(nsnull); NS_RELEASE(mAttrStyleSheet); } + if (nsnull != mInlineStyleSheet) { + mInlineStyleSheet->SetOwningDocument(nsnull); + NS_RELEASE(mInlineStyleSheet); + } nsIWebShell* webShell; @@ -165,6 +176,9 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl, if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) { AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet } + if (NS_OK == NS_NewHTMLCSSStyleSheet(&mInlineStyleSheet, aUrl, this)) { + AddStyleSheet(mInlineStyleSheet); // tell the world about our new style sheet + } // Set the parser as the stream listener for the document loader... static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); @@ -194,8 +208,6 @@ nsXMLDocument::EndLoad() return nsDocument::EndLoad(); } -// XXX Currently a nsIHTMLDocument method. Should go into an interface -// implemented for XML documents that hold HTML content. NS_IMETHODIMP nsXMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) { @@ -213,6 +225,33 @@ nsXMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) return NS_OK; } +NS_IMETHODIMP +nsXMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult) +{ + NS_PRECONDITION(nsnull != aResult, "null ptr"); + if (nsnull == aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = mInlineStyleSheet; + if (nsnull == mInlineStyleSheet) { + return NS_ERROR_NOT_AVAILABLE; // probably not the right error... + } + else { + NS_ADDREF(mInlineStyleSheet); + } + return NS_OK; +} + +void nsXMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet) +{ + if ((nsnull != mInlineStyleSheet) && (aSheet != mInlineStyleSheet)) { + aSet->InsertDocStyleSheetAfter(aSheet, mInlineStyleSheet); + } + else { + aSet->InsertDocStyleSheetBefore(aSheet, nsnull); // put it in front + } +} + // nsIDOMDocument interface NS_IMETHODIMP nsXMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType) diff --git a/mozilla/content/xml/document/src/nsXMLDocument.h b/mozilla/content/xml/document/src/nsXMLDocument.h index 9915fd5a42d..2fe28ecb81e 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.h +++ b/mozilla/content/xml/document/src/nsXMLDocument.h @@ -80,11 +80,15 @@ public: // nsIHTMLContentContainer NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult); + NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult); protected: + void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); + // For HTML elements in our content model nsIHTMLStyleSheet* mAttrStyleSheet; + nsIHTMLCSSStyleSheet* mInlineStyleSheet; nsVoidArray *mProlog; nsVoidArray *mEpilog; diff --git a/mozilla/layout/xml/document/src/nsXMLDocument.cpp b/mozilla/layout/xml/document/src/nsXMLDocument.cpp index b7eec8d213d..97cc4344ac8 100644 --- a/mozilla/layout/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/layout/xml/document/src/nsXMLDocument.cpp @@ -32,6 +32,8 @@ #include "nsIHTMLContent.h" #include "nsHTMLParts.h" #include "nsIHTMLStyleSheet.h" +#include "nsIHTMLCSSStyleSheet.h" +#include "nsIStyleSet.h" #include "nsRepository.h" #include "nsIDOMComment.h" #include "nsIDOMElement.h" @@ -62,6 +64,7 @@ nsXMLDocument::nsXMLDocument() mParser = nsnull; mNameSpaces = nsnull; mAttrStyleSheet = nsnull; + mInlineStyleSheet = nsnull; mProlog = nsnull; mEpilog = nsnull; @@ -89,6 +92,10 @@ nsXMLDocument::~nsXMLDocument() mAttrStyleSheet->SetOwningDocument(nsnull); NS_RELEASE(mAttrStyleSheet); } + if (nsnull != mInlineStyleSheet) { + mInlineStyleSheet->SetOwningDocument(nsnull); + NS_RELEASE(mInlineStyleSheet); + } if (nsnull != mProlog) { delete mProlog; } @@ -143,6 +150,10 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl, mAttrStyleSheet->SetOwningDocument(nsnull); NS_RELEASE(mAttrStyleSheet); } + if (nsnull != mInlineStyleSheet) { + mInlineStyleSheet->SetOwningDocument(nsnull); + NS_RELEASE(mInlineStyleSheet); + } nsIWebShell* webShell; @@ -165,6 +176,9 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl, if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) { AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet } + if (NS_OK == NS_NewHTMLCSSStyleSheet(&mInlineStyleSheet, aUrl, this)) { + AddStyleSheet(mInlineStyleSheet); // tell the world about our new style sheet + } // Set the parser as the stream listener for the document loader... static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); @@ -194,8 +208,6 @@ nsXMLDocument::EndLoad() return nsDocument::EndLoad(); } -// XXX Currently a nsIHTMLDocument method. Should go into an interface -// implemented for XML documents that hold HTML content. NS_IMETHODIMP nsXMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) { @@ -213,6 +225,33 @@ nsXMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) return NS_OK; } +NS_IMETHODIMP +nsXMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult) +{ + NS_PRECONDITION(nsnull != aResult, "null ptr"); + if (nsnull == aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = mInlineStyleSheet; + if (nsnull == mInlineStyleSheet) { + return NS_ERROR_NOT_AVAILABLE; // probably not the right error... + } + else { + NS_ADDREF(mInlineStyleSheet); + } + return NS_OK; +} + +void nsXMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet) +{ + if ((nsnull != mInlineStyleSheet) && (aSheet != mInlineStyleSheet)) { + aSet->InsertDocStyleSheetAfter(aSheet, mInlineStyleSheet); + } + else { + aSet->InsertDocStyleSheetBefore(aSheet, nsnull); // put it in front + } +} + // nsIDOMDocument interface NS_IMETHODIMP nsXMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType) diff --git a/mozilla/layout/xml/document/src/nsXMLDocument.h b/mozilla/layout/xml/document/src/nsXMLDocument.h index 9915fd5a42d..2fe28ecb81e 100644 --- a/mozilla/layout/xml/document/src/nsXMLDocument.h +++ b/mozilla/layout/xml/document/src/nsXMLDocument.h @@ -80,11 +80,15 @@ public: // nsIHTMLContentContainer NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult); + NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult); protected: + void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); + // For HTML elements in our content model nsIHTMLStyleSheet* mAttrStyleSheet; + nsIHTMLCSSStyleSheet* mInlineStyleSheet; nsVoidArray *mProlog; nsVoidArray *mEpilog;