Bug 1339711 - Part 3: stylo: Support mathsize, width, and scriptminsize presentation attributes in MathML; r=emilio

MozReview-Commit-ID: GvHslYdBfXU
This commit is contained in:
Manish Goregaokar 2017-04-10 15:28:48 +08:00
parent fd3cc1e497
commit 9d7550892d
7 changed files with 56 additions and 20 deletions

View File

@ -488,15 +488,8 @@ nsMathMLElement::ParseNumericValue(const nsString& aString,
void
nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
GenericSpecifiedValues* aGenericData)
GenericSpecifiedValues* aData)
{
if (aGenericData->IsServo()) {
// FIXME (bug 1339711) handle MathML properties in Stylo
NS_WARNING("stylo: cannot handle MathML presentation attributes");
return;
}
nsRuleData* aData = aGenericData->AsGecko();
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
// scriptsizemultiplier
//
@ -539,17 +532,20 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
// Unitless and percent values give a multiple of the default value.
//
value = aAttributes->GetAttr(nsGkAtoms::scriptminsize_);
nsCSSValue* scriptMinSize = aData->ValueForScriptMinSize();
if (value && value->Type() == nsAttrValue::eString &&
scriptMinSize->GetUnit() == eCSSUnit_Null) {
ParseNumericValue(value->GetStringValue(), *scriptMinSize,
!aData->PropertyIsSet(eCSSProperty__moz_script_min_size)) {
nsCSSValue scriptMinSize;
ParseNumericValue(value->GetStringValue(), scriptMinSize,
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
aData->mPresContext->Document());
if (scriptMinSize->GetUnit() == eCSSUnit_Percent) {
scriptMinSize->SetFloatValue(8.0 * scriptMinSize->GetPercentValue(),
if (scriptMinSize.GetUnit() == eCSSUnit_Percent) {
scriptMinSize.SetFloatValue(8.0 * scriptMinSize.GetPercentValue(),
eCSSUnit_Point);
}
if (scriptMinSize.GetUnit() != eCSSUnit_Null) {
aData->SetLengthValue(eCSSProperty__moz_script_min_size, scriptMinSize);
}
}
// scriptlevel
@ -622,11 +618,11 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
aData->mPresContext->Document());
}
}
nsCSSValue* fontSize = aData->ValueForFontSize();
if (value && value->Type() == nsAttrValue::eString &&
fontSize->GetUnit() == eCSSUnit_Null) {
!aData->PropertyIsSet(eCSSProperty_font_size)) {
nsAutoString str(value->GetStringValue());
if (!ParseNumericValue(str, *fontSize, PARSE_SUPPRESS_WARNINGS |
nsCSSValue fontSize;
if (!ParseNumericValue(str, fontSize, PARSE_SUPPRESS_WARNINGS |
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
nullptr)
&& parseSizeKeywords) {
@ -638,10 +634,15 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
str.CompressWhitespace();
for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
if (str.EqualsASCII(sizes[i])) {
fontSize->SetIntValue(values[i], eCSSUnit_Enumerated);
aData->SetKeywordValue(eCSSProperty_font_size, values[i]);
break;
}
}
} else if (fontSize.GetUnit() == eCSSUnit_Percent) {
aData->SetPercentValue(eCSSProperty_font_size,
fontSize.GetPercentValue());
} else if (fontSize.GetUnit() != eCSSUnit_Null) {
aData->SetLengthValue(eCSSProperty_font_size, fontSize);
}
}
@ -849,13 +850,19 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
// values: "auto" | length
// default: auto
//
nsCSSValue* width = aData->ValueForWidth();
if (width->GetUnit() == eCSSUnit_Null) {
if (!aData->PropertyIsSet(eCSSProperty_width)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
nsCSSValue width;
// This does not handle auto and unitless values
if (value && value->Type() == nsAttrValue::eString) {
ParseNumericValue(value->GetStringValue(), *width, 0,
ParseNumericValue(value->GetStringValue(), width, 0,
aData->mPresContext->Document());
if (width.GetUnit() == eCSSUnit_Percent) {
aData->SetPercentValue(eCSSProperty_width,
width.GetPercentValue());
} else if (width.GetUnit() != eCSSUnit_Null) {
aData->SetLengthValue(eCSSProperty_width, width);
}
}
}
}

View File

@ -78,6 +78,8 @@ public:
inline void SetPixelValue(nsCSSPropertyID aId, float aValue);
inline void SetPixelValueIfUnset(nsCSSPropertyID aId, float aValue);
inline void SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue);
// Set a property to a number value
inline void SetNumberValue(nsCSSPropertyID aId, float aValue);

View File

@ -98,6 +98,12 @@ GenericSpecifiedValues::SetPixelValueIfUnset(nsCSSPropertyID aId, float aValue)
MOZ_STYLO_FORWARD(SetPixelValueIfUnset, (aId, aValue))
}
void
GenericSpecifiedValues::SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue)
{
MOZ_STYLO_FORWARD(SetLengthValue, (aId, aValue))
}
void
GenericSpecifiedValues::SetNumberValue(nsCSSPropertyID aId, float aValue)
{

View File

@ -250,6 +250,11 @@ SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetPixelValue, void,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property,
float value)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetLengthValue, void,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property,
float value,
nsCSSUnit unit)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetNumberValue, void,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property,

View File

@ -68,6 +68,13 @@ ServoSpecifiedValues::SetPixelValue(nsCSSPropertyID aId, float aValue)
Servo_DeclarationBlock_SetPixelValue(mDecl, aId, aValue);
}
void
ServoSpecifiedValues::SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue)
{
MOZ_ASSERT(aValue.IsLengthUnit());
Servo_DeclarationBlock_SetLengthValue(mDecl, aId, aValue.GetFloatValue(), aValue.GetUnit());
}
void
ServoSpecifiedValues::SetNumberValue(nsCSSPropertyID aId, float aValue)
{

View File

@ -60,6 +60,9 @@ public:
}
}
void SetLengthValue(nsCSSPropertyID aId,
nsCSSValue aValue);
void SetNumberValue(nsCSSPropertyID aId,
float aValue);

View File

@ -166,6 +166,12 @@ struct nsRuleData final: mozilla::GenericSpecifiedValues
}
}
void SetLengthValue(nsCSSPropertyID aId,
nsCSSValue aValue) {
nsCSSValue* val = ValueFor(aId);
*val = aValue;
}
void SetNumberValue(nsCSSPropertyID aId,
float aValue) {
ValueFor(aId)->SetFloatValue(aValue, eCSSUnit_Number);