Skip to content

Commit 9ed97a1

Browse files
committed
Event dispatching on disabled form controls
https://bugs.webkit.org/show_bug.cgi?id=251246 rdar://104727624 Reviewed by Ryosuke Niwa. Start dispatching events on disabled form controls behind a runtime flag. This patch also makes "click", "mousedown", and "mouseup" events have their event paths never include any disabled form controls or ancestors of disabled form controls. This aligns with what Blink did in: - https://chromium-review.googlesource.com/c/chromium/src/+/3929060 And is being discussed at: - whatwg/html#5886 Also make it so that fieldset elements can no longer be disabled, as per: - https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute This gets us closer to the specification and Chrome & Firefox's behavior. This is part of Interop 2023. All new behavior is behind a runtime feature flag, currently off by default. * LayoutTests/fast/css/pseudo-indeterminate-radio-buttons-basics-expected.html: * LayoutTests/fast/forms/disabled-mousedown-event-expected.txt: * LayoutTests/fast/forms/disabled-mousedown-event.html: * LayoutTests/fast/forms/fieldset/fieldset-disabled-expected.txt: * LayoutTests/fast/forms/fieldset/fieldset-disabled.html: Resync these tests from Blink. * LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-on-disabled-elements.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/disabled-elements/disabled-event-dispatch.tentative-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/disabled-elements/fieldset-event-propagation.tentative-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/selectors/pseudo-classes/disabled.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/selectors/pseudo-classes/enabled.html: Resync these tests from WPT and rebaseline now that more checks are passing. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/disabled-elements/event-propagate-disabled.tentative-expected.txt: Rebaseline now that more checks are passing. Note that some subtests are failing but I believe the test needs updating. These subtests are failing in Blink as well: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/third_party/blink/web_tests/external/wpt/html/semantics/disabled-elements/event-propagate-disabled.tentative.html.ini * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): * Source/WebCore/dom/EventContext.cpp: (WebCore::EventContext::handleLocalEvents const): * Source/WebCore/dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): * Source/WebCore/dom/EventPath.cpp: (WebCore::EventPath::adjustForDisabledFormControl): * Source/WebCore/dom/EventPath.h: * Source/WebCore/html/HTMLFieldSetElement.cpp: (WebCore::HTMLFieldSetElement::isDisabledFormControl const): * Source/WebCore/html/HTMLFieldSetElement.h: * Source/WebCore/html/HTMLFormControlElement.h: Canonical link: https://commits.webkit.org/264098@main
1 parent fe83c2f commit 9ed97a1

22 files changed

Lines changed: 309 additions & 351 deletions

LayoutTests/fast/css/pseudo-indeterminate-radio-buttons-basics-expected.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<input type="radio" name="group12" readonly>
111111
<span><input type="radio" name="group12" checked readonly class="checked"></span>
112112
</form>
113-
<fieldset disabled class="disabled">
113+
<fieldset disabled>
114114
<input type="radio" class="indeterminate disabled">
115115
<input type="radio" class="indeterminate disabled">
116116
<input type="radio" name="group1" class="indeterminate disabled">
@@ -141,7 +141,7 @@
141141
<span><input type="radio" name="group12" checked readonly class="checked disabled"></span>
142142
</fieldset>
143143
<form>
144-
<fieldset disabled class="disabled">
144+
<fieldset disabled>
145145
<input type="radio" class="indeterminate disabled">
146146
<input type="radio" class="indeterminate disabled">
147147
<input type="radio" name="group1" class="indeterminate disabled">
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This test ensures WebKit fires mousedown event on a disabled input element.
21

32

4-
PASS
3+
PASS mousedown events should not be fired on parents of disabled input elements.
4+

LayoutTests/fast/forms/disabled-mousedown-event.html

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<!DOCTYPE html>
2-
<html>
3-
<body>
4-
<p>This test ensures WebKit fires mousedown event on a disabled input element.</p>
2+
<link rel=author href="mailto:jarhar@chromium.org">
3+
<link rel=author href="mailto:rniwa@webkit.org">
4+
<link rel=help href="https://bugs.webkit.org/show_bug.cgi?id=27795">
5+
<link rel=help href="https://github.com/whatwg/html/issues/2368">
6+
<link rel=help href="https://github.com/whatwg/html/issues/5886">
7+
<script src="../../resources/testharness.js"></script>
8+
<script src="../../resources/testharnessreport.js"></script>
9+
510
<span><input id="test" type="text" disabled></span>
6-
<div id="log">FAIL</div>
7-
<script>
811

9-
if (window.testRunner)
10-
testRunner.dumpAsText();
12+
<script>
13+
async function rafPromise() {
14+
return new Promise(resolve => requestAnimationFrame(resolve));
15+
}
1116

1217
function clickOn(element)
1318
{
@@ -18,12 +23,13 @@
1823
eventSender.mouseUp();
1924
}
2025

