Skip to content

Commit

Permalink
MathML element in "display: flex" is not repainted on content change.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=254722

Reviewed by Antti Koivisto.

1. RenderMathMLBlock::layoutItems -> this is similar to what other FCs do on first layout (i.e. full repaint) -see RenderFlexibleBox::layoutAndPlaceChildren, RenderBlockflow::layoutBlockChild.
2. RenderMathMLMath::centerChildren/layoutRowItems -> introduce some generic repaint logic when things get moved around.

* LayoutTests/fast/repaint/mathm-gains-new-content-blank-expected.txt: Added.
* LayoutTests/fast/repaint/mathm-gains-new-content-blank.html: Added.
* Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp:
(WebCore::RenderMathMLBlock::layoutItems):

Canonical link: https://commits.webkit.org/262674@main
  • Loading branch information
alanbaradlay committed Apr 6, 2023
1 parent ac46799 commit 63e18b5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
@@ -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)
)

38 changes: 38 additions & 0 deletions LayoutTests/fast/repaint/mathm-gains-new-content-blank.html
@@ -0,0 +1,38 @@
<style>
math {
font-family: Ahem;
font-size: 20px;
}
</style>
<!-- This is a bit flaky, but repros in Safari after a few attempts -->
<math style="display: block" xmlns="http://www.w3.org/1998/Math/MathML">
<mn>PASS if</mn>
<mn id=change_this></mn>
</math>
<pre id=repaints></pre>
<script src="../../resources/ui-helper.js"></script>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
async function runTest() {

if (window.internals)
internals.startTrackingRepaints();

change_this.textContent = 'this is visible.';

await UIHelper.renderingUpdate();

if (window.internals) {
repaints.innerHTML = window.internals.repaintRectsAsText();
internals.stopTrackingRepaints();
}

if (window.testRunner)
testRunner.notifyDone();
}

window.addEventListener('load', runTest);
</script>
3 changes: 3 additions & 0 deletions Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
Expand Up @@ -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)
Expand All @@ -225,6 +226,8 @@ void RenderMathMLBlock::layoutItems(bool relayoutChildren)

child->setLocation(childLocation);
horizontalOffset += childHorizontalExtent + child->marginEnd();
if (!everHadLayout && child->checkForRepaintDuringLayout())
child->repaint();
}
}

Expand Down
15 changes: 12 additions & 3 deletions Source/WebCore/rendering/mathml/RenderMathMLMath.cpp
Expand Up @@ -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);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/rendering/mathml/RenderMathMLRow.cpp
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 63e18b5

Please sign in to comment.