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

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

Issue 1544673003: Refactor propagation of parsing errors for SVG attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 if (ptr != end) { 61 if (ptr != end) {
62 m_value = 0; 62 m_value = 0;
63 return false; 63 return false;
64 } 64 }
65 65
66 return true; 66 return true;
67 } 67 }
68 68
69 void SVGNumber::setValueAsString(const String& string, ExceptionState& exception State) 69 SVGParsingError SVGNumber::setValueAsString(const String& string)
70 { 70 {
71 if (string.isEmpty()) { 71 if (string.isEmpty()) {
72 m_value = 0; 72 m_value = 0;
73 return; 73 return NoError;
74 } 74 }
75 75
76 bool valid = false; 76 bool valid = false;
77 if (string.is8Bit()) { 77 if (string.is8Bit()) {
78 const LChar* ptr = string.characters8(); 78 const LChar* ptr = string.characters8();
79 const LChar* end = ptr + string.length(); 79 const LChar* end = ptr + string.length();
80 valid = parse(ptr, end); 80 valid = parse(ptr, end);
81 } else { 81 } else {
82 const UChar* ptr = string.characters16(); 82 const UChar* ptr = string.characters16();
83 const UChar* end = ptr + string.length(); 83 const UChar* end = ptr + string.length();
84 valid = parse(ptr, end); 84 valid = parse(ptr, end);
85 } 85 }
86 86
87 if (!valid) { 87 if (!valid) {
88 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid.");
89 m_value = 0; 88 m_value = 0;
pdr. 2015/12/23 04:00:08 Nit for contemplation: this isn't required, but we
fs 2015/12/23 10:04:17 Yes, I've been noticing these things here and ther
89 return ParsingAttributeFailedError;
90 } 90 }
91 return NoError;
91 } 92 }
92 93
93 void SVGNumber::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) 94 void SVGNumber::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*)
94 { 95 {
95 setValue(m_value + toSVGNumber(other)->value()); 96 setValue(m_value + toSVGNumber(other)->value());
96 } 97 }
97 98
98 void SVGNumber::calculateAnimatedValue(SVGAnimationElement* animationElement, fl oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr om, PassRefPtrWillBeRawPtr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGProper tyBase> toAtEndOfDuration, SVGElement*) 99 void SVGNumber::calculateAnimatedValue(SVGAnimationElement* animationElement, fl oat percentage, unsigned repeatCount, PassRefPtrWillBeRawPtr<SVGPropertyBase> fr om, PassRefPtrWillBeRawPtr<SVGPropertyBase> to, PassRefPtrWillBeRawPtr<SVGProper tyBase> toAtEndOfDuration, SVGElement*)
99 { 100 {
100 ASSERT(animationElement); 101 ASSERT(animationElement);
101 102
102 RefPtrWillBeRawPtr<SVGNumber> fromNumber = toSVGNumber(from); 103 RefPtrWillBeRawPtr<SVGNumber> fromNumber = toSVGNumber(from);
103 RefPtrWillBeRawPtr<SVGNumber> toNumber = toSVGNumber(to); 104 RefPtrWillBeRawPtr<SVGNumber> toNumber = toSVGNumber(to);
104 RefPtrWillBeRawPtr<SVGNumber> toAtEndOfDurationNumber = toSVGNumber(toAtEndO fDuration); 105 RefPtrWillBeRawPtr<SVGNumber> toAtEndOfDurationNumber = toSVGNumber(toAtEndO fDuration);
105 106
106 animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumber- >value(), toNumber->value(), toAtEndOfDurationNumber->value(), m_value); 107 animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumber- >value(), toNumber->value(), toAtEndOfDurationNumber->value(), m_value);
107 } 108 }
108 109
109 float SVGNumber::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> other , SVGElement*) 110 float SVGNumber::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> other , SVGElement*)
110 { 111 {
111 return fabsf(m_value - toSVGNumber(other)->value()); 112 return fabsf(m_value - toSVGNumber(other)->value());
112 } 113 }
113 114
114 PassRefPtrWillBeRawPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const 115 PassRefPtrWillBeRawPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const
115 { 116 {
116 return create(m_value); 117 return create(m_value);
117 } 118 }
118 119
119 void SVGNumberAcceptPercentage::setValueAsString(const String& string, Exception State& exceptionState) 120 SVGParsingError SVGNumberAcceptPercentage::setValueAsString(const String& string )
120 { 121 {
121 bool valid = parseNumberOrPercentage(string, m_value); 122 if (parseNumberOrPercentage(string, m_value))
123 return NoError;
122 124
123 if (!valid) { 125 m_value = 0;
124 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid."); 126 return ParsingAttributeFailedError;
125 m_value = 0;
126 }
127 } 127 }
128 128
129 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) 129 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value)
130 : SVGNumber(value) 130 : SVGNumber(value)
131 { 131 {
132 } 132 }
133 133
134 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698