Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1411)

Side by Side Diff: Source/core/css/parser/CSSParserImpl.cpp

Issue 799003003: CSS Parser: Implement parseRule (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@attoken
Patch Set: rebase/address comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/parser/CSSParserImpl.h ('k') | Source/core/css/parser/CSSParserTokenRange.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/CSSParserImpl.h" 6 #include "core/css/parser/CSSParserImpl.h"
7 7
8 #include "core/css/CSSStyleSheet.h" 8 #include "core/css/CSSStyleSheet.h"
9 #include "core/css/StylePropertySet.h" 9 #include "core/css/StylePropertySet.h"
10 #include "core/css/StyleSheetContents.h" 10 #include "core/css/StyleSheetContents.h"
11 #include "core/css/parser/CSSParserValues.h" 11 #include "core/css/parser/CSSParserValues.h"
12 #include "core/css/parser/CSSPropertyParser.h" 12 #include "core/css/parser/CSSPropertyParser.h"
13 #include "core/css/parser/CSSSelectorParser.h"
13 #include "core/css/parser/CSSTokenizer.h" 14 #include "core/css/parser/CSSTokenizer.h"
14 #include "core/dom/Document.h" 15 #include "core/dom/Document.h"
15 #include "core/dom/Element.h" 16 #include "core/dom/Element.h"
16 #include "core/frame/UseCounter.h" 17 #include "core/frame/UseCounter.h"
17 #include "wtf/BitArray.h" 18 #include "wtf/BitArray.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, const String& s) 22 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, const String& s)
22 : m_context(context) 23 : m_context(context)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 CSSRuleSourceData::Type ruleType = CSSRuleSourceData::STYLE_RULE; 82 CSSRuleSourceData::Type ruleType = CSSRuleSourceData::STYLE_RULE;
82 if (declaration->cssParserMode() == CSSViewportRuleMode) 83 if (declaration->cssParserMode() == CSSViewportRuleMode)
83 ruleType = CSSRuleSourceData::VIEWPORT_RULE; 84 ruleType = CSSRuleSourceData::VIEWPORT_RULE;
84 parser.consumeDeclarationList(CSSParserTokenRange(parser.m_tokens), ruleType ); 85 parser.consumeDeclarationList(CSSParserTokenRange(parser.m_tokens), ruleType );
85 if (parser.m_parsedProperties.isEmpty()) 86 if (parser.m_parsedProperties.isEmpty())
86 return false; 87 return false;
87 declaration->addParsedProperties(parser.m_parsedProperties); 88 declaration->addParsedProperties(parser.m_parsedProperties);
88 return true; 89 return true;
89 } 90 }
90 91
92 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::parseRule(const String& str ing, const CSSParserContext& context)
93 {
94 CSSParserImpl parser(context, string);
95 CSSParserTokenRange range(parser.m_tokens);
96 range.consumeWhitespaceAndComments();
97 if (range.atEnd())
98 return nullptr; // Parse error, empty rule
99 RefPtrWillBeRawPtr<StyleRuleBase> rule;
100 if (range.peek().type() == AtKeywordToken)
101 rule = parser.consumeAtRule(range);
102 else
103 rule = parser.consumeQualifiedRule(range);
104 if (!rule)
105 return nullptr; // Parse error, failed to consume rule
106 range.consumeWhitespaceAndComments();
107 if (!rule || !range.atEnd())
108 return nullptr; // Parse error, trailing garbage
109 return rule;
110 }
111
112 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::consumeAtRule(CSSParserToke nRange& range)
113 {
114 // FIXME: Implement at-rule parsing
115 return nullptr;
116 }
117
118 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::consumeQualifiedRule(CSSPar serTokenRange& range)
119 {
120 const CSSParserToken* preludeStart = &range.peek();
121 while (!range.atEnd() && range.peek().type() != LeftBraceToken)
122 range.consumeComponentValue();
123
124 if (range.atEnd())
125 return nullptr; // Parse error, EOF instead of qualified rule block
126
127 CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek() );
128 CSSParserTokenRange block = range.consumeBlock();
129 return consumeStyleRule(prelude, block);
130 }
131
132 PassRefPtrWillBeRawPtr<StyleRule> CSSParserImpl::consumeStyleRule(CSSParserToken Range prelude, CSSParserTokenRange block)
133 {
134 CSSSelectorList selectorList;
135 CSSSelectorParser::parseSelector(prelude, m_context, selectorList);
136 if (!selectorList.isValid())
137 return nullptr; // Parse error, invalid selector list
138 consumeDeclarationList(block, CSSRuleSourceData::STYLE_RULE);
139
140 RefPtrWillBeRawPtr<StyleRule> rule = StyleRule::create();
141 rule->wrapperAdoptSelectorList(selectorList);
142 rule->setProperties(createStylePropertySet(m_parsedProperties, m_context.mod e()));
143 m_parsedProperties.clear();
144 return rule.release();
145 }
146
91 void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, CSSRuleSou rceData::Type ruleType) 147 void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, CSSRuleSou rceData::Type ruleType)
92 { 148 {
93 while (!range.atEnd()) { 149 while (!range.atEnd()) {
94 switch (range.peek().type()) { 150 switch (range.peek().type()) {
95 case CommentToken: 151 case CommentToken:
96 case WhitespaceToken: 152 case WhitespaceToken:
97 case SemicolonToken: 153 case SemicolonToken:
98 range.consume(); 154 range.consume();
99 break; 155 break;
100 case IdentToken: { 156 case IdentToken: {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID propertyID, bool important, CSSRuleSourceData::Type ruleType) 195 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID propertyID, bool important, CSSRuleSourceData::Type ruleType)
140 { 196 {
141 CSSParserValueList valueList(range); 197 CSSParserValueList valueList(range);
142 if (!valueList.size()) 198 if (!valueList.size())
143 return; // Parser error 199 return; // Parser error
144 bool inViewport = ruleType == CSSRuleSourceData::VIEWPORT_RULE; 200 bool inViewport = ruleType == CSSRuleSourceData::VIEWPORT_RULE;
145 CSSPropertyParser::parseValue(propertyID, important, &valueList, m_context, inViewport, m_parsedProperties, ruleType); 201 CSSPropertyParser::parseValue(propertyID, important, &valueList, m_context, inViewport, m_parsedProperties, ruleType);
146 } 202 }
147 203
148 } // namespace blink 204 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSParserImpl.h ('k') | Source/core/css/parser/CSSParserTokenRange.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698