Commit 994100f1 authored by Shu Chen's avatar Shu Chen Committed by Commit Bot

Fixes the Input IME custom bindings.

Bug: 733825
Change-Id: I4232ab3e2d55a03d1522971a544374a3aae2c7ed
Reviewed-on: https://chromium-review.googlesource.com/1128780
Commit-Queue: Shu Chen <shuchen@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580795}
parent c7ce19d5
...@@ -96,11 +96,6 @@ ...@@ -96,11 +96,6 @@
"enum": ["normal", "login", "lock", "secondary-login"], "enum": ["normal", "login", "lock", "secondary-login"],
"description": "The screen type under which the IME is activated." "description": "The screen type under which the IME is activated."
}, },
{
"id": "CallbackStyle",
"type": "string",
"enum": ["async"]
},
{ {
"id": "MouseButton", "id": "MouseButton",
"type": "string", "type": "string",
...@@ -752,7 +747,7 @@ ...@@ -752,7 +747,7 @@
{ {
"name": "onKeyEvent", "name": "onKeyEvent",
"type": "function", "type": "function",
"description": "Fired when a key event is sent from the operating system. The event will be sent to the extension if this extension owns the active IME.", "description": "Fired when a key event is sent from the operating system. The event will be sent to the extension if this extension owns the active IME. The listener function should return true if the event was handled false if it was not. If the event will be evaluated asynchronously, this function must return undefined and the IME must later call keyEventHandled() with the result.",
"platforms": ["chromeos", "win", "linux"], "platforms": ["chromeos", "win", "linux"],
"options": { "options": {
"supportsFilters": false, "supportsFilters": false,
...@@ -772,20 +767,9 @@ ...@@ -772,20 +767,9 @@
"description": "Data on the key event" "description": "Data on the key event"
} }
], ],
"extraParameters": [
{
"type": "array",
"optional": true,
"name": "extraInfoSpec",
"description": "Array of extra information that specifies how the callback is invoked.",
"items": {
"$ref": "CallbackStyle"
}
}
],
"returns": { "returns": {
"type": "boolean", "type": "boolean",
"description": "True if the keystroke was handled, false if not. This function should always return a value if |async| is not specified.", "description": "True if the keystroke was handled, false if not. Or returns undefined if the extension decides to call keyEventHandled explicitly.",
"optional": true "optional": true
} }
}, },
......
...@@ -11,13 +11,11 @@ var registerArgumentMassager = bindingUtil ? ...@@ -11,13 +11,11 @@ var registerArgumentMassager = bindingUtil ?
$Function.bind(bindingUtil.registerEventArgumentMassager, bindingUtil) : $Function.bind(bindingUtil.registerEventArgumentMassager, bindingUtil) :
require('event_bindings').registerArgumentMassager; require('event_bindings').registerArgumentMassager;
// TODO(crbug.com/733825): These bindings have some issues. var keyEventHandled;
var inputIme;
registerArgumentMassager('input.ime.onKeyEvent', registerArgumentMassager('input.ime.onKeyEvent',
function(args, dispatch) { function(args, dispatch) {
var keyData = args[1]; var keyData = args[1];
var result = false; var result = undefined;
try { try {
// dispatch() is weird - it returns an object {results: array<results>} iff // dispatch() is weird - it returns an object {results: array<results>} iff
// there is at least one result value that !== undefined. Since onKeyEvent // there is at least one result value that !== undefined. Since onKeyEvent
...@@ -27,25 +25,22 @@ registerArgumentMassager('input.ime.onKeyEvent', ...@@ -27,25 +25,22 @@ registerArgumentMassager('input.ime.onKeyEvent',
if (dispatchResult && dispatchResult.results) if (dispatchResult && dispatchResult.results)
result = dispatchResult.results[0]; result = dispatchResult.results[0];
} catch (e) { } catch (e) {
result = false;
console.error('Error in event handler for onKeyEvent: ' + e.stack); console.error('Error in event handler for onKeyEvent: ' + e.stack);
} }
if (!inputIme.onKeyEvent.async) if (result !== undefined) {
inputIme.keyEventHandled(keyData.requestId, result); keyEventHandled(keyData.requestId, !!result);
}
}); });
binding.registerCustomHook(function(api) { binding.registerCustomHook(function(api) {
inputIme = api.compiledApi; keyEventHandled = api.compiledApi.keyEventHandled;
var originalAddListener = inputIme.onKeyEvent.addListener; // TODO(shuchen): override onKeyEvent.addListener only for compatibility.
inputIme.onKeyEvent.addListener = function(cb, opt_extraInfo) { // This should be removed after the IME extension doesn't rely on the
inputIme.onKeyEvent.async = false; // additional "async" parameter.
if (opt_extraInfo instanceof Array) { var originalAddListener = api.compiledApi.onKeyEvent.addListener;
for (var i = 0; i < opt_extraInfo.length; ++i) { api.compiledApi.onKeyEvent.addListener = function(cb, opt_extraInfo) {
if (opt_extraInfo[i] == 'async') {
inputIme.onKeyEvent.async = true;
}
}
}
$Function.call(originalAddListener, this, cb); $Function.call(originalAddListener, this, cb);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment