Skip to content

Commit f322877

Browse files
fred-wangmoz-wptsync-bot
authored andcommitted
Support CSS width/height properties on MathML elements.
This patch implements support for the width/height properties on MathML elements [1]. The general algorithm from the spec is as follows: (1) The outcome of the math layout is a "math content box". (2) The content box sets its size from computed width/height values. If auto, it's the one of the "math content box". This patch ignores percentage values for now [2] [3]. (3) math content box is shifted so that its inline-start and top edges aligns with the ones of the content box. There are exceptions elements like mfrac and munder/mover/munderover which instead horizontally center the math content box within the content box. For baseline adjustment, we follow what Chromium does, see [4]. (4) Padding+border are added around the content box. Note that we ignore the box-sizing property for now [5]. The patch essentially tweaks the various MathML layout algorithms to perform steps (3) and (4) before the calls to GetBorderPaddingForPlace and InflateReflowAndBoundingMetrics. [1] https://w3c.github.io/mathml-core/#layout-algorithms [2] w3c/mathml-core#76 [3] w3c/mathml-core#77 [4] w3c/mathml-core#259 [5] w3c/mathml-core#257 Below is more information about test coverage: - width-height-001: Verify that width, height, inline-size and block-size properties sets the size of the content box. This test used to verify they are ignored, this patch fixes the `<meta name="assert">` tag. It also adds a test for the case the specified size is smaller than the content (we force non empty descendants to make sure this content is large enough) and to verify the width is used for the preferred width. - width-height-002, width-height-003: These are reftests visually checking offsets of the math content box within a larger content box (specified by width/height) for the mtext, mrow, mpadded, mfrac, msqrt, mroot, in LTR/RTL modes. In particular they allow to verify some painted elements like fraction bar and radical symbols. - width-height-004: This test more directly checks that the math content box is horizontally centered within a larger content box for munder, mover, munderover and mfrac. This patch extends the test to cover the case when the math content box is wider (i.e. overflowing outside the content box) and removes unnecessary specified height. - width-height-005: New test for other layout algorithm that don't center the math content box, checking inline-start edges of children when a width is specified. We check both LTR/RTL modes and wider/narrower content boxes. - width-height-006: Same but checking the top edges for larger/smaller height and verifying that baseline is perserved. Differential Revision: https://phabricator.services.mozilla.com/D221436 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1916988 gecko-commit: dc848382811227e2f040f438794da638b8792f5b gecko-reviewers: emilio
1 parent d3ec111 commit f322877

File tree

4 files changed

+1040
-2
lines changed

4 files changed

+1040
-2
lines changed

mathml/relations/css-styling/width-height-001.html

+31-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<title>width, height, inline-size and block-size</title>
66
<link rel="help" href="https://w3c.github.io/mathml-core/#layout-algorithms">
7-
<meta name="assert" content="Verify that width, height, inline-size and block-size properties are ignored.">
7+
<meta name="assert" content="Verify that width, height, inline-size and block-size properties set the size of the content box.">
88
<script src="/resources/testharness.js"></script>
99
<script src="/resources/testharnessreport.js"></script>
1010
<script src="/mathml/support/feature-detection.js"></script>
@@ -30,6 +30,7 @@
3030
document.body.insertAdjacentHTML("beforeend", `<div style="position: absolute;"><math><mrow>${MathMLFragments[tag]}</mrow></math></div>`);
3131
let div = document.body.lastElementChild;
3232
let element = FragmentHelper.element(div.firstElementChild);
33+
FragmentHelper.forceNonEmptyDescendants(element);
3334

3435
test(function() {
3536
assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`);
@@ -49,6 +50,35 @@
4950
assert_approx_equals(box.height, 700, epsilon, "height");
5051
}, `inline-size and block-size properties on ${tag}`);
5152

53+
// Test that if we specify a size smaller than the content, then
54+
// it is used too. Note that we skip mtable, which follows CSS
55+
// tables rules and behave differently in that case.
56+
if (tag != "mtable") {
57+
test(function() {
58+
assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`);
59+
var style = `width: 2px; height: 1px;`;
60+
element.setAttribute("style", style);
61+
let box = element.getBoundingClientRect();
62+
assert_approx_equals(box.width, 2, epsilon, "width");
63+
assert_approx_equals(box.height, 1, epsilon, "height");
64+
}, `width and height properties on ${tag} (content overflowing)`);
65+
}
66+
67+
div.style = "display: none;"; // Hide the div after measurement.
68+
69+
document.body.insertAdjacentHTML("beforeend", `<div style="position: absolute;"><div style="display: inline-block"><math><mrow>${MathMLFragments[tag]}</mrow></math></div></div>`);
70+
let shrinkWrapDiv = document.body.lastElementChild.firstElementChild;
71+
element = FragmentHelper.element(shrinkWrapDiv.firstElementChild);
72+
FragmentHelper.forceNonEmptyDescendants(element);
73+
74+
test(function() {
75+
assert_true(MathMLFeatureDetection[`has_${tag}`](), `${tag} is supported`);
76+
var style = `width: 300px;`;
77+
element.setAttribute("style", style);
78+
let box = shrinkWrapDiv.getBoundingClientRect();
79+
assert_approx_equals(box.width, 300, epsilon);
80+
}, `width property on ${tag} (preferred width)`);
81+
5282
div.style = "display: none;"; // Hide the div after measurement.
5383
}
5484

