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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 433163005: Refactoring for InputMethodEngine and InputMethodEventRouter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed browser_tests: ExtensionApiTest.InputImeApiBasic Created 6 years, 4 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 (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
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
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 const std::string& extension_id =
374 extension_ime_util::GetExtensionIDFromInputMethodID(
375 input_method_id_to_switch);
376 const std::string& component_id =
377 extension_ime_util::GetComponentIDByInputMethodID(
378 input_method_id_to_switch);
379 engine = engine_map_[extension_id];
380 IMEBridge::Get()->SetCurrentEngineHandler(engine);
381 if (engine)
382 engine->Enable(component_id);
383
384 // Change the keyboard layout to a preferred layout for the input method. 384 // Change the keyboard layout to a preferred layout for the input method.
385 if (!keyboard_->SetCurrentKeyboardLayoutByName( 385 if (!keyboard_->SetCurrentKeyboardLayoutByName(
386 current_input_method_.GetPreferredKeyboardLayout())) { 386 current_input_method_.GetPreferredKeyboardLayout())) {
387 LOG(ERROR) << "Failed to change keyboard layout to " 387 LOG(ERROR) << "Failed to change keyboard layout to "
388 << current_input_method_.GetPreferredKeyboardLayout(); 388 << current_input_method_.GetPreferredKeyboardLayout();
389 } 389 }
390 390
391 // Update input method indicators (e.g. "US", "DV") in Chrome windows. 391 // Update input method indicators (e.g. "US", "DV") in Chrome windows.
392 FOR_EACH_OBSERVER(InputMethodManager::Observer, 392 FOR_EACH_OBSERVER(InputMethodManager::Observer,
393 observers_, 393 observers_,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 IMEBridge::Get()->GetCurrentEngineHandler(); 426 IMEBridge::Get()->GetCurrentEngineHandler();
427 if (engine) 427 if (engine)
428 engine->PropertyActivate(key); 428 engine->PropertyActivate(key);
429 return; 429 return;
430 } 430 }
431 431
432 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; 432 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key;
433 } 433 }
434 434
435 void InputMethodManagerImpl::AddInputMethodExtension( 435 void InputMethodManagerImpl::AddInputMethodExtension(
436 Profile* profile, 436 const std::string& extension_id,
437 const std::string& id, 437 const InputMethodDescriptors& descriptors,
438 InputMethodEngineInterface* engine) { 438 InputMethodEngineInterface* engine) {
439 if (state_ == STATE_TERMINATING) 439 if (state_ == STATE_TERMINATING)
440 return; 440 return;
441 441
442 DCHECK(engine); 442 DCHECK(engine);
443 443
444 profile_engine_map_[profile][id] = engine; 444 engine_map_[extension_id] = engine;
445 445
446 if (id == current_input_method_.id()) { 446 if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID(
447 current_input_method_.id())) {
447 IMEBridge::Get()->SetCurrentEngineHandler(engine); 448 IMEBridge::Get()->SetCurrentEngineHandler(engine);
448 engine->Enable(); 449 engine->Enable(extension_ime_util::GetComponentIDByInputMethodID(
450 current_input_method_.id()));
449 } 451 }
450 452
451 if (extension_ime_util::IsComponentExtensionIME(id)) 453 bool contain = false;
452 return; 454 for (size_t i = 0; i < descriptors.size(); i++) {
455 const InputMethodDescriptor& descriptor = descriptors[i];
456 const std::string& id = descriptor.id();
457 extra_input_methods_[id] = descriptor;
458 if (Contains(enabled_extension_imes_, id)) {
459 if (!Contains(active_input_method_ids_, id)) {
460 active_input_method_ids_.push_back(id);
461 } else {
462 DVLOG(1) << "AddInputMethodExtension: already added: " << id << ", "
463 << descriptor.name();
464 }
465 contain = true;
466 }
467 }
453 468
454 CHECK(extension_ime_util::IsExtensionIME(id)) 469 // Ensure that the input method daemon is running.
455 << id << "is not a valid extension input method ID"; 470 if (contain)
456
457 const InputMethodDescriptor& descriptor = engine->GetDescriptor();
458 extra_input_methods_[id] = descriptor;
459
460 if (Contains(enabled_extension_imes_, id)) {
461 if (!Contains(active_input_method_ids_, id)) {
462 active_input_method_ids_.push_back(id);
463 } else {
464 DVLOG(1) << "AddInputMethodExtension: alread added: "
465 << id << ", " << descriptor.name();
466 }
467
468 // Ensure that the input method daemon is running.
469 MaybeInitializeCandidateWindowController(); 471 MaybeInitializeCandidateWindowController();
470 }
471 } 472 }
472 473
473 void InputMethodManagerImpl::RemoveInputMethodExtension(Profile* profile, 474 void InputMethodManagerImpl::RemoveInputMethodExtension(
474 const std::string& id) { 475 const std::string& extension_id) {
475 if (!extension_ime_util::IsExtensionIME(id)) 476 // Remove the active input methods with |extension_id|.
476 DVLOG(1) << id << " is not a valid extension input method ID."; 477 std::vector<std::string> new_active_input_method_ids;
478 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
479 if (extension_id != 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);
477 484
478 std::vector<std::string>::iterator i = std::find( 485 // Remove the extra input methods with |extension_id|.
479 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); 486 std::map<std::string, InputMethodDescriptor> new_extra_input_methods;
480 if (i != active_input_method_ids_.end()) 487 for (std::map<std::string, InputMethodDescriptor>::iterator i =
481 active_input_method_ids_.erase(i); 488 extra_input_methods_.begin();
482 extra_input_methods_.erase(id); 489 i != extra_input_methods_.end();
490 ++i) {
491 if (extension_id !=
492 extension_ime_util::GetExtensionIDFromInputMethodID(i->first))
493 new_extra_input_methods[i->first] = i->second;
494 }
495 extra_input_methods_.swap(new_extra_input_methods);
483 496
484 EngineMap& engine_map = profile_engine_map_[profile]; 497 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id])
485 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map[id])
486 IMEBridge::Get()->SetCurrentEngineHandler(NULL); 498 IMEBridge::Get()->SetCurrentEngineHandler(NULL);
487 engine_map.erase(id); 499 engine_map_.erase(extension_id);
488 500
489 // No need to switch input method when terminating. 501 // No need to switch input method when terminating.
490 if (state_ != STATE_TERMINATING) { 502 if (state_ != STATE_TERMINATING) {
491 // If |current_input_method| is no longer in |active_input_method_ids_|, 503 // If |current_input_method| is no longer in |active_input_method_ids_|,
492 // switch to the first one in |active_input_method_ids_|. 504 // switch to the first one in |active_input_method_ids_|.
493 ChangeInputMethod(current_input_method_.id()); 505 ChangeInputMethod(current_input_method_.id());
494 } 506 }
495 } 507 }
496 508
497 void InputMethodManagerImpl::GetInputMethodExtensions( 509 void InputMethodManagerImpl::GetInputMethodExtensions(
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 872
861 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { 873 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
862 if (candidate_window_controller_.get()) 874 if (candidate_window_controller_.get())
863 return; 875 return;
864 876
865 candidate_window_controller_.reset( 877 candidate_window_controller_.reset(
866 CandidateWindowController::CreateCandidateWindowController()); 878 CandidateWindowController::CreateCandidateWindowController());
867 candidate_window_controller_->AddObserver(this); 879 candidate_window_controller_->AddObserver(this);
868 } 880 }
869 881
870 Profile* InputMethodManagerImpl::GetProfile() const {
871 return ProfileManager::GetActiveUserProfile();
872 }
873
874 } // namespace input_method 882 } // namespace input_method
875 } // namespace chromeos 883 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698