Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify the textInput event #362

Merged
merged 13 commits into from
Feb 21, 2024
Merged

Specify the textInput event #362

merged 13 commits into from
Feb 21, 2024

Conversation

zcorpan
Copy link
Member

@zcorpan zcorpan commented Nov 24, 2023

Fixes #353

The following tasks have been completed:

Implementation commitment:

@zcorpan
Copy link
Member Author

zcorpan commented Dec 5, 2023

I think fixing #361 first would be nice so that this event can slot in between beforeinput and input in the default action chain.

@zcorpan zcorpan marked this pull request as ready for review January 11, 2024 23:17
@zcorpan
Copy link
Member Author

zcorpan commented Jan 11, 2024

I've moved the spec for this into event-algo.bs, since trying to make it well-defined in the current spec was ... challenging.

I think this is ready for review.

event-algo.bs Show resolved Hide resolved
event-algo.bs Show resolved Hide resolved
event-algo.bs Show resolved Hide resolved
@masayuki-nakano
Copy link

And I've not tested when replacing typo word with the spellchecker.

@masayuki-nakano
Copy link

WPt is required at least for:

  • no constructor
  • initTextEvent
  • Document.createEvent and instance of TextEditor and instance of UIEvent with the result.
  • addEventListener with textInput and textinput
  • With typing a character (an ASCII character and a non-BMP character)
  • With deleting a character around caret (no textInput)
  • With deleting a character with non-collapsed selection (no textInput)
  • With execCommand("insertText", false, "something") (no textInput)

@masayuki-nakano
Copy link

Oh? There is no ontextinput nor ontextInput attribute in the global event handler? Chrome does not run the script set to it and there is no property when I check an element with the devtools.

@masayuki-nakano
Copy link

Hmm, in <input>, Chrome fires beforeinput event but no textInput event when I press Enter...

@masayuki-nakano
Copy link

When I replace a misspell word on Chrome, Chrome does not fire textInput after beforeinput.

@masayuki-nakano
Copy link

I wonder, whether textInput should be fired after a beforeinput event listener makes the editing host blurred.

event-algo.bs Outdated Show resolved Hide resolved
@masayuki-nakano
Copy link

If I call preventDefault of textInput at DnD in same editing host, the deletion is also canceled on Chrome. It's impossible to emulate that on Firefox without adding a lot of hacky code...

And also a call of preventDefault for IME composition cannot cancel the default action but its cancelable is set to true on Chrome.

@masayuki-nakano
Copy link

I wonder, how about insertFromYank? I don't know whether Chrome and/or Safari support it and how to do that.

@zcorpan
Copy link
Member Author

zcorpan commented Feb 2, 2024

I wonder, whether textInput should be fired after a beforeinput event listener makes the editing host blurred.

Interestingly, Chrome and Safari seem to prevent moving focus while handling beforeinput: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/12339

(Opening a popup works, but still fires the textInput event.)

@zcorpan
Copy link
Member Author

zcorpan commented Feb 2, 2024

I wonder, how about insertFromYank? I don't know whether Chrome and/or Safari support it and how to do that.

I didn't know it was a thing, but I see it in https://w3c.github.io/input-events/ (issue: w3c/input-events#20 ).

Per https://www.howtogeek.com/293850/how-to-use-macos-built-in-kill-and-yank-as-an-alternative-cut-and-paste/ on macOS you can use ctrl+k to kill (cut) and ctrl+y to yank (paste).

Testing in http://software.hixie.ch/utilities/js/live-dom-viewer/saved/12340 , neither Safari or Chrome fire textInput when yanking.

@zcorpan
Copy link
Member Author

zcorpan commented Feb 2, 2024

Hmm, in <input>, Chrome fires beforeinput event but no textInput event when I press Enter...

Should I check if the event target is an HTMLInputElement element in the spec?

@masayuki-nakano
Copy link

Hmm, in <input>, Chrome fires beforeinput event but no textInput event when I press Enter...

Should I check if the event target is an HTMLInputElement element in the spec?

Yeah, I think so. (Thank you for investigating about yanking!)

zcorpan added a commit to whatwg/dom that referenced this pull request Feb 8, 2024
zcorpan added a commit to web-platform-tests/wpt that referenced this pull request Feb 8, 2024
zcorpan added a commit to web-platform-tests/wpt that referenced this pull request Feb 8, 2024
@zcorpan
Copy link
Member Author

zcorpan commented Feb 8, 2024

WPt is required at least for:

* no constructor

* `initTextEvent`

* `Document.createEvent` and `instance of TextEditor` and `instance of UIEvent` with the result.

* `addEventListener` with `textInput` and `textinput`

