Chromium Code Reviews| Index: chrome/browser/extensions/api/input_ime/input_ime_api.cc |
| diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api.cc b/chrome/browser/extensions/api/input_ime/input_ime_api.cc |
| index 1ce5be01e3624331ff7ad2ac492af82b258dcead..ee0de1e469c02b18707a8b41f620bdc5ecc556a8 100644 |
| --- a/chrome/browser/extensions/api/input_ime/input_ime_api.cc |
| +++ b/chrome/browser/extensions/api/input_ime/input_ime_api.cc |
| @@ -10,6 +10,8 @@ |
| namespace input_ime = extensions::api::input_ime; |
| namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; |
| +namespace SetComposition = extensions::api::input_ime::SetComposition; |
| +namespace CommitText = extensions::api::input_ime::CommitText; |
| using ui::IMEEngineHandlerInterface; |
| using input_method::InputMethodEngineBase; |
| @@ -244,6 +246,12 @@ InputImeEventRouter* InputImeEventRouterFactory::GetRouter(Profile* profile) { |
| } |
| bool InputImeKeyEventHandledFunction::RunAsync() { |
| + InputMethodEngineBase* engine = |
| + GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| + ->GetActiveEngine(extension_id()); |
| + if (engine) |
| + engine->KeyEventHandled(); |
| + |
| scoped_ptr<KeyEventHandled::Params> params( |
| KeyEventHandled::Params::Create(*args_)); |
| GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| @@ -251,6 +259,73 @@ bool InputImeKeyEventHandledFunction::RunAsync() { |
| return true; |
| } |
| +ExtensionFunction::ResponseAction InputImeSetCompositionFunction::Run() { |
| + InputMethodEngineBase* engine = |
| + GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| + ->GetActiveEngine(extension_id()); |
| + base::DictionaryValue* output = new base::DictionaryValue(); |
|
Devlin
2016/02/04 00:09:17
prefer scoped ptr generally, but also we should ju
Azure Wei
2016/02/04 03:21:19
Done.
|
| + if (!engine) { |
| + output->SetBoolean("success", false); |
| + } else { |
| + scoped_ptr<SetComposition::Params> parent_params( |
| + SetComposition::Params::Create(*args_)); |
| + const SetComposition::Params::Parameters& params = |
| + parent_params->parameters; |
| + std::vector<InputMethodEngineBase::SegmentInfo> segments; |
| + if (params.segments) { |
| + const std::vector< |
| + linked_ptr<SetComposition::Params::Parameters::SegmentsType>>& |
| + segments_args = *params.segments; |
| + for (const auto& segments_arg : segments_args) { |
| + EXTENSION_FUNCTION_VALIDATE(segments_arg->style != |
| + input_ime::UNDERLINE_STYLE_NONE); |
| + InputMethodEngineBase::SegmentInfo segment_info; |
| + segment_info.start = segments_arg->start; |
| + segment_info.end = segments_arg->end; |
| + if (segments_arg->style == input_ime::UNDERLINE_STYLE_UNDERLINE) { |
| + segment_info.style = InputMethodEngineBase::SEGMENT_STYLE_UNDERLINE; |
| + } else if (segments_arg->style == |
| + input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) { |
| + segment_info.style = |
| + InputMethodEngineBase::SEGMENT_STYLE_DOUBLE_UNDERLINE; |
| + } else { |
| + segment_info.style = |
| + InputMethodEngineBase::SEGMENT_STYLE_NO_UNDERLINE; |
| + } |
| + segments.push_back(segment_info); |
| + } |
| + } |
| + int selection_start = |
| + params.selection_start ? *params.selection_start : params.cursor; |
| + int selection_end = |
| + params.selection_end ? *params.selection_end : params.cursor; |
| + output->SetBoolean( |
| + "success", engine->SetComposition( |
| + params.context_id, params.text.c_str(), selection_start, |
| + selection_end, params.cursor, segments, &error_)); |
| + } |
| + return RespondNow(OneArgument(output)); |
| +} |
| + |
| +ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() { |
| + base::DictionaryValue* output = new base::DictionaryValue(); |
| + InputMethodEngineBase* engine = |
| + GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| + ->GetActiveEngine(extension_id()); |
| + |
| + if (!engine) { |
| + output->SetBoolean("success", false); |
| + } else { |
| + scoped_ptr<CommitText::Params> parent_params( |
| + CommitText::Params::Create(*args_)); |
| + const CommitText::Params::Parameters& params = parent_params->parameters; |
| + output->SetBoolean( |
| + "success", |
| + engine->CommitText(params.context_id, params.text.c_str(), &error_)); |
| + } |
| + return RespondNow(OneArgument(output)); |
| +} |
| + |
| InputImeAPI::InputImeAPI(content::BrowserContext* context) |
| : browser_context_(context), extension_registry_observer_(this) { |
| extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |