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 "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/CSSSelectorParser.h" | 6 #include "core/css/parser/CSSSelectorParser.h" |
7 | 7 |
8 #include "core/css/CSSSelectorList.h" | 8 #include "core/css/CSSSelectorList.h" |
9 #include "core/css/StyleSheetContents.h" | 9 #include "core/css/StyleSheetContents.h" |
10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 selector = consumeComplexSelector(); | 43 selector = consumeComplexSelector(); |
44 if (!selector) | 44 if (!selector) |
45 return; | 45 return; |
46 selectorList.append(selector.release()); | 46 selectorList.append(selector.release()); |
47 } | 47 } |
48 | 48 |
49 if (!m_failedParsing) | 49 if (!m_failedParsing) |
50 output.adoptSelectorVector(selectorList); | 50 output.adoptSelectorVector(selectorList); |
51 } | 51 } |
52 | 52 |
53 void CSSSelectorParser::consumeCompoundSelectorList(CSSSelectorList& output) | |
54 { | |
55 Vector<OwnPtr<CSSParserSelector> > selectorList; | |
56 OwnPtr<CSSParserSelector> selector = consumeCompoundSelector(); | |
57 if (!selector) | |
58 return; | |
59 selectorList.append(selector.release()); | |
60 while (!m_tokenRange.atEnd() && m_tokenRange.peek().type() == CommaToken) { | |
61 m_tokenRange.consumeIncludingWhitespaceAndComments(); | |
62 selector = consumeCompoundSelector(); | |
63 if (!selector) | |
64 return; | |
65 selectorList.append(selector.release()); | |
66 } | |
67 | |
68 if (!m_failedParsing) | |
69 output.adoptSelectorVector(selectorList); | |
70 } | |
71 | |
53 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeComplexSelector() | 72 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeComplexSelector() |
54 { | 73 { |
55 OwnPtr<CSSParserSelector> selector = consumeCompoundSelector(); | 74 OwnPtr<CSSParserSelector> selector = consumeCompoundSelector(); |
56 if (!selector) | 75 if (!selector) |
57 return nullptr; | 76 return nullptr; |
58 while (CSSSelector::Relation combinator = consumeCombinator()) { | 77 while (CSSSelector::Relation combinator = consumeCombinator()) { |
59 OwnPtr<CSSParserSelector> nextSelector = consumeCompoundSelector(); | 78 OwnPtr<CSSParserSelector> nextSelector = consumeCompoundSelector(); |
60 if (!nextSelector) | 79 if (!nextSelector) |
61 return combinator == CSSSelector::Descendant ? selector.release() : nullptr; | 80 return combinator == CSSSelector::Descendant ? selector.release() : nullptr; |
62 CSSParserSelector* end = nextSelector.get(); | 81 CSSParserSelector* end = nextSelector.get(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 selector->setAttribute(qualifiedName, consumeAttributeFlags()); | 252 selector->setAttribute(qualifiedName, consumeAttributeFlags()); |
234 | 253 |
235 if (!m_tokenRange.atEnd() && m_tokenRange.consumeIncludingComments().type() != RightBracketToken) | 254 if (!m_tokenRange.atEnd() && m_tokenRange.consumeIncludingComments().type() != RightBracketToken) |
236 return nullptr; | 255 return nullptr; |
237 | 256 |
238 return selector.release(); | 257 return selector.release(); |
239 } | 258 } |
240 | 259 |
241 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumePseudo() | 260 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumePseudo() |
242 { | 261 { |
243 // FIXME: Implement pseudo-element and pseudo-class parsing | 262 ASSERT(m_tokenRange.peek().type() == ColonToken); |
263 m_tokenRange.consumeIncludingComments(); | |
264 | |
265 int colons = 1; | |
266 if (m_tokenRange.peek().type() == ColonToken) { | |
267 m_tokenRange.consumeIncludingComments(); | |
268 colons++; | |
269 } | |
270 | |
271 const CSSParserToken& token = m_tokenRange.consumeIncludingComments(); | |
272 if (token.type() != IdentToken && token.type() != FunctionToken) | |
273 return nullptr; | |
274 m_tokenRange.consumeWhitespaceAndComments(); | |
275 | |
276 OwnPtr<CSSParserSelector> selector = CSSParserSelector::create(); | |
277 selector->setMatch(colons == 1 ? CSSSelector::PseudoClass : CSSSelector::Pse udoElement); | |
278 selector->setValue(AtomicString(token.value().lower())); | |
279 | |
280 if (token.type() == IdentToken) { | |
281 if (selector->pseudoType() == CSSSelector::PseudoUnknown) | |
282 return nullptr; | |
283 return selector.release(); | |
284 } | |
285 | |
286 if ((colons == 1 | |
287 && (equalIgnoringCase(token.value(), "host") | |
288 || equalIgnoringCase(token.value(), "host-context") | |
289 || equalIgnoringCase(token.value(), "-webkit-any"))) | |
290 || (colons == 2 && equalIgnoringCase(token.value(), "cue"))) { | |
291 | |
292 CSSSelectorList* selectorList = new CSSSelectorList(); | |
293 consumeCompoundSelectorList(*selectorList); | |
294 if (!selectorList->isValid() || (!m_tokenRange.atEnd() && m_tokenRange.c onsumeIncludingComments().type() != RightParenthesisToken)) | |
alancutter (OOO until 2018)
2014/12/29 02:53:01
consumeCompoundSelectorList does not consume trail
Timothy Loh
2015/01/05 05:24:51
Updated consumeCompoundSelectorList to consume tra
| |
295 return nullptr; | |
296 | |
297 selector->setSelectorList(adoptPtr(selectorList)); | |
298 selector->pseudoType(); // FIXME: Do we need to force the pseudo type to be cached? | |
299 ASSERT(selector->pseudoType() != CSSSelector::PseudoUnknown); | |
300 return selector.release(); | |
301 } | |
302 | |
303 if (colons == 1 && equalIgnoringCase(token.value(), "not")) { | |
304 OwnPtr<CSSParserSelector> innerSelector = consumeCompoundSelector(); | |
305 if (!innerSelector || !innerSelector->isSimple()) | |
306 return nullptr; | |
307 Vector<OwnPtr<CSSParserSelector> > selectorVector; | |
308 selectorVector.append(innerSelector.release()); | |
309 selector->adoptSelectorVector(selectorVector); | |
310 if (!m_tokenRange.atEnd() && m_tokenRange.consumeIncludingComments().typ e() != RightParenthesisToken) | |
alancutter (OOO until 2018)
2014/12/29 02:53:01
consumeCompoundSelector does not consume trailing
| |
311 return nullptr; | |
312 return selector.release(); | |
313 } | |
314 | |
315 // FIXME: Support :nth-*(<an+b>) | |
316 // FIXME: Support :lang(<ident>) | |
317 | |
244 return nullptr; | 318 return nullptr; |
245 } | 319 } |
246 | 320 |
247 CSSSelector::Relation CSSSelectorParser::consumeCombinator() | 321 CSSSelector::Relation CSSSelectorParser::consumeCombinator() |
248 { | 322 { |
249 CSSSelector::Relation fallbackResult = CSSSelector::SubSelector; | 323 CSSSelector::Relation fallbackResult = CSSSelector::SubSelector; |
250 while (m_tokenRange.peek().type() == WhitespaceToken || m_tokenRange.peek(). type() == CommentToken) { | 324 while (m_tokenRange.peek().type() == WhitespaceToken || m_tokenRange.peek(). type() == CommentToken) { |
251 if (m_tokenRange.consume().type() == WhitespaceToken) | 325 if (m_tokenRange.consume().type() == WhitespaceToken) |
252 fallbackResult = CSSSelector::Descendant; | 326 fallbackResult = CSSSelector::Descendant; |
253 } | 327 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 } | 484 } |
411 if (specifiers->isContentPseudoElement()) { | 485 if (specifiers->isContentPseudoElement()) { |
412 specifiers->insertTagHistory(CSSSelector::SubSelector, newSpecifier, CSS Selector::SubSelector); | 486 specifiers->insertTagHistory(CSSSelector::SubSelector, newSpecifier, CSS Selector::SubSelector); |
413 return specifiers; | 487 return specifiers; |
414 } | 488 } |
415 specifiers->appendTagHistory(CSSSelector::SubSelector, newSpecifier); | 489 specifiers->appendTagHistory(CSSSelector::SubSelector, newSpecifier); |
416 return specifiers; | 490 return specifiers; |
417 } | 491 } |
418 | 492 |
419 } // namespace blink | 493 } // namespace blink |
OLD | NEW |