| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace DeleteSurroundingText = | 28 namespace DeleteSurroundingText = |
| 29 extensions::api::input_ime::DeleteSurroundingText; | 29 extensions::api::input_ime::DeleteSurroundingText; |
| 30 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; | 30 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; |
| 31 namespace SendKeyEvents = extensions::api::input_ime::SendKeyEvents; | 31 namespace SendKeyEvents = extensions::api::input_ime::SendKeyEvents; |
| 32 namespace HideInputView = extensions::api::input_ime::HideInputView; | 32 namespace HideInputView = extensions::api::input_ime::HideInputView; |
| 33 namespace SetMenuItems = extensions::api::input_ime::SetMenuItems; | 33 namespace SetMenuItems = extensions::api::input_ime::SetMenuItems; |
| 34 namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition; | 34 namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition; |
| 35 namespace SetCandidates = extensions::api::input_ime::SetCandidates; | 35 namespace SetCandidates = extensions::api::input_ime::SetCandidates; |
| 36 namespace SetCandidateWindowProperties = | 36 namespace SetCandidateWindowProperties = |
| 37 extensions::api::input_ime::SetCandidateWindowProperties; | 37 extensions::api::input_ime::SetCandidateWindowProperties; |
| 38 namespace CommitText = extensions::api::input_ime::CommitText; | |
| 39 namespace ClearComposition = extensions::api::input_ime::ClearComposition; | 38 namespace ClearComposition = extensions::api::input_ime::ClearComposition; |
| 40 namespace SetComposition = extensions::api::input_ime::SetComposition; | |
| 41 namespace OnCompositionBoundsChanged = | 39 namespace OnCompositionBoundsChanged = |
| 42 extensions::api::input_method_private::OnCompositionBoundsChanged; | 40 extensions::api::input_method_private::OnCompositionBoundsChanged; |
| 43 using ui::IMEEngineHandlerInterface; | 41 using ui::IMEEngineHandlerInterface; |
| 44 using input_method::InputMethodEngineBase; | 42 using input_method::InputMethodEngineBase; |
| 45 using chromeos::InputMethodEngine; | 43 using chromeos::InputMethodEngine; |
| 46 | 44 |
| 47 namespace { | 45 namespace { |
| 48 const char kErrorEngineNotAvailable[] = "Engine is not available"; | 46 const char kErrorEngineNotAvailable[] = "Engine is not available"; |
| 49 const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; | 47 const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; |
| 50 const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; | 48 const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 337 } |
| 340 | 338 |
| 341 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( | 339 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( |
| 342 const std::string& extension_id) { | 340 const std::string& extension_id) { |
| 343 std::map<std::string, InputMethodEngine*>::iterator it = | 341 std::map<std::string, InputMethodEngine*>::iterator it = |
| 344 engine_map_.find(extension_id); | 342 engine_map_.find(extension_id); |
| 345 return (it != engine_map_.end() && it->second->IsActive()) ? it->second | 343 return (it != engine_map_.end() && it->second->IsActive()) ? it->second |
| 346 : nullptr; | 344 : nullptr; |
| 347 } | 345 } |
| 348 | 346 |
| 349 bool InputImeSetCompositionFunction::RunSync() { | |
| 350 InputMethodEngine* engine = GetActiveEngine( | |
| 351 Profile::FromBrowserContext(browser_context()), extension_id()); | |
| 352 if (!engine) { | |
| 353 SetResult(new base::FundamentalValue(false)); | |
| 354 return true; | |
| 355 } | |
| 356 | |
| 357 scoped_ptr<SetComposition::Params> parent_params( | |
| 358 SetComposition::Params::Create(*args_)); | |
| 359 const SetComposition::Params::Parameters& params = parent_params->parameters; | |
| 360 std::vector<InputMethodEngineBase::SegmentInfo> segments; | |
| 361 if (params.segments) { | |
| 362 const std::vector<linked_ptr< | |
| 363 SetComposition::Params::Parameters::SegmentsType> >& | |
| 364 segments_args = *params.segments; | |
| 365 for (size_t i = 0; i < segments_args.size(); ++i) { | |
| 366 EXTENSION_FUNCTION_VALIDATE( | |
| 367 segments_args[i]->style != | |
| 368 input_ime::UNDERLINE_STYLE_NONE); | |
| 369 segments.push_back(InputMethodEngineBase::SegmentInfo()); | |
| 370 segments.back().start = segments_args[i]->start; | |
| 371 segments.back().end = segments_args[i]->end; | |
| 372 if (segments_args[i]->style == | |
| 373 input_ime::UNDERLINE_STYLE_UNDERLINE) { | |
| 374 segments.back().style = InputMethodEngineBase::SEGMENT_STYLE_UNDERLINE; | |
| 375 } else if (segments_args[i]->style == | |
| 376 input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) { | |
| 377 segments.back().style = | |
| 378 InputMethodEngineBase::SEGMENT_STYLE_DOUBLE_UNDERLINE; | |
| 379 } else { | |
| 380 segments.back().style = | |
| 381 InputMethodEngineBase::SEGMENT_STYLE_NO_UNDERLINE; | |
| 382 } | |
| 383 } | |
| 384 } | |
| 385 | |
| 386 int selection_start = | |
| 387 params.selection_start ? *params.selection_start : params.cursor; | |
| 388 int selection_end = | |
| 389 params.selection_end ? *params.selection_end : params.cursor; | |
| 390 | |
| 391 SetResult(new base::FundamentalValue( | |
| 392 engine->SetComposition(params.context_id, params.text.c_str(), | |
| 393 selection_start, selection_end, params.cursor, | |
| 394 segments, &error_))); | |
| 395 return true; | |
| 396 } | |
| 397 | |
| 398 bool InputImeClearCompositionFunction::RunSync() { | 347 bool InputImeClearCompositionFunction::RunSync() { |
| 399 InputMethodEngine* engine = GetActiveEngine( | 348 InputMethodEngine* engine = GetActiveEngine( |
| 400 Profile::FromBrowserContext(browser_context()), extension_id()); | 349 Profile::FromBrowserContext(browser_context()), extension_id()); |
| 401 if (!engine) { | 350 if (!engine) { |
| 402 SetResult(new base::FundamentalValue(false)); | 351 SetResult(new base::FundamentalValue(false)); |
| 403 return true; | 352 return true; |
| 404 } | 353 } |
| 405 | 354 |
| 406 scoped_ptr<ClearComposition::Params> parent_params( | 355 scoped_ptr<ClearComposition::Params> parent_params( |
| 407 ClearComposition::Params::Create(*args_)); | 356 ClearComposition::Params::Create(*args_)); |
| 408 const ClearComposition::Params::Parameters& params = | 357 const ClearComposition::Params::Parameters& params = |
| 409 parent_params->parameters; | 358 parent_params->parameters; |
| 410 | 359 |
| 411 SetResult(new base::FundamentalValue( | 360 SetResult(new base::FundamentalValue( |
| 412 engine->ClearComposition(params.context_id, &error_))); | 361 engine->ClearComposition(params.context_id, &error_))); |
| 413 return true; | 362 return true; |
| 414 } | 363 } |
| 415 | 364 |
| 416 bool InputImeCommitTextFunction::RunSync() { | |
| 417 InputMethodEngine* engine = GetActiveEngine( | |
| 418 Profile::FromBrowserContext(browser_context()), extension_id()); | |
| 419 if (!engine) { | |
| 420 SetResult(new base::FundamentalValue(false)); | |
| 421 return true; | |
| 422 } | |
| 423 | |
| 424 scoped_ptr<CommitText::Params> parent_params( | |
| 425 CommitText::Params::Create(*args_)); | |
| 426 const CommitText::Params::Parameters& params = | |
| 427 parent_params->parameters; | |
| 428 | |
| 429 SetResult(new base::FundamentalValue( | |
| 430 engine->CommitText(params.context_id, params.text.c_str(), &error_))); | |
| 431 return true; | |
| 432 } | |
| 433 | |
| 434 bool InputImeHideInputViewFunction::RunAsync() { | 365 bool InputImeHideInputViewFunction::RunAsync() { |
| 435 InputMethodEngine* engine = GetActiveEngine( | 366 InputMethodEngine* engine = GetActiveEngine( |
| 436 Profile::FromBrowserContext(browser_context()), extension_id()); | 367 Profile::FromBrowserContext(browser_context()), extension_id()); |
| 437 if (!engine) { | 368 if (!engine) { |
| 438 return true; | 369 return true; |
| 439 } | 370 } |
| 440 engine->HideInputView(); | 371 engine->HideInputView(); |
| 441 return true; | 372 return true; |
| 442 } | 373 } |
| 443 | 374 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 return; | 643 return; |
| 713 InputMethodEngine* engine = | 644 InputMethodEngine* engine = |
| 714 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), | 645 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), |
| 715 details.extension_id); | 646 details.extension_id); |
| 716 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 647 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
| 717 if (engine) | 648 if (engine) |
| 718 engine->Enable(engine->GetActiveComponentId()); | 649 engine->Enable(engine->GetActiveComponentId()); |
| 719 } | 650 } |
| 720 | 651 |
| 721 } // namespace extensions | 652 } // namespace extensions |
| OLD | NEW |