Bug 1128281 - Pass strokeOptions to getGeometryBounds. r=jwatt

This commit is contained in:
Robert Longson 2015-02-03 18:36:32 +00:00
parent 3bfde08bc7
commit 8af42d4a1f
14 changed files with 44 additions and 44 deletions

View File

@ -82,8 +82,8 @@ SVGCircleElement::GetLengthInfo()
// nsSVGPathGeometryElement methods
bool
SVGCircleElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform)
SVGCircleElement::GetGeometryBounds(
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
{
float x, y, r;
GetAnimatedLengthValues(&x, &y, &r, nullptr);
@ -97,8 +97,8 @@ SVGCircleElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
if (aTransform.IsRectilinear()) {
// Optimize the case where we can treat the circle as a rectangle and
// still get tight bounds.
if (aStrokeWidth > 0.f) {
r += aStrokeWidth / 2.f;
if (aStrokeOptions.mLineWidth > 0.f) {
r += aStrokeOptions.mLineWidth / 2.f;
}
Rect rect(x - r, y - r, 2 * r, 2 * r);
*aBounds = aTransform.TransformBounds(rect);

View File

@ -30,8 +30,8 @@ public:
virtual bool HasValidDimensions() const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -93,8 +93,8 @@ SVGEllipseElement::GetLengthInfo()
// nsSVGPathGeometryElement methods
bool
SVGEllipseElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform)
SVGEllipseElement::GetGeometryBounds(
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
{
float x, y, rx, ry;
GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
@ -108,9 +108,9 @@ SVGEllipseElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
if (aTransform.IsRectilinear()) {
// Optimize the case where we can treat the ellipse as a rectangle and
// still get tight bounds.
if (aStrokeWidth > 0.f) {
rx += aStrokeWidth / 2.f;
ry += aStrokeWidth / 2.f;
if (aStrokeOptions.mLineWidth > 0.f) {
rx += aStrokeOptions.mLineWidth / 2.f;
ry += aStrokeOptions.mLineWidth / 2.f;
}
Rect rect(x - rx, y - ry, 2 * rx, 2 * ry);
*aBounds = aTransform.TransformBounds(rect);

View File

@ -30,8 +30,8 @@ public:
virtual bool HasValidDimensions() const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -225,8 +225,8 @@ SVGImageElement::IsAttributeMapped(const nsIAtom* name) const
/* For the purposes of the update/invalidation logic pretend to
be a rectangle. */
bool
SVGImageElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform)
SVGImageElement::GetGeometryBounds(
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
{
Rect rect;
GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width,

View File

@ -53,8 +53,8 @@ public:
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle cap, const Matrix& aTransform) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
// nsSVGSVGElement methods:

View File

@ -127,26 +127,26 @@ SVGLineElement::BuildPath(PathBuilder* aBuilder)
}
bool
SVGLineElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform)
SVGLineElement::GetGeometryBounds(
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
{
float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
if (aStrokeWidth <= 0) {
if (aStrokeOptions.mLineWidth <= 0) {
*aBounds = Rect(aTransform * Point(x1, y1), Size());
aBounds->ExpandToEnclose(aTransform * Point(x2, y2));
return true;
}
if (aCapStyle == CapStyle::ROUND) {
if (aStrokeOptions.mLineCap == CapStyle::ROUND) {
if (!aTransform.IsRectilinear()) {
// TODO: handle this case.
return false;
}
Rect bounds(Point(x1, y1), Size());
bounds.ExpandToEnclose(Point(x2, y2));
bounds.Inflate(aStrokeWidth / 2.f);
bounds.Inflate(aStrokeOptions.mLineWidth / 2.f);
*aBounds = aTransform.TransformBounds(bounds);
return true;
}
@ -155,20 +155,20 @@ SVGLineElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
Float xDelta;
Float yDelta;
if (aCapStyle == CapStyle::BUTT) {
if (aStrokeOptions.mLineCap == CapStyle::BUTT) {
if (length == 0.f) {
xDelta = yDelta = 0.f;
} else {
Float ratio = aStrokeWidth / 2.f / length;
Float ratio = aStrokeOptions.mLineWidth / 2.f / length;
xDelta = ratio * (y2 - y1);
yDelta = ratio * (x2 - x1);
}
} else {
MOZ_ASSERT(aCapStyle == CapStyle::SQUARE);
MOZ_ASSERT(aStrokeOptions.mLineCap == CapStyle::SQUARE);
if (length == 0.f) {
xDelta = yDelta = aStrokeWidth / 2.f;
xDelta = yDelta = aStrokeOptions.mLineWidth / 2.f;
} else {
Float ratio = aStrokeWidth / 2.f / length;
Float ratio = aStrokeOptions.mLineWidth / 2.f / length;
xDelta = yDelta = ratio * (fabs(y2 - y1) + fabs(x2 - x1));
}
}

View File

@ -34,8 +34,8 @@ public:
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual void GetAsSimplePath(SimplePath* aSimplePath) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle cap, const Matrix& aTransform) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) MOZ_OVERRIDE;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -111,8 +111,8 @@ SVGRectElement::GetLengthInfo()
// nsSVGPathGeometryElement methods
bool
SVGRectElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform)
SVGRectElement::GetGeometryBounds(
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
{
Rect rect;
Float rx, ry;
@ -137,8 +137,8 @@ SVGRectElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
}
}
if (aStrokeWidth > 0.f) {
rect.Inflate(aStrokeWidth / 2.f);
if (aStrokeOptions.mLineWidth > 0.f) {
rect.Inflate(aStrokeOptions.mLineWidth / 2.f);
}
*aBounds = aTransform.TransformBounds(rect);

View File

@ -30,8 +30,8 @@ public:
virtual bool HasValidDimensions() const MOZ_OVERRIDE;
// nsSVGPathGeometryElement methods:
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) MOZ_OVERRIDE;
virtual void GetAsSimplePath(SimplePath* aSimplePath) MOZ_OVERRIDE;
virtual TemporaryRef<Path> BuildPath(PathBuilder* aBuilder = nullptr) MOZ_OVERRIDE;

View File

@ -40,6 +40,7 @@ protected:
typedef mozilla::gfx::Point Point;
typedef mozilla::gfx::PathBuilder PathBuilder;
typedef mozilla::gfx::Rect Rect;
typedef mozilla::gfx::StrokeOptions StrokeOptions;
public:
explicit nsSVGPathGeometryElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
@ -77,8 +78,8 @@ public:
* shapes and simple transforms where the Moz2D Path backends can fail to
* produce the clean integer bounds that content authors expect in some cases.
*/
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform) {
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) {
return false;
}

View File

@ -121,8 +121,8 @@ nsSVGPolyElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
}
bool
nsSVGPolyElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform)
nsSVGPolyElement::GetGeometryBounds(
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
{
const SVGPointList &points = mPoints.GetAnimValue();
@ -132,7 +132,7 @@ nsSVGPolyElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
return true;
}
if (aStrokeWidth > 0) {
if (aStrokeOptions.mLineWidth > 0) {
// We don't handle stroke-miterlimit etc. yet
return false;
}

View File

@ -45,8 +45,8 @@ public:
virtual bool AttributeDefinesGeometry(const nsIAtom *aName) MOZ_OVERRIDE;
virtual bool IsMarkable() MOZ_OVERRIDE { return true; }
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
CapStyle aCapStyle, const Matrix& aTransform) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
const Matrix& aTransform) MOZ_OVERRIDE;
// WebIDL
already_AddRefed<mozilla::DOMSVGPointList> Points();

View File

@ -480,8 +480,7 @@ nsSVGPathGeometryFrame::GetBBoxContribution(const Matrix &aToBBoxUserspace,
}
Rect simpleBounds;
gotSimpleBounds = element->GetGeometryBounds(&simpleBounds,
strokeOptions.mLineWidth,
strokeOptions.mLineCap,
strokeOptions,
aToBBoxUserspace);
if (gotSimpleBounds) {
bbox = simpleBounds;