21-
var test = document.getElementById('test');
22-
test.parentNode.addEventListener('mousedown', function () { document.getElementById('log').textContent = 'PASS'; }, false);
26+
promise_test(async () => {
27+
const test = document.getElementById('test');
28+
test.parentNode.addEventListener('mousedown', () => assert_unreached('mousedown should not be fired.'));
2329

24-
if (window.eventSender)
25-
clickOn(test);
30+
clickOn(test);
2631

32+
await rafPromise();
33+
await rafPromise();
34+
}, 'mousedown events should not be fired on parents of disabled input elements.');
2735
</script>
28-
</body>
29-
</html>
Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,3 @@
1-
Tests for HTMLFieldSetElement.disabled behavior.
21

3-
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4-
5-
6-
7-
Verifying parser generated fieldsets.
8-
PASS parserGeneratedInput1.value is "L"
9-
PASS parserGeneratedInput2.value is "M"
10-
PASS parserGeneratedInput3.value is "NO"
11-
PASS parserGeneratedInput4.value is ""
12-
PASS parserGeneratedInput5.value is "PQRST"
13-
PASS parserGeneratedInput6.value is ""
14-
PASS parserGeneratedInput7.value is ""
15-
PASS parserGeneratedInput8.value is ""
16-
PASS parserGeneratedInput9.value is ""
17-
18-
Testing a single fieldset element.
19-
Verifying HTMLFormControl can be disabled regardless of enclosing fieldset.
20-
PASS textInput.disabled is true
21-
PASS textInput.value is ""
22-
PASS fieldSet.disabled is false
23-
Fieldset is enabled by default. A user can insertText into the text input field.
24-
PASS textInput.value is "A"
25-
Disable fieldset.
26-
PASS fieldSet.disabled is true
27-
Once the fieldset is disabled, text cannot be inserted.
28-
PASS textInput.value is "A"
29-
Check if the style of the text element changed.
30-
PASS getComputedStyle(textInput).backgroundColor is 'rgb(255, 0, 0)'
31-
Enable fieldset.
32-
PASS fieldSet.disabled is false
33-
PASS getComputedStyle(textInput).backgroundColor is 'rgb(255, 255, 100)'
34-
PASS textInput.value is "AB"
35-
Move the textinput element out of the fieldset.
36-
Disable the fieldset.
37-
PASS fieldSet.disabled is true
38-
Text can be inserted, because the textinput element is outside of the disabled fieldset.
39-
PASS textInput.value is "ABC"
40-
Enable the fieldset.
41-
PASS fieldSet.disabled is false
42-
Insert a table into the fieldset.
43-
Move the textinput field into the table.
44-
PASS textInput.value is "ABCD"
45-
Disable the fieldset.
46-
PASS fieldSet.disabled is true
47-
Inserting text should fail.
48-
PASS textInput.value is "ABCD"
49-
Enable the fieldset.
50-
PASS fieldSet.disabled is false
51-
PASS textInput.value is "ABCDE"
52-
53-
Testing nested fieldset elements.
54-
Verifying that subordinates of both fieldsets are enabled.
55-
PASS outerTextInput.value is "F"
56-
PASS innerTextInput.value is "F"
57-
Disabling the inner fieldset only.
58-
PASS innerFieldSet.disabled is true
59-
PASS outerTextInput.value is "FGG"
60-
PASS innerTextInput.value is "F"
61-
Enabling the inner and disabling the outer fieldset.
62-
PASS outerFieldSet.disabled is true
63-
PASS innerFieldSet.disabled is false
64-
PASS outerTextInput.value is "FGG"
65-
PASS innerTextInput.value is "F"
66-
Disabling both fieldset elements.
67-
PASS outerFieldSet.disabled is true
68-
PASS innerFieldSet.disabled is true
69-
PASS outerTextInput.value is "FGG"
70-
PASS innerTextInput.value is "F"
71-
Enabling both fieldset elements.
72-
PASS outerFieldSet.disabled is false
73-
PASS innerFieldSet.disabled is false
74-
PASS outerTextInput.value is "FGGH"
75-
PASS innerTextInput.value is "FH"
76-
77-
Test behavior of the first legend element in a fieldset elements.
78-
Children of the first legend element in a fieldset should not get disabled with the fieldset.
79-
PASS legendFieldSet.disabled is true
80-
PASS firstLegendTextInput.value is "II"
81-
PASS secondLegendTextInput.value is ""
82-
Insert another legend element before the currently first one, and check again.
83-
PASS insertedLegendTextInput.value is "JJJ"
84-
PASS firstLegendTextInput.value is "II"
85-
PASS secondLegendTextInput.value is ""
86-
Enable the fieldset again and check for sanity.
87-
PASS legendFieldSet.disabled is false
88-
PASS insertedLegendTextInput.value is "JJJK"
89-
PASS firstLegendTextInput.value is "IIK"
90-
PASS secondLegendTextInput.value is "K"
91-
PASS disabledFieldsetWithTabindex.focus(); document.activeElement is document.body
92-
PASS successfullyParsed is true
93-
94-
TEST COMPLETE
2+
PASS Tests for HTMLFieldSetElement.disabled behavior.
953

0 commit comments

Comments
 (0)