Bug 824327: Convert SVGScriptElement to WebIDL r=bz

--HG--
rename : content/svg/content/src/nsSVGScriptElement.cpp => content/svg/content/src/SVGScriptElement.cpp
rename : content/svg/content/src/nsSVGScriptElement.cpp => content/svg/content/src/SVGScriptElement.h
This commit is contained in:
David Zbarsky 2013-01-05 04:41:28 -05:00
Родитель 4bbe6e8a41
Коммит cbdc494f2c
7 изменённых файлов: 368 добавлений и 280 удалений

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

@ -72,7 +72,6 @@ CPPSRCS = \
nsSVGPolyElement.cpp \
nsSVGPolygonElement.cpp \
nsSVGPolylineElement.cpp \
nsSVGScriptElement.cpp \
nsSVGString.cpp \
nsSVGRect.cpp \
nsSVGRectElement.cpp \
@ -131,6 +130,7 @@ CPPSRCS = \
SVGOrientSMILType.cpp \
SVGPathSegListSMILType.cpp \
SVGPointListSMILType.cpp \
SVGScriptElement.cpp \
SVGStopElement.cpp \
SVGStyleElement.cpp \
SVGTransformListSMILType.cpp \
@ -157,6 +157,7 @@ EXPORTS_mozilla/dom = \
SVGDescElement.h \
SVGMetadataElement.h \
SVGMPathElement.h \
SVGScriptElement.h \
SVGStopElement.h \
SVGStyleElement.h \
SVGTitleElement.h \

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

