Commit 4a8c5381 authored by zork@chromium.org's avatar zork@chromium.org

Add a parameter that specifies whether onKeyEvent is asynchronous

BUG=159981


Review URL: https://chromiumcodereview.appspot.com/11299270

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170714 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b1989f5
......@@ -416,7 +416,7 @@ chromeos::InputMethodEngine* InputImeEventRouter::GetActiveEngine(
return NULL;
}
void InputImeEventRouter::OnEventHandled(
void InputImeEventRouter::OnKeyEventHandled(
const std::string& extension_id,
const std::string& request_id,
bool handled) {
......@@ -820,14 +820,14 @@ bool UpdateMenuItemsFunction::RunImpl() {
return true;
}
bool InputEventHandled::RunImpl() {
bool KeyEventHandled::RunImpl() {
std::string request_id_str;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str));
bool handled = false;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled));
InputImeEventRouter::GetInstance()->OnEventHandled(
InputImeEventRouter::GetInstance()->OnKeyEventHandled(
extension_id(), request_id_str, handled);
return true;
......
......@@ -40,9 +40,9 @@ class InputImeEventRouter {
// Called when a key event was handled.
void OnEventHandled(const std::string& extension_id,
const std::string& request_id,
bool handled);
void OnKeyEventHandled(const std::string& extension_id,
const std::string& request_id,
bool handled);
std::string AddRequest(const std::string& engine_id,
chromeos::input_method::KeyEventHandle* key_data);
......@@ -159,12 +159,12 @@ class UpdateMenuItemsFunction : public SyncExtensionFunction {
virtual bool RunImpl() OVERRIDE;
};
class InputEventHandled : public AsyncExtensionFunction {
class KeyEventHandled : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION_NAME("input.ime.eventHandled");
DECLARE_EXTENSION_FUNCTION_NAME("input.ime.keyEventHandled");
protected:
virtual ~InputEventHandled() {}
virtual ~KeyEventHandled() {}
// ExtensionFunction:
virtual bool RunImpl() OVERRIDE;
......
......@@ -298,8 +298,7 @@ void ExtensionFunctionRegistry::ResetFunctions() {
RegisterFunction<extensions::SetCursorPositionFunction>();
RegisterFunction<extensions::SetMenuItemsFunction>();
RegisterFunction<extensions::UpdateMenuItemsFunction>();
RegisterFunction<extensions::InputEventHandled>();
RegisterFunction<extensions::KeyEventHandled>();
// Power
RegisterFunction<extensions::power::RequestKeepAwakeFunction>();
......
......@@ -403,13 +403,12 @@
]
},
{
"name": "eventHandled",
"nodoc": true,
"name": "keyEventHandled",
"type": "function",
"description": "Used internally to send a response for onKeyEvent.",
"description": "Indicates that the key event received by onKeyEvent is handled. This should only be called if the onKeyEvent listener is asynchronous.",
"parameters": [
{"type": "string", "name": "requestId"},
{"type": "boolean", "name": "response"}
{"type": "string", "name": "requestId", "description": "Request id of the event that was handled. This should come from keyEvent.requestId"},
{"type": "boolean", "name": "response", "description": "True if the keystroke was handled, false if not"}
]
}
],
......@@ -496,9 +495,22 @@
"description": "Data on the key event"
}
],
"extraParameters": [
{
"type": "array",
"optional": true,
"name": "extraInfoSpec",
"description": "Array of extra information that should be passed to the listener function.",
"items": {
"type": "string",
"enum": ["async"]
}
}
],
"returns": {
"type": "boolean",
"description": "True if the keystroke was handled, false if not"
"description": "True if the keystroke was handled, false if not",
"optional": true
}
},
{
......
......@@ -18,6 +18,19 @@ chromeHidden.registerCustomHook('input.ime', function() {
} catch (e) {
console.error('Error in event handler for onKeyEvent: ' + e.stack);
}
chrome.input.ime.eventHandled(keyData.requestId, result);
if (!chrome.input.ime.onKeyEvent.async)
chrome.input.ime.keyEventHandled(keyData.requestId, result);
};
chrome.input.ime.onKeyEvent.addListener = function(cb, opt_extraInfo) {
chrome.input.ime.onKeyEvent.async = false;
if (opt_extraInfo instanceof Array) {
for (var i = 0; i < opt_extraInfo.length; ++i) {
if (opt_extraInfo[i] == "async") {
chrome.input.ime.onKeyEvent.async = true;
}
}
}
chrome.Event.prototype.addListener.call(this, cb, null);
};
});
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