Bug 825147: Convert SVGRectElement to WebIDL r=bz

--HG--
rename : content/svg/content/src/nsSVGRectElement.cpp => content/svg/content/src/SVGRectElement.cpp
rename : content/svg/content/src/nsSVGRectElement.cpp => content/svg/content/src/SVGRectElement.h
This commit is contained in:
David Zbarsky 2013-01-06 04:32:01 -05:00
parent 7cc0fdc8ca
commit ef2a415b95
6 changed files with 324 additions and 199 deletions

View File

@ -67,7 +67,6 @@ CPPSRCS = \
nsSVGPolyElement.cpp \
nsSVGString.cpp \
nsSVGRect.cpp \
nsSVGRectElement.cpp \
nsSVGSVGElement.cpp \
nsSVGSymbolElement.cpp \
nsSVGTSpanElement.cpp \
@ -99,6 +98,7 @@ CPPSRCS = \
SVGPathSegUtils.cpp \
SVGPointList.cpp \
SVGPreserveAspectRatio.cpp \
SVGRectElement.cpp \
SVGStringList.cpp \
SVGTitleElement.cpp \
SVGTransform.cpp \
@ -167,6 +167,7 @@ EXPORTS_mozilla/dom = \
SVGMPathElement.h \
SVGPolygonElement.h \
SVGPolylineElement.h \
SVGRectElement.h \
SVGScriptElement.h \
SVGStopElement.h \
SVGStyleElement.h \

View File

