1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/SVGFEOffsetElement.h"
8 #include "mozilla/dom/SVGFEOffsetElementBinding.h"
9 #include "mozilla/SVGFilterInstance.h"
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/dom/BindContext.h"
13 NS_IMPL_NS_NEW_SVG_ELEMENT(FEOffset
)
15 using namespace mozilla::gfx
;
17 namespace mozilla::dom
{
19 JSObject
* SVGFEOffsetElement::WrapNode(JSContext
* aCx
,
20 JS::Handle
<JSObject
*> aGivenProto
) {
21 return SVGFEOffsetElement_Binding::Wrap(aCx
, this, aGivenProto
);
24 SVGElement::NumberInfo
SVGFEOffsetElement::sNumberInfo
[2] = {
25 {nsGkAtoms::dx
, 0}, {nsGkAtoms::dy
, 0}};
27 SVGElement::StringInfo
SVGFEOffsetElement::sStringInfo
[2] = {
28 {nsGkAtoms::result
, kNameSpaceID_None
, true},
29 {nsGkAtoms::in
, kNameSpaceID_None
, true}};
31 //----------------------------------------------------------------------
34 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEOffsetElement
)
36 //----------------------------------------------------------------------
38 already_AddRefed
<DOMSVGAnimatedString
> SVGFEOffsetElement::In1() {
39 return mStringAttributes
[IN1
].ToDOMAnimatedString(this);
42 already_AddRefed
<DOMSVGAnimatedNumber
> SVGFEOffsetElement::Dx() {
43 return mNumberAttributes
[DX
].ToDOMAnimatedNumber(this);
46 already_AddRefed
<DOMSVGAnimatedNumber
> SVGFEOffsetElement::Dy() {
47 return mNumberAttributes
[DY
].ToDOMAnimatedNumber(this);
50 FilterPrimitiveDescription
SVGFEOffsetElement::GetPrimitiveDescription(
51 SVGFilterInstance
* aInstance
, const IntRect
& aFilterSubregion
,
52 const nsTArray
<bool>& aInputsAreTainted
,
53 nsTArray
<RefPtr
<SourceSurface
>>& aInputImages
) {
54 OffsetAttributes atts
;
55 IntPoint
offset(int32_t(aInstance
->GetPrimitiveNumber(
56 SVGContentUtils::X
, &mNumberAttributes
[DX
])),
57 int32_t(aInstance
->GetPrimitiveNumber(
58 SVGContentUtils::Y
, &mNumberAttributes
[DY
])));
60 return FilterPrimitiveDescription(AsVariant(std::move(atts
)));
63 bool SVGFEOffsetElement::AttributeAffectsRendering(int32_t aNameSpaceID
,
64 nsAtom
* aAttribute
) const {
65 return SVGFEOffsetElementBase::AttributeAffectsRendering(aNameSpaceID
,
67 (aNameSpaceID
== kNameSpaceID_None
&&
68 (aAttribute
== nsGkAtoms::in
|| aAttribute
== nsGkAtoms::dx
||
69 aAttribute
== nsGkAtoms::dy
));
72 void SVGFEOffsetElement::GetSourceImageNames(
73 nsTArray
<SVGStringInfo
>& aSources
) {
74 aSources
.AppendElement(SVGStringInfo(&mStringAttributes
[IN1
], this));
77 nsresult
SVGFEOffsetElement::BindToTree(BindContext
& aCtx
, nsINode
& aParent
) {
78 if (aCtx
.InComposedDoc()) {
79 aCtx
.OwnerDoc().SetUseCounter(eUseCounter_custom_feOffset
);
82 return SVGFEOffsetElementBase::BindToTree(aCtx
, aParent
);
85 //----------------------------------------------------------------------
88 SVGElement::NumberAttributesInfo
SVGFEOffsetElement::GetNumberInfo() {
89 return NumberAttributesInfo(mNumberAttributes
, sNumberInfo
,
90 std::size(sNumberInfo
));
93 SVGElement::StringAttributesInfo
SVGFEOffsetElement::GetStringInfo() {
94 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
95 std::size(sStringInfo
));
98 } // namespace mozilla::dom