Skip to content

Commit 91904fc

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
<mpadded> should treat percentage values as absent for width/height/depth attribute
https://bugs.webkit.org/show_bug.cgi?id=304790 rdar://167350169 Reviewed by Alan Baradlay. According to the MathML Core specification [1], if the width, height, or depth attributes are percentages, they should be treated as if absent (using default values based on the inner box dimensions). Previously, these percentage values were incorrectly resolved relative to the content dimensions. This patch checks for LengthType::Percentage in mpaddedWidth(), mpaddedHeight(), and mpaddedDepth(), and returns the content dimension directly when a percentage is encountered, matching the behavior for absent/invalid attributes. [1] https://w3c.github.io/mathml-core/#inner-box-and-requested-parameters As drive-by, we updated to use std::max(0_lu, ..) rather than explicity std::max<LayoutUnit> similar to through out other code. * Source/WebCore/rendering/mathml/RenderMathMLPadded.cpp: (WebCore::RenderMathMLPadded::lspace const): Drive-by fix (WebCore::RenderMathMLPadded::mpaddedWidth const): (WebCore::RenderMathMLPadded::mpaddedHeight const): (WebCore::RenderMathMLPadded::mpaddedDepth const): > Progressions: * LayoutTests/imported/w3c/web-platform-tests/mathml/presentation-markup/mpadded/mpadded-002-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/mathml/presentation-markup/mpadded/mpadded-percentage-002-expected.txt: Canonical link: https://commits.webkit.org/305027@main
1 parent 6970795 commit 91904fc

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

LayoutTests/imported/w3c/web-platform-tests/mathml/presentation-markup/mpadded/mpadded-002-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
PASS mpadded with no attributes
33
PASS Different widths
44
PASS Different heights
5-
FAIL Percentage calculation for width, height and depth assert_equals: width expected 100 but got 50
5+
PASS Percentage calculation for width, height and depth
66
PASS Different depths
77
PASS Various combinations of height, depth and width.
88
PASS Preferred width

LayoutTests/imported/w3c/web-platform-tests/mathml/presentation-markup/mpadded/mpadded-percentage-002-expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
FAIL width='200%' is interpreted as the default value assert_approx_equals: inline size expected 10 +/- 1 but got 20
3-
FAIL height='200%' is interpreted as the default value assert_approx_equals: block size expected 50 +/- 1 but got 70
4-
FAIL depth='200%' is interpreted as the default value assert_approx_equals: block size expected 50 +/- 1 but got 80
2+
PASS width='200%' is interpreted as the default value
3+
PASS height='200%' is interpreted as the default value
4+
PASS depth='200%' is interpreted as the default value
55
PASS lspace='200%' is interpreted as the default value
66
PASS voffset='200%' is interpreted as the default value
77

Source/WebCore/rendering/mathml/RenderMathMLPadded.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,35 @@ LayoutUnit RenderMathMLPadded::voffset() const
5757

5858
LayoutUnit RenderMathMLPadded::lspace() const
5959
{
60-
LayoutUnit lspace = toUserUnits(element().lspace(), style(), 0);
6160
// FIXME: Negative lspace values are not supported yet (https://bugs.webkit.org/show_bug.cgi?id=85730).
62-
return std::max<LayoutUnit>(0, lspace);
61+
return std::max(0_lu, toUserUnits(element().lspace(), style(), 0));
6362
}
6463

6564
LayoutUnit RenderMathMLPadded::mpaddedWidth(LayoutUnit contentWidth) const
6665
{
67-
return std::max<LayoutUnit>(0, toUserUnits(element().width(), style(), contentWidth));
66+
auto& widthAttr = element().width();
67+
// If parsing failed (attribute not set) or it's a percentage, use the content width as default.
68+
if (widthAttr.type == MathMLElement::LengthType::ParsingFailed || widthAttr.type == MathMLElement::LengthType::Percentage)
69+
return contentWidth;
70+
return std::max(0_lu, toUserUnits(widthAttr, style(), 0));
6871
}
6972

7073
LayoutUnit RenderMathMLPadded::mpaddedHeight(LayoutUnit contentHeight) const
7174
{
72-
return std::max<LayoutUnit>(0, toUserUnits(element().height(), style(), contentHeight));
75+
auto& heightAttr = element().height();
76+
// If parsing failed (attribute not set) or it's a percentage, use the content height as default.
77+
if (heightAttr.type == MathMLElement::LengthType::ParsingFailed || heightAttr.type == MathMLElement::LengthType::Percentage)
78+
return contentHeight;
79+
return std::max(0_lu, toUserUnits(heightAttr, style(), 0));
7380
}
7481

7582
LayoutUnit RenderMathMLPadded::mpaddedDepth(LayoutUnit contentDepth) const
7683
{
77-
return std::max<LayoutUnit>(0, toUserUnits(element().depth(), style(), contentDepth));
84+
auto& depthAttr = element().depth();
85+
// If parsing failed (attribute not set) or it's a percentage, use the content depth as default.
86+
if (depthAttr.type == MathMLElement::LengthType::ParsingFailed || depthAttr.type == MathMLElement::LengthType::Percentage)
87+
return contentDepth;
88+
return std::max(0_lu, toUserUnits(depthAttr, style(), 0));
7889
}
7990

8091
void RenderMathMLPadded::computePreferredLogicalWidths()

0 commit comments

Comments
 (0)