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

Side by Side Diff: third_party/WebKit/Source/platform/Length.cpp

Issue 1636333003: Implement specced parsing algorithm for <area coords> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "platform/Length.h" 25 #include "platform/Length.h"
26 26
27 #include "platform/CalculationValue.h" 27 #include "platform/CalculationValue.h"
28 #include "platform/animation/AnimationUtilities.h" 28 #include "platform/animation/AnimationUtilities.h"
29 #include "wtf/ASCIICType.h"
30 #include "wtf/text/StringBuffer.h"
31 #include "wtf/text/WTFString.h"
32 29
33 using namespace WTF; 30 using namespace WTF;
34 31
35 namespace blink { 32 namespace blink {
36 33
37 template<typename CharType>
38 static unsigned splitLength(const CharType* data, unsigned length, unsigned& int Length, unsigned& doubleLength)
39 {
40 ASSERT(length);
41
42 unsigned i = 0;
43 while (i < length && isSpaceOrNewline(data[i]))
44 ++i;
45 if (i < length && (data[i] == '+' || data[i] == '-'))
46 ++i;
47 while (i < length && isASCIIDigit(data[i]))
48 ++i;
49 intLength = i;
50 while (i < length && (isASCIIDigit(data[i]) || data[i] == '.'))
51 ++i;
52 doubleLength = i;
53
54 // IE quirk: Skip whitespace between the number and the % character (20 % => 20%).
55 while (i < length && isSpaceOrNewline(data[i]))
56 ++i;
57
58 return i;
59 }
60
61 template<typename CharType>
62 static Length parseHTMLAreaCoordinate(const CharType* data, unsigned length)
63 {
64 unsigned intLength;
65 unsigned doubleLength;
66 splitLength(data, length, intLength, doubleLength);
67
68 return Length(charactersToIntStrict(data, intLength), Fixed);
69 }
70
71 // FIXME: Per HTML5, this should follow the "rules for parsing a list of integer s".
72 Vector<Length> parseHTMLAreaElementCoords(const String& string)
73 {
74 unsigned length = string.length();
75 StringBuffer<LChar> spacified(length);
76 for (unsigned i = 0; i < length; i++) {
77 UChar cc = string[i];
78 if (cc > '9' || (cc < '0' && cc != '-' && cc != '.'))
79 spacified[i] = ' ';
80 else
81 spacified[i] = cc;
82 }
83 RefPtr<StringImpl> str = spacified.release();
84 str = str->simplifyWhiteSpace();
85 ASSERT(str->is8Bit());
86
87 if (!str->length())
88 return Vector<Length>();
89
90 unsigned len = str->count(' ') + 1;
91 Vector<Length> r(len);
92
93 unsigned i = 0;
94 unsigned pos = 0;
95 size_t pos2;
96
97 while ((pos2 = str->find(' ', pos)) != kNotFound) {
98 r[i++] = parseHTMLAreaCoordinate(str->characters8() + pos, pos2 - pos);
99 pos = pos2 + 1;
100 }
101 r[i] = parseHTMLAreaCoordinate(str->characters8() + pos, str->length() - pos );
102
103 ASSERT(i == len - 1);
104
105 return r;
106 }
107
108 class CalculationValueHandleMap { 34 class CalculationValueHandleMap {
109 USING_FAST_MALLOC(CalculationValueHandleMap); 35 USING_FAST_MALLOC(CalculationValueHandleMap);
110 WTF_MAKE_NONCOPYABLE(CalculationValueHandleMap); 36 WTF_MAKE_NONCOPYABLE(CalculationValueHandleMap);
111 public: 37 public:
112 CalculationValueHandleMap() 38 CalculationValueHandleMap()
113 : m_index(1) 39 : m_index(1)
114 { 40 {
115 } 41 }
116 42
117 int insert(PassRefPtr<CalculationValue> calcValue) 43 int insert(PassRefPtr<CalculationValue> calcValue)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return isCalculated() && (&calculationValue() == &o.calculationValue() || ca lculationValue() == o.calculationValue()); 183 return isCalculated() && (&calculationValue() == &o.calculationValue() || ca lculationValue() == o.calculationValue());
258 } 184 }
259 185
260 struct SameSizeAsLength { 186 struct SameSizeAsLength {
261 int32_t value; 187 int32_t value;
262 int32_t metaData; 188 int32_t metaData;
263 }; 189 };
264 static_assert(sizeof(Length) == sizeof(SameSizeAsLength), "length should stay sm all"); 190 static_assert(sizeof(Length) == sizeof(SameSizeAsLength), "length should stay sm all");
265 191
266 } // namespace blink 192 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/Length.h ('k') | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698