Skip to content

Commit

Permalink
Bug 1461046 Part 2: Change ShapeUtils::ComputeInsetRect to return the…
Browse files Browse the repository at this point in the history
… inverse of a rect deflated more than its bounds can tolerate. r=dholbert

MozReview-Commit-ID: IScKyqzjMoy

--HG--
extra : rebase_source : 2057746c86b8ad86a1afd989111f83d6d9b8cafb
  • Loading branch information
bradwerth committed May 19, 2018
1 parent 39839d2 commit cafe50b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
28 changes: 21 additions & 7 deletions layout/base/ShapeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,29 @@ ShapeUtils::ComputeInsetRect(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates();
MOZ_ASSERT(coords.Length() == 4, "wrong number of arguments");

nsMargin inset(coords[0].ComputeCoordPercentCalc(aRefBox.height),
coords[1].ComputeCoordPercentCalc(aRefBox.width),
coords[2].ComputeCoordPercentCalc(aRefBox.height),
coords[3].ComputeCoordPercentCalc(aRefBox.width));
nsMargin inset(coords[0].ComputeCoordPercentCalc(aRefBox.Height()),
coords[1].ComputeCoordPercentCalc(aRefBox.Width()),
coords[2].ComputeCoordPercentCalc(aRefBox.Height()),
coords[3].ComputeCoordPercentCalc(aRefBox.Width()));

nscoord x = aRefBox.X() + inset.left;
nscoord width = aRefBox.Width() - inset.LeftRight();
nscoord y = aRefBox.Y() + inset.top;
nscoord height = aRefBox.Height() - inset.TopBottom();

// Invert left and right, if necessary.
if (width < 0) {
width *= -1;
x -= width;
}

nsRect insetRect(aRefBox);
insetRect.Deflate(inset);
// Invert top and bottom, if necessary.
if (height < 0) {
height *= -1;
y -= height;
}

return insetRect;
return nsRect(x, y, width, height);
}

/* static */ bool
Expand Down
11 changes: 10 additions & 1 deletion layout/base/ShapeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ struct ShapeUtils final
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsPoint& aCenter, const nsRect& aRefBox);

// Compute the rect for an inset.
// Compute the rect for an inset. If the inset amount is larger than
// aRefBox itself, this will return a rect the same shape as the inverse
// rect that would be created by insetting aRefBox by the inset amount.
// This process is *not* what is called for by the current spec at
// https://drafts.csswg.org/css-shapes-1/#supported-basic-shapes.
// The spec currently treats empty shapes, including overly-inset rects, as
// defining 'empty float areas' that don't affect layout. However, it is
// practically useful to treat empty shapes as having edges for purposes of
// affecting layout, and there is growing momentum for the approach we
// are taking here.
// @param aRefBox the reference box of the inset.
// @return The inset rect in app units.
static nsRect ComputeInsetRect(
Expand Down

0 comments on commit cafe50b

Please sign in to comment.