Bug 1635304 [wpt PR 23392] - Remove erroneous named properties object test, a=testonly
[gecko.git] / dom / svg / SVGFEDisplacementMapElement.cpp
blob5743bab03f06ba346ec8a333a3d575f8bc717016
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/SVGFEDisplacementMapElement.h"
8 #include "mozilla/dom/SVGFEDisplacementMapElementBinding.h"
9 #include "nsSVGFilterInstance.h"
10 #include "nsSVGUtils.h"
12 NS_IMPL_NS_NEW_SVG_ELEMENT(FEDisplacementMap)
14 using namespace mozilla::gfx;
16 namespace mozilla {
17 namespace dom {
19 JSObject* SVGFEDisplacementMapElement::WrapNode(
20 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
21 return SVGFEDisplacementMapElement_Binding::Wrap(aCx, this, aGivenProto);
24 SVGElement::NumberInfo SVGFEDisplacementMapElement::sNumberInfo[1] = {
25 {nsGkAtoms::scale, 0, false},
28 SVGEnumMapping SVGFEDisplacementMapElement::sChannelMap[] = {
29 {nsGkAtoms::R, SVG_CHANNEL_R},
30 {nsGkAtoms::G, SVG_CHANNEL_G},
31 {nsGkAtoms::B, SVG_CHANNEL_B},
32 {nsGkAtoms::A, SVG_CHANNEL_A},
33 {nullptr, 0}};
35 SVGElement::EnumInfo SVGFEDisplacementMapElement::sEnumInfo[2] = {
36 {nsGkAtoms::xChannelSelector, sChannelMap, SVG_CHANNEL_A},
37 {nsGkAtoms::yChannelSelector, sChannelMap, SVG_CHANNEL_A}};
39 SVGElement::StringInfo SVGFEDisplacementMapElement::sStringInfo[3] = {
40 {nsGkAtoms::result, kNameSpaceID_None, true},
41 {nsGkAtoms::in, kNameSpaceID_None, true},
42 {nsGkAtoms::in2, kNameSpaceID_None, true}};
44 //----------------------------------------------------------------------
45 // nsINode methods
47 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDisplacementMapElement)
49 //----------------------------------------------------------------------
51 already_AddRefed<DOMSVGAnimatedString> SVGFEDisplacementMapElement::In1() {
52 return mStringAttributes[IN1].ToDOMAnimatedString(this);
55 already_AddRefed<DOMSVGAnimatedString> SVGFEDisplacementMapElement::In2() {
56 return mStringAttributes[IN2].ToDOMAnimatedString(this);
59 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDisplacementMapElement::Scale() {
60 return mNumberAttributes[SCALE].ToDOMAnimatedNumber(this);
63 already_AddRefed<DOMSVGAnimatedEnumeration>
64 SVGFEDisplacementMapElement::XChannelSelector() {
65 return mEnumAttributes[CHANNEL_X].ToDOMAnimatedEnum(this);
68 already_AddRefed<DOMSVGAnimatedEnumeration>
69 SVGFEDisplacementMapElement::YChannelSelector() {
70 return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(this);
73 FilterPrimitiveDescription SVGFEDisplacementMapElement::GetPrimitiveDescription(
74 nsSVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
75 const nsTArray<bool>& aInputsAreTainted,
76 nsTArray<RefPtr<SourceSurface>>& aInputImages) {
77 if (aInputsAreTainted[1]) {
78 // If the map is tainted, refuse to apply the effect and act as a
79 // pass-through filter instead, as required by the spec.
80 OffsetAttributes atts;
81 atts.mValue = IntPoint(0, 0);
82 return FilterPrimitiveDescription(AsVariant(std::move(atts)));
85 float scale = aInstance->GetPrimitiveNumber(SVGContentUtils::XY,
86 &mNumberAttributes[SCALE]);
87 uint32_t xChannel = mEnumAttributes[CHANNEL_X].GetAnimValue();
88 uint32_t yChannel = mEnumAttributes[CHANNEL_Y].GetAnimValue();
89 DisplacementMapAttributes atts;
90 atts.mScale = scale;
91 atts.mXChannel = xChannel;
92 atts.mYChannel = yChannel;
93 return FilterPrimitiveDescription(AsVariant(std::move(atts)));
96 bool SVGFEDisplacementMapElement::AttributeAffectsRendering(
97 int32_t aNameSpaceID, nsAtom* aAttribute) const {
98 return SVGFEDisplacementMapElementBase::AttributeAffectsRendering(
99 aNameSpaceID, aAttribute) ||
100 (aNameSpaceID == kNameSpaceID_None &&
101 (aAttribute == nsGkAtoms::in || aAttribute == nsGkAtoms::in2 ||
102 aAttribute == nsGkAtoms::scale ||
103 aAttribute == nsGkAtoms::xChannelSelector ||
104 aAttribute == nsGkAtoms::yChannelSelector));
107 void SVGFEDisplacementMapElement::GetSourceImageNames(
108 nsTArray<SVGStringInfo>& aSources) {
109 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
110 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN2], this));
113 //----------------------------------------------------------------------
114 // SVGElement methods
116 SVGElement::NumberAttributesInfo SVGFEDisplacementMapElement::GetNumberInfo() {
117 return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
118 ArrayLength(sNumberInfo));
121 SVGElement::EnumAttributesInfo SVGFEDisplacementMapElement::GetEnumInfo() {
122 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
125 SVGElement::StringAttributesInfo SVGFEDisplacementMapElement::GetStringInfo() {
126 return StringAttributesInfo(mStringAttributes, sStringInfo,
127 ArrayLength(sStringInfo));
130 } // namespace dom
131 } // namespace mozilla