Bug 825732: Convert SVGTextElement to WebIDL r=bz, longsonr

--HG--
rename : content/svg/content/src/nsSVGTextElement.cpp => content/svg/content/src/SVGTextElement.cpp
rename : content/svg/content/src/nsSVGTextElement.cpp => content/svg/content/src/SVGTextElement.h
This commit is contained in:
David Zbarsky 2013-01-06 09:14:43 -05:00
parent 2ff60e5bf0
commit 8408a43708
7 changed files with 143 additions and 371 deletions

View File

@ -67,7 +67,6 @@ CPPSRCS = \
nsSVGSVGElement.cpp \
nsSVGSymbolElement.cpp \
nsSVGTSpanElement.cpp \
nsSVGTextElement.cpp \
nsSVGUnknownElement.cpp \
nsSVGUseElement.cpp \
nsSVGViewBox.cpp \
@ -128,6 +127,7 @@ CPPSRCS = \
SVGStyleElement.cpp \
SVGSwitchElement.cpp \
SVGTextContentElement.cpp \
SVGTextElement.cpp \
SVGTextPathElement.cpp \
SVGTextPositioningElement.cpp \
SVGTitleElement.cpp \
@ -181,6 +181,7 @@ EXPORTS_mozilla/dom = \
SVGStyleElement.h \
SVGSwitchElement.h \
SVGTextContentElement.h \
SVGTextElement.h \
SVGTextPathElement.h \
SVGTextPositioningElement.h \
SVGTitleElement.h \

View File

