| 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/MediaQueryParser.h" | 5 #include "core/css/parser/MediaQueryParser.h" |
| 6 | 6 |
| 7 #include "core/MediaTypeNames.h" | 7 #include "core/MediaTypeNames.h" |
| 8 #include "core/css/parser/CSSPropertyParser.h" | 8 #include "core/css/parser/CSSPropertyParser.h" |
| 9 #include "core/css/parser/CSSTokenizer.h" | 9 #include "core/css/parser/CSSTokenizer.h" |
| 10 #include "wtf/Vector.h" | 10 #include "wtf/Vector.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 // State machine member functions start here | 60 // State machine member functions start here |
| 61 void MediaQueryParser::readRestrictor(CSSParserTokenType type, const CSSParserTo
ken& token) | 61 void MediaQueryParser::readRestrictor(CSSParserTokenType type, const CSSParserTo
ken& token) |
| 62 { | 62 { |
| 63 readMediaType(type, token); | 63 readMediaType(type, token); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void MediaQueryParser::readMediaNot(CSSParserTokenType type, const CSSParserToke
n& token) | 66 void MediaQueryParser::readMediaNot(CSSParserTokenType type, const CSSParserToke
n& token) |
| 67 { | 67 { |
| 68 if (type == IdentToken && equalIgnoringCase(token.value(), "not")) | 68 if (type == IdentToken && token.valueEqualsIgnoringASCIICase("not")) |
| 69 setStateAndRestrict(ReadFeatureStart, MediaQuery::Not); | 69 setStateAndRestrict(ReadFeatureStart, MediaQuery::Not); |
| 70 else | 70 else |
| 71 readFeatureStart(type, token); | 71 readFeatureStart(type, token); |
| 72 } | 72 } |
| 73 | 73 |
| 74 static bool isRestrictorOrLogicalOperator(const String& tokenValue) | 74 static bool isRestrictorOrLogicalOperator(const CSSParserToken& token) |
| 75 { | 75 { |
| 76 // FIXME: it would be more efficient to use lower-case always for tokenValue
. | 76 // FIXME: it would be more efficient to use lower-case always for tokenValue
. |
| 77 return equalIgnoringCase(tokenValue, "not") | 77 return token.valueEqualsIgnoringASCIICase("not") |
| 78 || equalIgnoringCase(tokenValue, "and") | 78 || token.valueEqualsIgnoringASCIICase("and") |
| 79 || equalIgnoringCase(tokenValue, "or") | 79 || token.valueEqualsIgnoringASCIICase("or") |
| 80 || equalIgnoringCase(tokenValue, "only"); | 80 || token.valueEqualsIgnoringASCIICase("only"); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void MediaQueryParser::readMediaType(CSSParserTokenType type, const CSSParserTok
en& token) | 83 void MediaQueryParser::readMediaType(CSSParserTokenType type, const CSSParserTok
en& token) |
| 84 { | 84 { |
| 85 if (type == LeftParenthesisToken) { | 85 if (type == LeftParenthesisToken) { |
| 86 if (m_mediaQueryData.restrictor() != MediaQuery::None) | 86 if (m_mediaQueryData.restrictor() != MediaQuery::None) |
| 87 m_state = SkipUntilComma; | 87 m_state = SkipUntilComma; |
| 88 else | 88 else |
| 89 m_state = ReadFeature; | 89 m_state = ReadFeature; |
| 90 } else if (type == IdentToken) { | 90 } else if (type == IdentToken) { |
| 91 if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "not")
) { | 91 if (m_state == ReadRestrictor && token.valueEqualsIgnoringASCIICase("not
")) { |
| 92 setStateAndRestrict(ReadMediaType, MediaQuery::Not); | 92 setStateAndRestrict(ReadMediaType, MediaQuery::Not); |
| 93 } else if (m_state == ReadRestrictor && equalIgnoringCase(token.value(),
"only")) { | 93 } else if (m_state == ReadRestrictor && token.valueEqualsIgnoringASCIICa
se("only")) { |
| 94 setStateAndRestrict(ReadMediaType, MediaQuery::Only); | 94 setStateAndRestrict(ReadMediaType, MediaQuery::Only); |
| 95 } else if (m_mediaQueryData.restrictor() != MediaQuery::None | 95 } else if (m_mediaQueryData.restrictor() != MediaQuery::None |
| 96 && isRestrictorOrLogicalOperator(token.value())) { | 96 && isRestrictorOrLogicalOperator(token)) { |
| 97 m_state = SkipUntilComma; | 97 m_state = SkipUntilComma; |
| 98 } else { | 98 } else { |
| 99 m_mediaQueryData.setMediaType(token.value()); | 99 m_mediaQueryData.setMediaType(token.value()); |
| 100 m_state = ReadAnd; | 100 m_state = ReadAnd; |
| 101 } | 101 } |
| 102 } else if (type == EOFToken && (!m_querySet->queryVector().size() || m_state
!= ReadRestrictor)) { | 102 } else if (type == EOFToken && (!m_querySet->queryVector().size() || m_state
!= ReadRestrictor)) { |
| 103 m_state = Done; | 103 m_state = Done; |
| 104 } else { | 104 } else { |
| 105 m_state = SkipUntilComma; | 105 m_state = SkipUntilComma; |
| 106 if (type == CommaToken) | 106 if (type == CommaToken) |
| 107 skipUntilComma(type, token); | 107 skipUntilComma(type, token); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 void MediaQueryParser::readAnd(CSSParserTokenType type, const CSSParserToken& to
ken) | 111 void MediaQueryParser::readAnd(CSSParserTokenType type, const CSSParserToken& to
ken) |
| 112 { | 112 { |
| 113 if (type == IdentToken && equalIgnoringCase(token.value(), "and")) { | 113 if (type == IdentToken && token.valueEqualsIgnoringASCIICase("and")) { |
| 114 m_state = ReadFeatureStart; | 114 m_state = ReadFeatureStart; |
| 115 } else if (type == CommaToken && m_parserType != MediaConditionParser) { | 115 } else if (type == CommaToken && m_parserType != MediaConditionParser) { |
| 116 m_querySet->addMediaQuery(m_mediaQueryData.takeMediaQuery()); | 116 m_querySet->addMediaQuery(m_mediaQueryData.takeMediaQuery()); |
| 117 m_state = ReadRestrictor; | 117 m_state = ReadRestrictor; |
| 118 } else if (type == EOFToken) { | 118 } else if (type == EOFToken) { |
| 119 m_state = Done; | 119 m_state = Done; |
| 120 } else { | 120 } else { |
| 121 m_state = SkipUntilComma; | 121 m_state = SkipUntilComma; |
| 122 } | 122 } |
| 123 } | 123 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 return false; | 275 return false; |
| 276 } | 276 } |
| 277 | 277 |
| 278 void MediaQueryData::setMediaType(const String& mediaType) | 278 void MediaQueryData::setMediaType(const String& mediaType) |
| 279 { | 279 { |
| 280 m_mediaType = mediaType; | 280 m_mediaType = mediaType; |
| 281 m_mediaTypeSet = true; | 281 m_mediaTypeSet = true; |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace blink | 284 } // namespace blink |
| OLD | NEW |