| OLD | NEW |
| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef CSSParserValues_h | 21 #ifndef CSSParserSelector_h |
| 22 #define CSSParserValues_h | 22 #define CSSParserSelector_h |
| 23 | 23 |
| 24 #include "core/CSSValueKeywords.h" | |
| 25 #include "core/css/CSSPrimitiveValue.h" | |
| 26 #include "core/css/CSSSelector.h" | 24 #include "core/css/CSSSelector.h" |
| 27 #include "core/css/CSSValueList.h" | |
| 28 #include "core/css/parser/CSSParserString.h" | |
| 29 #include "core/css/parser/CSSParserTokenRange.h" | |
| 30 #include "wtf/Allocator.h" | |
| 31 | 25 |
| 32 namespace blink { | 26 namespace blink { |
| 33 | 27 |
| 34 class QualifiedName; | |
| 35 | |
| 36 struct CSSParserFunction; | |
| 37 struct CSSParserCalcFunction; | |
| 38 class CSSParserValueList; | |
| 39 | |
| 40 struct CSSParserValue { | |
| 41 ALLOW_ONLY_INLINE_ALLOCATION(); | |
| 42 CSSValueID id; | |
| 43 bool isInt; | |
| 44 union { | |
| 45 double fValue; | |
| 46 int iValue; | |
| 47 CSSParserString string; | |
| 48 CSSParserFunction* function; | |
| 49 CSSParserCalcFunction* calcFunction; | |
| 50 CSSParserValueList* valueList; | |
| 51 struct { | |
| 52 UChar32 start; | |
| 53 UChar32 end; | |
| 54 } m_unicodeRange; | |
| 55 }; | |
| 56 enum { | |
| 57 Operator = 0x100000, | |
| 58 Function = 0x100001, | |
| 59 CalcFunction = 0x100002, | |
| 60 ValueList = 0x100003, | |
| 61 HexColor = 0x100004, | |
| 62 Identifier = 0x100005, | |
| 63 // Represents a dimension by a list of two values, a UnitType::Number an
d an Identifier | |
| 64 DimensionList = 0x100006, | |
| 65 // Represents a unicode range by a pair of UChar32 values | |
| 66 UnicodeRange = 0x100007, | |
| 67 }; | |
| 68 int m_unit; | |
| 69 CSSPrimitiveValue::UnitType unit() const { return static_cast<CSSPrimitiveVa
lue::UnitType>(m_unit); } | |
| 70 void setUnit(CSSPrimitiveValue::UnitType unit) { m_unit = static_cast<int>(u
nit); } | |
| 71 | |
| 72 inline void setFromNumber(double value, CSSPrimitiveValue::UnitType); | |
| 73 inline void setFromOperator(UChar); | |
| 74 inline void setFromValueList(PassOwnPtr<CSSParserValueList>); | |
| 75 }; | |
| 76 | |
| 77 class CORE_EXPORT CSSParserValueList { | |
| 78 WTF_MAKE_FAST_ALLOCATED(CSSParserValueList); | |
| 79 public: | |
| 80 CSSParserValueList() | |
| 81 : m_current(0) | |
| 82 { | |
| 83 } | |
| 84 CSSParserValueList(CSSParserTokenRange); | |
| 85 ~CSSParserValueList(); | |
| 86 | |
| 87 void addValue(const CSSParserValue&); | |
| 88 | |
| 89 unsigned size() const { return m_values.size(); } | |
| 90 unsigned currentIndex() { return m_current; } | |
| 91 CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m
_current] : 0; } | |
| 92 CSSParserValue* next() { ++m_current; return current(); } | |
| 93 CSSParserValue* previous() | |
| 94 { | |
| 95 if (!m_current) | |
| 96 return 0; | |
| 97 --m_current; | |
| 98 return current(); | |
| 99 } | |
| 100 void setCurrentIndex(unsigned index) | |
| 101 { | |
| 102 ASSERT(index < m_values.size()); | |
| 103 if (index < m_values.size()) | |
| 104 m_current = index; | |
| 105 } | |
| 106 | |
| 107 CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values
[i] : 0; } | |
| 108 | |
| 109 void clearAndLeakValues() { m_values.clear(); m_current = 0;} | |
| 110 void destroyAndClear(); | |
| 111 | |
| 112 private: | |
| 113 unsigned m_current; | |
| 114 Vector<CSSParserValue, 4> m_values; | |
| 115 }; | |
| 116 | |
| 117 struct CSSParserFunction { | |
| 118 WTF_MAKE_FAST_ALLOCATED(CSSParserFunction); | |
| 119 public: | |
| 120 CSSValueID id; | |
| 121 OwnPtr<CSSParserValueList> args; | |
| 122 }; | |
| 123 | |
| 124 struct CSSParserCalcFunction { | |
| 125 WTF_MAKE_FAST_ALLOCATED(CSSParserCalcFunction); | |
| 126 public: | |
| 127 CSSParserCalcFunction(CSSParserTokenRange args_) : args(args_) {} | |
| 128 CSSParserTokenRange args; | |
| 129 }; | |
| 130 | |
| 131 class CSSParserSelector { | 28 class CSSParserSelector { |
| 132 WTF_MAKE_NONCOPYABLE(CSSParserSelector); WTF_MAKE_FAST_ALLOCATED(CSSParserSe
lector); | 29 WTF_MAKE_NONCOPYABLE(CSSParserSelector); WTF_MAKE_FAST_ALLOCATED(CSSParserSe
lector); |
| 133 public: | 30 public: |
| 134 CSSParserSelector(); | 31 CSSParserSelector(); |
| 135 explicit CSSParserSelector(const QualifiedName&, bool isImplicit = false); | 32 explicit CSSParserSelector(const QualifiedName&, bool isImplicit = false); |
| 136 | 33 |
| 137 static PassOwnPtr<CSSParserSelector> create() { return adoptPtr(new CSSParse
rSelector); } | 34 static PassOwnPtr<CSSParserSelector> create() { return adoptPtr(new CSSParse
rSelector); } |
| 138 static PassOwnPtr<CSSParserSelector> create(const QualifiedName& name, bool
isImplicit = false) { return adoptPtr(new CSSParserSelector(name, isImplicit));
} | 35 static PassOwnPtr<CSSParserSelector> create(const QualifiedName& name, bool
isImplicit = false) { return adoptPtr(new CSSParserSelector(name, isImplicit));
} |
| 139 | 36 |
| 140 ~CSSParserSelector(); | 37 ~CSSParserSelector(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 private: | 74 private: |
| 178 OwnPtr<CSSSelector> m_selector; | 75 OwnPtr<CSSSelector> m_selector; |
| 179 OwnPtr<CSSParserSelector> m_tagHistory; | 76 OwnPtr<CSSParserSelector> m_tagHistory; |
| 180 }; | 77 }; |
| 181 | 78 |
| 182 inline bool CSSParserSelector::hasShadowPseudo() const | 79 inline bool CSSParserSelector::hasShadowPseudo() const |
| 183 { | 80 { |
| 184 return m_selector->relation() == CSSSelector::ShadowPseudo; | 81 return m_selector->relation() == CSSSelector::ShadowPseudo; |
| 185 } | 82 } |
| 186 | 83 |
| 187 inline void CSSParserValue::setFromNumber(double value, CSSPrimitiveValue::UnitT
ype unit) | 84 } // namespace blink |
| 188 { | |
| 189 id = CSSValueInvalid; | |
| 190 isInt = false; | |
| 191 fValue = value; | |
| 192 this->setUnit(std::isfinite(value) ? unit : CSSPrimitiveValue::UnitType::Unk
nown); | |
| 193 } | |
| 194 | |
| 195 inline void CSSParserValue::setFromOperator(UChar c) | |
| 196 { | |
| 197 id = CSSValueInvalid; | |
| 198 m_unit = Operator; | |
| 199 iValue = c; | |
| 200 isInt = false; | |
| 201 } | |
| 202 | |
| 203 inline void CSSParserValue::setFromValueList(PassOwnPtr<CSSParserValueList> valu
eList) | |
| 204 { | |
| 205 id = CSSValueInvalid; | |
| 206 this->valueList = valueList.leakPtr(); | |
| 207 m_unit = ValueList; | |
| 208 isInt = false; | |
| 209 } | |
| 210 | |
| 211 } | |
| 212 | 85 |
| 213 #endif | 86 #endif |
| OLD | NEW |