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 "SVGGeometryProperty.h"
8 #include "SVGCircleElement.h"
9 #include "SVGEllipseElement.h"
10 #include "SVGForeignObjectElement.h"
11 #include "SVGImageElement.h"
12 #include "SVGRectElement.h"
13 #include "SVGUseElement.h"
14 #include "nsCSSValue.h"
16 namespace mozilla::dom::SVGGeometryProperty
{
18 nsCSSUnit
SpecifiedUnitTypeToCSSUnit(uint8_t aSpecifiedUnit
) {
19 switch (aSpecifiedUnit
) {
20 case SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
:
21 case SVGLength_Binding::SVG_LENGTHTYPE_PX
:
22 return nsCSSUnit::eCSSUnit_Pixel
;
24 case SVGLength_Binding::SVG_LENGTHTYPE_MM
:
25 return nsCSSUnit::eCSSUnit_Millimeter
;
27 case SVGLength_Binding::SVG_LENGTHTYPE_CM
:
28 return nsCSSUnit::eCSSUnit_Centimeter
;
30 case SVGLength_Binding::SVG_LENGTHTYPE_IN
:
31 return nsCSSUnit::eCSSUnit_Inch
;
33 case SVGLength_Binding::SVG_LENGTHTYPE_PT
:
34 return nsCSSUnit::eCSSUnit_Point
;
36 case SVGLength_Binding::SVG_LENGTHTYPE_PC
:
37 return nsCSSUnit::eCSSUnit_Pica
;
39 case SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE
:
40 return nsCSSUnit::eCSSUnit_Percent
;
42 case SVGLength_Binding::SVG_LENGTHTYPE_EMS
:
43 return nsCSSUnit::eCSSUnit_EM
;
45 case SVGLength_Binding::SVG_LENGTHTYPE_EXS
:
46 return nsCSSUnit::eCSSUnit_XHeight
;
49 MOZ_ASSERT_UNREACHABLE("Unknown unit type");
50 return nsCSSUnit::eCSSUnit_Pixel
;
54 nsCSSPropertyID
AttrEnumToCSSPropId(const SVGElement
* aElement
,
56 // This is a very trivial function only applied to a few elements,
57 // so we want to avoid making it virtual.
58 if (aElement
->IsSVGElement(nsGkAtoms::rect
)) {
59 return SVGRectElement::GetCSSPropertyIdForAttrEnum(aAttrEnum
);
61 if (aElement
->IsSVGElement(nsGkAtoms::circle
)) {
62 return SVGCircleElement::GetCSSPropertyIdForAttrEnum(aAttrEnum
);
64 if (aElement
->IsSVGElement(nsGkAtoms::ellipse
)) {
65 return SVGEllipseElement::GetCSSPropertyIdForAttrEnum(aAttrEnum
);
67 if (aElement
->IsSVGElement(nsGkAtoms::image
)) {
68 return SVGImageElement::GetCSSPropertyIdForAttrEnum(aAttrEnum
);
70 if (aElement
->IsSVGElement(nsGkAtoms::foreignObject
)) {
71 return SVGForeignObjectElement::GetCSSPropertyIdForAttrEnum(aAttrEnum
);
73 if (aElement
->IsSVGElement(nsGkAtoms::use
)) {
74 return SVGUseElement::GetCSSPropertyIdForAttrEnum(aAttrEnum
);
76 return eCSSProperty_UNKNOWN
;
79 bool IsNonNegativeGeometryProperty(nsCSSPropertyID aProp
) {
80 return aProp
== eCSSProperty_r
|| aProp
== eCSSProperty_rx
||
81 aProp
== eCSSProperty_ry
|| aProp
== eCSSProperty_width
||
82 aProp
== eCSSProperty_height
;
85 bool ElementMapsLengthsToStyle(SVGElement
const* aElement
) {
86 return aElement
->IsAnyOfSVGElements(nsGkAtoms::rect
, nsGkAtoms::circle
,
87 nsGkAtoms::ellipse
, nsGkAtoms::image
,
88 nsGkAtoms::foreignObject
, nsGkAtoms::use
);
91 } // namespace mozilla::dom::SVGGeometryProperty