From a7074f9c0a6edc1f07df5bf6cc45d4061af206bd Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Mon, 25 Mar 2013 02:26:06 -0400 Subject: [PATCH] Bug 847120: Convert SVGFEDisplacementMapElement to WebIDL r=Ms2ger --- .../src/SVGFEDisplacementMapElement.cpp | 123 ++++++++++-------- .../content/src/SVGFEDisplacementMapElement.h | 44 ++++--- dom/base/nsDOMClassInfo.cpp | 8 -- dom/base/nsDOMClassInfoClasses.h | 1 - dom/interfaces/svg/nsIDOMSVGFilters.idl | 17 --- dom/webidl/SVGFEDisplacementMapElement.webidl | 33 +++++ dom/webidl/WebIDL.mk | 1 + 7 files changed, 128 insertions(+), 99 deletions(-) create mode 100644 dom/webidl/SVGFEDisplacementMapElement.webidl diff --git a/content/svg/content/src/SVGFEDisplacementMapElement.cpp b/content/svg/content/src/SVGFEDisplacementMapElement.cpp index 75d134c1c90..a10c809f167 100644 --- a/content/svg/content/src/SVGFEDisplacementMapElement.cpp +++ b/content/svg/content/src/SVGFEDisplacementMapElement.cpp @@ -4,103 +4,113 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/SVGFEDisplacementMapElement.h" +#include "mozilla/dom/SVGFEDisplacementMapElementBinding.h" +#include "nsSVGFilterInstance.h" +#include "nsSVGUtils.h" + +NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDisplacementMap) namespace mozilla { namespace dom { -nsSVGElement::NumberInfo nsSVGFEDisplacementMapElement::sNumberInfo[1] = +// Channel Selectors +static const unsigned short SVG_CHANNEL_UNKNOWN = 0; +static const unsigned short SVG_CHANNEL_R = 1; +static const unsigned short SVG_CHANNEL_G = 2; +static const unsigned short SVG_CHANNEL_B = 3; +static const unsigned short SVG_CHANNEL_A = 4; + +JSObject* +SVGFEDisplacementMapElement::WrapNode(JSContext* aCx, JSObject* aScope) +{ + return SVGFEDisplacementMapElementBinding::Wrap(aCx, aScope, this); +} + +nsSVGElement::NumberInfo SVGFEDisplacementMapElement::sNumberInfo[1] = { { &nsGkAtoms::scale, 0, false }, }; -nsSVGEnumMapping nsSVGFEDisplacementMapElement::sChannelMap[] = { - {&nsGkAtoms::R, nsSVGFEDisplacementMapElement::SVG_CHANNEL_R}, - {&nsGkAtoms::G, nsSVGFEDisplacementMapElement::SVG_CHANNEL_G}, - {&nsGkAtoms::B, nsSVGFEDisplacementMapElement::SVG_CHANNEL_B}, - {&nsGkAtoms::A, nsSVGFEDisplacementMapElement::SVG_CHANNEL_A}, +nsSVGEnumMapping SVGFEDisplacementMapElement::sChannelMap[] = { + {&nsGkAtoms::R, SVG_CHANNEL_R}, + {&nsGkAtoms::G, SVG_CHANNEL_G}, + {&nsGkAtoms::B, SVG_CHANNEL_B}, + {&nsGkAtoms::A, SVG_CHANNEL_A}, {nullptr, 0} }; -nsSVGElement::EnumInfo nsSVGFEDisplacementMapElement::sEnumInfo[2] = +nsSVGElement::EnumInfo SVGFEDisplacementMapElement::sEnumInfo[2] = { { &nsGkAtoms::xChannelSelector, sChannelMap, - nsSVGFEDisplacementMapElement::SVG_CHANNEL_A + SVG_CHANNEL_A }, { &nsGkAtoms::yChannelSelector, sChannelMap, - nsSVGFEDisplacementMapElement::SVG_CHANNEL_A + SVG_CHANNEL_A } }; -nsSVGElement::StringInfo nsSVGFEDisplacementMapElement::sStringInfo[3] = +nsSVGElement::StringInfo SVGFEDisplacementMapElement::sStringInfo[3] = { { &nsGkAtoms::result, kNameSpaceID_None, true }, { &nsGkAtoms::in, kNameSpaceID_None, true }, { &nsGkAtoms::in2, kNameSpaceID_None, true } }; -NS_IMPL_NS_NEW_SVG_ELEMENT(FEDisplacementMap) - //---------------------------------------------------------------------- // nsISupports methods -NS_IMPL_ADDREF_INHERITED(nsSVGFEDisplacementMapElement,nsSVGFEDisplacementMapElementBase) -NS_IMPL_RELEASE_INHERITED(nsSVGFEDisplacementMapElement,nsSVGFEDisplacementMapElementBase) +NS_IMPL_ADDREF_INHERITED(SVGFEDisplacementMapElement,SVGFEDisplacementMapElementBase) +NS_IMPL_RELEASE_INHERITED(SVGFEDisplacementMapElement,SVGFEDisplacementMapElementBase) -DOMCI_NODE_DATA(SVGFEDisplacementMapElement, nsSVGFEDisplacementMapElement) - -NS_INTERFACE_TABLE_HEAD(nsSVGFEDisplacementMapElement) - NS_NODE_INTERFACE_TABLE5(nsSVGFEDisplacementMapElement, nsIDOMNode, - nsIDOMElement, nsIDOMSVGElement, - nsIDOMSVGFilterPrimitiveStandardAttributes, - nsIDOMSVGFEDisplacementMapElement) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGFEDisplacementMapElement) -NS_INTERFACE_MAP_END_INHERITING(nsSVGFEDisplacementMapElementBase) +NS_INTERFACE_TABLE_HEAD(SVGFEDisplacementMapElement) + NS_NODE_INTERFACE_TABLE3(SVGFEDisplacementMapElement, nsIDOMNode, + nsIDOMElement, nsIDOMSVGElement) +NS_INTERFACE_MAP_END_INHERITING(SVGFEDisplacementMapElementBase) //---------------------------------------------------------------------- // nsIDOMNode methods -NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGFEDisplacementMapElement) +NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDisplacementMapElement) //---------------------------------------------------------------------- -// nsIDOMSVGFEDisplacementMapElement methods -/* readonly attribute nsIDOMSVGAnimatedString in1; */ -NS_IMETHODIMP nsSVGFEDisplacementMapElement::GetIn1(nsIDOMSVGAnimatedString * *aIn) +already_AddRefed +SVGFEDisplacementMapElement::In1() { - return mStringAttributes[IN1].ToDOMAnimatedString(aIn, this); + return mStringAttributes[IN1].ToDOMAnimatedString(this); } -/* readonly attribute nsIDOMSVGAnimatedString in2; */ -NS_IMETHODIMP nsSVGFEDisplacementMapElement::GetIn2(nsIDOMSVGAnimatedString * *aIn) +already_AddRefed +SVGFEDisplacementMapElement::In2() { - return mStringAttributes[IN2].ToDOMAnimatedString(aIn, this); + return mStringAttributes[IN2].ToDOMAnimatedString(this); } -/* readonly attribute nsIDOMSVGAnimatedNumber scale; */ -NS_IMETHODIMP nsSVGFEDisplacementMapElement::GetScale(nsIDOMSVGAnimatedNumber * *aScale) +already_AddRefed +SVGFEDisplacementMapElement::Scale() { - return mNumberAttributes[SCALE].ToDOMAnimatedNumber(aScale, this); + return mNumberAttributes[SCALE].ToDOMAnimatedNumber(this); } -/* readonly attribute nsIDOMSVGAnimatedEnumeration xChannelSelector; */ -NS_IMETHODIMP nsSVGFEDisplacementMapElement::GetXChannelSelector(nsIDOMSVGAnimatedEnumeration * *aChannel) +already_AddRefed +SVGFEDisplacementMapElement::XChannelSelector() { - return mEnumAttributes[CHANNEL_X].ToDOMAnimatedEnum(aChannel, this); + return mEnumAttributes[CHANNEL_X].ToDOMAnimatedEnum(this); } -/* readonly attribute nsIDOMSVGAnimatedEnumeration yChannelSelector; */ -NS_IMETHODIMP nsSVGFEDisplacementMapElement::GetYChannelSelector(nsIDOMSVGAnimatedEnumeration * *aChannel) +already_AddRefed +SVGFEDisplacementMapElement::YChannelSelector() { - return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(aChannel, this); + return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(this); } nsresult -nsSVGFEDisplacementMapElement::Filter(nsSVGFilterInstance *instance, - const nsTArray& aSources, - const Image* aTarget, - const nsIntRect& rect) +SVGFEDisplacementMapElement::Filter(nsSVGFilterInstance* instance, + const nsTArray& aSources, + const Image* aTarget, + const nsIntRect& rect) { float scale = instance->GetPrimitiveNumber(SVGContentUtils::XY, &mNumberAttributes[SCALE]); @@ -161,10 +171,10 @@ nsSVGFEDisplacementMapElement::Filter(nsSVGFilterInstance *instance, } bool -nsSVGFEDisplacementMapElement::AttributeAffectsRendering(int32_t aNameSpaceID, - nsIAtom* aAttribute) const +SVGFEDisplacementMapElement::AttributeAffectsRendering(int32_t aNameSpaceID, + nsIAtom* aAttribute) const { - return nsSVGFEDisplacementMapElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) || + return SVGFEDisplacementMapElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) || (aNameSpaceID == kNameSpaceID_None && (aAttribute == nsGkAtoms::in || aAttribute == nsGkAtoms::in2 || @@ -174,14 +184,14 @@ nsSVGFEDisplacementMapElement::AttributeAffectsRendering(int32_t aNameSpaceID, } void -nsSVGFEDisplacementMapElement::GetSourceImageNames(nsTArray& aSources) +SVGFEDisplacementMapElement::GetSourceImageNames(nsTArray& aSources) { aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this)); aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN2], this)); } nsIntRect -nsSVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray& aSourceBBoxes, +SVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray& aSourceBBoxes, const nsSVGFilterInstance& aInstance) { // XXX we could do something clever here involving analysis of 'scale' @@ -191,7 +201,7 @@ nsSVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray& aSou } void -nsSVGFEDisplacementMapElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox, +SVGFEDisplacementMapElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox, nsTArray& aSourceBBoxes, const nsSVGFilterInstance& aInstance) { // in2 contains the displacements, which we read for each target pixel @@ -204,8 +214,8 @@ nsSVGFEDisplacementMapElement::ComputeNeededSourceBBoxes(const nsIntRect& aTarge } nsIntRect -nsSVGFEDisplacementMapElement::ComputeChangeBBox(const nsTArray& aSourceChangeBoxes, - const nsSVGFilterInstance& aInstance) +SVGFEDisplacementMapElement::ComputeChangeBBox(const nsTArray& aSourceChangeBoxes, + const nsSVGFilterInstance& aInstance) { // XXX we could do something clever here involving analysis of 'scale' // to figure out the maximum displacement @@ -216,22 +226,25 @@ nsSVGFEDisplacementMapElement::ComputeChangeBBox(const nsTArray& aSou // nsSVGElement methods nsSVGElement::NumberAttributesInfo -nsSVGFEDisplacementMapElement::GetNumberInfo() +SVGFEDisplacementMapElement::GetNumberInfo() { return NumberAttributesInfo(mNumberAttributes, sNumberInfo, ArrayLength(sNumberInfo)); } nsSVGElement::EnumAttributesInfo -nsSVGFEDisplacementMapElement::GetEnumInfo() +SVGFEDisplacementMapElement::GetEnumInfo() { return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo)); } nsSVGElement::StringAttributesInfo -nsSVGFEDisplacementMapElement::GetStringInfo() +SVGFEDisplacementMapElement::GetStringInfo() { return StringAttributesInfo(mStringAttributes, sStringInfo, ArrayLength(sStringInfo)); } + +} // namespace dom +} // namespace mozilla diff --git a/content/svg/content/src/SVGFEDisplacementMapElement.h b/content/svg/content/src/SVGFEDisplacementMapElement.h index fef65336c83..318758382b4 100644 --- a/content/svg/content/src/SVGFEDisplacementMapElement.h +++ b/content/svg/content/src/SVGFEDisplacementMapElement.h @@ -6,29 +6,34 @@ #ifndef mozilla_dom_SVGFEDisplacementMapElement_h #define mozilla_dom_SVGFEDisplacementMapElement_h +#include "nsSVGEnum.h" #include "nsSVGFilters.h" +nsresult NS_NewSVGFEDisplacementMapElement(nsIContent **aResult, + already_AddRefed aNodeInfo); + namespace mozilla { namespace dom { -typedef nsSVGFE nsSVGFEDisplacementMapElementBase; +typedef nsSVGFE SVGFEDisplacementMapElementBase; -class nsSVGFEDisplacementMapElement : public nsSVGFEDisplacementMapElementBase, - public nsIDOMSVGFEDisplacementMapElement +class SVGFEDisplacementMapElement : public SVGFEDisplacementMapElementBase, + public nsIDOMSVGElement { protected: - friend nsresult NS_NewSVGFEDisplacementMapElement(nsIContent **aResult, - already_AddRefed aNodeInfo); - nsSVGFEDisplacementMapElement(already_AddRefed aNodeInfo) - : nsSVGFEDisplacementMapElementBase(aNodeInfo) {} + friend nsresult (::NS_NewSVGFEDisplacementMapElement(nsIContent **aResult, + already_AddRefed aNodeInfo)); + SVGFEDisplacementMapElement(already_AddRefed aNodeInfo) + : SVGFEDisplacementMapElementBase(aNodeInfo) + { + SetIsDOMBinding(); + } + virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE; public: // interfaces: NS_DECL_ISUPPORTS_INHERITED - // FE Base - NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFEDisplacementMapElementBase::) - virtual nsresult Filter(nsSVGFilterInstance* aInstance, const nsTArray& aSources, const Image* aTarget, @@ -44,19 +49,22 @@ public: virtual nsIntRect ComputeChangeBBox(const nsTArray& aSourceChangeBoxes, const nsSVGFilterInstance& aInstance); - // DisplacementMap - NS_DECL_NSIDOMSVGFEDISPLACEMENTMAPELEMENT - - NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEDisplacementMapElementBase::) + NS_FORWARD_NSIDOMSVGELEMENT(SVGFEDisplacementMapElementBase::) NS_FORWARD_NSIDOMNODE_TO_NSINODE NS_FORWARD_NSIDOMELEMENT_TO_GENERIC virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; - virtual nsXPCClassInfo* GetClassInfo(); - virtual nsIDOMNode* AsDOMNode() { return this; } + + // WebIDL + already_AddRefed In1(); + already_AddRefed In2(); + already_AddRefed Scale(); + already_AddRefed XChannelSelector(); + already_AddRefed YChannelSelector(); + protected: virtual bool OperatesOnSRGB(nsSVGFilterInstance* aInstance, int32_t aInput, Image* aImage) { @@ -64,8 +72,8 @@ protected: case 0: return aImage->mColorModel.mColorSpace == ColorModel::SRGB; case 1: - return nsSVGFEDisplacementMapElementBase::OperatesOnSRGB(aInstance, - aInput, aImage); + return SVGFEDisplacementMapElementBase::OperatesOnSRGB(aInstance, + aInput, aImage); default: NS_ERROR("Will not give correct output color model"); return false; diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index f1d5d293c6d..a611210cd95 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -814,8 +814,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(SVGFEConvolveMatrixElement, nsElementSH, ELEMENT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(SVGFEDisplacementMapElement, nsElementSH, - ELEMENT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(SVGFEMorphologyElement, nsElementSH, ELEMENT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(SVGFETurbulenceElement, nsElementSH, @@ -2235,12 +2233,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(SVGFEDisplacementMapElement, nsIDOMSVGFEDisplacementMapElement) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFEDisplacementMapElement) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFilterPrimitiveStandardAttributes) - DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(SVGFEMorphologyElement, nsIDOMSVGFEMorphologyElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFEMorphologyElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFilterPrimitiveStandardAttributes) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index b438294f0d6..0a01468bdf6 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -123,7 +123,6 @@ DOMCI_CLASS(SVGDocument) // SVG element classes DOMCI_CLASS(TimeEvent) DOMCI_CLASS(SVGFEConvolveMatrixElement) -DOMCI_CLASS(SVGFEDisplacementMapElement) DOMCI_CLASS(SVGFEMorphologyElement) DOMCI_CLASS(SVGFETurbulenceElement) DOMCI_CLASS(SVGUnknownElement) diff --git a/dom/interfaces/svg/nsIDOMSVGFilters.idl b/dom/interfaces/svg/nsIDOMSVGFilters.idl index b2746e8b3e8..4a8833b3a8c 100644 --- a/dom/interfaces/svg/nsIDOMSVGFilters.idl +++ b/dom/interfaces/svg/nsIDOMSVGFilters.idl @@ -80,20 +80,3 @@ interface nsIDOMSVGFEConvolveMatrixElement : nsIDOMSVGFilterPrimitiveStandardAtt readonly attribute nsIDOMSVGAnimatedNumber kernelUnitLengthY; readonly attribute nsISupports preserveAlpha; }; - -[scriptable, uuid(5ab43048-d59a-4e3c-ad2f-6a5d8593f6d0)] -interface nsIDOMSVGFEDisplacementMapElement : nsIDOMSVGFilterPrimitiveStandardAttributes -{ - // Channel Selectors - const unsigned short SVG_CHANNEL_UNKNOWN = 0; - const unsigned short SVG_CHANNEL_R = 1; - const unsigned short SVG_CHANNEL_G = 2; - const unsigned short SVG_CHANNEL_B = 3; - const unsigned short SVG_CHANNEL_A = 4; - - readonly attribute nsIDOMSVGAnimatedString in1; - readonly attribute nsIDOMSVGAnimatedString in2; - readonly attribute nsIDOMSVGAnimatedNumber scale; - readonly attribute nsIDOMSVGAnimatedEnumeration xChannelSelector; - readonly attribute nsIDOMSVGAnimatedEnumeration yChannelSelector; -}; diff --git a/dom/webidl/SVGFEDisplacementMapElement.webidl b/dom/webidl/SVGFEDisplacementMapElement.webidl new file mode 100644 index 00000000000..de31a8ea4c3 --- /dev/null +++ b/dom/webidl/SVGFEDisplacementMapElement.webidl @@ -0,0 +1,33 @@ +/* -*- 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 SVGAnimatedEnumeration; +interface SVGAnimatedNumber; +interface SVGAnimatedString; + +interface SVGFEDisplacementMapElement : SVGElement { + + // Channel Selectors + const unsigned short SVG_CHANNEL_UNKNOWN = 0; + const unsigned short SVG_CHANNEL_R = 1; + const unsigned short SVG_CHANNEL_G = 2; + const unsigned short SVG_CHANNEL_B = 3; + const unsigned short SVG_CHANNEL_A = 4; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedString in2; + readonly attribute SVGAnimatedNumber scale; + readonly attribute SVGAnimatedEnumeration xChannelSelector; + readonly attribute SVGAnimatedEnumeration yChannelSelector; +}; + +SVGFEDisplacementMapElement implements SVGFilterPrimitiveStandardAttributes; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index b291c814280..6c0b4c4880f 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -191,6 +191,7 @@ webidl_files = \ SVGFEComponentTransferElement.webidl \ SVGFECompositeElement.webidl \ SVGFEDiffuseLightingElement.webidl \ + SVGFEDisplacementMapElement.webidl \ SVGFEDistantLightElement.webidl \ SVGFEFloodElement.webidl \ SVGFEFuncAElement.webidl \