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 #include "core/css/parser/CSSParserToken.h" | 5 #include "core/css/parser/CSSParserToken.h" |
6 | 6 |
7 #include "core/css/CSSMarkup.h" | 7 #include "core/css/CSSMarkup.h" |
8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
9 #include "core/css/parser/CSSPropertyParser.h" | 9 #include "core/css/parser/CSSPropertyParser.h" |
10 #include "wtf/HashMap.h" | 10 #include "wtf/HashMap.h" |
11 #include "wtf/text/StringBuilder.h" | 11 #include "wtf/text/StringBuilder.h" |
12 #include <limits.h> | 12 #include <limits.h> |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 CSSParserToken::CSSParserToken(CSSParserTokenType type, BlockType blockType) | 16 CSSParserToken::CSSParserToken(CSSParserTokenType type, BlockType blockType) |
17 : m_type(type), m_blockType(blockType) {} | 17 : m_type(type), m_blockType(blockType) {} |
18 | 18 |
19 // Just a helper used for Delimiter tokens. | 19 // Just a helper used for Delimiter tokens. |
20 CSSParserToken::CSSParserToken(CSSParserTokenType type, UChar c) | 20 CSSParserToken::CSSParserToken(CSSParserTokenType type, UChar c) |
21 : m_type(type), m_blockType(NotBlock), m_delimiter(c) { | 21 : m_type(type), m_blockType(NotBlock), m_delimiter(c) { |
22 ASSERT(m_type == DelimiterToken); | 22 DCHECK_EQ(m_type, DelimiterToken); |
23 } | 23 } |
24 | 24 |
25 CSSParserToken::CSSParserToken(CSSParserTokenType type, | 25 CSSParserToken::CSSParserToken(CSSParserTokenType type, |
26 StringView value, | 26 StringView value, |
27 BlockType blockType) | 27 BlockType blockType) |
28 : m_type(type), m_blockType(blockType) { | 28 : m_type(type), m_blockType(blockType) { |
29 initValueFromStringView(value); | 29 initValueFromStringView(value); |
30 m_id = -1; | 30 m_id = -1; |
31 } | 31 } |
32 | 32 |
33 CSSParserToken::CSSParserToken(CSSParserTokenType type, | 33 CSSParserToken::CSSParserToken(CSSParserTokenType type, |
34 double numericValue, | 34 double numericValue, |
35 NumericValueType numericValueType, | 35 NumericValueType numericValueType, |
36 NumericSign sign) | 36 NumericSign sign) |
37 : m_type(type), | 37 : m_type(type), |
38 m_blockType(NotBlock), | 38 m_blockType(NotBlock), |
39 m_numericValueType(numericValueType), | 39 m_numericValueType(numericValueType), |
40 m_numericSign(sign), | 40 m_numericSign(sign), |
41 m_unit(static_cast<unsigned>(CSSPrimitiveValue::UnitType::Number)) { | 41 m_unit(static_cast<unsigned>(CSSPrimitiveValue::UnitType::Number)) { |
42 ASSERT(type == NumberToken); | 42 DCHECK_EQ(type, NumberToken); |
43 m_numericValue = | 43 m_numericValue = |
44 clampTo<double>(numericValue, -std::numeric_limits<float>::max(), | 44 clampTo<double>(numericValue, -std::numeric_limits<float>::max(), |
45 std::numeric_limits<float>::max()); | 45 std::numeric_limits<float>::max()); |
46 } | 46 } |
47 | 47 |
48 CSSParserToken::CSSParserToken(CSSParserTokenType type, | 48 CSSParserToken::CSSParserToken(CSSParserTokenType type, |
49 UChar32 start, | 49 UChar32 start, |
50 UChar32 end) | 50 UChar32 end) |
51 : m_type(UnicodeRangeToken), m_blockType(NotBlock) { | 51 : m_type(UnicodeRangeToken), m_blockType(NotBlock) { |
52 DCHECK_EQ(type, UnicodeRangeToken); | 52 DCHECK_EQ(type, UnicodeRangeToken); |
53 m_unicodeRange.start = start; | 53 m_unicodeRange.start = start; |
54 m_unicodeRange.end = end; | 54 m_unicodeRange.end = end; |
55 } | 55 } |
56 | 56 |
57 CSSParserToken::CSSParserToken(HashTokenType type, StringView value) | 57 CSSParserToken::CSSParserToken(HashTokenType type, StringView value) |
58 : m_type(HashToken), m_blockType(NotBlock), m_hashTokenType(type) { | 58 : m_type(HashToken), m_blockType(NotBlock), m_hashTokenType(type) { |
59 initValueFromStringView(value); | 59 initValueFromStringView(value); |
60 } | 60 } |
61 | 61 |
62 void CSSParserToken::convertToDimensionWithUnit(StringView unit) { | 62 void CSSParserToken::convertToDimensionWithUnit(StringView unit) { |
63 ASSERT(m_type == NumberToken); | 63 DCHECK_EQ(m_type, NumberToken); |
64 m_type = DimensionToken; | 64 m_type = DimensionToken; |
65 initValueFromStringView(unit); | 65 initValueFromStringView(unit); |
66 m_unit = static_cast<unsigned>(CSSPrimitiveValue::stringToUnitType(unit)); | 66 m_unit = static_cast<unsigned>(CSSPrimitiveValue::stringToUnitType(unit)); |
67 } | 67 } |
68 | 68 |
69 void CSSParserToken::convertToPercentage() { | 69 void CSSParserToken::convertToPercentage() { |
70 ASSERT(m_type == NumberToken); | 70 DCHECK_EQ(m_type, NumberToken); |
71 m_type = PercentageToken; | 71 m_type = PercentageToken; |
72 m_unit = static_cast<unsigned>(CSSPrimitiveValue::UnitType::Percentage); | 72 m_unit = static_cast<unsigned>(CSSPrimitiveValue::UnitType::Percentage); |
73 } | 73 } |
74 | 74 |
75 UChar CSSParserToken::delimiter() const { | 75 UChar CSSParserToken::delimiter() const { |
76 ASSERT(m_type == DelimiterToken); | 76 DCHECK_EQ(m_type, DelimiterToken); |
77 return m_delimiter; | 77 return m_delimiter; |
78 } | 78 } |
79 | 79 |
80 NumericSign CSSParserToken::numericSign() const { | 80 NumericSign CSSParserToken::numericSign() const { |
81 // This is valid for DimensionToken and PercentageToken, but only used | 81 // This is valid for DimensionToken and PercentageToken, but only used |
82 // in <an+b> parsing on NumberTokens. | 82 // in <an+b> parsing on NumberTokens. |
83 ASSERT(m_type == NumberToken); | 83 DCHECK_EQ(m_type, NumberToken); |
84 return static_cast<NumericSign>(m_numericSign); | 84 return static_cast<NumericSign>(m_numericSign); |
85 } | 85 } |
86 | 86 |
87 NumericValueType CSSParserToken::numericValueType() const { | 87 NumericValueType CSSParserToken::numericValueType() const { |
88 ASSERT(m_type == NumberToken || m_type == PercentageToken || | 88 DCHECK(m_type == NumberToken || m_type == PercentageToken || |
89 m_type == DimensionToken); | 89 m_type == DimensionToken); |
90 return static_cast<NumericValueType>(m_numericValueType); | 90 return static_cast<NumericValueType>(m_numericValueType); |
91 } | 91 } |
92 | 92 |
93 double CSSParserToken::numericValue() const { | 93 double CSSParserToken::numericValue() const { |
94 ASSERT(m_type == NumberToken || m_type == PercentageToken || | 94 DCHECK(m_type == NumberToken || m_type == PercentageToken || |
95 m_type == DimensionToken); | 95 m_type == DimensionToken); |
96 return m_numericValue; | 96 return m_numericValue; |
97 } | 97 } |
98 | 98 |
99 CSSPropertyID CSSParserToken::parseAsUnresolvedCSSPropertyID() const { | 99 CSSPropertyID CSSParserToken::parseAsUnresolvedCSSPropertyID() const { |
100 ASSERT(m_type == IdentToken); | 100 DCHECK_EQ(m_type, IdentToken); |
101 return unresolvedCSSPropertyID(value()); | 101 return unresolvedCSSPropertyID(value()); |
102 } | 102 } |
103 | 103 |
104 CSSValueID CSSParserToken::id() const { | 104 CSSValueID CSSParserToken::id() const { |
105 if (m_type != IdentToken) | 105 if (m_type != IdentToken) |
106 return CSSValueInvalid; | 106 return CSSValueInvalid; |
107 if (m_id < 0) | 107 if (m_id < 0) |
108 m_id = cssValueKeywordID(value()); | 108 m_id = cssValueKeywordID(value()); |
109 return static_cast<CSSValueID>(m_id); | 109 return static_cast<CSSValueID>(m_id); |
110 } | 110 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 return builder.append('['); | 271 return builder.append('['); |
272 case RightBracketToken: | 272 case RightBracketToken: |
273 return builder.append(']'); | 273 return builder.append(']'); |
274 case LeftBraceToken: | 274 case LeftBraceToken: |
275 return builder.append('{'); | 275 return builder.append('{'); |
276 case RightBraceToken: | 276 case RightBraceToken: |
277 return builder.append('}'); | 277 return builder.append('}'); |
278 | 278 |
279 case EOFToken: | 279 case EOFToken: |
280 case CommentToken: | 280 case CommentToken: |
281 ASSERT_NOT_REACHED(); | 281 NOTREACHED(); |
282 return; | 282 return; |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 } // namespace blink | 286 } // namespace blink |
OLD | NEW |