summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkochi@chromium.org <kochi@chromium.org>2014-08-26 07:21:05 +0000
committerkochi@chromium.org <kochi@chromium.org>2014-08-26 07:21:05 +0000
commitae61aa1fef6b6b8c8eee0988ff26b133c8e7d45e (patch)
treeb7f59d2c361471c40fef96ab1aa5c368c814b140
parent631c1b3c7604fafc016b5e9740d7e997a552512d (diff)
downloadchromium_src-ae61aa1fef6b6b8c8eee0988ff26b133c8e7d45e.zip
chromium_src-ae61aa1fef6b6b8c8eee0988ff26b133c8e7d45e.tar.gz
chromium_src-ae61aa1fef6b6b8c8eee0988ff26b133c8e7d45e.tar.bz2
Allow :host()::before and :host::after to work as expected
In style definition in a shadow tree, :host()::before and :host()::after should match and work as expected. (i.e. prepend/append "content" to its shadow host). BUG=393509 TEST=pass layout tests Review URL: https://codereview.chromium.org/402813003 git-svn-id: svn://svn.chromium.org/blink/trunk@180888 bbb929c8-8fbe-4397-9dbb-9b2b20218538
-rw-r--r--third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class-expected.html2
-rw-r--r--third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class.html14
-rw-r--r--third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class-expected.html2
-rw-r--r--third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class.html12
-rw-r--r--third_party/WebKit/Source/core/css/SelectorChecker.cpp9
5 files changed, 35 insertions, 4 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class-expected.html b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class-expected.html
new file mode 100644
index 0000000..7768cf3
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class-expected.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<div>before shadow root:SHADOW</div>
diff --git a/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class.html b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class.html
new file mode 100644
index 0000000..6d8a2e6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-context-pseudo-class.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<body class=shadow>
+<div id="host">HOST</div>
+</body>
+<script>
+var host = document.getElementById('host');
+var root = host.createShadowRoot();
+root.innerHTML = '\
+<style>\
+ :host-context(body.shadow)::before { content: "before shadow root:"; }\
+ :host-context(body.light)::before { content: "this should not appear:"; }\
+</style>\
+<span>SHADOW</span>';
+</script>
diff --git a/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class-expected.html b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class-expected.html
new file mode 100644
index 0000000..20ccc46
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class-expected.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<div>before shadow root:SHADOW:after shadow root</div>
diff --git a/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class.html b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class.html
new file mode 100644
index 0000000..9a57bb4
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/css-generated-content/shadow-host-pseudo-class.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<div id="host">HOST</div>
+<script>
+var host = document.getElementById('host');
+var root = host.createShadowRoot();
+root.innerHTML = '\
+<style>\
+ :host::before { content: "before shadow root:"; }\
+ :host::after { content: ":after shadow root"; }\
+</style>\
+<span>SHADOW</span>';
+</script>
diff --git a/third_party/WebKit/Source/core/css/SelectorChecker.cpp b/third_party/WebKit/Source/core/css/SelectorChecker.cpp
index ebe49c1..70beb60 100644
--- a/third_party/WebKit/Source/core/css/SelectorChecker.cpp
+++ b/third_party/WebKit/Source/core/css/SelectorChecker.cpp
@@ -507,10 +507,11 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context, const Sib
bool elementIsHostInItsShadowTree = isHostInItsShadowTree(element, context.scope);
- // Only :host and :ancestor should match the host: http://drafts.csswg.org/css-scoping/#host-element
- if (elementIsHostInItsShadowTree && !selector.isHostPseudoClass()
- && !(context.contextFlags & TreatShadowHostAsNormalScope))
- return false;
+ // Only :host and :host-context() should match the host: http://drafts.csswg.org/css-scoping/#host-element
+ if (elementIsHostInItsShadowTree && (!selector.isHostPseudoClass()
+ && !(context.contextFlags & TreatShadowHostAsNormalScope)
+ && selector.match() != CSSSelector::PseudoElement))
+ return false;
if (selector.match() == CSSSelector::Tag)
return SelectorChecker::tagMatches(element, selector.tagQName());