Bug 1908069 - Add border/padding/margin support to MathML token elements. r=emilio

See D216670 for the general approach taken.

Differential Revision: https://phabricator.services.mozilla.com/D216855
This commit is contained in:
Frédéric Wang 2024-08-07 06:00:44 +00:00
parent f508d43e1d
commit 8956b160de
8 changed files with 49 additions and 88 deletions

View File

@ -120,6 +120,10 @@ struct BaseMargin {
left = std::min(left, aMargin.left);
}
bool IsAllZero() const {
return left == 0 && top == 0 && right == 0 && bottom == 0;
}
// Overloaded operators. Note that '=' isn't defined so we'll get the
// compiler generated default assignment operator
bool operator==(const Sub& aMargin) const {

View File

@ -1423,10 +1423,7 @@ class LogicalMargin {
return *this;
}
bool IsAllZero() const {
return (mMargin.left == 0 && mMargin.top == 0 && mMargin.right == 0 &&
mMargin.bottom == 0);
}
bool IsAllZero() const { return mMargin.IsAllZero(); }
bool operator==(const LogicalMargin& aMargin) const {
CHECK_WRITING_MODE(aMargin.GetWritingMode());

View File

@ -155,10 +155,16 @@ nsresult nsMathMLTokenFrame::Place(DrawTarget* aDrawTarget,
mBoundingMetrics = nsBoundingMetrics();
for (nsIFrame* childFrame : PrincipalChildList()) {
ReflowOutput childSize(aDesiredSize.GetWritingMode());
GetReflowAndBoundingMetricsFor(childFrame, childSize,
childSize.mBoundingMetrics, nullptr);
nsBoundingMetrics bmChild;
GetReflowAndBoundingMetricsFor(childFrame, childSize, bmChild, nullptr);
auto childMargin = GetMarginForPlace(aFlags, childFrame);
bmChild.ascent += childMargin.top;
bmChild.descent += childMargin.bottom;
bmChild.rightBearing += childMargin.LeftRight();
bmChild.width += childMargin.LeftRight();
// compute and cache the bounding metrics
mBoundingMetrics += childSize.mBoundingMetrics;
mBoundingMetrics += bmChild;
}
RefPtr<nsFontMetrics> fm =
@ -172,17 +178,24 @@ nsresult nsMathMLTokenFrame::Place(DrawTarget* aDrawTarget,
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() +
std::max(mBoundingMetrics.descent, descent);
// Add padding+border.
auto borderPadding = GetBorderPaddingForPlace(aFlags);
InflateReflowAndBoundingMetrics(borderPadding, aDesiredSize,
mBoundingMetrics);
if (!aFlags.contains(PlaceFlag::MeasureOnly)) {
nscoord dy, dx = 0;
nscoord dx = borderPadding.left;
for (nsIFrame* childFrame : PrincipalChildList()) {
ReflowOutput childSize(aDesiredSize.GetWritingMode());
GetReflowAndBoundingMetricsFor(childFrame, childSize,
childSize.mBoundingMetrics);
auto childMargin = GetMarginForPlace(aFlags, childFrame);
// place and size the child; (dx,0) makes the caret happy - bug 188146
dy = childSize.Height() == 0
? 0
: aDesiredSize.BlockStartAscent() - childSize.BlockStartAscent();
nscoord dy = childSize.Height() == 0
? 0
: aDesiredSize.BlockStartAscent() -
childSize.BlockStartAscent() + childMargin.top;
FinishReflowChild(childFrame, PresContext(), childSize, nullptr, dx, dy,
ReflowChildFlags::Default);
dx += childSize.Width();

View File

@ -839,17 +839,20 @@ nsMathMLmoFrame::Stretch(DrawTarget* aDrawTarget,
// container and so we put the spacing, otherwise we don't include the
// spacing, the outermost embellished container will take care of it.
nscoord leadingSpace = 0, trailingSpace = 0;
if (!NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(mFlags)) {
// Account the spacing if we are not an accent with explicit attributes
nscoord leadingSpace = mEmbellishData.leadingSpace;
if (isAccent && !NS_MATHML_OPERATOR_HAS_LSPACE_ATTR(mFlags)) {
leadingSpace = 0;
if (!isAccent || NS_MATHML_OPERATOR_HAS_LSPACE_ATTR(mFlags)) {
leadingSpace = mEmbellishData.leadingSpace;
}
nscoord trailingSpace = mEmbellishData.trailingSpace;
if (isAccent && !NS_MATHML_OPERATOR_HAS_RSPACE_ATTR(mFlags)) {
trailingSpace = 0;
if (!isAccent || NS_MATHML_OPERATOR_HAS_RSPACE_ATTR(mFlags)) {
trailingSpace = mEmbellishData.trailingSpace;
}
}
flags = PlaceFlags();
auto borderPadding = GetBorderPaddingForPlace(flags);
if (leadingSpace || trailingSpace || !borderPadding.IsAllZero()) {
mBoundingMetrics.width += leadingSpace + trailingSpace;
aDesiredStretchSize.Width() = mBoundingMetrics.width;
aDesiredStretchSize.mBoundingMetrics.width = mBoundingMetrics.width;
@ -857,22 +860,29 @@ nsMathMLmoFrame::Stretch(DrawTarget* aDrawTarget,
nscoord dx = StyleVisibility()->mDirection == StyleDirection::Rtl
? trailingSpace
: leadingSpace;
if (dx) {
mBoundingMetrics.leftBearing += dx;
mBoundingMetrics.rightBearing += dx;
aDesiredStretchSize.mBoundingMetrics.leftBearing += dx;
aDesiredStretchSize.mBoundingMetrics.rightBearing += dx;
// Add border/padding.
InflateReflowAndBoundingMetrics(borderPadding, aDesiredStretchSize,
mBoundingMetrics);
dx += borderPadding.left;
nscoord dy = borderPadding.top;
if (dx || dy) {
// adjust the offsets
mBoundingMetrics.leftBearing += dx;
mBoundingMetrics.rightBearing += dx;
aDesiredStretchSize.mBoundingMetrics.leftBearing += dx;
aDesiredStretchSize.mBoundingMetrics.rightBearing += dx;
if (useMathMLChar) {
nsRect rect;
mMathMLChar.GetRect(rect);
mMathMLChar.SetRect(
nsRect(rect.x + dx, rect.y, rect.width, rect.height));
nsRect(rect.x + dx, rect.y + dy, rect.width, rect.height));
} else {
nsIFrame* childFrame = firstChild;
while (childFrame) {
childFrame->SetPosition(childFrame->GetPosition() + nsPoint(dx, 0));
childFrame->SetPosition(childFrame->GetPosition() + nsPoint(dx, dy));
childFrame = childFrame->GetNextSibling();
}
}
@ -1016,6 +1026,7 @@ void nsMathMLmoFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext,
aDesiredSize.Width() = mMathMLChar.GetMaxWidth(
this, aRenderingContext->GetDrawTarget(),
nsLayoutUtils::FontSizeInflationFor(this), stretchHint);
aDesiredSize.Width() += IntrinsicISizeOffsets().BorderPadding();
} else {
nsMathMLTokenFrame::GetIntrinsicISizeMetrics(aRenderingContext,
aDesiredSize);

View File

@ -2,9 +2,6 @@
[Border properties on mmultiscripts]
expected: FAIL
[Border properties on mn]
expected: FAIL
[Border properties on msup]
expected: FAIL
@ -26,21 +23,9 @@
[Border properties on mroot]
expected: FAIL
[Border properties on mi]
expected: FAIL
[Border properties on mo]
expected: FAIL
[Border properties on ms]
expected: FAIL
[Border properties on munderover]
expected: FAIL
[Border properties on mtext]
expected: FAIL
[Border properties on mover]
expected: FAIL
@ -65,26 +50,11 @@
[Border properties on msqrt (rtl)]
expected: FAIL
[Border properties on ms (rtl)]
expected: FAIL
[Border properties on mi (rtl)]
expected: FAIL
[Border properties on mo (rtl)]
expected: FAIL
[Border properties on mroot (rtl)]
expected: FAIL
[Border properties on mtext (rtl)]
expected: FAIL
[Border properties on menclose (rtl)]
expected: FAIL
[Border properties on msubsup (rtl)]
expected: FAIL
[Border properties on mn (rtl)]
expected: FAIL

View File

@ -1,25 +1,10 @@
[padding-002.html]
[Padding properties on mtext]
expected: FAIL
[Padding properties on ms]
expected: FAIL
[Padding properties on msqrt]
expected: FAIL
[Padding properties on menclose]
expected: FAIL
[Padding properties on mn]
expected: FAIL
[Padding properties on mo]
expected: FAIL
[Padding properties on mi]
expected: FAIL
[Padding properties on mroot]
expected: FAIL
@ -44,21 +29,12 @@
[Padding properties on mover]
expected: FAIL
[Padding properties on mtext (rtl)]
expected: FAIL
[Padding properties on munder (rtl)]
expected: FAIL
[Padding properties on mo (rtl)]
expected: FAIL
[Padding properties on mroot (rtl)]
expected: FAIL
[Padding properties on mn (rtl)]
expected: FAIL
[Padding properties on msub (rtl)]
expected: FAIL
@ -77,12 +53,6 @@
[Padding properties on mover (rtl)]
expected: FAIL
[Padding properties on mi (rtl)]
expected: FAIL
[Padding properties on ms (rtl)]
expected: FAIL
[Padding properties on msqrt (rtl)]
expected: FAIL

View File

@ -1,2 +0,0 @@
[padding-border-margin-002.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[padding-border-margin-003.html]
expected: FAIL