Skip to content

Empty <msqrt> is misaligned vertically relative to <msqrt><mrow></mrow></msqrt>#64606

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
Ahmad-S792:eng/Investigate-0-02-failure-for-mathml-presentation-markup-radicals-empty-msqrt-html
May 11, 2026
Merged

Empty <msqrt> is misaligned vertically relative to <msqrt><mrow></mrow></msqrt>#64606
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
Ahmad-S792:eng/Investigate-0-02-failure-for-mathml-presentation-markup-radicals-empty-msqrt-html

Conversation

@Ahmad-S792
Copy link
Copy Markdown
Contributor

@Ahmad-S792 Ahmad-S792 commented May 9, 2026

1b116ea

Empty <msqrt> is misaligned vertically relative to <msqrt><mrow></mrow></msqrt>
https://bugs.webkit.org/show_bug.cgi?id=302662
rdar://165365714

Reviewed by Frédéric Wang Nélar.

Per MathML Core, an empty <msqrt> must render as if it had a single empty
<mrow> child (https://w3c.github.io/mathml-core/#radicals-msqrt-mroot). While
layout produces the same box, the baseline reported by the renderer does not:
RenderMathMLRow::firstLineBaseline() returns nullopt when there are no
in-flow children, so the inline-block fallback uses the box's bottom edge.
The reference case with an explicit empty <mrow> child instead reports a
baseline at radicalAscent, which is where the implicit mrow sits above the
radical's rule line. The two forms therefore sit at different vertical
positions on the line (offset by radicalDescent, which is non-zero whenever
the stretched radical operator is taller than verticalGap + ruleThickness).

Override firstLineBaseline() in RenderMathMLRoot to synthesize the baseline
of the implicit empty mrow when the root is a SquareRoot with no in-flow
child. With no base content, baseAscent is zero, so the synthesized ascent
collapses to verticalGap + ruleThickness + extraAscender (plus border and
padding before). Compute this on demand from verticalParameters() rather
than caching it in a member, and make verticalParameters() const so it can
be called from firstLineBaseline().

RootType::RootWithIndex with a missing child is !isValid() and already falls
through to plain row layout, where the default baseline is correct, so it
does not need special handling.

* LayoutTests/TestExpectations: Progression
* Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp:
(WebCore::RenderMathMLRoot::verticalParameters const):
(WebCore::RenderMathMLRoot::firstLineBaseline const):
* Source/WebCore/rendering/mathml/RenderMathMLRoot.h:

Canonical link: https://commits.webkit.org/313000@main

980f4e4

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ❌ 🛠 vision-apple
🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@Ahmad-S792 Ahmad-S792 self-assigned this May 9, 2026
@Ahmad-S792 Ahmad-S792 added the MathML For bugs specific to MathML. label May 9, 2026
@Ahmad-S792 Ahmad-S792 marked this pull request as draft May 9, 2026 08:37
@Ahmad-S792 Ahmad-S792 force-pushed the eng/Investigate-0-02-failure-for-mathml-presentation-markup-radicals-empty-msqrt-html branch from bd117e0 to 3d3db47 Compare May 9, 2026 09:20
@Ahmad-S792 Ahmad-S792 added Layout and Rendering For bugs with layout and rendering of Web pages. and removed MathML For bugs specific to MathML. labels May 9, 2026
@Ahmad-S792 Ahmad-S792 marked this pull request as ready for review May 9, 2026 09:20
@Ahmad-S792 Ahmad-S792 requested a review from fred-wang May 9, 2026 09:20
Comment thread Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp Outdated
MathOperator m_radicalOperator;
LayoutUnit m_radicalOperatorTop;
LayoutUnit m_baseWidth;
LayoutUnit m_ascent;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pity we have to introduce a new member just for the sake of handling the empty msqrt... The alternative would be to use an anonymous mrow, which I guess is worse memory-wise

Incidentally, it's possible we can compute these LayoutUnit members needed as needed (sharing code with layout) if that's not too computationally costly, so that we avoid the storage and invalidation issue. I believe that's what Chromium do. Anyway, probably not worth considering for this issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fred-wang - I did changes here, so it would be good, if you can have another look. Thanks!

@Ahmad-S792 Ahmad-S792 force-pushed the eng/Investigate-0-02-failure-for-mathml-presentation-markup-radicals-empty-msqrt-html branch from 3d3db47 to 980f4e4 Compare May 11, 2026 09:54
@Ahmad-S792 Ahmad-S792 added MathML For bugs specific to MathML. and removed Layout and Rendering For bugs with layout and rendering of Web pages. labels May 11, 2026
Copy link
Copy Markdown
Contributor

@fred-wang fred-wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK nice!

@Ahmad-S792 Ahmad-S792 added the merge-queue Applied to send a pull request to merge-queue label May 11, 2026
…w></msqrt>

https://bugs.webkit.org/show_bug.cgi?id=302662
rdar://165365714

Reviewed by Frédéric Wang Nélar.

Per MathML Core, an empty <msqrt> must render as if it had a single empty
<mrow> child (https://w3c.github.io/mathml-core/#radicals-msqrt-mroot). While
layout produces the same box, the baseline reported by the renderer does not:
RenderMathMLRow::firstLineBaseline() returns nullopt when there are no
in-flow children, so the inline-block fallback uses the box's bottom edge.
The reference case with an explicit empty <mrow> child instead reports a
baseline at radicalAscent, which is where the implicit mrow sits above the
radical's rule line. The two forms therefore sit at different vertical
positions on the line (offset by radicalDescent, which is non-zero whenever
the stretched radical operator is taller than verticalGap + ruleThickness).

Override firstLineBaseline() in RenderMathMLRoot to synthesize the baseline
of the implicit empty mrow when the root is a SquareRoot with no in-flow
child. With no base content, baseAscent is zero, so the synthesized ascent
collapses to verticalGap + ruleThickness + extraAscender (plus border and
padding before). Compute this on demand from verticalParameters() rather
than caching it in a member, and make verticalParameters() const so it can
be called from firstLineBaseline().

RootType::RootWithIndex with a missing child is !isValid() and already falls
through to plain row layout, where the default baseline is correct, so it
does not need special handling.

* LayoutTests/TestExpectations: Progression
* Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp:
(WebCore::RenderMathMLRoot::verticalParameters const):
(WebCore::RenderMathMLRoot::firstLineBaseline const):
* Source/WebCore/rendering/mathml/RenderMathMLRoot.h:

Canonical link: https://commits.webkit.org/313000@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Investigate-0-02-failure-for-mathml-presentation-markup-radicals-empty-msqrt-html branch from 980f4e4 to 1b116ea Compare May 11, 2026 10:50
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 313000@main (1b116ea): https://commits.webkit.org/313000@main

Reviewed commits have been landed. Closing PR #64606 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 1b116ea into WebKit:main May 11, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 11, 2026
@Ahmad-S792 Ahmad-S792 deleted the eng/Investigate-0-02-failure-for-mathml-presentation-markup-radicals-empty-msqrt-html branch May 11, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MathML For bugs specific to MathML.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants