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

Side by Side Diff: Source/core/platform/Length.cpp

Issue 18565005: Revert "Rewrite parseFrameSetListOfDimension to match HTML5" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/platform/Length.h ('k') | Source/core/tests/HTMLDimension.cpp » ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 4 * (C) 2001 Dirk Mueller ( mueller@kde.org )
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 unsigned doubleLength; 66 unsigned doubleLength;
67 splitLength(data, length, intLength, doubleLength); 67 splitLength(data, length, intLength, doubleLength);
68 68
69 bool ok; 69 bool ok;
70 int r = charactersToIntStrict(data, intLength, &ok); 70 int r = charactersToIntStrict(data, intLength, &ok);
71 if (ok) 71 if (ok)
72 return Length(r, Fixed); 72 return Length(r, Fixed);
73 return Length(0, Fixed); 73 return Length(0, Fixed);
74 } 74 }
75 75
76 template<typename CharType>
77 static Length parseFrameSetDimension(const CharType* data, unsigned length)
78 {
79 if (!length)
80 return Length(1, Relative);
81
82 unsigned intLength;
83 unsigned doubleLength;
84 unsigned i = splitLength(data, length, intLength, doubleLength);
85
86 bool ok;
87 CharType next = (i < length) ? data[i] : ' ';
88 if (next == '%') {
89 // IE quirk: accept decimal fractions for percentages.
90 double r = charactersToDouble(data, doubleLength, &ok);
91 if (ok)
92 return Length(r, Percent);
93 return Length(1, Relative);
94 }
95 int r = charactersToIntStrict(data, intLength, &ok);
96 if (next == '*') {
97 if (ok)
98 return Length(r, Relative);
99 return Length(1, Relative);
100 }
101 if (ok)
102 return Length(r, Fixed);
103 return Length(0, Relative);
104 }
105
76 // FIXME: Per HTML5, this should follow the "rules for parsing a list of integer s". 106 // FIXME: Per HTML5, this should follow the "rules for parsing a list of integer s".
77 Vector<Length> parseHTMLAreaElementCoords(const String& string) 107 Vector<Length> parseHTMLAreaElementCoords(const String& string)
78 { 108 {
79 unsigned length = string.length(); 109 unsigned length = string.length();
80 StringBuffer<LChar> spacified(length); 110 StringBuffer<LChar> spacified(length);
81 for (unsigned i = 0; i < length; i++) { 111 for (unsigned i = 0; i < length; i++) {
82 UChar cc = string[i]; 112 UChar cc = string[i];
83 if (cc > '9' || (cc < '0' && cc != '-' && cc != '.')) 113 if (cc > '9' || (cc < '0' && cc != '-' && cc != '.'))
84 spacified[i] = ' '; 114 spacified[i] = ' ';
85 else 115 else
(...skipping 17 matching lines...) Expand all
103 r[i++] = parseHTMLAreaCoordinate(str->characters8() + pos, pos2 - pos); 133 r[i++] = parseHTMLAreaCoordinate(str->characters8() + pos, pos2 - pos);
104 pos = pos2 + 1; 134 pos = pos2 + 1;
105 } 135 }
106 r[i] = parseHTMLAreaCoordinate(str->characters8() + pos, str->length() - pos ); 136 r[i] = parseHTMLAreaCoordinate(str->characters8() + pos, str->length() - pos );
107 137
108 ASSERT(i == len - 1); 138 ASSERT(i == len - 1);
109 139
110 return r; 140 return r;
111 } 141 }
112 142
143 template<typename CharType>
144 static Vector<Length> parseFrameSetListOfDimensionsInternal(StringImpl* str)
145 {
146 unsigned len = str->count(',') + 1;
147 Vector<Length> r(len);
148
149 int i = 0;
150 unsigned pos = 0;
151 size_t pos2;
152
153 while ((pos2 = str->find(',', pos)) != notFound) {
154 r[i++] = parseFrameSetDimension(str->getCharacters<CharType>() + pos, po s2 - pos);
155 pos = pos2 + 1;
156 }
157
158 ASSERT(i == len - 1);
159
160 // IE Quirk: If the last comma is the last char skip it and reduce len by on e.
161 if (str->length() - pos > 0)
162 r[i] = parseFrameSetDimension(str->getCharacters<CharType>() + pos, str- >length() - pos);
163 else
164 r.shrink(r.size() - 1);
165
166 return r;
167 }
168
169 // FIXME: Per HTML5, this should "use the rules for parsing a list of dimensions ".
170 Vector<Length> parseFrameSetListOfDimensions(const String& string)
171 {
172 RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace();
173 if (!str->length())
174 return Vector<Length>();
175 if (str->is8Bit())
176 return parseFrameSetListOfDimensionsInternal<LChar>(str.get());
177 return parseFrameSetListOfDimensionsInternal<UChar>(str.get());
178 }
179
113 class CalculationValueHandleMap { 180 class CalculationValueHandleMap {
114 WTF_MAKE_FAST_ALLOCATED; 181 WTF_MAKE_FAST_ALLOCATED;
115 public: 182 public:
116 CalculationValueHandleMap() 183 CalculationValueHandleMap()
117 : m_index(1) 184 : m_index(1)
118 { 185 {
119 } 186 }
120 187
121 int insert(PassRefPtr<CalculationValue> calcValue) 188 int insert(PassRefPtr<CalculationValue> calcValue)
122 { 189 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 return isCalculated() && (calculationValue() == o.calculationValue() || *cal culationValue() == *o.calculationValue()); 277 return isCalculated() && (calculationValue() == o.calculationValue() || *cal culationValue() == *o.calculationValue());
211 } 278 }
212 279
213 struct SameSizeAsLength { 280 struct SameSizeAsLength {
214 int32_t value; 281 int32_t value;
215 int32_t metaData; 282 int32_t metaData;
216 }; 283 };
217 COMPILE_ASSERT(sizeof(Length) == sizeof(SameSizeAsLength), length_should_stay_sm all); 284 COMPILE_ASSERT(sizeof(Length) == sizeof(SameSizeAsLength), length_should_stay_sm all);
218 285
219 } // namespace WebCore 286 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/Length.h ('k') | Source/core/tests/HTMLDimension.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698