mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-13 18:27:35 +00:00
Bug 1326407 Part 1 - Extract a function to compute inset rect. r=dbaron
MozReview-Commit-ID: DmVOVArtzBZ --HG-- extra : rebase_source : 835edd63d53cb439f4ebcd0551a2d4a8065f1ba6
This commit is contained in:
parent
a43fbc3c79
commit
3c289a249f
@ -9,6 +9,7 @@
|
||||
#include <cstdlib>
|
||||
|
||||
#include "nsCSSRendering.h"
|
||||
#include "nsMargin.h"
|
||||
#include "nsRuleNode.h"
|
||||
#include "nsStyleCoord.h"
|
||||
#include "nsStyleStruct.h"
|
||||
@ -115,4 +116,25 @@ ShapeUtils::ComputeEllipseRadii(StyleBasicShape* const aBasicShape,
|
||||
return radii;
|
||||
}
|
||||
|
||||
/* static */ nsRect
|
||||
ShapeUtils::ComputeInsetRect(StyleBasicShape* const aBasicShape,
|
||||
const nsRect& aRefBox)
|
||||
{
|
||||
MOZ_ASSERT(aBasicShape->GetShapeType() == StyleBasicShapeType::Inset,
|
||||
"The basic shape must be inset()!");
|
||||
|
||||
const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates();
|
||||
MOZ_ASSERT(coords.Length() == 4, "wrong number of arguments");
|
||||
|
||||
nsMargin inset(nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.height),
|
||||
nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.width),
|
||||
nsRuleNode::ComputeCoordPercentCalc(coords[2], aRefBox.height),
|
||||
nsRuleNode::ComputeCoordPercentCalc(coords[3], aRefBox.width));
|
||||
|
||||
nsRect insetRect(aRefBox);
|
||||
insetRect.Deflate(inset);
|
||||
|
||||
return insetRect;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -26,7 +26,6 @@ struct ShapeUtils final
|
||||
// farthest-side, for a circle or an ellipse on a single dimension. The
|
||||
// caller needs to call for both dimensions and combine the result.
|
||||
// https://drafts.csswg.org/css-shapes/#typedef-shape-radius.
|
||||
//
|
||||
// @return The length of the radius in app units.
|
||||
static nscoord ComputeShapeRadius(const StyleShapeRadius aType,
|
||||
const nscoord aCenter,
|
||||
@ -34,7 +33,6 @@ struct ShapeUtils final
|
||||
const nscoord aPosMax);
|
||||
|
||||
// Compute the center of a circle or an ellipse.
|
||||
//
|
||||
// @param aRefBox The reference box of the basic shape.
|
||||
// @return The point of the center.
|
||||
static nsPoint ComputeCircleOrEllipseCenter(
|
||||
@ -57,6 +55,13 @@ struct ShapeUtils final
|
||||
static nsSize ComputeEllipseRadii(
|
||||
mozilla::StyleBasicShape* const aBasicShape,
|
||||
const nsPoint& aCenter, const nsRect& aRefBox);
|
||||
|
||||
// Compute the rect for an inset.
|
||||
// @param aRefBox the reference box of the inset.
|
||||
// @return The inset rect in app units.
|
||||
static nsRect ComputeInsetRect(
|
||||
mozilla::StyleBasicShape* const aBasicShape,
|
||||
const nsRect& aRefBox);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -177,21 +177,13 @@ nsCSSClipPathInstance::CreateClipPathInset(DrawTarget* aDrawTarget,
|
||||
const nsRect& aRefBox)
|
||||
{
|
||||
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
|
||||
const nsTArray<nsStyleCoord>& coords = basicShape->Coordinates();
|
||||
MOZ_ASSERT(coords.Length() == 4, "wrong number of arguments");
|
||||
|
||||
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
||||
|
||||
nscoord appUnitsPerDevPixel =
|
||||
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
|
||||
nsMargin inset(nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.height),
|
||||
nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.width),
|
||||
nsRuleNode::ComputeCoordPercentCalc(coords[2], aRefBox.height),
|
||||
nsRuleNode::ComputeCoordPercentCalc(coords[3], aRefBox.width));
|
||||
|
||||
nsRect insetRect(aRefBox);
|
||||
insetRect.Deflate(inset);
|
||||
nsRect insetRect = ShapeUtils::ComputeInsetRect(basicShape, aRefBox);
|
||||
const Rect insetRectPixels = NSRectToRect(insetRect, appUnitsPerDevPixel);
|
||||
const nsStyleCorners& radius = basicShape->GetRadius();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user