Skip to content

Commit 384bff9

Browse files
committed
Bug 1916988 - Support CSS width/height properties on MathML elements. r=emilio
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 `` 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 UltraBlame original commit: dc848382811227e2f040f438794da638b8792f5b
1 parent a94d52b commit 384bff9

24 files changed

+9839
-732
lines changed

layout/mathml/nsMathMLContainerFrame.cpp

Lines changed: 416 additions & 3 deletions
Large diffs are not rendered by default.

layout/mathml/nsMathMLContainerFrame.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,42 @@ radical
13531353
symbol
13541354
.
13551355
IgnoreBorderPadding
1356+
/
1357+
/
1358+
If
1359+
DoNotAdjustForWidthAndHeight
1360+
is
1361+
set
1362+
the
1363+
function
1364+
will
1365+
complete
1366+
/
1367+
/
1368+
without
1369+
setting
1370+
the
1371+
computed
1372+
width
1373+
and
1374+
height
1375+
after
1376+
the
1377+
math
1378+
layout
1379+
.
1380+
This
1381+
/
1382+
/
1383+
can
1384+
be
1385+
used
1386+
similarly
1387+
to
1388+
IgnoreBorderPadding
1389+
above
1390+
.
1391+
DoNotAdjustForWidthAndHeight
13561392
}
13571393
;
13581394
using
@@ -1988,6 +2024,68 @@ PlaceFlags
19882024
aFlags
19892025
)
19902026
;
2027+
struct
2028+
WidthAndHeightForPlaceAdjustment
2029+
{
2030+
mozilla
2031+
:
2032+
:
2033+
Maybe
2034+
<
2035+
nscoord
2036+
>
2037+
width
2038+
;
2039+
mozilla
2040+
:
2041+
:
2042+
Maybe
2043+
<
2044+
nscoord
2045+
>
2046+
height
2047+
;
2048+
}
2049+
;
2050+
WidthAndHeightForPlaceAdjustment
2051+
GetWidthAndHeightForPlaceAdjustment
2052+
(
2053+
const
2054+
PlaceFlags
2055+
&
2056+
aFlags
2057+
)
2058+
;
2059+
virtual
2060+
bool
2061+
IsMathContentBoxHorizontallyCentered
2062+
(
2063+
)
2064+
const
2065+
{
2066+
return
2067+
false
2068+
;
2069+
}
2070+
nscoord
2071+
ApplyAdjustmentForWidthAndHeight
2072+
(
2073+
const
2074+
PlaceFlags
2075+
&
2076+
aFlags
2077+
const
2078+
WidthAndHeightForPlaceAdjustment
2079+
&
2080+
aSizes
2081+
ReflowOutput
2082+
&
2083+
aReflowOutput
2084+
nsBoundingMetrics
2085+
&
2086+
aBoundingMetrics
2087+
)
2088+
;
19912089
protected
19922090
:
19932091
/

