Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 SVGLengthType SVGLengthTearOff::unitType() | 56 SVGLengthType SVGLengthTearOff::unitType() |
| 57 { | 57 { |
| 58 return target()->unitType(); | 58 return hasExposedLengthUnit() ? target()->unitType() : LengthTypeUnknown; |
| 59 } | 59 } |
| 60 | 60 |
| 61 SVGLengthMode SVGLengthTearOff::unitMode() | 61 SVGLengthMode SVGLengthTearOff::unitMode() |
| 62 { | 62 { |
| 63 return target()->unitMode(); | 63 return target()->unitMode(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 float SVGLengthTearOff::value(ExceptionState& exceptionState) | 66 float SVGLengthTearOff::value(ExceptionState& exceptionState) |
| 67 { | 67 { |
| 68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { | 68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 if (isImmutable()) { | 101 if (isImmutable()) { |
| 102 es.throwDOMException(NoModificationAllowedError, "The attribute is read- only."); | 102 es.throwDOMException(NoModificationAllowedError, "The attribute is read- only."); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 target()->setValueInSpecifiedUnits(value); | 105 target()->setValueInSpecifiedUnits(value); |
| 106 commitChange(); | 106 commitChange(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 String SVGLengthTearOff::valueAsString() | 109 String SVGLengthTearOff::valueAsString() |
| 110 { | 110 { |
| 111 return target()->valueAsString(); | 111 return hasExposedLengthUnit() ? target()->valueAsString() : String::number(0 ); |
|
Erik Dahlström (inactive)
2015/03/31 09:20:50
Not all <length> properties have 0 (with no unit)
Shanmuga Pandi
2015/04/01 15:01:37
Added TODO note. I will work on this issue seperat
Erik Dahlström (inactive)
2015/04/02 07:58:40
Acknowledged.
| |
| 112 } | 112 } |
| 113 | 113 |
| 114 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es) | 114 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es) |
| 115 { | 115 { |
| 116 if (isImmutable()) { | 116 if (isImmutable()) { |
| 117 es.throwDOMException(NoModificationAllowedError, "The attribute is read- only."); | 117 es.throwDOMException(NoModificationAllowedError, "The attribute is read- only."); |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 | 120 |
| 121 String oldValue = target()->valueAsString(); | |
| 122 | |
| 121 target()->setValueAsString(str, es); | 123 target()->setValueAsString(str, es); |
| 124 | |
| 125 if (!es.hadException() && !hasExposedLengthUnit()) { | |
| 126 target()->setValueAsString(oldValue, ASSERT_NO_EXCEPTION); // rollback t o old value | |
| 127 es.throwDOMException(SyntaxError, "The value provided ('" + str + "') is invalid."); | |
| 128 return; | |
| 129 } | |
| 130 | |
| 122 commitChange(); | 131 commitChange(); |
| 123 } | 132 } |
| 124 | 133 |
| 125 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) | 134 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) |
| 126 { | 135 { |
| 127 if (isImmutable()) { | 136 if (isImmutable()) { |
| 128 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); | 137 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); |
| 129 return; | 138 return; |
| 130 } | 139 } |
| 131 | 140 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 160 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); | 169 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); |
| 161 commitChange(); | 170 commitChange(); |
| 162 } | 171 } |
| 163 | 172 |
| 164 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName) | 173 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName) |
| 165 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) | 174 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) |
| 166 { | 175 { |
| 167 } | 176 } |
| 168 | 177 |
| 169 } | 178 } |
| OLD | NEW |