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

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

Issue 302643004: [SVG2] Allow leading and trailing whitespace in svg attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@relax_todouble_wtf
Patch Set: split tests to combat slow xp trybots Created 6 years, 6 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
« no previous file with comments | « Source/core/svg/SVGLengthList.cpp ('k') | Source/core/svg/SVGParserUtilities.h » ('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) 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 String SVGNumber::valueAsString() const 57 String SVGNumber::valueAsString() const
58 { 58 {
59 return String::number(m_value); 59 return String::number(m_value);
60 } 60 }
61 61
62 template<typename CharType> 62 template<typename CharType>
63 bool SVGNumber::parse(const CharType*& ptr, const CharType* end) 63 bool SVGNumber::parse(const CharType*& ptr, const CharType* end)
64 { 64 {
65 if (!parseNumber(ptr, end, m_value, false)) { 65 if (!parseNumber(ptr, end, m_value, AllowLeadingAndTrailingWhitespace)) {
66 m_value = 0; 66 m_value = 0;
67 return false; 67 return false;
68 } 68 }
69 69
70 if (ptr != end) { 70 if (ptr != end) {
71 m_value = 0; 71 m_value = 0;
72 return false; 72 return false;
73 } 73 }
74 74
75 return true; 75 return true;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return fabsf(m_value - toSVGNumber(other)->value()); 120 return fabsf(m_value - toSVGNumber(other)->value());
121 } 121 }
122 122
123 PassRefPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const 123 PassRefPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const
124 { 124 {
125 return create(m_value); 125 return create(m_value);
126 } 126 }
127 127
128 void SVGNumberAcceptPercentage::setValueAsString(const String& string, Exception State& exceptionState) 128 void SVGNumberAcceptPercentage::setValueAsString(const String& string, Exception State& exceptionState)
129 { 129 {
130 if (string.isEmpty()) { 130 bool valid = parseNumberOrPercentage(string, m_value);
131
132 if (!valid) {
133 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid.");
131 m_value = 0; 134 m_value = 0;
132 return;
133 } 135 }
134
135 if (string.endsWith('%')) {
136 SVGNumber::setValueAsString(string.left(string.length() - 1), exceptionS tate);
137 if (exceptionState.hadException())
138 return;
139
140 m_value /= 100.0f;
141 return;
142 }
143
144 SVGNumber::setValueAsString(string, exceptionState);
145 } 136 }
146 137
147 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) 138 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value)
148 : SVGNumber(value) 139 : SVGNumber(value)
149 { 140 {
150 } 141 }
151 142
152 } 143 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGLengthList.cpp ('k') | Source/core/svg/SVGParserUtilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698