Skip to content

Commit

Permalink
Support CSS width/height properties on MathML elements
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=281292

Reviewed by NOBODY (OOPS!).

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.
  • Loading branch information
fred authored and fred-wang committed Oct 21, 2024
1 parent 1dbca0a commit 55628d9
Show file tree
Hide file tree
Showing 29 changed files with 656 additions and 1,741 deletions.
1 change: 0 additions & 1 deletion LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,6 @@ imported/w3c/web-platform-tests/mathml/relations/css-styling/padding-border-marg
imported/w3c/web-platform-tests/mathml/relations/css-styling/table-width-2.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/table-width-3.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-002.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/width-height-003.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/presentation-markup/operators/mo-form-dynamic-002.html [ ImageOnlyFailure ]

# This MathML test should be rewritten.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@

FAIL width and height properties on maction assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on maction assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on maction (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on maction (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on menclose assert_approx_equals: width expected 500 +/- 1 but got 88.03125
FAIL inline-size and block-size properties on menclose assert_approx_equals: width expected 600 +/- 1 but got 88.03125
FAIL width and height properties on menclose (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 88.03125
FAIL width property on menclose (preferred width) assert_approx_equals: expected 300 +/- 1 but got 88.03125
FAIL width and height properties on merror assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on merror assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on merror (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on merror (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on mfrac assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on mfrac assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on mfrac (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on mfrac (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
PASS width and height properties on maction
PASS inline-size and block-size properties on maction
PASS width and height properties on maction (content overflowing)
PASS width property on maction (preferred width)
PASS width and height properties on menclose
PASS inline-size and block-size properties on menclose
PASS width and height properties on menclose (content overflowing)
PASS width property on menclose (preferred width)
PASS width and height properties on merror
PASS inline-size and block-size properties on merror
PASS width and height properties on merror (content overflowing)
PASS width property on merror (preferred width)
PASS width and height properties on mfrac
PASS inline-size and block-size properties on mfrac
PASS width and height properties on mfrac (content overflowing)
PASS width property on mfrac (preferred width)
PASS width and height properties on mi
PASS inline-size and block-size properties on mi
PASS width and height properties on mi (content overflowing)
PASS width property on mi (preferred width)
FAIL width and height properties on mmultiscripts assert_approx_equals: width expected 500 +/- 1 but got 132.03125
FAIL inline-size and block-size properties on mmultiscripts assert_approx_equals: width expected 600 +/- 1 but got 132.03125
FAIL width and height properties on mmultiscripts (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
FAIL width property on mmultiscripts (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
PASS width and height properties on mmultiscripts
PASS inline-size and block-size properties on mmultiscripts
PASS width and height properties on mmultiscripts (content overflowing)
PASS width property on mmultiscripts (preferred width)
PASS width and height properties on mn
PASS inline-size and block-size properties on mn
PASS width and height properties on mn (content overflowing)
Expand All @@ -31,73 +31,73 @@ PASS width and height properties on mo
PASS inline-size and block-size properties on mo
PASS width and height properties on mo (content overflowing)
FAIL width property on mo (preferred width) assert_approx_equals: expected 300 +/- 1 but got 308.875
FAIL width and height properties on mover assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on mover assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on mover (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on mover (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on mpadded assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on mpadded assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on mpadded (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on mpadded (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on mphantom assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on mphantom assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on mphantom (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on mphantom (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on mroot assert_approx_equals: width expected 500 +/- 1 but got 128.53125
FAIL inline-size and block-size properties on mroot assert_approx_equals: width expected 600 +/- 1 but got 128.53125
FAIL width and height properties on mroot (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 128.53125
FAIL width property on mroot (preferred width) assert_approx_equals: expected 300 +/- 1 but got 135.21875
FAIL width and height properties on mrow assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on mrow assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on mrow (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on mrow (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
PASS width and height properties on mover
PASS inline-size and block-size properties on mover
PASS width and height properties on mover (content overflowing)
PASS width property on mover (preferred width)
PASS width and height properties on mpadded
PASS inline-size and block-size properties on mpadded
PASS width and height properties on mpadded (content overflowing)
PASS width property on mpadded (preferred width)
PASS width and height properties on mphantom
PASS inline-size and block-size properties on mphantom
PASS width and height properties on mphantom (content overflowing)
PASS width property on mphantom (preferred width)
PASS width and height properties on mroot
PASS inline-size and block-size properties on mroot
PASS width and height properties on mroot (content overflowing)
PASS width property on mroot (preferred width)
PASS width and height properties on mrow
PASS inline-size and block-size properties on mrow
PASS width and height properties on mrow (content overflowing)
PASS width property on mrow (preferred width)
PASS width and height properties on ms
PASS inline-size and block-size properties on ms
PASS width and height properties on ms (content overflowing)
PASS width property on ms (preferred width)
FAIL width and height properties on mspace assert_approx_equals: width expected 500 +/- 1 but got 0
FAIL inline-size and block-size properties on mspace assert_approx_equals: width expected 600 +/- 1 but got 0
FAIL width and height properties on mspace (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 0
FAIL width property on mspace (preferred width) assert_approx_equals: expected 300 +/- 1 but got 0
FAIL width and height properties on msqrt assert_approx_equals: width expected 500 +/- 1 but got 89.578125
FAIL inline-size and block-size properties on msqrt assert_approx_equals: width expected 600 +/- 1 but got 89.578125
FAIL width and height properties on msqrt (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 89.578125
FAIL width property on msqrt (preferred width) assert_approx_equals: expected 300 +/- 1 but got 96.265625
FAIL width and height properties on mstyle assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on mstyle assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on mstyle (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on mstyle (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on msub assert_approx_equals: width expected 500 +/- 1 but got 132.03125
FAIL inline-size and block-size properties on msub assert_approx_equals: width expected 600 +/- 1 but got 132.03125
FAIL width and height properties on msub (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
FAIL width property on msub (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
FAIL width and height properties on msubsup assert_approx_equals: width expected 500 +/- 1 but got 132.03125
FAIL inline-size and block-size properties on msubsup assert_approx_equals: width expected 600 +/- 1 but got 132.03125
FAIL width and height properties on msubsup (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
FAIL width property on msubsup (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
FAIL width and height properties on msup assert_approx_equals: width expected 500 +/- 1 but got 132.03125
FAIL inline-size and block-size properties on msup assert_approx_equals: width expected 600 +/- 1 but got 132.03125
FAIL width and height properties on msup (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 132.03125
FAIL width property on msup (preferred width) assert_approx_equals: expected 300 +/- 1 but got 132.03125
PASS width and height properties on mspace
PASS inline-size and block-size properties on mspace
PASS width and height properties on mspace (content overflowing)
PASS width property on mspace (preferred width)
PASS width and height properties on msqrt
PASS inline-size and block-size properties on msqrt
PASS width and height properties on msqrt (content overflowing)
PASS width property on msqrt (preferred width)
PASS width and height properties on mstyle
PASS inline-size and block-size properties on mstyle
PASS width and height properties on mstyle (content overflowing)
PASS width property on mstyle (preferred width)
PASS width and height properties on msub
PASS inline-size and block-size properties on msub
PASS width and height properties on msub (content overflowing)
PASS width property on msub (preferred width)
PASS width and height properties on msubsup
PASS inline-size and block-size properties on msubsup
PASS width and height properties on msubsup (content overflowing)
PASS width property on msubsup (preferred width)
PASS width and height properties on msup
PASS inline-size and block-size properties on msup
PASS width and height properties on msup (content overflowing)
PASS width property on msup (preferred width)
PASS width and height properties on mtable
PASS inline-size and block-size properties on mtable
PASS width property on mtable (preferred width)
PASS width and height properties on mtext
PASS inline-size and block-size properties on mtext
PASS width and height properties on mtext (content overflowing)
PASS width property on mtext (preferred width)
FAIL width and height properties on munder assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on munder assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on munder (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on munder (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on munderover assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on munderover assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on munderover (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on munderover (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
FAIL width and height properties on semantics assert_approx_equals: width expected 500 +/- 1 but got 76.875
FAIL inline-size and block-size properties on semantics assert_approx_equals: width expected 600 +/- 1 but got 76.875
FAIL width and height properties on semantics (content overflowing) assert_approx_equals: width expected 2 +/- 1 but got 76.875
FAIL width property on semantics (preferred width) assert_approx_equals: expected 300 +/- 1 but got 76.875
PASS width and height properties on munder
PASS inline-size and block-size properties on munder
PASS width and height properties on munder (content overflowing)
PASS width property on munder (preferred width)
PASS width and height properties on munderover
PASS inline-size and block-size properties on munderover
PASS width and height properties on munderover (content overflowing)
PASS width property on munderover (preferred width)
PASS width and height properties on semantics
PASS inline-size and block-size properties on semantics
PASS width and height properties on semantics (content overflowing)
PASS width property on semantics (preferred width)
a
a
a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ X

XXXXXXXXXXXX
XXXXXXXXXXXX

XXXXXXXXXXXX
XXXXXXXXXXXX
X
Expand All @@ -38,7 +37,6 @@ X

XXXXXXXXXXXX
XXXXXXXXXXXX

XXXXXXXXXXXX
XXXXXXXXXXXX
X
Expand All @@ -49,7 +47,6 @@ X

XXXXXXXXXXXX
XXXXXXXXXXXX

XXXXXXXXXXXX
XXXXXXXXXXXX
X
Expand All @@ -60,7 +57,6 @@ X

XXXXXXXXXXXX
XXXXXXXXXXXX

XXXXXXXXXXXX
XXXXXXXXXXXX
X
Expand All @@ -74,7 +70,6 @@ X
XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXX

XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXX
Expand Down
Loading

0 comments on commit 55628d9

Please sign in to comment.