Bug 825147: Convert SVGLineElement to WebIDL r=bz

--HG--
rename : content/svg/content/src/nsSVGLineElement.cpp => content/svg/content/src/SVGLineElement.cpp
rename : content/svg/content/src/nsSVGLineElement.cpp => content/svg/content/src/SVGLineElement.h
This commit is contained in:
David Zbarsky 2013-01-06 04:32:02 -05:00
Родитель b3f0ff27ea
Коммит 64cec390c7
6 изменённых файлов: 265 добавлений и 172 удалений

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

@ -57,7 +57,6 @@ CPPSRCS = \
nsSVGInteger.cpp \
nsSVGIntegerPair.cpp \
nsSVGLength2.cpp \
nsSVGLineElement.cpp \
nsSVGMarkerElement.cpp \
nsSVGMaskElement.cpp \
nsSVGNumber2.cpp \
@ -105,6 +104,7 @@ CPPSRCS = \
SVGLength.cpp \
SVGLengthList.cpp \
SVGLengthListSMILType.cpp \
SVGLineElement.cpp \
SVGLocatableElement.cpp \
SVGMetadataElement.cpp \
SVGMotionSMILType.cpp \
@ -164,6 +164,7 @@ EXPORTS_mozilla/dom = \
SVGGElement.h \
SVGGraphicsElement.h \
SVGImageElement.h \
SVGLineElement.h \
SVGLocatableElement.h \
SVGMetadataElement.h \
SVGMPathElement.h \

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

