Bug 970802 - part 3: Implement beforeinput event dispatcher and add onbeforeinput event handler attribute r=smaug

This patch makes `nsContentUtils::DispatchInputEvent()` dispatch `beforeinput`
event too.  And also adds `onbeforeinput` event handler which is really
important for feature detection (although Chrome has not implemented this
attribute yet: https://bugs.chromium.org/p/chromium/issues/detail?id=947408).

However, we don't implement `InputEvent.getTargetRanges()` in this bug and
implementing `beforeinput` event may hit bugs of some web apps.  Therefore,
this patch disables `beforeinput` event by default even in Nightly channel.

Differential Revision: https://phabricator.services.mozilla.com/D58125
This commit is contained in:
Masayuki Nakano
2020-01-14 07:15:45 +00:00
parent d56156d1f8
commit 2275339080
11 changed files with 216 additions and 30 deletions

View File

@@ -2957,12 +2957,15 @@ bool TextControlState::SetValueWithoutTextEditor(
// event with "insertReplacementText" since web apps may want to know
// the user operation which changes editor value with a built-in function
// like autocomplete, password manager, session restore, etc.
// XXX Should we stop dispatching `input` event if the text control
// element has already removed from the DOM tree by a `beforeinput`
// event listener?
if (aHandlingSetValue.GetSetValueFlags() & eSetValue_BySetUserInput) {
MOZ_ASSERT(aHandlingSetValue.GetTextControlElement());
MOZ_ASSERT(!aHandlingSetValue.GetSettingValue().IsVoid());
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(
MOZ_KnownLive(aHandlingSetValue.GetTextControlElement()),
EditorInputType::eInsertReplacementText, nullptr,
eEditorInput, EditorInputType::eInsertReplacementText, nullptr,
nsContentUtils::InputEventOptions(
aHandlingSetValue.GetSettingValue()));
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),