Skip to content

Commit

Permalink
[mathml] Update CSS math-superscript-shift to match the specification
Browse files Browse the repository at this point in the history
This feature was initially implemented in [1] [2]. After discussion with
the CSSWG, the property and values have been renamed [3]. This CL performs
the following changes:
- Rename math-superscript-shift to math-shift
- Rename value "display" and "inline" to "normal" and "compact"
- Add a MathML test to verify the effect of CSS math-shift
  (rather than just testing indirectly via UA style sheet rules).
- Sort math-style / math-shift alphabetically

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2144185
[2] https://chromium-review.googlesource.com/c/chromium/src/+/2277814
[3] w3c/csswg-drafts#5388

Bug: 6606
Change-Id: I1c7c7c12954261217cafffabffbe044c6659db9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421662
Reviewed-by: Rob Buis <[email protected]>
Reviewed-by: Rune Lillesveen <[email protected]>
Commit-Queue: Frédéric Wang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#809259}
  • Loading branch information
fred-wang authored and Commit Bot committed Sep 22, 2020
1 parent 0ca99fb commit c82a21d
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ enum CSSSampleId {
kMathStyle = 656,
kAspectRatio = 657,
kAppearance = 658,
kMathSuperscriptShiftStyle = 659,
// kMathSuperscriptShiftStyle = 659,
kRubyPosition = 660,
kTextUnderlineOffset = 661,
kContentVisibility = 662,
Expand All @@ -719,6 +719,7 @@ enum CSSSampleId {
kDescentOverride = 673,
kAdvanceOverride = 674,
kLineGapOverride = 675,
kMathShift = 676,
// 1. Add new features above this line (don't change the assigned numbers of
// the existing items).
// 2. Run the src/tools/metrics/histograms/update_use_counter_css.py script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ const CSSPropertyID kComputedPropertyArray[] = {
CSSPropertyID::kMarginLeft, CSSPropertyID::kMarginRight,
CSSPropertyID::kMarginTop, CSSPropertyID::kMarkerEnd,
CSSPropertyID::kMarkerMid, CSSPropertyID::kMarkerStart,
CSSPropertyID::kMaskType, CSSPropertyID::kMathStyle,
CSSPropertyID::kMathSuperscriptShiftStyle, CSSPropertyID::kMaxBlockSize,
CSSPropertyID::kMaskType, CSSPropertyID::kMathShift,
CSSPropertyID::kMathStyle, CSSPropertyID::kMaxBlockSize,
CSSPropertyID::kMaxHeight, CSSPropertyID::kMaxInlineSize,
CSSPropertyID::kMaxWidth, CSSPropertyID::kMinBlockSize,
CSSPropertyID::kMinHeight, CSSPropertyID::kMinInlineSize,
Expand Down
14 changes: 7 additions & 7 deletions third_party/blink/renderer/core/css/css_properties.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2516,26 +2516,26 @@
keywords: ["luminance", "alpha"],
typedom_types: ["Keyword"]
},
// TODO(rbuis): should be moved to high priority later.
{
name: "math-style",
name: "math-shift",
property_methods: ["CSSValueFromComputedStyleInternal"],
field_template: "keyword",
inherited: true,
keywords: ["normal", "compact"],
typedom_types: ["Keyword"],
default_value: "normal",
runtime_flag: "CSSMathStyle"
runtime_flag: "CSSMathShift"
},
// TODO(rbuis): should be moved to high priority later.
{
name: "math-superscript-shift-style",
name: "math-style",
property_methods: ["CSSValueFromComputedStyleInternal"],
field_template: "keyword",
inherited: true,
keywords: ["inline", "display"],
keywords: ["normal", "compact"],
typedom_types: ["Keyword"],
default_value: "display",
runtime_flag: "CSSMathSuperscriptShiftStyle"
default_value: "normal",
runtime_flag: "CSSMathStyle"
},
{
name: "max-height",
Expand Down
10 changes: 4 additions & 6 deletions third_party/blink/renderer/core/css/css_value_keywords.json5
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,13 @@
"wavy",
"-webkit-nowrap",

//
// math-style
//
// math-shift
// normal
"compact",

// math-shift
// inline
"display",
// math-style
// normal
// compact

// CSS3 Values
// box-align
Expand Down
10 changes: 5 additions & 5 deletions third_party/blink/renderer/core/css/mathml.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* By default, we only display the MathML formulas without any formatting other than the one specified by the display attribute. */
math {
display: inline-math;
math-superscript-shift-style: display;
math-shift: normal;
math-style: compact;
}

Expand Down Expand Up @@ -83,16 +83,16 @@ mfrac > * {
}

mfrac > :nth-child(2) {
math-superscript-shift-style: inline;
math-shift: compact;
}

/* Other rules for scriptlevel, displaystyle and math-superscript-shift-style */
/* Other rules for scriptlevel, displaystyle and math-shift */
mroot > :not(:first-child) {
font-size: scriptlevel(add(2));
math-style: compact;
}
mroot, msqrt {
math-superscript-shift-style: inline;
math-shift: compact;
}
msub > :not(:first-child),
msup > :not(:first-child),
Expand All @@ -116,6 +116,6 @@ munder > :nth-child(2),
munderover > :nth-child(2),
mover[accent="true" i] > :first-child,
munderover[accent="true" i] > :first-child {
math-superscript-shift-style: inline;
math-shift: compact;
}

Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,14 @@ bool CSSParserFastPaths::IsValidKeywordPropertyAndValue(
case CSSPropertyID::kMaskType:
return value_id == CSSValueID::kLuminance ||
value_id == CSSValueID::kAlpha;
case CSSPropertyID::kMathShift:
DCHECK(RuntimeEnabledFeatures::CSSMathShiftEnabled());
return value_id == CSSValueID::kNormal ||
value_id == CSSValueID::kCompact;
case CSSPropertyID::kMathStyle:
DCHECK(RuntimeEnabledFeatures::CSSMathStyleEnabled());
return value_id == CSSValueID::kNormal ||
value_id == CSSValueID::kCompact;
case CSSPropertyID::kMathSuperscriptShiftStyle:
DCHECK(RuntimeEnabledFeatures::CSSMathSuperscriptShiftStyleEnabled());
return value_id == CSSValueID::kInline ||
value_id == CSSValueID::kDisplay;
case CSSPropertyID::kObjectFit:
return value_id == CSSValueID::kFill ||
value_id == CSSValueID::kContain ||
Expand Down Expand Up @@ -1045,8 +1045,8 @@ bool CSSParserFastPaths::IsKeywordPropertyID(CSSPropertyID property_id) {
case CSSPropertyID::kListStylePosition:
case CSSPropertyID::kListStyleType:
case CSSPropertyID::kMaskType:
case CSSPropertyID::kMathShift:
case CSSPropertyID::kMathStyle:
case CSSPropertyID::kMathSuperscriptShiftStyle:
case CSSPropertyID::kObjectFit:
case CSSPropertyID::kOutlineStyle:
case CSSPropertyID::kOverflowAnchor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4083,20 +4083,20 @@ const CSSValue* MaskType::CSSValueFromComputedStyleInternal(
return CSSIdentifierValue::Create(svg_style.MaskType());
}

const CSSValue* MathStyle::CSSValueFromComputedStyleInternal(
const CSSValue* MathShift::CSSValueFromComputedStyleInternal(
const ComputedStyle& style,
const SVGComputedStyle&,
const LayoutObject*,
bool allow_visited_style) const {
return CSSIdentifierValue::Create(style.MathStyle());
return CSSIdentifierValue::Create(style.MathShift());
}

const CSSValue* MathSuperscriptShiftStyle::CSSValueFromComputedStyleInternal(
const CSSValue* MathStyle::CSSValueFromComputedStyleInternal(
const ComputedStyle& style,
const SVGComputedStyle&,
const LayoutObject*,
bool allow_visited_style) const {
return CSSIdentifierValue::Create(style.MathSuperscriptShiftStyle());
return CSSIdentifierValue::Create(style.MathStyle());
}

const CSSValue* MaxBlockSize::ParseSingleValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ NGMathScriptsLayoutAlgorithm::GetVerticalMetrics(
if (type == MathScriptType::kSuper || type == MathScriptType::kSubSup ||
type == MathScriptType::kMultiscripts || type == MathScriptType::kOver ||
type == MathScriptType::kMultiscripts) {
if (Style().MathSuperscriptShiftStyle() ==
EMathSuperscriptShiftStyle::kInline)
if (Style().MathShift() == EMathShift::kCompact)
shift_up = parameters.superscript_shift_up_cramped;
metrics.sup_shift =
std::max(shift_up, base_metrics.ascent -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,12 @@
name: "CSSMatchedPropertiesCacheDependencies",
},
{
name: "CSSMathStyle",
name: "CSSMathShift",
status: "experimental",
implied_by: ["MathMLCore"],
},
{
name: "CSSMathSuperscriptShiftStyle",
name: "CSSMathStyle",
status: "experimental",
implied_by: ["MathMLCore"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#radicals-msqrt-mroot">
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#displaystyle-and-scriptlevel-in-scripts">
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#user-agent-stylesheet">
<meta name="assert" content="Verify default calculation of math-superscript-shift-style on MathML elements">
<meta name="assert" content="Verify default calculation of math-shift on MathML elements">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
Expand Down Expand Up @@ -138,6 +138,14 @@
assert_cramped("mmultiscripts-005", false, "post-superscript");
}, "mmultiscripts");

test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_cramped("css-001", false);
assert_cramped("css-002", true);
assert_cramped("css-003", true);
assert_cramped("css-004", false);
}, "element with specified CSS math-style");

done();
}
</script>
Expand Down Expand Up @@ -588,5 +596,31 @@
</mmultiscripts>
</math>
</p>
<p>
<math id="css-001" style="math-shift: normal">
<msup class="testedElement">
<mspace height="2em" width="2em"/>
<mspace height="1em" width="1em"/>
</msup>
</math>
<math id="css-002" style="math-shift: compact">
<msup class="testedElement">
<mspace height="2em" width="2em"/>
<mspace height="1em" width="1em"/>
</msup>
</math>
<math id="css-003" style="math-shift: normal">
<msup class="testedElement" style="math-shift: compact">
<mspace height="2em" width="2em"/>
<mspace height="1em" width="1em"/>
</msup>
</math>
<math id="css-004" style="math-shift: compact">
<msup class="testedElement" style="math-shift: normal">
<mspace height="2em" width="2em"/>
<mspace height="1em" width="1em"/>
</msup>
</math>
</p>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ marker-end: none
marker-mid: none
marker-start: none
mask-type: luminance
math-shift: normal
math-style: normal
math-superscript-shift-style: display
max-block-size: none
max-height: none
max-inline-size: none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ marker-end: none
marker-mid: none
marker-start: none
mask-type: luminance
math-shift: normal
math-style: normal
math-superscript-shift-style: display
max-block-size: none
max-height: none
max-inline-size: none
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ marker-end: none
marker-mid: none
marker-start: none
mask-type: luminance
math-shift: normal
math-style: normal
math-superscript-shift-style: display
max-block-size: none
max-height: none
max-inline-size: none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ markerMid
markerStart
mask
maskType
mathShift
mathStyle
mathSuperscriptShiftStyle
maxBlockSize
maxHeight
maxInlineSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ All changes to this list should go through Blink's feature review process: http:
marker-start
mask
mask-type
math-shift
math-style
math-superscript-shift-style
max-block-size
max-height
max-inline-size
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46289,6 +46289,7 @@ Called by update_use_counter_css.py.-->
<int value="673" label="descent-override"/>
<int value="674" label="advance-override"/>
<int value="675" label="line-gap-override"/>
<int value="676" label="math-shift"/>
</enum>

<enum name="MappedEditingCommands">
Expand Down

0 comments on commit c82a21d

Please sign in to comment.