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

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

Issue 190033005: [IME] Removes the duplicated IMEs in chrome://settings/languages, and support async component IMEs … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 case STATE_TERMINATING: { 105 case STATE_TERMINATING: {
106 if (candidate_window_controller_.get()) 106 if (candidate_window_controller_.get())
107 candidate_window_controller_.reset(); 107 candidate_window_controller_.reset();
108 break; 108 break;
109 } 109 }
110 } 110 }
111 } 111 }
112 112
113 scoped_ptr<InputMethodDescriptors> 113 scoped_ptr<InputMethodDescriptors>
114 InputMethodManagerImpl::GetSupportedInputMethods() const { 114 InputMethodManagerImpl::GetSupportedInputMethods() const {
115 return whitelist_.GetSupportedInputMethods(); 115 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) {
116 return whitelist_.GetSupportedInputMethods();
117 }
118 // Returns empty list because all the supported imes have been migrated to
119 // component extension imes.
120 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass();
116 } 121 }
117 122
118 scoped_ptr<InputMethodDescriptors> 123 scoped_ptr<InputMethodDescriptors>
119 InputMethodManagerImpl::GetActiveInputMethods() const { 124 InputMethodManagerImpl::GetActiveInputMethods() const {
120 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); 125 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors);
121 // Build the active input method descriptors from the active input 126 // Build the active input method descriptors from the active input
122 // methods cache |active_input_method_ids_|. 127 // methods cache |active_input_method_ids_|.
123 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 128 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
124 const std::string& input_method_id = active_input_method_ids_[i]; 129 const std::string& input_method_id = active_input_method_ids_[i];
125 const InputMethodDescriptor* descriptor = 130 const InputMethodDescriptor* descriptor =
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 244 }
240 245
241 if (!Contains(*new_active_input_method_ids, input_method_id)) 246 if (!Contains(*new_active_input_method_ids, input_method_id))
242 new_active_input_method_ids->push_back(input_method_id); 247 new_active_input_method_ids->push_back(input_method_id);
243 248
244 return true; 249 return true;
245 } 250 }
246 251
247 // Starts or stops the system input method framework as needed. 252 // Starts or stops the system input method framework as needed.
248 void InputMethodManagerImpl::ReconfigureIMFramework() { 253 void InputMethodManagerImpl::ReconfigureIMFramework() {
249 if (component_extension_ime_manager_->IsInitialized()) 254 LoadNecessaryComponentExtensions();
250 LoadNecessaryComponentExtensions();
251
252 const bool need_engine =
253 !ContainsOnlyKeyboardLayout(active_input_method_ids_);
254 255
255 // Initialize candidate window controller and widgets such as 256 // Initialize candidate window controller and widgets such as
256 // candidate window, infolist and mode indicator. Note, mode 257 // candidate window, infolist and mode indicator. Note, mode
257 // indicator is used by only keyboard layout input methods. 258 // indicator is used by only keyboard layout input methods.
258 if (need_engine || active_input_method_ids_.size() > 1) 259 MaybeInitializeCandidateWindowController();
259 MaybeInitializeCandidateWindowController();
260 } 260 }
261 261
262 bool InputMethodManagerImpl::EnableInputMethod( 262 bool InputMethodManagerImpl::EnableInputMethod(
263 const std::string& input_method_id) { 263 const std::string& input_method_id) {
264 if (!EnableInputMethodImpl(input_method_id, &active_input_method_ids_)) 264 if (!EnableInputMethodImpl(input_method_id, &active_input_method_ids_))
265 return false; 265 return false;
266 266
267 ReconfigureIMFramework(); 267 ReconfigureIMFramework();
268 return true; 268 return true;
269 } 269 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if (candidate_window_controller_.get()) 345 if (candidate_window_controller_.get())
346 candidate_window_controller_->Hide(); 346 candidate_window_controller_->Hide();
347 347
348 // Disable the current engine handler. 348 // Disable the current engine handler.
349 IMEEngineHandlerInterface* engine = 349 IMEEngineHandlerInterface* engine =
350 IMEBridge::Get()->GetCurrentEngineHandler(); 350 IMEBridge::Get()->GetCurrentEngineHandler();
351 if (engine) 351 if (engine)
352 engine->Disable(); 352 engine->Disable();
353 353
354 // Configure the next engine handler. 354 // Configure the next engine handler.
355 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { 355 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) &&
356 !extension_ime_util::IsKeyboardLayoutExtension(
357 input_method_id_to_switch)) {
356 IMEBridge::Get()->SetCurrentEngineHandler(NULL); 358 IMEBridge::Get()->SetCurrentEngineHandler(NULL);
357 } else { 359 } else {
358 IMEEngineHandlerInterface* next_engine = 360 IMEEngineHandlerInterface* next_engine =
359 IMEBridge::Get()->SetCurrentEngineHandlerById( 361 IMEBridge::Get()->SetCurrentEngineHandlerById(
360 input_method_id_to_switch); 362 input_method_id_to_switch);
361 363
362 if (next_engine) 364 if (next_engine)
363 next_engine->Enable(); 365 next_engine->Enable();
364 } 366 }
365 367
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 ChangeInputMethodInternal(pending_input_method_, false); 420 ChangeInputMethodInternal(pending_input_method_, false);
419 } 421 }
420 422
421 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { 423 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() {
422 if (!component_extension_ime_manager_->IsInitialized()) 424 if (!component_extension_ime_manager_->IsInitialized())
423 return; 425 return;
424 // Load component extensions but also update |active_input_method_ids_| as 426 // Load component extensions but also update |active_input_method_ids_| as
425 // some component extension IMEs may have been removed from the Chrome OS 427 // some component extension IMEs may have been removed from the Chrome OS
426 // image. If specified component extension IME no longer exists, falling back 428 // image. If specified component extension IME no longer exists, falling back
427 // to an existing IME. 429 // to an existing IME.
428 std::vector<std::string> unfiltered_input_method_ids = 430 std::vector<std::string> unfiltered_input_method_ids;
429 active_input_method_ids_; 431 unfiltered_input_method_ids.swap(active_input_method_ids_);
430 active_input_method_ids_.clear();
431 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) { 432 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) {
432 if (!extension_ime_util::IsComponentExtensionIME( 433 if (!extension_ime_util::IsComponentExtensionIME(
433 unfiltered_input_method_ids[i])) { 434 unfiltered_input_method_ids[i])) {
434 // Legacy IMEs or xkb layouts are alwayes active. 435 // Legacy IMEs or xkb layouts are alwayes active.
435 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 436 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]);
436 } else if (component_extension_ime_manager_->IsWhitelisted( 437 } else if (component_extension_ime_manager_->IsWhitelisted(
437 unfiltered_input_method_ids[i])) { 438 unfiltered_input_method_ids[i])) {
438 component_extension_ime_manager_->LoadComponentExtensionIME( 439 component_extension_ime_manager_->LoadComponentExtensionIME(
439 unfiltered_input_method_ids[i]); 440 unfiltered_input_method_ids[i]);
440 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 441 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]);
441 } 442 }
442 } 443 }
444 // TODO(shuchen): move this call in ComponentExtensionIMEManager.
445 component_extension_ime_manager_->NotifyInitialized();
443 } 446 }
444 447
445 void InputMethodManagerImpl::ActivateInputMethodMenuItem( 448 void InputMethodManagerImpl::ActivateInputMethodMenuItem(
446 const std::string& key) { 449 const std::string& key) {
447 DCHECK(!key.empty()); 450 DCHECK(!key.empty());
448 451
449 if (ash::ime::InputMethodMenuManager::GetInstance()-> 452 if (ash::ime::InputMethodMenuManager::GetInstance()->
450 HasInputMethodMenuItemForKey(key)) { 453 HasInputMethodMenuItemForKey(key)) {
451 IMEEngineHandlerInterface* engine = 454 IMEEngineHandlerInterface* engine =
452 IMEBridge::Get()->GetCurrentEngineHandler(); 455 IMEBridge::Get()->GetCurrentEngineHandler();
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 active_input_method_ids_ = saved_active_input_method_ids_; 831 active_input_method_ids_ = saved_active_input_method_ids_;
829 832
830 ChangeInputMethod(current_input_method_.id()); 833 ChangeInputMethod(current_input_method_.id());
831 } 834 }
832 835
833 bool InputMethodManagerImpl::InputMethodIsActivated( 836 bool InputMethodManagerImpl::InputMethodIsActivated(
834 const std::string& input_method_id) { 837 const std::string& input_method_id) {
835 return Contains(active_input_method_ids_, input_method_id); 838 return Contains(active_input_method_ids_, input_method_id);
836 } 839 }
837 840
838 bool InputMethodManagerImpl::ContainsOnlyKeyboardLayout(
839 const std::vector<std::string>& value) {
840 for (size_t i = 0; i < value.size(); ++i) {
841 if (!InputMethodUtil::IsKeyboardLayout(value[i]))
842 return false;
843 }
844 return true;
845 }
846
847 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { 841 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
848 if (candidate_window_controller_.get()) 842 if (candidate_window_controller_.get())
849 return; 843 return;
850 844
851 candidate_window_controller_.reset( 845 candidate_window_controller_.reset(
852 CandidateWindowController::CreateCandidateWindowController()); 846 CandidateWindowController::CreateCandidateWindowController());
853 candidate_window_controller_->AddObserver(this); 847 candidate_window_controller_->AddObserver(this);
854 } 848 }
855 849
856 } // namespace input_method 850 } // namespace input_method
857 } // namespace chromeos 851 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698