Skip to content

Commit

Permalink
Bug 1548524 - Remove attributes deprecated from MathML3. r=emilio
Browse files Browse the repository at this point in the history
See w3c/mathml#5 (comment)
and https://groups.google.com/forum/#!topic/mozilla.dev.platform/kl5c87mBlO0

This patch introduces a new preference
mathml.deprecated_style_attributes.disabled in order to disable legacy support
for attributes background, color, fontfamily, fontsize, fontstyle and
fontweight. Note that xlink:href will be handled separately in bug 1575870.

* A new counter and deprecation message is introduced for these attributes.
  In nsMathMLElement, the old WarnDeprecated calls are replaced with a single
  call to WarnOnceAbout for the deprecate attributes. Notice that for some
  reason, the color attribute used to send warning in both ParseAttribute and
  MapMathMLAttributesInto.
* sMtableStyles is removed and replaced with a simple comparison.
* sMathML3Attributes is split into two tables: one for script attributes which
  will be handled in bug 1548471 and one for style attributes, handled here.
  The attributes in this second table is now ignored when the feature flag is
  disabled.
* test_bug553917.html is updated so that it no longer checks the old warning
  messages for these attributes. New warning messages have been verified
  manually.
* Reftests checking support for these attributes are run with the support
  enabled.
* Finally, WPT tests are run with the support disabled and a new test
  is added to verify that these attributes are no longer mapped to CSS.

Differential Revision: https://phabricator.services.mozilla.com/D43111

UltraBlame original commit: 69105b8565ce19ceb8c26757d0a81138854f1d13
  • Loading branch information
marco-c committed Oct 4, 2019
1 parent 0f2bbdb commit 0e9c061
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 48 deletions.
1 change: 1 addition & 0 deletions dom/base/nsDeprecatedOperationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ DEPRECATED_OPERATION(MouseEvent_MozPressure)
DEPRECATED_OPERATION(MathML_DeprecatedLineThicknessValue)
DEPRECATED_OPERATION(MathML_DeprecatedMathSizeValue)
DEPRECATED_OPERATION(MathML_DeprecatedMathSpaceValue)
DEPRECATED_OPERATION(MathML_DeprecatedStyleAttribute)
2 changes: 2 additions & 0 deletions dom/locales/en-US/chrome/dom/dom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,5 @@ MathML_DeprecatedMathSizeValueWarning=“small”, “normal” and “big” ar
# LOCALIZATION NOTE: Do not translate veryverythinmathspace, verythinmathspace,
# thinmathspace, mediummathspace, thickmathspace, verythickmathspace, veryverythickmathspace and MathML.
MathML_DeprecatedMathSpaceValueWarning=“veryverythinmathspace”, “verythinmathspace”, “thinmathspace”, “mediummathspace”, “thickmathspace”, “verythickmathspace” and “veryverythickmathspace” are deprecated values for MathML lengths and will be removed at a future date.
# LOCALIZATION NOTE: Do not translate MathML, background, color, fontfamily, fontsize, fontstyle and fontweight.
MathML_DeprecatedStyleAttributeWarning=MathML attributes “background”, “color”, “fontfamily”, “fontsize”, “fontstyle” and “fontweight” are deprecated and will be removed at a future date.
61 changes: 25 additions & 36 deletions dom/mathml/nsMathMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ bool nsMathMLElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
MOZ_ASSERT(IsMathMLElement());

if (aNamespaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::color) {
WarnDeprecated(nsGkAtoms::color->GetUTF16String(),
nsGkAtoms::mathcolor_->GetUTF16String(), OwnerDoc());
}
if (aAttribute == nsGkAtoms::color || aAttribute == nsGkAtoms::mathcolor_ ||
aAttribute == nsGkAtoms::background ||
aAttribute == nsGkAtoms::mathbackground_) {
Expand All @@ -136,9 +132,6 @@ bool nsMathMLElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
aMaybeScriptedPrincipal, aResult);
}

static Element::MappedAttributeEntry sMtableStyles[] = {{nsGkAtoms::width},
{nullptr}};


