forked from mirrors/gecko-dev
Bug 1785903 - Use inset rect as the border area to compute shape radii. r=TYLin
Differential Revision: https://phabricator.services.mozilla.com/D155072
This commit is contained in:
parent
c20ec755c9
commit
d6c13d0b23
7 changed files with 43 additions and 8 deletions
|
|
@ -124,9 +124,11 @@ nsRect ShapeUtils::ComputeInsetRect(const StyleBasicShape& aBasicShape,
|
|||
|
||||
/* static */
|
||||
bool ShapeUtils::ComputeInsetRadii(const StyleBasicShape& aBasicShape,
|
||||
const nsRect& aRefBox, nscoord aRadii[8]) {
|
||||
const nsRect& aRefBox,
|
||||
const nsRect& aInsetRect,
|
||||
nscoord aRadii[8]) {
|
||||
const auto& radius = aBasicShape.AsInset().round;
|
||||
return nsIFrame::ComputeBorderRadii(radius, aRefBox.Size(), aRefBox.Size(),
|
||||
return nsIFrame::ComputeBorderRadii(radius, aRefBox.Size(), aInsetRect.Size(),
|
||||
Sides(), aRadii);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,10 +70,11 @@ struct ShapeUtils final {
|
|||
|
||||
// Compute the radii for an inset.
|
||||
// @param aRefBox the reference box of the inset.
|
||||
// @param aInsetRect the inset rect in app units.
|
||||
// @param aRadii the returned radii in app units.
|
||||
// @return true if any of the radii is nonzero; false otherwise.
|
||||
static bool ComputeInsetRadii(const StyleBasicShape&, const nsRect& aRefBox,
|
||||
nscoord aRadii[8]);
|
||||
const nsRect& aInsetRect, nscoord aRadii[8]);
|
||||
|
||||
// Compute the vertices for a polygon.
|
||||
// @param aRefBox the reference box of the polygon.
|
||||
|
|
|
|||
|
|
@ -2522,14 +2522,14 @@ nsFloatManager::ShapeInfo::CreateInset(const StyleBasicShape& aBasicShape,
|
|||
// https://drafts.csswg.org/css-shapes-1/#funcdef-inset
|
||||
nsRect physicalShapeBoxRect =
|
||||
aShapeBoxRect.GetPhysicalRect(aWM, aContainerSize);
|
||||
nsRect insetRect =
|
||||
const nsRect insetRect =
|
||||
ShapeUtils::ComputeInsetRect(aBasicShape, physicalShapeBoxRect);
|
||||
|
||||
nsRect logicalInsetRect = ConvertToFloatLogical(
|
||||
LogicalRect(aWM, insetRect, aContainerSize), aWM, aContainerSize);
|
||||
nscoord physicalRadii[8];
|
||||
bool hasRadii = ShapeUtils::ComputeInsetRadii(
|
||||
aBasicShape, physicalShapeBoxRect, physicalRadii);
|
||||
aBasicShape, physicalShapeBoxRect, insetRect, physicalRadii);
|
||||
|
||||
// With a zero shape-margin, we will be able to use the fast constructor.
|
||||
if (aShapeMargin == 0) {
|
||||
|
|
|
|||
|
|
@ -8012,7 +8012,7 @@ static Maybe<wr::WrClipChainId> CreateSimpleClipRegion(
|
|||
|
||||
nscoord radii[8] = {0};
|
||||
|
||||
if (ShapeUtils::ComputeInsetRadii(shape, refBox, radii)) {
|
||||
if (ShapeUtils::ComputeInsetRadii(shape, refBox, insetRect, radii)) {
|
||||
clipId = aBuilder.DefineRoundedRectClip(
|
||||
Nothing(),
|
||||
wr::ToComplexClipRegion(insetRect, radii, appUnitsPerDevPixel));
|
||||
|
|
|
|||
|
|
@ -210,11 +210,12 @@ already_AddRefed<Path> CSSClipPathInstance::CreateClipPathInset(
|
|||
nscoord appUnitsPerDevPixel =
|
||||
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
|
||||
nsRect insetRect = ShapeUtils::ComputeInsetRect(basicShape, aRefBox);
|
||||
const nsRect insetRect = ShapeUtils::ComputeInsetRect(basicShape, aRefBox);
|
||||
const Rect insetRectPixels = NSRectToRect(insetRect, appUnitsPerDevPixel);
|
||||
nscoord appUnitsRadii[8];
|
||||
|
||||
if (ShapeUtils::ComputeInsetRadii(basicShape, aRefBox, appUnitsRadii)) {
|
||||
if (ShapeUtils::ComputeInsetRadii(basicShape, aRefBox, insetRect,
|
||||
appUnitsRadii)) {
|
||||
RectCornerRadii corners;
|
||||
nsCSSRendering::ComputePixelRadii(appUnitsRadii, appUnitsPerDevPixel,
|
||||
&corners);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>CSS Test Reference</title>
|
||||
<style>
|
||||
#target {
|
||||
margin: 30px;
|
||||
height: 40px;
|
||||
width: 40px;
|
||||
background-color: lime;
|
||||
border-radius: 5px;
|
||||
}
|
||||
</style>
|
||||
<div id="target"></div>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>CSS clip path with zero box size</title>
|
||||
<link rel="help" href="https://drafts.fxtf.org/css-masking-1/#the-clip-path">
|
||||
<link rel="help" href="https://bugzil.la/1785903">
|
||||
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
|
||||
<link rel="author" title="Mozilla" href="https://mozilla.org">
|
||||
<link rel="match" href="clip-path-round-zero-size-ref.html">
|
||||
<style>
|
||||
#target {
|
||||
margin: 50px;
|
||||
height: 0px;
|
||||
width: 0px;
|
||||
outline: 50px solid lime;
|
||||
clip-path: inset(-20px round 5px);
|
||||
}
|
||||
</style>
|
||||
<div id="target"></div>
|
||||
Loading…
Reference in a new issue