Title: [287363] trunk
Revision
287363
Author
[email protected]
Date
2021-12-22 10:35:41 -0800 (Wed, 22 Dec 2021)

Log Message

[:has() pseudo-class] :has() selector invalidation issue with toggling :checked
https://bugs.webkit.org/show_bug.cgi?id=234561

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

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

Source/WebCore:

Test: imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html

Pseudo-classes need to use Style::PseudoClassChangeInvalidation to support invalidation as :has() argument.
This patch adds it for :checked.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseAttribute):
(WebCore::HTMLInputElement::setChecked):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::HTMLOptionElement):
(WebCore::HTMLOptionElement::matchesDefaultPseudoClass const):

Use a member for :default instead of attribute test so we can do invalidation over changing it in parseAttribute.

(WebCore::HTMLOptionElement::parseAttribute):
(WebCore::HTMLOptionElement::setSelectedState):
* html/HTMLOptionElement.h:

LayoutTests:

Results here change because we do more accurate invalidation.

* fast/css/indirect-adjacent-style-invalidation-1-expected.txt:
* fast/css/indirect-adjacent-style-invalidation-1.html:
* fast/css/indirect-adjacent-style-invalidation-2-expected.txt:
* fast/css/indirect-adjacent-style-invalidation-2.html:
* fast/css/indirect-adjacent-style-invalidation-3-expected.txt:
* fast/css/indirect-adjacent-style-invalidation-3.html:
* fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation-expected.txt:
* fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation.html:

Stop testing invalidation state for the element where :checked state changed. That is not
really the point of these tests anyway.
With accurate invalidation the result depends on plaform (iOS has :checked in UA sheet
while other platforms don't)

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287362 => 287363)


--- trunk/LayoutTests/ChangeLog	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/ChangeLog	2021-12-22 18:35:41 UTC (rev 287363)
@@ -1,5 +1,28 @@
 2021-12-22  Antti Koivisto  <[email protected]>
 
+        [:has() pseudo-class] :has() selector invalidation issue with toggling :checked
+        https://bugs.webkit.org/show_bug.cgi?id=234561
+
+        Reviewed by Simon Fraser.
+
+        Results here change because we do more accurate invalidation.
+
+        * fast/css/indirect-adjacent-style-invalidation-1-expected.txt:
+        * fast/css/indirect-adjacent-style-invalidation-1.html:
+        * fast/css/indirect-adjacent-style-invalidation-2-expected.txt:
+        * fast/css/indirect-adjacent-style-invalidation-2.html:
+        * fast/css/indirect-adjacent-style-invalidation-3-expected.txt:
+        * fast/css/indirect-adjacent-style-invalidation-3.html:
+        * fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation-expected.txt:
+        * fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation.html:
+
+        Stop testing invalidation state for the element where :checked state changed. That is not
+        really the point of these tests anyway.
+        With accurate invalidation the result depends on plaform (iOS has :checked in UA sheet
+        while other platforms don't)
+
+2021-12-22  Antti Koivisto  <[email protected]>
+
         [:has() pseudo-class] :has() selector does not render on first pass?
         https://bugs.webkit.org/show_bug.cgi?id=234531
 

Modified: trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-1-expected.txt (287362 => 287363)


--- trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-1-expected.txt	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-1-expected.txt	2021-12-22 18:35:41 UTC (rev 287363)
@@ -3,30 +3,20 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 0, 0)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 0, 0)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is true
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is true
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 1, 2)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 1, 2)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is true
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is true
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 0, 0)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 0, 0)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-1.html (287362 => 287363)


--- trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-1.html	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-1.html	2021-12-22 18:35:41 UTC (rev 287363)
@@ -47,8 +47,6 @@
 
 function shouldNeedStyleRecalc(expected) {
     var testFunction = expected ? shouldBeTrue : shouldBeFalse;
-    testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\".activator\")[0])");
-    testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\".activator\")[1])");
     testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\"target\")[0])");
     testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\"target\")[1])");
 }

Modified: trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-2-expected.txt (287362 => 287363)


--- trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-2-expected.txt	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-2-expected.txt	2021-12-22 18:35:41 UTC (rev 287363)
@@ -3,30 +3,20 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 0, 0)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 0, 0)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is true
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is true
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 1, 2)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 1, 2)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is true
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is true
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 0, 0)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 0, 0)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-2.html (287362 => 287363)


--- trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-2.html	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-2.html	2021-12-22 18:35:41 UTC (rev 287363)
@@ -47,8 +47,6 @@
 
 function shouldNeedStyleRecalc(expected) {
     var testFunction = expected ? shouldBeTrue : shouldBeFalse;
-    testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\".activator\")[0])");
-    testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\".activator\")[1])");
     testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\"target\")[0])");
     testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\"target\")[1])");
 }

Modified: trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-3-expected.txt (287362 => 287363)


--- trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-3-expected.txt	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-3-expected.txt	2021-12-22 18:35:41 UTC (rev 287363)
@@ -3,30 +3,20 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 0, 0)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 0, 0)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is true
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is true
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 1, 2)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 1, 2)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is true
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is true
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is true
 PASS getComputedStyle(document.querySelectorAll("target")[0]).color is "rgb(0, 0, 0)"
 PASS getComputedStyle(document.querySelectorAll("target")[1]).color is "rgb(0, 0, 0)"
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[0]) is false
-PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(".activator")[1]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[0]) is false
 PASS window.internals.nodeNeedsStyleRecalc(document.querySelectorAll("target")[1]) is false
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-3.html (287362 => 287363)


--- trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-3.html	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/indirect-adjacent-style-invalidation-3.html	2021-12-22 18:35:41 UTC (rev 287363)
@@ -6,7 +6,7 @@
 * {
     color: black;
 }
-:checked:matches(*, :last-of-type, *) ~ target {
+:checked:is(*, :last-of-type, *) ~ target {
     color: rgb(0, 1, 2);
 }
 </style>
@@ -47,8 +47,6 @@
 
 function shouldNeedStyleRecalc(expected) {
     var testFunction = expected ? shouldBeTrue : shouldBeFalse;
-    testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\".activator\")[0])");
-    testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\".activator\")[1])");
     testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\"target\")[0])");
     testFunction("window.internals.nodeNeedsStyleRecalc(document.querySelectorAll(\"target\")[1])");
 }

Modified: trunk/LayoutTests/fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation-expected.txt (287362 => 287363)


--- trunk/LayoutTests/fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation-expected.txt	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation-expected.txt	2021-12-22 18:35:41 UTC (rev 287363)
@@ -15,11 +15,9 @@
 PASS elementsWithIndeterminateStyle() is []
 PASS checkedElements() is ["radio3", "radio8"]
 Check radio4
-PASS elementsNeedingStyleRecalc() is ["radio3", "radio4"]
 PASS elementsWithIndeterminateStyle() is []
 PASS checkedElements() is ["radio4", "radio8"]
 Check radio9
-PASS elementsNeedingStyleRecalc() is ["radio8", "radio9"]
 PASS elementsWithIndeterminateStyle() is []
 PASS checkedElements() is ["radio4", "radio9"]
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation.html (287362 => 287363)


--- trunk/LayoutTests/fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation.html	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/fast/css/pseudo-indeterminate-with-radio-buttons-style-invalidation.html	2021-12-22 18:35:41 UTC (rev 287363)
@@ -85,17 +85,15 @@
 shouldBe("elementsWithIndeterminateStyle()", '[]');
 shouldBe("checkedElements()", '["radio3", "radio8"]');
 
-// Checking radio4, we should not need to invalidate anything but the two modified elements.
+// Checking radio4, we should not need to invalidate anything.
 debug("Check radio4");
 document.getElementById("radio4").checked = true;
-shouldBe("elementsNeedingStyleRecalc()", '["radio3", "radio4"]');
 shouldBe("elementsWithIndeterminateStyle()", '[]');
 shouldBe("checkedElements()", '["radio4", "radio8"]');
 
-// Checking radio9, we should not need to invalidate anything but the two modified elements.
+// Checking radio9, we should not need to invalidate anything.
 debug("Check radio9");
 document.getElementById("radio9").checked = true;
-shouldBe("elementsNeedingStyleRecalc()", '["radio8", "radio9"]');
 shouldBe("elementsWithIndeterminateStyle()", '[]');
 shouldBe("checkedElements()", '["radio4", "radio9"]');
 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (287362 => 287363)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-22 18:35:41 UTC (rev 287363)
