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 // TODO(shanmuga.m@samsung.com): Not all <length> properties have 0 (with no
unit) as the default (lacuna) value, Need to return default value instead of 0 |
| 112 return hasExposedLengthUnit() ? target()->valueAsString() : String::number(0
); |
112 } | 113 } |
113 | 114 |
114 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es) | 115 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es) |
115 { | 116 { |
116 if (isImmutable()) { | 117 if (isImmutable()) { |
117 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); | 118 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
118 return; | 119 return; |
119 } | 120 } |
120 | 121 |
| 122 String oldValue = target()->valueAsString(); |
| 123 |
121 target()->setValueAsString(str, es); | 124 target()->setValueAsString(str, es); |
| 125 |
| 126 if (!es.hadException() && !hasExposedLengthUnit()) { |
| 127 target()->setValueAsString(oldValue, ASSERT_NO_EXCEPTION); // rollback t
o old value |
| 128 es.throwDOMException(SyntaxError, "The value provided ('" + str + "') is
invalid."); |
| 129 return; |
| 130 } |
| 131 |
122 commitChange(); | 132 commitChange(); |
123 } | 133 } |
124 | 134 |
125 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) | 135 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) |
126 { | 136 { |
127 if (isImmutable()) { | 137 if (isImmutable()) { |
128 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); | 138 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
129 return; | 139 return; |
130 } | 140 } |
131 | 141 |
(...skipping 28 matching lines...) Expand all Loading... |
160 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); | 170 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); |
161 commitChange(); | 171 commitChange(); |
162 } | 172 } |
163 | 173 |
164 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) | 174 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) |
165 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) | 175 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) |
166 { | 176 { |
167 } | 177 } |
168 | 178 |
169 } | 179 } |
OLD | NEW |