Move the methods for handling inline style and attribute style sheets up to

nsDocument.  Bug 230947, r+sr=jst
This commit is contained in:
bzbarsky%mit.edu 2004-01-22 03:35:09 +00:00
Родитель bbe0e03d7d
Коммит cdb84804de
10 изменённых файлов: 64 добавлений и 171 удалений

Просмотреть файл

@ -535,6 +535,9 @@ public:
}
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0;
/**
* Reset this document to aURI and aLoadGroup. aURI must not be null.
*/
virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup) = 0;
virtual void AddReference(void *aKey, nsISupports *aReference) = 0;

Просмотреть файл

@ -683,6 +683,7 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
void
nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
{
NS_PRECONDITION(aURI, "Null URI passed to ResetToURI");
mDocumentTitle.Truncate();
mPrincipal = nsnull;
@ -707,24 +708,9 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
}
mChildren.Clear();
// The stylesheets should forget us
PRInt32 indx = mStyleSheets.Count();
while (--indx >= 0) {
nsIStyleSheet* sheet = mStyleSheets[indx];
sheet->SetOwningDocument(nsnull);
PRBool applicable;
sheet->GetApplicable(applicable);
if (applicable) {
RemoveStyleSheetFromStyleSets(sheet);
}
// XXX Tell observers?
}
// Release all the sheets
mStyleSheets.Clear();
// Reset our stylesheets
ResetStylesheetsToURI(aURI);
// Release the listener manager
mListenerManager = nsnull;
@ -744,10 +730,60 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
mLastModified.Truncate();
mContentType.Truncate();
mContentLanguage.Truncate();
mBaseTarget.Truncate();
mXMLDeclarationBits = 0;
}
nsresult
nsDocument::ResetStylesheetsToURI(nsIURI* aURI)
{
NS_PRECONDITION(aURI, "Null URI passed to ResetStylesheetsToURI");
// The stylesheets should forget us
PRInt32 indx = mStyleSheets.Count();
while (--indx >= 0) {
nsIStyleSheet* sheet = mStyleSheets[indx];
sheet->SetOwningDocument(nsnull);
PRBool applicable;
sheet->GetApplicable(applicable);
if (applicable) {
RemoveStyleSheetFromStyleSets(sheet);
}
// XXX Tell observers?
}
// Release all the sheets
mStyleSheets.Clear();
// Now reset our inline style and attribute sheets. Note that we
// already set their owning document to null in the loop above, but
// we'll reset it when we call AddStyleSheet on them.
nsresult rv;
if (mAttrStyleSheet) {
rv = mAttrStyleSheet->Reset(aURI);
} else {
rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURI, this);
}
NS_ENSURE_SUCCESS(rv, rv);
AddStyleSheet(mAttrStyleSheet, 0);
if (mStyleAttrStyleSheet) {
rv = mStyleAttrStyleSheet->Reset(aURI);
} else {
rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), aURI,
this);
}
NS_ENSURE_SUCCESS(rv, rv);
AddStyleSheet(mStyleAttrStyleSheet, 0);
return rv;
}
nsresult
nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
@ -870,12 +906,13 @@ nsDocument::SetBaseURI(nsIURI* aURI)
void
nsDocument::GetBaseTarget(nsAString &aBaseTarget) const
{
aBaseTarget.Truncate();
aBaseTarget.Assign(mBaseTarget);
}
void
nsDocument::SetBaseTarget(const nsAString &aBaseTarget)
{
mBaseTarget.Assign(aBaseTarget);
}
void

Просмотреть файл

@ -563,6 +563,8 @@ protected:
nsCompatibility aCompatMode,
nsIPresShell** aInstancePtrResult);
nsresult ResetStylesheetsToURI(nsIURI* aURI);
nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult);
nsDocument();
@ -614,6 +616,8 @@ protected:
nsCOMPtr<nsIScriptEventManager> mScriptEventManager;
nsString mBaseTarget;
private:
nsresult IsAllowedAsChild(PRUint16 aNodeType, nsIContent* aRefContent);

