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

MozReview-Commit-ID: A6OTJ9PD43c

--HG--
extra : rebase_source : bcb53b7a0a966e2931c74db475ee8b7573354792
This commit is contained in:
Ting-Yu Lin 2017-01-06 16:35:53 +08:00
Родитель 2b3505661e
Коммит 74706308e7
3 изменённых файлов: 31 добавлений и 12 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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");