Chromium Code Reviews| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 DVLOG(1) << "Can't change the current input method to " | 324 DVLOG(1) << "Can't change the current input method to " |
| 325 << input_method_id << " since the engine is not enabled. " | 325 << input_method_id << " since the engine is not enabled. " |
| 326 << "Switch to " << input_method_id_to_switch << " instead."; | 326 << "Switch to " << input_method_id_to_switch << " instead."; |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 // Hide candidate window and info list. | 330 // Hide candidate window and info list. |
| 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. | |
| 335 IMEEngineHandlerInterface* engine = | |
| 336 IMEBridge::Get()->GetCurrentEngineHandler(); | |
| 337 if (engine) | |
| 338 engine->Disable(); | |
| 339 | |
| 340 // Configure the next engine handler. | |
| 341 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) && | |
| 342 !extension_ime_util::IsKeyboardLayoutExtension( | |
| 343 input_method_id_to_switch)) { | |
| 344 IMEBridge::Get()->SetCurrentEngineHandler(NULL); | |
| 345 } else { | |
| 346 IMEEngineHandlerInterface* next_engine = | |
| 347 profile_engine_map_[GetProfile()][input_method_id_to_switch]; | |
| 348 if (next_engine) { | |
| 349 IMEBridge::Get()->SetCurrentEngineHandler(next_engine); | |
| 350 next_engine->Enable(); | |
| 351 } | |
| 352 } | |
| 353 | |
| 354 // TODO(komatsu): Check if it is necessary to perform the above routine | 334 // 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|. | 335 // when the current input method is equal to |input_method_id_to_swich|. |
| 356 if (current_input_method_.id() != input_method_id_to_switch) { | 336 if (current_input_method_.id() != input_method_id_to_switch) { |
| 357 // Clear property list. Property list would be updated by | 337 // Clear property list. Property list would be updated by |
| 358 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. | 338 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. |
| 359 // If the current input method is a keyboard layout, empty | 339 // If the current input method is a keyboard layout, empty |
| 360 // properties are sufficient. | 340 // properties are sufficient. |
| 361 const ash::ime::InputMethodMenuItemList empty_menu_item_list; | 341 const ash::ime::InputMethodMenuItemList empty_menu_item_list; |
| 362 ash::ime::InputMethodMenuManager* input_method_menu_manager = | 342 ash::ime::InputMethodMenuManager* input_method_menu_manager = |
| 363 ash::ime::InputMethodMenuManager::GetInstance(); | 343 ash::ime::InputMethodMenuManager::GetInstance(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 374 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 354 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
| 375 if (!descriptor) | 355 if (!descriptor) |
| 376 LOG(ERROR) << "Unknown input method id: " << input_method_id_to_switch; | 356 LOG(ERROR) << "Unknown input method id: " << input_method_id_to_switch; |
| 377 } | 357 } |
| 378 DCHECK(descriptor); | 358 DCHECK(descriptor); |
| 379 | 359 |
| 380 previous_input_method_ = current_input_method_; | 360 previous_input_method_ = current_input_method_; |
| 381 current_input_method_ = *descriptor; | 361 current_input_method_ = *descriptor; |
| 382 } | 362 } |
| 383 | 363 |
| 364 // Disable the current engine handler. | |
| 365 IMEEngineHandlerInterface* engine = | |
| 366 IMEBridge::Get()->GetCurrentEngineHandler(); | |
| 367 if (engine) | |
| 368 engine->Disable(); | |
| 369 | |
| 370 // Configure the next engine handler. | |
| 371 // This must be after |current_input_method_| has been set to new input | |
| 372 // method, because engine's Enable() method needs to access it. | |
| 373 std::string extension_id = | |
|
Yuki
2014/08/05 07:57:18
Please use const references.
const std::string& ex
Shu Chen
2014/08/05 14:04:31
Done.
| |
| 374 extension_ime_util::GetExtensionIDFromInputMethodID( | |
| 375 input_method_id_to_switch); | |
| 376 std::string engine_id = extension_ime_util::GetEngineIDByInputMethodID( | |
|
Yuki
2014/08/05 07:57:18
Ditto.
Shu Chen
2014/08/05 14:04:31
Done.
| |
| 377 input_method_id_to_switch); | |
| 378 engine = engine_map_[extension_id]; | |
| 379 IMEBridge::Get()->SetCurrentEngineHandler(engine); | |
| 380 if (engine) | |
| 381 engine->Enable(engine_id); | |
|
Yuki
2014/08/05 07:57:18
I'm uneasy with this part of code (and InputMethod
Shu Chen
2014/08/05 14:04:31
Sorry for confusion. I've changed the naming engin
| |
| 382 | |
| 384 // Change the keyboard layout to a preferred layout for the input method. | 383 // Change the keyboard layout to a preferred layout for the input method. |
| 385 if (!keyboard_->SetCurrentKeyboardLayoutByName( | 384 if (!keyboard_->SetCurrentKeyboardLayoutByName( |
| 386 current_input_method_.GetPreferredKeyboardLayout())) { | 385 current_input_method_.GetPreferredKeyboardLayout())) { |
| 387 LOG(ERROR) << "Failed to change keyboard layout to " | 386 LOG(ERROR) << "Failed to change keyboard layout to " |
| 388 << current_input_method_.GetPreferredKeyboardLayout(); | 387 << current_input_method_.GetPreferredKeyboardLayout(); |
| 389 } | 388 } |
| 390 | 389 |
| 391 // Update input method indicators (e.g. "US", "DV") in Chrome windows. | 390 // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
| 392 FOR_EACH_OBSERVER(InputMethodManager::Observer, | 391 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
| 393 observers_, | 392 observers_, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 IMEBridge::Get()->GetCurrentEngineHandler(); | 425 IMEBridge::Get()->GetCurrentEngineHandler(); |
| 427 if (engine) | 426 if (engine) |
| 428 engine->PropertyActivate(key); | 427 engine->PropertyActivate(key); |
| 429 return; | 428 return; |
| 430 } | 429 } |
| 431 | 430 |
| 432 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; | 431 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; |
| 433 } | 432 } |
| 434 | 433 |
| 435 void InputMethodManagerImpl::AddInputMethodExtension( | 434 void InputMethodManagerImpl::AddInputMethodExtension( |
| 436 const std::string& id, | 435 const std::string& extension_id, |
| 436 const InputMethodDescriptors& descriptors, | |
| 437 InputMethodEngineInterface* engine) { | 437 InputMethodEngineInterface* engine) { |
| 438 if (state_ == STATE_TERMINATING) | 438 if (state_ == STATE_TERMINATING) |
| 439 return; | 439 return; |
| 440 | 440 |
| 441 DCHECK(engine); | 441 DCHECK(engine); |
| 442 | 442 |
| 443 profile_engine_map_[GetProfile()][id] = engine; | 443 engine_map_[extension_id] = engine; |
| 444 | 444 |
| 445 if (id == current_input_method_.id()) { | 445 if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID( |
| 446 current_input_method_.id())) { | |
| 446 IMEBridge::Get()->SetCurrentEngineHandler(engine); | 447 IMEBridge::Get()->SetCurrentEngineHandler(engine); |
| 447 engine->Enable(); | 448 engine->Enable(extension_ime_util::GetEngineIDByInputMethodID( |
| 449 current_input_method_.id())); | |
| 448 } | 450 } |
| 449 | 451 |
| 450 if (extension_ime_util::IsComponentExtensionIME(id)) | 452 bool contain = false; |
| 451 return; | 453 for (size_t i = 0; i < descriptors.size(); i++) { |
| 454 const InputMethodDescriptor& descriptor = descriptors[i]; | |
| 455 const std::string& id = descriptor.id(); | |
| 456 extra_input_methods_[id] = descriptor; | |
| 457 if (Contains(enabled_extension_imes_, id)) { | |
| 458 if (!Contains(active_input_method_ids_, id)) { | |
| 459 active_input_method_ids_.push_back(id); | |
| 460 } else { | |
| 461 DVLOG(1) << "AddInputMethodExtension: already added: " | |
| 462 << id << ", " << descriptor.name(); | |
| 463 } | |
| 464 contain = true; | |
| 465 } | |
| 466 } | |
| 452 | 467 |
| 453 CHECK(extension_ime_util::IsExtensionIME(id)) | 468 // Ensure that the input method daemon is running. |
| 454 << id << "is not a valid extension input method ID"; | 469 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(); | 470 MaybeInitializeCandidateWindowController(); |
| 469 } | |
| 470 } | 471 } |
| 471 | 472 |
| 472 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { | 473 void InputMethodManagerImpl::RemoveInputMethodExtension( |
| 473 if (!extension_ime_util::IsExtensionIME(id)) | 474 const std::string& extension_id) { |
| 474 DVLOG(1) << id << " is not a valid extension input method ID."; | 475 // Removes the active input methods with |extension_id|. |
| 476 std::vector<std::string> new_active_input_method_ids_; | |
| 477 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { | |
| 478 if (extension_id != | |
| 479 extension_ime_util::GetExtensionIDFromInputMethodID( | |
| 480 active_input_method_ids_[i])) | |
| 481 new_active_input_method_ids_.push_back(active_input_method_ids_[i]); | |
| 482 } | |
| 483 active_input_method_ids_.swap(new_active_input_method_ids_); | |
| 475 | 484 |
| 476 std::vector<std::string>::iterator i = std::find( | 485 // Removes the extra input methods with |extension_id|. |
| 477 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); | 486 std::map<std::string, InputMethodDescriptor> new_extra_input_methods_; |
| 478 if (i != active_input_method_ids_.end()) | 487 for (std::map<std::string, InputMethodDescriptor>::iterator i = |
| 479 active_input_method_ids_.erase(i); | 488 extra_input_methods_.begin(); i != extra_input_methods_.end(); ++i) { |
| 480 extra_input_methods_.erase(id); | 489 if (extension_id != |
| 490 extension_ime_util::GetExtensionIDFromInputMethodID(i->first)) | |
| 491 new_extra_input_methods_[i->first] = i->second; | |
| 492 } | |
| 493 extra_input_methods_.swap(new_extra_input_methods_); | |
| 481 | 494 |
| 482 EngineMap& engine_map = profile_engine_map_[GetProfile()]; | 495 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id]) |
| 483 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map[id]) | |
| 484 IMEBridge::Get()->SetCurrentEngineHandler(NULL); | 496 IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
| 485 engine_map.erase(id); | 497 engine_map_.erase(extension_id); |
| 486 | 498 |
| 487 // No need to switch input method when terminating. | 499 // No need to switch input method when terminating. |
| 488 if (state_ != STATE_TERMINATING) { | 500 if (state_ != STATE_TERMINATING) { |
| 489 // If |current_input_method| is no longer in |active_input_method_ids_|, | 501 // If |current_input_method| is no longer in |active_input_method_ids_|, |
| 490 // switch to the first one in |active_input_method_ids_|. | 502 // switch to the first one in |active_input_method_ids_|. |
| 491 ChangeInputMethod(current_input_method_.id()); | 503 ChangeInputMethod(current_input_method_.id()); |
| 492 } | 504 } |
| 493 } | 505 } |
| 494 | 506 |
| 495 void InputMethodManagerImpl::GetInputMethodExtensions( | 507 void InputMethodManagerImpl::GetInputMethodExtensions( |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 | 870 |
| 859 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { | 871 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { |
| 860 if (candidate_window_controller_.get()) | 872 if (candidate_window_controller_.get()) |
| 861 return; | 873 return; |
| 862 | 874 |
| 863 candidate_window_controller_.reset( | 875 candidate_window_controller_.reset( |
| 864 CandidateWindowController::CreateCandidateWindowController()); | 876 CandidateWindowController::CreateCandidateWindowController()); |
| 865 candidate_window_controller_->AddObserver(this); | 877 candidate_window_controller_->AddObserver(this); |
| 866 } | 878 } |
| 867 | 879 |
| 868 Profile* InputMethodManagerImpl::GetProfile() const { | |
| 869 return ProfileManager::GetActiveUserProfile(); | |
| 870 } | |
| 871 | |
| 872 } // namespace input_method | 880 } // namespace input_method |
| 873 } // namespace chromeos | 881 } // namespace chromeos |
| OLD | NEW |