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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp

Issue 1523843004: Add support for new CSS ::slotted() pseudo element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WIP Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
index 564b31d911422b116489cadc7ae64a29019c36c6..29d0b14ac16c16ded20b20671f15a0a94582320d 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp
@@ -24,6 +24,9 @@ static void recordSelectorStats(const CSSParserContext& context, const CSSSelect
case CSSSelector::PseudoUnresolved:
feature = UseCounter::CSSSelectorPseudoUnresolved;
break;
+ case CSSSelector::PseudoSlotted:
+ feature = UseCounter::CSSSelectorPseudoSlotted;
+ break;
case CSSSelector::PseudoContent:
feature = UseCounter::CSSSelectorPseudoContent;
break;
@@ -360,6 +363,7 @@ PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumePseudo(CSSParserTokenRan
selector->setSelectorList(selectorList.release());
return selector.release();
}
+ case CSSSelector::PseudoSlotted:
case CSSSelector::PseudoNot:
{
OwnPtr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
@@ -369,6 +373,8 @@ PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumePseudo(CSSParserTokenRan
Vector<OwnPtr<CSSParserSelector>> selectorVector;
selectorVector.append(innerSelector.release());
selector->adoptSelectorVector(selectorVector);
+ if (selector->pseudoType() == CSSSelector::PseudoSlotted)
+ selector->setRelationIsAffectedByPseudoSlotted();
return selector.release();
}
case CSSSelector::PseudoLang:
@@ -576,8 +582,8 @@ void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomicString& namespac
if (compoundSelector->crossesTreeScopes())
return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, compoundSelector, elementName.isNull());
- if (compoundSelector->pseudoType() == CSSSelector::PseudoContent)
- return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, compoundSelector, elementName.isNull());
+ if (compoundSelector->pseudoType() == CSSSelector::PseudoContent || compoundSelector->pseudoType() == CSSSelector::PseudoSlotted)
+ return rewriteSpecifiersWithElementNameForContentOrSlottedPseudoElement(tag, compoundSelector, elementName.isNull());
// *:host never matches, so we can't discard the * otherwise we can't tell the
// difference between *:host and just :host.
@@ -609,13 +615,14 @@ void CSSSelectorParser::rewriteSpecifiersWithElementNameForCustomPseudoElement(c
lastShadowPseudo->setRelation(CSSSelector::ShadowPseudo);
}
-void CSSSelectorParser::rewriteSpecifiersWithElementNameForContentPseudoElement(const QualifiedName& tag, CSSParserSelector* specifiers, bool tagIsImplicit)
+void CSSSelectorParser::rewriteSpecifiersWithElementNameForContentOrSlottedPseudoElement(const QualifiedName& tag, CSSParserSelector* specifiers, bool tagIsImplicit)
{
CSSParserSelector* last = specifiers;
CSSParserSelector* history = specifiers;
while (history->tagHistory()) {
history = history->tagHistory();
- if (history->pseudoType() == CSSSelector::PseudoContent || history->relationIsAffectedByPseudoContent())
+ if (history->pseudoType() == CSSSelector::PseudoContent || history->relationIsAffectedByPseudoContent()
+ || history->pseudoType() == CSSSelector::PseudoSlotted || history->relationIsAffectedByPseudoSlotted())
last = history;
}
@@ -625,10 +632,10 @@ void CSSSelectorParser::rewriteSpecifiersWithElementNameForContentPseudoElement(
return;
}
- // For shadow-ID pseudo-elements to be correctly matched, the ShadowPseudo combinator has to be used.
- // We therefore create a new Selector with that combinator here in any case, even if matching any (host) element in any namespace (i.e. '*').
OwnPtr<CSSParserSelector> elementNameSelector = CSSParserSelector::create(tag);
last->setTagHistory(elementNameSelector.release());
+ if (last->pseudoType() == CSSSelector::PseudoSlotted)
+ last->setRelation(CSSSelector::ShadowSlot);
}
PassOwnPtr<CSSParserSelector> CSSSelectorParser::addSimpleSelectorToCompound(PassOwnPtr<CSSParserSelector> compoundSelector, PassOwnPtr<CSSParserSelector> simpleSelector)

Powered by Google App Engine
This is Rietveld 408576698