| 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..42320a52e99060d0b27ba67e7e406ff3e54f1e78 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;
|
|
|
| @@ -251,6 +253,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();
|
| + 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_));
|
|
|