Diff
Modified: trunk/LayoutTests/ChangeLog (199290 => 199291)
--- trunk/LayoutTests/ChangeLog 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/LayoutTests/ChangeLog 2016-04-11 09:13:06 UTC (rev 199291)
@@ -1,3 +1,16 @@
+2016-04-11 Antti Koivisto <[email protected]>
+
+ Implement functional :host() pseudo class
+ https://bugs.webkit.org/show_bug.cgi?id=156397
+ <rdar://problem/25621445>
+
+ Reviewed by Darin Adler.
+
+ Enable, fix and expand the test.
+
+ * fast/shadow-dom/css-scoping-shadow-host-functional-rule.html:
+ * platform/mac/TestExpectations:
+
2016-04-11 Said Abou-Hallawa <sabouhallawa@apple,com>
Merge CG ImageSource and non CG ImageSource implementation in one file
Modified: trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-functional-rule.html (199290 => 199291)
--- trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-functional-rule.html 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-functional-rule.html 2016-04-11 09:13:06 UTC (rev 199291)
@@ -8,41 +8,56 @@
</head>
<body>
<style>
- my-host, good-host, other-host, other-good-host {
+ host1, host2, host3, host4, host5 {
display: block;
width: 100px;
- height: 50px;
+ height: 20px;
background: red;
}
- good-host, other-good-host {
+ host3, host4, host5 {
background: green;
}
</style>
- <p>Test passes if you see a single 100px by 100px green box below.</p>
- <my-host>
+ <p>Test passes if you see a single 100px by 100px green box below.</p>
+ <host1>
<div>FAIL</div>
- </my-host>
- <div class="container">
- <good-host>
- <div>FAIL</div>
- </good-host>
+ </host1>
+ <host2 id="bar" class="foo" name="baz">
+ <div>FAIL</div>
+ </host2>
+ <div>
+ <host3>
+ FAIL
+ </host3>
</div>
- <other-host id="bar" class="foo" name="baz">
+ <host4>
+ <div class="child">FAIL</div>
+ </host4>
+ <host5>
<div>FAIL</div>
- </other-host>
- <other-good-host>
- <div class="child">FAIL</div>
- </other-good-host>
+ </host5>
<script>
try {
- var shadowHost = document.querySelector('other-host');
+ var shadowHost = document.querySelector('host1');
shadowRoot = shadowHost.attachShadow({mode: 'open'});
- shadowRoot.innerHTML = '<style> :host(other-host.foo#bar[name=baz]) { background: green; } </style>';
+ shadowRoot.innerHTML = '<style> :host(host1) { background: green !important; } </style>';
- shadowHost = document.querySelector('other-good-host');
+ shadowHost = document.querySelector('host2');
shadowRoot = shadowHost.attachShadow({mode: 'open'});
- shadowRoot.innerHTML = '<style> :host(.child) { background: red; } </style>';
+ shadowRoot.innerHTML = '<style> :host(host2.foo#bar[name=baz]) { background: green !important; } </style>';
+
+ shadowHost = document.querySelector('host3');
+ shadowRoot = shadowHost.attachShadow({mode: 'open'});
+ shadowRoot.innerHTML = '<style> :host(div host3) { background: red !important; } </style>';
+
+ shadowHost = document.querySelector('host4');
+ shadowRoot = shadowHost.attachShadow({mode: 'open'});
+ shadowRoot.innerHTML = '<style> :host(.child) { background: red !important; } </style>';
+
+ shadowHost = document.querySelector('host5');
+ shadowRoot = shadowHost.attachShadow({mode: 'open'});
+ shadowRoot.innerHTML = '<style> :host(host1) { background: red !important; } </style>';
} catch (exception) {
document.body.appendChild(document.createTextNode(exception));
}
Modified: trunk/LayoutTests/platform/mac/TestExpectations (199290 => 199291)
--- trunk/LayoutTests/platform/mac/TestExpectations 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/LayoutTests/platform/mac/TestExpectations 2016-04-11 09:13:06 UTC (rev 199291)
@@ -1224,7 +1224,6 @@
webkit.org/b/149128 fast/text/control-characters [ ImageOnlyFailure ]
webkit.org/b/148695 fast/shadow-dom [ Pass ]
-webkit.org/b/149440 fast/shadow-dom/css-scoping-shadow-host-functional-rule.html [ ImageOnlyFailure ]
# Touch events is not enabled on Mac
webkit.org/b/149592 fast/shadow-dom/touch-event-ios.html [ Failure ]
Modified: trunk/Source/WebCore/ChangeLog (199290 => 199291)
--- trunk/Source/WebCore/ChangeLog 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/ChangeLog 2016-04-11 09:13:06 UTC (rev 199291)
@@ -1,3 +1,50 @@
+2016-04-11 Antti Koivisto <[email protected]>
+
+ Implement functional :host() pseudo class
+ https://bugs.webkit.org/show_bug.cgi?id=156397
+ <rdar://problem/25621445>
+
+ Reviewed by Darin Adler.
+
+ We already support :host. Add functional syntax too.
+
+ * css/CSSGrammar.y.in:
+
+ Parse functional :host().
+
+ * css/CSSParser.cpp:
+ (WebCore::CSSParser::detectFunctionTypeToken):
+ * css/CSSParserValues.cpp:
+ (WebCore::CSSParserSelector::parsePseudoClassHostFunctionSelector):
+ * css/CSSParserValues.h:
+ * css/ElementRuleCollector.cpp:
+ (WebCore::ElementRuleCollector::matchedRuleList):
+ (WebCore::ElementRuleCollector::addMatchedRule):
+
+ Factor some shared code here.
+
+ (WebCore::ElementRuleCollector::matchHostPseudoClassRules):
+
+ Instead of using the generic paths use a :host specific code path for matching.
+ This makes it easier to avoid :host matching when it shouldn't.
+
+ (WebCore::ElementRuleCollector::collectMatchingRulesForList):
+ * css/ElementRuleCollector.h:
+ * css/RuleSet.cpp:
+ (WebCore::computeMatchBasedOnRuleHash):
+
+ :host is always handled by the special matching path.
+
+ * css/SelectorChecker.cpp:
+ (WebCore::SelectorChecker::match):
+ (WebCore::SelectorChecker::matchHostPseudoClass):
+
+ Add a function specifically for checking :host. In always fails on the normal code paths.
+ Check the argument selector if provided.
+
+ (WebCore::hasScrollbarPseudoElement):
+ * css/SelectorChecker.h:
+
2016-04-11 Said Abou-Hallawa <sabouhallawa@apple,com>
Merge CG ImageSource and non CG ImageSource implementation in one file
Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (199290 => 199291)
--- trunk/Source/WebCore/css/CSSGrammar.y.in 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in 2016-04-11 09:13:06 UTC (rev 199291)
@@ -368,6 +368,7 @@
#if ENABLE_SHADOW_DOM
%token <string> SLOTTEDFUNCTION
+%token <string> HOSTFUNCTION
#endif
@@ -1367,6 +1368,9 @@
| ':' ':' SLOTTEDFUNCTION maybe_space compound_selector maybe_space ')' {
$$ = CSSParserSelector::parsePseudoElementSlottedFunctionSelector($3, $5);
}
+ | ':' HOSTFUNCTION maybe_space compound_selector maybe_space ')' {
+ $$ = CSSParserSelector::parsePseudoClassHostFunctionSelector($2, $4);
+ }
#endif
// use by :-webkit-any.
// FIXME: should we support generic selectors here or just simple_selectors?
Modified: trunk/Source/WebCore/css/CSSParser.cpp (199290 => 199291)
--- trunk/Source/WebCore/css/CSSParser.cpp 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2016-04-11 09:13:06 UTC (rev 199291)
@@ -11897,6 +11897,12 @@
return true;
}
#endif
+#if ENABLE(SHADOW_DOM)
+ if (isEqualToCSSIdentifier(name, "host")) {
+ m_token = HOSTFUNCTION;
+ return true;
+ }
+#endif
return false;
case 7:
Modified: trunk/Source/WebCore/css/CSSParserValues.cpp (199290 => 199291)
--- trunk/Source/WebCore/css/CSSParserValues.cpp 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/CSSParserValues.cpp 2016-04-11 09:13:06 UTC (rev 199291)
@@ -255,6 +255,30 @@
selector->adoptSelectorVector(*selectorVector);
return selector.release();
}
+
+CSSParserSelector* CSSParserSelector::parsePseudoClassHostFunctionSelector(const CSSParserString& functionIdentifier, CSSParserSelector* parsedSelector)
+{
+ ASSERT_UNUSED(functionIdentifier, String(functionIdentifier) == "host(");
+
+ if (!parsedSelector)
+ return nullptr;
+
+ std::unique_ptr<CSSParserSelector> ownedParsedSelector(parsedSelector);
+
+ for (auto* component = parsedSelector; component; component = component->tagHistory()) {
+ if (component->matchesPseudoElement())
+ return nullptr;
+ }
+
+ auto selectorVector = std::make_unique<Vector<std::unique_ptr<CSSParserSelector>>>();
+ selectorVector->append(WTFMove(ownedParsedSelector));
+
+ auto selector = std::make_unique<CSSParserSelector>();
+ selector->m_selector->setMatch(CSSSelector::PseudoClass);
+ selector->m_selector->setPseudoClassType(CSSSelector::PseudoClassHost);
+ selector->adoptSelectorVector(*selectorVector);
+ return selector.release();
+}
#endif
CSSParserSelector* CSSParserSelector::parsePseudoClassAndCompatibilityElementSelector(CSSParserString& pseudoTypeString)
Modified: trunk/Source/WebCore/css/CSSParserValues.h (199290 => 199291)
--- trunk/Source/WebCore/css/CSSParserValues.h 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/CSSParserValues.h 2016-04-11 09:13:06 UTC (rev 199291)
@@ -206,6 +206,7 @@
static CSSParserSelector* parsePseudoElementCueFunctionSelector(const CSSParserString& functionIdentifier, Vector<std::unique_ptr<CSSParserSelector>>*);
#if ENABLE(SHADOW_DOM)
static CSSParserSelector* parsePseudoElementSlottedFunctionSelector(const CSSParserString& functionIdentifier, CSSParserSelector*);
+ static CSSParserSelector* parsePseudoClassHostFunctionSelector(const CSSParserString& functionIdentifier, CSSParserSelector*);
#endif
static CSSParserSelector* parsePseudoClassAndCompatibilityElementSelector(CSSParserString& pseudoTypeString);
Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (199290 => 199291)
--- trunk/Source/WebCore/css/ElementRuleCollector.cpp 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp 2016-04-11 09:13:06 UTC (rev 199291)
@@ -107,9 +107,14 @@
return m_matchedRuleList;
}
-inline void ElementRuleCollector::addMatchedRule(const MatchedRule& matchedRule)
+inline void ElementRuleCollector::addMatchedRule(const RuleData& ruleData, unsigned specificity, StyleResolver::RuleRange& ruleRange)
{
- m_matchedRules.append(matchedRule);
+ // Update our first/last rule indices in the matched rules array.
+ ++ruleRange.lastRuleIndex;
+ if (ruleRange.firstRuleIndex == -1)
+ ruleRange.firstRuleIndex = ruleRange.lastRuleIndex;
+
+ m_matchedRules.append({ &ruleData, specificity });
}
void ElementRuleCollector::clearMatchedRules()
@@ -232,9 +237,19 @@
clearMatchedRules();
m_result.ranges.lastAuthorRule = m_result.matchedProperties().size() - 1;
+ SelectorChecker::CheckingContext context(m_mode);
+ SelectorChecker selectorChecker(m_element.document());
+
auto ruleRange = m_result.ranges.authorRuleRange();
- MatchRequest matchRequest(&shadowAuthorStyle, includeEmptyRules);
- collectMatchingRulesForList(&shadowHostRules, matchRequest, ruleRange);
+ for (auto& ruleData : shadowHostRules) {
+ if (ruleData.rule()->properties().isEmpty() && !includeEmptyRules)
+ continue;
+ auto& selector = *ruleData.selector();
+ unsigned specificity = 0;
+ if (!selectorChecker.matchHostPseudoClass(selector, m_element, context, specificity))
+ continue;
+ addMatchedRule(ruleData, specificity, ruleRange);
+ }
// We just sort the host rules before other author rules. This matches the current vague spec language
// but is not necessarily exactly what is needed.
@@ -486,15 +501,8 @@
continue;
unsigned specificity;
- if (ruleMatches(ruleData, specificity)) {
- // Update our first/last rule indices in the matched rules array.
- ++ruleRange.lastRuleIndex;
- if (ruleRange.firstRuleIndex == -1)
- ruleRange.firstRuleIndex = ruleRange.lastRuleIndex;
-
- // Add this rule to our list of matched rules.
- addMatchedRule({&ruleData, specificity});
- }
+ if (ruleMatches(ruleData, specificity))
+ addMatchedRule(ruleData, specificity, ruleRange);
}
}
Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (199290 => 199291)
--- trunk/Source/WebCore/css/ElementRuleCollector.h 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h 2016-04-11 09:13:06 UTC (rev 199291)
@@ -89,7 +89,7 @@
void sortMatchedRules();
void sortAndTransferMatchedRules();
- void addMatchedRule(const MatchedRule&);
+ void addMatchedRule(const RuleData&, unsigned specificity, StyleResolver::RuleRange&);
const Element& m_element;
const RuleSet& m_authorStyle;
Modified: trunk/Source/WebCore/css/RuleSet.cpp (199290 => 199291)
--- trunk/Source/WebCore/css/RuleSet.cpp 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/RuleSet.cpp 2016-04-11 09:13:06 UTC (rev 199291)
@@ -70,10 +70,6 @@
}
if (SelectorChecker::isCommonPseudoClassSelector(&selector))
return MatchBasedOnRuleHash::ClassB;
-#if ENABLE(SHADOW_DOM)
- if (selector.match() == CSSSelector::PseudoClass && selector.pseudoClassType() == CSSSelector::PseudoClassHost)
- return MatchBasedOnRuleHash::ClassB;
-#endif
if (selector.match() == CSSSelector::Id)
return MatchBasedOnRuleHash::ClassA;
if (selector.match() == CSSSelector::Class)
Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (199290 => 199291)
--- trunk/Source/WebCore/css/SelectorChecker.cpp 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp 2016-04-11 09:13:06 UTC (rev 199291)
@@ -199,6 +199,33 @@
return true;
}
+#if ENABLE(SHADOW_DOM)
+bool SelectorChecker::matchHostPseudoClass(const CSSSelector& selector, const Element& element, CheckingContext& checkingContext, unsigned& specificity) const
+{
+ ASSERT(element.shadowRoot());
+ ASSERT(selector.match() == CSSSelector::PseudoClass && selector.pseudoClassType() == CSSSelector::PseudoClassHost);
+ ASSERT(checkingContext.resolvingMode != SelectorChecker::Mode::QueryingRules);
+
+ specificity = selector.simpleSelectorSpecificity();
+
+ // :host doesn't combine with any other selectors.
+ if (selector.tagHistory())
+ return false;
+
+ if (auto* selectorList = selector.selectorList()) {
+ LocalContext context(*selectorList->first(), element, VisitedMatchType::Enabled, NOPSEUDO);
+ context.inFunctionalPseudoClass = true;
+ context.pseudoElementEffective = false;
+ PseudoIdSet ignoreDynamicPseudo;
+ unsigned subselectorSpecificity = 0;
+ if (matchRecursively(checkingContext, context, ignoreDynamicPseudo, subselectorSpecificity).match != Match::SelectorMatches)
+ return false;
+ specificity = CSSSelector::addSpecificities(specificity, subselectorSpecificity);
+ }
+ return true;
+}
+#endif
+
inline static bool hasScrollbarPseudoElement(const PseudoIdSet& dynamicPseudoIdSet)
{
PseudoIdSet scrollbarIdSet = { SCROLLBAR, SCROLLBAR_THUMB, SCROLLBAR_BUTTON, SCROLLBAR_TRACK, SCROLLBAR_TRACK_PIECE, SCROLLBAR_CORNER };
Modified: trunk/Source/WebCore/css/SelectorChecker.h (199290 => 199291)
--- trunk/Source/WebCore/css/SelectorChecker.h 2016-04-11 07:29:33 UTC (rev 199290)
+++ trunk/Source/WebCore/css/SelectorChecker.h 2016-04-11 09:13:06 UTC (rev 199291)
@@ -95,6 +95,10 @@
bool match(const CSSSelector&, const Element&, CheckingContext&, unsigned& specificity) const;
+#if ENABLE(SHADOW_DOM)
+ bool matchHostPseudoClass(const CSSSelector&, const Element&, CheckingContext&, unsigned& specificity) const;
+#endif
+
static bool isCommonPseudoClassSelector(const CSSSelector*);
static bool matchesFocusPseudoClass(const Element&);
static bool attributeSelectorMatches(const Element&, const QualifiedName&, const AtomicString& attributeValue, const CSSSelector&);