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 != static_cast<unsigned short>(CSSPrimitiveValue::UnitType::Unkn own) |
46 return static_cast<SVGLengthType>(type); | 46 && type <= static_cast<unsigned short>(CSSPrimitiveValue::UnitType::Pica s); |
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); | |
fs
2015/10/30 19:50:00
I think this function should map LengthTypeNumber
Stephen Chennney
2015/11/03 21:59:41
Yes. Done.
| |
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: | |
fs
2015/10/30 19:50:00
...and if the above was true, this would not be a
Stephen Chennney
2015/11/03 21:59:41
Yes. Done, or at least about to be tested.
| |
66 case CSSPrimitiveValue::UnitType::UserUnits: | |
67 return LengthTypeNumber; | |
68 case CSSPrimitiveValue::UnitType::Percentage: | |
69 return LengthTypePercentage; | |
70 case CSSPrimitiveValue::UnitType::Ems: | |
71 return LengthTypeEMS; | |
72 case CSSPrimitiveValue::UnitType::Exs: | |
73 return LengthTypeEXS; | |
74 case CSSPrimitiveValue::UnitType::Pixels: | |
75 return LengthTypePX; | |
76 case CSSPrimitiveValue::UnitType::Centimeters: | |
77 return LengthTypeCM; | |
78 case CSSPrimitiveValue::UnitType::Millimeters: | |
79 return LengthTypeMM; | |
80 case CSSPrimitiveValue::UnitType::Inches: | |
81 return LengthTypeIN; | |
82 case CSSPrimitiveValue::UnitType::Points: | |
83 return LengthTypePT; | |
84 case CSSPrimitiveValue::UnitType::Picas: | |
85 return LengthTypePC; | |
86 default: | |
87 return LengthTypeUnknown; | |
88 } | |
89 } | |
54 } // namespace | 90 } // namespace |
55 | 91 |
56 SVGLengthType SVGLengthTearOff::unitType() | 92 SVGLengthType SVGLengthTearOff::unitType() |
57 { | 93 { |
58 return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown; | 94 return hasExposedLengthUnit() ? toSVGLengthType(target()->typeWithCalcResolv ed()) : LengthTypeUnknown; |
59 } | 95 } |
60 | 96 |
61 SVGLengthMode SVGLengthTearOff::unitMode() | 97 SVGLengthMode SVGLengthTearOff::unitMode() |
62 { | 98 { |
63 return target()->unitMode(); | 99 return target()->unitMode(); |
64 } | 100 } |
65 | 101 |
66 float SVGLengthTearOff::value(ExceptionState& exceptionState) | 102 float SVGLengthTearOff::value(ExceptionState& exceptionState) |
67 { | 103 { |
68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { | 104 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 commitChange(); | 168 commitChange(); |
133 } | 169 } |
134 | 170 |
135 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) | 171 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) |
136 { | 172 { |
137 if (isImmutable()) { | 173 if (isImmutable()) { |
138 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); | 174 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); |
139 return; | 175 return; |
140 } | 176 } |
141 | 177 |
142 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 178 if (!isValidLengthUnit(unitType)) { |
143 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi th unknown or invalid units (" + String::number(unitType) + ")."); | 179 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi th unknown or invalid units (" + String::number(unitType) + ")."); |
144 return; | 180 return; |
145 } | 181 } |
146 | 182 |
147 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecified Units); | 183 target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUn its); |
148 commitChange(); | 184 commitChange(); |
149 } | 185 } |
150 | 186 |
151 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio nState& exceptionState) | 187 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio nState& exceptionState) |
152 { | 188 { |
153 if (isImmutable()) { | 189 if (isImmutable()) { |
154 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); | 190 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); |
155 return; | 191 return; |
156 } | 192 } |
157 | 193 |
158 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 194 if (!isValidLengthUnit(unitType)) { |
159 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u nknown or invalid units (" + String::number(unitType) + ")."); | 195 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u nknown or invalid units (" + String::number(unitType) + ")."); |
160 return; | 196 return; |
161 } | 197 } |
162 | 198 |
163 if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(uni tType))) | 199 if ((target()->isRelative() || SVGLength::isRelativeUnit(toCSSUnitType(unitT ype))) |
164 && !canResolveRelativeUnits(contextElement())) { | 200 && !canResolveRelativeUnits(contextElement())) { |
165 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); | 201 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); |
166 return; | 202 return; |
167 } | 203 } |
168 | 204 |
169 SVGLengthContext lengthContext(contextElement()); | 205 SVGLengthContext lengthContext(contextElement()); |
170 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); | 206 target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext); |
171 commitChange(); | 207 commitChange(); |
172 } | 208 } |
173 | 209 |
174 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName) | 210 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName) |
175 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) | 211 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) |
176 { | 212 { |
177 } | 213 } |
178 | 214 |
179 } | 215 } |
OLD | NEW |