Title: [224864] trunk
Revision
224864
Author
an...@apple.com
Date
2017-11-14 17:15:21 -0800 (Tue, 14 Nov 2017)

Log Message

Media query with :host inside a custom elements doesn't get updated on window resize
https://bugs.webkit.org/show_bug.cgi?id=176101
<rdar://problem/34163850>

Reviewed by Simon Fraser.

Source/WebCore:

If a media query containing :host or ::slotted stops applying we fail to update the style.

* style/StyleScope.cpp:
(WebCore::Style::invalidateHostAndSlottedStyleIfNeeded):

    Factor into function.

(WebCore::Style::Scope::updateActiveStyleSheets):
(WebCore::Style::Scope::scheduleUpdate):

    Invalidate elements that may match :host and ::slotted before clearing style resolver for full update.

LayoutTests:

Expand the existing test case to cover :host and ::slotted.

* fast/shadow-dom/media-query-in-shadow-style-expected.html:
* fast/shadow-dom/resources/media-query-in-shadow-style-frame.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224863 => 224864)


--- trunk/LayoutTests/ChangeLog	2017-11-15 00:43:32 UTC (rev 224863)
+++ trunk/LayoutTests/ChangeLog	2017-11-15 01:15:21 UTC (rev 224864)
@@ -1,3 +1,16 @@
+2017-11-14  Antti Koivisto  <an...@apple.com>
+
+        Media query with :host inside a custom elements doesn't get updated on window resize
+        https://bugs.webkit.org/show_bug.cgi?id=176101
+        <rdar://problem/34163850>
+
+        Reviewed by Simon Fraser.
+
+        Expand the existing test case to cover :host and ::slotted.
+
+        * fast/shadow-dom/media-query-in-shadow-style-expected.html:
+        * fast/shadow-dom/resources/media-query-in-shadow-style-frame.html:
+
 2017-11-14  Ryan Haddad  <ryanhad...@apple.com>
 
         Mark fast/scrolling/rtl-scrollbars.html as flaky.

Modified: trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html (224863 => 224864)


--- trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html	2017-11-15 00:43:32 UTC (rev 224863)
+++ trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html	2017-11-15 01:15:21 UTC (rev 224864)
@@ -1,4 +1,4 @@
-<iframe src="" style='color:red'>Text</span>" width=150 height=50></iframe><br>
-<iframe src="" style='color:green'>Text</span>" width=300 height=50></iframe><br>
-<iframe src="" style='color:red'>Text</span>" width=150 height=50></iframe><br>
-<iframe src="" style='color:green'>Text</span>" width=300 height=50></iframe><br>
+<iframe src="" style='color:red'>Text</div>" width=150 height=50></iframe><br>
+<iframe src="" style='color:green;background-color: lightgrey'>Text</div>" width=300 height=50></iframe><br>
+<iframe src="" style='color:red'>Text</div>" width=150 height=50></iframe><br>
+<iframe src="" style='color:green;background-color: lightgrey'>Text</div>" width=300 height=50></iframe><br>

Modified: trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html (224863 => 224864)


--- trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html	2017-11-15 00:43:32 UTC (rev 224863)
+++ trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html	2017-11-15 01:15:21 UTC (rev 224864)
@@ -1,4 +1,4 @@
-<div id=test></div>
+<div id=test><span>Text</span></div>
 <script>
 const shadow = test.attachShadow({mode: 'open'});
 shadow.innerHTML = `
@@ -5,11 +5,12 @@
     <style>
     @media (min-width:200px) {
         div { color: green }
+        :host { background-color: lightgrey }
     }
     @media (max-width:200px) {
-        div { color: red }
+        ::slotted(*) { color: red }
     }
     </style>
-    <div>Text</div>
+    <div><slot></slot></div>
 `;
 </script>

Modified: trunk/Source/WebCore/ChangeLog (224863 => 224864)


