Chromium Code Reviews| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 69 |
| 70 template<typename CharType> | 70 template<typename CharType> |
| 71 SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end) | 71 SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end) |
| 72 { | 72 { |
| 73 if (ptr == end) | 73 if (ptr == end) |
| 74 return LengthTypeNumber; | 74 return LengthTypeNumber; |
| 75 | 75 |
| 76 const UChar firstChar = *ptr; | 76 const UChar firstChar = *ptr; |
| 77 | 77 |
| 78 if (++ptr == end) | 78 if (++ptr == end) |
| 79 return firstChar == '%' ? LengthTypePercentage : LengthTypeUnknown; | 79 return firstChar == '%' ? LengthTypePercentage : (isSVGSpace(firstChar) ? LengthTypeNumber : LengthTypeUnknown); |
|
pdr.
2014/06/02 14:35:19
This isn't needed: if the first character is a per
fs
2014/06/03 14:35:37
Nested ternary expressions FTW? =)
if (firstChar
| |
| 80 | 80 |
| 81 const UChar secondChar = *ptr; | 81 const UChar secondChar = *ptr; |
| 82 ptr++; | |
| 82 | 83 |
| 83 if (++ptr != end) | 84 skipOptionalSVGSpaces(ptr, end); |
| 84 return LengthTypeUnknown; | |
| 85 | 85 |
| 86 if (firstChar == 'e' && secondChar == 'm') | 86 if (ptr == end) { |
| 87 return LengthTypeEMS; | 87 if (firstChar == 'e' && secondChar == 'm') |
| 88 if (firstChar == 'e' && secondChar == 'x') | 88 return LengthTypeEMS; |
| 89 return LengthTypeEXS; | 89 if (firstChar == 'e' && secondChar == 'x') |
| 90 if (firstChar == 'p' && secondChar == 'x') | 90 return LengthTypeEXS; |
| 91 return LengthTypePX; | 91 if (firstChar == 'p' && secondChar == 'x') |
| 92 if (firstChar == 'c' && secondChar == 'm') | 92 return LengthTypePX; |
| 93 return LengthTypeCM; | 93 if (firstChar == 'c' && secondChar == 'm') |
| 94 if (firstChar == 'm' && secondChar == 'm') | 94 return LengthTypeCM; |
| 95 return LengthTypeMM; | 95 if (firstChar == 'm' && secondChar == 'm') |
| 96 if (firstChar == 'i' && secondChar == 'n') | 96 return LengthTypeMM; |
| 97 return LengthTypeIN; | 97 if (firstChar == 'i' && secondChar == 'n') |
| 98 if (firstChar == 'p' && secondChar == 't') | 98 return LengthTypeIN; |
| 99 return LengthTypePT; | 99 if (firstChar == 'p' && secondChar == 't') |
| 100 if (firstChar == 'p' && secondChar == 'c') | 100 return LengthTypePT; |
| 101 return LengthTypePC; | 101 if (firstChar == 'p' && secondChar == 'c') |
| 102 return LengthTypePC; | |
| 103 if (isSVGSpace(secondChar)) { | |
| 104 if (isSVGSpace(firstChar)) | |
| 105 return LengthTypeNumber; | |
|
pdr.
2014/06/02 14:35:19
Two spaces are a number?
fs
2014/06/03 14:35:37
More like "two spaces are not a unit".
"42 "
An
| |
| 106 if (firstChar == '%') | |
| 107 return LengthTypePercentage; | |
| 108 } | |
| 109 } | |
| 102 | 110 |
| 103 return LengthTypeUnknown; | 111 return LengthTypeUnknown; |
| 104 } | 112 } |
| 105 | 113 |
| 106 } // namespace | 114 } // namespace |
| 107 | 115 |
| 108 SVGLength::SVGLength(SVGLengthMode mode) | 116 SVGLength::SVGLength(SVGLengthMode mode) |
| 109 : SVGPropertyBase(classType()) | 117 : SVGPropertyBase(classType()) |
| 110 , m_valueInSpecifiedUnits(0) | 118 , m_valueInSpecifiedUnits(0) |
| 111 , m_unitMode(mode) | 119 , m_unitMode(mode) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 190 |
| 183 return m_valueInSpecifiedUnits; | 191 return m_valueInSpecifiedUnits; |
| 184 } | 192 } |
| 185 | 193 |
| 186 template<typename CharType> | 194 template<typename CharType> |
| 187 static bool parseValueInternal(const String& string, float& convertedNumber, SVG LengthType& type) | 195 static bool parseValueInternal(const String& string, float& convertedNumber, SVG LengthType& type) |
| 188 { | 196 { |
| 189 const CharType* ptr = string.getCharacters<CharType>(); | 197 const CharType* ptr = string.getCharacters<CharType>(); |
| 190 const CharType* end = ptr + string.length(); | 198 const CharType* end = ptr + string.length(); |
| 191 | 199 |
| 192 if (!parseNumber(ptr, end, convertedNumber, false)) | 200 if (!parseNumber(ptr, end, convertedNumber, ALLOW_LEADING)) |
| 193 return false; | 201 return false; |
| 194 | 202 |
| 195 type = stringToLengthType(ptr, end); | 203 type = stringToLengthType(ptr, end); |
| 196 ASSERT(ptr <= end); | 204 ASSERT(ptr <= end); |
| 197 if (type == LengthTypeUnknown) | 205 if (type == LengthTypeUnknown) |
| 198 return false; | 206 return false; |
| 199 | 207 |
| 200 return true; | 208 return true; |
| 201 } | 209 } |
| 202 | 210 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 466 |
| 459 float SVGLength::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, SVGEleme nt* contextElement) | 467 float SVGLength::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, SVGEleme nt* contextElement) |
| 460 { | 468 { |
| 461 SVGLengthContext lengthContext(contextElement); | 469 SVGLengthContext lengthContext(contextElement); |
| 462 RefPtr<SVGLength> toLength = toSVGLength(toValue); | 470 RefPtr<SVGLength> toLength = toSVGLength(toValue); |
| 463 | 471 |
| 464 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length Context, IGNORE_EXCEPTION)); | 472 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length Context, IGNORE_EXCEPTION)); |
| 465 } | 473 } |
| 466 | 474 |
| 467 } | 475 } |
| OLD | NEW |