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

Side by Side Diff: Source/core/css/parser/CSSParserValues.h

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 14 matching lines...) Expand all
25 #include "core/css/CSSPrimitiveValue.h" 25 #include "core/css/CSSPrimitiveValue.h"
26 #include "core/css/CSSSelector.h" 26 #include "core/css/CSSSelector.h"
27 #include "core/css/CSSValueList.h" 27 #include "core/css/CSSValueList.h"
28 #include "wtf/text/AtomicString.h" 28 #include "wtf/text/AtomicString.h"
29 #include "wtf/text/WTFString.h" 29 #include "wtf/text/WTFString.h"
30 30
31 namespace blink { 31 namespace blink {
32 32
33 class QualifiedName; 33 class QualifiedName;
34 class CSSParserTokenRange; 34 class CSSParserTokenRange;
35 class CSSTokenizerScope;
35 36
36 struct CSSParserString { 37 struct CSSParserString {
37 void init(const LChar* characters, unsigned length) 38 void init(const LChar* characters, unsigned length)
38 { 39 {
39 m_data.characters8 = characters; 40 m_data.characters8 = characters;
40 m_length = length; 41 m_length = length;
41 m_is8Bit = true; 42 m_is8Bit = true;
42 } 43 }
43 44
44 void init(const UChar* characters, unsigned length) 45 void init(const UChar* characters, unsigned length)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 bool match = is8Bit() ? WTF::equalIgnoringCase(str, characters8(), lengt h()) : WTF::equalIgnoringCase(str, characters16(), length()); 92 bool match = is8Bit() ? WTF::equalIgnoringCase(str, characters8(), lengt h()) : WTF::equalIgnoringCase(str, characters16(), length());
92 if (!match) 93 if (!match)
93 return false; 94 return false;
94 ASSERT(strlen(str) >= length()); 95 ASSERT(strlen(str) >= length());
95 return str[length()] == '\0'; 96 return str[length()] == '\0';
96 } 97 }
97 98
98 operator String() const { return is8Bit() ? String(m_data.characters8, m_len gth) : StringImpl::create8BitIfPossible(m_data.characters16, m_length); } 99 operator String() const { return is8Bit() ? String(m_data.characters8, m_len gth) : StringImpl::create8BitIfPossible(m_data.characters16, m_length); }
99 operator AtomicString() const { return is8Bit() ? AtomicString(m_data.charac ters8, m_length) : AtomicString(m_data.characters16, m_length); } 100 operator AtomicString() const { return is8Bit() ? AtomicString(m_data.charac ters8, m_length) : AtomicString(m_data.characters16, m_length); }
100 101
102 bool isFunction() const { return length() > 0 && (*this)[length() - 1] == '( '; }
103
101 union { 104 union {
102 const LChar* characters8; 105 const LChar* characters8;
103 const UChar* characters16; 106 const UChar* characters16;
104 const void* charactersRaw; 107 const void* charactersRaw;
105 } m_data; 108 } m_data;
106 unsigned m_length; 109 unsigned m_length;
107 bool m_is8Bit; 110 bool m_is8Bit;
108 }; 111 };
109 112
110 struct CSSParserFunction; 113 struct CSSParserFunction;
111 class CSSParserValueList; 114 class CSSParserValueList;
112 115
113 struct CSSParserValue { 116 struct CSSParserValue {
114 CSSValueID id; 117 CSSValueID id;
115 bool isInt; 118 bool isInt;
116 union { 119 union {
117 double fValue; 120 double fValue;
118 int iValue; 121 int iValue;
119 CSSParserString string; 122 CSSParserString string;
120 CSSParserFunction* function; 123 CSSParserFunction* function;
121 CSSParserValueList* valueList; 124 CSSParserValueList* valueList;
122 struct { 125 struct {
123 UChar32 start; 126 UChar32 start;
124 UChar32 end; 127 UChar32 end;
125 } m_unicodeRange; 128 } m_unicodeRange;
129 CSSVariableData* variableData;
126 }; 130 };
127 enum { 131 enum {
128 Operator = 0x100000, 132 Operator = 0x100000,
129 Function = 0x100001, 133 Function = 0x100001,
130 ValueList = 0x100002, 134 ValueList = 0x100002,
131 Q_EMS = 0x100003, 135 Q_EMS = 0x100003,
132 HexColor = 0x100004, 136 HexColor = 0x100004,
133 // Represents a dimension by a list of two values, a CSS_NUMBER and an C SS_IDENT 137 // Represents a dimension by a list of two values, a CSS_NUMBER and an C SS_IDENT
134 DimensionList = 0x100006, 138 DimensionList = 0x100006,
135 // Represents a unicode range by a pair of UChar32 values 139 // Represents a unicode range by a pair of UChar32 values
136 UnicodeRange = 0x100007, 140 UnicodeRange = 0x100007,
141 // Reperesents a copy of part of a CSSTokenizerScope for defining and re solving variables
142 VariableValue = 0x100008,
137 }; 143 };
138 int unit; 144 int unit;
139 145
140 inline void setFromNumber(double value, int unit = CSSPrimitiveValue::CSS_NU MBER); 146 inline void setFromNumber(double value, int unit = CSSPrimitiveValue::CSS_NU MBER);
141 inline void setFromOperator(UChar); 147 inline void setFromOperator(UChar);
142 inline void setFromFunction(CSSParserFunction*); 148 inline void setFromFunction(CSSParserFunction*);
143 inline void setFromValueList(PassOwnPtr<CSSParserValueList>); 149 inline void setFromValueList(PassOwnPtr<CSSParserValueList>);
144 }; 150 };
145 151
146 class CORE_EXPORT CSSParserValueList { 152 class CORE_EXPORT CSSParserValueList {
147 WTF_MAKE_FAST_ALLOCATED(CSSParserValueList); 153 WTF_MAKE_FAST_ALLOCATED(CSSParserValueList);
148 public: 154 public:
149 CSSParserValueList() 155 CSSParserValueList()
150 : m_current(0) 156 : m_current(0)
151 { 157 {
152 } 158 }
153 CSSParserValueList(CSSParserTokenRange, bool& usesRemUnits); 159 CSSParserValueList(CSSParserTokenRange, bool& usesRemUnits, bool& usesVariab les);
154 ~CSSParserValueList(); 160 ~CSSParserValueList();
155 161
156 void addValue(const CSSParserValue&); 162 void addValue(const CSSParserValue&);
157 163
158 unsigned size() const { return m_values.size(); } 164 unsigned size() const { return m_values.size(); }
159 unsigned currentIndex() { return m_current; } 165 unsigned currentIndex() { return m_current; }
160 CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m _current] : 0; } 166 CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m _current] : 0; }
161 CSSParserValue* next() { ++m_current; return current(); } 167 CSSParserValue* next() { ++m_current; return current(); }
162 CSSParserValue* previous() 168 CSSParserValue* previous()
163 { 169 {
164 if (!m_current) 170 if (!m_current)
165 return 0; 171 return 0;
166 --m_current; 172 --m_current;
167 return current(); 173 return current();
168 } 174 }
169 void setCurrentIndex(unsigned index) 175 void setCurrentIndex(unsigned index)
170 { 176 {
171 ASSERT(index < m_values.size()); 177 ASSERT(index < m_values.size());
172 if (index < m_values.size()) 178 if (index < m_values.size())
173 m_current = index; 179 m_current = index;
174 } 180 }
175 181
176 CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values [i] : 0; } 182 CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values [i] : 0; }
177 183
178 void clearAndLeakValues() { m_values.clear(); m_current = 0;} 184 void clearAndLeakValues() { m_values.clear(); m_current = 0;}
179 void destroyAndClear(); 185 void destroyAndClear();
186 private:
187 void checkForVariableReferencesOrDestroyAndClear(const CSSParserTokenRange& originalRange);
188 void consumeVariableValue(const CSSParserTokenRange&);
180 189
181 private:
182 unsigned m_current; 190 unsigned m_current;
183 Vector<CSSParserValue, 4> m_values; 191 Vector<CSSParserValue, 4> m_values;
184 }; 192 };
185 193
186 struct CSSParserFunction { 194 struct CSSParserFunction {
187 WTF_MAKE_FAST_ALLOCATED(CSSParserFunction); 195 WTF_MAKE_FAST_ALLOCATED(CSSParserFunction);
188 public: 196 public:
189 CSSValueID id; 197 CSSValueID id;
190 OwnPtr<CSSParserValueList> args; 198 OwnPtr<CSSParserValueList> args;
191 }; 199 };
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 279 }
272 280
273 inline void CSSParserValue::setFromValueList(PassOwnPtr<CSSParserValueList> valu eList) 281 inline void CSSParserValue::setFromValueList(PassOwnPtr<CSSParserValueList> valu eList)
274 { 282 {
275 id = CSSValueInvalid; 283 id = CSSValueInvalid;
276 this->valueList = valueList.leakPtr(); 284 this->valueList = valueList.leakPtr();
277 unit = ValueList; 285 unit = ValueList;
278 isInt = false; 286 isInt = false;
279 } 287 }
280 288
281 } 289 };
282 290
283 #endif 291 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698