| 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 17 matching lines...) Expand all Loading... |
| 28 #include "core/svg/SVGAnimationElement.h" | 28 #include "core/svg/SVGAnimationElement.h" |
| 29 #include "wtf/MathExtras.h" | 29 #include "wtf/MathExtras.h" |
| 30 #include "wtf/text/WTFString.h" | 30 #include "wtf/text/WTFString.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 SVGLength::SVGLength(SVGLengthMode mode) | 34 SVGLength::SVGLength(SVGLengthMode mode) |
| 35 : m_value( | 35 : m_value( |
| 36 CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::UserUnits)), | 36 CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::UserUnits)), |
| 37 m_unitMode(static_cast<unsigned>(mode)) { | 37 m_unitMode(static_cast<unsigned>(mode)) { |
| 38 ASSERT(unitMode() == mode); | 38 DCHECK_EQ(unitMode(), mode); |
| 39 } | 39 } |
| 40 | 40 |
| 41 SVGLength::SVGLength(const SVGLength& o) | 41 SVGLength::SVGLength(const SVGLength& o) |
| 42 : m_value(o.m_value), m_unitMode(o.m_unitMode) {} | 42 : m_value(o.m_value), m_unitMode(o.m_unitMode) {} |
| 43 | 43 |
| 44 DEFINE_TRACE(SVGLength) { | 44 DEFINE_TRACE(SVGLength) { |
| 45 visitor->trace(m_value); | 45 visitor->trace(m_value); |
| 46 SVGPropertyBase::trace(visitor); | 46 SVGPropertyBase::trace(visitor); |
| 47 } | 47 } |
| 48 | 48 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 static bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type) { | 93 static bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type) { |
| 94 return (CSSPrimitiveValue::isLength(type) || | 94 return (CSSPrimitiveValue::isLength(type) || |
| 95 type == CSSPrimitiveValue::UnitType::Number || | 95 type == CSSPrimitiveValue::UnitType::Number || |
| 96 type == CSSPrimitiveValue::UnitType::Percentage || | 96 type == CSSPrimitiveValue::UnitType::Percentage || |
| 97 isCalcCSSUnitType(type)) && | 97 isCalcCSSUnitType(type)) && |
| 98 type != CSSPrimitiveValue::UnitType::QuirkyEms; | 98 type != CSSPrimitiveValue::UnitType::QuirkyEms; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type) { | 101 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type) { |
| 102 ASSERT(isSupportedCSSUnitType(type)); | 102 DCHECK(isSupportedCSSUnitType(type)); |
| 103 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type); | 103 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type); |
| 104 } | 104 } |
| 105 | 105 |
| 106 float SVGLength::valueAsPercentage() const { | 106 float SVGLength::valueAsPercentage() const { |
| 107 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy | 107 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy |
| 108 // but could eventually be changed. | 108 // but could eventually be changed. |
| 109 if (m_value->isPercentage()) { | 109 if (m_value->isPercentage()) { |
| 110 // Note: This division is a source of floating point inaccuracy. | 110 // Note: This division is a source of floating point inaccuracy. |
| 111 return m_value->getFloatValue() / 100; | 111 return m_value->getFloatValue() / 100; |
| 112 } | 112 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return m_value->customCSSText(); | 159 return m_value->customCSSText(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, | 162 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, |
| 163 float value) { | 163 float value) { |
| 164 m_value = CSSPrimitiveValue::create(value, type); | 164 m_value = CSSPrimitiveValue::create(value, type); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void SVGLength::convertToSpecifiedUnits(CSSPrimitiveValue::UnitType type, | 167 void SVGLength::convertToSpecifiedUnits(CSSPrimitiveValue::UnitType type, |
| 168 const SVGLengthContext& context) { | 168 const SVGLengthContext& context) { |
| 169 ASSERT(isSupportedCSSUnitType(type)); | 169 DCHECK(isSupportedCSSUnitType(type)); |
| 170 | 170 |
| 171 float valueInUserUnits = value(context); | 171 float valueInUserUnits = value(context); |
| 172 m_value = CSSPrimitiveValue::create( | 172 m_value = CSSPrimitiveValue::create( |
| 173 context.convertValueFromUserUnits(valueInUserUnits, unitMode(), type), | 173 context.convertValueFromUserUnits(valueInUserUnits, unitMode(), type), |
| 174 type); | 174 type); |
| 175 } | 175 } |
| 176 | 176 |
| 177 SVGLengthMode SVGLength::lengthModeForAnimatedLengthAttribute( | 177 SVGLengthMode SVGLength::lengthModeForAnimatedLengthAttribute( |
| 178 const QualifiedName& attrName) { | 178 const QualifiedName& attrName) { |
| 179 typedef HashMap<QualifiedName, SVGLengthMode> LengthModeForLengthAttributeMap; | 179 typedef HashMap<QualifiedName, SVGLengthMode> LengthModeForLengthAttributeMap; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 SVGLength* toLength = toSVGLength(toValue); | 241 SVGLength* toLength = toSVGLength(toValue); |
| 242 SVGLength* toAtEndOfDurationLength = toSVGLength(toAtEndOfDurationValue); | 242 SVGLength* toAtEndOfDurationLength = toSVGLength(toAtEndOfDurationValue); |
| 243 | 243 |
| 244 SVGLengthContext lengthContext(contextElement); | 244 SVGLengthContext lengthContext(contextElement); |
| 245 float animatedNumber = value(lengthContext); | 245 float animatedNumber = value(lengthContext); |
| 246 animationElement->animateAdditiveNumber( | 246 animationElement->animateAdditiveNumber( |
| 247 percentage, repeatCount, fromLength->value(lengthContext), | 247 percentage, repeatCount, fromLength->value(lengthContext), |
| 248 toLength->value(lengthContext), | 248 toLength->value(lengthContext), |
| 249 toAtEndOfDurationLength->value(lengthContext), animatedNumber); | 249 toAtEndOfDurationLength->value(lengthContext), animatedNumber); |
| 250 | 250 |
| 251 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute( | 251 DCHECK_EQ(unitMode(), lengthModeForAnimatedLengthAttribute( |
| 252 animationElement->attributeName())); | 252 animationElement->attributeName())); |
| 253 | 253 |
| 254 // TODO(shanmuga.m): Construct a calc() expression if the units fall in | 254 // TODO(shanmuga.m): Construct a calc() expression if the units fall in |
| 255 // different categories. | 255 // different categories. |
| 256 CSSPrimitiveValue::UnitType newUnit = CSSPrimitiveValue::UnitType::UserUnits; | 256 CSSPrimitiveValue::UnitType newUnit = CSSPrimitiveValue::UnitType::UserUnits; |
| 257 if (percentage < 0.5) { | 257 if (percentage < 0.5) { |
| 258 if (!fromLength->isCalculated()) | 258 if (!fromLength->isCalculated()) |
| 259 newUnit = fromLength->typeWithCalcResolved(); | 259 newUnit = fromLength->typeWithCalcResolved(); |
| 260 } else { | 260 } else { |
| 261 if (!toLength->isCalculated()) | 261 if (!toLength->isCalculated()) |
| 262 newUnit = toLength->typeWithCalcResolved(); | 262 newUnit = toLength->typeWithCalcResolved(); |
| 263 } | 263 } |
| 264 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, | 264 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, |
| 265 unitMode(), newUnit); | 265 unitMode(), newUnit); |
| 266 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); | 266 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); |
| 267 } | 267 } |
| 268 | 268 |
| 269 float SVGLength::calculateDistance(SVGPropertyBase* toValue, | 269 float SVGLength::calculateDistance(SVGPropertyBase* toValue, |
| 270 SVGElement* contextElement) { | 270 SVGElement* contextElement) { |
| 271 SVGLengthContext lengthContext(contextElement); | 271 SVGLengthContext lengthContext(contextElement); |
| 272 SVGLength* toLength = toSVGLength(toValue); | 272 SVGLength* toLength = toSVGLength(toValue); |
| 273 | 273 |
| 274 return fabsf(toLength->value(lengthContext) - value(lengthContext)); | 274 return fabsf(toLength->value(lengthContext) - value(lengthContext)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 } // namespace blink | 277 } // namespace blink |
| OLD | NEW |