@@ -1,3 +1,13 @@
+2021-12-22  Antti Koivisto  <[email protected]>
+
+        [:has() pseudo-class] :has() selector invalidation issue with toggling :checked
+        https://bugs.webkit.org/show_bug.cgi?id=234561
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/selectors/invalidation/has-pseudo-class-expected.txt: Added.
+        * web-platform-tests/css/selectors/invalidation/has-pseudo-class.html: Added.
+
 2021-12-22  Tim Nguyen  <[email protected]>
 
         Internally unprefix -webkit-text-emphasis properties

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class-expected.txt (0 => 287363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class-expected.txt	2021-12-22 18:35:41 UTC (rev 287363)
@@ -0,0 +1,8 @@
+
+
+PASS Initial color
+PASS Set checked on checkbox
+PASS Unset checked on checkbox
+PASS Set selected on option
+PASS Unset selected on option
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html (0 => 287363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html	2021-12-22 18:35:41 UTC (rev 287363)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Selector Invalidation: :has() with pseudo-classes</title>
+<link rel="author" title="Antti Koivisto" href=""
+<script src=""
+<script src=""
+<link rel="help" href=""
+<style>
+div, main { color: grey }
+main:has(#checkbox:checked) > #subject { color: red }
+main:has(#option:checked) > #subject { color: green }
+</style>
+
+<main id=main>
+    <input type=checkbox id=checkbox></input>
+    <select><option>a</option><option id=option>b</option></select>
+    <div id=subject></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)';
+const yellow = 'rgb(255, 255, 0)';
+const purple = 'rgb(128, 0, 128)';
+const pink = 'rgb(255, 192, 203)';
+
+function testColor(test_name, color) {
+    test(function() {
+        assert_equals(getComputedStyle(subject).color, color);
+    }, test_name);
+}
+
+function testPseudoClassChange(element, property, expectedColor)
+{
+    element[property] = true;
+    testColor(`Set ${property} on ${element.id}`, expectedColor);
+    element[property] = false;
+    testColor(`Unset ${property} on ${element.id}`, grey);
+}
+
+testColor('Initial color', grey);
+
+testPseudoClassChange(checkbox, "checked", red);
+testPseudoClassChange(option, "selected", green);
+</script>

Modified: trunk/Source/WebCore/ChangeLog (287362 => 287363)


--- trunk/Source/WebCore/ChangeLog	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/Source/WebCore/ChangeLog	2021-12-22 18:35:41 UTC (rev 287363)
@@ -1,5 +1,30 @@
 2021-12-22  Antti Koivisto  <[email protected]>
 
+        [:has() pseudo-class] :has() selector invalidation issue with toggling :checked
+        https://bugs.webkit.org/show_bug.cgi?id=234561
+
+        Reviewed by Simon Fraser.
+
+        Test: imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html
+
+        Pseudo-classes need to use Style::PseudoClassChangeInvalidation to support invalidation as :has() argument.
+        This patch adds it for :checked.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::parseAttribute):
+        (WebCore::HTMLInputElement::setChecked):
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::HTMLOptionElement):
+        (WebCore::HTMLOptionElement::matchesDefaultPseudoClass const):
+
+        Use a member for :default instead of attribute test so we can do invalidation over changing it in parseAttribute.
+
+        (WebCore::HTMLOptionElement::parseAttribute):
+        (WebCore::HTMLOptionElement::setSelectedState):
+        * html/HTMLOptionElement.h:
+
+2021-12-22  Antti Koivisto  <[email protected]>
+
         [:has() pseudo-class] :has() selector does not render on first pass?
         https://bugs.webkit.org/show_bug.cgi?id=234531
 

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (287362 => 287363)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-12-22 18:35:41 UTC (rev 287363)
@@ -60,6 +60,7 @@
 #include "NodeRenderStyle.h"
 #include "Page.h"
 #include "PlatformMouseEvent.h"
+#include "PseudoClassChangeInvalidation.h"
 #include "RenderTextControlSingleLine.h"
 #include "RenderTheme.h"
 #include "ScopedEventQueue.h"
@@ -797,7 +798,6 @@
     } else if (name == checkedAttr) {
         if (m_inputType->isCheckable())
             invalidateStyleForSubtree();
-
         // Another radio button in the same group might be checked by state
         // restore. We shouldn't call setChecked() even if this has the checked
         // attribute. So, delay the setChecked() call until
@@ -982,9 +982,10 @@
 
     m_inputType->willUpdateCheckedness(nowChecked);
 
+    Style::PseudoClassChangeInvalidation checkedInvalidation(*this, CSSSelector::PseudoClassChecked);
+
     m_dirtyCheckednessFlag = true;
     m_isChecked = nowChecked;
-    invalidateStyleForSubtree();
 
     if (RadioButtonGroups* buttons = radioButtonGroups())
         buttons->updateCheckedState(*this);
@@ -999,8 +1000,6 @@
         if (AXObjectCache* cache = renderer()->document().existingAXObjectCache())
             cache->checkedStateChanged(this);
     }
