Bug 823394 Part 2: Add WebIDL API to SVGElement and enable binding r=bz

This commit is contained in:
David Zbarsky 2012-12-23 03:22:58 -05:00
parent 9a8115eee5
commit 4612303f43
7 changed files with 130 additions and 16 deletions

View File

@ -59,6 +59,7 @@
#include "nsAttrValueOrString.h"
#include "nsSMILAnimationController.h"
#include "nsDOMCSSDeclaration.h"
#include "mozilla/dom/SVGElementBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -81,26 +82,42 @@ nsSVGElement::nsSVGElement(already_AddRefed<nsINodeInfo> aNodeInfo)
{
}
JSObject*
nsSVGElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
{
return SVGElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
//----------------------------------------------------------------------
/* readonly attribute nsIDOMSVGAnimatedString className; */
NS_IMETHODIMP
nsSVGElement::GetClassName(nsIDOMSVGAnimatedString** aClassName)
{
return mClassAttribute.ToDOMAnimatedString(aClassName, this);
*aClassName = ClassName().get();
return NS_OK;
}
/* readonly attribute nsIDOMCSSStyleDeclaration style; */
NS_IMETHODIMP
nsSVGElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
{
nsresult rv;
*aStyle = nsSVGElementBase::GetStyle(&rv);
if (NS_FAILED(rv)) {
return rv;
ErrorResult rv;
NS_ADDREF(*aStyle = GetStyle(rv));
return rv.ErrorCode();
}
nsICSSDeclaration*
nsSVGElement::GetStyle(ErrorResult& rv)
{
nsresult res;
nsICSSDeclaration* style = nsSVGElementBase::GetStyle(&res);
if (NS_FAILED(res)) {
rv.Throw(res);
return nullptr;
}
NS_ADDREF(*aStyle);
return NS_OK;
return style;
}
/* nsIDOMCSSValue getPresentationAttribute (in DOMString name); */
@ -115,6 +132,13 @@ nsSVGElement::GetPresentationAttribute(const nsAString& aName,
return NS_ERROR_NOT_IMPLEMENTED;
}
already_AddRefed<CSSValue>
nsSVGElement::GetPresentationAttribute(const nsAString& aName, ErrorResult& rv)
{
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
return nullptr;
}
//----------------------------------------------------------------------
// nsSVGElement methods
@ -1127,24 +1151,52 @@ NS_IMETHODIMP nsSVGElement::SetId(const nsAString & aId)
NS_IMETHODIMP
nsSVGElement::GetOwnerSVGElement(nsIDOMSVGSVGElement * *aOwnerSVGElement)
{
NS_IF_ADDREF(*aOwnerSVGElement = GetCtx());
ErrorResult rv;
NS_IF_ADDREF(*aOwnerSVGElement = GetOwnerSVGElement(rv));
return rv.ErrorCode();
}
if (*aOwnerSVGElement || Tag() == nsGkAtoms::svg) {
// If we found something or we're the outermost SVG element, that's OK.
return NS_OK;
nsSVGSVGElement*
nsSVGElement::GetOwnerSVGElement(ErrorResult& rv)
{
nsSVGSVGElement* ownerSVGElement = GetCtx();
// If we didn't find anything and we're not the outermost SVG element,
// we've got an invalid structure
if (!ownerSVGElement && Tag() != nsGkAtoms::svg) {
rv.Throw(NS_ERROR_FAILURE);
}
// Otherwise, we've got an invalid structure
return NS_ERROR_FAILURE;
return ownerSVGElement;
}
/* readonly attribute nsIDOMSVGElement viewportElement; */
NS_IMETHODIMP
nsSVGElement::GetViewportElement(nsIDOMSVGElement * *aViewportElement)
{
*aViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
nsCOMPtr<nsSVGElement> elem = GetViewportElement();
nsCOMPtr<nsIDOMSVGElement> svgElem = do_QueryInterface(elem);
svgElem.forget(aViewportElement);
return NS_OK;
}
already_AddRefed<nsSVGElement>
nsSVGElement::GetViewportElement()
{
nsCOMPtr<nsIDOMSVGElement> elem =
SVGContentUtils::GetNearestViewportElement(this);
nsCOMPtr<nsSVGElement> svgElem = do_QueryInterface(elem);
return svgElem.forget();
}
already_AddRefed<nsIDOMSVGAnimatedString>
nsSVGElement::ClassName()
{
nsCOMPtr<nsIDOMSVGAnimatedString> className;
mClassAttribute.ToDOMAnimatedString(getter_AddRefs(className), this);
return className.forget();
}
//------------------------------------------------------------------------
// Helper class: MappedAttrParser, for parsing values of mapped attributes

View File

@ -37,6 +37,10 @@ class nsSVGSVGElement;
class nsSVGViewBox;
namespace mozilla {
namespace dom {
class CSSValue;
}
class SVGAnimatedNumberList;
class SVGNumberList;
class SVGAnimatedLengthList;
@ -294,7 +298,15 @@ public:
return nullptr;
}
// WebIDL
nsSVGSVGElement* GetOwnerSVGElement(mozilla::ErrorResult& rv);
already_AddRefed<nsSVGElement> GetViewportElement();
already_AddRefed<nsIDOMSVGAnimatedString> ClassName();
nsICSSDeclaration* GetStyle(mozilla::ErrorResult& rv);
already_AddRefed<mozilla::dom::CSSValue> GetPresentationAttribute(const nsAString& aName, mozilla::ErrorResult& rv);
protected:
virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap);
#ifdef DEBUG
// We define BeforeSetAttr here and mark it MOZ_FINAL to ensure it is NOT used
// by SVG elements.

View File

@ -461,6 +461,13 @@ DOMInterfaces = {
'headerFile': 'DOMSVGAnimatedTransformList.h'
},
'SVGElement': {
'nativeType': 'nsSVGElement',
'hasXPConnectImpls': True,
'hasInstanceInterface': 'nsIDOMSVGElement',
'resultNotAddRefed': ['ownerSVGElement', 'style']
},
'SVGLengthList': {
'nativeType': 'mozilla::DOMSVGLengthList',
'headerFile': 'DOMSVGLengthList.h',
@ -997,8 +1004,10 @@ addExternalIface('ProcessingInstruction', nativeType='nsXMLProcessingInstruction
addExternalIface('Range', nativeType='nsRange')
addExternalIface("Rect")
addExternalIface('StyleSheetList')
addExternalIface('SVGAnimatedString')
addExternalIface('SVGLength')
addExternalIface('SVGNumber')
addExternalIface('SVGSVGElement', nativeType='nsSVGSVGElement')
addExternalIface('Text', nativeType='nsTextNode')
addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
addExternalIface('TreeWalker')

View File

@ -0,0 +1,36 @@
/* -*- 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 SVGSVGElement;
interface SVGAnimatedString;
interface SVGElement : Element {
attribute DOMString id;
/* [SetterThrows]
attribute DOMString xmlbase; */
readonly attribute SVGAnimatedString className;
[Throws]
readonly attribute CSSStyleDeclaration style;
[Throws] // because not implemented
CSSValue? getPresentationAttribute(DOMString name);
/*[SetterThrows]
attribute DOMString xmllang;
[SetterThrows]
attribute DOMString xmlspace;*/
[Throws]
readonly attribute SVGSVGElement? ownerSVGElement;
readonly attribute SVGElement? viewportElement;
};

View File

@ -75,6 +75,7 @@ webidl_files = \
SVGAnimatedNumberList.webidl \
SVGAnimatedPreserveAspectRatio.webidl \
SVGAnimatedTransformList.webidl \
SVGElement.webidl \
SVGLengthList.webidl \
SVGMatrix.webidl \
SVGNumberList.webidl \

View File

@ -420,7 +420,8 @@ customIncludes = [
'nsICSSDeclaration.h',
'mozilla/dom/NodeBinding.h',
'mozilla/dom/ElementBinding.h',
'mozilla/dom/HTMLElementBinding.h'
'mozilla/dom/HTMLElementBinding.h',
'mozilla/dom/SVGElementBinding.h'
]
customReturnInterfaces = [
@ -595,5 +596,6 @@ customMethodCalls = {
newBindingProperties = {
'nsIDOMNode': 'mozilla::dom::NodeBinding::sNativePropertyHooks.mNativeProperties.regular',
'nsIDOMElement': 'mozilla::dom::ElementBinding::sNativePropertyHooks.mNativeProperties.regular',
'nsIDOMHTMLElement': 'mozilla::dom::HTMLElementBinding::sNativePropertyHooks.mNativeProperties.regular'
'nsIDOMHTMLElement': 'mozilla::dom::HTMLElementBinding::sNativePropertyHooks.mNativeProperties.regular',
'nsIDOMSVGElement': 'mozilla::dom::SVGElementBinding::sNativePropertyHooks.mNativeProperties.regular'
}

View File

@ -20,6 +20,7 @@
#include "mozilla/dom/NodeBinding.h"
#include "mozilla/dom/ElementBinding.h"
#include "mozilla/dom/HTMLElementBinding.h"
#include "mozilla/dom/SVGElementBinding.h"
template<class T>
struct ProtoIDAndDepth
@ -45,6 +46,7 @@ NEW_BINDING(mozilla::dom::EventTarget, EventTarget);
NEW_BINDING(nsINode, Node);
NEW_BINDING(mozilla::dom::Element, Element);
NEW_BINDING(nsGenericHTMLElement, HTMLElement);
NEW_BINDING(nsSVGElement, SVGElement);
#define DEFINE_UNWRAP_CAST(_interface, _base, _bit) \
template <> \