| 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 "core/frame/UseCounter.h" | 10 #include "core/frame/UseCounter.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 break; | 43 break; |
| 44 } | 44 } |
| 45 if (feature != UseCounter::NumberOfFeatures) | 45 if (feature != UseCounter::NumberOfFeatures) |
| 46 context.useCounter()->count(feature); | 46 context.useCounter()->count(feature); |
| 47 if (current->selectorList()) | 47 if (current->selectorList()) |
| 48 recordSelectorStats(context, *current->selectorList()); | 48 recordSelectorStats(context, *current->selectorList()); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CSSSelectorParser::parseSelector(CSSParserTokenRange range, const CSSParser
Context& context, const AtomicString& defaultNamespace, StyleSheetContents* styl
eSheet, CSSSelectorList& output) | 53 void CSSSelectorParser::parseSelector(CSSParserTokenRange range, const CSSParser
Context& context, StyleSheetContents* styleSheet, CSSSelectorList& output) |
| 54 { | 54 { |
| 55 CSSSelectorParser parser(context, defaultNamespace, styleSheet); | 55 CSSSelectorParser parser(context, styleSheet); |
| 56 range.consumeWhitespace(); | 56 range.consumeWhitespace(); |
| 57 CSSSelectorList result; | 57 CSSSelectorList result; |
| 58 parser.consumeComplexSelectorList(range, result); | 58 parser.consumeComplexSelectorList(range, result); |
| 59 if (range.atEnd()) { | 59 if (range.atEnd()) { |
| 60 output.adopt(result); | 60 output.adopt(result); |
| 61 recordSelectorStats(context, output); | 61 recordSelectorStats(context, output); |
| 62 } | 62 } |
| 63 ASSERT(!(output.isValid() && parser.m_failedParsing)); | 63 ASSERT(!(output.isValid() && parser.m_failedParsing)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 CSSSelectorParser::CSSSelectorParser(const CSSParserContext& context, const Atom
icString& defaultNamespace, StyleSheetContents* styleSheet) | 66 CSSSelectorParser::CSSSelectorParser(const CSSParserContext& context, StyleSheet
Contents* styleSheet) |
| 67 : m_context(context) | 67 : m_context(context) |
| 68 , m_defaultNamespace(defaultNamespace) | |
| 69 , m_styleSheet(styleSheet) | 68 , m_styleSheet(styleSheet) |
| 70 , m_failedParsing(false) | 69 , m_failedParsing(false) |
| 71 { | 70 { |
| 72 } | 71 } |
| 73 | 72 |
| 74 void CSSSelectorParser::consumeComplexSelectorList(CSSParserTokenRange& range, C
SSSelectorList& output) | 73 void CSSSelectorParser::consumeComplexSelectorList(CSSParserTokenRange& range, C
SSSelectorList& output) |
| 75 { | 74 { |
| 76 Vector<OwnPtr<CSSParserSelector>> selectorList; | 75 Vector<OwnPtr<CSSParserSelector>> selectorList; |
| 77 OwnPtr<CSSParserSelector> selector = consumeComplexSelector(range); | 76 OwnPtr<CSSParserSelector> selector = consumeComplexSelector(range); |
| 78 if (!selector) | 77 if (!selector) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 while (OwnPtr<CSSParserSelector> simpleSelector = consumeSimpleSelector(rang
e)) { | 154 while (OwnPtr<CSSParserSelector> simpleSelector = consumeSimpleSelector(rang
e)) { |
| 156 if (compoundSelector) | 155 if (compoundSelector) |
| 157 compoundSelector = addSimpleSelectorToCompound(compoundSelector.rele
ase(), simpleSelector.release()); | 156 compoundSelector = addSimpleSelectorToCompound(compoundSelector.rele
ase(), simpleSelector.release()); |
| 158 else | 157 else |
| 159 compoundSelector = simpleSelector.release(); | 158 compoundSelector = simpleSelector.release(); |
| 160 } | 159 } |
| 161 | 160 |
| 162 if (!compoundSelector) { | 161 if (!compoundSelector) { |
| 163 if (hasNamespace) | 162 if (hasNamespace) |
| 164 return CSSParserSelector::create(determineNameInNamespace(namespaceP
refix, elementName)); | 163 return CSSParserSelector::create(determineNameInNamespace(namespaceP
refix, elementName)); |
| 165 return CSSParserSelector::create(QualifiedName(nullAtom, elementName, m_
defaultNamespace)); | 164 return CSSParserSelector::create(QualifiedName(nullAtom, elementName, de
faultNamespace())); |
| 166 } | 165 } |
| 167 prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.g
et()); | 166 prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.g
et()); |
| 168 return compoundSelector.release(); | 167 return compoundSelector.release(); |
| 169 } | 168 } |
| 170 | 169 |
| 171 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeSimpleSelector(CSSParser
TokenRange& range) | 170 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeSimpleSelector(CSSParser
TokenRange& range) |
| 172 { | 171 { |
| 173 const CSSParserToken& token = range.peek(); | 172 const CSSParserToken& token = range.peek(); |
| 174 OwnPtr<CSSParserSelector> selector; | 173 OwnPtr<CSSParserSelector> selector; |
| 175 if (token.type() == HashToken) | 174 if (token.type() == HashToken) |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 if (b.type() != NumberToken || b.numericValueType() != IntegerValueType) | 528 if (b.type() != NumberToken || b.numericValueType() != IntegerValueType) |
| 530 return false; | 529 return false; |
| 531 if ((b.numericSign() == NoSign) == (sign == NoSign)) | 530 if ((b.numericSign() == NoSign) == (sign == NoSign)) |
| 532 return false; | 531 return false; |
| 533 result.second = b.numericValue(); | 532 result.second = b.numericValue(); |
| 534 if (sign == MinusSign) | 533 if (sign == MinusSign) |
| 535 result.second = -result.second; | 534 result.second = -result.second; |
| 536 return true; | 535 return true; |
| 537 } | 536 } |
| 538 | 537 |
| 538 const AtomicString& CSSSelectorParser::defaultNamespace() const |
| 539 { |
| 540 if (!m_styleSheet) |
| 541 return starAtom; |
| 542 return m_styleSheet->defaultNamespace(); |
| 543 } |
| 544 |
| 539 QualifiedName CSSSelectorParser::determineNameInNamespace(const AtomicString& pr
efix, const AtomicString& localName) | 545 QualifiedName CSSSelectorParser::determineNameInNamespace(const AtomicString& pr
efix, const AtomicString& localName) |
| 540 { | 546 { |
| 541 if (!m_styleSheet) | 547 if (!m_styleSheet) |
| 542 return QualifiedName(prefix, localName, m_defaultNamespace); | 548 return QualifiedName(prefix, localName, defaultNamespace()); |
| 543 return QualifiedName(prefix, localName, m_styleSheet->determineNamespace(pre
fix)); | 549 return QualifiedName(prefix, localName, m_styleSheet->determineNamespace(pre
fix)); |
| 544 } | 550 } |
| 545 | 551 |
| 546 void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomicString& namespac
ePrefix, const AtomicString& elementName, CSSParserSelector* compoundSelector) | 552 void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomicString& namespac
ePrefix, const AtomicString& elementName, CSSParserSelector* compoundSelector) |
| 547 { | 553 { |
| 548 if (elementName.isNull() && m_defaultNamespace == starAtom && !compoundSelec
tor->crossesTreeScopes()) | 554 if (elementName.isNull() && defaultNamespace() == starAtom && !compoundSelec
tor->crossesTreeScopes()) |
| 549 return; | 555 return; |
| 550 | 556 |
| 551 AtomicString determinedElementName = elementName.isNull() ? starAtom : eleme
ntName; | 557 AtomicString determinedElementName = elementName.isNull() ? starAtom : eleme
ntName; |
| 552 AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleShe
et ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace; | 558 AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleShe
et ? m_styleSheet->determineNamespace(namespacePrefix) : defaultNamespace(); |
| 553 QualifiedName tag(namespacePrefix, determinedElementName, determinedNamespac
e); | 559 QualifiedName tag(namespacePrefix, determinedElementName, determinedNamespac
e); |
| 554 | 560 |
| 555 if (compoundSelector->crossesTreeScopes()) | 561 if (compoundSelector->crossesTreeScopes()) |
| 556 return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, compo
undSelector, elementName.isNull()); | 562 return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, compo
undSelector, elementName.isNull()); |
| 557 | 563 |
| 558 if (compoundSelector->pseudoType() == CSSSelector::PseudoContent) | 564 if (compoundSelector->pseudoType() == CSSSelector::PseudoContent) |
| 559 return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, comp
oundSelector, elementName.isNull()); | 565 return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, comp
oundSelector, elementName.isNull()); |
| 560 | 566 |
| 561 // *:host never matches, so we can't discard the * otherwise we can't tell t
he | 567 // *:host never matches, so we can't discard the * otherwise we can't tell t
he |
| 562 // difference between *:host and just :host. | 568 // difference between *:host and just :host. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); | 660 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); |
| 655 return compoundSelector; | 661 return compoundSelector; |
| 656 } | 662 } |
| 657 | 663 |
| 658 // All other simple selectors are added to the end of the compound. | 664 // All other simple selectors are added to the end of the compound. |
| 659 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; | 665 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; |
| 660 return compoundSelector; | 666 return compoundSelector; |
| 661 } | 667 } |
| 662 | 668 |
| 663 } // namespace blink | 669 } // namespace blink |
| OLD | NEW |