| Index: third_party/WebKit/Source/core/html/HTMLDimension.cpp
|
| diff --git a/third_party/WebKit/Source/core/html/HTMLDimension.cpp b/third_party/WebKit/Source/core/html/HTMLDimension.cpp
|
| index eb5086168e83742a34d87b67a4a91bcaef042f25..21cf532b85eabe4949fa03c2a66ba375a4e8fa71 100644
|
| --- a/third_party/WebKit/Source/core/html/HTMLDimension.cpp
|
| +++ b/third_party/WebKit/Source/core/html/HTMLDimension.cpp
|
| @@ -30,7 +30,9 @@
|
|
|
| #include "core/html/HTMLDimension.h"
|
|
|
| +#include "core/html/parser/HTMLParserIdioms.h"
|
| #include "wtf/MathExtras.h"
|
| +#include "wtf/text/ParsingUtilities.h"
|
| #include "wtf/text/StringToNumber.h"
|
| #include "wtf/text/WTFString.h"
|
|
|
| @@ -146,4 +148,53 @@ Vector<HTMLDimension> parseListOfDimensions(const String& input) {
|
| return parsedDimensions;
|
| }
|
|
|
| +template <typename CharacterType>
|
| +static bool parseDimensionValue(const CharacterType* current,
|
| + const CharacterType* end,
|
| + HTMLDimension& dimension) {
|
| + skipWhile<CharacterType, isHTMLSpace>(current, end);
|
| + // Deviation: HTML allows '+' here.
|
| + const CharacterType* numberStart = current;
|
| + if (!skipExactly<CharacterType, isASCIIDigit>(current, end))
|
| + return false;
|
| + skipWhile<CharacterType, isASCIIDigit>(current, end);
|
| + if (skipExactly<CharacterType>(current, end, '.')) {
|
| + // Deviation: HTML requires a digit after the full stop to be able to treat
|
| + // the value as a percentage (if not, the '.' will considered "garbage",
|
| + // yielding a regular length.) Gecko and Edge does not.
|
| + skipWhile<CharacterType, isASCIIDigit>(current, end);
|
| + }
|
| + bool ok;
|
| + double value = charactersToDouble(numberStart, current - numberStart, &ok);
|
| + if (!ok)
|
| + return false;
|
| + HTMLDimension::HTMLDimensionType type = HTMLDimension::Absolute;
|
| + if (current < end) {
|
| + if (*current == '%') {
|
| + type = HTMLDimension::Percentage;
|
| + } else if (*current == '*') {
|
| + // Deviation: HTML does not recognize '*' in this context, and we don't
|
| + // treat it as a valid value. We do count it though, so this is purely
|
| + // for statistics. Note though that per the specced behavior, "<number>*"
|
| + // would be the same as "<number>" (i.e '*' would just be trailing
|
| + // garbage.)
|
| + type = HTMLDimension::Relative;
|
| + }
|
| + }
|
| + dimension = HTMLDimension(value, type);
|
| + return true;
|
| +}
|
| +
|
| +// https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-dimension-values
|
| +bool parseDimensionValue(const String& input, HTMLDimension& dimension) {
|
| + if (input.isEmpty())
|
| + return false;
|
| + if (input.is8Bit()) {
|
| + return parseDimensionValue(input.characters8(),
|
| + input.characters8() + input.length(), dimension);
|
| + }
|
| + return parseDimensionValue(input.characters16(),
|
| + input.characters16() + input.length(), dimension);
|
| +}
|
| +
|
| } // namespace blink
|
|
|