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

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: error tolerance for missing background page for key events. 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::GetEngineIDByInputMethodID(input_method_id_to_switch);
Yuki 2014/08/06 04:42:23 s/GetEngineID/GetComponentID/
Shu Chen 2014/08/06 05:45:03 Done.
378 engine = engine_map_[extension_id];
379 IMEBridge::Get()->SetCurrentEngineHandler(engine);
380 if (engine)
381 engine->Enable(component_id);
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
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 Profile* profile, 435 const std::string& extension_id,
437 const std::string& id, 436 const InputMethodDescriptors& descriptors,
438 InputMethodEngineInterface* engine) { 437 InputMethodEngineInterface* engine) {
439 if (state_ == STATE_TERMINATING) 438 if (state_ == STATE_TERMINATING)
440 return; 439 return;
441 440
442 DCHECK(engine); 441 DCHECK(engine);
443 442
444 profile_engine_map_[profile][id] = engine; 443 engine_map_[extension_id] = engine;
445 444
446 if (id == current_input_method_.id()) { 445 if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID(
446 current_input_method_.id())) {
447 IMEBridge::Get()->SetCurrentEngineHandler(engine); 447 IMEBridge::Get()->SetCurrentEngineHandler(engine);
448 engine->Enable(); 448 engine->Enable(extension_ime_util::GetEngineIDByInputMethodID(
449 current_input_method_.id()));
449 } 450 }
450 451
451 if (extension_ime_util::IsComponentExtensionIME(id)) 452 bool contain = false;
452 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: " << id << ", "
462 << descriptor.name();
463 }
464 contain = true;
465 }
466 }
453 467
454 CHECK(extension_ime_util::IsExtensionIME(id)) 468 // Ensure that the input method daemon is running.
455 << id << "is not a valid extension input method ID"; 469 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(); 470 MaybeInitializeCandidateWindowController();
470 }
471 } 471 }
472 472
473 void InputMethodManagerImpl::RemoveInputMethodExtension(Profile* profile, 473 void InputMethodManagerImpl::RemoveInputMethodExtension(
474 const std::string& id) { 474 const std::string& extension_id) {
475 if (!extension_ime_util::IsExtensionIME(id)) 475 // Removes the active input methods with |extension_id|.
Yuki 2014/08/06 04:42:23 s/Removes/Remove/ Descriptive for class/function/
Shu Chen 2014/08/06 05:45:03 Done.
476 DVLOG(1) << id << " is not a valid extension input method ID."; 476 std::vector<std::string> new_active_input_method_ids_;
Yuki 2014/08/06 04:42:23 s/ids_/ids/ This variable is a local variable, is
Shu Chen 2014/08/06 05:45:03 Done.
477 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
478 if (extension_id != extension_ime_util::GetExtensionIDFromInputMethodID(
479 active_input_method_ids_[i]))
480 new_active_input_method_ids_.push_back(active_input_method_ids_[i]);
481 }
482 active_input_method_ids_.swap(new_active_input_method_ids_);
477 483
478 std::vector<std::string>::iterator i = std::find( 484 // Removes the extra input methods with |extension_id|.
Yuki 2014/08/06 04:42:23 Ditto.
Shu Chen 2014/08/06 05:45:03 Done.
479 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); 485 std::map<std::string, InputMethodDescriptor> new_extra_input_methods_;
Yuki 2014/08/06 04:42:24 Ditto.
Shu Chen 2014/08/06 05:45:03 Done.
480 if (i != active_input_method_ids_.end()) 486 for (std::map<std::string, InputMethodDescriptor>::iterator i =
481 active_input_method_ids_.erase(i); 487 extra_input_methods_.begin();
482 extra_input_methods_.erase(id); 488 i != extra_input_methods_.end();
489 ++i) {
490 if (extension_id !=
491 extension_ime_util::GetExtensionIDFromInputMethodID(i->first))
492 new_extra_input_methods_[i->first] = i->second;
493 }
494 extra_input_methods_.swap(new_extra_input_methods_);
483 495
484 EngineMap& engine_map = profile_engine_map_[profile]; 496 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id])
485 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map[id])
486 IMEBridge::Get()->SetCurrentEngineHandler(NULL); 497 IMEBridge::Get()->SetCurrentEngineHandler(NULL);
487 engine_map.erase(id); 498 engine_map_.erase(extension_id);
488 499
489 // No need to switch input method when terminating. 500 // No need to switch input method when terminating.
490 if (state_ != STATE_TERMINATING) { 501 if (state_ != STATE_TERMINATING) {
491 // If |current_input_method| is no longer in |active_input_method_ids_|, 502 // If |current_input_method| is no longer in |active_input_method_ids_|,
492 // switch to the first one in |active_input_method_ids_|. 503 // switch to the first one in |active_input_method_ids_|.
493 ChangeInputMethod(current_input_method_.id()); 504 ChangeInputMethod(current_input_method_.id());
494 } 505 }
495 } 506 }
496 507
497 void InputMethodManagerImpl::GetInputMethodExtensions( 508 void InputMethodManagerImpl::GetInputMethodExtensions(
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 871
861 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { 872 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
862 if (candidate_window_controller_.get()) 873 if (candidate_window_controller_.get())
863 return; 874 return;
864 875
865 candidate_window_controller_.reset( 876 candidate_window_controller_.reset(
866 CandidateWindowController::CreateCandidateWindowController()); 877 CandidateWindowController::CreateCandidateWindowController());
867 candidate_window_controller_->AddObserver(this); 878 candidate_window_controller_->AddObserver(this);
868 } 879 }
869 880
870 Profile* InputMethodManagerImpl::GetProfile() const {
871 return ProfileManager::GetActiveUserProfile();
872 }
873
874 } // namespace input_method 881 } // namespace input_method
875 } // namespace chromeos 882 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698