From 0bbab9b4028424f7033a1576c710a571c7bca77a Mon Sep 17 00:00:00 2001 From: "neil%parkwaycc.co.uk" Date: Thu, 5 Aug 2004 11:38:42 +0000 Subject: [PATCH] Bug 32372 should be possible to completely disable CSS p=fantasai@inkedblade.net r=me (xpfe) r/sr=dbaron git-svn-id: svn://10.0.0.236/trunk@160395 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 13 +++++++++ mozilla/content/base/src/nsDocument.h | 7 +++-- mozilla/content/base/src/nsDocumentViewer.cpp | 28 ++++++++++++++++++ mozilla/content/base/src/nsStyleSet.cpp | 29 +++++++++++++++++++ mozilla/content/base/src/nsStyleSet.h | 5 ++++ .../content/html/style/public/nsICSSLoader.h | 1 + .../content/html/style/src/nsCSSLoader.cpp | 7 +++++ mozilla/content/html/style/src/nsCSSLoader.h | 1 + mozilla/docshell/base/nsDocShell.cpp | 8 ++++- .../docshell/base/nsIMarkupDocumentViewer.idl | 3 ++ .../dom/public/idl/stylesheets/Makefile.in | 1 + mozilla/dom/src/base/nsDOMClassInfo.cpp | 7 ++++- mozilla/layout/base/nsDocumentViewer.cpp | 28 ++++++++++++++++++ mozilla/layout/base/nsIPresShell.h | 7 +++++ mozilla/layout/base/nsPresShell.cpp | 19 ++++++++++++ mozilla/layout/base/public/nsIPresShell.h | 7 +++++ mozilla/layout/html/base/src/nsPresShell.cpp | 19 ++++++++++++ mozilla/layout/style/nsCSSLoader.cpp | 7 +++++ mozilla/layout/style/nsCSSLoader.h | 1 + mozilla/layout/style/nsICSSLoader.h | 1 + mozilla/layout/style/nsStyleSet.cpp | 29 +++++++++++++++++++ mozilla/layout/style/nsStyleSet.h | 5 ++++ .../browser/resources/content/navigator.js | 22 +++++++++----- .../resources/content/navigatorOverlay.xul | 3 +- .../resources/locale/en-US/navigator.dtd | 6 ++-- 25 files changed, 250 insertions(+), 14 deletions(-) diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index b4412aea1a6..036dc6d7e14 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -628,6 +628,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent) NS_INTERFACE_MAP_ENTRY(nsIDOM3DocumentEvent) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocumentStyle) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentRange) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentTraversal) @@ -2553,6 +2554,18 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets) return NS_OK; } +NS_IMETHODIMP +nsDocument::GetPreferredStylesheetSet(nsAString& aStyleTitle) +{ + if (mCSSLoader) { + mCSSLoader->GetPreferredSheet(aStyleTitle); + } + else { + aStyleTitle.Truncate(); + } + return NS_OK; +} + NS_IMETHODIMP nsDocument::GetCharacterSet(nsAString& aCharacterSet) { diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 75e8a456cc5..b508642f417 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -49,7 +49,7 @@ #include "nsIDOMDocumentView.h" #include "nsIDOMDocumentXBL.h" #include "nsIDOMNSDocument.h" -#include "nsIDOMDocumentStyle.h" +#include "nsIDOMNSDocumentStyle.h" #include "nsIDOMDocumentRange.h" #include "nsIDOMDocumentTraversal.h" #include "nsStubDocumentObserver.h" @@ -185,7 +185,7 @@ class nsDocument : public nsIDocument, public nsIDOMNSDocument, public nsIDOMDocumentEvent, public nsIDOM3DocumentEvent, - public nsIDOMDocumentStyle, + public nsIDOMNSDocumentStyle, public nsIDOMDocumentView, public nsIDOMDocumentRange, public nsIDOMDocumentTraversal, @@ -468,6 +468,9 @@ public: // nsIDOMDocumentStyle NS_DECL_NSIDOMDOCUMENTSTYLE + // nsIDOMNSDocumentStyle + NS_DECL_NSIDOMNSDOCUMENTSTYLE + // nsIDOMDocumentView NS_DECL_NSIDOMDOCUMENTVIEW diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 88279ed822b..4310d17ac16 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -2344,6 +2344,34 @@ DocumentViewerImpl::GetTextZoom(float* aTextZoom) return NS_OK; } +static void +SetChildAuthorStyleDisabled(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + PRBool styleDisabled = *NS_STATIC_CAST(PRBool*, aClosure); + aChild->SetAuthorStyleDisabled(styleDisabled); +} + + +NS_IMETHODIMP +DocumentViewerImpl::SetAuthorStyleDisabled(PRBool aStyleDisabled) +{ + if (mPresShell) { + nsresult rv = mPresShell->SetAuthorStyleDisabled(aStyleDisabled); + if (NS_FAILED(rv)) return rv; + } + return CallChildren(SetChildAuthorStyleDisabled, &aStyleDisabled); +} + +NS_IMETHODIMP +DocumentViewerImpl::GetAuthorStyleDisabled(PRBool* aStyleDisabled) +{ + *aStyleDisabled = PR_FALSE; + if (mPresShell) { + return mPresShell->GetAuthorStyleDisabled(aStyleDisabled); + } + return NS_OK; +} + NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) { diff --git a/mozilla/content/base/src/nsStyleSet.cpp b/mozilla/content/base/src/nsStyleSet.cpp index 8c93219afe6..9996055333e 100644 --- a/mozilla/content/base/src/nsStyleSet.cpp +++ b/mozilla/content/base/src/nsStyleSet.cpp @@ -57,6 +57,7 @@ nsStyleSet::nsStyleSet() mDestroyedCount(0), mBatching(0), mInShutdown(PR_FALSE), + mAuthorStyleDisabled(PR_FALSE), mDirty(0) { } @@ -95,6 +96,13 @@ nsresult nsStyleSet::GatherRuleProcessors(sheetType aType) { mRuleProcessors[aType] = nsnull; + if (mAuthorStyleDisabled && (aType == eDocSheet || + aType == ePresHintSheet || + aType == eHTMLPresHintSheet || + aType == eStyleAttrSheet)) { + //don't regather if this level is disabled + return NS_OK; + } if (mSheets[aType].Count()) { switch (aType) { case eAgentSheet: @@ -198,6 +206,27 @@ nsStyleSet::ReplaceSheets(sheetType aType, return NS_OK; } +PRBool +nsStyleSet::GetAuthorStyleDisabled() +{ + return mAuthorStyleDisabled; +} + +nsresult +nsStyleSet::SetAuthorStyleDisabled(PRBool aStyleDisabled) +{ + if (aStyleDisabled == !mAuthorStyleDisabled) { + mAuthorStyleDisabled = aStyleDisabled; + BeginUpdate(); + mDirty |= 1 << eDocSheet | + 1 << ePresHintSheet | + 1 << eHTMLPresHintSheet | + 1 << eStyleAttrSheet; + return EndUpdate(); + } + return NS_OK; +} + // -------- Doc Sheets nsresult diff --git a/mozilla/content/base/src/nsStyleSet.h b/mozilla/content/base/src/nsStyleSet.h index e1adee2c93e..88ba04cb230 100644 --- a/mozilla/content/base/src/nsStyleSet.h +++ b/mozilla/content/base/src/nsStyleSet.h @@ -171,6 +171,10 @@ class nsStyleSet nsresult ReplaceSheets(sheetType aType, const nsCOMArray &aNewSheets); + //Enable/Disable entire author style level (Doc & PresHint levels) + PRBool GetAuthorStyleDisabled(); + nsresult SetAuthorStyleDisabled(PRBool aStyleDisabled); + PRInt32 SheetCount(sheetType aType) const { return mSheets[aType].Count(); } @@ -256,6 +260,7 @@ class nsStyleSet PRUint16 mBatching; unsigned mInShutdown : 1; + unsigned mAuthorStyleDisabled: 1; unsigned mDirty : 7; // one dirty bit is used per sheet type }; diff --git a/mozilla/content/html/style/public/nsICSSLoader.h b/mozilla/content/html/style/public/nsICSSLoader.h index 4a3a924b086..73ae79c9f8e 100644 --- a/mozilla/content/html/style/public/nsICSSLoader.h +++ b/mozilla/content/html/style/public/nsICSSLoader.h @@ -70,6 +70,7 @@ public: NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive) = 0; NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode) = 0; NS_IMETHOD SetPreferredSheet(const nsAString& aTitle) = 0; + NS_IMETHOD GetPreferredSheet(nsAString& aTitle) = 0; // Get/Recycle a CSS parser for general use NS_IMETHOD GetParserFor(nsICSSStyleSheet* aSheet, diff --git a/mozilla/content/html/style/src/nsCSSLoader.cpp b/mozilla/content/html/style/src/nsCSSLoader.cpp index 397f9444914..f252dcc4a0d 100644 --- a/mozilla/content/html/style/src/nsCSSLoader.cpp +++ b/mozilla/content/html/style/src/nsCSSLoader.cpp @@ -326,6 +326,13 @@ CSSLoaderImpl::SetPreferredSheet(const nsAString& aTitle) return NS_OK; } +NS_IMETHODIMP +CSSLoaderImpl::GetPreferredSheet(nsAString& aTitle) +{ + aTitle.Assign(mPreferredSheet); + return NS_OK; +} + NS_IMETHODIMP CSSLoaderImpl::GetParserFor(nsICSSStyleSheet* aSheet, nsICSSParser** aParser) diff --git a/mozilla/content/html/style/src/nsCSSLoader.h b/mozilla/content/html/style/src/nsCSSLoader.h index 68accc1e54b..117514e5d98 100644 --- a/mozilla/content/html/style/src/nsCSSLoader.h +++ b/mozilla/content/html/style/src/nsCSSLoader.h @@ -219,6 +219,7 @@ public: NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive); NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode); NS_IMETHOD SetPreferredSheet(const nsAString& aTitle); + NS_IMETHOD GetPreferredSheet(nsAString& aTitle); NS_IMETHOD GetParserFor(nsICSSStyleSheet* aSheet, nsICSSParser** aParser); diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 7b28844eabf..62ac76d7753 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -2125,7 +2125,7 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild) if (!childAsDocShell) return NS_OK; - // charset and zoom will be inherited in SetupNewViewer() + // charset, style-disabling, and zoom will be inherited in SetupNewViewer() // Now take this document's charset and set the parentCharset field of the // child's DocumentCharsetInfo to it. We'll later use that field, in the @@ -4726,6 +4726,7 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) PRInt32 hintCharsetSource; nsCAutoString prevDocCharset; float textZoom; + PRBool styleDisabled; // |newMUDV| also serves as a flag to set the data from the above vars nsCOMPtr newMUDV; @@ -4764,6 +4765,9 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) NS_ENSURE_SUCCESS(oldMUDV-> GetTextZoom(&textZoom), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV-> + GetAuthorStyleDisabled(&styleDisabled), + NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(oldMUDV-> GetPrevDocCharacterSet(prevDocCharset), NS_ERROR_FAILURE); @@ -4894,6 +4898,8 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(newMUDV->SetTextZoom(textZoom), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetAuthorStyleDisabled(styleDisabled), + NS_ERROR_FAILURE); } // End copying block (Don't mess with the old content/document viewer diff --git a/mozilla/docshell/base/nsIMarkupDocumentViewer.idl b/mozilla/docshell/base/nsIMarkupDocumentViewer.idl index e645bafd0c2..5c6990d6fb6 100644 --- a/mozilla/docshell/base/nsIMarkupDocumentViewer.idl +++ b/mozilla/docshell/base/nsIMarkupDocumentViewer.idl @@ -67,6 +67,9 @@ interface nsIMarkupDocumentViewer : nsISupports /** The amount by which to scale all text. Default is 1.0. */ attribute float textZoom; + /** Disable entire author style level (including HTML presentation hints) */ + attribute boolean authorStyleDisabled; + /* XXX Comment here! */ diff --git a/mozilla/dom/public/idl/stylesheets/Makefile.in b/mozilla/dom/public/idl/stylesheets/Makefile.in index be1f5983545..3e59eb1785e 100644 --- a/mozilla/dom/public/idl/stylesheets/Makefile.in +++ b/mozilla/dom/public/idl/stylesheets/Makefile.in @@ -48,6 +48,7 @@ GRE_MODULE = 1 SDK_XPIDLSRCS = \ nsIDOMDocumentStyle.idl \ + nsIDOMNSDocumentStyle.idl \ nsIDOMMediaList.idl \ nsIDOMStyleSheet.idl \ nsIDOMStyleSheetList.idl \ diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index 509686b9665..2d602a8cde3 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -199,7 +199,7 @@ #include "nsIDOMMouseEvent.h" #include "nsIDOMPopupBlockedEvent.h" #include "nsIDOMMutationEvent.h" -#include "nsIDOMDocumentStyle.h" +#include "nsIDOMNSDocumentStyle.h" #include "nsIDOMDocumentRange.h" #include "nsIDOMDocumentTraversal.h" #include "nsIDOMDocumentXBL.h" @@ -1454,6 +1454,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocument) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocumentStyle) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal) @@ -1560,6 +1561,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocument) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocumentStyle) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal) @@ -2003,6 +2005,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocumentStyle) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal) DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) @@ -2099,6 +2102,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocument) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocumentStyle) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal) @@ -2164,6 +2168,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSDocumentStyle) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) DOM_CLASSINFO_MAP_END_WITH_XPATH diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 88279ed822b..4310d17ac16 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -2344,6 +2344,34 @@ DocumentViewerImpl::GetTextZoom(float* aTextZoom) return NS_OK; } +static void +SetChildAuthorStyleDisabled(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + PRBool styleDisabled = *NS_STATIC_CAST(PRBool*, aClosure); + aChild->SetAuthorStyleDisabled(styleDisabled); +} + + +NS_IMETHODIMP +DocumentViewerImpl::SetAuthorStyleDisabled(PRBool aStyleDisabled) +{ + if (mPresShell) { + nsresult rv = mPresShell->SetAuthorStyleDisabled(aStyleDisabled); + if (NS_FAILED(rv)) return rv; + } + return CallChildren(SetChildAuthorStyleDisabled, &aStyleDisabled); +} + +NS_IMETHODIMP +DocumentViewerImpl::GetAuthorStyleDisabled(PRBool* aStyleDisabled) +{ + *aStyleDisabled = PR_FALSE; + if (mPresShell) { + return mPresShell->GetAuthorStyleDisabled(aStyleDisabled); + } + return NS_OK; +} + NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) { diff --git a/mozilla/layout/base/nsIPresShell.h b/mozilla/layout/base/nsIPresShell.h index eabd1385027..4707f30f1dc 100644 --- a/mozilla/layout/base/nsIPresShell.h +++ b/mozilla/layout/base/nsIPresShell.h @@ -190,6 +190,13 @@ public: NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle) = 0; + + /* Enable/disable author style level. Disabling author style disables the entire + * author level of the cascade, including the HTML preshint level. + */ + NS_IMETHOD SetAuthorStyleDisabled(PRBool aStyleDisabled) = 0; + NS_IMETHOD GetAuthorStyleDisabled(PRBool* aStyleDisabled) = 0; + /* * Called when stylesheets are added/removed/enabled/disabled to rebuild * all style data for a given pres shell without necessarily reconstructing diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index e9972f48bc7..5902fe0cd65 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -1090,6 +1090,8 @@ public: NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle); NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); + NS_IMETHOD GetAuthorStyleDisabled(PRBool* aStyleDisabled); + NS_IMETHOD SetAuthorStyleDisabled(PRBool aStyleDisabled); NS_IMETHOD ReconstructStyleData(); NS_IMETHOD SetPreferenceStyleRules(PRBool aForceReflow); NS_IMETHOD EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType=0xFF); @@ -2121,6 +2123,23 @@ PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList) return NS_OK; } +NS_IMETHODIMP +PresShell::SetAuthorStyleDisabled(PRBool aStyleDisabled) +{ + if (aStyleDisabled != mStyleSet->GetAuthorStyleDisabled()) { + nsresult rv = mStyleSet->SetAuthorStyleDisabled(aStyleDisabled); + if (NS_FAILED(rv)) return rv; + return ReconstructStyleData(); + } + return NS_OK; +} + +NS_IMETHODIMP +PresShell::GetAuthorStyleDisabled(PRBool* aStyleDisabled) +{ + *aStyleDisabled = mStyleSet->GetAuthorStyleDisabled(); + return NS_OK; +} NS_IMETHODIMP PresShell::EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType/*=0xFF*/) diff --git a/mozilla/layout/base/public/nsIPresShell.h b/mozilla/layout/base/public/nsIPresShell.h index eabd1385027..4707f30f1dc 100644 --- a/mozilla/layout/base/public/nsIPresShell.h +++ b/mozilla/layout/base/public/nsIPresShell.h @@ -190,6 +190,13 @@ public: NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle) = 0; + + /* Enable/disable author style level. Disabling author style disables the entire + * author level of the cascade, including the HTML preshint level. + */ + NS_IMETHOD SetAuthorStyleDisabled(PRBool aStyleDisabled) = 0; + NS_IMETHOD GetAuthorStyleDisabled(PRBool* aStyleDisabled) = 0; + /* * Called when stylesheets are added/removed/enabled/disabled to rebuild * all style data for a given pres shell without necessarily reconstructing diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index e9972f48bc7..5902fe0cd65 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -1090,6 +1090,8 @@ public: NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle); NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); + NS_IMETHOD GetAuthorStyleDisabled(PRBool* aStyleDisabled); + NS_IMETHOD SetAuthorStyleDisabled(PRBool aStyleDisabled); NS_IMETHOD ReconstructStyleData(); NS_IMETHOD SetPreferenceStyleRules(PRBool aForceReflow); NS_IMETHOD EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType=0xFF); @@ -2121,6 +2123,23 @@ PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList) return NS_OK; } +NS_IMETHODIMP +PresShell::SetAuthorStyleDisabled(PRBool aStyleDisabled) +{ + if (aStyleDisabled != mStyleSet->GetAuthorStyleDisabled()) { + nsresult rv = mStyleSet->SetAuthorStyleDisabled(aStyleDisabled); + if (NS_FAILED(rv)) return rv; + return ReconstructStyleData(); + } + return NS_OK; +} + +NS_IMETHODIMP +PresShell::GetAuthorStyleDisabled(PRBool* aStyleDisabled) +{ + *aStyleDisabled = mStyleSet->GetAuthorStyleDisabled(); + return NS_OK; +} NS_IMETHODIMP PresShell::EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType/*=0xFF*/) diff --git a/mozilla/layout/style/nsCSSLoader.cpp b/mozilla/layout/style/nsCSSLoader.cpp index 397f9444914..f252dcc4a0d 100644 --- a/mozilla/layout/style/nsCSSLoader.cpp +++ b/mozilla/layout/style/nsCSSLoader.cpp @@ -326,6 +326,13 @@ CSSLoaderImpl::SetPreferredSheet(const nsAString& aTitle) return NS_OK; } +NS_IMETHODIMP +CSSLoaderImpl::GetPreferredSheet(nsAString& aTitle) +{ + aTitle.Assign(mPreferredSheet); + return NS_OK; +} + NS_IMETHODIMP CSSLoaderImpl::GetParserFor(nsICSSStyleSheet* aSheet, nsICSSParser** aParser) diff --git a/mozilla/layout/style/nsCSSLoader.h b/mozilla/layout/style/nsCSSLoader.h index 68accc1e54b..117514e5d98 100644 --- a/mozilla/layout/style/nsCSSLoader.h +++ b/mozilla/layout/style/nsCSSLoader.h @@ -219,6 +219,7 @@ public: NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive); NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode); NS_IMETHOD SetPreferredSheet(const nsAString& aTitle); + NS_IMETHOD GetPreferredSheet(nsAString& aTitle); NS_IMETHOD GetParserFor(nsICSSStyleSheet* aSheet, nsICSSParser** aParser); diff --git a/mozilla/layout/style/nsICSSLoader.h b/mozilla/layout/style/nsICSSLoader.h index 4a3a924b086..73ae79c9f8e 100644 --- a/mozilla/layout/style/nsICSSLoader.h +++ b/mozilla/layout/style/nsICSSLoader.h @@ -70,6 +70,7 @@ public: NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive) = 0; NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode) = 0; NS_IMETHOD SetPreferredSheet(const nsAString& aTitle) = 0; + NS_IMETHOD GetPreferredSheet(nsAString& aTitle) = 0; // Get/Recycle a CSS parser for general use NS_IMETHOD GetParserFor(nsICSSStyleSheet* aSheet, diff --git a/mozilla/layout/style/nsStyleSet.cpp b/mozilla/layout/style/nsStyleSet.cpp index 8c93219afe6..9996055333e 100644 --- a/mozilla/layout/style/nsStyleSet.cpp +++ b/mozilla/layout/style/nsStyleSet.cpp @@ -57,6 +57,7 @@ nsStyleSet::nsStyleSet() mDestroyedCount(0), mBatching(0), mInShutdown(PR_FALSE), + mAuthorStyleDisabled(PR_FALSE), mDirty(0) { } @@ -95,6 +96,13 @@ nsresult nsStyleSet::GatherRuleProcessors(sheetType aType) { mRuleProcessors[aType] = nsnull; + if (mAuthorStyleDisabled && (aType == eDocSheet || + aType == ePresHintSheet || + aType == eHTMLPresHintSheet || + aType == eStyleAttrSheet)) { + //don't regather if this level is disabled + return NS_OK; + } if (mSheets[aType].Count()) { switch (aType) { case eAgentSheet: @@ -198,6 +206,27 @@ nsStyleSet::ReplaceSheets(sheetType aType, return NS_OK; } +PRBool +nsStyleSet::GetAuthorStyleDisabled() +{ + return mAuthorStyleDisabled; +} + +nsresult +nsStyleSet::SetAuthorStyleDisabled(PRBool aStyleDisabled) +{ + if (aStyleDisabled == !mAuthorStyleDisabled) { + mAuthorStyleDisabled = aStyleDisabled; + BeginUpdate(); + mDirty |= 1 << eDocSheet | + 1 << ePresHintSheet | + 1 << eHTMLPresHintSheet | + 1 << eStyleAttrSheet; + return EndUpdate(); + } + return NS_OK; +} + // -------- Doc Sheets nsresult diff --git a/mozilla/layout/style/nsStyleSet.h b/mozilla/layout/style/nsStyleSet.h index e1adee2c93e..88ba04cb230 100644 --- a/mozilla/layout/style/nsStyleSet.h +++ b/mozilla/layout/style/nsStyleSet.h @@ -171,6 +171,10 @@ class nsStyleSet nsresult ReplaceSheets(sheetType aType, const nsCOMArray &aNewSheets); + //Enable/Disable entire author style level (Doc & PresHint levels) + PRBool GetAuthorStyleDisabled(); + nsresult SetAuthorStyleDisabled(PRBool aStyleDisabled); + PRInt32 SheetCount(sheetType aType) const { return mSheets[aType].Count(); } @@ -256,6 +260,7 @@ class nsStyleSet PRUint16 mBatching; unsigned mInShutdown : 1; + unsigned mAuthorStyleDisabled: 1; unsigned mDirty : 7; // one dirty bit is used per sheet type }; diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index b907e46547d..e42ea5101a9 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -1802,20 +1802,22 @@ function getAllStyleSheets(frameset) function stylesheetFillPopup(menuPopup) { - var itemNoOptStyles = menuPopup.firstChild; - while (itemNoOptStyles.nextSibling) - menuPopup.removeChild(itemNoOptStyles.nextSibling); + /* Clear menu */ + var itemPersistentOnly = menuPopup.firstChild.nextSibling; + while (itemPersistentOnly.nextSibling) + menuPopup.removeChild(itemPersistentOnly.nextSibling); - var noOptionalStyles = true; var styleSheets = getAllStyleSheets(window.content); var currentStyleSheets = []; + var styleDisabled = getMarkupDocumentViewer().authorStyleDisabled; + var altStyleSelected = false; for (var i = 0; i < styleSheets.length; ++i) { var currentStyleSheet = styleSheets[i]; if (currentStyleSheet.title) { if (!currentStyleSheet.disabled) - noOptionalStyles = false; + altStyleSelected = true; var lastWithSameTitle = null; if (currentStyleSheet.title in currentStyleSheets) @@ -1826,7 +1828,7 @@ function stylesheetFillPopup(menuPopup) menuItem.setAttribute("type", "radio"); menuItem.setAttribute("label", currentStyleSheet.title); menuItem.setAttribute("data", currentStyleSheet.title); - menuItem.setAttribute("checked", !currentStyleSheet.disabled); + menuItem.setAttribute("checked", !currentStyleSheet.disabled && !styleDisabled); menuPopup.appendChild(menuItem); currentStyleSheets[currentStyleSheet.title] = menuItem; } else { @@ -1835,7 +1837,9 @@ function stylesheetFillPopup(menuPopup) } } } - itemNoOptStyles.setAttribute("checked", noOptionalStyles); + menuPopup.firstChild.setAttribute("checked", styleDisabled); + itemPersistentOnly.setAttribute("checked", !altStyleSelected && !styleDisabled); + itemPersistentOnly.hidden = (window.content.document.preferredStylesheetSet) ? true : false; } function stylesheetInFrame(frame, title) { @@ -1870,6 +1874,10 @@ function stylesheetSwitchAll(frameset, title) { } } +function setStyleDisabled(disabled) { + getMarkupDocumentViewer().authorStyleDisabled = disabled; +} + function applyTheme(themeName) { var id = themeName.getAttribute('id'); diff --git a/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul b/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul index fcdea425476..c53be6afab6 100644 --- a/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul +++ b/mozilla/xpfe/browser/resources/content/navigatorOverlay.xul @@ -403,7 +403,8 @@ + oncommand="stylesheetSwitchAll(window.content, event.target.getAttribute('data')); setStyleDisabled(false);" type="radio"> + diff --git a/mozilla/xpfe/browser/resources/locale/en-US/navigator.dtd b/mozilla/xpfe/browser/resources/locale/en-US/navigator.dtd index d24fb86ad19..1aa5348c9ce 100644 --- a/mozilla/xpfe/browser/resources/locale/en-US/navigator.dtd +++ b/mozilla/xpfe/browser/resources/locale/en-US/navigator.dtd @@ -60,8 +60,10 @@ - - + + + +