@ -0,0 +1,68 @@
/* -*- 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/SVGTextElement.h"
#include "mozilla/dom/SVGTextElementBinding.h"
DOMCI_NODE_DATA(SVGTextElement, mozilla::dom::SVGTextElement)
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Text)
namespace mozilla {
namespace dom {
JSObject*
SVGTextElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
{
return SVGTextElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(SVGTextElement,SVGTextElementBase)
NS_IMPL_RELEASE_INHERITED(SVGTextElement,SVGTextElementBase)
NS_INTERFACE_TABLE_HEAD(SVGTextElement)
NS_NODE_INTERFACE_TABLE6(SVGTextElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement, nsIDOMSVGTextElement,
nsIDOMSVGTextPositioningElement,
nsIDOMSVGTextContentElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGTextElement)
NS_INTERFACE_MAP_END_INHERITING(SVGTextElementBase)
//----------------------------------------------------------------------
// Implementation
SVGTextElement::SVGTextElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: SVGTextElementBase(aNodeInfo)
{
SetIsDOMBinding();
}
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextElement)
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGTextElement::IsAttributeMapped(const nsIAtom* name) const
{
static const MappedAttributeEntry* const map[] = {
sTextContentElementsMap,
sFontSpecificationMap
};
return FindAttributeDependence(name, map) ||
SVGTextElementBase::IsAttributeMapped(name);
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,57 @@
/* -*- 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_SVGTextElement_h
#define mozilla_dom_SVGTextElement_h
#include "mozilla/dom/SVGTextPositioningElement.h"
#include "nsIDOMSVGTextElement.h"
nsresult NS_NewSVGTextElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
namespace mozilla {
namespace dom {
typedef SVGTextPositioningElement SVGTextElementBase;
class SVGTextElement MOZ_FINAL : public SVGTextElementBase,
public nsIDOMSVGTextElement // nsIDOMSVGTextPositioningElement
{
protected:
SVGTextElement(already_AddRefed<nsINodeInfo> aNodeInfo);
virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE;
friend nsresult (::NS_NewSVGTextElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo));
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGTEXTELEMENT
// xxx If xpcom allowed virtual inheritance we wouldn't need to
// forward here :-(
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
NS_FORWARD_NSIDOMSVGELEMENT(SVGTextElementBase::)
NS_FORWARD_NSIDOMSVGTEXTCONTENTELEMENT(SVGTextElementBase::)
NS_FORWARD_NSIDOMSVGTEXTPOSITIONINGELEMENT(SVGTextElementBase::)
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGTextElement_h

View File

@ -21,11 +21,6 @@ class DOMSVGAnimatedNumberList;
namespace dom {
typedef SVGTextContentElement SVGTextPositioningElementBase;
/**
* Note that nsSVGTextElement does not inherit this class - it reimplements it
* instead (see its documenting comment). The upshot is that any changes to
* this class also need to be made in nsSVGTextElement.
*/
class SVGTextPositioningElement : public SVGTextPositioningElementBase
{
public:

View File

@ -1,365 +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 "SVGGraphicsElement.h"
#include "nsGkAtoms.h"
#include "nsIDOMSVGTextElement.h"
#include "nsCOMPtr.h"
#include "nsSVGSVGElement.h"
#include "SVGTextPositioningElement.h"
#include "nsError.h"
#include "SVGAnimatedLengthList.h"
#include "DOMSVGAnimatedLengthList.h"
#include "SVGLengthList.h"
#include "SVGNumberList.h"
#include "SVGAnimatedNumberList.h"
#include "DOMSVGAnimatedNumberList.h"
#include "DOMSVGPoint.h"
#include "nsSVGTextContainerFrame.h"
using namespace mozilla;
typedef dom::SVGGraphicsElement nsSVGTextElementBase;
/**
* This class does not inherit nsSVGTextPositioningElement - it reimplements it
* instead.
*
* Ideally this class would inherit nsSVGTextPositioningElement in addition to
* nsSVGGraphicElement, but we don't want two instances of nsSVGStylableElement
* and all the classes it inherits. Instead we choose to inherit one of the
* classes (nsSVGGraphicElement) and reimplement the missing pieces from the
* other (nsSVGTextPositioningElement (and thus nsSVGTextContentElement)). Care
* must be taken when making changes to the reimplemented pieces to keep
* nsSVGTextPositioningElement in sync (and vice versa).
*/
class nsSVGTextElement : public nsSVGTextElementBase,
public nsIDOMSVGTextElement // nsIDOMSVGTextPositioningElement
{
protected:
friend nsresult NS_NewSVGTextElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
nsSVGTextElement(already_AddRefed<nsINodeInfo> aNodeInfo);
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGTEXTELEMENT
NS_DECL_NSIDOMSVGTEXTPOSITIONINGELEMENT
NS_DECL_NSIDOMSVGTEXTCONTENTELEMENT
// xxx If xpcom allowed virtual inheritance we wouldn't need to
// forward here :-(
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTextElementBase::)
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
protected:
nsSVGTextContainerFrame* GetTextContainerFrame() {
return do_QueryFrame(GetPrimaryFrame(Flush_Layout));
}
virtual LengthListAttributesInfo GetLengthListInfo();
virtual NumberListAttributesInfo GetNumberListInfo();
// nsIDOMSVGTextPositioning properties:
enum { X, Y, DX, DY };
SVGAnimatedLengthList mLengthListAttributes[4];
static LengthListInfo sLengthListInfo[4];
enum { ROTATE };
SVGAnimatedNumberList mNumberListAttributes[1];
static NumberListInfo sNumberListInfo[1];
};
NS_IMPL_NS_NEW_SVG_ELEMENT(Text)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGTextElement,nsSVGTextElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGTextElement,nsSVGTextElementBase)
DOMCI_NODE_DATA(SVGTextElement, nsSVGTextElement)
NS_INTERFACE_TABLE_HEAD(nsSVGTextElement)
NS_NODE_INTERFACE_TABLE6(nsSVGTextElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement, nsIDOMSVGTextElement,
nsIDOMSVGTextPositioningElement,
nsIDOMSVGTextContentElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGTextElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGTextElementBase)
//----------------------------------------------------------------------
// Implementation
nsSVGTextElement::nsSVGTextElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGTextElementBase(aNodeInfo)
{
}
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGTextElement)
//----------------------------------------------------------------------
// nsIDOMSVGTextElement methods
// - no methods -
//----------------------------------------------------------------------
// nsIDOMSVGTextPositioningElement methods
/* readonly attribute DOMSVGAnimatedLengthList x; */
NS_IMETHODIMP
nsSVGTextElement::GetX(nsISupports * *aX)
{
*aX = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[X],
this, X, SVGContentUtils::X).get();
return NS_OK;
}
/* readonly attribute DOMSVGAnimatedLengthList y; */
NS_IMETHODIMP
nsSVGTextElement::GetY(nsISupports * *aY)
{
*aY = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[Y],
this, Y, SVGContentUtils::Y).get();
return NS_OK;
}
/* readonly attribute DOMSVGAnimatedLengthList dx; */
NS_IMETHODIMP
nsSVGTextElement::GetDx(nsISupports * *aDx)
{
*aDx = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DX],
this, DX, SVGContentUtils::X).get();
return NS_OK;
}
/* readonly attribute DOMSVGAnimatedLengthList dy; */
NS_IMETHODIMP
nsSVGTextElement::GetDy(nsISupports * *aDy)
{
*aDy = DOMSVGAnimatedLengthList::GetDOMWrapper(&mLengthListAttributes[DY],
this, DY, SVGContentUtils::Y).get();
return NS_OK;
}
/* readonly attribute DOMSVGAnimatedNumberList rotate; */
NS_IMETHODIMP
nsSVGTextElement::GetRotate(nsISupports * *aRotate)
{
*aRotate = DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[ROTATE],
this, ROTATE).get();
return NS_OK;
}
//----------------------------------------------------------------------
// nsIDOMSVGTextContentElement methods
/* readonly attribute nsIDOMSVGAnimatedLength textLength; */
NS_IMETHODIMP
nsSVGTextElement::GetTextLength(nsIDOMSVGAnimatedLength * *aTextLength)
{
NS_NOTYETIMPLEMENTED("nsSVGTextElement::GetTextLength");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMSVGAnimatedEnumeration lengthAdjust; */
NS_IMETHODIMP
nsSVGTextElement::GetLengthAdjust(nsIDOMSVGAnimatedEnumeration * *aLengthAdjust)
{
NS_NOTYETIMPLEMENTED("nsSVGTextElement::GetLengthAdjust");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* long getNumberOfChars (); */
NS_IMETHODIMP
nsSVGTextElement::GetNumberOfChars(int32_t *_retval)
{
*_retval = 0;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (metrics)
*_retval = metrics->GetNumberOfChars();
return NS_OK;
}
/* float getComputedTextLength (); */
NS_IMETHODIMP
nsSVGTextElement::GetComputedTextLength(float *_retval)
{
*_retval = 0.0;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (metrics)
*_retval = metrics->GetComputedTextLength();
return NS_OK;
}
/* float getSubStringLength (in unsigned long charnum, in unsigned long nchars); */
NS_IMETHODIMP
nsSVGTextElement::GetSubStringLength(uint32_t charnum, uint32_t nchars, float *_retval)
{
*_retval = 0.0f;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (!metrics)
return NS_OK;
uint32_t charcount = metrics->GetNumberOfChars();
if (charcount <= charnum || nchars > charcount - charnum)
return NS_ERROR_DOM_INDEX_SIZE_ERR;
if (nchars == 0)
return NS_OK;
*_retval = metrics->GetSubStringLength(charnum, nchars);
return NS_OK;
}
/* DOMSVGPoint getStartPositionOfChar (in unsigned long charnum); */
NS_IMETHODIMP
nsSVGTextElement::GetStartPositionOfChar(uint32_t charnum, nsISupports **_retval)
{
*_retval = nullptr;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (!metrics) return NS_ERROR_FAILURE;
return metrics->GetStartPositionOfChar(charnum, _retval);
}
/* DOMSVGPoint getEndPositionOfChar (in unsigned long charnum); */
NS_IMETHODIMP
nsSVGTextElement::GetEndPositionOfChar(uint32_t charnum, nsISupports **_retval)
{
*_retval = nullptr;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (!metrics) return NS_ERROR_FAILURE;
return metrics->GetEndPositionOfChar(charnum, _retval);
}
/* nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
NS_IMETHODIMP
nsSVGTextElement::GetExtentOfChar(uint32_t charnum, nsIDOMSVGRect **_retval)
{
*_retval = nullptr;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (!metrics) return NS_ERROR_FAILURE;
return metrics->GetExtentOfChar(charnum, _retval);
}
/* float getRotationOfChar (in unsigned long charnum); */
NS_IMETHODIMP
nsSVGTextElement::GetRotationOfChar(uint32_t charnum, float *_retval)
{
*_retval = 0.0;
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (!metrics) return NS_ERROR_FAILURE;
return metrics->GetRotationOfChar(charnum, _retval);
}
/* long getCharNumAtPosition (in DOMSVGPoint point); */
NS_IMETHODIMP
nsSVGTextElement::GetCharNumAtPosition(nsISupports *point, int32_t *_retval)
{
*_retval = -1;
nsCOMPtr<DOMSVGPoint> domPoint = do_QueryInterface(point);
if (!domPoint) {
return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
}
nsSVGTextContainerFrame* metrics = GetTextContainerFrame();
if (metrics)
*_retval = metrics->GetCharNumAtPosition(domPoint);
return NS_OK;
}
/* void selectSubString (in unsigned long charnum, in unsigned long nchars); */
NS_IMETHODIMP
nsSVGTextElement::SelectSubString(uint32_t charnum, uint32_t nchars)
{
NS_NOTYETIMPLEMENTED("nsSVGTextElement::SelectSubString");
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
nsSVGTextElement::IsAttributeMapped(const nsIAtom* name) const
{
static const MappedAttributeEntry* const map[] = {
sTextContentElementsMap,
sFontSpecificationMap
};
return FindAttributeDependence(name, map) ||
nsSVGTextElementBase::IsAttributeMapped(name);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::LengthListInfo nsSVGTextElement::sLengthListInfo[4] =
{
{ &nsGkAtoms::x, SVGContentUtils::X, false },
{ &nsGkAtoms::y, SVGContentUtils::Y, false },
{ &nsGkAtoms::dx, SVGContentUtils::X, true },
{ &nsGkAtoms::dy, SVGContentUtils::Y, true }
};
nsSVGElement::LengthListAttributesInfo
nsSVGTextElement::GetLengthListInfo()
{
return LengthListAttributesInfo(mLengthListAttributes, sLengthListInfo,
ArrayLength(sLengthListInfo));
}
nsSVGElement::NumberListInfo nsSVGTextElement::sNumberListInfo[1] =
{
{ &nsGkAtoms::rotate }
};
nsSVGElement::NumberListAttributesInfo
nsSVGTextElement::GetNumberListInfo()
{
return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
ArrayLength(sNumberListInfo));
}

View File

@ -0,0 +1,15 @@
/* -*- 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 SVGTextElement : SVGTextPositioningElement {
};

View File

@ -139,6 +139,7 @@ webidl_files = \
SVGSwitchElement.webidl \
SVGTests.webidl \
SVGTextContentElement.webidl \
SVGTextElement.webidl \
SVGTextPathElement.webidl \
SVGTextPositioningElement.webidl \
SVGTitleElement.webidl \