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