layout/mathml/nsMathMLTokenFrame.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,36 @@ descent
12401240
;
12411241
/
12421242
/
1243+
Apply
1244+
width
1245+
/
1246+
height
1247+
to
1248+
math
1249+
content
1250+
box
1251+
.
1252+
auto
1253+
sizes
1254+
=
1255+
GetWidthAndHeightForPlaceAdjustment
1256+
(
1257+
aFlags
1258+
)
1259+
;
1260+
auto
1261+
shiftX
1262+
=
1263+
ApplyAdjustmentForWidthAndHeight
1264+
(
1265+
aFlags
1266+
sizes
1267+
aDesiredSize
1268+
mBoundingMetrics
1269+
)
1270+
;
1271+
/
1272+
/
12431273
Add
12441274
padding
12451275
+
@@ -1281,6 +1311,11 @@ borderPadding
12811311
.
12821312
left
12831313
;
1314+
dx
1315+
+
1316+
=
1317+
shiftX
1318+
;
12841319
for
12851320
(
12861321
nsIFrame

layout/mathml/nsMathMLmencloseFrame.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,11 @@ PlaceFlag
17291729
:
17301730
:
17311731
IgnoreBorderPadding
1732+
+
1733+
PlaceFlag
1734+
:
1735+
:
1736+
DoNotAdjustForWidthAndHeight
17321737
;
17331738
nsresult
17341739
rv
@@ -3623,6 +3628,36 @@ mBoundingMetrics
36233628
;
36243629
/
36253630
/
3631+
Apply
3632+
width
3633+
/
3634+
height
3635+
to
3636+
math
3637+
content
3638+
box
3639+
.
3640+
auto
3641+
sizes
3642+
=
3643+
GetWidthAndHeightForPlaceAdjustment
3644+
(
3645+
aFlags
3646+
)
3647+
;
3648+
dx_left
3649+
+
3650+
=
3651+
ApplyAdjustmentForWidthAndHeight
3652+
(
3653+
aFlags
3654+
sizes
3655+
aDesiredSize
3656+
mBoundingMetrics
3657+
)
3658+
;
3659+
/
3660+
/
36263661
Add
36273662
padding
36283663
+

layout/mathml/nsMathMLmfracFrame.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,89 @@ mBoundingMetrics
24582458
;
24592459
/
24602460
/
2461+
Apply
2462+
width
2463+
/
2464+
height
2465+
to
2466+
math
2467+
content
2468+
box
2469+
.
2470+
auto
2471+
sizes
2472+
=
2473+
GetWidthAndHeightForPlaceAdjustment
2474+
(
2475+
aFlags
2476+
)
2477+
;
2478+
auto
2479+
shiftX
2480+
=
2481+
ApplyAdjustmentForWidthAndHeight
2482+
(
2483+
aFlags
2484+
sizes
2485+
aDesiredSize
2486+
mBoundingMetrics
2487+
)
2488+
;
2489+
if
2490+
(
2491+
sizes
2492+
.
2493+
width
2494+
)
2495+
{
2496+
/
2497+
/
2498+
MathML
2499+
Core
2500+
says
2501+
the
2502+
math
2503+
content
2504+
box
2505+
is
2506+
horizontally
2507+
centered
2508+
/
2509+
/
2510+
but
2511+
the
2512+
fraction
2513+
bar
2514+
still
2515+
takes
2516+
the
2517+
full
2518+
width
2519+
of
2520+
the
2521+
content
2522+
box
2523+
.
2524+
dxNum
2525+
+
2526+
=
2527+
shiftX
2528+
;
2529+
dxDen
2530+
+
2531+
=
2532+
shiftX
2533+
;
2534+
width
2535+
=
2536+
*
2537+
sizes
2538+
.
2539+
width
2540+
;
2541+
}
2542+
/
2543+
/
24612544
Add
24622545
padding
24632546
+

layout/mathml/nsMathMLmfracFrame.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,17 @@ nsMathMLmfracFrame
645645
(
646646
)
647647
;
648+
bool
649+
IsMathContentBoxHorizontallyCentered
650+
(
651+
)
652+
const
653+
final
654+
{
655+
return
656+
true
657+
;
658+
}
648659
/
649660
/
650661
Display

layout/mathml/nsMathMLmmultiscriptsFrame.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,6 +4198,39 @@ boundingMetrics
41984198
;
41994199
/
42004200
/
4201+
Apply
4202+
width
4203+
/
4204+
height
4205+
to
4206+
math
4207+
content
4208+
box
4209+
.
4210+
auto
4211+
sizes
4212+
=
4213+
aFrame
4214+
-
4215+
>
4216+
GetWidthAndHeightForPlaceAdjustment
4217+
(
4218+
aFlags
4219+
)
4220+
;
4221+
aFrame
4222+
-
4223+
>
4224+
ApplyAdjustmentForWidthAndHeight
4225+
(
4226+
aFlags
4227+
sizes
4228+
aDesiredSize
4229+
boundingMetrics
4230+
)
4231+
;
4232+
/
4233+
/
42014234
Add
42024235
padding
42034236
+

0 commit comments

Comments
 (0)