Skip to content

Commit

Permalink
Support border/padding/margin on RenderMathMLOperator
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=276357

Reviewed by Rob Buis.

This patch adds support for border/padding/margin on `<mo>` elements
for which useMathOperator() returns true and therefore uses use
special layout and painting instead of deferring to RenderMathMLToken.

* LayoutTests/TestExpectations: Mark borders/paddings/margins reftests
  for largeop/stretchy operators as passing.
* Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp:
(WebCore::RenderMathMLOperator::stretchTo): Include borders/paddings in
  logical width/height.
(WebCore::RenderMathMLOperator::computePreferredLogicalWidths): Include
  borders/paddings in preferred width. Children are text nodes, no need
  to consider margins.
(WebCore::RenderMathMLOperator::layoutBlock): Include borders/paddings
  for in logical width/height. Also call recomputeLogicalWidth() to set
  the inline margins on the element (block margins are handled by the
  parent). Children are text nodes, no need to consider margins for them.
(WebCore::RenderMathMLOperator::firstLineBaseline const):
  Include border/padding in the ascent.
(WebCore::RenderMathMLOperator::paint): Shift painting by the left/top
  border/padding.

Canonical link: https://commits.webkit.org/280833@main
  • Loading branch information
fred-wang committed Jul 10, 2024
1 parent 5c0b0d8 commit 9a01858
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 0 additions & 2 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1828,8 +1828,6 @@ imported/w3c/web-platform-tests/mathml/relations/css-styling/floats/floating-ins
imported/w3c/web-platform-tests/mathml/relations/css-styling/mathvariant-basic-transforms-with-default-font.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/mathvariant-double-struck-font-style-font-weight.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/mi-fontstyle-fontweight.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/padding-border-margin/padding-border-margin-002.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/mathml/relations/css-styling/padding-border-margin/padding-border-margin-003.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 ]

Expand Down
19 changes: 11 additions & 8 deletions Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void RenderMathMLOperator::stretchTo(LayoutUnit heightAboveBaseline, LayoutUnit

m_mathOperator.stretchTo(style(), m_stretchHeightAboveBaseline + m_stretchDepthBelowBaseline);

setLogicalHeight(m_mathOperator.ascent() + m_mathOperator.descent());
setLogicalHeight(m_mathOperator.ascent() + m_mathOperator.descent() + borderAndPaddingLogicalHeight());
}

void RenderMathMLOperator::stretchTo(LayoutUnit width)
Expand All @@ -174,8 +174,8 @@ void RenderMathMLOperator::stretchTo(LayoutUnit width)
m_stretchWidth = width;
m_mathOperator.stretchTo(style(), width);

setLogicalWidth(leadingSpace() + width + trailingSpace());
setLogicalHeight(m_mathOperator.ascent() + m_mathOperator.descent());
setLogicalWidth(leadingSpace() + width + trailingSpace() + borderAndPaddingLogicalWidth());
setLogicalHeight(m_mathOperator.ascent() + m_mathOperator.descent() + borderAndPaddingLogicalHeight());
}

void RenderMathMLOperator::resetStretchSize()
Expand All @@ -196,6 +196,7 @@ void RenderMathMLOperator::computePreferredLogicalWidths()
LayoutUnit preferredWidth;

if (!useMathOperator()) {
// No need to include padding/border/margin here, RenderMathMLToken::computePreferredLogicalWidths takes care of them.
RenderMathMLToken::computePreferredLogicalWidths();
preferredWidth = m_maxPreferredLogicalWidth;
if (isInvisibleOperator()) {
Expand All @@ -205,7 +206,7 @@ void RenderMathMLOperator::computePreferredLogicalWidths()
preferredWidth -= std::min(LayoutUnit(glyphWidth), preferredWidth);
}
} else
preferredWidth = m_mathOperator.maxPreferredWidth();
preferredWidth = m_mathOperator.maxPreferredWidth() + borderAndPaddingLogicalWidth();

// FIXME: The spacing should be added to the whole embellished operator (https://webkit.org/b/124831).
// FIXME: The spacing should only be added inside (perhaps inferred) mrow (http://www.w3.org/TR/MathML/chapter3.html#presm.opspacing).
Expand All @@ -227,14 +228,16 @@ void RenderMathMLOperator::layoutBlock(bool relayoutChildren, LayoutUnit pageLog
LayoutUnit trailingSpaceValue = trailingSpace();

if (useMathOperator()) {
recomputeLogicalWidth();
for (auto child = firstChildBox(); child; child = child->nextSiblingBox())
child->layoutIfNeeded();
setLogicalWidth(leadingSpaceValue + m_mathOperator.width() + trailingSpaceValue);
setLogicalHeight(m_mathOperator.ascent() + m_mathOperator.descent());
setLogicalWidth(leadingSpaceValue + m_mathOperator.width() + trailingSpaceValue + borderAndPaddingLogicalWidth());
setLogicalHeight(m_mathOperator.ascent() + m_mathOperator.descent() + borderAndPaddingLogicalHeight());

layoutPositionedObjects(relayoutChildren);
} else {
// We first do the normal layout without spacing.
// No need to handle padding/border/margin here, RenderMathMLToken::layoutBlock takes care of them.
recomputeLogicalWidth();
LayoutUnit width = logicalWidth();
setLogicalWidth(width - leadingSpaceValue - trailingSpaceValue);
Expand Down Expand Up @@ -308,7 +311,7 @@ LayoutUnit RenderMathMLOperator::verticalStretchedOperatorShift() const
std::optional<LayoutUnit> RenderMathMLOperator::firstLineBaseline() const
{
if (useMathOperator())
return LayoutUnit { static_cast<int>(lround(static_cast<float>(m_mathOperator.ascent() - verticalStretchedOperatorShift()))) };
return LayoutUnit { static_cast<int>(lround(static_cast<float>(m_mathOperator.ascent() - verticalStretchedOperatorShift()))) } + borderAndPaddingBefore();
return RenderMathMLToken::firstLineBaseline();
}

Expand All @@ -319,7 +322,7 @@ void RenderMathMLOperator::paint(PaintInfo& info, const LayoutPoint& paintOffset
return;

LayoutPoint operatorTopLeft = paintOffset + location();
operatorTopLeft.move(style().isLeftToRightDirection() ? leadingSpace() : trailingSpace(), 0_lu);
operatorTopLeft.move((style().isLeftToRightDirection() ? leadingSpace() : trailingSpace()) + borderLeft() + paddingLeft(), borderAndPaddingBefore());

m_mathOperator.paint(style(), info, operatorTopLeft);
}
Expand Down

0 comments on commit 9a01858

Please sign in to comment.