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

textInput event should be supported correctly #1564

Merged
merged 2 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/client/sandbox/event/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,23 @@ export default class EventSimulator {
return null;
}

_dispatchTextEvent (el, text) {
const name = browserUtils.isIE ? 'textinput' : 'textInput';

let event = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specification https://webplatform.github.io/docs/dom/TextEvent/initTextEvent.

Rewrite as

 if (nativeMethods.WindowTextEvent && nativeMethods.documentCreateEvent) {
           const event = nativeMethods.documentCreateEvent.call(document, 'TextEvent');         
           const textEventArgs = {
                 eventType: browserUtils.isIE ? 'textinput' : 'textInput',
                 ...other parameters
           };
          
           event.initTextEvent(textEventArgs.eventType, ....);

           return this._raiseDispatchEvent(el, event);
 }

return null;

Also there are few questions about event.initTextEvent(name, true, true, null, text, 0, '') parameters:

  • null specified for window on which this event is occurring. Maybe it should be the current window instead of null?
  • 0 specified how text is entered. Now it equals TextEvent.DOM_INPUT_METHOD_UNKNOWN = 0. Maybe we should use TextEvent.DOM_INPUT_METHOD_KEYBOARD = 1?
  • '' specified the locale name. As I understand it should be the current locale name - navigator.language.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree


if (nativeMethods.WindowTextEvent && nativeMethods.documentCreateEvent) {
event = nativeMethods.documentCreateEvent.call(document, 'TextEvent');

event.initTextEvent(name, true, true, null, text, 0, '');
}

if (event)
return this._raiseDispatchEvent(el, event);

return null;
}

_dispatchEvent (el, name, shouldBubble, flag) {
let ev = null;

Expand Down Expand Up @@ -775,6 +792,10 @@ export default class EventSimulator {
return this._dispatchEvent(el, 'change', true, this.DISPATCHED_EVENT_FLAG);
}

textInput (el, text) {
return this._dispatchTextEvent(el, text);
}

input (el) {
return this._dispatchEvent(el, 'input', true);
}
Expand Down
1 change: 1 addition & 0 deletions src/client/sandbox/native-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class NativeMethods {
this.WindowTouchEvent = win.TouchEvent || winProto.TouchEvent;
this.WindowKeyboardEvent = win.KeyboardEvent || winProto.KeyboardEvent;
this.WindowFocusEvent = win.FocusEvent || winProto.FocusEvent;
this.WindowTextEvent = win.TextEvent || winProto.TextEvent;


this.canvasContextDrawImage = win.CanvasRenderingContext2D.prototype.drawImage;
Expand Down
23 changes: 23 additions & 0 deletions test/client/fixtures/sandbox/event/event-simulator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,26 @@ test('wrong type of the blur event (GH-947)', function () {
eventSimulator.blur(domElement);
ok(raised);
});

Copy link
Contributor

@miherlosev miherlosev Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment that firefox does not support textInput event.
Rename test to text input and place it right after the drag and drop events test.

if (!browserUtils.isFirefox) {
test('Should handle textInput event and pass e.data property (GH-1956)', function () {

var handler = function (e) {
var ev = e || window.event;

if (ev instanceof Event && ev instanceof TextEvent && e.data === 'Hello')
raised = true;
};

document.addEventListener('textInput', handler); // Chrome way
document.addEventListener('textinput', handler); // IE way

eventSimulator.textInput(domElement, 'Hello');

document.removeEventListener('textInput', handler); // Chrome way
document.removeEventListener('textinput', handler); // IE way

ok(raised);
});
}