Skip to content

Commit

Permalink
Bug 1783841 - Remove MathML preferences deprecated_style_attributes a…
Browse files Browse the repository at this point in the history
…nd mathsize_names. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D154087
  • Loading branch information
fred-wang committed Aug 11, 2022
1 parent f795e7c commit 19970b9
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 364 deletions.
208 changes: 6 additions & 202 deletions dom/mathml/MathMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,12 @@ static Element::MappedAttributeEntry sGlobalAttributes[] = {
{nsGkAtoms::mathvariant_}, {nsGkAtoms::scriptlevel_},
{nsGkAtoms::displaystyle_}, {nullptr}};

static Element::MappedAttributeEntry sDeprecatedStyleAttributes[] = {
{nsGkAtoms::background},
{nsGkAtoms::color},
{nsGkAtoms::fontfamily_},
{nsGkAtoms::fontsize_},
{nsGkAtoms::fontstyle_},
{nsGkAtoms::fontweight_},
{nullptr}};

bool MathMLElement::IsAttributeMapped(const nsAtom* aAttribute) const {
MOZ_ASSERT(IsMathMLElement());

static const MappedAttributeEntry* const globalMap[] = {sGlobalAttributes};
static const MappedAttributeEntry* const styleMap[] = {
sDeprecatedStyleAttributes};

return FindAttributeDependence(aAttribute, globalMap) ||
(!StaticPrefs::mathml_deprecated_style_attributes_disabled() &&
FindAttributeDependence(aAttribute, styleMap)) ||
(!StaticPrefs::mathml_scriptminsize_attribute_disabled() &&
aAttribute == nsGkAtoms::scriptminsize_) ||
(!StaticPrefs::mathml_scriptsizemultiplier_attribute_disabled() &&
Expand Down Expand Up @@ -463,142 +450,22 @@ void MathMLElement::MapMathMLAttributesInto(
}

// mathsize
//
// "Specifies the size to display the token content. The values 'small' and
// 'big' choose a size smaller or larger than the current font size, but
// leave the exact proportions unspecified; 'normal' is allowed for
// completeness, but since it is equivalent to '100%' or '1em', it has no
// effect."
//
// values: "small" | "normal" | "big" | length
// default: inherited
//
// fontsize
//
// "Specified the size for the token. Deprecated in favor of mathsize."
//
// values: length
// default: inherited
//
// In both cases, we don't allow negative values.
// Unitless values give a multiple of the default value.
//
bool parseSizeKeywords = !StaticPrefs::mathml_mathsize_names_disabled();
// https://w3c.github.io/mathml-core/#dfn-mathsize
value = aAttributes->GetAttr(nsGkAtoms::mathsize_);
if (!value) {
parseSizeKeywords = false;
value = aAttributes->GetAttr(nsGkAtoms::fontsize_);
if (value) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedStyleAttribute);
}
}
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_size)) {
auto str = value->GetStringValue();
nsCSSValue fontSize;
uint32_t flags = PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT;
if (parseSizeKeywords) {
// Do not warn for invalid value if mathsize keywords are accepted.
flags |= PARSE_SUPPRESS_WARNINGS;
}
if (!ParseNumericValue(str, fontSize, flags, nullptr) &&
parseSizeKeywords) {
static const char sizes[3][7] = {"small", "normal", "big"};
static const StyleFontSizeKeyword values[MOZ_ARRAY_LENGTH(sizes)] = {
StyleFontSizeKeyword::Small, StyleFontSizeKeyword::Medium,
StyleFontSizeKeyword::Large};
str.CompressWhitespace();
for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
if (str.EqualsASCII(sizes[i])) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedMathSizeValue);
aDecls.SetKeywordValue(eCSSProperty_font_size, values[i]);
break;
}
}
} else if (fontSize.GetUnit() == eCSSUnit_Percent) {
ParseNumericValue(str, fontSize, flags, nullptr);
if (fontSize.GetUnit() == eCSSUnit_Percent) {
aDecls.SetPercentValue(eCSSProperty_font_size,
fontSize.GetPercentValue());
} else if (fontSize.GetUnit() != eCSSUnit_Null) {
aDecls.SetLengthValue(eCSSProperty_font_size, fontSize);
}
}

// fontfamily
//
// "Should be the name of a font that may be available to a MathML renderer,
// or a CSS font specification; See Section 6.5 Using CSS with MathML and
// CSS for more information. Deprecated in favor of mathvariant."
//
// values: string
//
value = aAttributes->GetAttr(nsGkAtoms::fontfamily_);
if (value) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedStyleAttribute);
}
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_family)) {
aDecls.SetFontFamily(NS_ConvertUTF16toUTF8(value->GetStringValue()));
}

// fontstyle
//
// "Specified the font style to use for the token. Deprecated in favor of
// mathvariant."
//
// values: "normal" | "italic"
// default: normal (except on <mi>)
//
// Note that the font-style property is reset in layout/style/ when
// -moz-math-variant is specified.
value = aAttributes->GetAttr(nsGkAtoms::fontstyle_);
if (value) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedStyleAttribute);
if (value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_style)) {
auto str = value->GetStringValue();
str.CompressWhitespace();
// FIXME(emilio): This should use FontSlantStyle or what not. Or even
// better, it looks deprecated since forever, we should just kill it.
if (str.EqualsASCII("normal")) {
aDecls.SetKeywordValue(eCSSProperty_font_style, NS_FONT_STYLE_NORMAL);
} else if (str.EqualsASCII("italic")) {
aDecls.SetKeywordValue(eCSSProperty_font_style, NS_FONT_STYLE_ITALIC);
}
}
}

// fontweight
//
// "Specified the font weight for the token. Deprecated in favor of
// mathvariant."
//
// values: "normal" | "bold"
// default: normal
//
// Note that the font-weight property is reset in layout/style/ when
// -moz-math-variant is specified.
value = aAttributes->GetAttr(nsGkAtoms::fontweight_);
if (value) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedStyleAttribute);
if (value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_weight)) {
auto str = value->GetStringValue();
str.CompressWhitespace();
if (str.EqualsASCII("normal")) {
aDecls.SetKeywordValue(eCSSProperty_font_weight,
FontWeight::NORMAL.ToFloat());
} else if (str.EqualsASCII("bold")) {
aDecls.SetKeywordValue(eCSSProperty_font_weight,
FontWeight::BOLD.ToFloat());
}
}
}

// mathvariant
//
// "Specifies the logical class of the token. Note that this class is more
Expand Down Expand Up @@ -661,31 +528,8 @@ void MathMLElement::MapMathMLAttributesInto(
}

// mathbackground
//
// "Specifies the background color to be used to fill in the bounding box of
// the element and its children. The default, 'transparent', lets the
// background color, if any, used in the current rendering context to show
// through."
//
// values: color | "transparent"
// default: "transparent"
//
// background
//
// "Specified the background color to be used to fill in the bounding box of
// the element and its children. Deprecated in favor of mathbackground."
//
// values: color | "transparent"
// default: "transparent"
//
// https://w3c.github.io/mathml-core/#dfn-mathbackground
value = aAttributes->GetAttr(nsGkAtoms::mathbackground_);
if (!value) {
value = aAttributes->GetAttr(nsGkAtoms::background);
if (value) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedStyleAttribute);
}
}
if (value) {
nscolor color;
if (value->GetColorValue(color)) {
Expand All @@ -694,30 +538,8 @@ void MathMLElement::MapMathMLAttributesInto(
}

// mathcolor
//
// "Specifies the foreground color to use when drawing the components of this
// element, such as the content for token elements or any lines, surds, or
// other decorations. It also establishes the default mathcolor used for
// child elements when used on a layout element."
//
// values: color
// default: inherited
//
// color
//
// "Specified the color for the token. Deprecated in favor of mathcolor."
//
// values: color
// default: inherited
//
// https://w3c.github.io/mathml-core/#dfn-mathcolor
value = aAttributes->GetAttr(nsGkAtoms::mathcolor_);
if (!value) {
value = aAttributes->GetAttr(nsGkAtoms::color);
if (value) {
aDecls.Document()->WarnOnceAbout(
dom::DeprecatedOperations::eMathML_DeprecatedStyleAttribute);
}
}
nscolor color;
if (value && value->GetColorValue(color)) {
aDecls.SetColorValueIfUnset(eCSSProperty_color, color);
Expand Down Expand Up @@ -750,25 +572,7 @@ void MathMLElement::MapMathMLAttributesInto(
}

// dir
//
// Overall Directionality of Mathematics Formulas:
// "The overall directionality for a formula, basically the direction of the
// Layout Schemata, is specified by the dir attribute on the containing math
// element (see Section 2.2 The Top-Level math Element). The default is ltr.
// [...] The overall directionality is usually set on the math, but may also
// be switched for individual subformula by using the dir attribute on mrow
// or mstyle elements."
//
// Bidirectional Layout in Token Elements:
// "Specifies the initial directionality for text within the token:
// ltr (Left To Right) or rtl (Right To Left). This attribute should only be
// needed in rare cases involving weak or neutral characters;
// see Section 3.1.5.1 Overall Directionality of Mathematics Formulas for
// further discussion. It has no effect on mspace."
//
// values: "ltr" | "rtl"
// default: inherited
//
// https://w3c.github.io/mathml-core/#dfn-dir
value = aAttributes->GetAttr(nsGkAtoms::dir);
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_direction)) {
Expand Down
7 changes: 3 additions & 4 deletions layout/mathml/tests/test_bug553917.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
stringBundleService.createBundle("chrome://global/locale/mathml/mathml.properties");

const allow_linethickness_names = !SpecialPowers.getBoolPref('mathml.mfrac_linethickness_names.disabled');
const allow_mathsize_names = !SpecialPowers.getBoolPref('mathml.mathsize_names.disabled');
const allow_mathspace_names = !SpecialPowers.getBoolPref('mathml.mathspace_names.disabled');
const allow_scriptsizemultiplier_attribute = !SpecialPowers.getBoolPref('mathml.scriptsizemultiplier_attribute.disabled');

Expand Down Expand Up @@ -75,9 +74,9 @@
allow_linethickness_names,
allow_linethickness_names,
allow_linethickness_names,
allow_mathsize_names,
allow_mathsize_names,
allow_mathsize_names,
false,
false,
false,
allow_mathspace_names,
allow_mathspace_names,
allow_mathspace_names,
Expand Down
14 changes: 0 additions & 14 deletions layout/reftests/mathml/355548-3-ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,17 @@
<p><m:math>
<m:mstyle><m:mi style="font-size:30px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:30px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:30px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:30px;">Id</m:mi></m:mstyle>
</m:math></p>

<p><m:math>
<m:mstyle><m:mi style="font-size:small;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:medium;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:large;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
</m:math></p>

<p><m:math>
<m:mstyle><m:mi style="font-family:Verdana; font-size:48px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-family:monospace; font-size:48px;">Id</m:mi></m:mstyle>
</m:math></p>

<p><m:math>
<m:mstyle><m:mi style="font-size:48px; background:green;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px; background:green;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px; background:green;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px; background:green;">Id</m:mi></m:mstyle>
</m:math></p>

<p><m:math>
Expand All @@ -40,8 +28,6 @@
<p><m:math>
<m:mstyle><m:mi style="font-size:48px; color:green;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px; color:green;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px; color:green;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px; color:green;">Id</m:mi></m:mstyle>
</m:math></p>

<p><m:math>
Expand Down
30 changes: 6 additions & 24 deletions layout/reftests/mathml/355548-3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,20 @@

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
<m:mstyle mathsize="30px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle fontsize="30px"><m:mi>Id</m:mi></m:mstyle>
<!-- mathsize takes priority over fontsize -->
<m:mstyle mathsize="30px" fontsize="20px"><m:mi>Id</m:mi></m:mstyle>
<!-- CSS takes priority over mathsize and fontsize -->
<m:mstyle mathsize="24px" fontsize="20px" style="font-size:30px;"><m:mi>Id</m:mi></m:mstyle>
<!-- CSS takes priority over mathsize -->
<m:mstyle mathsize="24px" style="font-size:30px;"><m:mi>Id</m:mi></m:mstyle>
</m:mstyle></m:math></p>

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
<m:mstyle mathsize="small"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="normal"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="big"><m:mi>Id</m:mi></m:mstyle>
<!-- check that fontsize doesn't accept those values -->
<m:mstyle fontsize="small"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle fontsize="normal"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle fontsize="big"><m:mi>Id</m:mi></m:mstyle>
</m:mstyle></m:math></p>

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
<m:mstyle fontfamily="Verdana"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle fontfamily="Verdana" style="font-family:monospace;"><m:mi>Id</m:mi></m:mstyle>
</m:mstyle></m:math></p>

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
<m:mstyle mathbackground="green"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle background="green"><m:mi>Id</m:mi></m:mstyle>
<!-- mathsize takes priority over fontsize -->
<m:mstyle mathbackground="green" background="red"><m:mi>Id</m:mi></m:mstyle>
<!-- CSS takes priority over mathsize and fontsize -->
<m:mstyle mathbackground="red" background="yellow" style="background:green;"><m:mi>Id</m:mi></m:mstyle>
<!-- CSS takes priority over mathbackground -->
<m:mstyle mathbackground="red" style="background:green;"><m:mi>Id</m:mi></m:mstyle>
</m:mstyle></m:math></p>

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
Expand All @@ -46,11 +31,8 @@

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
<m:mstyle mathcolor="green"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle color="green"><m:mi>Id</m:mi></m:mstyle>
<!-- mathsize takes priority over fontsize -->
<m:mstyle mathcolor="green" color="red"><m:mi>Id</m:mi></m:mstyle>
<!-- CSS takes priority over mathsize and fontsize -->
<m:mstyle mathcolor="red" color="yellow" style="color:green;"><m:mi>Id</m:mi></m:mstyle>
<!-- CSS takes priority over mathcolor -->
<m:mstyle mathcolor="red" style="color:green;"><m:mi>Id</m:mi></m:mstyle>
</m:mstyle></m:math></p>

<p><m:math><m:mstyle scriptlevel="0" scriptsizemultiplier="0.5" scriptminsize="18px" style="font-size:48px;">
Expand Down
Loading

0 comments on commit 19970b9

Please sign in to comment.