Shadow DOM: :host() From The First Shadow Context Should Not Style All Shadow Context
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Apr 2016 16:45:51 +0000 (16:45 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Apr 2016 16:45:51 +0000 (16:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156235
<rdar://problem/24668206>

Reviewed by Andreas Kling.

Source/WebCore:

Test: fast/shadow-dom/host-style-sharing.html

* style/StyleSharingResolver.cpp:
(WebCore::Style::SharingResolver::resolve):
(WebCore::Style::SharingResolver::canShareStyleWithElement):

    Disallow style sharing for shadow hosts affected by :host pseudo class rules.

LayoutTests:

* fast/shadow-dom/host-style-sharing-expected.html: Added.
* fast/shadow-dom/host-style-sharing.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199060 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/shadow-dom/host-style-sharing-expected.html [new file with mode: 0644]
LayoutTests/fast/shadow-dom/host-style-sharing.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/style/StyleSharingResolver.cpp

index 08995e5..385da19 100644 (file)
@@ -1,5 +1,16 @@
 2016-04-05  Antti Koivisto  <antti@apple.com>
 
+        Shadow DOM: :host() From The First Shadow Context Should Not Style All Shadow Context
+        https://bugs.webkit.org/show_bug.cgi?id=156235
+        <rdar://problem/24668206>
+
+        Reviewed by Andreas Kling.
+
+        * fast/shadow-dom/host-style-sharing-expected.html: Added.
+        * fast/shadow-dom/host-style-sharing.html: Added.
+
+2016-04-05  Antti Koivisto  <antti@apple.com>
+
         Use RenderTreeUpdater for text node mutations
         https://bugs.webkit.org/show_bug.cgi?id=156107
 
diff --git a/LayoutTests/fast/shadow-dom/host-style-sharing-expected.html b/LayoutTests/fast/shadow-dom/host-style-sharing-expected.html
new file mode 100644 (file)
index 0000000..c691941
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title></title>
+  </head>
+  <body>
+    <style>
+    #host1 { border: 1px solid #f09; }
+    #host2 { border: 1px solid #000; }
+    </style>
+
+    <template id="for-host-1">
+      I &#9829; <slot name="what-I-love"><slot>
+    </template>
+
+    <template id="for-host-2">
+      I <strike>&#9829;</strike> <slot name="what-I-hate"><slot>
+    </template>
+
+    <div id="host1">
+      <span name="what-I-love">Shadow DOM<span>
+    </div>
+
+    <div id="host2">
+      <span name="what-I-hate">Shadow DOM<span>
+    </div>
+
+    <script>
+      var host1 = document.querySelector('#host1');
+      var host1ShadowRoot = host1.attachShadow({mode: 'closed'});
+      var host1ShadowContent = document.importNode(document.querySelector('#for-host-1').content, true);
+      host1ShadowRoot.appendChild(host1ShadowContent);
+
+      var host2 = document.querySelector('#host2');
+      var host2ShadowRoot = host2.attachShadow({mode: 'closed'});
+      var host2ShadowContent = document.importNode(document.querySelector('#for-host-2').content, true);
+      host2ShadowRoot.appendChild(host2ShadowContent);
+    </script>
+  </body>
+</html>
diff --git a/LayoutTests/fast/shadow-dom/host-style-sharing.html b/LayoutTests/fast/shadow-dom/host-style-sharing.html
new file mode 100644 (file)
index 0000000..80f8086
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title></title>
+  </head>
+  <body>
+    <template id="for-host-1">
+      <style>
+      :host { border: 1px solid #f09; }
+      </style>
+      I &#9829; <slot name="what-I-love"><slot>
+    </template>
+
+    <template id="for-host-2">
+      <style>
+      :host { border: 1px solid #000; }
+      </style>
+      I <strike>&#9829;</strike> <slot name="what-I-hate"><slot>
+    </template>
+
+    <div id="host1">
+      <span name="what-I-love">Shadow DOM<span>
+    </div>
+
+    <div id="host2">
+      <span name="what-I-hate">Shadow DOM<span>
+    </div>
+
+    <script>
+      var host1 = document.querySelector('#host1');
+      var host1ShadowRoot = host1.attachShadow({mode: 'closed'});
+      var host1ShadowContent = document.importNode(document.querySelector('#for-host-1').content, true);
+      host1ShadowRoot.appendChild(host1ShadowContent);
+
+      var host2 = document.querySelector('#host2');
+      var host2ShadowRoot = host2.attachShadow({mode: 'closed'});
+      var host2ShadowContent = document.importNode(document.querySelector('#for-host-2').content, true);
+      host2ShadowRoot.appendChild(host2ShadowContent);
+    </script>
+  </body>
+</html>
index b972540..ca5d74e 100644 (file)
@@ -1,3 +1,19 @@
+2016-04-05  Antti Koivisto  <antti@apple.com>
+
+        Shadow DOM: :host() From The First Shadow Context Should Not Style All Shadow Context
+        https://bugs.webkit.org/show_bug.cgi?id=156235
+        <rdar://problem/24668206>
+
+        Reviewed by Andreas Kling.
+
+        Test: fast/shadow-dom/host-style-sharing.html
+
+        * style/StyleSharingResolver.cpp:
+        (WebCore::Style::SharingResolver::resolve):
+        (WebCore::Style::SharingResolver::canShareStyleWithElement):
+
+            Disallow style sharing for shadow hosts affected by :host pseudo class rules.
+
 2016-04-05  Alex Christensen  <achristensen@webkit.org>
 
         Speculative build fix after r199043
index a91f66a..466ac50 100644 (file)
@@ -33,6 +33,7 @@
 #include "NodeRenderStyle.h"
 #include "RenderStyle.h"
 #include "SVGElement.h"
+#include "ShadowRoot.h"
 #include "StyleUpdate.h"
 #include "StyledElement.h"
 #include "VisitedLinkState.h"
@@ -95,6 +96,10 @@ RefPtr<RenderStyle> SharingResolver::resolve(const Element& searchElement, const
         return nullptr;
     if (elementHasDirectionAuto(element))
         return nullptr;
+#if ENABLE(SHADOW_DOM)
+    if (element.shadowRoot() && !element.shadowRoot()->styleResolver().ruleSets().authorStyle()->hostPseudoClassRules().isEmpty())
+        return nullptr;
+#endif
 
     Context context {
         update,
@@ -278,6 +283,11 @@ bool SharingResolver::canShareStyleWithElement(const Context& context, const Sty
     if (element.matchesInvalidPseudoClass() != element.matchesValidPseudoClass())
         return false;
 
+#if ENABLE(SHADOW_DOM)
+    if (element.shadowRoot() && !element.shadowRoot()->styleResolver().ruleSets().authorStyle()->hostPseudoClassRules().isEmpty())
+        return nullptr;
+#endif
+
 #if ENABLE(VIDEO_TRACK)
     // Deny sharing styles between WebVTT and non-WebVTT nodes.
     if (is<WebVTTElement>(element))