Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGLengthTearOff.cpp

Issue 2357463002: Consolidate read-only exception throwing for SVG*TearOffs (Closed)
Patch Set: Baseline updates Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 { 122 {
123 return target()->unitMode(); 123 return target()->unitMode();
124 } 124 }
125 125
126 float SVGLengthTearOff::value(ExceptionState& exceptionState) 126 float SVGLengthTearOff::value(ExceptionState& exceptionState)
127 { 127 {
128 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { 128 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) {
129 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); 129 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length.");
130 return 0; 130 return 0;
131 } 131 }
132
133 SVGLengthContext lengthContext(contextElement()); 132 SVGLengthContext lengthContext(contextElement());
134 return target()->value(lengthContext); 133 return target()->value(lengthContext);
135 } 134 }
136 135
137 void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState) 136 void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState)
138 { 137 {
139 if (isImmutable()) { 138 if (isImmutable()) {
140 exceptionState.throwDOMException(NoModificationAllowedError, "The attrib ute is read-only."); 139 throwReadOnly(exceptionState);
141 return; 140 return;
142 } 141 }
143
144 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { 142 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) {
145 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); 143 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length.");
146 return; 144 return;
147 } 145 }
148
149 SVGLengthContext lengthContext(contextElement()); 146 SVGLengthContext lengthContext(contextElement());
150 if (target()->isCalculated()) 147 if (target()->isCalculated())
151 target()->setValueAsNumber(value); 148 target()->setValueAsNumber(value);
152 else 149 else
153 target()->setValue(value, lengthContext); 150 target()->setValue(value, lengthContext);
154
155 commitChange(); 151 commitChange();
156 } 152 }
157 153
158 float SVGLengthTearOff::valueInSpecifiedUnits() 154 float SVGLengthTearOff::valueInSpecifiedUnits()
159 { 155 {
160 if (target()->isCalculated()) 156 if (target()->isCalculated())
161 return 0; 157 return 0;
162
163 return target()->valueInSpecifiedUnits(); 158 return target()->valueInSpecifiedUnits();
164 } 159 }
165 160
166 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& exc eptionState) 161 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& exc eptionState)
167 { 162 {
168 if (isImmutable()) { 163 if (isImmutable()) {
169 exceptionState.throwDOMException(NoModificationAllowedError, "The attrib ute is read-only."); 164 throwReadOnly(exceptionState);
170 return; 165 return;
171 } 166 }
172
173 if (target()->isCalculated()) 167 if (target()->isCalculated())
174 target()->setValueAsNumber(value); 168 target()->setValueAsNumber(value);
175 else 169 else
176 target()->setValueInSpecifiedUnits(value); 170 target()->setValueInSpecifiedUnits(value);
177
178 commitChange(); 171 commitChange();
179 } 172 }
180 173
181 String SVGLengthTearOff::valueAsString() 174 String SVGLengthTearOff::valueAsString()
182 { 175 {
183 // 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 176 // 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
184 return hasExposedLengthUnit() ? target()->valueAsString() : String::number(0 ); 177 return hasExposedLengthUnit() ? target()->valueAsString() : String::number(0 );
185 } 178 }
186 179
187 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& excep tionState) 180 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& excep tionState)
188 { 181 {
189 if (isImmutable()) { 182 if (isImmutable()) {
190 exceptionState.throwDOMException(NoModificationAllowedError, "The attrib ute is read-only."); 183 throwReadOnly(exceptionState);
191 return; 184 return;
192 } 185 }
193
194 String oldValue = target()->valueAsString(); 186 String oldValue = target()->valueAsString();
195
196 SVGParsingError status = target()->setValueAsString(str); 187 SVGParsingError status = target()->setValueAsString(str);
197
198 if (status == SVGParseStatus::NoError && !hasExposedLengthUnit()) { 188 if (status == SVGParseStatus::NoError && !hasExposedLengthUnit()) {
199 target()->setValueAsString(oldValue); // rollback to old value 189 target()->setValueAsString(oldValue); // rollback to old value
200 status = SVGParseStatus::ParsingFailed; 190 status = SVGParseStatus::ParsingFailed;
201 } 191 }
202 if (status != SVGParseStatus::NoError) { 192 if (status != SVGParseStatus::NoError) {
203 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + str + "') is invalid."); 193 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + str + "') is invalid.");
204 return; 194 return;
205 } 195 }
206
207 commitChange(); 196 commitChange();
208 } 197 }
209 198
210 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState) 199 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val ueInSpecifiedUnits, ExceptionState& exceptionState)
211 { 200 {
212 if (isImmutable()) { 201 if (isImmutable()) {
213 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); 202 throwReadOnly(exceptionState);
214 return; 203 return;
215 } 204 }
216
217 if (!isValidLengthUnit(unitType)) { 205 if (!isValidLengthUnit(unitType)) {
218 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi th unknown or invalid units (" + String::number(unitType) + ")."); 206 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi th unknown or invalid units (" + String::number(unitType) + ").");
219 return; 207 return;
220 } 208 }
221
222 target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUn its); 209 target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUn its);
223 commitChange(); 210 commitChange();
224 } 211 }
225 212
226 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio nState& exceptionState) 213 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio nState& exceptionState)
227 { 214 {
228 if (isImmutable()) { 215 if (isImmutable()) {
229 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only."); 216 throwReadOnly(exceptionState);
230 return; 217 return;
231 } 218 }
232
233 if (!isValidLengthUnit(unitType)) { 219 if (!isValidLengthUnit(unitType)) {
234 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u nknown or invalid units (" + String::number(unitType) + ")."); 220 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u nknown or invalid units (" + String::number(unitType) + ").");
235 return; 221 return;
236 } 222 }
237
238 if ((target()->isRelative() || CSSPrimitiveValue::isRelativeUnit(toCSSUnitTy pe(unitType))) 223 if ((target()->isRelative() || CSSPrimitiveValue::isRelativeUnit(toCSSUnitTy pe(unitType)))
239 && !canResolveRelativeUnits(contextElement())) { 224 && !canResolveRelativeUnits(contextElement())) {
240 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length."); 225 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r elative length.");
241 return; 226 return;
242 } 227 }
243
244 SVGLengthContext lengthContext(contextElement()); 228 SVGLengthContext lengthContext(contextElement());
245 target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext); 229 target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext);
246 commitChange(); 230 commitChange();
247 } 231 }
248 232
249 SVGLengthTearOff::SVGLengthTearOff(SVGLength* target, SVGElement* contextElement , PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName) 233 SVGLengthTearOff::SVGLengthTearOff(SVGLength* target, SVGElement* contextElement , PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName)
250 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName) 234 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a ttributeName)
251 { 235 {
252 } 236 }
253 237
254 DEFINE_TRACE_WRAPPERS(SVGLengthTearOff) 238 DEFINE_TRACE_WRAPPERS(SVGLengthTearOff)
255 { 239 {
256 visitor->traceWrappers(contextElement()); 240 visitor->traceWrappers(contextElement());
257 } 241 }
258 242
259 } // namespace blink 243 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGAngleTearOff.cpp ('k') | third_party/WebKit/Source/core/svg/SVGMatrixTearOff.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698