Bug 847120: Convert SVGFEColorMatrixElement to WebIDL r=Ms2ger

This commit is contained in:
David Zbarsky 2013-03-18 19:14:40 -04:00
parent d6265808f0
commit 9da42b90e4
8 changed files with 120 additions and 97 deletions

View File

@ -3,95 +3,99 @@
* 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 "DOMSVGAnimatedNumberList.h"
#include "mozilla/dom/SVGFEColorMatrixElement.h"
#include "mozilla/dom/SVGFEColorMatrixElementBinding.h"
#include "nsSVGUtils.h"
#define NUM_ENTRIES_IN_4x5_MATRIX 20
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEColorMatrix)
namespace mozilla {
namespace dom {
nsSVGEnumMapping nsSVGFEColorMatrixElement::sTypeMap[] = {
{&nsGkAtoms::matrix, nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_MATRIX},
{&nsGkAtoms::saturate, nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_SATURATE},
{&nsGkAtoms::hueRotate, nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_HUE_ROTATE},
{&nsGkAtoms::luminanceToAlpha, nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA},
JSObject*
SVGFEColorMatrixElement::WrapNode(JSContext* aCx, JSObject* aScope)
{
return SVGFEColorMatrixElementBinding::Wrap(aCx, aScope, this);
}
nsSVGEnumMapping SVGFEColorMatrixElement::sTypeMap[] = {
{&nsGkAtoms::matrix, SVG_FECOLORMATRIX_TYPE_MATRIX},
{&nsGkAtoms::saturate, SVG_FECOLORMATRIX_TYPE_SATURATE},
{&nsGkAtoms::hueRotate, SVG_FECOLORMATRIX_TYPE_HUE_ROTATE},
{&nsGkAtoms::luminanceToAlpha, SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA},
{nullptr, 0}
};
nsSVGElement::EnumInfo nsSVGFEColorMatrixElement::sEnumInfo[1] =
nsSVGElement::EnumInfo SVGFEColorMatrixElement::sEnumInfo[1] =
{
{ &nsGkAtoms::type,
sTypeMap,
nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_MATRIX
SVG_FECOLORMATRIX_TYPE_MATRIX
}
};
nsSVGElement::StringInfo nsSVGFEColorMatrixElement::sStringInfo[2] =
nsSVGElement::StringInfo SVGFEColorMatrixElement::sStringInfo[2] =
{
{ &nsGkAtoms::result, kNameSpaceID_None, true },
{ &nsGkAtoms::in, kNameSpaceID_None, true }
};
nsSVGElement::NumberListInfo nsSVGFEColorMatrixElement::sNumberListInfo[1] =
nsSVGElement::NumberListInfo SVGFEColorMatrixElement::sNumberListInfo[1] =
{
{ &nsGkAtoms::values }
};
NS_IMPL_NS_NEW_SVG_ELEMENT(FEColorMatrix)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGFEColorMatrixElement,nsSVGFEColorMatrixElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGFEColorMatrixElement,nsSVGFEColorMatrixElementBase)
NS_IMPL_ADDREF_INHERITED(SVGFEColorMatrixElement,SVGFEColorMatrixElementBase)
NS_IMPL_RELEASE_INHERITED(SVGFEColorMatrixElement,SVGFEColorMatrixElementBase)
DOMCI_NODE_DATA(SVGFEColorMatrixElement, nsSVGFEColorMatrixElement)
NS_INTERFACE_TABLE_HEAD(nsSVGFEColorMatrixElement)
NS_NODE_INTERFACE_TABLE5(nsSVGFEColorMatrixElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGFilterPrimitiveStandardAttributes,
nsIDOMSVGFEColorMatrixElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGFEColorMatrixElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGFEColorMatrixElementBase)
NS_INTERFACE_TABLE_HEAD(SVGFEColorMatrixElement)
NS_NODE_INTERFACE_TABLE3(SVGFEColorMatrixElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement)
NS_INTERFACE_MAP_END_INHERITING(SVGFEColorMatrixElementBase)
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGFEColorMatrixElement)
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEColorMatrixElement)
//----------------------------------------------------------------------
// nsSVGFEColorMatrixElement methods
/* readonly attribute nsIDOMSVGAnimatedString in1; */
NS_IMETHODIMP nsSVGFEColorMatrixElement::GetIn1(nsIDOMSVGAnimatedString * *aIn)
already_AddRefed<nsIDOMSVGAnimatedString>
SVGFEColorMatrixElement::In1()
{
return mStringAttributes[IN1].ToDOMAnimatedString(aIn, this);
return mStringAttributes[IN1].ToDOMAnimatedString(this);
}
/* readonly attribute nsIDOMSVGAnimatedEnumeration type; */
NS_IMETHODIMP nsSVGFEColorMatrixElement::GetType(nsIDOMSVGAnimatedEnumeration * *aType)
already_AddRefed<nsIDOMSVGAnimatedEnumeration>
SVGFEColorMatrixElement::Type()
{
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(aType, this);
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
}
/* readonly attribute DOMSVGAnimatedNumberList values; */
NS_IMETHODIMP nsSVGFEColorMatrixElement::GetValues(nsISupports * *aValues)
already_AddRefed<DOMSVGAnimatedNumberList>
SVGFEColorMatrixElement::Values()
{
*aValues = DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[VALUES],
this, VALUES).get();
return NS_OK;
return DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[VALUES],
this, VALUES);
}
void
nsSVGFEColorMatrixElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
SVGFEColorMatrixElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
{
aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
}
nsresult
nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
SVGFEColorMatrixElement::Filter(nsSVGFilterInstance* instance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& rect)
@ -104,9 +108,9 @@ nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
const SVGNumberList &values = mNumberListAttributes[VALUES].GetAnimValue();
if (!mNumberListAttributes[VALUES].IsExplicitlySet() &&
(type == nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_MATRIX ||
type == nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_SATURATE ||
type == nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_HUE_ROTATE)) {
(type == SVG_FECOLORMATRIX_TYPE_MATRIX ||
type == SVG_FECOLORMATRIX_TYPE_SATURATE ||
type == SVG_FECOLORMATRIX_TYPE_HUE_ROTATE)) {
// identity matrix filter
CopyRect(aTarget, aSources[0], rect);
return NS_OK;
@ -128,7 +132,7 @@ nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
float s, c;
switch (type) {
case nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_MATRIX:
case SVG_FECOLORMATRIX_TYPE_MATRIX:
if (values.Length() != NUM_ENTRIES_IN_4x5_MATRIX)
return NS_ERROR_FAILURE;
@ -137,7 +141,7 @@ nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
colorMatrix[j] = values[j];
}
break;
case nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_SATURATE:
case SVG_FECOLORMATRIX_TYPE_SATURATE:
if (values.Length() != 1)
return NS_ERROR_FAILURE;
@ -163,7 +167,7 @@ nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
break;
case nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_HUE_ROTATE:
case SVG_FECOLORMATRIX_TYPE_HUE_ROTATE:
{
memcpy(colorMatrix, identityMatrix, sizeof(colorMatrix));
@ -192,7 +196,7 @@ nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
break;
}
case nsSVGFEColorMatrixElement::SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA:
case SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA:
memcpy(colorMatrix, luminanceToAlphaMatrix, sizeof(colorMatrix));
break;
@ -229,10 +233,10 @@ nsSVGFEColorMatrixElement::Filter(nsSVGFilterInstance *instance,
}
bool
nsSVGFEColorMatrixElement::AttributeAffectsRendering(int32_t aNameSpaceID,
SVGFEColorMatrixElement::AttributeAffectsRendering(int32_t aNameSpaceID,
nsIAtom* aAttribute) const
{
return nsSVGFEColorMatrixElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
return SVGFEColorMatrixElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
(aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::in ||
aAttribute == nsGkAtoms::type ||
@ -243,21 +247,21 @@ nsSVGFEColorMatrixElement::AttributeAffectsRendering(int32_t aNameSpaceID,
// nsSVGElement methods
nsSVGElement::EnumAttributesInfo
nsSVGFEColorMatrixElement::GetEnumInfo()
SVGFEColorMatrixElement::GetEnumInfo()
{
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
ArrayLength(sEnumInfo));
}
nsSVGElement::StringAttributesInfo
nsSVGFEColorMatrixElement::GetStringInfo()
SVGFEColorMatrixElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
nsSVGElement::NumberListAttributesInfo
nsSVGFEColorMatrixElement::GetNumberListInfo()
SVGFEColorMatrixElement::GetNumberListInfo()
{
return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
ArrayLength(sNumberListInfo));

View File

@ -6,27 +6,41 @@
#ifndef mozilla_dom_SVGFEColorMatrixElement_h
#define mozilla_dom_SVGFEColorMatrixElement_h
typedef nsSVGFE nsSVGFEColorMatrixElementBase;
#include "nsSVGEnum.h"
#include "nsSVGFilters.h"
#include "SVGAnimatedNumberList.h"
nsresult NS_NewSVGFEColorMatrixElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
namespace mozilla {
namespace dom {
class nsSVGFEColorMatrixElement : public nsSVGFEColorMatrixElementBase,
public nsIDOMSVGFEColorMatrixElement
typedef nsSVGFE SVGFEColorMatrixElementBase;
static const unsigned short SVG_FECOLORMATRIX_TYPE_UNKNOWN = 0;
static const unsigned short SVG_FECOLORMATRIX_TYPE_MATRIX = 1;
static const unsigned short SVG_FECOLORMATRIX_TYPE_SATURATE = 2;
static const unsigned short SVG_FECOLORMATRIX_TYPE_HUE_ROTATE = 3;
static const unsigned short SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA = 4;
class SVGFEColorMatrixElement : public SVGFEColorMatrixElementBase,
public nsIDOMSVGElement
{
friend nsresult NS_NewSVGFEColorMatrixElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
friend nsresult (::NS_NewSVGFEColorMatrixElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo));
protected:
nsSVGFEColorMatrixElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGFEColorMatrixElementBase(aNodeInfo) {}
SVGFEColorMatrixElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: SVGFEColorMatrixElementBase(aNodeInfo)
{
SetIsDOMBinding();
}
virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
// FE Base
NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFEColorMatrixElementBase::)
virtual nsresult Filter(nsSVGFilterInstance* aInstance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
@ -36,19 +50,20 @@ public:
virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
// Color Matrix
NS_DECL_NSIDOMSVGFECOLORMATRIXELEMENT
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEColorMatrixElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(SVGFEColorMatrixElementBase::)
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<nsIDOMSVGAnimatedEnumeration> Type();
already_AddRefed<DOMSVGAnimatedNumberList> Values();
protected:
virtual bool OperatesOnPremultipledAlpha(int32_t) { return false; }

View File

@ -48,8 +48,6 @@
#undef LoadImage
#endif
#define NUM_ENTRIES_IN_4x5_MATRIX 20
using namespace mozilla;
using namespace mozilla::dom;

View File

@ -809,8 +809,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
// SVG element classes
NS_DEFINE_CLASSINFO_DATA(TimeEvent, nsEventSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFEColorMatrixElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFECompositeElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFEConvolveMatrixElement, nsElementSH,
@ -2236,12 +2234,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGFEColorMatrixElement, nsIDOMSVGFEColorMatrixElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFEColorMatrixElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFilterPrimitiveStandardAttributes)
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGFECompositeElement, nsIDOMSVGFECompositeElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFECompositeElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFilterPrimitiveStandardAttributes)

View File

@ -122,7 +122,6 @@ DOMCI_CLASS(SVGDocument)
// SVG element classes
DOMCI_CLASS(TimeEvent)
DOMCI_CLASS(SVGFEColorMatrixElement)
DOMCI_CLASS(SVGFECompositeElement)
DOMCI_CLASS(SVGFEConvolveMatrixElement)
DOMCI_CLASS(SVGFEDiffuseLightingElement)

View File

@ -21,22 +21,6 @@ interface nsIDOMSVGFilterPrimitiveStandardAttributes : nsIDOMSVGElement
readonly attribute nsIDOMSVGAnimatedString result;
};
[scriptable, uuid(a73ab3fb-05fa-4153-95e7-b2194b90e57c)]
interface nsIDOMSVGFEColorMatrixElement : nsIDOMSVGFilterPrimitiveStandardAttributes
{
// Color Matrix Types
const unsigned short SVG_FECOLORMATRIX_TYPE_UNKNOWN = 0;
const unsigned short SVG_FECOLORMATRIX_TYPE_MATRIX = 1;
const unsigned short SVG_FECOLORMATRIX_TYPE_SATURATE = 2;
const unsigned short SVG_FECOLORMATRIX_TYPE_HUE_ROTATE = 3;
const unsigned short SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA = 4;
readonly attribute nsIDOMSVGAnimatedString in1;
readonly attribute nsIDOMSVGAnimatedEnumeration type;
// SVGAnimatedNumberList
readonly attribute nsISupports values;
};
[scriptable, uuid(f264fd1f-b272-4796-99b5-68c90cbd030c)]
interface nsIDOMSVGFECompositeElement : nsIDOMSVGFilterPrimitiveStandardAttributes
{

View File

@ -0,0 +1,30 @@
/* -*- 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 SVGAnimatedString;
interface SVGFEColorMatrixElement : SVGElement {
// Color Matrix Types
const unsigned short SVG_FECOLORMATRIX_TYPE_UNKNOWN = 0;
const unsigned short SVG_FECOLORMATRIX_TYPE_MATRIX = 1;
const unsigned short SVG_FECOLORMATRIX_TYPE_SATURATE = 2;
const unsigned short SVG_FECOLORMATRIX_TYPE_HUEROTATE = 3;
const unsigned short SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA = 4;
readonly attribute SVGAnimatedString in1;
readonly attribute SVGAnimatedEnumeration type;
readonly attribute SVGAnimatedNumberList values;
};
SVGFEColorMatrixElement implements SVGFilterPrimitiveStandardAttributes;

View File

@ -182,6 +182,7 @@ webidl_files = \
SVGFilterElement.webidl \
SVGFilterPrimitiveStandardAttributes.webidl \
SVGFEBlendElement.webidl \
SVGFEColorMatrixElement.webidl \
SVGFEComponentTransferElement.webidl \
SVGFEDistantLightElement.webidl \
SVGFEFloodElement.webidl \