@ -0,0 +1,229 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=78: */
/* 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 "nsGkAtoms.h"
#include "nsNetUtil.h"
#include "nsContentUtils.h"
#include "mozilla/dom/SVGScriptElement.h"
#include "mozilla/dom/SVGScriptElementBinding.h"
DOMCI_NODE_DATA(SVGScriptElement, mozilla::dom::SVGScriptElement)
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT_CHECK_PARSER(Script)
namespace mozilla {
namespace dom {
JSObject*
SVGScriptElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
{
return SVGScriptElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
nsSVGElement::StringInfo SVGScriptElement::sStringInfo[1] =
{
{ &nsGkAtoms::href, kNameSpaceID_XLink, false }
};
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(SVGScriptElement,SVGScriptElementBase)
NS_IMPL_RELEASE_INHERITED(SVGScriptElement,SVGScriptElementBase)
NS_INTERFACE_TABLE_HEAD(SVGScriptElement)
NS_NODE_INTERFACE_TABLE8(SVGScriptElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement, nsIDOMSVGScriptElement,
nsIDOMSVGURIReference, nsIScriptLoaderObserver,
nsIScriptElement, nsIMutationObserver)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGScriptElement)
NS_INTERFACE_MAP_END_INHERITING(SVGScriptElementBase)
//----------------------------------------------------------------------
// Implementation
SVGScriptElement::SVGScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser)
: SVGScriptElementBase(aNodeInfo)
, nsScriptElement(aFromParser)
{
SetIsDOMBinding();
AddMutationObserver(this);
}
//----------------------------------------------------------------------
// nsIDOMNode methods
nsresult
SVGScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
{
*aResult = nullptr;
nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
SVGScriptElement* it = new SVGScriptElement(ni.forget(), NOT_FROM_PARSER);
nsCOMPtr<nsINode> kungFuDeathGrip = it;
nsresult rv1 = it->Init();
nsresult rv2 = const_cast<SVGScriptElement*>(this)->CopyInnerTo(it);
NS_ENSURE_SUCCESS(rv1, rv1);
NS_ENSURE_SUCCESS(rv2, rv2);
// The clone should be marked evaluated if we are.
it->mAlreadyStarted = mAlreadyStarted;
it->mLineNumber = mLineNumber;
it->mMalformed = mMalformed;
kungFuDeathGrip.swap(*aResult);
return NS_OK;
}
//----------------------------------------------------------------------
// nsIDOMSVGScriptElement methods
/* attribute DOMString type; */
NS_IMPL_STRING_ATTR(SVGScriptElement, Type, type)
/* attribute DOMString crossOrigin */
NS_IMPL_STRING_ATTR(SVGScriptElement, CrossOrigin, crossorigin)
//----------------------------------------------------------------------
// nsIDOMSVGURIReference methods
/* readonly attribute nsIDOMSVGAnimatedString href; */
NS_IMETHODIMP
SVGScriptElement::GetHref(nsIDOMSVGAnimatedString * *aHref)
{
*aHref = Href().get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedString>
SVGScriptElement::Href()
{
nsCOMPtr<nsIDOMSVGAnimatedString> href;
mStringAttributes[HREF].ToDOMAnimatedString(getter_AddRefs(href), this);
return href.forget();
}
//----------------------------------------------------------------------
// nsIScriptElement methods
void
SVGScriptElement::GetScriptType(nsAString& type)
{
GetType(type);
}
void
SVGScriptElement::GetScriptText(nsAString& text)
{
nsContentUtils::GetNodeTextContent(this, false, text);
}
void
SVGScriptElement::GetScriptCharset(nsAString& charset)
{
charset.Truncate();
}
void
SVGScriptElement::FreezeUriAsyncDefer()
{
if (mFrozen) {
return;
}
if (mStringAttributes[HREF].IsExplicitlySet()) {
// variation of this code in nsHTMLScriptElement - check if changes
// need to be transfered when modifying
nsAutoString src;
mStringAttributes[HREF].GetAnimValue(src, this);
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
NS_NewURI(getter_AddRefs(mUri), src, nullptr, baseURI);
// At this point mUri will be null for invalid URLs.
mExternal = true;
}
mFrozen = true;
}
//----------------------------------------------------------------------
// nsScriptElement methods
bool
SVGScriptElement::HasScriptContent()
{
return (mFrozen ? mExternal : mStringAttributes[HREF].IsExplicitlySet()) ||
nsContentUtils::HasNonEmptyTextContent(this);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::StringAttributesInfo
SVGScriptElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
//----------------------------------------------------------------------
// nsIContent methods
nsresult
SVGScriptElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers)
{
nsresult rv = SVGScriptElementBase::BindToTree(aDocument, aParent,
aBindingParent,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
if (aDocument) {
MaybeProcessScript();
}
return NS_OK;
}
nsresult
SVGScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) {
MaybeProcessScript();
}
return SVGScriptElementBase::AfterSetAttr(aNamespaceID, aName,
aValue, aNotify);
}
bool
SVGScriptElement::ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aNamespaceID == kNameSpaceID_None &&
aAttribute == nsGkAtoms::crossorigin) {
ParseCORSValue(aValue, aResult);
return true;
}
return SVGScriptElementBase::ParseAttribute(aNamespaceID, aAttribute,
aValue, aResult);
}
CORSMode
SVGScriptElement::GetCORSMode() const
{
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
}
} // namespace dom
} // namespace mozilla

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

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=78: */
/* 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_SVGScriptElement_h
#define mozilla_dom_SVGScriptElement_h
#include "nsSVGElement.h"
#include "nsIDOMSVGScriptElement.h"
#include "nsIDOMSVGURIReference.h"
#include "nsCOMPtr.h"
#include "nsSVGString.h"
#include "nsIDocument.h"
#include "nsScriptElement.h"
nsresult NS_NewSVGScriptElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo,
mozilla::dom::FromParser aFromParser);
namespace mozilla {
namespace dom {
typedef nsSVGElement SVGScriptElementBase;
class SVGScriptElement MOZ_FINAL : public SVGScriptElementBase,
public nsIDOMSVGScriptElement,
public nsIDOMSVGURIReference,
public nsScriptElement
{
protected:
friend nsresult (::NS_NewSVGScriptElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo,
mozilla::dom::FromParser aFromParser));
SVGScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser);
virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap) MOZ_OVERRIDE;
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGSCRIPTELEMENT
NS_DECL_NSIDOMSVGURIREFERENCE
// 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(SVGScriptElementBase::)
// nsIScriptElement
virtual void GetScriptType(nsAString& type);
virtual void GetScriptText(nsAString& text);
virtual void GetScriptCharset(nsAString& charset);
virtual void FreezeUriAsyncDefer();
virtual CORSMode GetCORSMode() const;
// nsScriptElement
virtual bool HasScriptContent();
// nsIContent specializations:
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers);
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify);
virtual bool ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
// WebIDL
already_AddRefed<nsIDOMSVGAnimatedString> Href();
protected:
virtual StringAttributesInfo GetStringInfo();
enum { HREF };
nsSVGString mStringAttributes[1];
static StringInfo sStringInfo[1];
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGScriptElement_h

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

@ -679,6 +679,26 @@ NS_NewSVG##_elementName##Element(nsIContent **aResult, \
return rv; \
}
#define NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT_CHECK_PARSER(_elementName) \
nsresult \
NS_NewSVG##_elementName##Element(nsIContent **aResult, \
already_AddRefed<nsINodeInfo> aNodeInfo, \
mozilla::dom::FromParser aFromParser) \
{ \
nsRefPtr<mozilla::dom::SVG##_elementName##Element> it = \
new mozilla::dom::SVG##_elementName##Element(aNodeInfo, aFromParser); \
\
nsresult rv = it->Init(); \
\
if (NS_FAILED(rv)) { \
return rv; \
} \
\
it.forget(aResult); \
\
return rv; \
}
// No unlinking, we'd need to null out the value pointer (the object it
// points to is held by the element) and null-check it everywhere.
#define NS_SVG_VAL_IMPL_CYCLE_COLLECTION(_val, _element) \

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

@ -1,279 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=78: */
/* 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 "nsSVGElement.h"
#include "nsGkAtoms.h"
#include "nsIDOMSVGScriptElement.h"
#include "nsIDOMSVGURIReference.h"
#include "nsCOMPtr.h"
#include "nsSVGString.h"
#include "nsIDocument.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "nsScriptElement.h"
#include "nsContentUtils.h"
using namespace mozilla;
using namespace mozilla::dom;
typedef nsSVGElement nsSVGScriptElementBase;
class nsSVGScriptElement : public nsSVGScriptElementBase,
public nsIDOMSVGScriptElement,
public nsIDOMSVGURIReference,
public nsScriptElement
{
protected:
friend nsresult NS_NewSVGScriptElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser);
nsSVGScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser);
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSVGSCRIPTELEMENT
NS_DECL_NSIDOMSVGURIREFERENCE
// 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(nsSVGScriptElementBase::)
// nsIScriptElement
virtual void GetScriptType(nsAString& type);
virtual void GetScriptText(nsAString& text);
virtual void GetScriptCharset(nsAString& charset);
virtual void FreezeUriAsyncDefer();
virtual CORSMode GetCORSMode() const;
// nsScriptElement
virtual bool HasScriptContent();
// nsIContent specializations:
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers);
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify);
virtual bool ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
protected:
virtual StringAttributesInfo GetStringInfo();
enum { HREF };
nsSVGString mStringAttributes[1];
static StringInfo sStringInfo[1];
};
nsSVGElement::StringInfo nsSVGScriptElement::sStringInfo[1] =
{
{ &nsGkAtoms::href, kNameSpaceID_XLink, false }
};
NS_IMPL_NS_NEW_SVG_ELEMENT_CHECK_PARSER(Script)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGScriptElement,nsSVGScriptElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGScriptElement,nsSVGScriptElementBase)
DOMCI_NODE_DATA(SVGScriptElement, nsSVGScriptElement)
NS_INTERFACE_TABLE_HEAD(nsSVGScriptElement)
NS_NODE_INTERFACE_TABLE8(nsSVGScriptElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement, nsIDOMSVGScriptElement,
nsIDOMSVGURIReference, nsIScriptLoaderObserver,
nsIScriptElement, nsIMutationObserver)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGScriptElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGScriptElementBase)
//----------------------------------------------------------------------
// Implementation
nsSVGScriptElement::nsSVGScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser)
: nsSVGScriptElementBase(aNodeInfo)
, nsScriptElement(aFromParser)
{
AddMutationObserver(this);
}
//----------------------------------------------------------------------
// nsIDOMNode methods
nsresult
nsSVGScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
{
*aResult = nullptr;
nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
nsSVGScriptElement* it = new nsSVGScriptElement(ni.forget(), NOT_FROM_PARSER);
nsCOMPtr<nsINode> kungFuDeathGrip = it;
nsresult rv1 = it->Init();
nsresult rv2 = const_cast<nsSVGScriptElement*>(this)->CopyInnerTo(it);
NS_ENSURE_SUCCESS(rv1, rv1);
NS_ENSURE_SUCCESS(rv2, rv2);
// The clone should be marked evaluated if we are.
it->mAlreadyStarted = mAlreadyStarted;
it->mLineNumber = mLineNumber;
it->mMalformed = mMalformed;
kungFuDeathGrip.swap(*aResult);
return NS_OK;
}
//----------------------------------------------------------------------
// nsIDOMSVGScriptElement methods
/* attribute DOMString type; */
NS_IMPL_STRING_ATTR(nsSVGScriptElement, Type, type)
/* attribute DOMString crossOrigin */
NS_IMPL_STRING_ATTR(nsSVGScriptElement, CrossOrigin, crossorigin)
//----------------------------------------------------------------------
// nsIDOMSVGURIReference methods
/* readonly attribute nsIDOMSVGAnimatedString href; */
NS_IMETHODIMP
nsSVGScriptElement::GetHref(nsIDOMSVGAnimatedString * *aHref)
{
return mStringAttributes[HREF].ToDOMAnimatedString(aHref, this);
}
//----------------------------------------------------------------------
// nsIScriptElement methods
void
nsSVGScriptElement::GetScriptType(nsAString& type)
{
GetType(type);
}
void
nsSVGScriptElement::GetScriptText(nsAString& text)
{
nsContentUtils::GetNodeTextContent(this, false, text);
}
void
nsSVGScriptElement::GetScriptCharset(nsAString& charset)
{
charset.Truncate();
}
void
nsSVGScriptElement::FreezeUriAsyncDefer()
{
if (mFrozen) {
return;
}
if (mStringAttributes[HREF].IsExplicitlySet()) {
// variation of this code in nsHTMLScriptElement - check if changes
// need to be transfered when modifying
nsAutoString src;
mStringAttributes[HREF].GetAnimValue(src, this);
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
NS_NewURI(getter_AddRefs(mUri), src, nullptr, baseURI);
// At this point mUri will be null for invalid URLs.
mExternal = true;
}
mFrozen = true;
}
//----------------------------------------------------------------------
// nsScriptElement methods
bool
nsSVGScriptElement::HasScriptContent()
{
return (mFrozen ? mExternal : mStringAttributes[HREF].IsExplicitlySet()) ||
nsContentUtils::HasNonEmptyTextContent(this);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::StringAttributesInfo
nsSVGScriptElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
//----------------------------------------------------------------------
// nsIContent methods
nsresult
nsSVGScriptElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers)
{
nsresult rv = nsSVGScriptElementBase::BindToTree(aDocument, aParent,
aBindingParent,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
if (aDocument) {
MaybeProcessScript();
}
return NS_OK;
}
nsresult
nsSVGScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) {
MaybeProcessScript();
}
return nsSVGScriptElementBase::AfterSetAttr(aNamespaceID, aName,
aValue, aNotify);
}
bool
nsSVGScriptElement::ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aNamespaceID == kNameSpaceID_None &&
aAttribute == nsGkAtoms::crossorigin) {
ParseCORSValue(aValue, aResult);
return true;
}
return nsSVGScriptElementBase::ParseAttribute(aNamespaceID, aAttribute,
aValue, aResult);
}
CORSMode
nsSVGScriptElement::GetCORSMode() const
{
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
}

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

@ -0,0 +1,21 @@
/* -*- 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 SVGScriptElement : SVGElement {
attribute DOMString type;
// CORS attribute
attribute DOMString crossOrigin;
};
SVGScriptElement implements SVGURIReference;

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

@ -109,6 +109,7 @@ webidl_files = \
SVGPoint.webidl \
SVGPointList.webidl \
SVGPreserveAspectRatio.webidl \
SVGScriptElement.webidl \
SVGStopElement.webidl \
SVGStyleElement.webidl \
SVGTitleElement.webidl \