* With typing a character (an ASCII character and a non-BMP character)

* With deleting a character around caret (no `textInput`)

* With deleting a character with non-collapsed selection (no `textInput`)

* With `execCommand("insertText", false, "something")` (no `textInput`)

Thanks, tested in web-platform-tests/wpt#44472

I used a smiley for non-BMP character, but I think it's not automatable with WebDriver currently.

@zcorpan
Copy link
Member Author

zcorpan commented Feb 8, 2024

Should I check if the event target is an HTMLInputElement element in the spec?

Done in 7b9b6a5

webkit-commit-queue pushed a commit to sideshowbarker/WebKit that referenced this pull request May 19, 2024
https://bugs.webkit.org/show_bug.cgi?id=268988

Reviewed by Wenson Hsieh and Ryosuke Niwa.

This change makes WebKit fire the beforeinput & textInput events in the
order (beforeinput first, textInput after) conforming to UI Events spec
requirements at w3c/uievents#362 and in the spec at
https://w3c.github.io/uievents/event-algo.html#fire%20key%20input%20events
and consistent with the order in which the events are fired in Blink.

Otherwise, without this change, WebKit fires the events in an order
(textInput first, beforeinput after) that breaks conformance with
the spec requirements, and that breaks compatibility with Blink.

Note also that this change makes WebKit conform to the requirements in
https://w3c.github.io/uievents/event-algo.html#fire%20key%20input%20events,
https://w3c.github.io/uievents/event-algo.html#handle%20native%20paste, and
https://w3c.github.io/uievents/event-algo.html#end%20composition — limiting
textInput to being fired only when ending a composition or when the input
type is insertText, insertParagraph, insertLineBreak, or insertFromPaste.

* LayoutTests/editing/execCommand/break-out-of-empty-list-item.html:
* LayoutTests/editing/inserting/typing-space-to-trigger-smart-link.html:
* LayoutTests/editing/pasteboard/paste-text-events-expected.txt:
* LayoutTests/editing/pasteboard/paste-text-events.html:
* LayoutTests/editing/style/highlight-insert-paragraph.html:
* LayoutTests/fast/events/input-events-fired-when-typing-expected.txt:
* LayoutTests/fast/events/input-events-fired-when-typing.html:
* LayoutTests/fast/events/ios/submit-form-target-blank-using-return-key.html:
* LayoutTests/fast/events/onchange-passwordfield.html:
* LayoutTests/fast/events/onchange-searchfield.html:
* LayoutTests/fast/events/onchange-textfield.html:
* LayoutTests/fast/forms/onchange-change-type.html:
* LayoutTests/http/tests/navigation/keyboard-events-during-provisional-navigation-expected.txt:
* LayoutTests/http/tests/navigation/keyboard-events-during-provisional-subframe-navigation-expected.txt:
* LayoutTests/platform/mac-wk2/http/tests/navigation/keyboard-events-during-provisional-navigation-expected.txt:
* LayoutTests/platform/wpe/TestExpectations:
* Source/WebCore/dom/Node.cpp:
(WebCore::Node::defaultEventHandler):
* Source/WebCore/dom/TextEvent.cpp:
(WebCore::TextEvent::TextEvent):
(WebCore::TextEvent::initTextEvent):
(WebCore::TextEvent::createForPlainTextPaste): Deleted.
(WebCore::TextEvent::createForFragmentPaste): Deleted.
(WebCore::TextEvent::createForDictation): Deleted.
* Source/WebCore/dom/TextEvent.h:
* Source/WebCore/editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::insertDictatedText):
* Source/WebCore/editing/Editor.cpp:
(WebCore::dispatchTextInputEvent):
(WebCore::Editor::selectionForCommand):
(WebCore::Editor::pasteAsPlainText):
(WebCore::Editor::pasteAsFragment):
(WebCore::dispatchTextInputEvents):
(WebCore::Editor::appliedEditing):
(WebCore::Editor::insertText):
(WebCore::Editor::insertTextForConfirmedComposition):
(WebCore::Editor::insertTextWithoutSendingTextEvent):
(WebCore::Editor::setComposition):
(WebCore::Editor::handleTextEvent): Deleted.
* Source/WebCore/editing/Editor.h:
* Source/WebCore/editing/EditorCommand.cpp:
(WebCore::executeInsertBacktab):
(WebCore::executeInsertLineBreak):
(WebCore::executeInsertNewline):
(WebCore::executeInsertTab):
(WebCore::executeYank):
(WebCore::executeYankAndSelect):
(WebCore::enabledVisibleSelection):
(WebCore::enabledVisibleSelectionAndMark):
(WebCore::enableCaretInEditableText):
(WebCore::enabledInEditableText):
* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::handleTextInput):
(WebCore::EventHandler::handleTextInputEvent): Deleted.
(WebCore::EventHandler::defaultTextInputEventHandler): Deleted.
* Source/WebCore/page/EventHandler.h:

