SVGMaskElement.cpp (3647B)
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/SVGMaskElement.h" 8 9 #include "mozilla/AlreadyAddRefed.h" 10 #include "mozilla/dom/SVGLengthBinding.h" 11 #include "mozilla/dom/SVGMaskElementBinding.h" 12 #include "mozilla/dom/SVGUnitTypesBinding.h" 13 #include "nsGkAtoms.h" 14 15 NS_IMPL_NS_NEW_SVG_ELEMENT(Mask) 16 17 namespace mozilla::dom { 18 19 using namespace SVGUnitTypes_Binding; 20 21 JSObject* SVGMaskElement::WrapNode(JSContext* aCx, 22 JS::Handle<JSObject*> aGivenProto) { 23 return SVGMaskElement_Binding::Wrap(aCx, this, aGivenProto); 24 } 25 26 //--------------------- Masks ------------------------ 27 28 SVGElement::LengthInfo SVGMaskElement::sLengthInfo[4] = { 29 {nsGkAtoms::x, -10, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 30 SVGContentUtils::X}, 31 {nsGkAtoms::y, -10, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 32 SVGContentUtils::Y}, 33 {nsGkAtoms::width, 120, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 34 SVGContentUtils::X}, 35 {nsGkAtoms::height, 120, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, 36 SVGContentUtils::Y}, 37 }; 38 39 SVGElement::EnumInfo SVGMaskElement::sEnumInfo[2] = { 40 {nsGkAtoms::maskUnits, sSVGUnitTypesMap, SVG_UNIT_TYPE_OBJECTBOUNDINGBOX}, 41 {nsGkAtoms::maskContentUnits, sSVGUnitTypesMap, 42 SVG_UNIT_TYPE_USERSPACEONUSE}}; 43 44 //---------------------------------------------------------------------- 45 // Implementation 46 47 SVGMaskElement::SVGMaskElement( 48 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 49 : SVGMaskElementBase(std::move(aNodeInfo)) {} 50 51 //---------------------------------------------------------------------- 52 // nsINode method 53 54 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMaskElement) 55 56 //---------------------------------------------------------------------- 57 58 already_AddRefed<DOMSVGAnimatedEnumeration> SVGMaskElement::MaskUnits() { 59 return mEnumAttributes[MASKUNITS].ToDOMAnimatedEnum(this); 60 } 61 62 already_AddRefed<DOMSVGAnimatedEnumeration> SVGMaskElement::MaskContentUnits() { 63 return mEnumAttributes[MASKCONTENTUNITS].ToDOMAnimatedEnum(this); 64 } 65 66 already_AddRefed<DOMSVGAnimatedLength> SVGMaskElement::X() { 67 return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this); 68 } 69 70 already_AddRefed<DOMSVGAnimatedLength> SVGMaskElement::Y() { 71 return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this); 72 } 73 74 already_AddRefed<DOMSVGAnimatedLength> SVGMaskElement::Width() { 75 return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this); 76 } 77 78 already_AddRefed<DOMSVGAnimatedLength> SVGMaskElement::Height() { 79 return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this); 80 } 81 82 //---------------------------------------------------------------------- 83 // SVGElement methods 84 85 /* virtual */ 86 bool SVGMaskElement::HasValidDimensions() const { 87 return (!mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() || 88 mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0) && 89 (!mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() || 90 mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0); 91 } 92 93 SVGElement::LengthAttributesInfo SVGMaskElement::GetLengthInfo() { 94 return LengthAttributesInfo(mLengthAttributes, sLengthInfo, 95 std::size(sLengthInfo)); 96 } 97 98 SVGElement::EnumAttributesInfo SVGMaskElement::GetEnumInfo() { 99 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, std::size(sEnumInfo)); 100 } 101 102 } // namespace mozilla::dom