Bug 847120: Move SVGFEOffsetElement to its own file r=Ms2ger

--HG--
rename : content/svg/content/src/nsSVGFilters.cpp => content/svg/content/src/SVGFEOffsetElement.cpp
rename : content/svg/content/src/nsSVGFilters.cpp => content/svg/content/src/SVGFEOffsetElement.h
This commit is contained in:
David Zbarsky 2013-03-21 13:38:28 -04:00
Родитель a0b9ad9084
Коммит c71f2af036
4 изменённых файлов: 233 добавлений и 204 удалений

Просмотреть файл

@ -87,6 +87,7 @@ CPPSRCS = \
SVGFEImageElement.cpp \
SVGFEMergeElement.cpp \
SVGFEMergeNodeElement.cpp \
SVGFEOffsetElement.cpp \
SVGFEPointLightElement.cpp \
SVGFETileElement.cpp \
SVGFilterElement.cpp \
@ -193,6 +194,7 @@ EXPORTS_mozilla/dom = \
SVGFEImageElement.h \
SVGFEMergeElement.h \
SVGFEMergeNodeElement.h \
SVGFEOffsetElement.h \
SVGFEPointLightElement.h \
SVGFETileElement.h \
SVGFilterElement.h \

Просмотреть файл

@ -0,0 +1,153 @@
/* a*- Mode: C++; 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/. */
#include "mozilla/dom/SVGFEOffsetElement.h"
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEOffset)
namespace mozilla {
namespace dom {
nsSVGElement::NumberInfo nsSVGFEOffsetElement::sNumberInfo[2] =
{
{ &nsGkAtoms::dx, 0, false },
{ &nsGkAtoms::dy, 0, false }
};
nsSVGElement::StringInfo nsSVGFEOffsetElement::sStringInfo[2] =
{
{ &nsGkAtoms::result, kNameSpaceID_None, true },
{ &nsGkAtoms::in, kNameSpaceID_None, true }
};
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGFEOffsetElement,nsSVGFEOffsetElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGFEOffsetElement,nsSVGFEOffsetElementBase)
DOMCI_NODE_DATA(SVGFEOffsetElement, nsSVGFEOffsetElement)
NS_INTERFACE_TABLE_HEAD(nsSVGFEOffsetElement)
NS_NODE_INTERFACE_TABLE5(nsSVGFEOffsetElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGFilterPrimitiveStandardAttributes,
nsIDOMSVGFEOffsetElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGFEOffsetElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGFEOffsetElementBase)
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGFEOffsetElement)
//----------------------------------------------------------------------
// nsIDOMSVGFEOffsetElement methods
/* readonly attribute nsIDOMSVGAnimatedString in1; */
NS_IMETHODIMP nsSVGFEOffsetElement::GetIn1(nsIDOMSVGAnimatedString * *aIn)
{
return mStringAttributes[IN1].ToDOMAnimatedString(aIn, this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber dx; */
NS_IMETHODIMP nsSVGFEOffsetElement::GetDx(nsIDOMSVGAnimatedNumber * *aDx)
{
return mNumberAttributes[DX].ToDOMAnimatedNumber(aDx, this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber dy; */
NS_IMETHODIMP nsSVGFEOffsetElement::GetDy(nsIDOMSVGAnimatedNumber * *aDy)
{
return mNumberAttributes[DY].ToDOMAnimatedNumber(aDy, this);
}
nsIntPoint
nsSVGFEOffsetElement::GetOffset(const nsSVGFilterInstance& aInstance)
{
return nsIntPoint(int32_t(aInstance.GetPrimitiveNumber(
SVGContentUtils::X, &mNumberAttributes[DX])),
int32_t(aInstance.GetPrimitiveNumber(
SVGContentUtils::Y, &mNumberAttributes[DY])));
}
nsresult
nsSVGFEOffsetElement::Filter(nsSVGFilterInstance *instance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& rect)
{
nsIntPoint offset = GetOffset(*instance);
gfxContext ctx(aTarget->mImage);
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
// Ensure rendering is limited to the filter primitive subregion
ctx.Clip(aTarget->mFilterPrimitiveSubregion);
ctx.Translate(gfxPoint(offset.x, offset.y));
ctx.SetSource(aSources[0]->mImage);
ctx.Paint();
return NS_OK;
}
bool
nsSVGFEOffsetElement::AttributeAffectsRendering(int32_t aNameSpaceID,
nsIAtom* aAttribute) const
{
return nsSVGFEOffsetElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
(aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::in ||
aAttribute == nsGkAtoms::dx ||
aAttribute == nsGkAtoms::dy));
}
void
nsSVGFEOffsetElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
{
aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
}
nsIntRect
nsSVGFEOffsetElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
const nsSVGFilterInstance& aInstance)
{
return aSourceBBoxes[0] + GetOffset(aInstance);
}
nsIntRect
nsSVGFEOffsetElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance)
{
return aSourceChangeBoxes[0] + GetOffset(aInstance);
}
void
nsSVGFEOffsetElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance)
{
aSourceBBoxes[0] = aTargetBBox - GetOffset(aInstance);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::NumberAttributesInfo
nsSVGFEOffsetElement::GetNumberInfo()
{
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
ArrayLength(sNumberInfo));
}
nsSVGElement::StringAttributesInfo
nsSVGFEOffsetElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,78 @@
/* a*- Mode: C++; 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/. */
#ifndef mozilla_dom_SVGFEOffsetElement_h
#define mozilla_dom_SVGFEOffsetElement_h
#include "nsSVGFilter.h"
namespace mozilla {
namespace dom {
typedef nsSVGFE nsSVGFEOffsetElementBase;
class nsSVGFEOffsetElement : public nsSVGFEOffsetElementBase,
public nsIDOMSVGFEOffsetElement
{
friend nsresult NS_NewSVGFEOffsetElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
protected:
nsSVGFEOffsetElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGFEOffsetElementBase(aNodeInfo) {}
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
// FE Base
NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFEOffsetElementBase::)
virtual nsresult Filter(nsSVGFilterInstance* aInstance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& aDataRect);
virtual bool AttributeAffectsRendering(
int32_t aNameSpaceID, nsIAtom* aAttribute) const;
virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
virtual nsIntRect ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
const nsSVGFilterInstance& aInstance);
virtual void ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance);
virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance);
// Offset
NS_DECL_NSIDOMSVGFEOFFSETELEMENT
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEOffsetElementBase::)
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; }
protected:
nsIntPoint GetOffset(const nsSVGFilterInstance& aInstance);
virtual NumberAttributesInfo GetNumberInfo();
virtual StringAttributesInfo GetStringInfo();
enum { DX, DY };
nsSVGNumber2 mNumberAttributes[2];
static NumberInfo sNumberInfo[2];
enum { RESULT, IN1 };
nsSVGString mStringAttributes[2];
static StringInfo sStringInfo[2];
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGFEOffsetElement_h

