Bug 847120: Convert SVGFEDisplacementMapElement to WebIDL r=Ms2ger

This commit is contained in:
David Zbarsky 2013-03-23 17:00:35 -04:00
parent 03acafede3
commit 4a15182a9e
7 changed files with 128 additions and 99 deletions

View File

@ -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<nsIDOMSVGAnimatedString>
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<nsIDOMSVGAnimatedString>
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<nsIDOMSVGAnimatedNumber>
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<nsIDOMSVGAnimatedEnumeration>
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<nsIDOMSVGAnimatedEnumeration>
SVGFEDisplacementMapElement::YChannelSelector()
{
return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(aChannel, this);
return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(this);
}
nsresult
nsSVGFEDisplacementMapElement::Filter(nsSVGFilterInstance *instance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& rect)
SVGFEDisplacementMapElement::Filter(nsSVGFilterInstance* instance,
const nsTArray<const Image*>& 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<nsSVGStringInfo>& aSources)
SVGFEDisplacementMapElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
{
aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN2], this));
}
nsIntRect
nsSVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
SVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
const nsSVGFilterInstance& aInstance)
{
// XXX we could do something clever here involving analysis of 'scale'
@ -191,7 +201,7 @@ nsSVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSou
}
void
nsSVGFEDisplacementMapElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
SVGFEDisplacementMapElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
nsTArray<nsIntRect>& 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<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance)
SVGFEDisplacementMapElement::ComputeChangeBBox(const nsTArray<nsIntRect>& 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<nsIntRect>& 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

View File

@ -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<nsINodeInfo> 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<nsINodeInfo> aNodeInfo);
nsSVGFEDisplacementMapElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGFEDisplacementMapElementBase(aNodeInfo) {}
friend nsresult (::NS_NewSVGFEDisplacementMapElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo));
SVGFEDisplacementMapElement(already_AddRefed<nsINodeInfo> 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<const Image*>& aSources,
const Image* aTarget,
@ -44,19 +49,22 @@ public:
virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& 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<nsIDOMSVGAnimatedString> In1();
already_AddRefed<nsIDOMSVGAnimatedString> In2();
already_AddRefed<nsIDOMSVGAnimatedNumber> Scale();
already_AddRefed<nsIDOMSVGAnimatedEnumeration> XChannelSelector();
already_AddRefed<nsIDOMSVGAnimatedEnumeration> 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;

View File

@ -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)

View File

@ -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)

View File

@ -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;
};

View File

@ -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;

View File

@ -191,6 +191,7 @@ webidl_files = \
SVGFEComponentTransferElement.webidl \
SVGFECompositeElement.webidl \
SVGFEDiffuseLightingElement.webidl \
SVGFEDisplacementMapElement.webidl \
SVGFEDistantLightElement.webidl \
SVGFEFloodElement.webidl \
SVGFEFuncAElement.webidl \