Skip to content

Commit 498cdeb

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
RenderMathMLRoot does not reset radical operator when children change dynamically
https://bugs.webkit.org/show_bug.cgi?id=304194 rdar://166556627 Reviewed by Frédéric Wang. When children are dynamically removed from msqrt or mroot elements, the radical operator retains its previously stretched width from the larger content, causing the element to be wider than necessary for the remaining children. The issue occurs because the renderer is not notified when the child list changes. While styleDidChange() properly resets m_radicalOperator for style changes, there was no corresponding mechanism to reset it when children are added or removed from the DOM. Fix by overriding childrenChanged() in MathMLRootElement to notify the renderer when the child list changes. The renderer resets m_radicalOperator and marks itself as needing layout and preferred width recalculation, ensuring width calculations reflect the current children rather than stale cached state. * Source/WebCore/mathml/MathMLRootElement.cpp: (WebCore::MathMLRootElement::childrenChanged): * Source/WebCore/mathml/MathMLRootElement.h: * Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp: (WebCore::RenderMathMLRoot::styleDidChange): * Source/WebCore/rendering/mathml/RenderMathMLRoot.h: > Progressions: * LayoutTests/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002-expected.txt: * LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-001-expected.txt: * LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002-expected.txt: * LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-001-expected.txt: * LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002-expected.txt: * LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-001-expected.txt: Canonical link: https://commits.webkit.org/304822@main
1 parent 14e5876 commit 498cdeb

File tree

10 files changed

+22
-12
lines changed

10 files changed

+22
-12
lines changed

LayoutTests/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002-expected.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PASS Appending and removing children to mroot
1414
PASS Appending and removing children to mrow
1515
PASS Appending and removing children to ms
1616
PASS Appending and removing children to mspace
17-
FAIL Appending and removing children to msqrt assert_approx_equals: inline size expected 12.703125 +/- 1 but got 16.640625
17+
PASS Appending and removing children to msqrt
1818
PASS Appending and removing children to mstyle
1919
PASS Appending and removing children to msub
2020
PASS Appending and removing children to msubsup
@@ -23,8 +23,7 @@ PASS Appending and removing children to mtable
2323
PASS Appending and removing children to mtext
2424
PASS Appending and removing children to munder
2525
PASS Appending and removing children to munderover
26-
FAIL Appending and removing children to semantics assert_approx_equals: block position (child 0) expected -362.890625 +/- 1 but got -380.890625
26+
FAIL Appending and removing children to semantics assert_approx_equals: block position (child 0) expected -112 +/- 1 but got -130
2727
maction:
28-
msqrt:
2928
semantics:
3029

LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-001-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PASS Adding missing children to mroot
3131
PASS Removing child from valid mroot
3232
PASS Adding child to valid mroot
3333
PASS Removing extra child from mroot
34-
FAIL Removing children from msqrt assert_approx_equals: inline size expected 13 +/- 1 but got 16
34+
PASS Removing children from msqrt
3535
PASS Adding children to msqrt
3636
PASS Removing children from mpadded
3737
PASS Adding children to mpadded

LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002-expected.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PASS Appending and removing children to mroot
1414
PASS Appending and removing children to mrow
1515
PASS Appending and removing children to ms
1616
PASS Appending and removing children to mspace
17-
FAIL Appending and removing children to msqrt assert_approx_equals: inline size expected 13 +/- 1 but got 16
17+
PASS Appending and removing children to msqrt
1818
PASS Appending and removing children to mstyle
1919
PASS Appending and removing children to msub
2020
PASS Appending and removing children to msubsup
@@ -24,5 +24,4 @@ PASS Appending and removing children to mtext
2424
PASS Appending and removing children to munder
2525
PASS Appending and removing children to munderover
2626
PASS Appending and removing children to semantics
27-
msqrt:
2827

LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-001-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PASS Adding missing children to mroot
3131
PASS Removing child from valid mroot
3232
PASS Adding child to valid mroot
3333
PASS Removing extra child from mroot
34-
FAIL Removing children from msqrt assert_approx_equals: inline size expected 12.703125 +/- 1 but got 18.828125
34+
PASS Removing children from msqrt
3535
PASS Adding children to msqrt
3636
PASS Removing children from mpadded
3737
PASS Adding children to mpadded

LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002-expected.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PASS Appending and removing children to mroot
1414
PASS Appending and removing children to mrow
1515
PASS Appending and removing children to ms
1616
PASS Appending and removing children to mspace
17-
FAIL Appending and removing children to msqrt assert_approx_equals: inline size expected 12.703125 +/- 1 but got 16.640625
17+
PASS Appending and removing children to msqrt
1818
PASS Appending and removing children to mstyle
1919
PASS Appending and removing children to msub
2020
PASS Appending and removing children to msubsup
@@ -23,8 +23,7 @@ PASS Appending and removing children to mtable
2323
PASS Appending and removing children to mtext
2424
PASS Appending and removing children to munder
2525
PASS Appending and removing children to munderover
26-
FAIL Appending and removing children to semantics assert_approx_equals: block position (child 0) expected -377.890625 +/- 1 but got -397.890625
26+
FAIL Appending and removing children to semantics assert_approx_equals: block position (child 0) expected -123 +/- 1 but got -143
2727
maction:
28-
msqrt:
2928
semantics:
3029

LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-001-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PASS Adding missing children to mroot
3131
PASS Removing child from valid mroot
3232
PASS Adding child to valid mroot
3333
PASS Removing extra child from mroot
34-
FAIL Removing children from msqrt assert_approx_equals: inline size expected 12.703125 +/- 1 but got 18.828125
34+
PASS Removing children from msqrt
3535
PASS Adding children to msqrt
3636
PASS Removing children from mpadded
3737
PASS Adding children to mpadded

Source/WebCore/mathml/MathMLRootElement.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ RenderPtr<RenderElement> MathMLRootElement::createElementRenderer(RenderStyle&&
6363
return createRenderer<RenderMathMLRoot>(*this, WTF::move(style));
6464
}
6565

66+
void MathMLRootElement::childrenChanged(const ChildChange& change)
67+
{
68+
MathMLRowElement::childrenChanged(change);
69+
70+
if (CheckedPtr rootRenderer = dynamicDowncast<RenderMathMLRoot>(this->renderer())) {
71+
rootRenderer->resetRadicalOperator();
72+
rootRenderer->setNeedsLayoutAndPreferredWidthsUpdate();
73+
}
74+
}
75+
6676
}
6777

6878
#endif // ENABLE(MATHML)

Source/WebCore/mathml/MathMLRootElement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class MathMLRootElement final : public MathMLRowElement {
4444
MathMLRootElement(const QualifiedName& tagName, Document&);
4545
RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
4646

47+
void childrenChanged(const ChildChange&) override;
48+
4749
const RootType m_rootType;
4850
};
4951

Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ RenderBox& RenderMathMLRoot::getIndex() const
100100
void RenderMathMLRoot::styleDidChange(Style::Difference diff, const RenderStyle* oldStyle)
101101
{
102102
RenderMathMLRow::styleDidChange(diff, oldStyle);
103-
m_radicalOperator.reset(style());
103+
resetRadicalOperator();
104104
}
105105

106106
RenderMathMLRoot::HorizontalParameters RenderMathMLRoot::horizontalParameters(LayoutUnit indexWidth)

Source/WebCore/rendering/mathml/RenderMathMLRoot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class RenderMathMLRoot final : public RenderMathMLRow {
4646
virtual ~RenderMathMLRoot();
4747

4848
void updateStyle();
49+
void resetRadicalOperator() { m_radicalOperator.reset(checkedStyle()); }
4950

5051
private:
5152
bool isValid() const;

0 commit comments

Comments
 (0)