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/SVGFilterElement.h"
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/ArrayUtils.h"
12 #include "mozilla/dom/SVGFilterElementBinding.h"
13 #include "mozilla/dom/SVGLengthBinding.h"
14 #include "mozilla/dom/SVGUnitTypesBinding.h"
15 #include "nsQueryObject.h"
17 NS_IMPL_NS_NEW_SVG_ELEMENT(Filter
)
19 namespace mozilla::dom
{
21 using namespace SVGUnitTypes_Binding
;
23 JSObject
* SVGFilterElement::WrapNode(JSContext
* aCx
,
24 JS::Handle
<JSObject
*> aGivenProto
) {
25 return SVGFilterElement_Binding::Wrap(aCx
, this, aGivenProto
);
28 SVGElement::LengthInfo
SVGFilterElement::sLengthInfo
[4] = {
29 {nsGkAtoms::x
, -10, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE
,
31 {nsGkAtoms::y
, -10, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE
,
33 {nsGkAtoms::width
, 120, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE
,
35 {nsGkAtoms::height
, 120, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE
,
39 SVGElement::EnumInfo
SVGFilterElement::sEnumInfo
[2] = {
40 {nsGkAtoms::filterUnits
, sSVGUnitTypesMap
, SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
},
41 {nsGkAtoms::primitiveUnits
, sSVGUnitTypesMap
,
42 SVG_UNIT_TYPE_USERSPACEONUSE
}};
44 SVGElement::StringInfo
SVGFilterElement::sStringInfo
[2] = {
45 {nsGkAtoms::href
, kNameSpaceID_None
, true},
46 {nsGkAtoms::href
, kNameSpaceID_XLink
, true}};
48 //----------------------------------------------------------------------
51 SVGFilterElement::SVGFilterElement(
52 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
53 : SVGFilterElementBase(std::move(aNodeInfo
)) {}
55 //----------------------------------------------------------------------
58 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFilterElement
)
60 //----------------------------------------------------------------------
62 already_AddRefed
<DOMSVGAnimatedLength
> SVGFilterElement::X() {
63 return mLengthAttributes
[ATTR_X
].ToDOMAnimatedLength(this);
66 already_AddRefed
<DOMSVGAnimatedLength
> SVGFilterElement::Y() {
67 return mLengthAttributes
[ATTR_Y
].ToDOMAnimatedLength(this);
70 already_AddRefed
<DOMSVGAnimatedLength
> SVGFilterElement::Width() {
71 return mLengthAttributes
[ATTR_WIDTH
].ToDOMAnimatedLength(this);
74 already_AddRefed
<DOMSVGAnimatedLength
> SVGFilterElement::Height() {
75 return mLengthAttributes
[ATTR_HEIGHT
].ToDOMAnimatedLength(this);
78 already_AddRefed
<DOMSVGAnimatedEnumeration
> SVGFilterElement::FilterUnits() {
79 return mEnumAttributes
[FILTERUNITS
].ToDOMAnimatedEnum(this);
82 already_AddRefed
<DOMSVGAnimatedEnumeration
> SVGFilterElement::PrimitiveUnits() {
83 return mEnumAttributes
[PRIMITIVEUNITS
].ToDOMAnimatedEnum(this);
86 already_AddRefed
<DOMSVGAnimatedString
> SVGFilterElement::Href() {
87 return mStringAttributes
[HREF
].IsExplicitlySet()
88 ? mStringAttributes
[HREF
].ToDOMAnimatedString(this)
89 : mStringAttributes
[XLINK_HREF
].ToDOMAnimatedString(this);
92 //----------------------------------------------------------------------
96 bool SVGFilterElement::HasValidDimensions() const {
97 return (!mLengthAttributes
[ATTR_WIDTH
].IsExplicitlySet() ||
98 mLengthAttributes
[ATTR_WIDTH
].GetAnimValInSpecifiedUnits() > 0) &&
99 (!mLengthAttributes
[ATTR_HEIGHT
].IsExplicitlySet() ||
100 mLengthAttributes
[ATTR_HEIGHT
].GetAnimValInSpecifiedUnits() > 0);
103 SVGElement::LengthAttributesInfo
SVGFilterElement::GetLengthInfo() {
104 return LengthAttributesInfo(mLengthAttributes
, sLengthInfo
,
105 std::size(sLengthInfo
));
108 SVGElement::EnumAttributesInfo
SVGFilterElement::GetEnumInfo() {
109 return EnumAttributesInfo(mEnumAttributes
, sEnumInfo
, std::size(sEnumInfo
));
112 SVGElement::StringAttributesInfo
SVGFilterElement::GetStringInfo() {
113 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
114 std::size(sStringInfo
));
117 } // namespace mozilla::dom