@ -0,0 +1,165 @@
/* -*- 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/SVGLineElement.h"
#include "mozilla/dom/SVGLineElementBinding.h"
#include "gfxContext.h"
DOMCI_NODE_DATA(SVGLineElement, mozilla::dom::SVGLineElement)
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Line)
namespace mozilla {
namespace dom {
JSObject*
SVGLineElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
{
return SVGLineElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
nsSVGElement::LengthInfo SVGLineElement::sLengthInfo[4] =
{
{ &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
};
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(SVGLineElement,SVGLineElementBase)
NS_IMPL_RELEASE_INHERITED(SVGLineElement,SVGLineElementBase)
NS_INTERFACE_TABLE_HEAD(SVGLineElement)
NS_NODE_INTERFACE_TABLE4(SVGLineElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGLineElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGLineElement)
NS_INTERFACE_MAP_END_INHERITING(SVGLineElementBase)
//----------------------------------------------------------------------
// Implementation
SVGLineElement::SVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: SVGLineElementBase(aNodeInfo)
{
SetIsDOMBinding();
}
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGLineElement)
//----------------------------------------------------------------------
// nsIDOMSVGLineElement methods
/* readonly attribute nsIDOMSVGAnimatedLength cx; */
NS_IMETHODIMP SVGLineElement::GetX1(nsIDOMSVGAnimatedLength * *aX1)
{
*aX1 = X1().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGLineElement::X1()
{
return mLengthAttributes[ATTR_X1].ToDOMAnimatedLength(this);
}
/* readonly attribute nsIDOMSVGAnimatedLength cy; */
NS_IMETHODIMP SVGLineElement::GetY1(nsIDOMSVGAnimatedLength * *aY1)
{
*aY1 = Y1().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGLineElement::Y1()
{
return mLengthAttributes[ATTR_Y1].ToDOMAnimatedLength(this);
}
/* readonly attribute nsIDOMSVGAnimatedLength rx; */
NS_IMETHODIMP SVGLineElement::GetX2(nsIDOMSVGAnimatedLength * *aX2)
{
*aX2 = X2().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGLineElement::X2()
{
return mLengthAttributes[ATTR_X2].ToDOMAnimatedLength(this);
}
/* readonly attribute nsIDOMSVGAnimatedLength ry; */
NS_IMETHODIMP SVGLineElement::GetY2(nsIDOMSVGAnimatedLength * *aY2)
{
*aY2 = Y2().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedLength>
SVGLineElement::Y2()
{
return mLengthAttributes[ATTR_Y2].ToDOMAnimatedLength(this);
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGLineElement::IsAttributeMapped(const nsIAtom* name) const
{
static const MappedAttributeEntry* const map[] = {
sMarkersMap
};
return FindAttributeDependence(name, map) ||
SVGLineElementBase::IsAttributeMapped(name);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::LengthAttributesInfo
SVGLineElement::GetLengthInfo()
{
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
ArrayLength(sLengthInfo));
}
//----------------------------------------------------------------------
// nsSVGPathGeometryElement methods
void
SVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
float angle = atan2(y2 - y1, x2 - x1);
aMarks->AppendElement(nsSVGMark(x1, y1, angle));
aMarks->AppendElement(nsSVGMark(x2, y2, angle));
}
void
SVGLineElement::ConstructPath(gfxContext *aCtx)
{
float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
aCtx->MoveTo(gfxPoint(x1, y1));
aCtx->LineTo(gfxPoint(x2, y2));
}
} // namespace dom
} // namespace mozilla

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

@ -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_SVGLineElement_h
#define mozilla_dom_SVGLineElement_h
#include "nsSVGPathGeometryElement.h"
#include "nsIDOMSVGLineElement.h"
#include "nsSVGLength2.h"
nsresult NS_NewSVGLineElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
namespace mozilla {
namespace dom {
typedef nsSVGPathGeometryElement SVGLineElementBase;
class SVGLineElement MOZ_FINAL : public SVGLineElementBase,
public nsIDOMSVGLineElement
{
protected:
SVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo);
virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE;
friend nsresult (::NS_NewSVGLineElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo));
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGLINEELEMENT
// xxx I wish we could use virtual inheritance
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
NS_FORWARD_NSIDOMSVGELEMENT(SVGLineElementBase::)
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
// nsSVGPathGeometryElement methods:
virtual bool IsMarkable() { return true; }
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
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> X1();
already_AddRefed<nsIDOMSVGAnimatedLength> Y1();
already_AddRefed<nsIDOMSVGAnimatedLength> X2();
already_AddRefed<nsIDOMSVGAnimatedLength> Y2();
protected:
virtual LengthAttributesInfo GetLengthInfo();
enum { ATTR_X1, ATTR_Y1, ATTR_X2, ATTR_Y2 };
nsSVGLength2 mLengthAttributes[4];
static LengthInfo sLengthInfo[4];
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGLineElement_h

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

@ -1,171 +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 "nsIDOMSVGLineElement.h"
#include "nsSVGLength2.h"
#include "nsGkAtoms.h"
#include "gfxContext.h"
using namespace mozilla;
typedef nsSVGPathGeometryElement nsSVGLineElementBase;
class nsSVGLineElement : public nsSVGLineElementBase,
public nsIDOMSVGLineElement
{
protected:
friend nsresult NS_NewSVGLineElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
nsSVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo);
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGLINEELEMENT
// xxx I wish we could use virtual inheritance
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLineElementBase::)
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
// nsSVGPathGeometryElement methods:
virtual bool IsMarkable() { return true; }
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
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 { X1, Y1, X2, Y2 };
nsSVGLength2 mLengthAttributes[4];
static LengthInfo sLengthInfo[4];
};
nsSVGElement::LengthInfo nsSVGLineElement::sLengthInfo[4] =
{
{ &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
};
NS_IMPL_NS_NEW_SVG_ELEMENT(Line)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
DOMCI_NODE_DATA(SVGLineElement, nsSVGLineElement)
NS_INTERFACE_TABLE_HEAD(nsSVGLineElement)
NS_NODE_INTERFACE_TABLE4(nsSVGLineElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGLineElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGLineElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGLineElementBase)
//----------------------------------------------------------------------
// Implementation
nsSVGLineElement::nsSVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGLineElementBase(aNodeInfo)
{
}
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGLineElement)
//----------------------------------------------------------------------
// nsIDOMSVGLineElement methods
/* readonly attribute nsIDOMSVGAnimatedLength cx; */
NS_IMETHODIMP nsSVGLineElement::GetX1(nsIDOMSVGAnimatedLength * *aX1)
{
return mLengthAttributes[X1].ToDOMAnimatedLength(aX1, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength cy; */
NS_IMETHODIMP nsSVGLineElement::GetY1(nsIDOMSVGAnimatedLength * *aY1)
{
return mLengthAttributes[Y1].ToDOMAnimatedLength(aY1, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength rx; */
NS_IMETHODIMP nsSVGLineElement::GetX2(nsIDOMSVGAnimatedLength * *aX2)
{
return mLengthAttributes[X2].ToDOMAnimatedLength(aX2, this);
}
/* readonly attribute nsIDOMSVGAnimatedLength ry; */
NS_IMETHODIMP nsSVGLineElement::GetY2(nsIDOMSVGAnimatedLength * *aY2)
{
return mLengthAttributes[Y2].ToDOMAnimatedLength(aY2, this);
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
nsSVGLineElement::IsAttributeMapped(const nsIAtom* name) const
{
static const MappedAttributeEntry* const map[] = {
sMarkersMap
};
return FindAttributeDependence(name, map) ||
nsSVGLineElementBase::IsAttributeMapped(name);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::LengthAttributesInfo
nsSVGLineElement::GetLengthInfo()
{
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
ArrayLength(sLengthInfo));
}
//----------------------------------------------------------------------
// nsSVGPathGeometryElement methods
void
nsSVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
float angle = atan2(y2 - y1, x2 - x1);
aMarks->AppendElement(nsSVGMark(x1, y1, angle));
aMarks->AppendElement(nsSVGMark(x2, y2, angle));
}
void
nsSVGLineElement::ConstructPath(gfxContext *aCtx)
{
float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
aCtx->MoveTo(gfxPoint(x1, y1));
aCtx->LineTo(gfxPoint(x2, y2));
}

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

@ -0,0 +1,25 @@
/* -*- 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 SVGLineElement : SVGGraphicsElement {
[Constant]
readonly attribute SVGAnimatedLength x1;
[Constant]
readonly attribute SVGAnimatedLength y1;
[Constant]
readonly attribute SVGAnimatedLength x2;
[Constant]
readonly attribute SVGAnimatedLength y2;
};

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

@ -114,6 +114,7 @@ webidl_files = \
SVGGraphicsElement.webidl \
SVGImageElement.webidl \
SVGLengthList.webidl \
SVGLineElement.webidl \
SVGLocatableElement.webidl \
SVGMatrix.webidl \
SVGMetadataElement.webidl \