diff --git a/LayoutTests/fast/repaint/mathm-gains-new-content-blank-expected.txt b/LayoutTests/fast/repaint/mathm-gains-new-content-blank-expected.txt new file mode 100644 index 000000000000..8f187d2d5c92 --- /dev/null +++ b/LayoutTests/fast/repaint/mathm-gains-new-content-blank-expected.txt @@ -0,0 +1,11 @@ +PASS if +this is visible. +(repaint rects + (rect 470 24 320 20) + (rect 470 24 320 20) + (rect 8 8 462 20) + (rect 148 8 642 36) + (rect 8 8 302 20) + (rect 148 8 482 20) +) + diff --git a/LayoutTests/fast/repaint/mathm-gains-new-content-blank.html b/LayoutTests/fast/repaint/mathm-gains-new-content-blank.html new file mode 100644 index 000000000000..e248f92089b8 --- /dev/null +++ b/LayoutTests/fast/repaint/mathm-gains-new-content-blank.html @@ -0,0 +1,38 @@ + + + + PASS if + + +

+
+
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp b/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
index 6166bc180a71..7e7e657cbf7c 100644
--- a/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
+++ b/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
@@ -199,6 +199,7 @@ void RenderMathMLBlock::layoutItems(bool relayoutChildren)
 
     LayoutUnit currentHorizontalExtent = contentLogicalWidth();
     for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
+        auto everHadLayout = child->everHadLayout();
         LayoutUnit childSize = child->maxPreferredLogicalWidth() - child->horizontalBorderAndPaddingExtent();
 
         if (preferredHorizontalExtent > currentHorizontalExtent)
@@ -225,6 +226,8 @@ void RenderMathMLBlock::layoutItems(bool relayoutChildren)
 
         child->setLocation(childLocation);
         horizontalOffset += childHorizontalExtent + child->marginEnd();
+        if (!everHadLayout && child->checkForRepaintDuringLayout())
+            child->repaint();
     }
 }
 
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp b/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp
index 7796503d6171..f8a196d18d7f 100644
--- a/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp
+++ b/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp
@@ -45,12 +45,21 @@ RenderMathMLMath::RenderMathMLMath(MathMLRowElement& element, RenderStyle&& styl
 
 void RenderMathMLMath::centerChildren(LayoutUnit contentWidth)
 {
-    LayoutUnit centerBlockOffset = (logicalWidth() - contentWidth) / 2;
+    auto centerBlockOffset = (logicalWidth() - contentWidth) / 2;
+    if (!centerBlockOffset)
+        return;
+
     if (!style().isLeftToRightDirection())
         centerBlockOffset = -centerBlockOffset;
     for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
-        if (!child->isOutOfFlowPositioned())
-            child->setLocation(child->location() + LayoutPoint(centerBlockOffset, 0_lu));
+        if (!child->isInFlow())
+            continue;
+        auto repaintRect = child->checkForRepaintDuringLayout() ? std::make_optional(child->frameRect()) : std::nullopt;
+        child->move(centerBlockOffset, { });
+        if (repaintRect) {
+            repaintRect->uniteEvenIfEmpty(child->frameRect());
+            repaintRectangle(*repaintRect);
+        }
     }
 }
 
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp b/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp
index a1650a18bbcf..29247abc8c02 100644
--- a/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp
+++ b/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp
@@ -153,7 +153,12 @@ void RenderMathMLRow::layoutRowItems(LayoutUnit width, LayoutUnit ascent)
         LayoutUnit childVerticalOffset = borderTop() + paddingTop() + child->marginTop() + ascent - childAscent;
         LayoutUnit childWidth = child->logicalWidth();
         LayoutUnit childHorizontalOffset = style().isLeftToRightDirection() ? horizontalOffset : width - horizontalOffset - childWidth;
+        auto repaintRect = child->checkForRepaintDuringLayout() ? std::make_optional(child->frameRect()) : std::nullopt;
         child->setLocation(LayoutPoint(childHorizontalOffset, childVerticalOffset));
+        if (repaintRect) {
+            repaintRect->uniteEvenIfEmpty(child->frameRect());
+            repaintRectangle(*repaintRect);
+        }
         horizontalOffset += childWidth + child->marginEnd();
     }
 }