--- trunk/Source/WebCore/ChangeLog	2017-11-15 00:43:32 UTC (rev 224863)
+++ trunk/Source/WebCore/ChangeLog	2017-11-15 01:15:21 UTC (rev 224864)
@@ -1,3 +1,23 @@
+2017-11-14  Antti Koivisto  <an...@apple.com>
+
+        Media query with :host inside a custom elements doesn't get updated on window resize
+        https://bugs.webkit.org/show_bug.cgi?id=176101
+        <rdar://problem/34163850>
+
+        Reviewed by Simon Fraser.
+
+        If a media query containing :host or ::slotted stops applying we fail to update the style.
+
+        * style/StyleScope.cpp:
+        (WebCore::Style::invalidateHostAndSlottedStyleIfNeeded):
+
+            Factor into function.
+
+        (WebCore::Style::Scope::updateActiveStyleSheets):
+        (WebCore::Style::Scope::scheduleUpdate):
+
+            Invalidate elements that may match :host and ::slotted before clearing style resolver for full update.
+
 2017-11-14  Carlos Garcia Campos  <cgar...@igalia.com>
 
         Move JSONValues to WTF and convert uses of InspectorValues.h to JSONValues.h

Modified: trunk/Source/WebCore/style/StyleScope.cpp (224863 => 224864)


--- trunk/Source/WebCore/style/StyleScope.cpp	2017-11-15 00:43:32 UTC (rev 224863)
+++ trunk/Source/WebCore/style/StyleScope.cpp	2017-11-15 01:15:21 UTC (rev 224864)
@@ -446,6 +446,18 @@
     }
 }
 
+static void invalidateHostAndSlottedStyleIfNeeded(ShadowRoot& shadowRoot, StyleResolver& resolver)
+{
+    auto& host = *shadowRoot.host();
+    if (!resolver.ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
+        host.invalidateStyle();
+
+    if (!resolver.ruleSets().authorStyle().slottedPseudoElementRules().isEmpty()) {
+        for (auto& shadowChild : childrenOfType<Element>(host))
+            shadowChild.invalidateStyle();
+    }
+}
+
 void Scope::updateActiveStyleSheets(UpdateType updateType)
 {
     ASSERT(!m_pendingUpdate);
@@ -493,14 +505,7 @@
         if (m_shadowRoot) {
             for (auto& shadowChild : childrenOfType<Element>(*m_shadowRoot))
                 shadowChild.invalidateStyleForSubtree();
-            if (m_shadowRoot->host()) {
-                if (!resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
-                    m_shadowRoot->host()->invalidateStyle();
-                if (!resolver().ruleSets().authorStyle().slottedPseudoElementRules().isEmpty()) {
-                    for (auto& shadowChild : childrenOfType<Element>(*m_shadowRoot->host()))
-                        shadowChild.invalidateStyle();
-                }
-            }
+            invalidateHostAndSlottedStyleIfNeeded(*m_shadowRoot, resolver());
         } else
             m_document.scheduleForcedStyleRecalc();
     }
@@ -585,9 +590,14 @@
 
 void Scope::scheduleUpdate(UpdateType update)
 {
-    // FIXME: The m_isUpdatingStyleResolver test is here because extension stylesheets can get us here from StyleResolver::appendAuthorStyleSheets.
-    if (update == UpdateType::ContentsOrInterpretation && !m_isUpdatingStyleResolver)
-        clearResolver();
+    if (update == UpdateType::ContentsOrInterpretation) {
+        // :host and ::slotted rules might go away.
+        if (m_shadowRoot && m_resolver)
+            invalidateHostAndSlottedStyleIfNeeded(*m_shadowRoot, *m_resolver);
+        // FIXME: The m_isUpdatingStyleResolver test is here because extension stylesheets can get us here from StyleResolver::appendAuthorStyleSheets.
+        if (!m_isUpdatingStyleResolver)
+            clearResolver();
+    }
 
     if (!m_pendingUpdate || *m_pendingUpdate < update) {
         m_pendingUpdate = update;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to