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 != CSSPrimitiveValue::CSS_UNKNOWN && type <= CSSPrimitiveValue::
CSS_PC; |
46 return static_cast<SVGLengthType>(type); | |
47 } | 46 } |
48 | 47 |
49 inline bool canResolveRelativeUnits(const SVGElement* contextElement) | 48 inline bool canResolveRelativeUnits(const SVGElement* contextElement) |
50 { | 49 { |
51 return contextElement && contextElement->inDocument(); | 50 return contextElement && contextElement->inDocument(); |
52 } | 51 } |
53 | 52 |
| 53 inline CSSPrimitiveValue::UnitType toCSSUnitType(unsigned short type) |
| 54 { |
| 55 ASSERT(isValidLengthUnit(type)); |
| 56 return static_cast<CSSPrimitiveValue::UnitType>(type); |
| 57 } |
| 58 |
| 59 inline SVGLengthType toSVGLengthType(CSSPrimitiveValue::UnitType type) |
| 60 { |
| 61 switch (type) { |
| 62 case CSSPrimitiveValue::UnitType::CSS_UNKNOWN: |
| 63 return LengthTypeUnknown; |
| 64 case CSSPrimitiveValue::UnitType::CSS_NUMBER: |
| 65 return LengthTypeNumber; |
| 66 case CSSPrimitiveValue::UnitType::CSS_PERCENTAGE: |
| 67 return LengthTypePercentage; |
| 68 case CSSPrimitiveValue::UnitType::CSS_EMS: |
| 69 return LengthTypeEMS; |
| 70 case CSSPrimitiveValue::UnitType::CSS_EXS: |
| 71 return LengthTypeEXS; |
| 72 case CSSPrimitiveValue::UnitType::CSS_PX: |
| 73 return LengthTypePX; |
| 74 case CSSPrimitiveValue::UnitType::CSS_CM: |
| 75 return LengthTypeCM; |
| 76 case CSSPrimitiveValue::UnitType::CSS_MM: |
| 77 return LengthTypeMM; |
| 78 case CSSPrimitiveValue::UnitType::CSS_IN: |
| 79 return LengthTypeIN; |
| 80 case CSSPrimitiveValue::UnitType::CSS_PT: |
| 81 return LengthTypePT; |
| 82 case CSSPrimitiveValue::UnitType::CSS_PC: |
| 83 return LengthTypePC; |
| 84 default: |
| 85 return LengthTypeUnknown; |
| 86 } |
| 87 } |
54 } // namespace | 88 } // namespace |
55 | 89 |
56 SVGLengthType SVGLengthTearOff::unitType() | 90 SVGLengthType SVGLengthTearOff::unitType() |
57 { | 91 { |
58 return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown; | 92 return hasExposedLengthUnit() ? toSVGLengthType(target()->primitiveType()) :
LengthTypeUnknown; |
59 } | 93 } |
60 | 94 |
61 SVGLengthMode SVGLengthTearOff::unitMode() | 95 SVGLengthMode SVGLengthTearOff::unitMode() |
62 { | 96 { |
63 return target()->unitMode(); | 97 return target()->unitMode(); |
64 } | 98 } |
65 | 99 |
66 float SVGLengthTearOff::value(ExceptionState& exceptionState) | 100 float SVGLengthTearOff::value(ExceptionState& exceptionState) |
67 { | 101 { |
68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { | 102 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 commitChange(); | 166 commitChange(); |
133 } | 167 } |
134 | 168 |
135 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) | 169 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) |
136 { | 170 { |
137 if (isImmutable()) { | 171 if (isImmutable()) { |
138 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); | 172 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
139 return; | 173 return; |
140 } | 174 } |
141 | 175 |
142 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 176 if (!isValidLengthUnit(unitType)) { |
143 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi
th unknown or invalid units (" + String::number(unitType) + ")."); | 177 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi
th unknown or invalid units (" + String::number(unitType) + ")."); |
144 return; | 178 return; |
145 } | 179 } |
146 | 180 |
147 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecified
Units); | 181 target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUn
its); |
148 commitChange(); | 182 commitChange(); |
149 } | 183 } |
150 | 184 |
151 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
nState& exceptionState) | 185 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
nState& exceptionState) |
152 { | 186 { |
153 if (isImmutable()) { | 187 if (isImmutable()) { |
154 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); | 188 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
155 return; | 189 return; |
156 } | 190 } |
157 | 191 |
158 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 192 if (!isValidLengthUnit(unitType)) { |
159 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); | 193 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); |
160 return; | 194 return; |
161 } | 195 } |
162 | 196 |
163 if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(uni
tType))) | 197 if ((target()->isRelative() || SVGLength::isRelativeUnit(toCSSUnitType(unitT
ype))) |
164 && !canResolveRelativeUnits(contextElement())) { | 198 && !canResolveRelativeUnits(contextElement())) { |
165 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); | 199 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); |
166 return; | 200 return; |
167 } | 201 } |
168 | 202 |
169 SVGLengthContext lengthContext(contextElement()); | 203 SVGLengthContext lengthContext(contextElement()); |
170 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); | 204 target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext); |
171 commitChange(); | 205 commitChange(); |
172 } | 206 } |
173 | 207 |
174 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) | 208 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) |
175 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) | 209 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) |
176 { | 210 { |
177 } | 211 } |
178 | 212 |
179 } | 213 } |
OLD | NEW |