Просмотреть файл

@ -659,210 +659,6 @@ NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEFuncAElement)
} // namespace dom
} // namespace mozilla
//---------------------Offset------------------------
typedef nsSVGFE nsSVGFEOffsetElementBase;
class nsSVGFEOffsetElement : public nsSVGFEOffsetElementBase,
public nsIDOMSVGFEOffsetElement
{
friend nsresult NS_NewSVGFEOffsetElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
protected:
nsSVGFEOffsetElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGFEOffsetElementBase(aNodeInfo) {}
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
// FE Base
NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFEOffsetElementBase::)
virtual nsresult Filter(nsSVGFilterInstance* aInstance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& aDataRect);
virtual bool AttributeAffectsRendering(
int32_t aNameSpaceID, nsIAtom* aAttribute) const;
virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
virtual nsIntRect ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
const nsSVGFilterInstance& aInstance);
virtual void ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance);
virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance);
// Offset
NS_DECL_NSIDOMSVGFEOFFSETELEMENT
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEOffsetElementBase::)
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; }
protected:
nsIntPoint GetOffset(const nsSVGFilterInstance& aInstance);
virtual NumberAttributesInfo GetNumberInfo();
virtual StringAttributesInfo GetStringInfo();
enum { DX, DY };
nsSVGNumber2 mNumberAttributes[2];
static NumberInfo sNumberInfo[2];
enum { RESULT, IN1 };
nsSVGString mStringAttributes[2];
static StringInfo sStringInfo[2];
};
nsSVGElement::NumberInfo nsSVGFEOffsetElement::sNumberInfo[2] =
{
{ &nsGkAtoms::dx, 0, false },
{ &nsGkAtoms::dy, 0, false }
};
nsSVGElement::StringInfo nsSVGFEOffsetElement::sStringInfo[2] =
{
{ &nsGkAtoms::result, kNameSpaceID_None, true },
{ &nsGkAtoms::in, kNameSpaceID_None, true }
};
NS_IMPL_NS_NEW_SVG_ELEMENT(FEOffset)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGFEOffsetElement,nsSVGFEOffsetElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGFEOffsetElement,nsSVGFEOffsetElementBase)
DOMCI_NODE_DATA(SVGFEOffsetElement, nsSVGFEOffsetElement)
NS_INTERFACE_TABLE_HEAD(nsSVGFEOffsetElement)
NS_NODE_INTERFACE_TABLE5(nsSVGFEOffsetElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGFilterPrimitiveStandardAttributes,
nsIDOMSVGFEOffsetElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGFEOffsetElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGFEOffsetElementBase)
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGFEOffsetElement)
//----------------------------------------------------------------------
// nsIDOMSVGFEOffsetElement methods
/* readonly attribute nsIDOMSVGAnimatedString in1; */
NS_IMETHODIMP nsSVGFEOffsetElement::GetIn1(nsIDOMSVGAnimatedString * *aIn)
{
return mStringAttributes[IN1].ToDOMAnimatedString(aIn, this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber dx; */
NS_IMETHODIMP nsSVGFEOffsetElement::GetDx(nsIDOMSVGAnimatedNumber * *aDx)
{
return mNumberAttributes[DX].ToDOMAnimatedNumber(aDx, this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber dy; */
NS_IMETHODIMP nsSVGFEOffsetElement::GetDy(nsIDOMSVGAnimatedNumber * *aDy)
{
return mNumberAttributes[DY].ToDOMAnimatedNumber(aDy, this);
}
nsIntPoint
nsSVGFEOffsetElement::GetOffset(const nsSVGFilterInstance& aInstance)
{
return nsIntPoint(int32_t(aInstance.GetPrimitiveNumber(
SVGContentUtils::X, &mNumberAttributes[DX])),
int32_t(aInstance.GetPrimitiveNumber(
SVGContentUtils::Y, &mNumberAttributes[DY])));
}
nsresult
nsSVGFEOffsetElement::Filter(nsSVGFilterInstance *instance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& rect)
{
nsIntPoint offset = GetOffset(*instance);
gfxContext ctx(aTarget->mImage);
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
// Ensure rendering is limited to the filter primitive subregion
ctx.Clip(aTarget->mFilterPrimitiveSubregion);
ctx.Translate(gfxPoint(offset.x, offset.y));
ctx.SetSource(aSources[0]->mImage);
ctx.Paint();
return NS_OK;
}
bool
nsSVGFEOffsetElement::AttributeAffectsRendering(int32_t aNameSpaceID,
nsIAtom* aAttribute) const
{
return nsSVGFEOffsetElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
(aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::in ||
aAttribute == nsGkAtoms::dx ||
aAttribute == nsGkAtoms::dy));
}
void
nsSVGFEOffsetElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
{
aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
}
nsIntRect
nsSVGFEOffsetElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
const nsSVGFilterInstance& aInstance)
{
return aSourceBBoxes[0] + GetOffset(aInstance);
}
nsIntRect
nsSVGFEOffsetElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance)
{
return aSourceChangeBoxes[0] + GetOffset(aInstance);
}
void
nsSVGFEOffsetElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance)
{
aSourceBBoxes[0] = aTargetBBox - GetOffset(aInstance);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::NumberAttributesInfo
nsSVGFEOffsetElement::GetNumberInfo()
{
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
ArrayLength(sNumberInfo));
}
nsSVGElement::StringAttributesInfo
nsSVGFEOffsetElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
//---------------------Turbulence------------------------
typedef nsSVGFE nsSVGFETurbulenceElementBase;