From cd990802cffb1a5f16456fcf116373c47d4c1f90 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Thu, 10 Jan 2013 00:30:13 -0500 Subject: [PATCH] Bug 825147: Convert SVGAElement to WebIDL r=bz --HG-- rename : content/svg/content/src/nsSVGAElement.cpp => content/svg/content/src/SVGAElement.cpp rename : content/svg/content/src/nsSVGAElement.h => content/svg/content/src/SVGAElement.h --- content/svg/content/src/Makefile.in | 3 +- .../{nsSVGAElement.cpp => SVGAElement.cpp} | 130 +++++++++++------- .../src/{nsSVGAElement.h => SVGAElement.h} | 43 ++++-- dom/bindings/Bindings.conf | 4 + dom/webidl/SVGAElement.webidl | 20 +++ dom/webidl/WebIDL.mk | 1 + layout/svg/nsSVGAFrame.cpp | 4 +- 7 files changed, 138 insertions(+), 67 deletions(-) rename content/svg/content/src/{nsSVGAElement.cpp => SVGAElement.cpp} (70%) rename content/svg/content/src/{nsSVGAElement.h => SVGAElement.h} (68%) create mode 100644 dom/webidl/SVGAElement.webidl diff --git a/content/svg/content/src/Makefile.in b/content/svg/content/src/Makefile.in index 115a303fb2d..4507c8ff441 100644 --- a/content/svg/content/src/Makefile.in +++ b/content/svg/content/src/Makefile.in @@ -36,7 +36,6 @@ CPPSRCS = \ DOMSVGTransformList.cpp \ nsDOMSVGZoomEvent.cpp \ nsDOMSVGEvent.cpp \ - nsSVGAElement.cpp \ nsSVGAngle.cpp \ nsSVGBoolean.cpp \ nsSVGClass.cpp \ @@ -67,6 +66,7 @@ CPPSRCS = \ nsSVGUnknownElement.cpp \ nsSVGUseElement.cpp \ nsSVGViewBox.cpp \ + SVGAElement.cpp \ SVGAltGlyphElement.cpp \ SVGAngle.cpp \ SVGAnimatedAngle.cpp \ @@ -153,6 +153,7 @@ EXPORTS = \ EXPORTS_NAMESPACES = mozilla/dom EXPORTS_mozilla/dom = \ + SVGAElement.h \ SVGAltGlyphElement.h \ SVGAngle.h \ SVGAnimatedAngle.h \ diff --git a/content/svg/content/src/nsSVGAElement.cpp b/content/svg/content/src/SVGAElement.cpp similarity index 70% rename from content/svg/content/src/nsSVGAElement.cpp rename to content/svg/content/src/SVGAElement.cpp index 5b9c72681ba..214124f0bf3 100644 --- a/content/svg/content/src/nsSVGAElement.cpp +++ b/content/svg/content/src/SVGAElement.cpp @@ -5,7 +5,8 @@ #include "mozilla/Util.h" -#include "nsSVGAElement.h" +#include "mozilla/dom/SVGAElement.h" +#include "mozilla/dom/SVGAElementBinding.h" #include "nsIDOMSVGAElement.h" #include "nsIDOMSVGURIReference.h" #include "nsILink.h" @@ -14,28 +15,34 @@ #include "nsGkAtoms.h" #include "nsContentUtils.h" -using namespace mozilla; -using namespace mozilla::dom; +DOMCI_NODE_DATA(SVGAElement, mozilla::dom::SVGAElement) -nsSVGElement::StringInfo nsSVGAElement::sStringInfo[2] = +NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(A) + +namespace mozilla { +namespace dom { + +JSObject* +SVGAElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap) +{ + return SVGAElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + +nsSVGElement::StringInfo SVGAElement::sStringInfo[2] = { { &nsGkAtoms::href, kNameSpaceID_XLink, true }, { &nsGkAtoms::target, kNameSpaceID_None, true } }; -NS_IMPL_NS_NEW_SVG_ELEMENT(A) - //---------------------------------------------------------------------- // nsISupports methods -NS_IMPL_ADDREF_INHERITED(nsSVGAElement, nsSVGAElementBase) -NS_IMPL_RELEASE_INHERITED(nsSVGAElement, nsSVGAElementBase) +NS_IMPL_ADDREF_INHERITED(SVGAElement, SVGAElementBase) +NS_IMPL_RELEASE_INHERITED(SVGAElement, SVGAElementBase) -DOMCI_NODE_DATA(SVGAElement, nsSVGAElement) - -NS_INTERFACE_TABLE_HEAD(nsSVGAElement) - NS_NODE_INTERFACE_TABLE7(nsSVGAElement, +NS_INTERFACE_TABLE_HEAD(SVGAElement) + NS_NODE_INTERFACE_TABLE7(SVGAElement, nsIDOMNode, nsIDOMElement, nsIDOMSVGElement, @@ -44,16 +51,17 @@ NS_INTERFACE_TABLE_HEAD(nsSVGAElement) nsILink, Link) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAElement) -NS_INTERFACE_MAP_END_INHERITING(nsSVGAElementBase) +NS_INTERFACE_MAP_END_INHERITING(SVGAElementBase) //---------------------------------------------------------------------- // Implementation -nsSVGAElement::nsSVGAElement(already_AddRefed aNodeInfo) - : nsSVGAElementBase(aNodeInfo), +SVGAElement::SVGAElement(already_AddRefed aNodeInfo) + : SVGAElementBase(aNodeInfo), Link(this) { + SetIsDOMBinding(); } //---------------------------------------------------------------------- @@ -61,18 +69,27 @@ nsSVGAElement::nsSVGAElement(already_AddRefed aNodeInfo) /* readonly attribute nsIDOMSVGAnimatedString href; */ NS_IMETHODIMP -nsSVGAElement::GetHref(nsIDOMSVGAnimatedString * *aHref) +SVGAElement::GetHref(nsIDOMSVGAnimatedString * *aHref) { - return mStringAttributes[HREF].ToDOMAnimatedString(aHref, this); + *aHref = Href().get(); + return NS_OK; } -NS_IMPL_STRING_ATTR(nsSVGAElement, Download, download) +already_AddRefed +SVGAElement::Href() +{ + nsCOMPtr href; + mStringAttributes[HREF].ToDOMAnimatedString(getter_AddRefs(href), this); + return href.forget(); +} + +NS_IMPL_STRING_ATTR(SVGAElement, Download, download) //---------------------------------------------------------------------- // nsINode methods nsresult -nsSVGAElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) +SVGAElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) { nsresult rv = Element::PreHandleEvent(aVisitor); NS_ENSURE_SUCCESS(rv, rv); @@ -81,12 +98,12 @@ nsSVGAElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) } nsresult -nsSVGAElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) +SVGAElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) { return PostHandleEventForLinks(aVisitor); } -NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGAElement) +NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGAElement) //---------------------------------------------------------------------- @@ -94,27 +111,37 @@ NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGAElement) /* readonly attribute nsIDOMSVGAnimatedString target; */ NS_IMETHODIMP -nsSVGAElement::GetTarget(nsIDOMSVGAnimatedString * *aTarget) +SVGAElement::GetTarget(nsIDOMSVGAnimatedString * *aTarget) { - return mStringAttributes[TARGET].ToDOMAnimatedString(aTarget, this); + *aTarget = Target().get(); + return NS_OK; } +already_AddRefed +SVGAElement::Target() +{ + nsCOMPtr target; + mStringAttributes[TARGET].ToDOMAnimatedString(getter_AddRefs(target), this); + return target.forget(); +} + + //---------------------------------------------------------------------- // nsIContent methods nsresult -nsSVGAElement::BindToTree(nsIDocument *aDocument, nsIContent *aParent, - nsIContent *aBindingParent, - bool aCompileEventHandlers) +SVGAElement::BindToTree(nsIDocument *aDocument, nsIContent *aParent, + nsIContent *aBindingParent, + bool aCompileEventHandlers) { Link::ResetLinkState(false, Link::ElementHasHref()); - nsresult rv = nsSVGAElementBase::BindToTree(aDocument, aParent, - aBindingParent, - aCompileEventHandlers); + nsresult rv = SVGAElementBase::BindToTree(aDocument, aParent, + aBindingParent, + aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); - + if (aDocument) { aDocument->RegisterPendingLinkUpdate(this); } @@ -123,28 +150,28 @@ nsSVGAElement::BindToTree(nsIDocument *aDocument, nsIContent *aParent, } void -nsSVGAElement::UnbindFromTree(bool aDeep, bool aNullParent) +SVGAElement::UnbindFromTree(bool aDeep, bool aNullParent) { // If this link is ever reinserted into a document, it might // be under a different xml:base, so forget the cached state now. Link::ResetLinkState(false, Link::ElementHasHref()); - + nsIDocument* doc = GetCurrentDoc(); if (doc) { doc->UnregisterPendingLinkUpdate(this); } - nsSVGAElementBase::UnbindFromTree(aDeep, aNullParent); + SVGAElementBase::UnbindFromTree(aDeep, aNullParent); } nsLinkState -nsSVGAElement::GetLinkState() const +SVGAElement::GetLinkState() const { return Link::GetLinkState(); } already_AddRefed -nsSVGAElement::GetHrefURI() const +SVGAElement::GetHrefURI() const { nsCOMPtr hrefURI; return IsLink(getter_AddRefs(hrefURI)) ? hrefURI.forget() : nullptr; @@ -152,7 +179,7 @@ nsSVGAElement::GetHrefURI() const NS_IMETHODIMP_(bool) -nsSVGAElement::IsAttributeMapped(const nsIAtom* name) const +SVGAElement::IsAttributeMapped(const nsIAtom* name) const { static const MappedAttributeEntry* const map[] = { sFEFloodMap, @@ -166,11 +193,11 @@ nsSVGAElement::IsAttributeMapped(const nsIAtom* name) const }; return FindAttributeDependence(name, map) || - nsSVGAElementBase::IsAttributeMapped(name); + SVGAElementBase::IsAttributeMapped(name); } bool -nsSVGAElement::IsFocusable(int32_t *aTabIndex, bool aWithMouse) +SVGAElement::IsFocusable(int32_t *aTabIndex, bool aWithMouse) { nsCOMPtr uri; if (IsLink(getter_AddRefs(uri))) { @@ -188,7 +215,7 @@ nsSVGAElement::IsFocusable(int32_t *aTabIndex, bool aWithMouse) } bool -nsSVGAElement::IsLink(nsIURI** aURI) const +SVGAElement::IsLink(nsIURI** aURI) const { // To be a clickable XLink for styling and interaction purposes, we require: // @@ -237,7 +264,7 @@ nsSVGAElement::IsLink(nsIURI** aURI) const } void -nsSVGAElement::GetLinkTarget(nsAString& aTarget) +SVGAElement::GetLinkTarget(nsAString& aTarget) { mStringAttributes[TARGET].GetAnimValue(aTarget, this); if (aTarget.IsEmpty()) { @@ -261,18 +288,18 @@ nsSVGAElement::GetLinkTarget(nsAString& aTarget) } nsEventStates -nsSVGAElement::IntrinsicState() const +SVGAElement::IntrinsicState() const { - return Link::LinkState() | nsSVGAElementBase::IntrinsicState(); + return Link::LinkState() | SVGAElementBase::IntrinsicState(); } nsresult -nsSVGAElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName, - nsIAtom* aPrefix, const nsAString& aValue, - bool aNotify) +SVGAElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName, + nsIAtom* aPrefix, const nsAString& aValue, + bool aNotify) { - nsresult rv = nsSVGAElementBase::SetAttr(aNameSpaceID, aName, aPrefix, - aValue, aNotify); + nsresult rv = SVGAElementBase::SetAttr(aNameSpaceID, aName, aPrefix, + aValue, aNotify); // The ordering of the parent class's SetAttr call and Link::ResetLinkState // is important here! The attribute is not set until SetAttr returns, and @@ -287,8 +314,8 @@ nsSVGAElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName, } nsresult -nsSVGAElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr, - bool aNotify) +SVGAElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr, + bool aNotify) { nsresult rv = nsSVGElement::UnsetAttr(aNameSpaceID, aAttr, aNotify); @@ -308,8 +335,11 @@ nsSVGAElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr, // nsSVGElement methods nsSVGElement::StringAttributesInfo -nsSVGAElement::GetStringInfo() +SVGAElement::GetStringInfo() { return StringAttributesInfo(mStringAttributes, sStringInfo, ArrayLength(sStringInfo)); } + +} // namespace dom +} // namespace mozilla diff --git a/content/svg/content/src/nsSVGAElement.h b/content/svg/content/src/SVGAElement.h similarity index 68% rename from content/svg/content/src/nsSVGAElement.h rename to content/svg/content/src/SVGAElement.h index 05a4eeb9824..b8b3ffd6af1 100644 --- a/content/svg/content/src/nsSVGAElement.h +++ b/content/svg/content/src/SVGAElement.h @@ -3,28 +3,35 @@ * 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 NS_SVGAELEMENT_H_ -#define NS_SVGAELEMENT_H_ +#ifndef mozilla_dom_SVGAElement_h +#define mozilla_dom_SVGAElement_h #include "Link.h" #include "nsIDOMSVGAElement.h" #include "nsIDOMSVGURIReference.h" #include "nsILink.h" #include "nsSVGString.h" -#include "SVGGraphicsElement.h" +#include "mozilla/dom/SVGGraphicsElement.h" -typedef mozilla::dom::SVGGraphicsElement nsSVGAElementBase; +nsresult NS_NewSVGAElement(nsIContent **aResult, + already_AddRefed aNodeInfo); -class nsSVGAElement : public nsSVGAElementBase, - public nsIDOMSVGAElement, - public nsIDOMSVGURIReference, - public nsILink, - public mozilla::dom::Link +namespace mozilla { +namespace dom { + +typedef SVGGraphicsElement SVGAElementBase; + +class SVGAElement MOZ_FINAL : public SVGAElementBase, + public nsIDOMSVGAElement, + public nsIDOMSVGURIReference, + public nsILink, + public Link { protected: - friend nsresult NS_NewSVGAElement(nsIContent **aResult, - already_AddRefed aNodeInfo); - nsSVGAElement(already_AddRefed aNodeInfo); + SVGAElement(already_AddRefed aNodeInfo); + friend nsresult (::NS_NewSVGAElement(nsIContent **aResult, + already_AddRefed aNodeInfo)); + virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap) MOZ_OVERRIDE; public: // interfaces: @@ -36,7 +43,7 @@ public: // XXX: I wish we could use virtual inheritance NS_FORWARD_NSIDOMNODE_TO_NSINODE NS_FORWARD_NSIDOMELEMENT_TO_GENERIC - NS_FORWARD_NSIDOMSVGELEMENT(nsSVGAElementBase::) + NS_FORWARD_NSIDOMSVGELEMENT(SVGAElementBase::) // nsINode interface methods virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor); @@ -74,6 +81,11 @@ public: virtual nsXPCClassInfo* GetClassInfo(); virtual nsIDOMNode* AsDOMNode() { return this; } + + // WebIDL + already_AddRefed Href(); + already_AddRefed Target(); + protected: virtual StringAttributesInfo GetStringInfo(); @@ -83,4 +95,7 @@ protected: static StringInfo sStringInfo[2]; }; -#endif // NS_SVGAELEMENT_H_ +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_SVGAElement_h diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 8e819b0e68b..7017b3418bc 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -589,6 +589,10 @@ DOMInterfaces = { 'prefable': True, }, +'SVGAElement': { + 'hasInstanceInterface': 'nsIDOMSVGAElement', +}, + 'SVGAnimatedLengthList': { 'nativeType': 'mozilla::DOMSVGAnimatedLengthList', 'headerFile': 'DOMSVGAnimatedLengthList.h' diff --git a/dom/webidl/SVGAElement.webidl b/dom/webidl/SVGAElement.webidl new file mode 100644 index 00000000000..1f3d793d8a0 --- /dev/null +++ b/dom/webidl/SVGAElement.webidl @@ -0,0 +1,20 @@ +/* -*- 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 SVGAnimatedString; + +interface SVGAElement : SVGGraphicsElement { + readonly attribute SVGAnimatedString target; +}; + +SVGAElement implements SVGURIReference; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 4b4cbc141a5..ee8bdbdff3d 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -98,6 +98,7 @@ webidl_files = \ Rect.webidl \ RGBColor.webidl \ Screen.webidl \ + SVGAElement.webidl \ SVGAltGlyphElement.webidl \ SVGAngle.webidl \ SVGAnimatedAngle.webidl \ diff --git a/layout/svg/nsSVGAFrame.cpp b/layout/svg/nsSVGAFrame.cpp index 6ff9c54973b..2e66dfdb3ba 100644 --- a/layout/svg/nsSVGAFrame.cpp +++ b/layout/svg/nsSVGAFrame.cpp @@ -5,7 +5,7 @@ // Keep in (case-insensitive) order: #include "gfxMatrix.h" -#include "nsSVGAElement.h" +#include "mozilla/dom/SVGAElement.h" #include "nsSVGIntegrationUtils.h" #include "nsSVGTSpanFrame.h" #include "nsSVGUtils.h" @@ -153,7 +153,7 @@ nsSVGAFrame::GetCanvasTM(uint32_t aFor) NS_ASSERTION(mParent, "null parent"); nsSVGContainerFrame *parent = static_cast(mParent); - nsSVGAElement *content = static_cast(mContent); + dom::SVGAElement *content = static_cast(mContent); gfxMatrix tm = content->PrependLocalTransformsTo(parent->GetCanvasTM(aFor));