Index: Source/core/platform/Length.cpp |
diff --git a/Source/core/platform/Length.cpp b/Source/core/platform/Length.cpp |
index d93d6afffa9cbb10713e6213ccce3a0b23ab50cb..89a1ee2730d199160ac0d5708c551fedcfa2fdc2 100644 |
--- a/Source/core/platform/Length.cpp |
+++ b/Source/core/platform/Length.cpp |
@@ -73,6 +73,36 @@ static Length parseHTMLAreaCoordinate(const CharType* data, unsigned length) |
return Length(0, Fixed); |
} |
+template<typename CharType> |
+static Length parseFrameSetDimension(const CharType* data, unsigned length) |
+{ |
+ if (!length) |
+ return Length(1, Relative); |
+ |
+ unsigned intLength; |
+ unsigned doubleLength; |
+ unsigned i = splitLength(data, length, intLength, doubleLength); |
+ |
+ bool ok; |
+ CharType next = (i < length) ? data[i] : ' '; |
+ if (next == '%') { |
+ // IE quirk: accept decimal fractions for percentages. |
+ double r = charactersToDouble(data, doubleLength, &ok); |
+ if (ok) |
+ return Length(r, Percent); |
+ return Length(1, Relative); |
+ } |
+ int r = charactersToIntStrict(data, intLength, &ok); |
+ if (next == '*') { |
+ if (ok) |
+ return Length(r, Relative); |
+ return Length(1, Relative); |
+ } |
+ if (ok) |
+ return Length(r, Fixed); |
+ return Length(0, Relative); |
+} |
+ |
// FIXME: Per HTML5, this should follow the "rules for parsing a list of integers". |
Vector<Length> parseHTMLAreaElementCoords(const String& string) |
{ |
@@ -110,6 +140,43 @@ Vector<Length> parseHTMLAreaElementCoords(const String& string) |
return r; |
} |
+template<typename CharType> |
+static Vector<Length> parseFrameSetListOfDimensionsInternal(StringImpl* str) |
+{ |
+ unsigned len = str->count(',') + 1; |
+ Vector<Length> r(len); |
+ |
+ int i = 0; |
+ unsigned pos = 0; |
+ size_t pos2; |
+ |
+ while ((pos2 = str->find(',', pos)) != notFound) { |
+ r[i++] = parseFrameSetDimension(str->getCharacters<CharType>() + pos, pos2 - pos); |
+ pos = pos2 + 1; |
+ } |
+ |
+ ASSERT(i == len - 1); |
+ |
+ // IE Quirk: If the last comma is the last char skip it and reduce len by one. |
+ if (str->length() - pos > 0) |
+ r[i] = parseFrameSetDimension(str->getCharacters<CharType>() + pos, str->length() - pos); |
+ else |
+ r.shrink(r.size() - 1); |
+ |
+ return r; |
+} |
+ |
+// FIXME: Per HTML5, this should "use the rules for parsing a list of dimensions". |
+Vector<Length> parseFrameSetListOfDimensions(const String& string) |
+{ |
+ RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace(); |
+ if (!str->length()) |
+ return Vector<Length>(); |
+ if (str->is8Bit()) |
+ return parseFrameSetListOfDimensionsInternal<LChar>(str.get()); |
+ return parseFrameSetListOfDimensionsInternal<UChar>(str.get()); |
+} |
+ |
class CalculationValueHandleMap { |
WTF_MAKE_FAST_ALLOCATED; |
public: |