Canonical link: https://commits.webkit.org/278971@main
sideshowbarker added a commit to sideshowbarker/WebKit that referenced this pull request May 28, 2024
https://bugs.webkit.org/show_bug.cgi?id=268988

Reviewed by NOBODY (OOPS!).

This change (controlled by the ConformantBeforeinputEventFiringOrderEnabled,
preference, also introduced in this change) makes WebKit fire the beforeinput
and textInput events in the order: beforeinput first, textInput after —
conforming to the requirements at w3c/uievents#362 and
https://w3c.github.io/uievents/event-algo.html#fire%20key%20input%20events
and consistent with the order in which the events are fired in Blink.

Otherwise, without this change, WebKit fires the events in the order:
textInput first, beforeinput after — which breaks conformance with the
spec requirements, and breaks compatibility with Blink.

Note also that this change makes WebKit conform to the requirements in
https://w3c.github.io/uievents/event-algo.html#fire%20key%20input%20events,
https://w3c.github.io/uievents/event-algo.html#handle%20native%20paste, and
https://w3c.github.io/uievents/event-algo.html#end%20composition — limiting
textInput to being fired only when ending a composition or when the input
type is insertText, insertParagraph, insertLineBreak, or insertFromPaste.

* LayoutTests/editing/execCommand/break-out-of-empty-list-item.html:
* LayoutTests/editing/inserting/typing-space-to-trigger-smart-link.html:
* LayoutTests/editing/pasteboard/paste-text-events-expected.txt:
* LayoutTests/editing/pasteboard/paste-text-events.html:
* LayoutTests/editing/style/highlight-insert-paragraph.html:
* LayoutTests/fast/events/input-events-fired-when-typing-expected.txt:
* LayoutTests/fast/events/input-events-fired-when-typing-nonconforming-expected.txt: Copied from LayoutTests/fast/events/input-events-fired-when-typing-expected.txt.
* LayoutTests/fast/events/input-events-fired-when-typing-nonconforming.html: Copied from LayoutTests/fast/events/input-events-fired-when-typing.html.
* LayoutTests/fast/events/input-events-fired-when-typing.html:
* LayoutTests/fast/events/ios/submit-form-target-blank-using-return-key-old-code-path-expected.txt: Added.
* LayoutTests/fast/events/ios/submit-form-target-blank-using-return-key-old-code-path.html: Added.
* LayoutTests/fast/forms/onchange-change-type.html:
* LayoutTests/http/tests/navigation/keyboard-events-during-provisional-navigation-expected.txt:
* LayoutTests/http/tests/navigation/keyboard-events-during-provisional-subframe-navigation-expected.txt:
* LayoutTests/platform/ios/TestExpectations:
* LayoutTests/platform/mac-wk2/http/tests/navigation/keyboard-events-during-provisional-navigation-expected.txt:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::insertDictatedText):
* Source/WebCore/editing/Editor.cpp:
(WebCore::dispatchTextInputEvent):
(WebCore::Editor::selectionForCommand):
(WebCore::Editor::handleTextEvent):
(WebCore::Editor::pasteAsPlainText):
(WebCore::Editor::pasteAsFragment):
(WebCore::dispatchTextInputEvents):
(WebCore::Editor::appliedEditing):
(WebCore::Editor::insertText):
(WebCore::Editor::insertTextForConfirmedComposition):
(WebCore::Editor::insertTextWithoutSendingTextEventNew):
(WebCore::Editor::insertTextWithoutSendingTextEventOld):
(WebCore::Editor::setComposition):
(WebCore::Editor::insertTextWithoutSendingTextEvent): Deleted.
* Source/WebCore/editing/Editor.h:
* Source/WebCore/editing/EditorCommand.cpp:
(WebCore::executeInsertBacktab):
(WebCore::executeInsertLineBreak):
(WebCore::executeInsertNewline):
(WebCore::executeInsertTab):
(WebCore::executeYank):
(WebCore::executeYankAndSelect):
(WebCore::enabledVisibleSelection):
(WebCore::enabledVisibleSelectionAndMark):
(WebCore::enableCaretInEditableText):
(WebCore::enabledInEditableText):
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::defaultEventHandler):
* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::handleTextInput):
* Source/WebCore/page/EventHandler.h:
vinhill pushed a commit to vinhill/dom that referenced this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify the textInput event
3 participants