Bug 1311244 Part 3 - Extract the computation of center as ComputeCircleOrEllipseCenter(). r=dbaron

MozReview-Commit-ID: A6OTJ9PD43c

--HG--
extra : rebase_source : c8b16ffaaf00c4ed3ec722d7502262005e9e21ec
This commit is contained in:
Ting-Yu Lin 2017-01-06 16:35:53 +08:00
parent e42b15fcf6
commit 93b5370abd
3 changed files with 31 additions and 12 deletions

View File

@ -8,6 +8,9 @@
#include <cstdlib>
#include "nsCSSRendering.h"
#include "nsStyleStruct.h"
namespace mozilla {
nscoord
@ -30,4 +33,16 @@ ShapeUtils::ComputeShapeRadius(const StyleShapeRadius aType,
return length;
}
nsPoint
ShapeUtils::ComputeCircleOrEllipseCenter(StyleBasicShape* const aBasicShape,
const nsRect& aRefBox)
{
nsPoint topLeft, anchor;
nsSize size(aRefBox.Size());
nsImageRenderer::ComputeObjectAnchorPoint(aBasicShape->GetPosition(),
size, size,
&topLeft, &anchor);
return nsPoint(anchor.x + aRefBox.x, anchor.y + aRefBox.y);
}
} // namespace mozilla

View File

@ -10,7 +10,11 @@
#include "nsCoord.h"
#include "nsStyleConsts.h"
struct nsPoint;
struct nsRect;
namespace mozilla {
class StyleBasicShape;
// ShapeUtils is a namespace class containing utility functions related to
// processing basic shapes in the CSS Shapes Module.
@ -28,6 +32,14 @@ struct ShapeUtils final
const nscoord aCenter,
const nscoord aPosMin,
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(
StyleBasicShape* const aBasicShape,
const nsRect& aRefBox);
};
} // namespace mozilla

View File

@ -113,12 +113,8 @@ nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget,
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
nsPoint topLeft, anchor;
nsSize size = nsSize(aRefBox.width, aRefBox.height);
nsImageRenderer::ComputeObjectAnchorPoint(basicShape->GetPosition(),
size, size,
&topLeft, &anchor);
nsPoint center(anchor.x + aRefBox.x, anchor.y + aRefBox.y);
nsPoint center =
ShapeUtils::ComputeCircleOrEllipseCenter(basicShape, aRefBox);
const nsTArray<nsStyleCoord>& coords = basicShape->Coordinates();
MOZ_ASSERT(coords.Length() == 1, "wrong number of arguments");
@ -163,12 +159,8 @@ nsCSSClipPathInstance::CreateClipPathEllipse(DrawTarget* aDrawTarget,
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
nsPoint topLeft, anchor;
nsSize size = nsSize(aRefBox.width, aRefBox.height);
nsImageRenderer::ComputeObjectAnchorPoint(basicShape->GetPosition(),
size, size,
&topLeft, &anchor);
nsPoint center(anchor.x + aRefBox.x, anchor.y + aRefBox.y);
nsPoint center =
ShapeUtils::ComputeCircleOrEllipseCenter(basicShape, aRefBox);
const nsTArray<nsStyleCoord>& coords = basicShape->Coordinates();
MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");