Don't allow presentational attributes to set colors if the "don't use document

colors" pref is set.  Bug 400452, r+sr=dbaron
This commit is contained in:
bzbarsky%mit.edu 2007-11-16 03:46:43 +00:00
Родитель 65c6552fe7
Коммит 680082c98d
9 изменённых файлов: 34 добавлений и 23 удалений

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

@ -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<nsIURI> 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)) {

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

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

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

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

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

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

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

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

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

@ -1215,7 +1215,7 @@ nsPresContext::SetContainer(nsISupports* aHandler)
}
already_AddRefed<nsISupports>
nsPresContext::GetContainerInternal()
nsPresContext::GetContainerInternal() const
{
nsISupports *result = nsnull;
if (mContainer)
@ -1225,7 +1225,7 @@ nsPresContext::GetContainerInternal()
}
already_AddRefed<nsISupports>
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<nsISupports> container = GetContainer();

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

@ -377,13 +377,13 @@ public:
NS_HIDDEN_(void) SetContainer(nsISupports* aContainer);
virtual NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerExternal();
NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerInternal();
virtual NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerExternal() const;
NS_HIDDEN_(already_AddRefed<nsISupports>) GetContainerInternal() const;
#ifdef _IMPL_NS_LAYOUT
already_AddRefed<nsISupports> GetContainer()
already_AddRefed<nsISupports> GetContainer() const
{ return GetContainerInternal(); }
#else
already_AddRefed<nsISupports> GetContainer()
already_AddRefed<nsISupports> 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<nsPresContext>;
NS_HIDDEN_(void) ThemeChangedInternal();

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

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

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

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