| 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 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 | 23 |
| 24 #include "core/svg/SVGLength.h" | 24 #include "core/svg/SVGLength.h" |
| 25 | 25 |
| 26 #include "bindings/core/v8/ExceptionState.h" | 26 #include "bindings/core/v8/ExceptionState.h" |
| 27 #include "core/SVGNames.h" | 27 #include "core/SVGNames.h" |
| 28 #include "core/css/CSSPrimitiveValue.h" | 28 #include "core/css/CSSPrimitiveValue.h" |
| 29 #include "core/css/CSSValue.h" |
| 30 #include "core/css/CSSValuePool.h" |
| 31 #include "core/css/parser/CSSParser.h" |
| 29 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 30 #include "core/svg/SVGAnimationElement.h" | 33 #include "core/svg/SVGAnimationElement.h" |
| 31 #include "core/svg/SVGParserUtilities.h" | 34 #include "core/svg/SVGParserUtilities.h" |
| 32 #include "platform/animation/AnimationUtilities.h" | 35 #include "platform/animation/AnimationUtilities.h" |
| 33 #include "wtf/MathExtras.h" | 36 #include "wtf/MathExtras.h" |
| 34 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 35 | 38 |
| 36 namespace blink { | 39 namespace blink { |
| 37 | 40 |
| 38 namespace { | |
| 39 | |
| 40 inline const char* lengthTypeToString(SVGLengthType type) | |
| 41 { | |
| 42 switch (type) { | |
| 43 case LengthTypeUnknown: | |
| 44 case LengthTypeNumber: | |
| 45 return ""; | |
| 46 case LengthTypePercentage: | |
| 47 return "%"; | |
| 48 case LengthTypeEMS: | |
| 49 return "em"; | |
| 50 case LengthTypeEXS: | |
| 51 return "ex"; | |
| 52 case LengthTypePX: | |
| 53 return "px"; | |
| 54 case LengthTypeCM: | |
| 55 return "cm"; | |
| 56 case LengthTypeMM: | |
| 57 return "mm"; | |
| 58 case LengthTypeIN: | |
| 59 return "in"; | |
| 60 case LengthTypePT: | |
| 61 return "pt"; | |
| 62 case LengthTypePC: | |
| 63 return "pc"; | |
| 64 case LengthTypeREMS: | |
| 65 return "rem"; | |
| 66 case LengthTypeCHS: | |
| 67 return "ch"; | |
| 68 } | |
| 69 | |
| 70 ASSERT_NOT_REACHED(); | |
| 71 return ""; | |
| 72 } | |
| 73 | |
| 74 template<typename CharType> | |
| 75 SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end) | |
| 76 { | |
| 77 if (ptr == end) | |
| 78 return LengthTypeNumber; | |
| 79 | |
| 80 SVGLengthType type = LengthTypeUnknown; | |
| 81 const CharType firstChar = *ptr++; | |
| 82 | |
| 83 if (firstChar == '%') { | |
| 84 type = LengthTypePercentage; | |
| 85 } else if (isHTMLSpace<CharType>(firstChar)) { | |
| 86 type = LengthTypeNumber; | |
| 87 } else if (ptr < end) { | |
| 88 const CharType secondChar = *ptr++; | |
| 89 | |
| 90 if (firstChar == 'p') { | |
| 91 if (secondChar == 'x') | |
| 92 type = LengthTypePX; | |
| 93 if (secondChar == 't') | |
| 94 type = LengthTypePT; | |
| 95 if (secondChar == 'c') | |
| 96 type = LengthTypePC; | |
| 97 } else if (firstChar == 'e') { | |
| 98 if (secondChar == 'm') | |
| 99 type = LengthTypeEMS; | |
| 100 if (secondChar == 'x') | |
| 101 type = LengthTypeEXS; | |
| 102 } else if (firstChar == 'r') { | |
| 103 if (secondChar == 'e' && ptr < end) { | |
| 104 const CharType thirdChar = *ptr++; | |
| 105 if (thirdChar == 'm') | |
| 106 type = LengthTypeREMS; | |
| 107 } | |
| 108 } else if (firstChar == 'c') { | |
| 109 if (secondChar == 'h') | |
| 110 type = LengthTypeCHS; | |
| 111 if (secondChar == 'm') | |
| 112 type = LengthTypeCM; | |
| 113 } else if (firstChar == 'm' && secondChar == 'm') { | |
| 114 type = LengthTypeMM; | |
| 115 } else if (firstChar == 'i' && secondChar == 'n') { | |
| 116 type = LengthTypeIN; | |
| 117 } else if (isHTMLSpace<CharType>(firstChar) && isHTMLSpace<CharType>(sec
ondChar)) { | |
| 118 type = LengthTypeNumber; | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 if (!skipOptionalSVGSpaces(ptr, end)) | |
| 123 return type; | |
| 124 | |
| 125 return LengthTypeUnknown; | |
| 126 } | |
| 127 | |
| 128 } // namespace | |
| 129 | |
| 130 SVGLength::SVGLength(SVGLengthMode mode) | 41 SVGLength::SVGLength(SVGLengthMode mode) |
| 131 : SVGPropertyBase(classType()) | 42 : SVGPropertyBase(classType()) |
| 132 , m_valueInSpecifiedUnits(0) | 43 , m_value(cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER)) |
| 133 , m_unitMode(static_cast<unsigned>(mode)) | 44 , m_unitMode(static_cast<unsigned>(mode)) |
| 134 , m_unitType(LengthTypeNumber) | |
| 135 { | 45 { |
| 136 ASSERT(unitMode() == mode); | 46 ASSERT(unitMode() == mode); |
| 137 } | 47 } |
| 138 | 48 |
| 139 SVGLength::SVGLength(const SVGLength& o) | 49 SVGLength::SVGLength(const SVGLength& o) |
| 140 : SVGPropertyBase(classType()) | 50 : SVGPropertyBase(classType()) |
| 141 , m_valueInSpecifiedUnits(o.m_valueInSpecifiedUnits) | 51 , m_value(o.m_value) |
| 142 , m_unitMode(o.m_unitMode) | 52 , m_unitMode(o.m_unitMode) |
| 143 , m_unitType(o.m_unitType) | |
| 144 { | 53 { |
| 145 } | 54 } |
| 146 | 55 |
| 56 DEFINE_TRACE(SVGLength) |
| 57 { |
| 58 visitor->trace(m_value); |
| 59 SVGPropertyBase::trace(visitor); |
| 60 } |
| 61 |
| 147 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::clone() const | 62 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::clone() const |
| 148 { | 63 { |
| 149 return adoptRefWillBeNoop(new SVGLength(*this)); | 64 return adoptRefWillBeNoop(new SVGLength(*this)); |
| 150 } | 65 } |
| 151 | 66 |
| 152 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLength::cloneForAnimation(const Strin
g& value) const | 67 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLength::cloneForAnimation(const Strin
g& value) const |
| 153 { | 68 { |
| 154 RefPtrWillBeRawPtr<SVGLength> length = create(); | 69 RefPtrWillBeRawPtr<SVGLength> length = create(); |
| 155 | 70 |
| 156 length->m_unitMode = m_unitMode; | 71 length->m_unitMode = m_unitMode; |
| 157 length->m_unitType = m_unitType; | |
| 158 | 72 |
| 159 TrackExceptionState exceptionState; | 73 TrackExceptionState exceptionState; |
| 160 length->setValueAsString(value, exceptionState); | 74 length->setValueAsString(value, exceptionState); |
| 161 if (exceptionState.hadException()) { | 75 if (exceptionState.hadException()) { |
| 162 length->m_unitType = LengthTypeNumber; | 76 length->m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_NU
MBER); |
| 163 length->m_valueInSpecifiedUnits = 0; | |
| 164 } | 77 } |
| 165 | 78 |
| 166 return length.release(); | 79 return length.release(); |
| 167 } | 80 } |
| 168 | 81 |
| 169 bool SVGLength::operator==(const SVGLength& other) const | 82 bool SVGLength::operator==(const SVGLength& other) const |
| 170 { | 83 { |
| 171 return m_unitMode == other.m_unitMode | 84 return m_unitMode == other.m_unitMode |
| 172 && m_unitType == other.m_unitType | 85 && m_value == other.m_value; |
| 173 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits; | |
| 174 } | 86 } |
| 175 | 87 |
| 176 float SVGLength::value(const SVGLengthContext& context) const | 88 float SVGLength::value(const SVGLengthContext& context) const |
| 177 { | 89 { |
| 178 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, unitMode(),
unitType()); | 90 return context.convertValueToUserUnits(m_value->getFloatValue(), unitMode(),
m_value->primitiveType()); |
| 179 } | 91 } |
| 180 | 92 |
| 181 void SVGLength::setValue(float value, const SVGLengthContext& context) | 93 void SVGLength::setValue(float value, const SVGLengthContext& context) |
| 182 { | 94 { |
| 183 m_valueInSpecifiedUnits = context.convertValueFromUserUnits(value, unitMode(
), unitType()); | 95 m_value = CSSPrimitiveValue::create( |
| 96 context.convertValueFromUserUnits(value, unitMode(), m_value->primitiveT
ype()), |
| 97 m_value->primitiveType()); |
| 184 } | 98 } |
| 185 | 99 |
| 186 void SVGLength::setUnitType(SVGLengthType type) | 100 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type) |
| 187 { | 101 { |
| 188 ASSERT(type != LengthTypeUnknown && type <= LengthTypeCHS); | 102 ASSERT(type != CSSPrimitiveValue::CSS_UNKNOWN && (type <= CSSPrimitiveValue:
:CSS_PC || type == CSSPrimitiveValue::CSS_CHS || type == CSSPrimitiveValue::CSS_
REMS)); |
| 189 m_unitType = type; | 103 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type); |
| 190 } | 104 } |
| 191 | 105 |
| 192 float SVGLength::valueAsPercentage() const | 106 float SVGLength::valueAsPercentage() const |
| 193 { | 107 { |
| 194 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. | 108 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. |
| 195 if (m_unitType == LengthTypePercentage) { | 109 if (m_value->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE) { |
| 196 // Note: This division is a source of floating point inaccuracy. | 110 // Note: This division is a source of floating point inaccuracy. |
| 197 return m_valueInSpecifiedUnits / 100; | 111 return m_value->getFloatValue() / 100; |
| 198 } | 112 } |
| 199 | 113 |
| 200 return m_valueInSpecifiedUnits; | 114 return m_value->getFloatValue(); |
| 201 } | 115 } |
| 202 | 116 |
| 203 float SVGLength::valueAsPercentage100() const | 117 float SVGLength::valueAsPercentage100() const |
| 204 { | 118 { |
| 205 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. | 119 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. |
| 206 if (m_unitType == LengthTypePercentage) | 120 if (m_value->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE) |
| 207 return m_valueInSpecifiedUnits; | 121 return m_value->getFloatValue(); |
| 208 | 122 |
| 209 return m_valueInSpecifiedUnits * 100; | 123 return m_value->getFloatValue() * 100; |
| 210 } | 124 } |
| 211 | 125 |
| 212 float SVGLength::scaleByPercentage(float input) const | 126 float SVGLength::scaleByPercentage(float input) const |
| 213 { | 127 { |
| 214 float result = input * m_valueInSpecifiedUnits; | 128 float result = input * m_value->getFloatValue(); |
| 215 if (m_unitType == LengthTypePercentage) { | 129 if (m_value->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE) { |
| 216 // Delaying division by 100 as long as possible since it introduces floa
ting point errors. | 130 // Delaying division by 100 as long as possible since it introduces floa
ting point errors. |
| 217 result = result / 100; | 131 result = result / 100; |
| 218 } | 132 } |
| 219 return result; | 133 return result; |
| 220 } | 134 } |
| 221 | 135 |
| 222 template<typename CharType> | |
| 223 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) | |
| 224 { | |
| 225 const CharType* ptr = string.getCharacters<CharType>(); | |
| 226 const CharType* end = ptr + string.length(); | |
| 227 | |
| 228 if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace)) | |
| 229 return false; | |
| 230 | |
| 231 type = stringToLengthType(ptr, end); | |
| 232 ASSERT(ptr <= end); | |
| 233 if (type == LengthTypeUnknown) | |
| 234 return false; | |
| 235 | |
| 236 return true; | |
| 237 } | |
| 238 | |
| 239 void SVGLength::setValueAsString(const String& string, ExceptionState& exception
State) | 136 void SVGLength::setValueAsString(const String& string, ExceptionState& exception
State) |
| 240 { | 137 { |
| 241 if (string.isEmpty()) { | 138 if (string.isEmpty()) { |
| 242 m_unitType = LengthTypeNumber; | 139 m_value = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER); |
| 243 m_valueInSpecifiedUnits = 0; | |
| 244 return; | 140 return; |
| 245 } | 141 } |
| 246 | 142 |
| 247 float convertedNumber = 0; | 143 CSSParserContext svgParserContext(SVGAttributeMode, 0); |
| 248 SVGLengthType type = LengthTypeUnknown; | 144 RefPtrWillBeRawPtr<CSSValue> parsed = CSSParser::parseSingleValue(CSSPropert
yX, string, svgParserContext); |
| 249 | 145 if (!parsed || !parsed->isPrimitiveValue()) { |
| 250 bool success = string.is8Bit() ? | |
| 251 parseValueInternal<LChar>(string, convertedNumber, type) : | |
| 252 parseValueInternal<UChar>(string, convertedNumber, type); | |
| 253 | |
| 254 if (!success) { | |
| 255 exceptionState.throwDOMException(SyntaxError, "The value provided ('" +
string + "') is invalid."); | 146 exceptionState.throwDOMException(SyntaxError, "The value provided ('" +
string + "') is invalid."); |
| 256 return; | 147 return; |
| 257 } | 148 } |
| 258 | 149 |
| 259 m_unitType = type; | 150 ASSERT(parsed->isPrimitiveValue()); |
| 260 m_valueInSpecifiedUnits = convertedNumber; | 151 m_value = toCSSPrimitiveValue(parsed.get()); |
| 261 } | 152 } |
| 262 | 153 |
| 263 String SVGLength::valueAsString() const | 154 String SVGLength::valueAsString() const |
| 264 { | 155 { |
| 265 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(unitType
()); | 156 return m_value->customCSSText(); |
| 266 } | 157 } |
| 267 | 158 |
| 268 void SVGLength::newValueSpecifiedUnits(SVGLengthType type, float value) | 159 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, float v
alue) |
| 269 { | 160 { |
| 270 setUnitType(type); | 161 m_value = CSSPrimitiveValue::create(value, type); |
| 271 m_valueInSpecifiedUnits = value; | |
| 272 } | 162 } |
| 273 | 163 |
| 274 void SVGLength::convertToSpecifiedUnits(SVGLengthType type, const SVGLengthConte
xt& context) | 164 void SVGLength::convertToSpecifiedUnits(CSSPrimitiveValue::UnitType type, const
SVGLengthContext& context) |
| 275 { | 165 { |
| 276 ASSERT(type != LengthTypeUnknown && type <= LengthTypeCHS); | 166 ASSERT(type != CSSPrimitiveValue::CSS_UNKNOWN && (type <= CSSPrimitiveValue:
:CSS_PC || type == CSSPrimitiveValue::CSS_CHS || type == CSSPrimitiveValue::CSS_
REMS)); |
| 277 | |
| 278 float valueInUserUnits = value(context); | 167 float valueInUserUnits = value(context); |
| 279 m_unitType = type; | 168 m_value = CSSPrimitiveValue::create( |
| 280 setValue(valueInUserUnits, context); | 169 context.convertValueFromUserUnits(valueInUserUnits, unitMode(), type), |
| 170 type); |
| 281 } | 171 } |
| 282 | 172 |
| 283 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::fromCSSPrimitiveValue(CSSPrimitiveV
alue* value) | 173 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::fromCSSPrimitiveValue(CSSPrimitiveV
alue* value) |
| 284 { | 174 { |
| 285 ASSERT(value); | 175 ASSERT(value); |
| 286 | |
| 287 SVGLengthType svgType; | |
| 288 switch (value->primitiveType()) { | |
| 289 case CSSPrimitiveValue::CSS_NUMBER: | |
| 290 svgType = LengthTypeNumber; | |
| 291 break; | |
| 292 case CSSPrimitiveValue::CSS_PERCENTAGE: | |
| 293 svgType = LengthTypePercentage; | |
| 294 break; | |
| 295 case CSSPrimitiveValue::CSS_EMS: | |
| 296 svgType = LengthTypeEMS; | |
| 297 break; | |
| 298 case CSSPrimitiveValue::CSS_EXS: | |
| 299 svgType = LengthTypeEXS; | |
| 300 break; | |
| 301 case CSSPrimitiveValue::CSS_PX: | |
| 302 svgType = LengthTypePX; | |
| 303 break; | |
| 304 case CSSPrimitiveValue::CSS_CM: | |
| 305 svgType = LengthTypeCM; | |
| 306 break; | |
| 307 case CSSPrimitiveValue::CSS_MM: | |
| 308 svgType = LengthTypeMM; | |
| 309 break; | |
| 310 case CSSPrimitiveValue::CSS_IN: | |
| 311 svgType = LengthTypeIN; | |
| 312 break; | |
| 313 case CSSPrimitiveValue::CSS_PT: | |
| 314 svgType = LengthTypePT; | |
| 315 break; | |
| 316 case CSSPrimitiveValue::CSS_REMS: | |
| 317 svgType = LengthTypeREMS; | |
| 318 break; | |
| 319 case CSSPrimitiveValue::CSS_CHS: | |
| 320 svgType = LengthTypeCHS; | |
| 321 break; | |
| 322 default: | |
| 323 ASSERT(value->primitiveType() == CSSPrimitiveValue::CSS_PC); | |
| 324 svgType = LengthTypePC; | |
| 325 break; | |
| 326 }; | |
| 327 | |
| 328 RefPtrWillBeRawPtr<SVGLength> length = SVGLength::create(); | 176 RefPtrWillBeRawPtr<SVGLength> length = SVGLength::create(); |
| 329 length->newValueSpecifiedUnits(svgType, value->getFloatValue()); | 177 length->m_value = value; |
| 330 return length.release(); | 178 return length.release(); |
| 331 } | 179 } |
| 332 | 180 |
| 333 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(PassRef
PtrWillBeRawPtr<SVGLength> passLength) | |
| 334 { | |
| 335 RefPtrWillBeRawPtr<SVGLength> length = passLength; | |
| 336 | |
| 337 CSSPrimitiveValue::UnitType cssType = CSSPrimitiveValue::CSS_UNKNOWN; | |
| 338 switch (length->unitType()) { | |
| 339 case LengthTypeUnknown: | |
| 340 break; | |
| 341 case LengthTypeNumber: | |
| 342 cssType = CSSPrimitiveValue::CSS_NUMBER; | |
| 343 break; | |
| 344 case LengthTypePercentage: | |
| 345 cssType = CSSPrimitiveValue::CSS_PERCENTAGE; | |
| 346 break; | |
| 347 case LengthTypeEMS: | |
| 348 cssType = CSSPrimitiveValue::CSS_EMS; | |
| 349 break; | |
| 350 case LengthTypeEXS: | |
| 351 cssType = CSSPrimitiveValue::CSS_EXS; | |
| 352 break; | |
| 353 case LengthTypePX: | |
| 354 cssType = CSSPrimitiveValue::CSS_PX; | |
| 355 break; | |
| 356 case LengthTypeCM: | |
| 357 cssType = CSSPrimitiveValue::CSS_CM; | |
| 358 break; | |
| 359 case LengthTypeMM: | |
| 360 cssType = CSSPrimitiveValue::CSS_MM; | |
| 361 break; | |
| 362 case LengthTypeIN: | |
| 363 cssType = CSSPrimitiveValue::CSS_IN; | |
| 364 break; | |
| 365 case LengthTypePT: | |
| 366 cssType = CSSPrimitiveValue::CSS_PT; | |
| 367 break; | |
| 368 case LengthTypePC: | |
| 369 cssType = CSSPrimitiveValue::CSS_PC; | |
| 370 break; | |
| 371 case LengthTypeREMS: | |
| 372 cssType = CSSPrimitiveValue::CSS_REMS; | |
| 373 break; | |
| 374 case LengthTypeCHS: | |
| 375 cssType = CSSPrimitiveValue::CSS_CHS; | |
| 376 break; | |
| 377 }; | |
| 378 | |
| 379 return CSSPrimitiveValue::create(length->valueInSpecifiedUnits(), cssType); | |
| 380 } | |
| 381 | |
| 382 SVGLengthMode SVGLength::lengthModeForAnimatedLengthAttribute(const QualifiedNam
e& attrName) | 181 SVGLengthMode SVGLength::lengthModeForAnimatedLengthAttribute(const QualifiedNam
e& attrName) |
| 383 { | 182 { |
| 384 typedef HashMap<QualifiedName, SVGLengthMode> LengthModeForLengthAttributeMa
p; | 183 typedef HashMap<QualifiedName, SVGLengthMode> LengthModeForLengthAttributeMa
p; |
| 385 DEFINE_STATIC_LOCAL(LengthModeForLengthAttributeMap, s_lengthModeMap, ()); | 184 DEFINE_STATIC_LOCAL(LengthModeForLengthAttributeMap, s_lengthModeMap, ()); |
| 386 | 185 |
| 387 if (s_lengthModeMap.isEmpty()) { | 186 if (s_lengthModeMap.isEmpty()) { |
| 388 s_lengthModeMap.set(SVGNames::xAttr, SVGLengthMode::Width); | 187 s_lengthModeMap.set(SVGNames::xAttr, SVGLengthMode::Width); |
| 389 s_lengthModeMap.set(SVGNames::yAttr, SVGLengthMode::Height); | 188 s_lengthModeMap.set(SVGNames::yAttr, SVGLengthMode::Height); |
| 390 s_lengthModeMap.set(SVGNames::cxAttr, SVGLengthMode::Width); | 189 s_lengthModeMap.set(SVGNames::cxAttr, SVGLengthMode::Width); |
| 391 s_lengthModeMap.set(SVGNames::cyAttr, SVGLengthMode::Height); | 190 s_lengthModeMap.set(SVGNames::cyAttr, SVGLengthMode::Height); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 413 if (s_lengthModeMap.contains(attrName)) | 212 if (s_lengthModeMap.contains(attrName)) |
| 414 return s_lengthModeMap.get(attrName); | 213 return s_lengthModeMap.get(attrName); |
| 415 | 214 |
| 416 return SVGLengthMode::Other; | 215 return SVGLengthMode::Other; |
| 417 } | 216 } |
| 418 | 217 |
| 419 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::blend(PassRefPtrWillBeRawPtr<SVGLen
gth> passFrom, float progress) const | 218 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::blend(PassRefPtrWillBeRawPtr<SVGLen
gth> passFrom, float progress) const |
| 420 { | 219 { |
| 421 RefPtrWillBeRawPtr<SVGLength> from = passFrom; | 220 RefPtrWillBeRawPtr<SVGLength> from = passFrom; |
| 422 | 221 |
| 423 SVGLengthType toType = unitType(); | 222 CSSPrimitiveValue::UnitType toType = m_value->primitiveType(); |
| 424 SVGLengthType fromType = from->unitType(); | 223 CSSPrimitiveValue::UnitType fromType = from->primitiveType(); |
| 425 if ((from->isZero() && isZero()) | 224 if ((from->isZero() && isZero()) |
| 426 || fromType == LengthTypeUnknown | 225 || fromType == CSSPrimitiveValue::CSS_UNKNOWN |
| 427 || toType == LengthTypeUnknown | 226 || toType == CSSPrimitiveValue::CSS_UNKNOWN |
| 428 || (!from->isZero() && fromType != LengthTypePercentage && toType == Len
gthTypePercentage) | 227 || (!from->isZero() && fromType != CSSPrimitiveValue::CSS_PERCENTAGE &&
toType == CSSPrimitiveValue::CSS_PERCENTAGE) |
| 429 || (!isZero() && fromType == LengthTypePercentage && toType != LengthTyp
ePercentage) | 228 || (!isZero() && fromType == CSSPrimitiveValue::CSS_PERCENTAGE && toType
!= CSSPrimitiveValue::CSS_PERCENTAGE) |
| 430 || (!from->isZero() && !isZero() && (fromType == LengthTypeEMS || fromTy
pe == LengthTypeEXS || fromType == LengthTypeREMS || fromType == LengthTypeCHS)
&& fromType != toType)) | 229 || (!from->isZero() && !isZero() && (fromType == CSSPrimitiveValue::CSS_
EMS || fromType == CSSPrimitiveValue::CSS_EXS || fromType == CSSPrimitiveValue::
CSS_REMS || fromType == CSSPrimitiveValue::CSS_CHS) && fromType != toType)) |
| 431 return clone(); | 230 return clone(); |
| 432 | 231 |
| 433 RefPtrWillBeRawPtr<SVGLength> length = create(); | 232 RefPtrWillBeRawPtr<SVGLength> length = create(); |
| 434 | 233 |
| 435 if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { | 234 if (fromType == CSSPrimitiveValue::CSS_PERCENTAGE || toType == CSSPrimitiveV
alue::CSS_PERCENTAGE) { |
| 436 float fromPercent = from->valueAsPercentage100(); | 235 float fromPercent = from->valueAsPercentage100(); |
| 437 float toPercent = valueAsPercentage100(); | 236 float toPercent = valueAsPercentage100(); |
| 438 length->newValueSpecifiedUnits(LengthTypePercentage, blink::blend(fromPe
rcent, toPercent, progress)); | 237 length->newValueSpecifiedUnits(CSSPrimitiveValue::CSS_PERCENTAGE, blink:
:blend(fromPercent, toPercent, progress)); |
| 439 return length; | 238 return length; |
| 440 } | 239 } |
| 441 | 240 |
| 442 if (fromType == toType || from->isZero() || isZero() || fromType == LengthTy
peEMS || fromType == LengthTypeEXS || fromType == LengthTypeREMS || fromType ==
LengthTypeCHS) { | 241 if (fromType == toType || from->isZero() || isZero() || fromType == CSSPrimi
tiveValue::CSS_EMS || fromType == CSSPrimitiveValue::CSS_EXS || fromType == CSSP
rimitiveValue::CSS_REMS || fromType == CSSPrimitiveValue::CSS_CHS) { |
| 443 float fromValue = from->valueInSpecifiedUnits(); | 242 float fromValue = from->valueInSpecifiedUnits(); |
| 444 float toValue = valueInSpecifiedUnits(); | 243 float toValue = valueInSpecifiedUnits(); |
| 445 if (isZero()) | 244 if (isZero()) |
| 446 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV
alue, progress)); | 245 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV
alue, progress)); |
| 447 else | 246 else |
| 448 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toVal
ue, progress)); | 247 length->newValueSpecifiedUnits(toType, blink::blend(fromValue, toVal
ue, progress)); |
| 449 return length; | 248 return length; |
| 450 } | 249 } |
| 451 | 250 |
| 452 ASSERT(!isRelative()); | 251 ASSERT(!isRelative()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 471 { | 270 { |
| 472 RefPtrWillBeRawPtr<SVGLength> fromLength = toSVGLength(fromValue); | 271 RefPtrWillBeRawPtr<SVGLength> fromLength = toSVGLength(fromValue); |
| 473 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); | 272 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); |
| 474 RefPtrWillBeRawPtr<SVGLength> toAtEndOfDurationLength = toSVGLength(toAtEndO
fDurationValue); | 273 RefPtrWillBeRawPtr<SVGLength> toAtEndOfDurationLength = toSVGLength(toAtEndO
fDurationValue); |
| 475 | 274 |
| 476 SVGLengthContext lengthContext(contextElement); | 275 SVGLengthContext lengthContext(contextElement); |
| 477 float animatedNumber = value(lengthContext); | 276 float animatedNumber = value(lengthContext); |
| 478 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength-
>value(lengthContext), toLength->value(lengthContext), toAtEndOfDurationLength->
value(lengthContext), animatedNumber); | 277 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength-
>value(lengthContext), toLength->value(lengthContext), toAtEndOfDurationLength->
value(lengthContext), animatedNumber); |
| 479 | 278 |
| 480 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement->
attributeName())); | 279 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement->
attributeName())); |
| 481 m_unitType = percentage < 0.5 ? fromLength->unitType() : toLength->unitType(
); | 280 |
| 482 setValue(animatedNumber, lengthContext); | 281 CSSPrimitiveValue::UnitType newUnit = percentage < 0.5 ? fromLength->primiti
veType() : toLength->primitiveType(); |
| 282 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, uni
tMode(), newUnit); |
| 283 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); |
| 483 } | 284 } |
| 484 | 285 |
| 485 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal
ue, SVGElement* contextElement) | 286 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal
ue, SVGElement* contextElement) |
| 486 { | 287 { |
| 487 SVGLengthContext lengthContext(contextElement); | 288 SVGLengthContext lengthContext(contextElement); |
| 488 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); | 289 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); |
| 489 | 290 |
| 490 return fabsf(toLength->value(lengthContext) - value(lengthContext)); | 291 return fabsf(toLength->value(lengthContext) - value(lengthContext)); |
| 491 } | 292 } |
| 492 | 293 |
| 493 } | 294 } |
| OLD | NEW |