OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2007 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "bindings/v8/ExceptionState.h" | 27 #include "bindings/v8/ExceptionState.h" |
28 #include "bindings/v8/ExceptionStatePlaceholder.h" | 28 #include "bindings/v8/ExceptionStatePlaceholder.h" |
29 #include "core/css/CSSPrimitiveValue.h" | 29 #include "core/css/CSSPrimitiveValue.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "core/svg/SVGParserUtilities.h" | 31 #include "core/svg/SVGParserUtilities.h" |
32 #include "wtf/MathExtras.h" | 32 #include "wtf/MathExtras.h" |
33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
| 37 static inline SVGLengthMode toSVGLengthMode(unsigned short mode) |
| 38 { |
| 39 ASSERT(mode >= LengthModeWidth && mode <= LengthModeOther); |
| 40 return static_cast<SVGLengthMode>(mode); |
| 41 } |
| 42 |
| 43 static inline SVGLengthType toSVGLengthType(unsigned short type) |
| 44 { |
| 45 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); |
| 46 return static_cast<SVGLengthType>(type); |
| 47 } |
| 48 |
37 static inline unsigned int storeUnit(SVGLengthMode mode, SVGLengthType type) | 49 static inline unsigned int storeUnit(SVGLengthMode mode, SVGLengthType type) |
38 { | 50 { |
39 return (mode << 4) | type; | 51 return (mode << 4) | type; |
40 } | 52 } |
41 | 53 |
42 static inline SVGLengthMode extractMode(unsigned int unit) | 54 static inline SVGLengthMode extractMode(unsigned int unit) |
43 { | 55 { |
44 unsigned int mode = unit >> 4; | 56 unsigned int mode = unit >> 4; |
45 return static_cast<SVGLengthMode>(mode); | 57 return toSVGLengthMode(mode); |
46 } | 58 } |
47 | 59 |
48 static inline SVGLengthType extractType(unsigned int unit) | 60 static inline SVGLengthType extractType(unsigned int unit) |
49 { | 61 { |
50 unsigned int mode = unit >> 4; | 62 unsigned int mode = unit >> 4; |
51 unsigned int type = unit ^ (mode << 4); | 63 unsigned int type = unit ^ (mode << 4); |
52 return static_cast<SVGLengthType>(type); | 64 return toSVGLengthType(type); |
53 } | 65 } |
54 | 66 |
55 static inline String lengthTypeToString(SVGLengthType type) | 67 static inline String lengthTypeToString(SVGLengthType type) |
56 { | 68 { |
57 switch (type) { | 69 switch (type) { |
58 case LengthTypeUnknown: | 70 case LengthTypeUnknown: |
59 case LengthTypeNumber: | 71 case LengthTypeNumber: |
60 return ""; | 72 return ""; |
61 case LengthTypePercentage: | 73 case LengthTypePercentage: |
62 return "%"; | 74 return "%"; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(extractT
ype(m_unit)); | 271 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(extractT
ype(m_unit)); |
260 } | 272 } |
261 | 273 |
262 void SVGLength::newValueSpecifiedUnits(unsigned short type, float value, Excepti
onState& es) | 274 void SVGLength::newValueSpecifiedUnits(unsigned short type, float value, Excepti
onState& es) |
263 { | 275 { |
264 if (type == LengthTypeUnknown || type > LengthTypePC) { | 276 if (type == LengthTypeUnknown || type > LengthTypePC) { |
265 es.throwDOMException(NotSupportedError); | 277 es.throwDOMException(NotSupportedError); |
266 return; | 278 return; |
267 } | 279 } |
268 | 280 |
269 m_unit = storeUnit(extractMode(m_unit), static_cast<SVGLengthType>(type)); | 281 m_unit = storeUnit(extractMode(m_unit), toSVGLengthType(type)); |
270 m_valueInSpecifiedUnits = value; | 282 m_valueInSpecifiedUnits = value; |
271 } | 283 } |
272 | 284 |
273 void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGLengthCont
ext& context, ExceptionState& es) | 285 void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGLengthCont
ext& context, ExceptionState& es) |
274 { | 286 { |
275 if (type == LengthTypeUnknown || type > LengthTypePC) { | 287 if (type == LengthTypeUnknown || type > LengthTypePC) { |
276 es.throwDOMException(NotSupportedError); | 288 es.throwDOMException(NotSupportedError); |
277 return; | 289 return; |
278 } | 290 } |
279 | 291 |
280 float valueInUserUnits = value(context, es); | 292 float valueInUserUnits = value(context, es); |
281 if (es.hadException()) | 293 if (es.hadException()) |
282 return; | 294 return; |
283 | 295 |
284 unsigned int originalUnitAndType = m_unit; | 296 unsigned int originalUnitAndType = m_unit; |
285 m_unit = storeUnit(extractMode(m_unit), static_cast<SVGLengthType>(type)); | 297 m_unit = storeUnit(extractMode(m_unit), toSVGLengthType(type)); |
286 setValue(valueInUserUnits, context, es); | 298 setValue(valueInUserUnits, context, es); |
287 if (!es.hadException()) | 299 if (!es.hadException()) |
288 return; | 300 return; |
289 | 301 |
290 // Eventually restore old unit and type | 302 // Eventually restore old unit and type |
291 m_unit = originalUnitAndType; | 303 m_unit = originalUnitAndType; |
292 } | 304 } |
293 | 305 |
294 SVGLength SVGLength::fromCSSPrimitiveValue(CSSPrimitiveValue* value) | 306 SVGLength SVGLength::fromCSSPrimitiveValue(CSSPrimitiveValue* value) |
295 { | 307 { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 s_lengthModeMap.set(SVGNames::startOffsetAttr, LengthModeWidth); | 427 s_lengthModeMap.set(SVGNames::startOffsetAttr, LengthModeWidth); |
416 } | 428 } |
417 | 429 |
418 if (s_lengthModeMap.contains(attrName)) | 430 if (s_lengthModeMap.contains(attrName)) |
419 return s_lengthModeMap.get(attrName); | 431 return s_lengthModeMap.get(attrName); |
420 | 432 |
421 return LengthModeOther; | 433 return LengthModeOther; |
422 } | 434 } |
423 | 435 |
424 } | 436 } |
OLD | NEW |