mathml/relations/css-styling/width-height-004.html

+62-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
}
2121
[data-name] {
2222
width: 7em;
23-
height: 3em;
2423
border: 1px solid blue;
2524
}
2625
</style>
@@ -64,6 +63,18 @@
6463
<mtext>X</mtext>
6564
</mfrac>
6665
</math>
66+
<math>
67+
<mfrac data-name="mfrac (horizontal overflow)">
68+
<mtext>XXXXXXXXXXXX</mtext>
69+
<mtext>XXXXXXXXXXXX</mtext>
70+
</mfrac>
71+
</math>
72+
<math dir="rtl">
73+
<mfrac data-name="RTL mfrac (horizontal overflow)">
74+
<mtext>XXXXXXXXXXXX</mtext>
75+
<mtext>XXXXXXXXXXXX</mtext>
76+
</mfrac>
77+
</math>
6778
</div>
6879

6980
<div class="test">
@@ -79,6 +90,18 @@
7990
<mtext>X</mtext>
8091
</mfrac>
8192
</math>
93+
<math>
94+
<mfrac linethickness="0" data-name="mfrac without bar (horizontal overflow)">
95+
<mtext>XXXXXXXXXXXX</mtext>
96+
<mtext>XXXXXXXXXXXX</mtext>
97+
</mfrac>
98+
</math>
99+
<math dir="rtl">
100+
<mfrac linethickness="0" data-name="RTL mfrac without bar (horizontal overflow)">
101+
<mtext>XXXXXXXXXXXX</mtext>
102+
<mtext>XXXXXXXXXXXX</mtext>
103+
</mfrac>
104+
</math>
82105
</div>
83106

84107
<div class="test">
@@ -94,6 +117,18 @@
94117
<mtext>X</mtext>
95118
</munder>
96119
</math>
120+
<math>
121+
<munder data-name="munder (horizontal overflow)">
122+
<mtext>XXXXXXXXXXXX</mtext>
123+
<mtext>XXXXXXXXXXXX</mtext>
124+
</munder>
125+
</math>
126+
<math dir="rtl">
127+
<munder data-name="RTL munder (horizontal overflow)">
128+
<mtext>XXXXXXXXXXXX</mtext>
129+
<mtext>XXXXXXXXXXXX</mtext>
130+
</munder>
131+
</math>
97132
</div>
98133

99134
<div class="test">
@@ -109,6 +144,18 @@
109144
<mtext>X</mtext>
110145
</mover>
111146
</math>
147+
<math>
148+
<mover data-name="mover (horizontal overflow)">
149+
<mtext>XXXXXXXXXXXX</mtext>
150+
<mtext>XXXXXXXXXXXX</mtext>
151+
</mover>
152+
</math>
153+
<math dir="rtl">
154+
<mover data-name="RTL mover (horizontal overflow)">
155+
<mtext>XXXXXXXXXXXX</mtext>
156+
<mtext>XXXXXXXXXXXX</mtext>
157+
</mover>
158+
</math>
112159
</div>
113160

114161
<div class="test">
@@ -126,6 +173,20 @@
126173
<mtext>X</mtext>
127174
</munderover>
128175
</math>
176+
<math>
177+
<munderover data-name="munderover (horizontal overflow)">
178+
<mtext>XXXXXXXXXXXX</mtext>
179+
<mtext>XXXXXXXXXXXX</mtext>
180+
<mtext>XXXXXXXXXXXX</mtext>
181+
</munderover>
182+
</math>
183+
<math dir="rtl">
184+
<munderover data-name="RTL munderover (horizontal overflow)">
185+
<mtext>XXXXXXXXXXXX</mtext>
186+
<mtext>XXXXXXXXXXXX</mtext>
187+
<mtext>XXXXXXXXXXXX</mtext>
188+
</munderover>
189+
</math>
129190
</div>
130191

131192
</body>

0 commit comments

Comments
 (0)