| 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) | |
| 44 { | |
| 45 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); | |
| 46 return static_cast<SVGLengthType>(type); | |
| 47 } | |
| 48 | |
| 49 inline bool canResolveRelativeUnits(const SVGElement* contextElement) | 43 inline bool canResolveRelativeUnits(const SVGElement* contextElement) |
| 50 { | 44 { |
| 51 return contextElement && contextElement->inDocument(); | 45 return contextElement && contextElement->inDocument(); |
| 52 } | 46 } |
| 53 | 47 |
| 48 inline CSSPrimitiveValue::UnitType toCSSUnitType(unsigned short type) |
| 49 { |
| 50 ASSERT(type >= CSSPrimitiveValue::CSS_UNKNOWN && type <= CSSPrimitiveValue::
CSS_PC); |
| 51 return static_cast<CSSPrimitiveValue::UnitType>(type); |
| 52 } |
| 53 |
| 54 inline SVGLengthType toSVGLengthType(CSSPrimitiveValue::UnitType type) |
| 55 { |
| 56 switch (type) { |
| 57 case CSSPrimitiveValue::UnitType::CSS_UNKNOWN: |
| 58 return LengthTypeUnknown; |
| 59 case CSSPrimitiveValue::UnitType::CSS_NUMBER: |
| 60 return LengthTypeNumber; |
| 61 case CSSPrimitiveValue::UnitType::CSS_PERCENTAGE: |
| 62 return LengthTypePercentage; |
| 63 case CSSPrimitiveValue::UnitType::CSS_EMS: |
| 64 return LengthTypeEMS; |
| 65 case CSSPrimitiveValue::UnitType::CSS_EXS: |
| 66 return LengthTypeEXS; |
| 67 case CSSPrimitiveValue::UnitType::CSS_PX: |
| 68 return LengthTypePX; |
| 69 case CSSPrimitiveValue::UnitType::CSS_CM: |
| 70 return LengthTypeCM; |
| 71 case CSSPrimitiveValue::UnitType::CSS_MM: |
| 72 return LengthTypeMM; |
| 73 case CSSPrimitiveValue::UnitType::CSS_IN: |
| 74 return LengthTypeIN; |
| 75 case CSSPrimitiveValue::UnitType::CSS_PT: |
| 76 return LengthTypePT; |
| 77 case CSSPrimitiveValue::UnitType::CSS_PC: |
| 78 return LengthTypePC; |
| 79 default: |
| 80 return LengthTypeUnknown; |
| 81 } |
| 82 } |
| 54 } // namespace | 83 } // namespace |
| 55 | 84 |
| 56 SVGLengthType SVGLengthTearOff::unitType() | 85 SVGLengthType SVGLengthTearOff::unitType() |
| 57 { | 86 { |
| 58 return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown; | 87 return hasExposedLengthUnit() ? toSVGLengthType(target()->getCSSPrimitiveVal
ue()->primitiveType()) : LengthTypeUnknown; |
| 59 } | 88 } |
| 60 | 89 |
| 61 SVGLengthMode SVGLengthTearOff::unitMode() | 90 SVGLengthMode SVGLengthTearOff::unitMode() |
| 62 { | 91 { |
| 63 return target()->unitMode(); | 92 return target()->unitMode(); |
| 64 } | 93 } |
| 65 | 94 |
| 66 float SVGLengthTearOff::value(ExceptionState& exceptionState) | 95 float SVGLengthTearOff::value(ExceptionState& exceptionState) |
| 67 { | 96 { |
| 68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { | 97 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 commitChange(); | 161 commitChange(); |
| 133 } | 162 } |
| 134 | 163 |
| 135 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) | 164 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) |
| 136 { | 165 { |
| 137 if (isImmutable()) { | 166 if (isImmutable()) { |
| 138 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); | 167 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
| 139 return; | 168 return; |
| 140 } | 169 } |
| 141 | 170 |
| 142 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 171 if (unitType == CSSPrimitiveValue::CSS_UNKNOWN || unitType > CSSPrimitiveVal
ue::CSS_PC) { |
| 143 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi
th unknown or invalid units (" + String::number(unitType) + ")."); | 172 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi
th unknown or invalid units (" + String::number(unitType) + ")."); |
| 144 return; | 173 return; |
| 145 } | 174 } |
| 146 | 175 |
| 147 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecified
Units); | 176 target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUn
its); |
| 148 commitChange(); | 177 commitChange(); |
| 149 } | 178 } |
| 150 | 179 |
| 151 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
nState& exceptionState) | 180 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
nState& exceptionState) |
| 152 { | 181 { |
| 153 if (isImmutable()) { | 182 if (isImmutable()) { |
| 154 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); | 183 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
| 155 return; | 184 return; |
| 156 } | 185 } |
| 157 | 186 |
| 158 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 187 if (unitType == CSSPrimitiveValue::CSS_UNKNOWN || unitType > CSSPrimitiveVal
ue::CSS_PC) { |
| 159 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); | 188 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); |
| 160 return; | 189 return; |
| 161 } | 190 } |
| 162 | 191 |
| 163 if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(uni
tType))) | 192 if ((target()->isRelative() || SVGLength::isRelativeUnit(toCSSUnitType(unitT
ype))) |
| 164 && !canResolveRelativeUnits(contextElement())) { | 193 && !canResolveRelativeUnits(contextElement())) { |
| 165 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); | 194 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); |
| 166 return; | 195 return; |
| 167 } | 196 } |
| 168 | 197 |
| 169 SVGLengthContext lengthContext(contextElement()); | 198 SVGLengthContext lengthContext(contextElement()); |
| 170 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); | 199 target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext); |
| 171 commitChange(); | 200 commitChange(); |
| 172 } | 201 } |
| 173 | 202 |
| 174 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) | 203 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) |
| 175 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) | 204 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) |
| 176 { | 205 { |
| 177 } | 206 } |
| 178 | 207 |
| 179 } | 208 } |
| OLD | NEW |