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 "core/css/parser/CSSSelectorParser.h" | 5 #include "core/css/parser/CSSSelectorParser.h" |
6 | 6 |
7 #include "core/css/CSSSelectorList.h" | 7 #include "core/css/CSSSelectorList.h" |
8 #include "core/css/StyleSheetContents.h" | 8 #include "core/css/StyleSheetContents.h" |
9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 else | 301 else |
302 compoundSelector = simpleSelector.release(); | 302 compoundSelector = simpleSelector.release(); |
303 } | 303 } |
304 | 304 |
305 if (!compoundSelector) { | 305 if (!compoundSelector) { |
306 AtomicString namespaceURI = determineNamespace(namespacePrefix); | 306 AtomicString namespaceURI = determineNamespace(namespacePrefix); |
307 if (namespaceURI.isNull()) { | 307 if (namespaceURI.isNull()) { |
308 m_failedParsing = true; | 308 m_failedParsing = true; |
309 return nullptr; | 309 return nullptr; |
310 } | 310 } |
| 311 if (namespaceURI == defaultNamespace()) |
| 312 namespacePrefix = nullAtom; |
311 return CSSParserSelector::create(QualifiedName(namespacePrefix, elementN
ame, namespaceURI)); | 313 return CSSParserSelector::create(QualifiedName(namespacePrefix, elementN
ame, namespaceURI)); |
312 } | 314 } |
313 prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.g
et()); | 315 prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.g
et()); |
314 return splitCompoundAtImplicitShadowCrossingCombinator(compoundSelector.rele
ase()); | 316 return splitCompoundAtImplicitShadowCrossingCombinator(compoundSelector.rele
ase()); |
315 } | 317 } |
316 | 318 |
317 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeSimpleSelector(CSSParser
TokenRange& range) | 319 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeSimpleSelector(CSSParser
TokenRange& range) |
318 { | 320 { |
319 const CSSParserToken& token = range.peek(); | 321 const CSSParserToken& token = range.peek(); |
320 OwnPtr<CSSParserSelector> selector; | 322 OwnPtr<CSSParserSelector> selector; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 { | 720 { |
719 if (elementName.isNull() && defaultNamespace() == starAtom && !compoundSelec
tor->needsImplicitShadowCombinatorForMatching()) | 721 if (elementName.isNull() && defaultNamespace() == starAtom && !compoundSelec
tor->needsImplicitShadowCombinatorForMatching()) |
720 return; | 722 return; |
721 | 723 |
722 AtomicString determinedElementName = elementName.isNull() ? starAtom : eleme
ntName; | 724 AtomicString determinedElementName = elementName.isNull() ? starAtom : eleme
ntName; |
723 AtomicString namespaceURI = determineNamespace(namespacePrefix); | 725 AtomicString namespaceURI = determineNamespace(namespacePrefix); |
724 if (namespaceURI.isNull()) { | 726 if (namespaceURI.isNull()) { |
725 m_failedParsing = true; | 727 m_failedParsing = true; |
726 return; | 728 return; |
727 } | 729 } |
728 QualifiedName tag = QualifiedName(namespacePrefix, determinedElementName, na
mespaceURI); | 730 AtomicString determinedPrefix = namespacePrefix; |
| 731 if (namespaceURI == defaultNamespace()) |
| 732 determinedPrefix = nullAtom; |
| 733 QualifiedName tag = QualifiedName(determinedPrefix, determinedElementName, n
amespaceURI); |
729 | 734 |
730 // *:host/*:host-context never matches, so we can't discard the *, | 735 // *:host/*:host-context never matches, so we can't discard the *, |
731 // otherwise we can't tell the difference between *:host and just :host. | 736 // otherwise we can't tell the difference between *:host and just :host. |
732 // | 737 // |
733 // Also, selectors where we use a ShadowPseudo combinator between the | 738 // Also, selectors where we use a ShadowPseudo combinator between the |
734 // element and the pseudo element for matching (custom pseudo elements, | 739 // element and the pseudo element for matching (custom pseudo elements, |
735 // ::cue, ::shadow), we need a universal selector to set the combinator | 740 // ::cue, ::shadow), we need a universal selector to set the combinator |
736 // (relation) on in the cases where there are no simple selectors preceding | 741 // (relation) on in the cases where there are no simple selectors preceding |
737 // the pseudo element. | 742 // the pseudo element. |
738 if (tag != anyQName() || compoundSelector->isHostPseudoSelector() || compoun
dSelector->needsImplicitShadowCombinatorForMatching()) | 743 bool explicitForHost = compoundSelector->isHostPseudoSelector() && !elementN
ame.isNull(); |
739 compoundSelector->prependTagSelector(tag, elementName.isNull()); | 744 if (tag != anyQName() || explicitForHost || compoundSelector->needsImplicitS
hadowCombinatorForMatching()) |
| 745 compoundSelector->prependTagSelector(tag, determinedPrefix == nullAtom &
& determinedElementName == starAtom && !explicitForHost); |
740 } | 746 } |
741 | 747 |
742 PassOwnPtr<CSSParserSelector> CSSSelectorParser::addSimpleSelectorToCompound(Pas
sOwnPtr<CSSParserSelector> compoundSelector, PassOwnPtr<CSSParserSelector> simpl
eSelector) | 748 PassOwnPtr<CSSParserSelector> CSSSelectorParser::addSimpleSelectorToCompound(Pas
sOwnPtr<CSSParserSelector> compoundSelector, PassOwnPtr<CSSParserSelector> simpl
eSelector) |
743 { | 749 { |
744 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; | 750 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; |
745 return compoundSelector; | 751 return compoundSelector; |
746 } | 752 } |
747 | 753 |
748 PassOwnPtr<CSSParserSelector> CSSSelectorParser::splitCompoundAtImplicitShadowCr
ossingCombinator(PassOwnPtr<CSSParserSelector> compoundSelector) | 754 PassOwnPtr<CSSParserSelector> CSSSelectorParser::splitCompoundAtImplicitShadowCr
ossingCombinator(PassOwnPtr<CSSParserSelector> compoundSelector) |
749 { | 755 { |
(...skipping 21 matching lines...) Expand all Loading... |
771 | 777 |
772 if (!splitAfter || !splitAfter->tagHistory()) | 778 if (!splitAfter || !splitAfter->tagHistory()) |
773 return compoundSelector; | 779 return compoundSelector; |
774 | 780 |
775 OwnPtr<CSSParserSelector> secondCompound = splitAfter->releaseTagHistory(); | 781 OwnPtr<CSSParserSelector> secondCompound = splitAfter->releaseTagHistory(); |
776 secondCompound->appendTagHistory(secondCompound->pseudoType() == CSSSelector
::PseudoSlotted ? CSSSelector::ShadowSlot : CSSSelector::ShadowPseudo, compoundS
elector); | 782 secondCompound->appendTagHistory(secondCompound->pseudoType() == CSSSelector
::PseudoSlotted ? CSSSelector::ShadowSlot : CSSSelector::ShadowPseudo, compoundS
elector); |
777 return secondCompound.release(); | 783 return secondCompound.release(); |
778 } | 784 } |
779 | 785 |
780 } // namespace blink | 786 } // namespace blink |
OLD | NEW |