Title: [288303] trunk
Revision
288303
Author
[email protected]
Date
2022-01-20 10:09:17 -0800 (Thu, 20 Jan 2022)

Log Message

[:has pseudo-class] Support :has(:not(foo))
https://bugs.webkit.org/show_bug.cgi?id=235399

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/css/selectors/invalidation/has-with-not-expected.txt: Added.
* web-platform-tests/css/selectors/invalidation/has-with-not.html: Added.

Source/WebCore:

This already works except for a filter bug.

Test: imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not.html

* style/HasSelectorFilter.h:
(WebCore::Style::HasSelectorFilter::reject const):

We shouldn't reject a selector if we have a null key.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288302 => 288303)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-20 18:06:49 UTC (rev 288302)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-20 18:09:17 UTC (rev 288303)
@@ -1,3 +1,13 @@
+2022-01-20  Antti Koivisto  <[email protected]>
+
+        [:has pseudo-class] Support :has(:not(foo))
+        https://bugs.webkit.org/show_bug.cgi?id=235399
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/css/selectors/invalidation/has-with-not-expected.txt: Added.
+        * web-platform-tests/css/selectors/invalidation/has-with-not.html: Added.
+
 2022-01-19  Chris Dumez  <[email protected]>
 
         Align our qualified name validation with the specification

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not-expected.txt (0 => 288303)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not-expected.txt	2022-01-20 18:09:17 UTC (rev 288303)
@@ -0,0 +1,23 @@
+
+PASS Initial color
+PASS remove .test to subject_child
+PASS add .test from subject_child
+PASS remove .test to subject_descendant
+PASS add .test from subject_descendant
+PASS insert element div before subject_child
+PASS remove element div before subject_child
+PASS insert element div before subject_descendant
+PASS remove element div before subject_descendant
+PASS insert element div after subject_child
+PASS remove element div after subject_child
+PASS insert element div after subject_descendant
+PASS remove element div after subject_descendant
+PASS insert tree div>div before subject_child
+PASS remove tree div>div before subject_child
+PASS insert tree div>div before subject_descendant
+PASS remove tree div>div before subject_descendant
+PASS insert tree div.test after subject_child
+PASS remove tree div.test after subject_child
+PASS insert tree div.test after subject_descendant
+PASS remove tree div.test after subject_descendant
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not.html (0 => 288303)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not.html	2022-01-20 18:09:17 UTC (rev 288303)
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Selector Invalidation: :has() with :not()</title>
+<link rel="author" title="Antti Koivisto" href=""
+<script src=""
+<script src=""
+<link rel="help" href=""
+<style>
+div, main { color: grey }
+#subject:has(:not(.test)) { color: green }
+#subject:has(.test :not(.test)) { color: red }
+</style>
+
+<main id=main>
+    <div id=subject>
+        <div id=subject_child class=test>
+            <div id=subject_descendant class=test></div>
+        </div>
+    </div>
+</main>
+
+<script>
+const grey = 'rgb(128, 128, 128)';
+const red = 'rgb(255, 0, 0)';
+const green = 'rgb(0, 128, 0)';
+const blue = 'rgb(0, 0, 255)';
+
+function testColor(test_name, color) {
+    test(function() {
+        assert_equals(getComputedStyle(subject).color, color);
+    }, test_name);
+}
+
+function testClassChange(element, expectedColor)
+{
+    element.classList.remove('test');
+    testColor(`remove .test to ${element.id}`, expectedColor);
+    element.classList.add('test');
+    testColor(`add .test from ${element.id}`, grey);
+}
+
+function testElementInsertionBefore(beforeElement, expectedColor)
+{
+    const newElement = document.createElement('div');
+
+    beforeElement.before(newElement);
+    testColor(`insert element div before ${beforeElement.id}`, expectedColor);
+
+    newElement.remove();
+    testColor(`remove element div before ${beforeElement.id}`, grey);
+}
+
+function testElementInsertionAfter(afterElement, expectedColor)
+{
+    const newElement = document.createElement('div');
+
+    afterElement.after(newElement);
+    testColor(`insert element div after ${afterElement.id}`, expectedColor);
+
+    newElement.remove();
+    testColor(`remove element div after ${afterElement.id}`, grey);
+}
+
+function testTreeInsertionBefore(beforeElement, expectedColor)
+{
+    const newElement = document.createElement('div');
+    const newChild = document.createElement('div');
+    newElement.appendChild(newChild);
+
+    beforeElement.before(newElement);
+    testColor(`insert tree div>div before ${beforeElement.id}`, expectedColor);
+
+    newElement.remove();
+    testColor(`remove tree div>div before ${beforeElement.id}`, grey);
+}
+
+function testTreeInsertionAfter(afterElement, expectedColor)
+{
+    const newElement = document.createElement('div');
+    const newChild = document.createElement('div');
+    newElement.appendChild(newChild);
+
+    afterElement.after(newElement);
+    testColor(`insert tree div.test after ${afterElement.id}`, expectedColor);
+
+    newElement.remove();
+    testColor(`remove tree div.test after ${afterElement.id}`, grey);
+}
+
+testColor('Initial color', grey);
+
+testClassChange(subject_child, green);
+testClassChange(subject_descendant, red);
+
+testElementInsertionBefore(subject_child, green);
+testElementInsertionBefore(subject_descendant, red);
+
+testElementInsertionAfter(subject_child, green);
+testElementInsertionAfter(subject_descendant, red);
+
+testTreeInsertionBefore(subject_child, green);
+testTreeInsertionBefore(subject_descendant, red);
+
+testTreeInsertionAfter(subject_child, green);
+testTreeInsertionAfter(subject_descendant, red);
+
+</script>

Modified: trunk/Source/WebCore/ChangeLog (288302 => 288303)


--- trunk/Source/WebCore/ChangeLog	2022-01-20 18:06:49 UTC (rev 288302)
+++ trunk/Source/WebCore/ChangeLog	2022-01-20 18:09:17 UTC (rev 288303)
@@ -1,3 +1,19 @@
+2022-01-20  Antti Koivisto  <[email protected]>
+
+        [:has pseudo-class] Support :has(:not(foo))
+        https://bugs.webkit.org/show_bug.cgi?id=235399
+
+        Reviewed by Darin Adler.
+
+        This already works except for a filter bug.
+
+        Test: imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-not.html
+
+        * style/HasSelectorFilter.h:
+        (WebCore::Style::HasSelectorFilter::reject const):
+
+        We shouldn't reject a selector if we have a null key.
+
 2022-01-20  Youenn Fablet  <[email protected]>
 
         Reconfiguring the CoreAudioSharedUnit should take into account that there is a speaker sample producer

Modified: trunk/Source/WebCore/style/HasSelectorFilter.h (288302 => 288303)


--- trunk/Source/WebCore/style/HasSelectorFilter.h	2022-01-20 18:06:49 UTC (rev 288302)
+++ trunk/Source/WebCore/style/HasSelectorFilter.h	2022-01-20 18:09:17 UTC (rev 288303)
@@ -48,9 +48,8 @@
     static Key makeKey(const CSSSelector& hasSelector);
 
     bool reject(const CSSSelector& hasSelector) const { return reject(makeKey(hasSelector)); }
-    bool reject(Key key) const { return !m_filter.mayContain(key); }
+    bool reject(Key key) const { return key && !m_filter.mayContain(key); }
 
-
 private:
     void add(const Element&);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to