Title: [288196] trunk
Revision
288196
Author
[email protected]
Date
2022-01-19 05:43:32 -0800 (Wed, 19 Jan 2022)

Log Message

[:has() pseudo-class] Compute specificity correctly
https://bugs.webkit.org/show_bug.cgi?id=235351

Reviewed by Alexey Shvayka.

LayoutTests/imported/w3c:

* web-platform-tests/css/selectors/has-complexity.html:

Fix specificity used in this test.

* web-platform-tests/css/selectors/has-specificity-expected.txt: Added.
* web-platform-tests/css/selectors/has-specificity.html: Added.

Source/WebCore:

"The specificity of an ':is()', ':not()', or ':has()' pseudo-class is replaced by
the specificity of the most specific complex selector in its selector list argument."

https://www.w3.org/TR/selectors-4/#specificity-rules

Test: imported/w3c/web-platform-tests/css/selectors/has-specificity.html

* css/CSSSelector.cpp:
(WebCore::simpleSelectorSpecificityInternal):

Compute :has() specificity like :is() and :not().

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288195 => 288196)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-19 13:06:07 UTC (rev 288195)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-19 13:43:32 UTC (rev 288196)
@@ -1,3 +1,17 @@
+2022-01-19  Antti Koivisto  <[email protected]>
+
+        [:has() pseudo-class] Compute specificity correctly
+        https://bugs.webkit.org/show_bug.cgi?id=235351
+
+        Reviewed by Alexey Shvayka.
+
+        * web-platform-tests/css/selectors/has-complexity.html:
+
+        Fix specificity used in this test.
+
+        * web-platform-tests/css/selectors/has-specificity-expected.txt: Added.
+        * web-platform-tests/css/selectors/has-specificity.html: Added.
+
 2022-01-18  Sergio Villar Senin  <[email protected]>
 
         [css-flexbox] Add support for intrinsic sizes to the flex shorthand

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-specificity-expected.txt (0 => 288196)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-specificity-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-specificity-expected.txt	2022-01-19 13:43:32 UTC (rev 288196)
@@ -0,0 +1,8 @@
+
+PASS :has(#foo) wins over :has(.foo)
+PASS :has(span#foo) wins over :has(#foo)
+PASS :has(.bar, #foo) has same specificity as :has(#foo, .bar)
+PASS :has(.bar, #foo) wins over :has(.foo, .bar)
+PASS :has(span + span) wins over :has(span)
+PASS :has(span, li, p) wins over :has(span, lo, p)
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-specificity.html (0 => 288196)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-specificity.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-specificity.html	2022-01-19 13:43:32 UTC (rev 288196)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<title>Specificity for complex :has selectors</title>
+<script src=""
+<script src=""
+<link rel="help" href=""
+<style>
+  main :has(#foo) { --t0:PASS; }
+  main :has(.foo) { --t0:FAIL; }
+
+  main :has(span#foo) { --t1:PASS; }
+  main :has(#foo) { --t1:FAIL; }
+
+  main :has(.bar, #foo) { --t2:FAIL; }
+  main :has(#foo, .bar) { --t2:PASS; }
+
+  main :has(.bar, #foo) { --t3:PASS; }
+  main :has(.foo, .bar) { --t3:FAIL; }
+
+  main :has(span + span) { --t4:PASS; }
+  main :has(span) { --t4:FAIL; }
+
+  main :has(span, li, #foo) { --t5:PASS; }
+  main :has(span, li, p) { --t5:FAIL; }
+</style>
+<main id=main>
+  <div id=div><p><span id=foo class=foo></span><span class=bar></span><li></li></p></div>
+</main>
+<script>
+  function test_value(name, description) {
+    test(function() {
+      let actual = getComputedStyle(div).getPropertyValue(name);
+      assert_equals(actual, 'PASS');
+    }, description);
+  }
+
+  test_value('--t0', ':has(#foo) wins over :has(.foo)');
+  test_value('--t1', ':has(span#foo) wins over :has(#foo)');
+  test_value('--t2', ':has(.bar, #foo) has same specificity as :has(#foo, .bar)');
+  test_value('--t3', ':has(.bar, #foo) wins over :has(.foo, .bar)');
+  test_value('--t4', ':has(span + span) wins over :has(span)');
+  test_value('--t5', ':has(span, li, p) wins over :has(span, lo, p)');
+</script>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-complexity.html (288195 => 288196)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-complexity.html	2022-01-19 13:06:07 UTC (rev 288195)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-complexity.html	2022-01-19 13:43:32 UTC (rev 288196)
@@ -9,7 +9,7 @@
 div, main { color: grey }
 main:has(span) .subject { color: red }
 main:has(span + span) .subject { color: green }
-main:has(final) .subject { color: blue }
+main:has(span + final) .subject { color: blue }
 main:has(nonexistent + span) .subject { color: black }
 main:has(span) span { color: black }
 main:has(nonexistent) span { color: black }

Modified: trunk/Source/WebCore/ChangeLog (288195 => 288196)


--- trunk/Source/WebCore/ChangeLog	2022-01-19 13:06:07 UTC (rev 288195)
+++ trunk/Source/WebCore/ChangeLog	2022-01-19 13:43:32 UTC (rev 288196)
@@ -1,3 +1,22 @@
+2022-01-19  Antti Koivisto  <[email protected]>
+
+        [:has() pseudo-class] Compute specificity correctly
+        https://bugs.webkit.org/show_bug.cgi?id=235351
+
+        Reviewed by Alexey Shvayka.
+
+        "The specificity of an ':is()', ':not()', or ':has()' pseudo-class is replaced by
+        the specificity of the most specific complex selector in its selector list argument."
+
+        https://www.w3.org/TR/selectors-4/#specificity-rules
+
+        Test: imported/w3c/web-platform-tests/css/selectors/has-specificity.html
+
+        * css/CSSSelector.cpp:
+        (WebCore::simpleSelectorSpecificityInternal):
+
+        Compute :has() specificity like :is() and :not().
+
 2022-01-19  Youenn Fablet  <[email protected]>
 
         [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running

Modified: trunk/Source/WebCore/css/CSSSelector.cpp (288195 => 288196)


--- trunk/Source/WebCore/css/CSSSelector.cpp	2022-01-19 13:06:07 UTC (rev 288195)
+++ trunk/Source/WebCore/css/CSSSelector.cpp	2022-01-19 13:43:32 UTC (rev 288196)
@@ -124,6 +124,7 @@
         case CSSSelector::PseudoClassIs:
         case CSSSelector::PseudoClassMatches:
         case CSSSelector::PseudoClassNot:
+        case CSSSelector::PseudoClassHas:
             return maxSpecificity(*simpleSelector.selectorList());
         case CSSSelector::PseudoClassWhere:
             return 0;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to