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