From 680082c98d73fa62a32c6477cc0037cbc238a698 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 16 Nov 2007 03:46:43 +0000 Subject: [PATCH] Don't allow presentational attributes to set colors if the "don't use document colors" pref is set. Bug 400452, r+sr=dbaron --- content/html/content/src/nsGenericHTMLElement.cpp | 12 +++++++----- content/html/content/src/nsHTMLBodyElement.cpp | 3 ++- content/html/content/src/nsHTMLFontElement.cpp | 3 ++- content/html/content/src/nsHTMLHRElement.cpp | 3 ++- content/html/content/src/nsHTMLTableElement.cpp | 6 ++++-- layout/base/nsPresContext.cpp | 6 +++--- layout/base/nsPresContext.h | 15 ++++++++++----- layout/style/nsCSSDataBlock.cpp | 4 +--- layout/style/nsHTMLStyleSheet.cpp | 5 +++-- 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 63e89690a16..c9e8af0b678 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -2181,7 +2181,9 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes, if (!(aData->mSIDs & NS_STYLE_INHERIT_BIT(Background))) return; - if (aData->mColorData->mBackImage.GetUnit() == eCSSUnit_Null) { + nsPresContext* presContext = aData->mPresContext; + if (aData->mColorData->mBackImage.GetUnit() == eCSSUnit_Null && + presContext->UseDocumentColors()) { // background const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::background); if (value && value->Type() == nsAttrValue::eString) { @@ -2193,7 +2195,7 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes, // as well as elements with _baseHref set. We need to be able // to get to the element somehow, or store the base URI in the // attributes. - nsIDocument* doc = aData->mPresContext->Document(); + nsIDocument* doc = presContext->Document(); nsCOMPtr uri; nsresult rv = nsContentUtils::NewURIWithDocumentCharset( getter_AddRefs(uri), spec, doc, doc->GetBaseURI()); @@ -2216,8 +2218,7 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes, } } } - else if (aData->mPresContext->CompatibilityMode() == - eCompatibility_NavQuirks) { + else if (presContext->CompatibilityMode() == eCompatibility_NavQuirks) { // in NavQuirks mode, allow the empty string to set the // background to empty aData->mColorData->mBackImage.SetNoneValue(); @@ -2233,7 +2234,8 @@ nsGenericHTMLElement::MapBGColorInto(const nsMappedAttributes* aAttributes, if (!(aData->mSIDs & NS_STYLE_INHERIT_BIT(Background))) return; - if (aData->mColorData->mBackColor.GetUnit() == eCSSUnit_Null) { + if (aData->mColorData->mBackColor.GetUnit() == eCSSUnit_Null && + aData->mPresContext->UseDocumentColors()) { const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bgcolor); nscolor color; if (value && value->GetColorValue(color)) { diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp index cc7789798f3..4ed0e721ad7 100644 --- a/content/html/content/src/nsHTMLBodyElement.cpp +++ b/content/html/content/src/nsHTMLBodyElement.cpp @@ -510,7 +510,8 @@ void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aD } if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) { - if (aData->mColorData->mColor.GetUnit() == eCSSUnit_Null) { + if (aData->mColorData->mColor.GetUnit() == eCSSUnit_Null && + aData->mPresContext->UseDocumentColors()) { // color: color nscolor color; const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::text); diff --git a/content/html/content/src/nsHTMLFontElement.cpp b/content/html/content/src/nsHTMLFontElement.cpp index d147593560e..1d4c0e12479 100644 --- a/content/html/content/src/nsHTMLFontElement.cpp +++ b/content/html/content/src/nsHTMLFontElement.cpp @@ -215,7 +215,8 @@ MapAttributesIntoRule(const nsMappedAttributes* aAttributes, } } if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) { - if (aData->mColorData->mColor.GetUnit() == eCSSUnit_Null) { + if (aData->mColorData->mColor.GetUnit() == eCSSUnit_Null && + aData->mPresContext->UseDocumentColors) { // color: color const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::color); nscolor color; diff --git a/content/html/content/src/nsHTMLHRElement.cpp b/content/html/content/src/nsHTMLHRElement.cpp index f9b9b8d7c33..f65324150d4 100644 --- a/content/html/content/src/nsHTMLHRElement.cpp +++ b/content/html/content/src/nsHTMLHRElement.cpp @@ -295,7 +295,8 @@ MapAttributesIntoRule(const nsMappedAttributes* aAttributes, // color: a color // (we got the color attribute earlier) if (colorIsSet && - aData->mColorData->mColor.GetUnit() == eCSSUnit_Null) { + aData->mColorData->mColor.GetUnit() == eCSSUnit_Null && + aData->mPresContext->UseDocumentColors()) { aData->mColorData->mColor.SetColorValue(color); } } diff --git a/content/html/content/src/nsHTMLTableElement.cpp b/content/html/content/src/nsHTMLTableElement.cpp index 02cdec88514..41f99ad99cb 100644 --- a/content/html/content/src/nsHTMLTableElement.cpp +++ b/content/html/content/src/nsHTMLTableElement.cpp @@ -1128,7 +1128,8 @@ MapAttributesIntoRule(const nsMappedAttributes* aAttributes, // which *element* it's matching (style rules should not stop matching // when the display type is changed). - nsCompatibility mode = aData->mPresContext->CompatibilityMode(); + nsPresContext* presContext = aData->mPresContext; + nsCompatibility mode = presContext->CompatibilityMode(); if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TableBorder)) { const nsStyleDisplay* readDisplay = aData->mStyleContext->GetStyleDisplay(); @@ -1331,7 +1332,8 @@ MapAttributesIntoRule(const nsMappedAttributes* aAttributes, // bordercolor const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bordercolor); nscolor color; - if (value && value->GetColorValue(color)) { + if (value && presContext->UseDocumentColors() && + value->GetColorValue(color)) { if (aData->mMarginData->mBorderColor.mLeft.GetUnit() == eCSSUnit_Null) aData->mMarginData->mBorderColor.mLeft.SetColorValue(color); if (aData->mMarginData->mBorderColor.mRight.GetUnit() == eCSSUnit_Null) diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 5c320301d0d..93b681744ea 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1215,7 +1215,7 @@ nsPresContext::SetContainer(nsISupports* aHandler) } already_AddRefed -nsPresContext::GetContainerInternal() +nsPresContext::GetContainerInternal() const { nsISupports *result = nsnull; if (mContainer) @@ -1225,7 +1225,7 @@ nsPresContext::GetContainerInternal() } already_AddRefed -nsPresContext::GetContainerExternal() +nsPresContext::GetContainerExternal() const { return GetContainerInternal(); } @@ -1462,7 +1462,7 @@ nsPresContext::CountReflows(const char * aName, nsIFrame * aFrame) #endif PRBool -nsPresContext::IsChrome() +nsPresContext::IsChrome() const { PRBool isChrome = PR_FALSE; nsCOMPtr container = GetContainer(); diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 910111220e7..a5e5ffad0bb 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -377,13 +377,13 @@ public: NS_HIDDEN_(void) SetContainer(nsISupports* aContainer); - virtual NS_HIDDEN_(already_AddRefed) GetContainerExternal(); - NS_HIDDEN_(already_AddRefed) GetContainerInternal(); + virtual NS_HIDDEN_(already_AddRefed) GetContainerExternal() const; + NS_HIDDEN_(already_AddRefed) GetContainerInternal() const; #ifdef _IMPL_NS_LAYOUT - already_AddRefed GetContainer() + already_AddRefed GetContainer() const { return GetContainerInternal(); } #else - already_AddRefed GetContainer() + already_AddRefed GetContainer() const { return GetContainerExternal(); } #endif @@ -727,11 +727,16 @@ public: mType == eContext_PrintPreview); } // Is this presentation in a chrome docshell? - PRBool IsChrome(); + PRBool IsChrome() const; // Public API for native theme code to get style internals. virtual PRBool HasAuthorSpecifiedBorderOrBackground(nsIFrame *aFrame) const; + // Is it OK to let the page specify colors and backgrounds? + PRBool UseDocumentColors() const { + return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome(); + } + protected: friend class nsRunnableMethod; NS_HIDDEN_(void) ThemeChangedInternal(); diff --git a/layout/style/nsCSSDataBlock.cpp b/layout/style/nsCSSDataBlock.cpp index 4a6efefac34..60c35edfa12 100644 --- a/layout/style/nsCSSDataBlock.cpp +++ b/layout/style/nsCSSDataBlock.cpp @@ -175,11 +175,9 @@ inline nsCSSQuotes* QuotesAtCursor(const char *aCursor) { static PRBool ShouldIgnoreColors(nsRuleData *aRuleData) { - nsPresContext *presContext = aRuleData->mPresContext; return aRuleData->mLevel != nsStyleSet::eAgentSheet && aRuleData->mLevel != nsStyleSet::eUserSheet && - !presContext->GetCachedBoolPref(kPresContext_UseDocumentColors) && - !presContext->IsChrome(); + !aRuleData->mPresContext->UseDocumentColors(); } nsresult diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 4c8a8a43f15..13c1f000bf2 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -76,8 +76,9 @@ NS_IMETHODIMP nsHTMLStyleSheet::HTMLColorRule::MapRuleInfoInto(nsRuleData* aRuleData) { if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) { - if (aRuleData->mColorData->mColor.GetUnit() == eCSSUnit_Null) - aRuleData->mColorData->mColor = nsCSSValue(mColor); + if (aRuleData->mColorData->mColor.GetUnit() == eCSSUnit_Null && + aRuleData->mPresContext->UseDocumentColors()) + aRuleData->mColorData->mColor.SetColorValue(mColor); } return NS_OK; }