OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/input_method/input_method_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
6 | 6 |
7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
8 | 8 |
9 #include "ash/ime/input_method_menu_item.h" | 9 #include "ash/ime/input_method_menu_item.h" |
10 #include "ash/ime/input_method_menu_manager.h" | 10 #include "ash/ime/input_method_menu_manager.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 if (candidate_window_controller_.get()) | 331 if (candidate_window_controller_.get()) |
332 candidate_window_controller_->Hide(); | 332 candidate_window_controller_->Hide(); |
333 | 333 |
334 // Disable the current engine handler. | 334 // Disable the current engine handler. |
335 IMEEngineHandlerInterface* engine = | 335 IMEEngineHandlerInterface* engine = |
336 IMEBridge::Get()->GetCurrentEngineHandler(); | 336 IMEBridge::Get()->GetCurrentEngineHandler(); |
337 if (engine) | 337 if (engine) |
338 engine->Disable(); | 338 engine->Disable(); |
339 | 339 |
340 // Configure the next engine handler. | 340 // Configure the next engine handler. |
341 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) && | 341 std::string extension_id = |
342 !extension_ime_util::IsKeyboardLayoutExtension( | 342 extension_ime_util::GetExtensionIDFromInputMethodID( |
343 input_method_id_to_switch)) { | 343 input_method_id_to_switch); |
344 IMEBridge::Get()->SetCurrentEngineHandler(NULL); | 344 std::string engine_id = extension_ime_util::GetEngineIDByInputMethodID( |
345 } else { | 345 input_method_id_to_switch); |
346 IMEEngineHandlerInterface* next_engine = | 346 engine = engine_map_[extension_id]; |
347 profile_engine_map_[GetProfile()][input_method_id_to_switch]; | 347 IMEBridge::Get()->SetCurrentEngineHandler(engine); |
348 if (next_engine) { | 348 if (engine) |
349 IMEBridge::Get()->SetCurrentEngineHandler(next_engine); | 349 engine->Enable(engine_id); |
350 next_engine->Enable(); | |
351 } | |
352 } | |
353 | 350 |
354 // TODO(komatsu): Check if it is necessary to perform the above routine | 351 // TODO(komatsu): Check if it is necessary to perform the above routine |
355 // when the current input method is equal to |input_method_id_to_swich|. | 352 // when the current input method is equal to |input_method_id_to_swich|. |
356 if (current_input_method_.id() != input_method_id_to_switch) { | 353 if (current_input_method_.id() != input_method_id_to_switch) { |
357 // Clear property list. Property list would be updated by | 354 // Clear property list. Property list would be updated by |
358 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. | 355 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. |
359 // If the current input method is a keyboard layout, empty | 356 // If the current input method is a keyboard layout, empty |
360 // properties are sufficient. | 357 // properties are sufficient. |
361 const ash::ime::InputMethodMenuItemList empty_menu_item_list; | 358 const ash::ime::InputMethodMenuItemList empty_menu_item_list; |
362 ash::ime::InputMethodMenuManager* input_method_menu_manager = | 359 ash::ime::InputMethodMenuManager* input_method_menu_manager = |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 IMEBridge::Get()->GetCurrentEngineHandler(); | 423 IMEBridge::Get()->GetCurrentEngineHandler(); |
427 if (engine) | 424 if (engine) |
428 engine->PropertyActivate(key); | 425 engine->PropertyActivate(key); |
429 return; | 426 return; |
430 } | 427 } |
431 | 428 |
432 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; | 429 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; |
433 } | 430 } |
434 | 431 |
435 void InputMethodManagerImpl::AddInputMethodExtension( | 432 void InputMethodManagerImpl::AddInputMethodExtension( |
436 const std::string& id, | 433 const std::string& extension_id, |
434 const InputMethodDescriptors& descriptors, | |
437 InputMethodEngineInterface* engine) { | 435 InputMethodEngineInterface* engine) { |
438 if (state_ == STATE_TERMINATING) | 436 if (state_ == STATE_TERMINATING) |
439 return; | 437 return; |
440 | 438 |
441 DCHECK(engine); | 439 DCHECK(engine); |
442 | 440 |
443 profile_engine_map_[GetProfile()][id] = engine; | 441 engine_map_[extension_id] = engine; |
444 | 442 |
445 if (id == current_input_method_.id()) { | 443 if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID( |
444 current_input_method_.id())) { | |
446 IMEBridge::Get()->SetCurrentEngineHandler(engine); | 445 IMEBridge::Get()->SetCurrentEngineHandler(engine); |
447 engine->Enable(); | 446 engine->Enable(extension_ime_util::GetEngineIDByInputMethodID( |
447 current_input_method_.id())); | |
448 } | 448 } |
449 | 449 |
450 if (extension_ime_util::IsComponentExtensionIME(id)) | 450 bool contain = false; |
451 return; | 451 for (size_t i = 0; i < descriptors.size(); i++) { |
452 const InputMethodDescriptor& descriptor = descriptors[i]; | |
453 const std::string& id = descriptor.id(); | |
454 extra_input_methods_[id] = descriptor; | |
455 if (Contains(enabled_extension_imes_, id)) { | |
456 if (!Contains(active_input_method_ids_, id)) { | |
457 active_input_method_ids_.push_back(id); | |
458 } else { | |
459 DVLOG(1) << "AddInputMethodExtension: alread added: " | |
Seigo Nonaka
2014/08/04 23:29:47
nit: /alread/already/ I'm sorry this is not your m
Shu Chen
2014/08/05 01:23:09
Done.
| |
460 << id << ", " << descriptor.name(); | |
461 } | |
462 contain = true; | |
463 } | |
464 } | |
452 | 465 |
453 CHECK(extension_ime_util::IsExtensionIME(id)) | 466 // Ensure that the input method daemon is running. |
454 << id << "is not a valid extension input method ID"; | 467 if (contain) |
455 | |
456 const InputMethodDescriptor& descriptor = engine->GetDescriptor(); | |
457 extra_input_methods_[id] = descriptor; | |
458 | |
459 if (Contains(enabled_extension_imes_, id)) { | |
460 if (!Contains(active_input_method_ids_, id)) { | |
461 active_input_method_ids_.push_back(id); | |
462 } else { | |
463 DVLOG(1) << "AddInputMethodExtension: alread added: " | |
464 << id << ", " << descriptor.name(); | |
465 } | |
466 | |
467 // Ensure that the input method daemon is running. | |
468 MaybeInitializeCandidateWindowController(); | 468 MaybeInitializeCandidateWindowController(); |
469 } | |
470 } | 469 } |
471 | 470 |
472 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { | 471 void InputMethodManagerImpl::RemoveInputMethodExtension( |
Shu Chen
2014/08/04 15:59:31
I'm not sure whether the below code to remove thin
Seigo Nonaka
2014/08/04 23:29:47
Maybe true. could you fix?
On 2014/08/04 15:59:3
Shu Chen
2014/08/05 01:23:09
Done.
| |
473 if (!extension_ime_util::IsExtensionIME(id)) | 472 const std::string& extension_id) { |
474 DVLOG(1) << id << " is not a valid extension input method ID."; | 473 for (std::vector<std::string>::iterator i = active_input_method_ids_.begin(); |
474 i != active_input_method_ids_.end();) { | |
475 if (extension_id == | |
476 extension_ime_util::GetExtensionIDFromInputMethodID(*i)) | |
477 active_input_method_ids_.erase(i); | |
478 else | |
479 ++i; | |
480 } | |
481 for (std::map<std::string, InputMethodDescriptor>::iterator i = | |
482 extra_input_methods_.begin(); | |
483 i != extra_input_methods_.end();) { | |
484 if (extension_id == | |
485 extension_ime_util::GetExtensionIDFromInputMethodID(i->first)) | |
486 extra_input_methods_.erase(i++); | |
487 else | |
488 i++; | |
489 } | |
475 | 490 |
476 std::vector<std::string>::iterator i = std::find( | 491 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id]) |
477 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); | |
478 if (i != active_input_method_ids_.end()) | |
479 active_input_method_ids_.erase(i); | |
480 extra_input_methods_.erase(id); | |
481 | |
482 EngineMap& engine_map = profile_engine_map_[GetProfile()]; | |
483 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map[id]) | |
484 IMEBridge::Get()->SetCurrentEngineHandler(NULL); | 492 IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
485 engine_map.erase(id); | 493 engine_map_.erase(extension_id); |
486 | 494 |
487 // No need to switch input method when terminating. | 495 // No need to switch input method when terminating. |
488 if (state_ != STATE_TERMINATING) { | 496 if (state_ != STATE_TERMINATING) { |
489 // If |current_input_method| is no longer in |active_input_method_ids_|, | 497 // If |current_input_method| is no longer in |active_input_method_ids_|, |
490 // switch to the first one in |active_input_method_ids_|. | 498 // switch to the first one in |active_input_method_ids_|. |
491 ChangeInputMethod(current_input_method_.id()); | 499 ChangeInputMethod(current_input_method_.id()); |
492 } | 500 } |
493 } | 501 } |
494 | 502 |
495 void InputMethodManagerImpl::GetInputMethodExtensions( | 503 void InputMethodManagerImpl::GetInputMethodExtensions( |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 CandidateWindowController::CreateCandidateWindowController()); | 872 CandidateWindowController::CreateCandidateWindowController()); |
865 candidate_window_controller_->AddObserver(this); | 873 candidate_window_controller_->AddObserver(this); |
866 } | 874 } |
867 | 875 |
868 Profile* InputMethodManagerImpl::GetProfile() const { | 876 Profile* InputMethodManagerImpl::GetProfile() const { |
869 return ProfileManager::GetActiveUserProfile(); | 877 return ProfileManager::GetActiveUserProfile(); |
870 } | 878 } |
871 | 879 |
872 } // namespace input_method | 880 } // namespace input_method |
873 } // namespace chromeos | 881 } // namespace chromeos |
OLD | NEW |