Просмотреть файл

@ -380,13 +380,7 @@ nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
mLoadFlags = nsIRequest::LOAD_NORMAL;
nsDocument::ResetToURI(aURI, aLoadGroup);
BaseResetToURI(aURI);
}
void
nsHTMLDocument::BaseResetToURI(nsIURI *aURI)
{
nsresult rv = NS_OK;
InvalidateHashTables();
@ -403,38 +397,11 @@ nsHTMLDocument::BaseResetToURI(nsIURI *aURI)
mImageMaps.Clear();
mForms = nsnull;
if (aURI) {
if (!mAttrStyleSheet) {
rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURI, this);
}
else {
rv = mAttrStyleSheet->Reset(aURI);
}
if (NS_SUCCEEDED(rv)) {
// tell the world about our new style sheet
AddStyleSheet(mAttrStyleSheet, 0);
if (!mStyleAttrStyleSheet) {
rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet),
aURI, this);
}
else {
rv = mStyleAttrStyleSheet->Reset(aURI);
}
if (NS_SUCCEEDED(rv)) {
// tell the world about our new style sheet
AddStyleSheet(mStyleAttrStyleSheet, 0);
}
}
}
NS_ASSERTION(!mWyciwygChannel,
"nsHTMLDocument::Reset() - Wyciwyg Channel still exists!");
mWyciwygChannel = nsnull;
mBaseTarget.Truncate();
// Make the content type default to "text/html", we are a HTML
// document, after all. Once we start getting data, this may be
// changed.
@ -1233,18 +1200,6 @@ nsHTMLDocument::InternalGetNumberOfStyleSheets() const
return count;
}
void
nsHTMLDocument::GetBaseTarget(nsAString& aTarget) const
{
aTarget.Assign(mBaseTarget);
}
void
nsHTMLDocument::SetBaseTarget(const nsAString& aTarget)
{
mBaseTarget = aTarget;
}
NS_IMETHODIMP
nsHTMLDocument::SetReferrer(const nsAString& aReferrer)
{

Просмотреть файл

@ -113,9 +113,6 @@ public:
virtual nsICSSLoader* GetCSSLoader();
virtual void GetBaseTarget(nsAString& aTarget) const;
virtual void SetBaseTarget(const nsAString& aTarget);
NS_IMETHOD SetReferrer(const nsAString& aReferrer);
NS_IMETHOD GetCompatibilityMode(nsCompatibility& aMode);
@ -259,11 +256,8 @@ protected:
nsresult CreateAndAddWyciwygChannel(void);
nsresult RemoveWyciwygChannel(void);
void BaseResetToURI(nsIURI* aURI);
virtual void RetrieveRelevantHeaders(nsIChannel *aChannel);
nsString mBaseTarget;
nsString mReferrer;
nsCOMPtr<nsIChannel> mChannel;

Просмотреть файл

@ -226,16 +226,6 @@ void
nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
{
nsDocument::Reset(aChannel, aLoadGroup);
nsCOMPtr<nsIURI> url;
if (aChannel) {
nsresult result = aChannel->GetURI(getter_AddRefs(url));
if (NS_FAILED(result))
return;
}
SetDefaultStylesheets(url);
mBaseTarget.Truncate();
mScriptContext = nsnull;
}
@ -1027,48 +1017,6 @@ nsXMLDocument::GetElementById(const nsAString& aElementId,
return CallQueryInterface(content, aReturn);
}
nsresult
nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl)
{
if (!aUrl) {
return NS_OK;
}
// XXXbz this code is very similar to the HTMLDocument code; should merge!
if (mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
}
if (mStyleAttrStyleSheet) {
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
}
nsresult rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aUrl,
this);
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), aUrl,
this);
NS_ENSURE_SUCCESS(rv, rv);
// tell the world about our new style sheets
AddStyleSheet(mAttrStyleSheet, 0);
AddStyleSheet(mStyleAttrStyleSheet, 0);
return rv;
}
void
nsXMLDocument::SetBaseTarget(const nsAString &aBaseTarget)
{
mBaseTarget.Assign(aBaseTarget);
}
void
nsXMLDocument::GetBaseTarget(nsAString &aBaseTarget) const
{
aBaseTarget.Assign(mBaseTarget);
}
nsICSSLoader*
nsXMLDocument::GetCSSLoader()
{

Просмотреть файл

@ -78,9 +78,6 @@ public:
virtual void EndLoad();
virtual void GetBaseTarget(nsAString &aBaseTarget) const;
virtual void SetBaseTarget(const nsAString &aBaseTarget);
// nsIDOMNode interface
NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
@ -127,13 +124,10 @@ protected:
virtual nsresult GetLoadGroup(nsILoadGroup **aLoadGroup);
nsresult SetDefaultStylesheets(nsIURI* aUrl);
// For additional catalog sheets (if any) needed to layout the XML vocabulary
// of the document. Catalog sheets are kept at the beginning of our array of
// style sheets and this counter is used as an offset to distinguish them
PRInt32 mCatalogSheetCount;
nsString mBaseTarget;
nsCOMPtr<nsIEventQueueService> mEventQService;

Просмотреть файл

@ -123,11 +123,6 @@ public:
*/
NS_IMETHOD SetCurrentPrototype(nsIXULPrototypeDocument* aDocument) = 0;
/**
* Load inline and attribute style sheets
*/
NS_IMETHOD PrepareStyleSheets(nsIURI* aURI) = 0;
/**
* Notify the XUL document that a subtree has been added
*/

Просмотреть файл

@ -525,42 +525,6 @@ nsXULDocument::SetContentType(const nsAString& aContentType)
// application/vnd.mozilla.xul+xml
}
NS_IMETHODIMP
nsXULDocument::PrepareStyleSheets(nsIURI* anURL)
{
nsresult rv;
// XXXbz this is similar to code in nsHTMLDocument and
// nsXMLDocument; move up to nsDocument?
// Delete references to style sheets - this should be done in superclass...
PRInt32 i = mStyleSheets.Count();
while (--i >= 0) {
mStyleSheets.ObjectAt(i)->SetOwningDocument(nsnull);
}
mStyleSheets.Clear();
// Create an HTML style sheet for the HTML content.
rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), anURL, this);
if (NS_FAILED(rv)) {
NS_ERROR("unable to add HTML style sheet");
return rv;
}
AddStyleSheet(mAttrStyleSheet, 0);
// Create an inline style sheet for inline content that contains a style
// attribute.
rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), anURL, this);
if (NS_FAILED(rv)) {
NS_ERROR("unable to add inline style sheet");
return rv;
}
AddStyleSheet(mStyleAttrStyleSheet, 0);
return NS_OK;
}
nsresult
nsXULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
@ -575,7 +539,7 @@ nsXULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsresult rv = aChannel->GetOriginalURI(getter_AddRefs(mDocumentURI));
if (NS_FAILED(rv)) return rv;
rv = PrepareStyleSheets(mDocumentURI);
rv = ResetStylesheetsToURI(mDocumentURI);
if (NS_FAILED(rv)) return rv;
RetrieveRelevantHeaders(aChannel);

Просмотреть файл

@ -146,7 +146,6 @@ public:
NS_IMETHOD SetMasterPrototype(nsIXULPrototypeDocument* aDocument);
NS_IMETHOD GetMasterPrototype(nsIXULPrototypeDocument** aDocument);
NS_IMETHOD SetCurrentPrototype(nsIXULPrototypeDocument* aDocument);
NS_IMETHOD PrepareStyleSheets(nsIURI* anURL);
NS_IMETHOD AddSubtreeToDocument(nsIContent* aElement);
NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aElement);
NS_IMETHOD SetTemplateBuilderFor(nsIContent* aContent,