OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CSSParserToken_h | 5 #ifndef CSSParserToken_h |
6 #define CSSParserToken_h | 6 #define CSSParserToken_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
10 #include "core/css/parser/CSSParserString.h" | |
11 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
| 11 #include "wtf/text/StringView.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 enum CSSParserTokenType { | 15 enum CSSParserTokenType { |
16 IdentToken = 0, | 16 IdentToken = 0, |
17 FunctionToken, | 17 FunctionToken, |
18 AtKeywordToken, | 18 AtKeywordToken, |
19 HashToken, | 19 HashToken, |
20 UrlToken, | 20 UrlToken, |
21 BadUrlToken, | 21 BadUrlToken, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 class CORE_EXPORT CSSParserToken { | 67 class CORE_EXPORT CSSParserToken { |
68 USING_FAST_MALLOC(CSSParserToken); | 68 USING_FAST_MALLOC(CSSParserToken); |
69 public: | 69 public: |
70 enum BlockType { | 70 enum BlockType { |
71 NotBlock, | 71 NotBlock, |
72 BlockStart, | 72 BlockStart, |
73 BlockEnd, | 73 BlockEnd, |
74 }; | 74 }; |
75 | 75 |
76 CSSParserToken(CSSParserTokenType, BlockType = NotBlock); | 76 CSSParserToken(CSSParserTokenType, BlockType = NotBlock); |
77 CSSParserToken(CSSParserTokenType, CSSParserString, BlockType = NotBlock); | 77 CSSParserToken(CSSParserTokenType, StringView, BlockType = NotBlock); |
78 | 78 |
79 CSSParserToken(CSSParserTokenType, UChar); // for DelimiterToken | 79 CSSParserToken(CSSParserTokenType, UChar); // for DelimiterToken |
80 CSSParserToken(CSSParserTokenType, double, NumericValueType, NumericSign); /
/ for NumberToken | 80 CSSParserToken(CSSParserTokenType, double, NumericValueType, NumericSign); /
/ for NumberToken |
81 CSSParserToken(CSSParserTokenType, UChar32, UChar32); // for UnicodeRangeTok
en | 81 CSSParserToken(CSSParserTokenType, UChar32, UChar32); // for UnicodeRangeTok
en |
82 | 82 |
83 CSSParserToken(HashTokenType, CSSParserString); | 83 CSSParserToken(HashTokenType, StringView); |
84 | 84 |
85 bool operator==(const CSSParserToken& other) const; | 85 bool operator==(const CSSParserToken& other) const; |
86 bool operator!=(const CSSParserToken& other) const { return !(*this == other
); } | 86 bool operator!=(const CSSParserToken& other) const { return !(*this == other
); } |
87 | 87 |
88 // Converts NumberToken to DimensionToken. | 88 // Converts NumberToken to DimensionToken. |
89 void convertToDimensionWithUnit(CSSParserString); | 89 void convertToDimensionWithUnit(StringView); |
90 | 90 |
91 // Converts NumberToken to PercentageToken. | 91 // Converts NumberToken to PercentageToken. |
92 void convertToPercentage(); | 92 void convertToPercentage(); |
93 | 93 |
94 CSSParserTokenType type() const { return static_cast<CSSParserTokenType>(m_t
ype); } | 94 CSSParserTokenType type() const { return static_cast<CSSParserTokenType>(m_t
ype); } |
95 CSSParserString value() const | 95 StringView value() const |
96 { | 96 { |
97 CSSParserString ret; | 97 return StringView(m_valueDataCharRaw, m_valueLength, m_valueIs8Bit); |
98 ret.initRaw(m_valueDataCharRaw, m_valueLength, m_valueIs8Bit); | |
99 return ret; | |
100 } | 98 } |
101 template<unsigned matchLength> | 99 // TODO(esprehn): Remove this method, callers should just use equalIgnoringA
SCIICase directly. |
102 bool valueEqualsIgnoringASCIICase(const char (&match)[matchLength]) const {
return value().equalIgnoringASCIICase<matchLength>(match); } | 100 bool valueEqualsIgnoringASCIICase(StringView match) const { return equalIgno
ringASCIICase(value(), match); } |
103 | 101 |
104 UChar delimiter() const; | 102 UChar delimiter() const; |
105 NumericSign numericSign() const; | 103 NumericSign numericSign() const; |
106 NumericValueType numericValueType() const; | 104 NumericValueType numericValueType() const; |
107 double numericValue() const; | 105 double numericValue() const; |
108 HashTokenType getHashTokenType() const { ASSERT(m_type == HashToken); return
m_hashTokenType; } | 106 HashTokenType getHashTokenType() const { ASSERT(m_type == HashToken); return
m_hashTokenType; } |
109 BlockType getBlockType() const { return static_cast<BlockType>(m_blockType);
} | 107 BlockType getBlockType() const { return static_cast<BlockType>(m_blockType);
} |
110 CSSPrimitiveValue::UnitType unitType() const { return static_cast<CSSPrimiti
veValue::UnitType>(m_unit); } | 108 CSSPrimitiveValue::UnitType unitType() const { return static_cast<CSSPrimiti
veValue::UnitType>(m_unit); } |
111 UChar32 unicodeRangeStart() const { ASSERT(m_type == UnicodeRangeToken); ret
urn m_unicodeRange.start; } | 109 UChar32 unicodeRangeStart() const { ASSERT(m_type == UnicodeRangeToken); ret
urn m_unicodeRange.start; } |
112 UChar32 unicodeRangeEnd() const { ASSERT(m_type == UnicodeRangeToken); retur
n m_unicodeRange.end; } | 110 UChar32 unicodeRangeEnd() const { ASSERT(m_type == UnicodeRangeToken); retur
n m_unicodeRange.end; } |
113 CSSValueID id() const; | 111 CSSValueID id() const; |
114 CSSValueID functionId() const; | 112 CSSValueID functionId() const; |
115 | 113 |
116 bool hasStringBacking() const; | 114 bool hasStringBacking() const; |
117 | 115 |
118 CSSPropertyID parseAsUnresolvedCSSPropertyID() const; | 116 CSSPropertyID parseAsUnresolvedCSSPropertyID() const; |
119 | 117 |
120 void serialize(StringBuilder&) const; | 118 void serialize(StringBuilder&) const; |
121 | 119 |
122 CSSParserToken copyWithUpdatedString(const CSSParserString&) const; | 120 CSSParserToken copyWithUpdatedString(const StringView&) const; |
123 | 121 |
124 private: | 122 private: |
125 void initValueFromCSSParserString(const CSSParserString& value) | 123 void initValueFromStringView(StringView string) |
126 { | 124 { |
127 m_valueLength = value.m_length; | 125 m_valueLength = string.length(); |
128 m_valueIs8Bit = value.m_is8Bit; | 126 m_valueIs8Bit = string.is8Bit(); |
129 m_valueDataCharRaw = value.m_data.charactersRaw; | 127 m_valueDataCharRaw = string.bytes(); |
130 } | 128 } |
131 unsigned m_type : 6; // CSSParserTokenType | 129 unsigned m_type : 6; // CSSParserTokenType |
132 unsigned m_blockType : 2; // BlockType | 130 unsigned m_blockType : 2; // BlockType |
133 unsigned m_numericValueType : 1; // NumericValueType | 131 unsigned m_numericValueType : 1; // NumericValueType |
134 unsigned m_numericSign : 2; // NumericSign | 132 unsigned m_numericSign : 2; // NumericSign |
135 unsigned m_unit : 7; // CSSPrimitiveValue::UnitType | 133 unsigned m_unit : 7; // CSSPrimitiveValue::UnitType |
136 | 134 |
137 bool valueDataCharRawEqual(const CSSParserToken& other) const; | 135 bool valueDataCharRawEqual(const CSSParserToken& other) const; |
138 | 136 |
139 // m_value... is an unpacked CSSParserString so that we can pack it | 137 // m_value... is an unpacked StringView so that we can pack it |
140 // tightly with the rest of this object for a smaller object size. | 138 // tightly with the rest of this object for a smaller object size. |
141 bool m_valueIs8Bit : 1; | 139 bool m_valueIs8Bit : 1; |
142 unsigned m_valueLength; | 140 unsigned m_valueLength; |
143 const void* m_valueDataCharRaw; // Either LChar* or UChar*. | 141 const void* m_valueDataCharRaw; // Either LChar* or UChar*. |
144 | 142 |
145 union { | 143 union { |
146 UChar m_delimiter; | 144 UChar m_delimiter; |
147 HashTokenType m_hashTokenType; | 145 HashTokenType m_hashTokenType; |
148 double m_numericValue; | 146 double m_numericValue; |
149 mutable int m_id; | 147 mutable int m_id; |
150 | 148 |
151 struct { | 149 struct { |
152 UChar32 start; | 150 UChar32 start; |
153 UChar32 end; | 151 UChar32 end; |
154 } m_unicodeRange; | 152 } m_unicodeRange; |
155 }; | 153 }; |
156 }; | 154 }; |
157 | 155 |
158 } // namespace blink | 156 } // namespace blink |
159 | 157 |
160 namespace WTF { | 158 namespace WTF { |
161 template <> | 159 template <> |
162 struct IsTriviallyMoveAssignable<blink::CSSParserToken> { | 160 struct IsTriviallyMoveAssignable<blink::CSSParserToken> { |
163 STATIC_ONLY(IsTriviallyMoveAssignable); | 161 STATIC_ONLY(IsTriviallyMoveAssignable); |
164 static const bool value = true; | 162 static const bool value = true; |
165 }; | 163 }; |
166 } | 164 } |
167 | 165 |
168 #endif // CSSSParserToken_h | 166 #endif // CSSSParserToken_h |
OLD | NEW |