Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc

Issue 1657593007: Implement chrome.input.ime.setComposition/commitText API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 334 }
337 335
338 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( 336 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine(
339 const std::string& extension_id) { 337 const std::string& extension_id) {
340 std::map<std::string, InputMethodEngine*>::iterator it = 338 std::map<std::string, InputMethodEngine*>::iterator it =
341 engine_map_.find(extension_id); 339 engine_map_.find(extension_id);
342 return (it != engine_map_.end() && it->second->IsActive()) ? it->second 340 return (it != engine_map_.end() && it->second->IsActive()) ? it->second
343 : nullptr; 341 : nullptr;
344 } 342 }
345 343
346 bool InputImeSetCompositionFunction::RunSync() {
347 InputMethodEngine* engine = GetActiveEngine(
348 Profile::FromBrowserContext(browser_context()), extension_id());
349 if (!engine) {
350 SetResult(new base::FundamentalValue(false));
351 return true;
352 }
353
354 scoped_ptr<SetComposition::Params> parent_params(
355 SetComposition::Params::Create(*args_));
356 const SetComposition::Params::Parameters& params = parent_params->parameters;
357 std::vector<InputMethodEngineBase::SegmentInfo> segments;
358 if (params.segments) {
359 const std::vector<linked_ptr<
360 SetComposition::Params::Parameters::SegmentsType> >&
361 segments_args = *params.segments;
362 for (size_t i = 0; i < segments_args.size(); ++i) {
363 EXTENSION_FUNCTION_VALIDATE(
364 segments_args[i]->style !=
365 input_ime::UNDERLINE_STYLE_NONE);
366 segments.push_back(InputMethodEngineBase::SegmentInfo());
367 segments.back().start = segments_args[i]->start;
368 segments.back().end = segments_args[i]->end;
369 if (segments_args[i]->style ==
370 input_ime::UNDERLINE_STYLE_UNDERLINE) {
371 segments.back().style = InputMethodEngineBase::SEGMENT_STYLE_UNDERLINE;
372 } else if (segments_args[i]->style ==
373 input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) {
374 segments.back().style =
375 InputMethodEngineBase::SEGMENT_STYLE_DOUBLE_UNDERLINE;
376 } else {
377 segments.back().style =
378 InputMethodEngineBase::SEGMENT_STYLE_NO_UNDERLINE;
379 }
380 }
381 }
382
383 int selection_start =
384 params.selection_start ? *params.selection_start : params.cursor;
385 int selection_end =
386 params.selection_end ? *params.selection_end : params.cursor;
387
388 SetResult(new base::FundamentalValue(
389 engine->SetComposition(params.context_id, params.text.c_str(),
390 selection_start, selection_end, params.cursor,
391 segments, &error_)));
392 return true;
393 }
394
395 bool InputImeClearCompositionFunction::RunSync() { 344 bool InputImeClearCompositionFunction::RunSync() {
396 InputMethodEngine* engine = GetActiveEngine( 345 InputMethodEngine* engine = GetActiveEngine(
397 Profile::FromBrowserContext(browser_context()), extension_id()); 346 Profile::FromBrowserContext(browser_context()), extension_id());
398 if (!engine) { 347 if (!engine) {
399 SetResult(new base::FundamentalValue(false)); 348 SetResult(new base::FundamentalValue(false));
400 return true; 349 return true;
401 } 350 }
402 351
403 scoped_ptr<ClearComposition::Params> parent_params( 352 scoped_ptr<ClearComposition::Params> parent_params(
404 ClearComposition::Params::Create(*args_)); 353 ClearComposition::Params::Create(*args_));
405 const ClearComposition::Params::Parameters& params = 354 const ClearComposition::Params::Parameters& params =
406 parent_params->parameters; 355 parent_params->parameters;
407 356
408 SetResult(new base::FundamentalValue( 357 SetResult(new base::FundamentalValue(
409 engine->ClearComposition(params.context_id, &error_))); 358 engine->ClearComposition(params.context_id, &error_)));
410 return true; 359 return true;
411 } 360 }
412 361
413 bool InputImeCommitTextFunction::RunSync() {
414 InputMethodEngine* engine = GetActiveEngine(
415 Profile::FromBrowserContext(browser_context()), extension_id());
416 if (!engine) {
417 SetResult(new base::FundamentalValue(false));
418 return true;
419 }
420
421 scoped_ptr<CommitText::Params> parent_params(
422 CommitText::Params::Create(*args_));
423 const CommitText::Params::Parameters& params =
424 parent_params->parameters;
425
426 SetResult(new base::FundamentalValue(
427 engine->CommitText(params.context_id, params.text.c_str(), &error_)));
428 return true;
429 }
430
431 bool InputImeHideInputViewFunction::RunAsync() { 362 bool InputImeHideInputViewFunction::RunAsync() {
432 InputMethodEngine* engine = GetActiveEngine( 363 InputMethodEngine* engine = GetActiveEngine(
433 Profile::FromBrowserContext(browser_context()), extension_id()); 364 Profile::FromBrowserContext(browser_context()), extension_id());
434 if (!engine) { 365 if (!engine) {
435 return true; 366 return true;
436 } 367 }
437 engine->HideInputView(); 368 engine->HideInputView();
438 return true; 369 return true;
439 } 370 }
440 371
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 return; 629 return;
699 InputMethodEngine* engine = 630 InputMethodEngine* engine =
700 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), 631 GetActiveEngine(Profile::FromBrowserContext(details.browser_context),
701 details.extension_id); 632 details.extension_id);
702 // Notifies the IME extension for IME ready with onActivate/onFocus events. 633 // Notifies the IME extension for IME ready with onActivate/onFocus events.
703 if (engine) 634 if (engine)
704 engine->Enable(engine->GetActiveComponentId()); 635 engine->Enable(engine->GetActiveComponentId());
705 } 636 }
706 637
707 } // namespace extensions 638 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698