Bug 1334330 - Part 7: stylo: Use GenericSpecifiedValue abstraction for <font>; r?emilio
MozReview-Commit-ID: E2FwWTF2MVI
--- a/dom/html/HTMLFontElement.cpp
+++ b/dom/html/HTMLFontElement.cpp
@@ -50,71 +50,58 @@ HTMLFontElement::ParseAttribute(int32_t
}
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
aResult);
}
void
HTMLFontElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
- GenericSpecifiedValues* aGenericData)
+ GenericSpecifiedValues* aData)
{
- nsRuleData* aData = aGenericData->AsRuleData();
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
+ if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Font))) {
// face: string list
- nsCSSValue* family = aData->ValueForFontFamily();
- if (family->GetUnit() == eCSSUnit_Null) {
+ if (!aData->PropertyIsSet(eCSSProperty_font_family)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::face);
if (value && value->Type() == nsAttrValue::eString &&
!value->IsEmptyString()) {
- nsCSSParser parser;
- parser.ParseFontFamilyListString(value->GetStringValue(),
- nullptr, 0, *family);
+ aData->SetFontFamily(value->GetStringValue());
}
}
-
// size: int
- nsCSSValue* fontSize = aData->ValueForFontSize();
- if (fontSize->GetUnit() == eCSSUnit_Null) {
+ if (!aData->PropertyIsSet(eCSSProperty_font_size)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
- if (value && value->Type() == nsAttrValue::eInteger) {
- fontSize->SetIntValue(value->GetIntegerValue(), eCSSUnit_Enumerated);
- }
+ if (value && value->Type() == nsAttrValue::eInteger)
+ aData->SetKeywordValue(eCSSProperty_font_size, value->GetIntegerValue());
}
}
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
- nsCSSValue* colorValue = aData->ValueForColor();
- if (colorValue->GetUnit() == eCSSUnit_Null &&
- aData->mPresContext->UseDocumentColors()) {
+ if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Color))) {
+ if (!aData->PropertyIsSet(eCSSProperty_color) &&
+ aData->PresContext()->UseDocumentColors()) {
// color: color
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::color);
nscolor color;
if (value && value->GetColorValue(color)) {
- colorValue->SetColorValue(color);
+ aData->SetColorValue(eCSSProperty_color, color);
}
}
}
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(TextReset) &&
- aData->mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
+ if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(TextReset)) &&
+ aData->PresContext()->CompatibilityMode() == eCompatibility_NavQuirks) {
// Make <a><font color="red">text</font></a> give the text a red underline
// in quirks mode. The NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL flag only
// affects quirks mode rendering.
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::color);
nscolor color;
if (value && value->GetColorValue(color)) {
- nsCSSValue* decoration = aData->ValueForTextDecorationLine();
- int32_t newValue = NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL;
- if (decoration->GetUnit() == eCSSUnit_Enumerated) {
- newValue |= decoration->GetIntValue();
- }
- decoration->SetIntValue(newValue, eCSSUnit_Enumerated);
+ aData->SetTextDecorationColorOverride();
}
}
- nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aGenericData);
+ nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
}
NS_IMETHODIMP_(bool)
HTMLFontElement::IsAttributeMapped(const nsIAtom* aAttribute) const
{
static const MappedAttributeEntry attributes[] = {
{ &nsGkAtoms::face },
{ &nsGkAtoms::size },
--- a/layout/style/GenericSpecifiedValues.h
+++ b/layout/style/GenericSpecifiedValues.h
@@ -73,12 +73,17 @@ public:
// Set a property to `currentcolor`
virtual void SetCurrentColor(nsCSSPropertyID aId) = 0;
virtual void SetCurrentColorIfUnset(nsCSSPropertyID aId) = 0;
// Set a property to an RGBA nscolor value
virtual void SetColorValue(nsCSSPropertyID aId, nscolor aValue) = 0;
virtual void SetColorValueIfUnset(nsCSSPropertyID aId, nscolor aValue) = 0;
+ // Set font-family to a string
+ virtual void SetFontFamily(const nsString& aValue) = 0;
+ // Add a quirks-mode override to the decoration color of elements nested in <a>
+ virtual void SetTextDecorationColorOverride() = 0;
+
virtual nsRuleData* AsRuleData() = 0;
};
#endif // mozilla_GenericSpecifiedValues_h
--- a/layout/style/nsRuleData.cpp
+++ b/layout/style/nsRuleData.cpp
@@ -1,15 +1,16 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsRuleData.h"
+#include "nsCSSParser.h"
#include "mozilla/Poison.h"
#include <stdint.h>
inline size_t
nsRuleData::GetPoisonOffset()
{
// Fill in mValueOffsets such that mValueStorage + mValueOffsets[i]
// will yield the frame poison value for all uninitialized value
@@ -35,16 +36,35 @@ nsRuleData::nsRuleData(uint32_t aSIDs, n
#ifndef MOZ_VALGRIND
size_t framePoisonOffset = GetPoisonOffset();
for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
mValueOffsets[i] = framePoisonOffset;
}
#endif
}
+void
+nsRuleData::SetFontFamily(const nsString& aValue)
+{
+ nsCSSValue* family = ValueForFontFamily();
+ nsCSSParser parser;
+ parser.ParseFontFamilyListString(aValue, nullptr, 0, *family);
+}
+
+void
+nsRuleData::SetTextDecorationColorOverride()
+{
+ nsCSSValue* decoration = ValueForTextDecorationLine();
+ int32_t newValue = NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL;
+ if (decoration->GetUnit() == eCSSUnit_Enumerated) {
+ newValue |= decoration->GetIntValue();
+ }
+ decoration->SetIntValue(newValue, eCSSUnit_Enumerated);
+}
+
#ifdef DEBUG
nsRuleData::~nsRuleData()
{
#ifndef MOZ_VALGRIND
// assert nothing in mSIDs has poison value
size_t framePoisonOffset = GetPoisonOffset();
for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
MOZ_ASSERT(!(mSIDs & (1 << i)) || mValueOffsets[i] != framePoisonOffset,
--- a/layout/style/nsRuleData.h
+++ b/layout/style/nsRuleData.h
@@ -215,16 +215,19 @@ struct nsRuleData final: GenericSpecifie
void SetColorValueIfUnset(nsCSSPropertyID aId,
nscolor aValue) override {
if (!PropertyIsSet(aId)) {
SetColorValue(aId, aValue);
}
}
+ void SetFontFamily(const nsString& aValue) override;
+ void SetTextDecorationColorOverride() override;
+
nsRuleData* AsRuleData() override {
return this;
}
private:
inline size_t GetPoisonOffset();
};