Implement ::slotted pseudo element
https://bugs.webkit.org/show_bug.cgi?id=149441
<rdar://problem/22731987>
Reviewed by Andreas Kling.
Source/WebCore:
Based on latest in https://github.com/w3c/webcomponents/issues/331
* css/CSSGrammar.y.in:
Parse ::slotted.
* css/CSSParser.cpp:
(WebCore::CSSParser::detectFunctionTypeToken):
* css/CSSParserValues.cpp:
(WebCore::CSSParserSelector::parsePseudoElementCueFunctionSelector):
(WebCore::CSSParserSelector::parsePseudoElementSlottedFunctionSelector):
Tokenize ::slotted.
(WebCore::CSSParserSelector::parsePseudoClassAndCompatibilityElementSelector):
* css/CSSParserValues.h:
* css/CSSSelector.cpp:
(WebCore::CSSSelector::pseudoId):
* css/CSSSelector.h:
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::matchAuthorRules):
(WebCore::ElementRuleCollector::matchHostPseudoClassRules):
(WebCore::ElementRuleCollector::matchSlottedPseudoElementRules):
Match ::slotted selector.
(WebCore::ElementRuleCollector::collectSlottedPseudoElementRulesForSlot):
Collect ::slotted rules that may apply to an element in a slot.
(WebCore::ElementRuleCollector::matchUserRules):
(WebCore::ElementRuleCollector::matchUARules):
(WebCore::findSlottedPseudoElementSelector):
(WebCore::ElementRuleCollector::ruleMatches):
* css/ElementRuleCollector.h:
* css/RuleSet.cpp:
(WebCore::RuleSet::addRule):
Collect ::slotted rules.
(WebCore::RuleSet::shrinkToFit):
* css/RuleSet.h:
(WebCore::RuleSet::hostPseudoClassRules):
(WebCore::RuleSet::slottedPseudoElementRules):
(WebCore::RuleSet::focusPseudoClassRules):
(WebCore::RuleSet::universalRules):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* style/StyleSharingResolver.cpp:
(WebCore::Style::SharingResolver::resolve):
Disable style sharing for children of shadow host. They may be affected by the shadow tree style
which is not considered in style sharing checks.
LayoutTests:
* fast/shadow-dom/css-scoping-shadow-slotted-rule.html:
Enable the test, fix it and update it to the current spec.
* fast/shadow-dom/slotted-pseudo-element-css-text-expected.txt: Added.
* fast/shadow-dom/slotted-pseudo-element-css-text.html: Added.
Add parsing/cssText test based on a Blink test.
There are a few failures due to * not roundtripping and the parser being too lenient with pseudo elements.
* platform/mac/TestExpectations:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@197165 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/css/RuleSet.cpp b/Source/WebCore/css/RuleSet.cpp
index 0ebd5fc..9d5f38d 100644
--- a/Source/WebCore/css/RuleSet.cpp
+++ b/Source/WebCore/css/RuleSet.cpp
@@ -266,6 +266,12 @@
m_hostPseudoClassRules.append(ruleData);
return;
}
+ if (selector->match() == CSSSelector::PseudoElement && selector->pseudoElementType() == CSSSelector::PseudoElementSlotted) {
+ // ::slotted pseudo elements work accross shadow boundary making filtering difficult.
+ ruleData.disableSelectorFiltering();
+ m_slottedPseudoElementRules.append(ruleData);
+ return;
+ }
#endif
if (selector->relation() != CSSSelector::SubSelector)
break;
@@ -422,6 +428,10 @@
#if ENABLE(VIDEO_TRACK)
m_cuePseudoRules.shrinkToFit();
#endif
+#if ENABLE(SHADOW_DOM)
+ m_hostPseudoClassRules.shrinkToFit();
+ m_slottedPseudoElementRules.shrinkToFit();
+#endif
m_focusPseudoClassRules.shrinkToFit();
m_universalRules.shrinkToFit();
m_pageRules.shrinkToFit();