Skip to content

Commit 83c5b73

Browse files
committed
Support CSS width/height properties on MathML elements
https://bugs.webkit.org/show_bug.cgi?id=281292 Reviewed by Rob Buis. 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 other browsers do, 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 adjustPreferredLogicalWidthsForBorderAndPadding() and adjustLayoutForBorderAndPadding(). In particular this might slightly change current behavior for mrow-like layout. More tweaks might be needed would be handled in follow-up patches. [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 [6] web-platform-tests/wpt#48569 * LayoutTests/TestExpectations: width-height-003.html PASS. msqrt case for width-height-003.html still has small diff. * LayoutTests/imported/w3c/web-platform-tests/mathml/presentation-markup/spaces/mspace-width-height-001-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-001-expected.txt: We pass everything except preferred mo size because of how we handle lspace/rspace, see [6]. * LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-004-expected.txt: Remove new lines in txt expectation. * LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-005-expected.txt: Use a platform-independent "everything PASS" expectation. * LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-006-expected.txt: Use a platform-independent "everything PASS" expectation. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-001-expected.txt: Removed. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-005-expected.txt: Removed. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-006-expected.txt: Removed. * LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-005-expected.txt: Removed. * LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-006-expected.txt: Removed. * LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-005-expected.txt: Removed. * LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-006-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/mathml/presentation-markup/spaces/mspace-width-height-001-expected.txt: Added. Use a platform-independent "everything PASS" expectation. * LayoutTests/mathml/presentation/mspace-prefered-width-expected.html: This was initially added in 136708@main, tweak expectation now that we support width on mspace. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/css-styling/display-2-expected.txt: Update now that we support width/height on MathML elements. * LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/display-2-expected.txt: Ditto. * LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/display-2-expected.txt: Ditto. * Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp: (WebCore::RenderMathMLBlock::sizeAppliedToMathContent): New helper to retrieve the specified CSS width/height, if any. (WebCore::RenderMathMLBlock::applySizeToMathContent): New helper to apply the specified CSS width/height to the math content box and return inline shift for further adjustments. * Source/WebCore/rendering/mathml/RenderMathMLBlock.h: (WebCore::RenderMathMLBlock::isMathContentCentered const): New helper to indicate whether math content should be centered on the inline axis if a different size is specified by the user. * Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp: (WebCore::RenderMathMLFraction::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLFraction::layoutBlock): Apply specified sizes, adjust children position. (WebCore::RenderMathMLFraction::paint): Comment about fraction bar painting. * Source/WebCore/rendering/mathml/RenderMathMLFraction.h: MathML Core says fraction content is centered. * Source/WebCore/rendering/mathml/RenderMathMLMenclose.cpp: (WebCore::RenderMathMLMenclose::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLMenclose::layoutBlock): Apply specified sizes, adjust children position. * Source/WebCore/rendering/mathml/RenderMathMLPadded.cpp: (WebCore::RenderMathMLPadded::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLPadded::layoutBlock): Apply specified sizes, adjust children position. * Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp: (WebCore::RenderMathMLRoot::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLRoot::layoutBlock): Apply specified sizes, adjust children position. * Source/WebCore/rendering/mathml/RenderMathMLRow.cpp: (WebCore::RenderMathMLRow::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLRow::layoutBlock): Apply specified sizes, adjust children position. This also removes previous setLogicalHeight() and updateLogicalHeight() calls. * Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp: (WebCore::RenderMathMLScripts::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLScripts::layoutBlock): Apply specified sizes, adjust children position. * Source/WebCore/rendering/mathml/RenderMathMLSpace.cpp: (WebCore::RenderMathMLSpace::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLSpace::layoutBlock): Apply specified sizes. Minor refactoring to make sure border/padding are handled after. * Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp: (WebCore::RenderMathMLUnderOver::computePreferredLogicalWidths): Account for specified sizes. (WebCore::RenderMathMLUnderOver::layoutBlock): Apply specified sizes, adjust children position. * Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h: MathML Core says munder/mover/munderover content is centered. Canonical link: https://commits.webkit.org/285892@main
1 parent 10381a8 commit 83c5b73

29 files changed

+656
-1741
lines changed

LayoutTests/TestExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,6 @@ imported/w3c/web-platform-tests/mathml/relations/css-styling/padding-border-marg
19551955
imported/w3c/web-platform-tests/mathml/relations/css-styling/table-width-2.html [ ImageOnlyFailure ]
19561956
imported/w3c/web-platform-tests/mathml/relations/css-styling/table-width-3.html [ ImageOnlyFailure ]
19571957
imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-002.html [ ImageOnlyFailure ]
1958-
imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-003.html [ ImageOnlyFailure ]
19591958
imported/w3c/web-platform-tests/mathml/presentation-markup/operators/mo-form-dynamic-002.html [ ImageOnlyFailure ]
19601959

