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( ...@@ -416,7 +416,7 @@ chromeos::InputMethodEngine* InputImeEventRouter::GetActiveEngine(
return NULL; return NULL;
} }
void InputImeEventRouter::OnEventHandled( void InputImeEventRouter::OnKeyEventHandled(
const std::string& extension_id, const std::string& extension_id,
const std::string& request_id, const std::string& request_id,
bool handled) { bool handled) {
...@@ -820,14 +820,14 @@ bool UpdateMenuItemsFunction::RunImpl() { ...@@ -820,14 +820,14 @@ bool UpdateMenuItemsFunction::RunImpl() {
return true; return true;
} }
bool InputEventHandled::RunImpl() { bool KeyEventHandled::RunImpl() {
std::string request_id_str; std::string request_id_str;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str)); EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str));
bool handled = false; bool handled = false;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled));
InputImeEventRouter::GetInstance()->OnEventHandled( InputImeEventRouter::GetInstance()->OnKeyEventHandled(
extension_id(), request_id_str, handled); extension_id(), request_id_str, handled);
return true; return true;
......
...@@ -40,9 +40,9 @@ class InputImeEventRouter { ...@@ -40,9 +40,9 @@ class InputImeEventRouter {
// Called when a key event was handled. // Called when a key event was handled.
void OnEventHandled(const std::string& extension_id, void OnKeyEventHandled(const std::string& extension_id,
const std::string& request_id, const std::string& request_id,
bool handled); bool handled);
std::string AddRequest(const std::string& engine_id, std::string AddRequest(const std::string& engine_id,
chromeos::input_method::KeyEventHandle* key_data); chromeos::input_method::KeyEventHandle* key_data);
...@@ -159,12 +159,12 @@ class UpdateMenuItemsFunction : public SyncExtensionFunction { ...@@ -159,12 +159,12 @@ class UpdateMenuItemsFunction : public SyncExtensionFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
}; };
class InputEventHandled : public AsyncExtensionFunction { class KeyEventHandled : public AsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION_NAME("input.ime.eventHandled"); DECLARE_EXTENSION_FUNCTION_NAME("input.ime.keyEventHandled");
protected: protected:
virtual ~InputEventHandled() {} virtual ~KeyEventHandled() {}
// ExtensionFunction: // ExtensionFunction:
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
......
...@@ -298,8 +298,7 @@ void ExtensionFunctionRegistry::ResetFunctions() { ...@@ -298,8 +298,7 @@ void ExtensionFunctionRegistry::ResetFunctions() {
RegisterFunction<extensions::SetCursorPositionFunction>(); RegisterFunction<extensions::SetCursorPositionFunction>();
RegisterFunction<extensions::SetMenuItemsFunction>(); RegisterFunction<extensions::SetMenuItemsFunction>();
RegisterFunction<extensions::UpdateMenuItemsFunction>(); RegisterFunction<extensions::UpdateMenuItemsFunction>();
RegisterFunction<extensions::KeyEventHandled>();
RegisterFunction<extensions::InputEventHandled>();
// Power // Power
RegisterFunction<extensions::power::RequestKeepAwakeFunction>(); RegisterFunction<extensions::power::RequestKeepAwakeFunction>();
......
...@@ -403,13 +403,12 @@ ...@@ -403,13 +403,12 @@
] ]
}, },
{ {
"name": "eventHandled", "name": "keyEventHandled",
"nodoc": true,
"type": "function", "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": [ "parameters": [
{"type": "string", "name": "requestId"}, {"type": "string", "name": "requestId", "description": "Request id of the event that was handled. This should come from keyEvent.requestId"},
{"type": "boolean", "name": "response"} {"type": "boolean", "name": "response", "description": "True if the keystroke was handled, false if not"}
] ]
} }
], ],
...@@ -496,9 +495,22 @@ ...@@ -496,9 +495,22 @@
"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 should be passed to the listener function.",
"items": {
"type": "string",
"enum": ["async"]
}
}
],
"returns": { "returns": {
"type": "boolean", "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() { ...@@ -18,6 +18,19 @@ chromeHidden.registerCustomHook('input.ime', function() {
} catch (e) { } catch (e) {
console.error('Error in event handler for onKeyEvent: ' + e.stack); 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