static Element::MappedAttributeEntry sGlobalAttributes[] = {
{nsGkAtoms::dir},
Expand All @@ -151,11 +144,10 @@ static Element::MappedAttributeEntry sGlobalAttributes[] = {
{nullptr}};


static Element::MappedAttributeEntry sMathML3Attributes[] = {

{nsGkAtoms::scriptminsize_},
{nsGkAtoms::scriptsizemultiplier_},

static Element::MappedAttributeEntry sDeprecatedScriptAttributes[] = {
{nsGkAtoms::scriptminsize_}, {nsGkAtoms::scriptsizemultiplier_}, {nullptr}};

static Element::MappedAttributeEntry sDeprecatedStyleAttributes[] = {
{nsGkAtoms::background},
{nsGkAtoms::color},
{nsGkAtoms::fontfamily_},
Expand All @@ -167,14 +159,16 @@ static Element::MappedAttributeEntry sMathML3Attributes[] = {
bool nsMathMLElement::IsAttributeMapped(const nsAtom* aAttribute) const {
MOZ_ASSERT(IsMathMLElement());

static const MappedAttributeEntry* const mtableMap[] = {
sMtableStyles, sGlobalAttributes, sMathML3Attributes};
if (mNodeInfo->Equals(nsGkAtoms::mtable_))
return FindAttributeDependence(aAttribute, mtableMap);
static const MappedAttributeEntry* const globalMap[] = {
sGlobalAttributes, sDeprecatedScriptAttributes};
static const MappedAttributeEntry* const styleMap[] = {
sDeprecatedStyleAttributes};

static const MappedAttributeEntry* const mathmlMap[] = {sGlobalAttributes,
sMathML3Attributes};
return FindAttributeDependence(aAttribute, mathmlMap);
return FindAttributeDependence(aAttribute, globalMap) ||
(!StaticPrefs::mathml_deprecated_style_attributes_disabled() &&
FindAttributeDependence(aAttribute, styleMap)) ||
(mNodeInfo->Equals(nsGkAtoms::mtable_) &&
aAttribute == nsGkAtoms::width);
}

nsMapRuleToAttributesFunc nsMathMLElement::GetAttributeMappingFunction() const {
Expand Down Expand Up @@ -526,8 +520,8 @@ void nsMathMLElement::MapMathMLAttributesInto(
parseSizeKeywords = false;
value = aAttributes->GetAttr(nsGkAtoms::fontsize_);
if (value) {
WarnDeprecated(nsGkAtoms::fontsize_->GetUTF16String(),
nsGkAtoms::mathsize_->GetUTF16String(), aDecls.Document());
aDecls.Document()->WarnOnceAbout(
dom::Document::eMathML_DeprecatedStyleAttribute);
}
}
if (value && value->Type() == nsAttrValue::eString &&
Expand Down Expand Up @@ -572,9 +566,8 @@ void nsMathMLElement::MapMathMLAttributesInto(

value = aAttributes->GetAttr(nsGkAtoms::fontfamily_);
if (value) {
WarnDeprecated(nsGkAtoms::fontfamily_->GetUTF16String(),
nsGkAtoms::mathvariant_->GetUTF16String(),
aDecls.Document());
aDecls.Document()->WarnOnceAbout(
dom::Document::eMathML_DeprecatedStyleAttribute);
}
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_family)) {
Expand All @@ -593,9 +586,8 @@ void nsMathMLElement::MapMathMLAttributesInto(

value = aAttributes->GetAttr(nsGkAtoms::fontstyle_);
if (value) {
WarnDeprecated(nsGkAtoms::fontstyle_->GetUTF16String(),
nsGkAtoms::mathvariant_->GetUTF16String(),
aDecls.Document());
aDecls.Document()->WarnOnceAbout(
dom::Document::eMathML_DeprecatedStyleAttribute);
if (value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_style)) {
nsAutoString str(value->GetStringValue());
Expand All @@ -622,9 +614,8 @@ void nsMathMLElement::MapMathMLAttributesInto(

value = aAttributes->GetAttr(nsGkAtoms::fontweight_);
if (value) {
WarnDeprecated(nsGkAtoms::fontweight_->GetUTF16String(),
nsGkAtoms::mathvariant_->GetUTF16String(),
aDecls.Document());
aDecls.Document()->WarnOnceAbout(
dom::Document::eMathML_DeprecatedStyleAttribute);
if (value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_weight)) {
nsAutoString str(value->GetStringValue());
Expand Down Expand Up @@ -722,9 +713,8 @@ void nsMathMLElement::MapMathMLAttributesInto(
if (!value) {
value = aAttributes->GetAttr(nsGkAtoms::background);
if (value) {
WarnDeprecated(nsGkAtoms::background->GetUTF16String(),
nsGkAtoms::mathbackground_->GetUTF16String(),
aDecls.Document());
aDecls.Document()->WarnOnceAbout(
dom::Document::eMathML_DeprecatedStyleAttribute);
}
}
if (value) {
Expand Down Expand Up @@ -755,9 +745,8 @@ void nsMathMLElement::MapMathMLAttributesInto(
if (!value) {
value = aAttributes->GetAttr(nsGkAtoms::color);
if (value) {
WarnDeprecated(nsGkAtoms::color->GetUTF16String(),
nsGkAtoms::mathcolor_->GetUTF16String(),
aDecls.Document());
aDecls.Document()->WarnOnceAbout(
dom::Document::eMathML_DeprecatedStyleAttribute);
}
}
nscolor color;
Expand Down
9 changes: 2 additions & 7 deletions layout/mathml/tests/test_bug553917.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
<math fontsize="10"></math>
<math xlink:href="http://www.mozilla.org"></math>*/
DeprecatedSupersededBy: {
status: [false, false, false, false, false],
args: [["fontfamily","mathvariant"],["color","mathcolor"], ["background","mathbackground"],
["fontsize","mathsize"], ["xlink:href","href"]] },
status: [false],
args: [["xlink:href","href"]] },
/*<math><mpadded width="BAD!"></mpadded></math>
<math><mpadded height="BAD!"></mpadded></math>
<math><mpadded voffset="BAD!"></mpadded></math>*/
Expand Down Expand Up @@ -199,10 +198,6 @@
<math><munderover></munderover></math>


<math fontfamily="serif"></math>
<math color="#112233"></math>
<math background="#FFFFFF"></math>
<math fontsize="10"></math>
<math xlink:href="http://www.mozilla.org"></math>


Expand Down
6 changes: 3 additions & 3 deletions layout/reftests/mathml/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
== 347496-1.xhtml 347496-1-ref.xhtml
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == 355548-1.xml 355548-1-ref.xml # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == 355548-2.xml 355548-2-ref.xml # Bug 1392106
pref(mathml.legacy_number_syntax.disabled,false) pref(mathml.nonzero_unitless_lengths.disabled,false) pref(mathml.mathsize_names.disabled,false) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == 355548-3.xml 355548-3-ref.xml # Bug 1392106
pref(mathml.deprecated_style_attributes.disabled,false) pref(mathml.legacy_number_syntax.disabled,false) pref(mathml.nonzero_unitless_lengths.disabled,false) pref(mathml.mathsize_names.disabled,false) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == 355548-3.xml 355548-3-ref.xml # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == 355548-4.xml 355548-4-ref.xml # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == 355548-5.xml 355548-5-ref.xml # Bug 1392106
== 370692-1.xhtml 370692-1-ref.xhtml
Expand Down Expand Up @@ -287,9 +287,9 @@ fails-if(Android&&!webrender) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu
fails-if(Android&&!webrender) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == mathvariant-1c.html mathvariant-1c-ref.html # Bug 1010679, Bug 1392106
== mathvariant-1d.html mathvariant-1d-ref.html
fails-if(Android&&!webrender) fails-if(OSX) == mathvariant-2.html mathvariant-2-ref.html # Bugs 1010678, 1010679
== mathvariant-3.html mathvariant-3-ref.html
pref(mathml.deprecated_style_attributes.disabled,false) == mathvariant-3.html mathvariant-3-ref.html
== mathvariant-4.html mathvariant-4-ref.html
== mathvariant-5.html mathvariant-5-ref.html
pref(mathml.deprecated_style_attributes.disabled,false) == mathvariant-5.html mathvariant-5-ref.html
== dtls-1.html dtls-1-ref.html
== dtls-2.html dtls-2-ref.html
== dtls-3.html dtls-3-ref.html
Expand Down
7 changes: 7 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5002,6 +5002,13 @@
# Prefs starting with "mathml."
#---------------------------------------------------------------------------

# Whether to disable deprecated style attributes background, color, fontfamily,
# fontsize, fontstyle and fontweight.
- name: mathml.deprecated_style_attributes.disabled
type: bool
value: @IS_NIGHTLY_BUILD@
mirror: always

# Whether to disable legacy MathML number values that are not valid CSS numbers
# (e.g. "1234.")
- name: mathml.legacy_number_syntax.disabled
Expand Down
2 changes: 1 addition & 1 deletion testing/web-platform/meta/mathml/__dir__.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prefs: [mathml.legacy_number_syntax.disabled: true, mathml.mathsize_names.disabled:true, mathml.mathspace_names.disabled: true, mathml.mfrac_linethickness_names.disabled:true, mathml.nonzero_unitless_lengths.disabled:true]
prefs: [mathml.deprecated_style_attributes.disabled: true, mathml.legacy_number_syntax.disabled: true, mathml.mathsize_names.disabled:true, mathml.mathspace_names.disabled: true, mathml.mfrac_linethickness_names.disabled:true, mathml.nonzero_unitless_lengths.disabled:true]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Attribute mapping</title>
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#legacy-mathml-style-attributes">
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#attributes-common-to-html-and-mathml-elements">
<meta name="assert" content="Verify that dir, mathcolor, mathbackground and mathsize are mapped to CSS">
<meta name="assert" content="Verify that dir, mathcolor, mathbackground and mathsize are mapped to CSS but that deprecated MathML3 attributes are not.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/mathml-fragments.js"></script>
Expand Down Expand Up @@ -70,6 +70,23 @@
element.setAttribute("mathsize", "30Px");
assert_equals(style.getPropertyValue("font-size"), "30px", "case insensitive");
}, `mathsize on the ${tag} element is mapped to CSS font-size`);

test(function() {
var properties = ["background-color", "color", "fontfamily", "font-size", "font-style", "font-weight"];
var oldStyle = {};
properties.forEach(property => {
oldStyle[property] = style.getPropertyValue(property);
});
element.setAttribute("background", "red");
element.setAttribute("color", "blue");
element.setAttribute("fontfamily", "monospace");
element.setAttribute("fontsize", "50px");
element.setAttribute("fontstyle", "italic");
element.setAttribute("fontweight", "bold");
properties.forEach(property => {
assert_equals(style.getPropertyValue(property), oldStyle[property], `${property}`);
});
}, `deprecated MathML3 attributes on the ${tag} element are not mapped to CSS`);
});

done();
Expand Down

0 comments on commit 0e9c061

Please sign in to comment.