19611960
# This MathML test should be rewritten.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
FAIL width attribute + width property assert_approx_equals: mspace width overridden by inline style expected 200 +/- 1 but got 500
3-
FAIL height/depth attributes + height property assert_approx_equals: mspace height overridden by inline style expected 200 +/- 1 but got 300
4-
FAIL height attribute + height property assert_approx_equals: mspace height overridden by inline style expected 200 +/- 1 but got 300
5-
FAIL depth attribute + height property assert_approx_equals: mspace height overridden by inline style expected 200 +/- 1 but got 300
2+
PASS width attribute + width property
3+
PASS height/depth attributes + height property
4+
PASS height attribute + height property
5+
PASS depth attribute + height property
66

LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-001-expected.txt

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11

2-
FAIL width and height properties on maction assert_approx_equals: width expected 500 +/- 1 but got 76.875
3-
FAIL inline-size and block-size properties on maction assert_approx_equals: width expected 600 +/- 1 but got 76.875
4-
FAIL width and height properties on maction (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
5-
FAIL width property on maction (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
6-
FAIL width and height properties on menclose assert_approx_equals: width expected 500 +/- 1 but got 88.03125
7-
FAIL inline-size and block-size properties on menclose assert_approx_equals: width expected 600 +/- 1 but got 88.03125
8-
FAIL width and height properties on menclose (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 88.03125
9-
FAIL width property on menclose (preferred width) assert_approx_equals: expected 300 +/- 1 but got 88.03125
10-
FAIL width and height properties on merror assert_approx_equals: width expected 500 +/- 1 but got 76.875
11-
FAIL inline-size and block-size properties on merror assert_approx_equals: width expected 600 +/- 1 but got 76.875
12-
FAIL width and height properties on merror (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
13-
FAIL width property on merror (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
14-
FAIL width and height properties on mfrac assert_approx_equals: width expected 500 +/- 1 but got 76.875
15-
FAIL inline-size and block-size properties on mfrac assert_approx_equals: width expected 600 +/- 1 but got 76.875
16-
FAIL width and height properties on mfrac (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
17-
FAIL width property on mfrac (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
2+
PASS width and height properties on maction
3+
PASS inline-size and block-size properties on maction
4+
PASS width and height properties on maction (content overflowing)
5+
PASS width property on maction (preferred width)
6+
PASS width and height properties on menclose
7+
PASS inline-size and block-size properties on menclose
8+
PASS width and height properties on menclose (content overflowing)
9+
PASS width property on menclose (preferred width)
10+
PASS width and height properties on merror
11+
PASS inline-size and block-size properties on merror
12+
PASS width and height properties on merror (content overflowing)
13+
PASS width property on merror (preferred width)
14+
PASS width and height properties on mfrac
15+
PASS inline-size and block-size properties on mfrac
16+
PASS width and height properties on mfrac (content overflowing)
17+
PASS width property on mfrac (preferred width)
1818
PASS width and height properties on mi
1919
PASS inline-size and block-size properties on mi
2020
PASS width and height properties on mi (content overflowing)
2121
PASS width property on mi (preferred width)
22-
FAIL width and height properties on mmultiscripts assert_approx_equals: width expected 500 +/- 1 but got 132.03125
23-
FAIL inline-size and block-size properties on mmultiscripts assert_approx_equals: width expected 600 +/- 1 but got 132.03125
24-
FAIL width and height properties on mmultiscripts (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
25-
FAIL width property on mmultiscripts (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
22+
PASS width and height properties on mmultiscripts
23+
PASS inline-size and block-size properties on mmultiscripts
24+
PASS width and height properties on mmultiscripts (content overflowing)
25+
PASS width property on mmultiscripts (preferred width)
2626
PASS width and height properties on mn
2727
PASS inline-size and block-size properties on mn
2828
PASS width and height properties on mn (content overflowing)
@@ -31,73 +31,73 @@ PASS width and height properties on mo
3131
PASS inline-size and block-size properties on mo
3232
PASS width and height properties on mo (content overflowing)
3333
FAIL width property on mo (preferred width) assert_approx_equals: expected 300 +/- 1 but got 308.875
34-
FAIL width and height properties on mover assert_approx_equals: width expected 500 +/- 1 but got 76.875
35-
FAIL inline-size and block-size properties on mover assert_approx_equals: width expected 600 +/- 1 but got 76.875
36-
FAIL width and height properties on mover (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
37-
FAIL width property on mover (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
38-
FAIL width and height properties on mpadded assert_approx_equals: width expected 500 +/- 1 but got 76.875
39-
FAIL inline-size and block-size properties on mpadded assert_approx_equals: width expected 600 +/- 1 but got 76.875
40-
FAIL width and height properties on mpadded (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
41-
FAIL width property on mpadded (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
42-
FAIL width and height properties on mphantom assert_approx_equals: width expected 500 +/- 1 but got 76.875
43-
FAIL inline-size and block-size properties on mphantom assert_approx_equals: width expected 600 +/- 1 but got 76.875
44-
FAIL width and height properties on mphantom (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
45-
FAIL width property on mphantom (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
46-
FAIL width and height properties on mroot assert_approx_equals: width expected 500 +/- 1 but got 128.53125
47-
FAIL inline-size and block-size properties on mroot assert_approx_equals: width expected 600 +/- 1 but got 128.53125
48-
FAIL width and height properties on mroot (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 128.53125
49-
FAIL width property on mroot (preferred width) assert_approx_equals: expected 300 +/- 1 but got 135.21875
50-
FAIL width and height properties on mrow assert_approx_equals: width expected 500 +/- 1 but got 76.875
51-
FAIL inline-size and block-size properties on mrow assert_approx_equals: width expected 600 +/- 1 but got 76.875
52-
FAIL width and height properties on mrow (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
53-
FAIL width property on mrow (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
34+
PASS width and height properties on mover
35+
PASS inline-size and block-size properties on mover
36+
PASS width and height properties on mover (content overflowing)
37+
PASS width property on mover (preferred width)
38+
PASS width and height properties on mpadded
39+
PASS inline-size and block-size properties on mpadded
40+
PASS width and height properties on mpadded (content overflowing)
41+
PASS width property on mpadded (preferred width)
42+
PASS width and height properties on mphantom
43+
PASS inline-size and block-size properties on mphantom
44+
PASS width and height properties on mphantom (content overflowing)
45+
PASS width property on mphantom (preferred width)
46+
PASS width and height properties on mroot
47+
PASS inline-size and block-size properties on mroot
48+
PASS width and height properties on mroot (content overflowing)
49+
PASS width property on mroot (preferred width)
50+
PASS width and height properties on mrow
51+
PASS inline-size and block-size properties on mrow
52+
PASS width and height properties on mrow (content overflowing)
53+
PASS width property on mrow (preferred width)
5454
PASS width and height properties on ms
5555
PASS inline-size and block-size properties on ms
5656
PASS width and height properties on ms (content overflowing)
5757
PASS width property on ms (preferred width)
58-
FAIL width and height properties on mspace assert_approx_equals: width expected 500 +/- 1 but got 0
59-
FAIL inline-size and block-size properties on mspace assert_approx_equals: width expected 600 +/- 1 but got 0
60-
FAIL width and height properties on mspace (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 0
61-
FAIL width property on mspace (preferred width) assert_approx_equals: expected 300 +/- 1 but got 0
62-
FAIL width and height properties on msqrt assert_approx_equals: width expected 500 +/- 1 but got 89.578125
63-
FAIL inline-size and block-size properties on msqrt assert_approx_equals: width expected 600 +/- 1 but got 89.578125
64-
FAIL width and height properties on msqrt (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 89.578125
65-
FAIL width property on msqrt (preferred width) assert_approx_equals: expected 300 +/- 1 but got 96.265625
66-
FAIL width and height properties on mstyle assert_approx_equals: width expected 500 +/- 1 but got 76.875
67-
FAIL inline-size and block-size properties on mstyle assert_approx_equals: width expected 600 +/- 1 but got 76.875
68-
FAIL width and height properties on mstyle (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
69-
FAIL width property on mstyle (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
70-
FAIL width and height properties on msub assert_approx_equals: width expected 500 +/- 1 but got 132.03125
71-
FAIL inline-size and block-size properties on msub assert_approx_equals: width expected 600 +/- 1 but got 132.03125
72-
FAIL width and height properties on msub (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
73-
FAIL width property on msub (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
74-
FAIL width and height properties on msubsup assert_approx_equals: width expected 500 +/- 1 but got 132.03125
75-
FAIL inline-size and block-size properties on msubsup assert_approx_equals: width expected 600 +/- 1 but got 132.03125
76-
FAIL width and height properties on msubsup (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
77-
FAIL width property on msubsup (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
78-
FAIL width and height properties on msup assert_approx_equals: width expected 500 +/- 1 but got 132.03125
79-
FAIL inline-size and block-size properties on msup assert_approx_equals: width expected 600 +/- 1 but got 132.03125
80-
FAIL width and height properties on msup (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
81-
FAIL width property on msup (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
58+
PASS width and height properties on mspace
59+
PASS inline-size and block-size properties on mspace
60+
PASS width and height properties on mspace (content overflowing)
61+
PASS width property on mspace (preferred width)
62+
PASS width and height properties on msqrt
63+
PASS inline-size and block-size properties on msqrt
64+
PASS width and height properties on msqrt (content overflowing)
65+
PASS width property on msqrt (preferred width)
66+
PASS width and height properties on mstyle
67+
PASS inline-size and block-size properties on mstyle
68+
PASS width and height properties on mstyle (content overflowing)
69+
PASS width property on mstyle (preferred width)
70+
PASS width and height properties on msub
71+
PASS inline-size and block-size properties on msub
72+
PASS width and height properties on msub (content overflowing)
73+
PASS width property on msub (preferred width)
74+
PASS width and height properties on msubsup
75+
PASS inline-size and block-size properties on msubsup
76+
PASS width and height properties on msubsup (content overflowing)
77+
PASS width property on msubsup (preferred width)
78+
PASS width and height properties on msup
79+
PASS inline-size and block-size properties on msup
80+
PASS width and height properties on msup (content overflowing)
81+
PASS width property on msup (preferred width)
8282
PASS width and height properties on mtable
8383
PASS inline-size and block-size properties on mtable
8484
PASS width property on mtable (preferred width)
8585
PASS width and height properties on mtext
8686
PASS inline-size and block-size properties on mtext
8787
PASS width and height properties on mtext (content overflowing)
8888
PASS width property on mtext (preferred width)
89-
FAIL width and height properties on munder assert_approx_equals: width expected 500 +/- 1 but got 76.875
90-
FAIL inline-size and block-size properties on munder assert_approx_equals: width expected 600 +/- 1 but got 76.875
91-
FAIL width and height properties on munder (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
92-
FAIL width property on munder (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
93-
FAIL width and height properties on munderover assert_approx_equals: width expected 500 +/- 1 but got 76.875
94-
FAIL inline-size and block-size properties on munderover assert_approx_equals: width expected 600 +/- 1 but got 76.875
95-
FAIL width and height properties on munderover (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
96-
FAIL width property on munderover (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
97-
FAIL width and height properties on semantics assert_approx_equals: width expected 500 +/- 1 but got 76.875
98-
FAIL inline-size and block-size properties on semantics assert_approx_equals: width expected 600 +/- 1 but got 76.875
99-
FAIL width and height properties on semantics (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
100-
FAIL width property on semantics (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
89+
PASS width and height properties on munder
90+
PASS inline-size and block-size properties on munder
91+
PASS width and height properties on munder (content overflowing)
92+
PASS width property on munder (preferred width)
93+
PASS width and height properties on munderover
94+
PASS inline-size and block-size properties on munderover
95+
PASS width and height properties on munderover (content overflowing)
96+
PASS width property on munderover (preferred width)
97+
PASS width and height properties on semantics
98+
PASS inline-size and block-size properties on semantics
99+
PASS width and height properties on semantics (content overflowing)
100+
PASS width property on semantics (preferred width)
101101
a
102102
a
103103
a

LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-004-expected.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ X
2727

2828
XXXXXXXXXXXX
2929
XXXXXXXXXXXX
30-
3130
XXXXXXXXXXXX
3231
XXXXXXXXXXXX
3332
X
@@ -38,7 +37,6 @@ X
3837

3938
XXXXXXXXXXXX
4039
XXXXXXXXXXXX
41-
4240
XXXXXXXXXXXX
4341
XXXXXXXXXXXX
4442
X
@@ -49,7 +47,6 @@ X
4947

5048
XXXXXXXXXXXX
5149
XXXXXXXXXXXX
52-
5350
XXXXXXXXXXXX
5451
XXXXXXXXXXXX
5552
X
@@ -60,7 +57,6 @@ X
6057

6158
XXXXXXXXXXXX
6259
XXXXXXXXXXXX
63-
6460
XXXXXXXXXXXX
6561
XXXXXXXXXXXX
6662
X
@@ -74,7 +70,6 @@ X
7470
XXXXXXXXXXXX
7571
XXXXXXXXXXXX
7672
XXXXXXXXXXXX
77-
7873
XXXXXXXXXXXX
7974
XXXXXXXXXXXX
8075
XXXXXXXXXXXX

0 commit comments

Comments
 (0)