8000 HTMLInputElement::setValueForUser should dispatch an input event · WebKit/WebKit@fd13c50 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd13c50

Browse files
mcatanzaroJonWBedard
authored andcommitted
HTMLInputElement::setValueForUser should dispatch an input event
https://bugs.webkit.org/show_bug.cgi?id=226023 rdar://78571564 Reviewed by Aditya Keerthi. HTMLInputElement::setValueForUser is used to autofill form elements. It differs from setting the form value normally because it creates a change event to trick websites into detecting user input. However, this is not enough for some websites that only look for input events and not change events to decide whether the user modified the form. On such websites, the user has to enter an extra character and then delete it as a workaround. This fixes password autofill on https://my.cigna.com and https://myaccount.spireenergy.com in Epiphany. * LayoutTests/fast/events/onchange-js-expected.txt: * LayoutTests/fast/events/onchange-js.html: Add test to ensure change event is not sent until blur, since I've removed that from the onchange-setvalueforuser.html test. * LayoutTests/fast/forms/onchange-setvalueforuser.html: Change this test to not complain about the change event being sent before focus out. * Source/WebCore/html/HTMLInputElement.h: (WebCore::HTMLInputElement::setValueForUser): Fix the bug. * Source/WebCore/html/SearchInputType.cpp: (WebCore::SearchInputType::handleKeydownEvent): This seems to be using setValueForUser by mistake. Call setValue directly instead to avoid breaking fast/forms/search-cancel-button-events.html. * Source/WebCore/html/shadow/TextControlInnerElements.cpp: (WebCore::SearchFieldCancelButtonElement::defaultEventHandler): Ditto. Canonical link: https://commits.webkit.org/259434@main
1 parent 2d1b53b commit fd13c50

File tree

6 files changed

+7
-14
lines changed

6 files changed

+7
-14
lines changed

LayoutTests/fast/events/onchange-js-expected.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
44

55

66
PASS input.value is "foo bar baz"
7+
PASS changeEventCounter is 0
78
PASS changeEventCounter is 1
89
PASS input.value is ""
910
PASS input.value is "foo bar baz"
11+
PASS changeEventCounter is 1
1012
PASS changeEventCounter is 2
1113
PASS successfullyParsed is true
1214

LayoutTests/fast/events/onchange-js.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
input.focus();
1818
document.execCommand('InsertText', false, 'foo bar baz');
1919
shouldBeEqualToString('input.value', 'foo bar baz');
20+
shouldBe('changeEventCounter', '0');
2021
input.blur();
2122
shouldBe('changeEventCounter', '1');
2223
shouldBeEqualToString('input.value', '');
2324
input.focus();
2425
document.execCommand('InsertText', false, 'foo bar baz');
2526
shouldBeEqualToString('input.value', 'foo bar baz');
27+
shouldBe('changeEventCounter', '1');
2628
input.blur();
2729
shouldBe('changeEventCounter', '2');
2830
</script>

LayoutTests/fast/forms/onchange-setvalueforuser.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,9 @@
1212

1313
if (window.testRunner) {
1414
testRunner.dumpAsText();
15-
}
16-
17-
tf.focus();
18-
if (window.testRunner) {
1915
testRunner.setValueForUser(tf, 'Hello!');
2016
}
2117

22-
// Should not fire the event until focus is lost.
23-
if (didFireOnChange) {
24-
testFailed('onchange fired too early');
25-
return;
26-
}
27-
28-
tf.blur();
2918
if (didFireOnChange) {
3019
testPassed('');
3120
} else {

Source/WebCore/html/HTMLInputElement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class HTMLInputElement : public HTMLTextFormControlElement {
8383
WEBCORE_EXPORT void setType(const AtomString&);
8484
WEBCORE_EXPORT String value() const final;
8585
WEBCORE_EXPORT ExceptionOr<void> setValue(const String&, TextFieldEventBehavior = DispatchNoEvent, TextControlSetValueSelection = TextControlSetValueSelection::SetSelectionToEnd) final;
86-
void setValueForUser(const String& value) { setValue(value, DispatchChangeEvent); }
86+
void setValueForUser(const String& value) { setValue(value, DispatchInputAndChangeEvent); }
8787
WEBCORE_EXPORT WallTime valueAsDate() const;
8888
WEBCORE_EXPORT ExceptionOr<void> setValueAsDate(WallTime);
8989
WEBCORE_EXPORT double valueAsNumber() const;

Source/WebCore/html/SearchInputType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ auto SearchInputType::handleKeydownEvent(KeyboardEvent& event) -> ShouldCallBase
146146
const String& key = event.keyIdentifier();
147147
if (key == "U+001B"_s) {
148148
Ref<HTMLInputElement> protectedInputElement(*element());
149-
protectedInputElement->setValueForUser(emptyString());
149+
protectedInputElement->setValue(emptyString(), DispatchChangeEvent);
150150
protectedInputElement->onSearch();
151151
event.setDefaultHandled();
152152
return ShouldCallBaseEventHandler::Yes;

Source/WebCore/html/shadow/TextControlInnerElements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void SearchFieldCancelButtonElement::defaultEventHandler(Event& event)
353353
}
354354

355355
if (event.type() == eventNames().clickEvent) {
356-
input->setValueForUser(emptyString());
356+
input->setValue(emptyString(), DispatchChangeEvent);
357357
input->onSearch();
358358
event.setDefaultHandled();
359359
}

0 commit comments

Comments
 (0)
0