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

Side by Side Diff: Source/core/svg/SVGLength.cpp

Issue 72363002: Rename es => exceptionState in other than bindings/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Retry Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGLength.h ('k') | Source/core/svg/SVGLengthContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 { 143 {
144 setValue(value, context, ASSERT_NO_EXCEPTION); 144 setValue(value, context, ASSERT_NO_EXCEPTION);
145 } 145 }
146 146
147 SVGLength::SVGLength(const SVGLength& other) 147 SVGLength::SVGLength(const SVGLength& other)
148 : m_valueInSpecifiedUnits(other.m_valueInSpecifiedUnits) 148 : m_valueInSpecifiedUnits(other.m_valueInSpecifiedUnits)
149 , m_unit(other.m_unit) 149 , m_unit(other.m_unit)
150 { 150 {
151 } 151 }
152 152
153 void SVGLength::setValueAsString(const String& valueAsString, SVGLengthMode mode , ExceptionState& es) 153 void SVGLength::setValueAsString(const String& valueAsString, SVGLengthMode mode , ExceptionState& exceptionState)
154 { 154 {
155 m_valueInSpecifiedUnits = 0; 155 m_valueInSpecifiedUnits = 0;
156 m_unit = storeUnit(mode, LengthTypeNumber); 156 m_unit = storeUnit(mode, LengthTypeNumber);
157 setValueAsString(valueAsString, es); 157 setValueAsString(valueAsString, exceptionState);
158 } 158 }
159 159
160 bool SVGLength::operator==(const SVGLength& other) const 160 bool SVGLength::operator==(const SVGLength& other) const
161 { 161 {
162 return m_unit == other.m_unit 162 return m_unit == other.m_unit
163 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits; 163 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits;
164 } 164 }
165 165
166 bool SVGLength::operator!=(const SVGLength& other) const 166 bool SVGLength::operator!=(const SVGLength& other) const
167 { 167 {
168 return !operator==(other); 168 return !operator==(other);
169 } 169 }
170 170
171 SVGLength SVGLength::construct(SVGLengthMode mode, const String& valueAsString, SVGParsingError& parseError, SVGLengthNegativeValuesMode negativeValuesMode) 171 SVGLength SVGLength::construct(SVGLengthMode mode, const String& valueAsString, SVGParsingError& parseError, SVGLengthNegativeValuesMode negativeValuesMode)
172 { 172 {
173 TrackExceptionState es; 173 TrackExceptionState exceptionState;
174 SVGLength length(mode); 174 SVGLength length(mode);
175 175
176 length.setValueAsString(valueAsString, es); 176 length.setValueAsString(valueAsString, exceptionState);
177 177
178 if (es.hadException()) 178 if (exceptionState.hadException())
179 parseError = ParsingAttributeFailedError; 179 parseError = ParsingAttributeFailedError;
180 else if (negativeValuesMode == ForbidNegativeLengths && length.valueInSpecif iedUnits() < 0) 180 else if (negativeValuesMode == ForbidNegativeLengths && length.valueInSpecif iedUnits() < 0)
181 parseError = NegativeValueForbiddenError; 181 parseError = NegativeValueForbiddenError;
182 182
183 return length; 183 return length;
184 } 184 }
185 185
186 SVGLengthType SVGLength::unitType() const 186 SVGLengthType SVGLength::unitType() const
187 { 187 {
188 return extractType(m_unit); 188 return extractType(m_unit);
189 } 189 }
190 190
191 SVGLengthMode SVGLength::unitMode() const 191 SVGLengthMode SVGLength::unitMode() const
192 { 192 {
193 return extractMode(m_unit); 193 return extractMode(m_unit);
194 } 194 }
195 195
196 float SVGLength::value(const SVGLengthContext& context) const 196 float SVGLength::value(const SVGLengthContext& context) const
197 { 197 {
198 return value(context, IGNORE_EXCEPTION); 198 return value(context, IGNORE_EXCEPTION);
199 } 199 }
200 200
201 float SVGLength::value(const SVGLengthContext& context, ExceptionState& es) cons t 201 float SVGLength::value(const SVGLengthContext& context, ExceptionState& exceptio nState) const
202 { 202 {
203 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, extractMode( m_unit), extractType(m_unit), es); 203 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, extractMode( m_unit), extractType(m_unit), exceptionState);
204 } 204 }
205 205
206 void SVGLength::setValue(const SVGLengthContext& context, float value, SVGLength Mode mode, SVGLengthType unitType, ExceptionState& es) 206 void SVGLength::setValue(const SVGLengthContext& context, float value, SVGLength Mode mode, SVGLengthType unitType, ExceptionState& exceptionState)
207 { 207 {
208 m_unit = storeUnit(mode, unitType); 208 m_unit = storeUnit(mode, unitType);
209 setValue(value, context, es); 209 setValue(value, context, exceptionState);
210 } 210 }
211 211
212 void SVGLength::setValue(float value, const SVGLengthContext& context, Exception State& es) 212 void SVGLength::setValue(float value, const SVGLengthContext& context, Exception State& exceptionState)
213 { 213 {
214 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed 214 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed
215 if (extractType(m_unit) == LengthTypePercentage) 215 if (extractType(m_unit) == LengthTypePercentage)
216 value = value / 100; 216 value = value / 100;
217 217
218 float convertedValue = context.convertValueFromUserUnits(value, extractMode( m_unit), extractType(m_unit), es); 218 float convertedValue = context.convertValueFromUserUnits(value, extractMode( m_unit), extractType(m_unit), exceptionState);
219 if (!es.hadException()) 219 if (!exceptionState.hadException())
220 m_valueInSpecifiedUnits = convertedValue; 220 m_valueInSpecifiedUnits = convertedValue;
221 } 221 }
222 float SVGLength::valueAsPercentage() const 222 float SVGLength::valueAsPercentage() const
223 { 223 {
224 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed 224 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed
225 if (extractType(m_unit) == LengthTypePercentage) 225 if (extractType(m_unit) == LengthTypePercentage)
226 return m_valueInSpecifiedUnits / 100; 226 return m_valueInSpecifiedUnits / 100;
227 227
228 return m_valueInSpecifiedUnits; 228 return m_valueInSpecifiedUnits;
229 } 229 }
230 230
231 template<typename CharType> 231 template<typename CharType>
232 static bool parseValueInternal(const String& string, float& convertedNumber, SVG LengthType& type) 232 static bool parseValueInternal(const String& string, float& convertedNumber, SVG LengthType& type)
233 { 233 {
234 const CharType* ptr = string.getCharacters<CharType>(); 234 const CharType* ptr = string.getCharacters<CharType>();
235 const CharType* end = ptr + string.length(); 235 const CharType* end = ptr + string.length();
236 236
237 if (!parseNumber(ptr, end, convertedNumber, false)) 237 if (!parseNumber(ptr, end, convertedNumber, false))
238 return false; 238 return false;
239 239
240 type = stringToLengthType(ptr, end); 240 type = stringToLengthType(ptr, end);
241 ASSERT(ptr <= end); 241 ASSERT(ptr <= end);
242 if (type == LengthTypeUnknown) 242 if (type == LengthTypeUnknown)
243 return false; 243 return false;
244 244
245 return true; 245 return true;
246 } 246 }
247 247
248 void SVGLength::setValueAsString(const String& string, ExceptionState& es) 248 void SVGLength::setValueAsString(const String& string, ExceptionState& exception State)
249 { 249 {
250 if (string.isEmpty()) 250 if (string.isEmpty())
251 return; 251 return;
252 252
253 float convertedNumber = 0; 253 float convertedNumber = 0;
254 SVGLengthType type = LengthTypeUnknown; 254 SVGLengthType type = LengthTypeUnknown;
255 255
256 bool success = string.is8Bit() ? 256 bool success = string.is8Bit() ?
257 parseValueInternal<LChar>(string, convertedNumber, type) : 257 parseValueInternal<LChar>(string, convertedNumber, type) :
258 parseValueInternal<UChar>(string, convertedNumber, type); 258 parseValueInternal<UChar>(string, convertedNumber, type);
259 259
260 if (!success) { 260 if (!success) {
261 es.throwUninformativeAndGenericDOMException(SyntaxError); 261 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError);
262 return; 262 return;
263 } 263 }
264 264
265 m_unit = storeUnit(extractMode(m_unit), type); 265 m_unit = storeUnit(extractMode(m_unit), type);
266 m_valueInSpecifiedUnits = convertedNumber; 266 m_valueInSpecifiedUnits = convertedNumber;
267 } 267 }
268 268
269 String SVGLength::valueAsString() const 269 String SVGLength::valueAsString() const
270 { 270 {
271 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(extractT ype(m_unit)); 271 return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(extractT ype(m_unit));
272 } 272 }
273 273
274 void SVGLength::newValueSpecifiedUnits(unsigned short type, float value, Excepti onState& es) 274 void SVGLength::newValueSpecifiedUnits(unsigned short type, float value, Excepti onState& exceptionState)
275 { 275 {
276 if (type == LengthTypeUnknown || type > LengthTypePC) { 276 if (type == LengthTypeUnknown || type > LengthTypePC) {
277 es.throwUninformativeAndGenericDOMException(NotSupportedError); 277 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
278 return; 278 return;
279 } 279 }
280 280
281 m_unit = storeUnit(extractMode(m_unit), toSVGLengthType(type)); 281 m_unit = storeUnit(extractMode(m_unit), toSVGLengthType(type));
282 m_valueInSpecifiedUnits = value; 282 m_valueInSpecifiedUnits = value;
283 } 283 }
284 284
285 void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGLengthCont ext& context, ExceptionState& es) 285 void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGLengthCont ext& context, ExceptionState& exceptionState)
286 { 286 {
287 if (type == LengthTypeUnknown || type > LengthTypePC) { 287 if (type == LengthTypeUnknown || type > LengthTypePC) {
288 es.throwUninformativeAndGenericDOMException(NotSupportedError); 288 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
289 return; 289 return;
290 } 290 }
291 291
292 float valueInUserUnits = value(context, es); 292 float valueInUserUnits = value(context, exceptionState);
293 if (es.hadException()) 293 if (exceptionState.hadException())
294 return; 294 return;
295 295
296 unsigned int originalUnitAndType = m_unit; 296 unsigned int originalUnitAndType = m_unit;
297 m_unit = storeUnit(extractMode(m_unit), toSVGLengthType(type)); 297 m_unit = storeUnit(extractMode(m_unit), toSVGLengthType(type));
298 setValue(valueInUserUnits, context, es); 298 setValue(valueInUserUnits, context, exceptionState);
299 if (!es.hadException()) 299 if (!exceptionState.hadException())
300 return; 300 return;
301 301
302 // Eventually restore old unit and type 302 // Eventually restore old unit and type
303 m_unit = originalUnitAndType; 303 m_unit = originalUnitAndType;
304 } 304 }
305 305
306 SVGLength SVGLength::fromCSSPrimitiveValue(CSSPrimitiveValue* value) 306 SVGLength SVGLength::fromCSSPrimitiveValue(CSSPrimitiveValue* value)
307 { 307 {
308 ASSERT(value); 308 ASSERT(value);
309 309
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 break; 341 break;
342 case CSSPrimitiveValue::CSS_UNKNOWN: 342 case CSSPrimitiveValue::CSS_UNKNOWN:
343 default: 343 default:
344 svgType = LengthTypeUnknown; 344 svgType = LengthTypeUnknown;
345 break; 345 break;
346 }; 346 };
347 347
348 if (svgType == LengthTypeUnknown) 348 if (svgType == LengthTypeUnknown)
349 return SVGLength(); 349 return SVGLength();
350 350
351 TrackExceptionState es; 351 TrackExceptionState exceptionState;
352 SVGLength length; 352 SVGLength length;
353 length.newValueSpecifiedUnits(svgType, value->getFloatValue(), es); 353 length.newValueSpecifiedUnits(svgType, value->getFloatValue(), exceptionStat e);
354 if (es.hadException()) 354 if (exceptionState.hadException())
355 return SVGLength(); 355 return SVGLength();
356 356
357 return length; 357 return length;
358 } 358 }
359 359
360 PassRefPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(const SVGLength& le ngth) 360 PassRefPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(const SVGLength& le ngth)
361 { 361 {
362 CSSPrimitiveValue::UnitTypes cssType = CSSPrimitiveValue::CSS_UNKNOWN; 362 CSSPrimitiveValue::UnitTypes cssType = CSSPrimitiveValue::CSS_UNKNOWN;
363 switch (length.unitType()) { 363 switch (length.unitType()) {
364 case LengthTypeUnknown: 364 case LengthTypeUnknown:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 s_lengthModeMap.set(SVGNames::startOffsetAttr, LengthModeWidth); 427 s_lengthModeMap.set(SVGNames::startOffsetAttr, LengthModeWidth);
428 } 428 }
429 429
430 if (s_lengthModeMap.contains(attrName)) 430 if (s_lengthModeMap.contains(attrName))
431 return s_lengthModeMap.get(attrName); 431 return s_lengthModeMap.get(attrName);
432 432
433 return LengthModeOther; 433 return LengthModeOther;
434 } 434 }
435 435
436 } 436 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGLength.h ('k') | Source/core/svg/SVGLengthContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698