OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "core/svg/SVGLengthTearOff.h" | 33 #include "core/svg/SVGLengthTearOff.h" |
34 | 34 |
35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/v8/ExceptionState.h" |
36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/svg/SVGElement.h" | 37 #include "core/svg/SVGElement.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 inline SVGLengthType toSVGLengthType(unsigned short type) | 43 inline bool isValidLengthUnit(unsigned short type) |
44 { | 44 { |
45 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); | 45 return type != (unsigned short)CSSPrimitiveValue::UnitType::Unknown |
46 return static_cast<SVGLengthType>(type); | 46 && type <= (unsigned short)CSSPrimitiveValue::UnitType::Picas; |
fs
2015/10/23 20:28:59
Nit: Use static_cast
| |
47 } | 47 } |
48 | 48 |
49 inline bool canResolveRelativeUnits(const SVGElement* contextElement) | 49 inline bool canResolveRelativeUnits(const SVGElement* contextElement) |
50 { | 50 { |
51 return contextElement && contextElement->inDocument(); | 51 return contextElement && contextElement->inDocument(); |
52 } | 52 } |
53 | 53 |
54 inline CSSPrimitiveValue::UnitType toCSSUnitType(unsigned short type) | |
55 { | |
56 ASSERT(isValidLengthUnit(type)); | |
57 return static_cast<CSSPrimitiveValue::UnitType>(type); | |
58 } | |
59 | |
60 inline SVGLengthType toSVGLengthType(CSSPrimitiveValue::UnitType type) | |
61 { | |
62 switch (type) { | |
63 case CSSPrimitiveValue::UnitType::Unknown: | |
64 return LengthTypeUnknown; | |
65 case CSSPrimitiveValue::UnitType::Number: | |
66 return LengthTypeNumber; | |
67 case CSSPrimitiveValue::UnitType::Percentage: | |
68 return LengthTypePercentage; | |
69 case CSSPrimitiveValue::UnitType::Ems: | |
70 return LengthTypeEMS; | |
71 case CSSPrimitiveValue::UnitType::Exs: | |
72 return LengthTypeEXS; | |
73 case CSSPrimitiveValue::UnitType::Pixels: | |
74 return LengthTypePX; | |
75 case CSSPrimitiveValue::UnitType::Centimeters: | |
76 return LengthTypeCM; | |
77 case CSSPrimitiveValue::UnitType::Millimeters: | |
78 return LengthTypeMM; | |
79 case CSSPrimitiveValue::UnitType::Inches: | |
80 return LengthTypeIN; | |
81 case CSSPrimitiveValue::UnitType::Points: | |
82 return LengthTypePT; | |
83 case CSSPrimitiveValue::UnitType::Picas: | |
84 return LengthTypePC; | |
85 default: | |
86 return LengthTypeUnknown; | |
87 } | |
88 } | |
54 } // namespace | 89 } // namespace |
55 | 90 |
56 SVGLengthType SVGLengthTearOff::unitType() | 91 SVGLengthType SVGLengthTearOff::unitType() |
57 { | 92 { |
58 return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown; | 93 return hasExposedLengthUnit() ? toSVGLengthType(target()->typeWithCalcResolv ed()) : LengthTypeUnknown; |
59 } | 94 } |
60 | 95 |
61 SVGLengthMode SVGLengthTearOff::unitMode() | 96 SVGLengthMode SVGLengthTearOff::unitMode() |
62 { | 97 { |
63 return target()->unitMode(); | 98 return target()->unitMode(); |
64 } | 99 } |
65 | 100 |
66 float SVGLengthTearOff::value(ExceptionState& exceptionState) | 101 float SVGLengthTearOff::value(ExceptionState& exceptionState) |
67 { | 102 { |
68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { | 103 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 commitChange(); | 167 commitChange(); |
133 } | 168 } |
134 | 169 |
135 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) | 170 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) |
136 { | 171 { |
137 if (isImmutable()) { | 172 if (isImmutable()) { |
138 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); | 173 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); |
139 return; | 174 return; |
140 } | 175 } |
141 | 176 |
142 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 177 if (!isValidLengthUnit(unitType)) { |
143 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi th unknown or invalid units (" + String::number(unitType) + ")."); | 178 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi th unknown or invalid units (" + String::number(unitType) + ")."); |
144 return; | 179 return; |
145 } | 180 } |
146 | 181 |
147 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecified Units); | 182 target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUn its); |
148 commitChange(); | 183 commitChange(); |
149 } | 184 } |
150 | 185 |
151 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio nState& exceptionState) | 186 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio nState& exceptionState) |
152 { | 187 { |
153 if (isImmutable()) { | 188 if (isImmutable()) { |
154 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); | 189 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); |
155 return; | 190 return; |
156 } | 191 } |
157 | 192 |
158 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 193 if (!isValidLengthUnit(unitType)) { |
159 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u nknown or invalid units (" + String::number(unitType) + ")."); | 194 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u nknown or invalid units (" + String::number(unitType) + ")."); |
160 return; | 195 return; |
161 } | 196 } |
162 | 197 |
163 if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(uni tType))) | 198 if ((target()->isRelative() || SVGLength::isRelativeUnit(toCSSUnitType(unitT ype))) |
164 && !canResolveRelativeUnits(contextElement())) { | 199 && !canResolveRelativeUnits(contextElement())) { |
165 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); | 200 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); |
166 return; | 201 return; |
167 } | 202 } |
168 | 203 |
169 SVGLengthContext lengthContext(contextElement()); | 204 SVGLengthContext lengthContext(contextElement()); |
170 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); | 205 target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext); |
171 commitChange(); | 206 commitChange(); |
172 } | 207 } |
173 | 208 |
174 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName) | 209 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName) |
175 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) | 210 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) |
176 { | 211 { |
177 } | 212 } |
178 | 213 |
179 } | 214 } |
OLD | NEW |