mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 823394 Part 2: Add WebIDL API to SVGElement and enable binding r=bz
This commit is contained in:
parent
7d32181339
commit
a4730bced7
@ -59,6 +59,7 @@
|
|||||||
#include "nsAttrValueOrString.h"
|
#include "nsAttrValueOrString.h"
|
||||||
#include "nsSMILAnimationController.h"
|
#include "nsSMILAnimationController.h"
|
||||||
#include "nsDOMCSSDeclaration.h"
|
#include "nsDOMCSSDeclaration.h"
|
||||||
|
#include "mozilla/dom/SVGElementBinding.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
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; */
|
/* readonly attribute nsIDOMSVGAnimatedString className; */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSVGElement::GetClassName(nsIDOMSVGAnimatedString** aClassName)
|
nsSVGElement::GetClassName(nsIDOMSVGAnimatedString** aClassName)
|
||||||
{
|
{
|
||||||
return mClassAttribute.ToDOMAnimatedString(aClassName, this);
|
*aClassName = ClassName().get();
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* readonly attribute nsIDOMCSSStyleDeclaration style; */
|
/* readonly attribute nsIDOMCSSStyleDeclaration style; */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSVGElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
nsSVGElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
ErrorResult rv;
|
||||||
*aStyle = nsSVGElementBase::GetStyle(&rv);
|
NS_ADDREF(*aStyle = GetStyle(rv));
|
||||||
if (NS_FAILED(rv)) {
|
return rv.ErrorCode();
|
||||||
return rv;
|
}
|
||||||
|
|
||||||
|
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); */
|
/* nsIDOMCSSValue getPresentationAttribute (in DOMString name); */
|
||||||
@ -115,6 +132,13 @@ nsSVGElement::GetPresentationAttribute(const nsAString& aName,
|
|||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
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
|
// nsSVGElement methods
|
||||||
|
|
||||||
@ -1127,24 +1151,52 @@ NS_IMETHODIMP nsSVGElement::SetId(const nsAString & aId)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSVGElement::GetOwnerSVGElement(nsIDOMSVGSVGElement * *aOwnerSVGElement)
|
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) {
|
nsSVGSVGElement*
|
||||||
// If we found something or we're the outermost SVG element, that's OK.
|
nsSVGElement::GetOwnerSVGElement(ErrorResult& rv)
|
||||||
return NS_OK;
|
{
|
||||||
|
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; */
|
/* readonly attribute nsIDOMSVGElement viewportElement; */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSVGElement::GetViewportElement(nsIDOMSVGElement * *aViewportElement)
|
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;
|
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
|
// Helper class: MappedAttrParser, for parsing values of mapped attributes
|
||||||
|
|
||||||
|
@ -37,6 +37,10 @@ class nsSVGSVGElement;
|
|||||||
class nsSVGViewBox;
|
class nsSVGViewBox;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
class CSSValue;
|
||||||
|
}
|
||||||
|
|
||||||
class SVGAnimatedNumberList;
|
class SVGAnimatedNumberList;
|
||||||
class SVGNumberList;
|
class SVGNumberList;
|
||||||
class SVGAnimatedLengthList;
|
class SVGAnimatedLengthList;
|
||||||
@ -294,7 +298,15 @@ public:
|
|||||||
return nullptr;
|
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:
|
protected:
|
||||||
|
virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// We define BeforeSetAttr here and mark it MOZ_FINAL to ensure it is NOT used
|
// We define BeforeSetAttr here and mark it MOZ_FINAL to ensure it is NOT used
|
||||||
// by SVG elements.
|
// by SVG elements.
|
||||||
|
@ -463,6 +463,13 @@ DOMInterfaces = {
|
|||||||
'headerFile': 'DOMSVGAnimatedTransformList.h'
|
'headerFile': 'DOMSVGAnimatedTransformList.h'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'SVGElement': {
|
||||||
|
'nativeType': 'nsSVGElement',
|
||||||
|
'hasXPConnectImpls': True,
|
||||||
|
'hasInstanceInterface': 'nsIDOMSVGElement',
|
||||||
|
'resultNotAddRefed': ['ownerSVGElement', 'style']
|
||||||
|
},
|
||||||
|
|
||||||
'SVGLengthList': {
|
'SVGLengthList': {
|
||||||
'nativeType': 'mozilla::DOMSVGLengthList',
|
'nativeType': 'mozilla::DOMSVGLengthList',
|
||||||
'headerFile': 'DOMSVGLengthList.h',
|
'headerFile': 'DOMSVGLengthList.h',
|
||||||
@ -1000,8 +1007,10 @@ addExternalIface('ProcessingInstruction', nativeType='nsXMLProcessingInstruction
|
|||||||
addExternalIface('Range', nativeType='nsRange')
|
addExternalIface('Range', nativeType='nsRange')
|
||||||
addExternalIface("Rect")
|
addExternalIface("Rect")
|
||||||
addExternalIface('StyleSheetList')
|
addExternalIface('StyleSheetList')
|
||||||
|
addExternalIface('SVGAnimatedString')
|
||||||
addExternalIface('SVGLength')
|
addExternalIface('SVGLength')
|
||||||
addExternalIface('SVGNumber')
|
addExternalIface('SVGNumber')
|
||||||
|
addExternalIface('SVGSVGElement', nativeType='nsSVGSVGElement')
|
||||||
addExternalIface('Text', nativeType='nsTextNode')
|
addExternalIface('Text', nativeType='nsTextNode')
|
||||||
addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
|
addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
|
||||||
addExternalIface('TreeWalker')
|
addExternalIface('TreeWalker')
|
||||||
|
36
dom/webidl/SVGElement.webidl
Normal file
36
dom/webidl/SVGElement.webidl
Normal 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;
|
||||||
|
};
|
@ -76,6 +76,7 @@ webidl_files = \
|
|||||||
SVGAnimatedNumberList.webidl \
|
SVGAnimatedNumberList.webidl \
|
||||||
SVGAnimatedPreserveAspectRatio.webidl \
|
SVGAnimatedPreserveAspectRatio.webidl \
|
||||||
SVGAnimatedTransformList.webidl \
|
SVGAnimatedTransformList.webidl \
|
||||||
|
SVGElement.webidl \
|
||||||
SVGLengthList.webidl \
|
SVGLengthList.webidl \
|
||||||
SVGMatrix.webidl \
|
SVGMatrix.webidl \
|
||||||
SVGNumberList.webidl \
|
SVGNumberList.webidl \
|
||||||
|
@ -388,7 +388,8 @@ customIncludes = [
|
|||||||
'mozilla/dom/NodeBinding.h',
|
'mozilla/dom/NodeBinding.h',
|
||||||
'mozilla/dom/ElementBinding.h',
|
'mozilla/dom/ElementBinding.h',
|
||||||
'mozilla/dom/HTMLElementBinding.h',
|
'mozilla/dom/HTMLElementBinding.h',
|
||||||
'mozilla/dom/DocumentBinding.h'
|
'mozilla/dom/DocumentBinding.h',
|
||||||
|
'mozilla/dom/SVGElementBinding.h'
|
||||||
]
|
]
|
||||||
|
|
||||||
customReturnInterfaces = [
|
customReturnInterfaces = [
|
||||||
@ -497,5 +498,6 @@ newBindingProperties = {
|
|||||||
'nsIDOMNode': 'mozilla::dom::NodeBinding::sNativePropertyHooks.mNativeProperties.regular',
|
'nsIDOMNode': 'mozilla::dom::NodeBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||||
'nsIDOMElement': 'mozilla::dom::ElementBinding::sNativePropertyHooks.mNativeProperties.regular',
|
'nsIDOMElement': 'mozilla::dom::ElementBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||||
'nsIDOMHTMLElement': 'mozilla::dom::HTMLElementBinding::sNativePropertyHooks.mNativeProperties.regular',
|
'nsIDOMHTMLElement': 'mozilla::dom::HTMLElementBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||||
'nsIDOMDocument': 'mozilla::dom::DocumentBinding::sNativePropertyHooks.mNativeProperties.regular'
|
'nsIDOMDocument': 'mozilla::dom::DocumentBinding::sNativePropertyHooks.mNativeProperties.regular',
|
||||||
|
'nsIDOMSVGElement': 'mozilla::dom::SVGElementBinding::sNativePropertyHooks.mNativeProperties.regular'
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "mozilla/dom/ElementBinding.h"
|
#include "mozilla/dom/ElementBinding.h"
|
||||||
#include "mozilla/dom/HTMLElementBinding.h"
|
#include "mozilla/dom/HTMLElementBinding.h"
|
||||||
#include "mozilla/dom/DocumentBinding.h"
|
#include "mozilla/dom/DocumentBinding.h"
|
||||||
|
#include "mozilla/dom/SVGElementBinding.h"
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct ProtoIDAndDepth
|
struct ProtoIDAndDepth
|
||||||
@ -48,6 +49,7 @@ NEW_BINDING(mozilla::dom::Element, Element);
|
|||||||
NEW_BINDING(nsGenericHTMLElement, HTMLElement);
|
NEW_BINDING(nsGenericHTMLElement, HTMLElement);
|
||||||
NEW_BINDING(nsIDocument, Document);
|
NEW_BINDING(nsIDocument, Document);
|
||||||
NEW_BINDING(nsDocument, Document);
|
NEW_BINDING(nsDocument, Document);
|
||||||
|
NEW_BINDING(nsSVGElement, SVGElement);
|
||||||
|
|
||||||
#define DEFINE_UNWRAP_CAST(_interface, _base, _bit) \
|
#define DEFINE_UNWRAP_CAST(_interface, _base, _bit) \
|
||||||
template <> \
|
template <> \
|
||||||
|
Loading…
Reference in New Issue
Block a user