Title: [204724] trunk
- Revision
- 204724
- Author
- [email protected]
- Date
- 2016-08-22 10:19:29 -0700 (Mon, 22 Aug 2016)
Log Message
Can't style descendants in shadow tree using the :host pseudo class
https://bugs.webkit.org/show_bug.cgi?id=160754
Reviewed by Darin Adler.
Source/WebCore:
"The :host pseudo-class, when evaluated in the context of a shadow tree, matches the shadow tree’s shadow host."
Currently :host() works for styling the host element itself (:host(.foo) { ... }). It should also be usable
for styling elements in the shadow tree:
:host(.foo) div { ... }
Test: fast/shadow-dom/css-scoping-host-descendant.html
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::matchHostPseudoClass):
(WebCore::localContextForParent):
Move to shadow host if we are matching :host and are at the root of the shadow tree.
Set didMoveToShadowHost bit in the context.
(WebCore::SelectorChecker::matchRecursively):
(WebCore::SelectorChecker::checkOne):
Call the existing matchHostPseudoClass to do :host matching if didMoveToShadowHost bit has been set.
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):
Disallow :host in the compiler (cases where it would match didn't reach the compiler before).
LayoutTests:
* fast/shadow-dom/css-scoping-host-descendant-expected.html: Added.
* fast/shadow-dom/css-scoping-host-descendant.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (204723 => 204724)
--- trunk/LayoutTests/ChangeLog 2016-08-22 16:40:49 UTC (rev 204723)
+++ trunk/LayoutTests/ChangeLog 2016-08-22 17:19:29 UTC (rev 204724)
@@ -1,3 +1,13 @@
+2016-08-22 Antti Koivisto <[email protected]>
+
+ Can't style descendants in shadow tree using the :host pseudo class
+ https://bugs.webkit.org/show_bug.cgi?id=160754
+
+ Reviewed by Darin Adler.
+
+ * fast/shadow-dom/css-scoping-host-descendant-expected.html: Added.
+ * fast/shadow-dom/css-scoping-host-descendant.html: Added.
+
2016-08-22 Daniel Bates <[email protected]>
[iOS] <a ping> and <area ping> tests time out
Added: trunk/LayoutTests/fast/shadow-dom/css-scoping-host-descendant-expected.html (0 => 204724)
--- trunk/LayoutTests/fast/shadow-dom/css-scoping-host-descendant-expected.html (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/css-scoping-host-descendant-expected.html 2016-08-22 17:19:29 UTC (rev 204724)
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <p>Test passes if you see a single 100px by 100px green box below.</p>
+ <div style="width: 100px; height: 100px; background: green;"></div>
+ </body>
+</html>
Added: trunk/LayoutTests/fast/shadow-dom/css-scoping-host-descendant.html (0 => 204724)
--- trunk/LayoutTests/fast/shadow-dom/css-scoping-host-descendant.html (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/css-scoping-host-descendant.html 2016-08-22 17:19:29 UTC (rev 204724)
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+my-host {
+ display: block;
+ width: 100px;
+ height: 25px;
+ background: red;
+}
+</style>
+</head>
+<body>
+<p>Test passes if you see a single 100px by 100px green box below.</p>
+<my-host id="t1"></my-host>
+<my-host id="t2" class="match"></my-host>
+<my-host id="t3" class="no-match"></my-host>
+<my-host id="t4" class="match"><div></div></my-host>
+
+<script>
+var host = document.querySelector('#t1');
+host.attachShadow({ mode: 'open' }).innerHTML = `
+ <style>
+ :host > div {
+ background-color: green; width: 100%; height: 100%;
+ }
+ </style>
+ <div></div>
+`;
+
+var host = document.querySelector('#t2');
+host.attachShadow({ mode: 'open' }).innerHTML = `
+ <style>
+ div { background-color: red; width: 100%; height: 100%; }
+ :host(.match) .descendant {
+ background-color: green;
+ }
+ </style>
+ <div><div class="descendant"></div></div>
+`;
+
+var host = document.querySelector('#t3');
+host.attachShadow({ mode: 'open' }).innerHTML = `
+ <style>
+ div { background-color: green; width: 100%; height: 100%; }
+ :host(.match) div {
+ background-color: red;
+ }
+ </style>
+ <div></div>
+`;
+
+var host = document.querySelector('#t4');
+host.attachShadow({ mode: 'open' }).innerHTML = `
+ <style>
+ :host(.match) ::slotted(div) {
+ background-color: green; width: 100%; height: 100%;
+ }
+ </style>
+ <slot></slot>
+`;
+
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (204723 => 204724)
--- trunk/Source/WebCore/ChangeLog 2016-08-22 16:40:49 UTC (rev 204723)
+++ trunk/Source/WebCore/ChangeLog 2016-08-22 17:19:29 UTC (rev 204724)
@@ -1,3 +1,36 @@
+2016-08-22 Antti Koivisto <[email protected]>
+
+ Can't style descendants in shadow tree using the :host pseudo class
+ https://bugs.webkit.org/show_bug.cgi?id=160754
+
+ Reviewed by Darin Adler.
+
+ "The :host pseudo-class, when evaluated in the context of a shadow tree, matches the shadow tree’s shadow host."
+
+ Currently :host() works for styling the host element itself (:host(.foo) { ... }). It should also be usable
+ for styling elements in the shadow tree:
+
+ :host(.foo) div { ... }
+
+ Test: fast/shadow-dom/css-scoping-host-descendant.html
+
+ * css/SelectorChecker.cpp:
+ (WebCore::SelectorChecker::matchHostPseudoClass):
+ (WebCore::localContextForParent):
+
+ Move to shadow host if we are matching :host and are at the root of the shadow tree.
+ Set didMoveToShadowHost bit in the context.
+
+ (WebCore::SelectorChecker::matchRecursively):
+ (WebCore::SelectorChecker::checkOne):
+
+ Call the existing matchHostPseudoClass to do :host matching if didMoveToShadowHost bit has been set.
+
+ * cssjit/SelectorCompiler.cpp:
+ (WebCore::SelectorCompiler::addPseudoClassType):
+
+ Disallow :host in the compiler (cases where it would match didn't reach the compiler before).
+
2016-08-22 Frederic Wang <[email protected]>
Use memoize pattern for the menclose notation attribute
Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (204723 => 204724)
--- trunk/Source/WebCore/css/SelectorChecker.cpp 2016-08-22 16:40:49 UTC (rev 204723)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp 2016-08-22 17:19:29 UTC (rev 204724)
@@ -81,6 +81,7 @@
bool pseudoElementEffective { true };
bool hasScrollbarPseudo { false };
bool hasSelectionPseudo { false };
+ bool didMoveToShadowHost { false };
};
@@ -211,7 +212,6 @@
{
ASSERT(element.shadowRoot());
ASSERT(selector.match() == CSSSelector::PseudoClass && selector.pseudoClassType() == CSSSelector::PseudoClassHost);
- ASSERT(checkingContext.resolvingMode != SelectorChecker::Mode::QueryingRules);
specificity = selector.simpleSelectorSpecificity();
@@ -249,8 +249,22 @@
// Disable :visited matching when we see the first link.
if (context.element->isLink())
updatedContext.visitedMatchType = VisitedMatchType::Disabled;
+
+ updatedContext.isMatchElement = false;
+
+ if (updatedContext.didMoveToShadowHost) {
+ updatedContext.element = nullptr;
+ return updatedContext;
+ }
+
+ // Move to the shadow host if matching :host and the parent is the shadow root.
+ if (context.selector->match() == CSSSelector::PseudoClass && context.selector->pseudoClassType() == CSSSelector::PseudoClassHost && is<ShadowRoot>(context.element->parentNode())) {
+ updatedContext.element = downcast<ShadowRoot>(*context.element->parentNode()).host();
+ updatedContext.didMoveToShadowHost = true;
+ return updatedContext;
+ }
+
updatedContext.element = context.element->parentElement();
- updatedContext.isMatchElement = false;
return updatedContext;
}
@@ -300,12 +314,12 @@
CSSSelector::Relation relation = context.selector->relation();
// Prepare next selector
- const CSSSelector* historySelector = context.selector->tagHistory();
- if (!historySelector)
+ const CSSSelector* leftSelector = context.selector->tagHistory();
+ if (!leftSelector)
return MatchResult::matches(matchType);
LocalContext nextContext(context);
- nextContext.selector = historySelector;
+ nextContext.selector = leftSelector;
if (relation != CSSSelector::SubSelector) {
// Bail-out if this selector is irrelevant for the pseudoId
@@ -1021,16 +1035,21 @@
return matchesPastCuePseudoClass(element);
#endif
- case CSSSelector::PseudoClassScope:
- {
- const Node* contextualReferenceNode = !checkingContext.scope ? element.document().documentElement() : checkingContext.scope;
- if (&element == contextualReferenceNode)
- return true;
- break;
- }
- case CSSSelector::PseudoClassHost:
- // :host matches based on context. Cases that reach selector checker don't match.
- return false;
+ case CSSSelector::PseudoClassScope: {
+ const Node* contextualReferenceNode = !checkingContext.scope ? element.document().documentElement() : checkingContext.scope;
+ if (&element == contextualReferenceNode)
+ return true;
+ break;
+ }
+ case CSSSelector::PseudoClassHost: {
+ if (!context.didMoveToShadowHost)
+ return false;
+ unsigned hostSpecificity;
+ if (!matchHostPseudoClass(selector, element, checkingContext, hostSpecificity))
+ return false;
+ specificity = CSSSelector::addSpecificities(specificity, hostSpecificity);
+ return true;
+ }
#if ENABLE(CUSTOM_ELEMENTS)
case CSSSelector::PseudoClassDefined:
return isDefinedElement(element);
Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (204723 => 204724)
--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp 2016-08-22 16:40:49 UTC (rev 204723)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp 2016-08-22 17:19:29 UTC (rev 204724)
@@ -829,8 +829,7 @@
return functionType;
}
case CSSSelector::PseudoClassHost:
- // :host matches based on context. Cases that reach selector checker don't match.
- return FunctionType::CannotMatchAnything;
+ return FunctionType::CannotCompile;
case CSSSelector::PseudoClassUnknown:
ASSERT_NOT_REACHED();
return FunctionType::CannotMatchAnything;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes