SVGGeometryProperty.cpp (2207B)
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 "SVGGeometryProperty.h" 8 9 #include "SVGCircleElement.h" 10 #include "SVGEllipseElement.h" 11 #include "SVGForeignObjectElement.h" 12 #include "SVGImageElement.h" 13 #include "SVGRectElement.h" 14 #include "SVGUseElement.h" 15 16 namespace mozilla::dom::SVGGeometryProperty { 17 18 NonCustomCSSPropertyId AttrEnumToCSSPropId(const SVGElement* aElement, 19 uint8_t aAttrEnum) { 20 // This is a very trivial function only applied to a few elements, 21 // so we want to avoid making it virtual. 22 if (aElement->IsSVGElement(nsGkAtoms::rect)) { 23 return SVGRectElement::GetCSSPropertyIdForAttrEnum(aAttrEnum); 24 } 25 if (aElement->IsSVGElement(nsGkAtoms::circle)) { 26 return SVGCircleElement::GetCSSPropertyIdForAttrEnum(aAttrEnum); 27 } 28 if (aElement->IsSVGElement(nsGkAtoms::ellipse)) { 29 return SVGEllipseElement::GetCSSPropertyIdForAttrEnum(aAttrEnum); 30 } 31 if (aElement->IsSVGElement(nsGkAtoms::image)) { 32 return SVGImageElement::GetCSSPropertyIdForAttrEnum(aAttrEnum); 33 } 34 if (aElement->IsSVGElement(nsGkAtoms::foreignObject)) { 35 return SVGForeignObjectElement::GetCSSPropertyIdForAttrEnum(aAttrEnum); 36 } 37 if (aElement->IsSVGElement(nsGkAtoms::use)) { 38 return SVGUseElement::GetCSSPropertyIdForAttrEnum(aAttrEnum); 39 } 40 return eCSSProperty_UNKNOWN; 41 } 42 43 bool IsNonNegativeGeometryProperty(NonCustomCSSPropertyId aProp) { 44 return aProp == eCSSProperty_r || aProp == eCSSProperty_rx || 45 aProp == eCSSProperty_ry || aProp == eCSSProperty_width || 46 aProp == eCSSProperty_height; 47 } 48 49 bool ElementMapsLengthsToStyle(SVGElement const* aElement) { 50 return aElement->IsAnyOfSVGElements(nsGkAtoms::rect, nsGkAtoms::circle, 51 nsGkAtoms::ellipse, nsGkAtoms::image, 52 nsGkAtoms::foreignObject, nsGkAtoms::use); 53 } 54 55 } // namespace mozilla::dom::SVGGeometryProperty