SVGFilterElement.cpp (4335B)
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/. */ 6 7 #include "mozilla/dom/SVGFilterElement.h" 8 9 #include "mozilla/AlreadyAddRefed.h" 10 #include "mozilla/dom/SVGFilterElementBinding.h" 11 #include "mozilla/dom/SVGLengthBinding.h" 12 #include "mozilla/dom/SVGUnitTypesBinding.h" 13 #include "nsGkAtoms.h" 14 #include "nsQueryObject.h" 15 16 NS_IMPL_NS_NEW_SVG_ELEMENT(Filter) 17 18 namespace mozilla::dom { 19 20 using namespace SVGUnitTypes_Binding; 21 22 JSObject* SVGFilterElement::WrapNode(JSContext* aCx, 23 JS::Handle<JSObject*> aGivenProto) { 24 return SVGFilterElement_Binding::Wrap(aCx, this, aGivenProto); 25 } 26 27 SVGElement::LengthInfo SVGFilterElement::sLengthInfo[4] = { 28 {nsGkAtoms::x, -10, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 29 SVGContentUtils::X}, 30 {nsGkAtoms::y, -10, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 31 SVGContentUtils::Y}, 32 {nsGkAtoms::width, 120, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 33 SVGContentUtils::X}, 34 {nsGkAtoms::height, 120, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 35 SVGContentUtils::Y}, 36 }; 37 38 SVGElement::EnumInfo SVGFilterElement::sEnumInfo[2] = { 39 {nsGkAtoms::filterUnits, sSVGUnitTypesMap, SVG_UNIT_TYPE_OBJECTBOUNDINGBOX}, 40 {nsGkAtoms::primitiveUnits, sSVGUnitTypesMap, 41 SVG_UNIT_TYPE_USERSPACEONUSE}}; 42 43 SVGElement::StringInfo SVGFilterElement::sStringInfo[2] = { 44 {nsGkAtoms::href, kNameSpaceID_None, true}, 45 {nsGkAtoms::href, kNameSpaceID_XLink, true}}; 46 47 //---------------------------------------------------------------------- 48 // Implementation 49 50 SVGFilterElement::SVGFilterElement( 51 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 52 : SVGFilterElementBase(std::move(aNodeInfo)) {} 53 54 //---------------------------------------------------------------------- 55 // nsINode methods 56 57 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFilterElement) 58 59 //---------------------------------------------------------------------- 60 61 already_AddRefed<DOMSVGAnimatedLength> SVGFilterElement::X() { 62 return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this); 63 } 64 65 already_AddRefed<DOMSVGAnimatedLength> SVGFilterElement::Y() { 66 return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this); 67 } 68 69 already_AddRefed<DOMSVGAnimatedLength> SVGFilterElement::Width() { 70 return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this); 71 } 72 73 already_AddRefed<DOMSVGAnimatedLength> SVGFilterElement::Height() { 74 return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this); 75 } 76 77 already_AddRefed<DOMSVGAnimatedEnumeration> SVGFilterElement::FilterUnits() { 78 return mEnumAttributes[FILTERUNITS].ToDOMAnimatedEnum(this); 79 } 80 81 already_AddRefed<DOMSVGAnimatedEnumeration> SVGFilterElement::PrimitiveUnits() { 82 return mEnumAttributes[PRIMITIVEUNITS].ToDOMAnimatedEnum(this); 83 } 84 85 already_AddRefed<DOMSVGAnimatedString> SVGFilterElement::Href() { 86 return mStringAttributes[HREF].IsExplicitlySet() || 87 !mStringAttributes[XLINK_HREF].IsExplicitlySet() 88 ? mStringAttributes[HREF].ToDOMAnimatedString(this) 89 : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this); 90 } 91 92 //---------------------------------------------------------------------- 93 // SVGElement methods 94 95 /* virtual */ 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); 101 } 102 103 SVGElement::LengthAttributesInfo SVGFilterElement::GetLengthInfo() { 104 return LengthAttributesInfo(mLengthAttributes, sLengthInfo, 105 std::size(sLengthInfo)); 106 } 107 108 SVGElement::EnumAttributesInfo SVGFilterElement::GetEnumInfo() { 109 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, std::size(sEnumInfo)); 110 } 111 112 SVGElement::StringAttributesInfo SVGFilterElement::GetStringInfo() { 113 return StringAttributesInfo(mStringAttributes, sStringInfo, 114 std::size(sStringInfo)); 115 } 116 117 } // namespace mozilla::dom