Bug 1666075 - Implement displaystyle attribute on all MathML elements. r=emilio

Gecko implements the displaystyle attribute as defined by MathML 3 i.e.
only on the math, mstyle and mtable elements. This commit follows MathML
Core and instead define it as a global attribute mapped to math-style.
See https://mathml-refresh.github.io/mathml-core/#the-displaystyle-and-scriptlevel-attributes

Differential Revision: https://phabricator.services.mozilla.com/D90786
This commit is contained in:
Frederic Wang 2020-09-24 15:34:17 +00:00
Родитель bf9ddd7014
Коммит 7ef35cabad
9 изменённых файлов: 30 добавлений и 225 удалений

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

@ -127,14 +127,10 @@ bool MathMLElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
// https://mathml-refresh.github.io/mathml-core/#global-attributes
static Element::MappedAttributeEntry sGlobalAttributes[] = {
{nsGkAtoms::dir},
{nsGkAtoms::mathbackground_},
{nsGkAtoms::mathcolor_},
{nsGkAtoms::mathsize_},
{nsGkAtoms::mathvariant_},
{nsGkAtoms::scriptlevel_},
// XXXfredw: Also map displaystyle to CSS math-style?
{nullptr}};
{nsGkAtoms::dir}, {nsGkAtoms::mathbackground_},
{nsGkAtoms::mathcolor_}, {nsGkAtoms::mathsize_},
{nsGkAtoms::mathvariant_}, {nsGkAtoms::scriptlevel_},
{nsGkAtoms::displaystyle_}, {nullptr}};
// XXXfredw(bug 1548471): Add a runtime flag to disable these attributes.
static Element::MappedAttributeEntry sDeprecatedScriptAttributes[] = {
@ -387,7 +383,7 @@ void MathMLElement::MapMathMLAttributesInto(
aAttributes->GetAttr(nsGkAtoms::scriptsizemultiplier_);
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty__moz_script_size_multiplier)) {
nsAutoString str(value->GetStringValue());
auto str = value->GetStringValue();
str.CompressWhitespace();
// MathML numbers can't have leading '+'
if (str.Length() > 0 && str.CharAt(0) != '+') {
@ -446,7 +442,7 @@ void MathMLElement::MapMathMLAttributesInto(
value = aAttributes->GetAttr(nsGkAtoms::scriptlevel_);
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty__moz_script_level)) {
nsAutoString str(value->GetStringValue());
auto str = value->GetStringValue();
str.CompressWhitespace();
if (str.Length() > 0) {
nsresult errorCode;
@ -501,7 +497,7 @@ void MathMLElement::MapMathMLAttributesInto(
}
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_size)) {
nsAutoString str(value->GetStringValue());
auto str = value->GetStringValue();
nsCSSValue fontSize;
uint32_t flags = PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT;
if (parseSizeKeywords) {
@ -565,7 +561,7 @@ void MathMLElement::MapMathMLAttributesInto(
dom::Document::eMathML_DeprecatedStyleAttribute);
if (value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_style)) {
nsAutoString str(value->GetStringValue());
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.
@ -593,7 +589,7 @@ void MathMLElement::MapMathMLAttributesInto(
dom::Document::eMathML_DeprecatedStyleAttribute);
if (value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_font_weight)) {
nsAutoString str(value->GetStringValue());
auto str = value->GetStringValue();
str.CompressWhitespace();
if (str.EqualsASCII("normal")) {
aDecls.SetKeywordValue(eCSSProperty_font_weight,
@ -619,7 +615,7 @@ void MathMLElement::MapMathMLAttributesInto(
value = aAttributes->GetAttr(nsGkAtoms::mathvariant_);
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty__moz_math_variant)) {
nsAutoString str(value->GetStringValue());
auto str = value->GetStringValue();
str.CompressWhitespace();
static const char sizes[19][23] = {"normal",
"bold",
@ -778,7 +774,7 @@ void MathMLElement::MapMathMLAttributesInto(
value = aAttributes->GetAttr(nsGkAtoms::dir);
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_direction)) {
nsAutoString str(value->GetStringValue());
auto str = value->GetStringValue();
static const char dirs[][4] = {"ltr", "rtl"};
static const StyleDirection dirValues[MOZ_ARRAY_LENGTH(dirs)] = {
StyleDirection::Ltr, StyleDirection::Rtl};
@ -789,6 +785,23 @@ void MathMLElement::MapMathMLAttributesInto(
}
}
}
// displaystyle
// https://mathml-refresh.github.io/mathml-core/#dfn-displaystyle
value = aAttributes->GetAttr(nsGkAtoms::displaystyle_);
if (value && value->Type() == nsAttrValue::eString &&
!aDecls.PropertyIsSet(eCSSProperty_math_style)) {
auto str = value->GetStringValue();
static const char displaystyles[][6] = {"false", "true"};
static const uint8_t mathStyle[MOZ_ARRAY_LENGTH(displaystyles)] = {
NS_STYLE_MATH_STYLE_COMPACT, NS_STYLE_MATH_STYLE_NORMAL};
for (uint32_t i = 0; i < ArrayLength(displaystyles); ++i) {
if (str.LowerCaseEqualsASCII(displaystyles[i])) {
aDecls.SetKeywordValue(eCSSProperty_math_style, mathStyle[i]);
break;
}
}
}
}
void MathMLElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {

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

@ -37,12 +37,6 @@ math[display="inline" i] {
display: inline;
math-style: compact;
}
math[displaystyle="false" i] {
math-style: compact;
}
math[displaystyle="true" i] {
math-style: normal;
}
/**************************************************************************/
/* Token elements */
@ -227,16 +221,6 @@ mtable[framespacing] > mtr > mtd {
and display attributes. See the <math> section above.
*/
/*
Map mstyle@displaystyle to math-style.
*/
mstyle[displaystyle="false" i] {
math-style: compact;
}
mstyle[displaystyle="true" i] {
math-style: normal;
}
/* munder, mover and munderover change the scriptlevels of their children
using -moz-math-increment-script-level because regular CSS rules are
insufficient to control when the scriptlevel should be incremented. All other
@ -313,7 +297,6 @@ munderover > :not(:first-child) {
mtable element sets displaystyle to "false" within the table elements.
*/
mtable { math-style: compact; }
mtable[displaystyle="true" i] { math-style: normal; }
/*
The mscarries element sets displaystyle to "false", and increments

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

@ -247,6 +247,7 @@ ${helpers.single_keyword(
has_effect_on_gecko_scrollbars=False,
animation_value_type="none",
enabled_in="ua",
needs_conversion=True,
)}
${helpers.single_keyword(

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

@ -4881,6 +4881,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
},
FontWeight => longhands::font_weight::SpecifiedValue::from_gecko_keyword(value),
ListStyleType => Box::new(longhands::list_style_type::SpecifiedValue::from_gecko_keyword(value)),
MathStyle => longhands::math_style::SpecifiedValue::from_gecko_keyword(value),
MozMathVariant => longhands::_moz_math_variant::SpecifiedValue::from_gecko_keyword(value),
WhiteSpace => longhands::white_space::SpecifiedValue::from_gecko_keyword(value),
CaptionSide => longhands::caption_side::SpecifiedValue::from_gecko_keyword(value),

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

@ -1,19 +0,0 @@
[frac-parameters-1.html]
[DenominatorGapMin Displaystyle on fraction]
expected: FAIL
[NumeratorDisplayStyleGapMin Displaystyle on fraction]
expected: FAIL
[DenominatorDisplayStyleShiftDown Displaystyle on fraction]
expected: FAIL
[DenominatorShiftDown Displaystyle on fraction]
expected: FAIL
[DenominatorDisplayStyleGapMin Displaystyle on fraction]
expected: FAIL
[NumeratorDisplayStyleShiftDown Displaystyle on fraction]
expected: FAIL

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

@ -1,13 +0,0 @@
[frac-parameters-2.html]
[ToShiftUp with Displaystyle on fraction]
expected: FAIL
[BottomDisplayStyleShiftDown Displaystyle om fraction]
expected: FAIL
[TopDisplayStyleShiftUp Displaystyle on fraction]
expected: FAIL
[DisplayStyleGapMin Dsiplaystyle on fraction]
expected: FAIL

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

@ -1,13 +1,4 @@
[attribute-mapping-002.html]
[displaystyle on the mphantom element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the mspace element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the mtd element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the munderover element is mapped to CSS text-transform]
expected: FAIL
@ -17,15 +8,6 @@
[mathvariant on the maction element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the munderover element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the msup element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the msub element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the munder element is mapped to CSS text-transform]
expected: FAIL
@ -35,45 +17,24 @@
[mathvariant on the mo element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the ms element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mtr element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mtr element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the annotation element is mapped to CSS text-transform]
expected: FAIL
[mathvariant on the mtd element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mo element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the maction element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mpadded element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the msqrt element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mprescripts element is mapped to CSS text-transform]
expected: FAIL
[mathvariant on the menclose element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the merror element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the menclose element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mover element is mapped to CSS text-transform]
expected: FAIL
@ -83,15 +44,9 @@
[mathvariant on the mi element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mtext element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the msubsup element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the munder element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the msub element is mapped to CSS text-transform]
expected: FAIL
@ -104,15 +59,6 @@
[mathvariant on the none element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mmultiscripts element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the mn element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the mi element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mmultiscripts element is mapped to CSS text-transform]
expected: FAIL
@ -122,63 +68,30 @@
[mathvariant on the mtext element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mfrac element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the msubsup element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the mrow element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the annotation-xml element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the none element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mroot element is mapped to CSS text-transform]
expected: FAIL
[mathvariant on the math element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mover element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mspace element is mapped to CSS text-transform]
expected: FAIL
[mathvariant on the msqrt element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mroot element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the mprescripts element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the mn element is mapped to CSS text-transform]
expected: FAIL
[mathvariant on the msup element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the mpadded element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the ms element is mapped to CSS text-transform]
expected: FAIL
[displaystyle on the annotation-xml element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the annotation element is mapped to CSS math-style]
expected: FAIL
[displaystyle on the semantics element is mapped to CSS math-style]
expected: FAIL
[mathvariant on the semantics element is mapped to CSS text-transform]
expected: FAIL

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

@ -1,64 +0,0 @@
[displaystyle-2.html]
[mover element (alternate_case)]
expected: FAIL
[msub element (lowercase)]
expected: FAIL
[mover element (uppercase)]
expected: FAIL
[msup element (lowercase)]
expected: FAIL
[munder element (uppercase)]
expected: FAIL
[mroot element (lowercase)]
expected: FAIL
[msub element (uppercase)]
expected: FAIL
[munderover element (alternate_case)]
expected: FAIL
[mroot element (uppercase)]
expected: FAIL
[munderover element (lowercase)]
expected: FAIL
[mroot element (alternate_case)]
expected: FAIL
[munder element (alternate_case)]
expected: FAIL
[msub element (alternate_case)]
expected: FAIL
[msubsup element (alternate_case)]
expected: FAIL
[msubsup element (lowercase)]
expected: FAIL
[munder element (lowercase)]
expected: FAIL
[mover element (lowercase)]
expected: FAIL
[munderover element (uppercase)]
expected: FAIL
[msubsup element (uppercase)]
expected: FAIL
[msup element (uppercase)]
expected: FAIL
[msup element (alternate_case)]
expected: FAIL

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

@ -1,10 +0,0 @@
[displaystyle-3.html]
[movablelimits for munderover element (displaystyle=true)]
expected: FAIL
[movablelimits for munder element (displaystyle=true)]
expected: FAIL
[movablelimits for mover element (displaystyle=true)]
expected: FAIL