Title: [295726] trunk
Revision
295726
Author
an...@apple.com
Date
2022-06-22 05:20:21 -0700 (Wed, 22 Jun 2022)

Log Message

[CSS Container Queries] Improper style sharing with container queries
https://bugs.webkit.org/show_bug.cgi?id=241848

Reviewed by Antoine Quint.

Elements affected by container queries may get different style even though DOM is perfectly symmetric because containers have different sizes.

* LayoutTests/fast/css/container-query-style-sharing-expected.html: Added.
* LayoutTests/fast/css/container-query-style-sharing.html: Added.
* Source/WebCore/style/StyleSharingResolver.cpp:
(WebCore::Style::SharingResolver::canShareStyleWithElement const):

Canonical link: https://commits.webkit.org/251731@main

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/fast/css/container-query-style-sharing-expected.html (0 => 295726)


--- trunk/LayoutTests/fast/css/container-query-style-sharing-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/container-query-style-sharing-expected.html	2022-06-22 12:20:21 UTC (rev 295726)
@@ -0,0 +1,17 @@
+<style>
+body {
+    display: grid;
+    grid-template-columns: 100px 50px;
+}
+div {
+    background-color: blue;
+}
+</style>
+<body>
+<div>
+    <span style="background-color: green">1</span>
+</div>
+<div>
+    <span style="background-color: red">2</span>
+</div>
+</body>

Added: trunk/LayoutTests/fast/css/container-query-style-sharing.html (0 => 295726)


--- trunk/LayoutTests/fast/css/container-query-style-sharing.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/container-query-style-sharing.html	2022-06-22 12:20:21 UTC (rev 295726)
@@ -0,0 +1,23 @@
+<style>
+body {
+    display: grid;
+    grid-template-columns: 100px 50px;
+}
+div {
+    container-type: inline-size;
+    background-color: blue;
+}
+span { background-color: red }
+@container (width = 100px) {
+    span { background-color: green }
+}
+</style>
+<body>
+<div>
+    <span>1</span>
+</div>
+<div>
+    <span>2</span>
+</div>
+</body>
+

Modified: trunk/Source/WebCore/style/StyleSharingResolver.cpp (295725 => 295726)


--- trunk/Source/WebCore/style/StyleSharingResolver.cpp	2022-06-22 09:20:20 UTC (rev 295725)
+++ trunk/Source/WebCore/style/StyleSharingResolver.cpp	2022-06-22 12:20:21 UTC (rev 295726)
@@ -261,6 +261,9 @@
     if (candidateElement.isLink() && context.elementLinkState != style->insideLink())
         return false;
 
+    if (style->containerType() != ContainerType::None)
+        return false;
+
     if (candidateElement.elementData() != element.elementData()) {
         // Attributes that are optimized as "common attribute selectors".
         if (candidateElement.attributeWithoutSynchronization(HTMLNames::readonlyAttr) != element.attributeWithoutSynchronization(HTMLNames::readonlyAttr))
@@ -293,6 +296,7 @@
     if (&candidateElement == m_document.fullscreenManager().currentFullscreenElement() || &element == m_document.fullscreenManager().currentFullscreenElement())
         return false;
 #endif
+
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to