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 "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/MediaQueryParser.h" | 6 #include "core/css/parser/MediaQueryParser.h" |
7 | 7 |
8 #include "core/MediaTypeNames.h" | 8 #include "core/MediaTypeNames.h" |
9 #include "core/css/parser/CSSPropertyParser.h" | 9 #include "core/css/parser/CSSPropertyParser.h" |
10 #include "core/css/parser/CSSTokenizer.h" | 10 #include "core/css/parser/CSSTokenizer.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 void MediaQueryParser::readMediaNot(CSSParserTokenType type, const CSSParserToke
n& token) | 71 void MediaQueryParser::readMediaNot(CSSParserTokenType type, const CSSParserToke
n& token) |
72 { | 72 { |
73 if (type == IdentToken && equalIgnoringCase(token.value(), "not")) | 73 if (type == IdentToken && equalIgnoringCase(token.value(), "not")) |
74 setStateAndRestrict(ReadFeatureStart, MediaQuery::Not); | 74 setStateAndRestrict(ReadFeatureStart, MediaQuery::Not); |
75 else | 75 else |
76 readFeatureStart(type, token); | 76 readFeatureStart(type, token); |
77 } | 77 } |
78 | 78 |
| 79 static bool isRestrictorOrLogicalOperator(const String& tokenValue) |
| 80 { |
| 81 // FIXME: it would be more efficient to use lower-case always for tokenValue
. |
| 82 return equalIgnoringCase(tokenValue, "not") |
| 83 || equalIgnoringCase(tokenValue, "and") |
| 84 || equalIgnoringCase(tokenValue, "or") |
| 85 || equalIgnoringCase(tokenValue, "only"); |
| 86 } |
| 87 |
79 void MediaQueryParser::readMediaType(CSSParserTokenType type, const CSSParserTok
en& token) | 88 void MediaQueryParser::readMediaType(CSSParserTokenType type, const CSSParserTok
en& token) |
80 { | 89 { |
81 if (type == LeftParenthesisToken) { | 90 if (type == LeftParenthesisToken) { |
82 m_state = ReadFeature; | 91 if (m_mediaQueryData.restrictor() != MediaQuery::None) |
| 92 m_state = SkipUntilComma; |
| 93 else |
| 94 m_state = ReadFeature; |
83 } else if (type == IdentToken) { | 95 } else if (type == IdentToken) { |
84 if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "not")
) { | 96 if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "not")
) { |
85 setStateAndRestrict(ReadMediaType, MediaQuery::Not); | 97 setStateAndRestrict(ReadMediaType, MediaQuery::Not); |
86 } else if (m_state == ReadRestrictor && equalIgnoringCase(token.value(),
"only")) { | 98 } else if (m_state == ReadRestrictor && equalIgnoringCase(token.value(),
"only")) { |
87 setStateAndRestrict(ReadMediaType, MediaQuery::Only); | 99 setStateAndRestrict(ReadMediaType, MediaQuery::Only); |
| 100 } else if (m_mediaQueryData.restrictor() != MediaQuery::None |
| 101 && isRestrictorOrLogicalOperator(token.value())) { |
| 102 m_state = SkipUntilComma; |
88 } else { | 103 } else { |
89 m_mediaQueryData.setMediaType(token.value()); | 104 m_mediaQueryData.setMediaType(token.value()); |
90 m_state = ReadAnd; | 105 m_state = ReadAnd; |
91 } | 106 } |
92 } else if (type == EOFToken && (!m_querySet->queryVector().size() || m_state
!= ReadRestrictor)) { | 107 } else if (type == EOFToken && (!m_querySet->queryVector().size() || m_state
!= ReadRestrictor)) { |
93 m_state = Done; | 108 m_state = Done; |
94 } else { | 109 } else { |
95 m_state = SkipUntilComma; | 110 m_state = SkipUntilComma; |
96 if (type == CommaToken) | 111 if (type == CommaToken) |
97 skipUntilComma(type, token); | 112 skipUntilComma(type, token); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 return true; | 295 return true; |
281 } | 296 } |
282 | 297 |
283 void MediaQueryData::setMediaType(const String& mediaType) | 298 void MediaQueryData::setMediaType(const String& mediaType) |
284 { | 299 { |
285 m_mediaType = mediaType; | 300 m_mediaType = mediaType; |
286 m_mediaTypeSet = true; | 301 m_mediaTypeSet = true; |
287 } | 302 } |
288 | 303 |
289 } // namespace blink | 304 } // namespace blink |
OLD | NEW |