-
-    invalidateStyleForSubtree();
 }
 
 void HTMLInputElement::setIndeterminate(bool newValue)

Modified: trunk/Source/WebCore/html/HTMLOptionElement.cpp (287362 => 287363)


--- trunk/Source/WebCore/html/HTMLOptionElement.cpp	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/Source/WebCore/html/HTMLOptionElement.cpp	2021-12-22 18:35:41 UTC (rev 287363)
@@ -38,6 +38,7 @@
 #include "HTMLSelectElement.h"
 #include "NodeRenderStyle.h"
 #include "NodeTraversal.h"
+#include "PseudoClassChangeInvalidation.h"
 #include "RenderMenuList.h"
 #include "RenderTheme.h"
 #include "ScriptElement.h"
@@ -54,8 +55,6 @@
 
 HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document& document)
     : HTMLElement(tagName, document)
-    , m_disabled(false)
-    , m_isSelected(false)
 {
     ASSERT(hasTagName(optionTag));
     setHasCustomStyleResolveCallbacks();
@@ -101,7 +100,7 @@
 
 bool HTMLOptionElement::matchesDefaultPseudoClass() const
 {
-    return hasAttributeWithoutSynchronization(selectedAttr);
+    return m_isDefault;
 }
 
 String HTMLOptionElement::text() const
@@ -185,15 +184,15 @@
                 renderer()->theme().stateChanged(*renderer(), ControlStates::States::Enabled);
         }
     } else if (name == selectedAttr) {
-        invalidateStyleForSubtree();
+        // FIXME: Use PseudoClassChangeInvalidation in other elements that implement matchesDefaultPseudoClass().
+        Style::PseudoClassChangeInvalidation defaultInvalidation(*this, CSSSelector::PseudoClassDefault);
+        m_isDefault = !value.isNull();
 
         // FIXME: This doesn't match what the HTML specification says.
         // The specification implies that removing the selected attribute or
         // changing the value of a selected attribute that is already present
-        // has no effect on whether the element is selected. Further, it seems
-        // that we need to do more than just set m_isSelected to select in that
-        // case; we'd need to do the other work from the setSelected function.
-        m_isSelected = !value.isNull();
+        // has no effect on whether the element is selected.
+        setSelectedState(!value.isNull());
     } else
         HTMLElement::parseAttribute(name, value);
 }
@@ -234,8 +233,9 @@
     if (m_isSelected == selected)
         return;
 
+    Style::PseudoClassChangeInvalidation checkedInvalidation(*this, CSSSelector::PseudoClassChecked);
+
     m_isSelected = selected;
-    invalidateStyleForSubtree();
 
 #if ENABLE(ACCESSIBILITY) && USE(ATSPI)
     if (auto* cache = document().existingAXObjectCache())

Modified: trunk/Source/WebCore/html/HTMLOptionElement.h (287362 => 287363)


--- trunk/Source/WebCore/html/HTMLOptionElement.h	2021-12-22 18:33:49 UTC (rev 287362)
+++ trunk/Source/WebCore/html/HTMLOptionElement.h	2021-12-22 18:35:41 UTC (rev 287363)
@@ -80,8 +80,9 @@
 
     String collectOptionInnerText() const;
 
-    bool m_disabled;
-    bool m_isSelected;
+    bool m_disabled { false };
+    bool m_isSelected { false };
+    bool m_isDefault { false };
 };
 
 } // namespace
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to