Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 12 matching lines...) Expand all Loading... | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/html/HTMLDimension.h" | 31 #include "core/html/HTMLDimension.h" |
| 32 | 32 |
| 33 #include "core/html/parser/HTMLParserIdioms.h" | |
| 33 #include "wtf/MathExtras.h" | 34 #include "wtf/MathExtras.h" |
| 35 #include "wtf/text/ParsingUtilities.h" | |
| 34 #include "wtf/text/StringToNumber.h" | 36 #include "wtf/text/StringToNumber.h" |
| 35 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 36 | 38 |
| 37 namespace blink { | 39 namespace blink { |
| 38 | 40 |
| 39 template <typename CharacterType> | 41 template <typename CharacterType> |
| 40 static HTMLDimension parseDimension(const CharacterType* characters, | 42 static HTMLDimension parseDimension(const CharacterType* characters, |
| 41 size_t lastParsedIndex, | 43 size_t lastParsedIndex, |
| 42 size_t endOfCurrentToken) { | 44 size_t endOfCurrentToken) { |
| 43 HTMLDimension::HTMLDimensionType type = HTMLDimension::Absolute; | 45 HTMLDimension::HTMLDimensionType type = HTMLDimension::Absolute; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 parsedDimensions.append( | 141 parsedDimensions.append( |
| 140 parseDimension(trimmedString, lastParsedIndex, nextComma)); | 142 parseDimension(trimmedString, lastParsedIndex, nextComma)); |
| 141 lastParsedIndex = nextComma + 1; | 143 lastParsedIndex = nextComma + 1; |
| 142 } | 144 } |
| 143 | 145 |
| 144 parsedDimensions.append( | 146 parsedDimensions.append( |
| 145 parseDimension(trimmedString, lastParsedIndex, trimmedString.length())); | 147 parseDimension(trimmedString, lastParsedIndex, trimmedString.length())); |
| 146 return parsedDimensions; | 148 return parsedDimensions; |
| 147 } | 149 } |
| 148 | 150 |
| 151 template <typename CharacterType> | |
| 152 static bool parseDimensionValue(const CharacterType* current, | |
| 153 const CharacterType* end, | |
| 154 HTMLDimension& dimension) { | |
| 155 skipWhile<CharacterType, isHTMLSpace>(current, end); | |
| 156 // Deviation: HTML allows '+' here. | |
| 157 const CharacterType* numberStart = current; | |
| 158 if (!skipExactly<CharacterType, isASCIIDigit>(current, end)) | |
| 159 return false; | |
| 160 skipWhile<CharacterType, isASCIIDigit>(current, end); | |
| 161 if (skipExactly<CharacterType>(current, end, '.')) { | |
| 162 // Deviation: HTML requires a digit after the full stop. Gecko and Edge | |
|
Timothy Loh
2016/11/25 00:07:47
I think you misread the spec here? From my reading
fs
2016/11/25 10:18:43
My comment could be made more clear I guess. I was
fs
2016/11/30 18:27:18
Clarified.
| |
| 163 // does not. | |
| 164 skipWhile<CharacterType, isASCIIDigit>(current, end); | |
| 165 } | |
| 166 bool ok; | |
| 167 double value = charactersToDouble(numberStart, current - numberStart, &ok); | |
| 168 if (!ok) | |
| 169 return false; | |
| 170 HTMLDimension::HTMLDimensionType type = HTMLDimension::Absolute; | |
| 171 if (current < end) { | |
| 172 if (*current == '%') { | |
| 173 type = HTMLDimension::Percentage; | |
| 174 } else if (*current == '*') { | |
| 175 // Deviation: HTML does not recognize '*' in this context, and we don't | |
| 176 // treat it as a valid value. We do count it though, so this is purely | |
| 177 // for statistics. Note though that per the specced behavior, "<number>*" | |
| 178 // would be the same as "<number>" (i.e '*' would just be trailing | |
| 179 // garbage.) | |
| 180 type = HTMLDimension::Relative; | |
| 181 } | |
| 182 } | |
| 183 dimension = HTMLDimension(value, type); | |
| 184 return true; | |
| 185 } | |
| 186 | |
| 187 // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing- dimension-values | |
| 188 bool parseDimensionValue(const String& input, HTMLDimension& dimension) { | |
| 189 if (input.isEmpty()) | |
| 190 return false; | |
| 191 if (input.is8Bit()) { | |
| 192 return parseDimensionValue(input.characters8(), | |
| 193 input.characters8() + input.length(), dimension); | |
| 194 } | |
| 195 return parseDimensionValue(input.characters16(), | |
| 196 input.characters16() + input.length(), dimension); | |
| 197 } | |
| 198 | |
| 149 } // namespace blink | 199 } // namespace blink |
| OLD | NEW |