| 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 #ifndef MediaQueryParser_h | 5 #ifndef MediaQueryParser_h |
| 6 #define MediaQueryParser_h | 6 #define MediaQueryParser_h |
| 7 | 7 |
| 8 #include "core/css/CSSParserValues.h" | 8 #include "core/css/CSSParserValues.h" |
| 9 #include "core/css/MediaList.h" | 9 #include "core/css/MediaList.h" |
| 10 #include "core/css/MediaQuery.h" | 10 #include "core/css/MediaQuery.h" |
| 11 #include "core/css/MediaQueryExp.h" | 11 #include "core/css/MediaQueryExp.h" |
| 12 #include "core/css/parser/MediaQueryBlockWatcher.h" |
| 12 #include "core/css/parser/MediaQueryToken.h" | 13 #include "core/css/parser/MediaQueryToken.h" |
| 13 #include "wtf/Vector.h" | 14 #include "wtf/Vector.h" |
| 14 #include "wtf/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
| 15 | 16 |
| 16 namespace WebCore { | 17 namespace WebCore { |
| 17 | 18 |
| 18 class MediaQuerySet; | 19 class MediaQuerySet; |
| 19 | 20 |
| 20 class MediaQueryData { | 21 class MediaQueryData { |
| 21 STACK_ALLOCATED(); | 22 STACK_ALLOCATED(); |
| 22 private: | 23 private: |
| 23 MediaQuery::Restrictor m_restrictor; | 24 MediaQuery::Restrictor m_restrictor; |
| 24 String m_mediaType; | 25 String m_mediaType; |
| 25 OwnPtrWillBeMember<ExpressionHeapVector> m_expressions; | 26 OwnPtrWillBeMember<ExpressionHeapVector> m_expressions; |
| 26 String m_mediaFeature; | 27 String m_mediaFeature; |
| 27 CSSParserValueList m_valueList; | 28 CSSParserValueList m_valueList; |
| 28 bool m_mediaTypeSet; | 29 bool m_mediaTypeSet; |
| 29 | 30 |
| 30 public: | 31 public: |
| 31 MediaQueryData(); | 32 MediaQueryData(); |
| 32 void clear(); | 33 void clear(); |
| 33 bool addExpression(); | 34 bool addExpression(); |
| 34 void addParserValue(MediaQueryTokenType, MediaQueryToken&); | 35 void addParserValue(MediaQueryTokenType, const MediaQueryToken&); |
| 35 void setMediaType(const String&); | 36 void setMediaType(const String&); |
| 36 PassOwnPtrWillBeRawPtr<MediaQuery> takeMediaQuery(); | 37 PassOwnPtrWillBeRawPtr<MediaQuery> takeMediaQuery(); |
| 37 | 38 |
| 38 inline bool currentMediaQueryChanged() const | 39 inline bool currentMediaQueryChanged() const |
| 39 { | 40 { |
| 40 return (m_restrictor != MediaQuery::None || m_mediaTypeSet || m_expressi
ons->size() > 0); | 41 return (m_restrictor != MediaQuery::None || m_mediaTypeSet || m_expressi
ons->size() > 0); |
| 41 } | 42 } |
| 42 | 43 |
| 43 inline void setRestrictor(MediaQuery::Restrictor restrictor) { m_restrictor
= restrictor; } | 44 inline void setRestrictor(MediaQuery::Restrictor restrictor) { m_restrictor
= restrictor; } |
| 44 | 45 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 enum ParserType { | 58 enum ParserType { |
| 58 MediaQuerySetParser, | 59 MediaQuerySetParser, |
| 59 MediaConditionParser, | 60 MediaConditionParser, |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 MediaQueryParser(ParserType); | 63 MediaQueryParser(ParserType); |
| 63 virtual ~MediaQueryParser(); | 64 virtual ~MediaQueryParser(); |
| 64 | 65 |
| 65 PassRefPtrWillBeRawPtr<MediaQuerySet> parseImpl(TokenIterator, TokenIterator
endToken); | 66 PassRefPtrWillBeRawPtr<MediaQuerySet> parseImpl(TokenIterator, TokenIterator
endToken); |
| 66 | 67 |
| 67 enum BlockType { | 68 void processToken(const MediaQueryToken&); |
| 68 ParenthesisBlock, | |
| 69 BracketsBlock, | |
| 70 BracesBlock | |
| 71 }; | |
| 72 | 69 |
| 73 enum StateChange { | 70 void readRestrictor(MediaQueryTokenType, const MediaQueryToken&); |
| 74 ModifyState, | 71 void readMediaType(MediaQueryTokenType, const MediaQueryToken&); |
| 75 DoNotModifyState | 72 void readAnd(MediaQueryTokenType, const MediaQueryToken&); |
| 76 }; | 73 void readFeatureStart(MediaQueryTokenType, const MediaQueryToken&); |
| 74 void readFeature(MediaQueryTokenType, const MediaQueryToken&); |
| 75 void readFeatureColon(MediaQueryTokenType, const MediaQueryToken&); |
| 76 void readFeatureValue(MediaQueryTokenType, const MediaQueryToken&); |
| 77 void readFeatureEnd(MediaQueryTokenType, const MediaQueryToken&); |
| 78 void skipUntilComma(MediaQueryTokenType, const MediaQueryToken&); |
| 79 void skipUntilBlockEnd(MediaQueryTokenType, const MediaQueryToken&); |
| 80 void done(MediaQueryTokenType, const MediaQueryToken&); |
| 77 | 81 |
| 78 struct BlockParameters { | 82 typedef void (MediaQueryParser::*State)(MediaQueryTokenType, const MediaQuer
yToken&); |
| 79 MediaQueryTokenType leftToken; | |
| 80 MediaQueryTokenType rightToken; | |
| 81 BlockType blockType; | |
| 82 StateChange stateChange; | |
| 83 }; | |
| 84 | |
| 85 void processToken(TokenIterator&); | |
| 86 | |
| 87 void readRestrictor(MediaQueryTokenType, TokenIterator&); | |
| 88 void readMediaType(MediaQueryTokenType, TokenIterator&); | |
| 89 void readAnd(MediaQueryTokenType, TokenIterator&); | |
| 90 void readFeatureStart(MediaQueryTokenType, TokenIterator&); | |
| 91 void readFeature(MediaQueryTokenType, TokenIterator&); | |
| 92 void readFeatureColon(MediaQueryTokenType, TokenIterator&); | |
| 93 void readFeatureValue(MediaQueryTokenType, TokenIterator&); | |
| 94 void readFeatureEnd(MediaQueryTokenType, TokenIterator&); | |
| 95 void skipUntilComma(MediaQueryTokenType, TokenIterator&); | |
| 96 void skipUntilBlockEnd(MediaQueryTokenType, TokenIterator&); | |
| 97 void done(MediaQueryTokenType, TokenIterator&); | |
| 98 | |
| 99 typedef void (MediaQueryParser::*State)(MediaQueryTokenType, TokenIterator&)
; | |
| 100 | 83 |
| 101 void setStateAndRestrict(State, MediaQuery::Restrictor); | 84 void setStateAndRestrict(State, MediaQuery::Restrictor); |
| 102 bool observeBlock(BlockParameters&, MediaQueryTokenType); | 85 void handleBlocks(const MediaQueryToken&); |
| 103 void observeBlocks(MediaQueryTokenType); | |
| 104 static void popIfBlockMatches(Vector<MediaQueryParser::BlockType>& blockStac
k, BlockType); | |
| 105 | 86 |
| 106 State m_state; | 87 State m_state; |
| 107 MediaQueryData m_mediaQueryData; | 88 MediaQueryData m_mediaQueryData; |
| 108 RefPtrWillBeMember<MediaQuerySet> m_querySet; | 89 RefPtrWillBeMember<MediaQuerySet> m_querySet; |
| 109 Vector<BlockType> m_blockStack; | 90 MediaQueryBlockWatcher m_blockWatcher; |
| 110 | 91 |
| 111 const static State ReadRestrictor; | 92 const static State ReadRestrictor; |
| 112 const static State ReadMediaType; | 93 const static State ReadMediaType; |
| 113 const static State ReadAnd; | 94 const static State ReadAnd; |
| 114 const static State ReadFeatureStart; | 95 const static State ReadFeatureStart; |
| 115 const static State ReadFeature; | 96 const static State ReadFeature; |
| 116 const static State ReadFeatureColon; | 97 const static State ReadFeatureColon; |
| 117 const static State ReadFeatureValue; | 98 const static State ReadFeatureValue; |
| 118 const static State ReadFeatureEnd; | 99 const static State ReadFeatureEnd; |
| 119 const static State SkipUntilComma; | 100 const static State SkipUntilComma; |
| 120 const static State SkipUntilBlockEnd; | 101 const static State SkipUntilBlockEnd; |
| 121 const static State Done; | 102 const static State Done; |
| 122 | 103 |
| 123 }; | 104 }; |
| 124 | 105 |
| 125 } // namespace WebCore | 106 } // namespace WebCore |
| 126 | 107 |
| 127 #endif // MediaQueryParser_h | 108 #endif // MediaQueryParser_h |
| OLD | NEW |