OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MediaQueryParser_h |
| 6 #define MediaQueryParser_h |
| 7 |
| 8 #include "core/css/CSSParserValues.h" |
| 9 #include "core/css/MediaList.h" |
| 10 #include "core/css/MediaQuery.h" |
| 11 #include "core/css/MediaQueryExp.h" |
| 12 #include "core/css/parser/CSSToken.h" |
| 13 #include "wtf/Vector.h" |
| 14 #include "wtf/text/WTFString.h" |
| 15 |
| 16 namespace WebCore { |
| 17 |
| 18 class MediaQuerySet; |
| 19 |
| 20 class MediaQueryData { |
| 21 private: |
| 22 RefPtrWillBeMember<MediaQuerySet> m_querySet; |
| 23 MediaQuery::Restrictor m_restrictor; |
| 24 String m_mediaType; |
| 25 OwnPtr<ExpressionHeapVector> m_expressions; |
| 26 String m_mediaFeature; |
| 27 CSSParserValueList m_valueList; |
| 28 bool m_mediaTypeSet; |
| 29 |
| 30 public: |
| 31 MediaQueryData(); |
| 32 void resetCurrentQuery(); |
| 33 void addCurrentMediaQuery(); |
| 34 bool addExpression(); |
| 35 void addParserValue(CSSTokenType, CSSToken*); |
| 36 void setMediaType(const String&); |
| 37 |
| 38 inline PassRefPtrWillBeRawPtr<MediaQuerySet> querySet() |
| 39 { |
| 40 return m_querySet; |
| 41 } |
| 42 |
| 43 inline unsigned querySetSize() |
| 44 { |
| 45 return m_querySet->queryVector().size(); |
| 46 } |
| 47 |
| 48 inline bool currentMediaQueryChanged() |
| 49 { |
| 50 return (m_restrictor != MediaQuery::None || m_mediaTypeSet || m_expressi
ons->size() > 0); |
| 51 } |
| 52 |
| 53 inline void addNotAllMediaQuery() |
| 54 { |
| 55 m_querySet->addMediaQuery(adoptPtr(new MediaQuery(MediaQuery::Not, "all"
, nullptr))); |
| 56 } |
| 57 |
| 58 inline void setRestrictor(MediaQuery::Restrictor restrictor) { m_restrictor
= restrictor; } |
| 59 |
| 60 inline void setMediaFeature(const String& str) { m_mediaFeature = str; } |
| 61 }; |
| 62 |
| 63 class MediaQueryParser { |
| 64 public: |
| 65 static PassRefPtrWillBeRawPtr<MediaQuerySet> parse(String); |
| 66 |
| 67 private: |
| 68 MediaQueryParser(String); |
| 69 virtual ~MediaQueryParser() { }; |
| 70 |
| 71 PassRefPtrWillBeRawPtr<MediaQuerySet> parseImpl(); |
| 72 |
| 73 |
| 74 typedef Vector<CSSToken>::iterator TokenIterator; |
| 75 |
| 76 void readRestrictor(CSSTokenType, TokenIterator&); |
| 77 void readMediaType(CSSTokenType, TokenIterator&); |
| 78 void readAnd(CSSTokenType, TokenIterator&); |
| 79 void readFeatureStart(CSSTokenType, TokenIterator&); |
| 80 void readFeature(CSSTokenType, TokenIterator&); |
| 81 void readFeatureColon(CSSTokenType, TokenIterator&); |
| 82 void readFeatureValue(CSSTokenType, TokenIterator&); |
| 83 void readFeatureEnd(CSSTokenType, TokenIterator&); |
| 84 void skipTillComma(CSSTokenType, TokenIterator&); |
| 85 void skipTillParen(CSSTokenType, TokenIterator&); |
| 86 void done(CSSTokenType, TokenIterator&); |
| 87 |
| 88 typedef void (MediaQueryParser::*State)(CSSTokenType, TokenIterator&); |
| 89 |
| 90 State m_state; |
| 91 Vector<CSSToken> m_tokens; |
| 92 MediaQueryData m_mediaQueryData; |
| 93 }; |
| 94 |
| 95 } // namespace WebCore |
| 96 |
| 97 #endif // MediaQueryParser_h |
OLD | NEW |