Bug 998941 - part 1-1: Implement InputEvent.data of UI Events r=smaug

InputEvent.data notifies web apps of inserting/inserted text with "beforeinput"
and "input" events.  So, this is important especially for "beforeinput" event
listeners.  That's the reason why we need to support this before implementing
"beforeinput" event.

This patch adds it into InputEvent and make it enabled by default.

Differential Revision: https://phabricator.services.mozilla.com/D19285

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-02-19 06:27:41 +00:00
parent 5851f87196
commit 0f145fc8e5
8 changed files with 29 additions and 22 deletions

View File

@ -27,6 +27,12 @@ InputEvent::InputEvent(EventTarget* aOwner, nsPresContext* aPresContext,
}
}
void InputEvent::GetData(nsAString& aData) {
InternalEditorInputEvent* editorInputEvent = mEvent->AsEditorInputEvent();
MOZ_ASSERT(editorInputEvent);
aData = editorInputEvent->mData;
}
void InputEvent::GetInputType(nsAString& aInputType) {
InternalEditorInputEvent* editorInputEvent = mEvent->AsEditorInputEvent();
MOZ_ASSERT(editorInputEvent);
@ -55,6 +61,7 @@ already_AddRefed<InputEvent> InputEvent::Constructor(
if (internalEvent->mInputType == EditorInputType::eUnknown) {
e->mInputTypeValue = aParam.mInputType;
}
internalEvent->mData = aParam.mData;
internalEvent->mIsComposing = aParam.mIsComposing;
e->SetTrusted(trusted);
e->SetComposed(aParam.mComposed);

View File

@ -32,6 +32,7 @@ class InputEvent : public UIEvent {
}
void GetInputType(nsAString& aInputType);
void GetData(nsAString& aData);
bool IsComposing();
protected:

View File

@ -888,19 +888,21 @@ is(e.eventPhase, Event.NONE, "Wrong event phase");
// InputEvent
e = new InputEvent("hello", {data: "something data", inputType: "invalid input type", isComposing: true});
is(e.type, "hello", "InputEvent should set type attribute");
todo_is(e.data, "something data", "InputEvent should have data attribute");
is(e.data, "something data", "InputEvent should have data attribute");
is(e.inputType, "invalid input type", "InputEvent should have inputType attribute");
is(e.isComposing, true, "InputEvent should have isComposing attribute");
e = new InputEvent("hello", {inputType: "insertText"});
e = new InputEvent("hello", {data: "", inputType: "insertText"});
is(e.data, "", "InputEvent.data should be empty string when empty string is specified explicitly");
is(e.inputType, "insertText", "InputEvent.inputType should return valid inputType from EditorInputType enum");
e = new InputEvent("hello", {inputType: "deleteWordBackward"});
e = new InputEvent("hello", {data: "foo", inputType: "deleteWordBackward"});
is(e.data, "foo", "InputEvent.data should be the specified string");
is(e.inputType, "deleteWordBackward", "InputEvent.inputType should return valid inputType from EditorInputType enum");
e = new InputEvent("hello", {inputType: "formatFontName"});
is(e.inputType, "formatFontName", "InputEvent.inputType should return valid inputType from EditorInputType enum");
e = new InputEvent("input", {});
todo_is(e.data, "", "InputEvent.data should be empty string in default");
is(e.data, null, "InputEvent.data should be null in default");
is(e.inputType, "", "InputEvent.inputType should be empty string in default");
is(e.isComposing, false, "InputEvent.isComposing should be false in default");

View File

@ -11,10 +11,19 @@ interface InputEvent : UIEvent
[Pref="dom.inputevent.inputtype.enabled"]
readonly attribute DOMString inputType;
[Pref="dom.inputevent.data.enabled"]
readonly attribute DOMString? data;
};
dictionary InputEventInit : UIEventInit
{
boolean isComposing = false;
DOMString inputType = "";
// NOTE: Currently, default value of `data` attribute is declared as empty
// string by UI Events. However, both Chrome and Safari uses `null`,
// and there is a spec issue about this:
// https://github.com/w3c/uievents/issues/139
// So, we take `null` for compatibility with them.
DOMString? data = null;
};

View File

@ -231,6 +231,9 @@ pref("dom.keyboardevent.keypress.hack.dispatch_non_printable_keys", "");
// check its explanation for the detail.
pref("dom.keyboardevent.keypress.hack.use_legacy_keycode_and_charcode", "");
// Whether InputEvent.data is enabled.
pref("dom.inputevent.data.enabled", true);
// Whether InputEvent.inputType is enabled.
pref("dom.inputevent.inputtype.enabled", true);

View File

@ -1,16 +1,4 @@
[inputevent-constructor.html]
[InputEvent constructor without InputEventInit.]
expected: FAIL
[InputEvent construtor with InputEventInit where data is null]
expected: FAIL
[InputEvent construtor with InputEventInit where data is empty string]
expected: FAIL
[InputEvent construtor with InputEventInit where data is non empty string]
expected: FAIL
[InputEvent construtor with InputEventInit where targetRanges is non empty list]
expected: FAIL

View File

@ -1,6 +0,0 @@
[idlharness.window.html]
[InputEvent interface: attribute data]
expected: FAIL
[InputEvent interface: new InputEvent("event") must inherit property "data" with the proper type]
expected: FAIL

View File

@ -1163,6 +1163,8 @@ class InternalEditorInputEvent : public InternalUIEvent {
return result;
}
nsString mData;
EditorInputType mInputType;
bool mIsComposing;
@ -1171,6 +1173,7 @@ class InternalEditorInputEvent : public InternalUIEvent {
bool aCopyTargets) {
AssignUIEventData(aEvent, aCopyTargets);
mData = aEvent.mData;
mInputType = aEvent.mInputType;
mIsComposing = aEvent.mIsComposing;
}