@ -0,0 +1,220 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/SVGRectElement.h"
#include "nsGkAtoms.h"
#include "gfxContext.h"
#include "mozilla/dom/SVGRectElementBinding.h"
DOMCI_NODE_DATA(SVGRectElement, mozilla::dom::SVGRectElement)
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Rect)
namespace mozilla {
namespace dom {
JSObject*
SVGRectElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
{
return SVGRectElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
nsSVGElement::LengthInfo SVGRectElement::sLengthInfo[6] =
{
{ &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y }
};
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(SVGRectElement,SVGRectElementBase)
NS_IMPL_RELEASE_INHERITED(SVGRectElement,SVGRectElementBase)
NS_INTERFACE_TABLE_HEAD(SVGRectElement)
NS_NODE_INTERFACE_TABLE4(SVGRectElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGRectElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGRectElement)
NS_INTERFACE_MAP_END_INHERITING(SVGRectElementBase)
//----------------------------------------------------------------------
// Implementation
SVGRectElement::SVGRectElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: SVGRectElementBase(aNodeInfo)
{
SetIsDOMBinding();
}
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGRectElement)
//----------------------------------------------------------------------
// nsIDOMSVGRectElement methods
/* readonly attribute nsIDOMSVGAnimatedLength x; */
NS_IMETHODIMP SVGRectElement::GetX(nsIDOMSVGAnimatedLength * *aX)
{
*aX = X().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGRectElement::X()
{
nsCOMPtr<nsIDOMSVGAnimatedLength> x;
mLengthAttributes[ATTR_X].ToDOMAnimatedLength(getter_AddRefs(x), this);
return x.forget();
}
/* readonly attribute nsIDOMSVGAnimatedLength y; */
NS_IMETHODIMP SVGRectElement::GetY(nsIDOMSVGAnimatedLength * *aY)
{
*aY = Y().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGRectElement::Y()
{
nsCOMPtr<nsIDOMSVGAnimatedLength> y;
mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(getter_AddRefs(y), this);
return y.forget();
}
/* readonly attribute nsIDOMSVGAnimatedLength width; */
NS_IMETHODIMP SVGRectElement::GetWidth(nsIDOMSVGAnimatedLength * *aWidth)
{
*aWidth = Width().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGRectElement::Width()
{
nsCOMPtr<nsIDOMSVGAnimatedLength> width;
mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(getter_AddRefs(width), this);
return width.forget();
}
/* readonly attribute nsIDOMSVGAnimatedLength height; */
NS_IMETHODIMP SVGRectElement::GetHeight(nsIDOMSVGAnimatedLength * *aHeight)
{
*aHeight = Height().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGRectElement::Height()
{
nsCOMPtr<nsIDOMSVGAnimatedLength> height;
mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(getter_AddRefs(height), this);
return height.forget();
}
/* readonly attribute nsIDOMSVGAnimatedLength rx; */
NS_IMETHODIMP SVGRectElement::GetRx(nsIDOMSVGAnimatedLength * *aRx)
{
*aRx = Rx().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGRectElement::Rx()
{
nsCOMPtr<nsIDOMSVGAnimatedLength> Rx;
mLengthAttributes[ATTR_RX].ToDOMAnimatedLength(getter_AddRefs(Rx), this);
return Rx.forget();
}
/* readonly attribute nsIDOMSVGAnimatedLength ry; */
NS_IMETHODIMP SVGRectElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
{
*aRy = Ry().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGRectElement::Ry()
{
nsCOMPtr<nsIDOMSVGAnimatedLength> Ry;
mLengthAttributes[ATTR_RY].ToDOMAnimatedLength(getter_AddRefs(Ry), this);
return Ry.forget();
}
//----------------------------------------------------------------------
// nsSVGElement methods
/* virtual */ bool
SVGRectElement::HasValidDimensions() const
{
return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() &&
mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() &&
mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0;
}
nsSVGElement::LengthAttributesInfo
SVGRectElement::GetLengthInfo()
{
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
ArrayLength(sLengthInfo));
}
//----------------------------------------------------------------------
// nsSVGPathGeometryElement methods
void
SVGRectElement::ConstructPath(gfxContext *aCtx)
{
float x, y, width, height, rx, ry;
GetAnimatedLengthValues(&x, &y, &width, &height, &rx, &ry, nullptr);
/* In a perfect world, this would be handled by the DOM, and
return a DOM exception. */
if (width <= 0 || height <= 0)
return;
rx = NS_MAX(rx, 0.0f);
ry = NS_MAX(ry, 0.0f);
/* optimize the no rounded corners case */
if (rx == 0 && ry == 0) {
aCtx->Rectangle(gfxRect(x, y, width, height));
return;
}
/* If either the 'rx' or the 'ry' attribute isn't set, then we
have to set it to the value of the other. */
bool hasRx = mLengthAttributes[ATTR_RX].IsExplicitlySet();
bool hasRy = mLengthAttributes[ATTR_RY].IsExplicitlySet();
if (hasRx && !hasRy)
ry = rx;
else if (hasRy && !hasRx)
rx = ry;
/* Clamp rx and ry to half the rect's width and height respectively. */
float halfWidth = width/2;
float halfHeight = height/2;
if (rx > halfWidth)
rx = halfWidth;
if (ry > halfHeight)
ry = halfHeight;
gfxSize corner(rx, ry);
aCtx->RoundedRectangle(gfxRect(x, y, width, height),
gfxCornerSizes(corner, corner, corner, corner));
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_SVGRectElement_h
#define mozilla_dom_SVGRectElement_h
#include "nsSVGPathGeometryElement.h"
#include "nsIDOMSVGRectElement.h"
#include "nsSVGLength2.h"
nsresult NS_NewSVGRectElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
typedef nsSVGPathGeometryElement SVGRectElementBase;
namespace mozilla {
namespace dom {
class SVGRectElement MOZ_FINAL : public SVGRectElementBase,
public nsIDOMSVGRectElement
{
protected:
SVGRectElement(already_AddRefed<nsINodeInfo> aNodeInfo);
virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE;
friend nsresult (::NS_NewSVGRectElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo));
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGRECTELEMENT
// xxx I wish we could use virtual inheritance
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
NS_FORWARD_NSIDOMSVGELEMENT(SVGRectElementBase::)
// nsSVGSVGElement methods:
virtual bool HasValidDimensions() const;
// nsSVGPathGeometryElement methods:
virtual void ConstructPath(gfxContext *aCtx);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
// WebIDL
already_AddRefed<nsIDOMSVGAnimatedLength> X();
already_AddRefed<nsIDOMSVGAnimatedLength> Y();
already_AddRefed<nsIDOMSVGAnimatedLength> Height();
already_AddRefed<nsIDOMSVGAnimatedLength> Width();
already_AddRefed<nsIDOMSVGAnimatedLength> Rx();
already_AddRefed<nsIDOMSVGAnimatedLength> Ry();
protected:
virtual LengthAttributesInfo GetLengthInfo();
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT, ATTR_RX, ATTR_RY };
nsSVGLength2 mLengthAttributes[6];
static LengthInfo sLengthInfo[6];
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGRectElement_h

View File

@ -1,198 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Util.h"
#include "nsSVGPathGeometryElement.h"
#include "nsIDOMSVGRectElement.h"
#include "nsSVGLength2.h"
#include "nsGkAtoms.h"
#include "gfxContext.h"
using namespace mozilla;
typedef nsSVGPathGeometryElement nsSVGRectElementBase;
class nsSVGRectElement : public nsSVGRectElementBase,
public nsIDOMSVGRectElement
{
protected:
friend nsresult NS_NewSVGRectElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
nsSVGRectElement(already_AddRefed<nsINodeInfo> aNodeInfo);
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGRECTELEMENT
// xxx I wish we could use virtual inheritance
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGRectElementBase::)
// nsSVGSVGElement methods:
virtual bool HasValidDimensions() const;
// nsSVGPathGeometryElement methods:
virtual void ConstructPath(gfxContext *aCtx);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
protected:
virtual LengthAttributesInfo GetLengthInfo();
enum { X, Y, WIDTH, HEIGHT, RX, RY };
nsSVGLength2 mLengthAttributes[6];
static LengthInfo sLengthInfo[6];
};
nsSVGElement::LengthInfo nsSVGRectElement::sLengthInfo[6] =
{
{ &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y }
};
NS_IMPL_NS_NEW_SVG_ELEMENT(Rect)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGRectElement,nsSVGRectElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGRectElement,nsSVGRectElementBase)
DOMCI_NODE_DATA(SVGRectElement, nsSVGRectElement)
NS_INTERFACE_TABLE_HEAD(nsSVGRectElement)
NS_NODE_INTERFACE_TABLE4(nsSVGRectElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGRectElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGRectElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGRectElementBase)
//----------------------------------------------------------------------
// Implementation
nsSVGRectElement::nsSVGRectElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGRectElementBase(aNodeInfo)
{
}
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGRectElement)
//----------------------------------------------------------------------
// nsIDOMSVGRectElement methods
/* readonly attribute nsIDOMSVGAnimatedLength x; */
NS_IMETHODIMP nsSVGRectElement::GetX(nsIDOMSVGAnimatedLength * *aX)
{
return mLengthAttributes[X].ToDOMAnimatedLength(aX, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength y; */
NS_IMETHODIMP nsSVGRectElement::GetY(nsIDOMSVGAnimatedLength * *aY)
{
return mLengthAttributes[Y].ToDOMAnimatedLength(aY, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength width; */
NS_IMETHODIMP nsSVGRectElement::GetWidth(nsIDOMSVGAnimatedLength * *aWidth)
{
return mLengthAttributes[WIDTH].ToDOMAnimatedLength(aWidth, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength height; */
NS_IMETHODIMP nsSVGRectElement::GetHeight(nsIDOMSVGAnimatedLength * *aHeight)
{
return mLengthAttributes[HEIGHT].ToDOMAnimatedLength(aHeight, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength rx; */
NS_IMETHODIMP nsSVGRectElement::GetRx(nsIDOMSVGAnimatedLength * *aRx)
{
return mLengthAttributes[RX].ToDOMAnimatedLength(aRx, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength ry; */
NS_IMETHODIMP nsSVGRectElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
{
return mLengthAttributes[RY].ToDOMAnimatedLength(aRy, this);
}
//----------------------------------------------------------------------
// nsSVGElement methods
/* virtual */ bool
nsSVGRectElement::HasValidDimensions() const
{
return mLengthAttributes[WIDTH].IsExplicitlySet() &&
mLengthAttributes[WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
mLengthAttributes[HEIGHT].IsExplicitlySet() &&
mLengthAttributes[HEIGHT].GetAnimValInSpecifiedUnits() > 0;
}
nsSVGElement::LengthAttributesInfo
nsSVGRectElement::GetLengthInfo()
{
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
ArrayLength(sLengthInfo));
}
//----------------------------------------------------------------------
// nsSVGPathGeometryElement methods
void
nsSVGRectElement::ConstructPath(gfxContext *aCtx)
{
float x, y, width, height, rx, ry;
GetAnimatedLengthValues(&x, &y, &width, &height, &rx, &ry, nullptr);
/* In a perfect world, this would be handled by the DOM, and
return a DOM exception. */
if (width <= 0 || height <= 0)
return;
rx = NS_MAX(rx, 0.0f);
ry = NS_MAX(ry, 0.0f);
/* optimize the no rounded corners case */
if (rx == 0 && ry == 0) {
aCtx->Rectangle(gfxRect(x, y, width, height));
return;
}
/* If either the 'rx' or the 'ry' attribute isn't set, then we
have to set it to the value of the other. */
bool hasRx = mLengthAttributes[RX].IsExplicitlySet();
bool hasRy = mLengthAttributes[RY].IsExplicitlySet();
if (hasRx && !hasRy)
ry = rx;
else if (hasRy && !hasRx)
rx = ry;
/* Clamp rx and ry to half the rect's width and height respectively. */
float halfWidth = width/2;
float halfHeight = height/2;
if (rx > halfWidth)
rx = halfWidth;
if (ry > halfHeight)
ry = halfHeight;
gfxSize corner(rx, ry);
aCtx->RoundedRectangle(gfxRect(x, y, width, height),
gfxCornerSizes(corner, corner, corner, corner));
}

View File

@ -0,0 +1,29 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://www.w3.org/TR/SVG2/
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface SVGAnimatedLength;
interface SVGRectElement : SVGGraphicsElement {
[Constant]
readonly attribute SVGAnimatedLength x;
[Constant]
readonly attribute SVGAnimatedLength y;
[Constant]
readonly attribute SVGAnimatedLength width;
[Constant]
readonly attribute SVGAnimatedLength height;
[Constant]
readonly attribute SVGAnimatedLength rx;
[Constant]
readonly attribute SVGAnimatedLength ry;
};

View File

@ -124,6 +124,7 @@ webidl_files = \
SVGPolygonElement.webidl \
SVGPolylineElement.webidl \
SVGPreserveAspectRatio.webidl \
SVGRectElement.webidl \
SVGScriptElement.webidl \
SVGStopElement.webidl \
SVGStyleElement.webidl \