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/MediaQueryToken.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 MediaQuery::Restrictor m_restrictor; | |
23 String m_mediaType; | |
24 OwnPtr<ExpressionHeapVector> m_expressions; | |
25 String m_mediaFeature; | |
26 CSSParserValueList m_valueList; | |
27 bool m_mediaTypeSet; | |
28 | |
29 public: | |
30 MediaQueryData(); | |
31 void clear(); | |
32 bool addExpression(); | |
33 void addParserValue(MediaQueryTokenType, MediaQueryToken&); | |
34 void setMediaType(const String&); | |
35 PassOwnPtr<MediaQuery> takeMediaQuery(); | |
36 | |
37 inline bool currentMediaQueryChanged() const | |
38 { | |
39 return (m_restrictor != MediaQuery::None || m_mediaTypeSet || m_expressi
ons->size() > 0); | |
40 } | |
41 | |
42 inline void setRestrictor(MediaQuery::Restrictor restrictor) { m_restrictor
= restrictor; } | |
43 | |
44 inline void setMediaFeature(const String& str) { m_mediaFeature = str; } | |
45 }; | |
46 | |
47 class MediaQueryParser { | |
48 public: | |
49 static PassRefPtrWillBeRawPtr<MediaQuerySet> parse(const String&); | |
50 | |
51 private: | |
52 MediaQueryParser(const String&); | |
53 virtual ~MediaQueryParser() { }; | |
54 | |
55 PassRefPtrWillBeRawPtr<MediaQuerySet> parseImpl(); | |
56 | |
57 typedef Vector<MediaQueryToken>::iterator TokenIterator; | |
58 | |
59 void processToken(TokenIterator&); | |
60 | |
61 void readRestrictor(MediaQueryTokenType, TokenIterator&); | |
62 void readMediaType(MediaQueryTokenType, TokenIterator&); | |
63 void readAnd(MediaQueryTokenType, TokenIterator&); | |
64 void readFeatureStart(MediaQueryTokenType, TokenIterator&); | |
65 void readFeature(MediaQueryTokenType, TokenIterator&); | |
66 void readFeatureColon(MediaQueryTokenType, TokenIterator&); | |
67 void readFeatureValue(MediaQueryTokenType, TokenIterator&); | |
68 void readFeatureEnd(MediaQueryTokenType, TokenIterator&); | |
69 void skipUntilComma(MediaQueryTokenType, TokenIterator&); | |
70 void skipUntilParenthesis(MediaQueryTokenType, TokenIterator&); | |
71 void done(MediaQueryTokenType, TokenIterator&); | |
72 | |
73 typedef void (MediaQueryParser::*State)(MediaQueryTokenType, TokenIterator&)
; | |
74 | |
75 void setStateAndRestrict(State, MediaQuery::Restrictor); | |
76 | |
77 State m_state; | |
78 Vector<MediaQueryToken> m_tokens; | |
79 MediaQueryData m_mediaQueryData; | |
80 RefPtrWillBeMember<MediaQuerySet> m_querySet; | |
81 | |
82 const static State ReadRestrictor; | |
83 const static State ReadMediaType; | |
84 const static State ReadAnd; | |
85 const static State ReadFeatureStart; | |
86 const static State ReadFeature; | |
87 const static State ReadFeatureColon; | |
88 const static State ReadFeatureValue; | |
89 const static State ReadFeatureEnd; | |
90 const static State SkipUntilComma; | |
91 const static State SkipUntilParenthesis; | |
92 const static State Done; | |
93 | |
94 }; | |
95 | |
96 } // namespace WebCore | |
97 | |
98 #endif // MediaQueryParser_h | |
OLD | NEW |