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 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 Loading... | |
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 if (component_extension_ime_manager_->IsInitialized()) |
Yuki
2014/03/07 07:47:04
We don't need this conditional. LoadNecessaryComp
Shu Chen
2014/03/07 08:24:09
Done.
| |
250 LoadNecessaryComponentExtensions(); | 255 LoadNecessaryComponentExtensions(); |
251 | 256 |
252 const bool need_engine = | |
253 !ContainsOnlyKeyboardLayout(active_input_method_ids_); | |
254 | |
255 // Initialize candidate window controller and widgets such as | 257 // Initialize candidate window controller and widgets such as |
256 // candidate window, infolist and mode indicator. Note, mode | 258 // candidate window, infolist and mode indicator. Note, mode |
257 // indicator is used by only keyboard layout input methods. | 259 // indicator is used by only keyboard layout input methods. |
258 if (need_engine || active_input_method_ids_.size() > 1) | 260 MaybeInitializeCandidateWindowController(); |
259 MaybeInitializeCandidateWindowController(); | |
260 } | 261 } |
261 | 262 |
262 bool InputMethodManagerImpl::EnableInputMethod( | 263 bool InputMethodManagerImpl::EnableInputMethod( |
263 const std::string& input_method_id) { | 264 const std::string& input_method_id) { |
264 if (!EnableInputMethodImpl(input_method_id, &active_input_method_ids_)) | 265 if (!EnableInputMethodImpl(input_method_id, &active_input_method_ids_)) |
265 return false; | 266 return false; |
266 | 267 |
267 ReconfigureIMFramework(); | 268 ReconfigureIMFramework(); |
268 return true; | 269 return true; |
269 } | 270 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 if (candidate_window_controller_.get()) | 346 if (candidate_window_controller_.get()) |
346 candidate_window_controller_->Hide(); | 347 candidate_window_controller_->Hide(); |
347 | 348 |
348 // Disable the current engine handler. | 349 // Disable the current engine handler. |
349 IMEEngineHandlerInterface* engine = | 350 IMEEngineHandlerInterface* engine = |
350 IMEBridge::Get()->GetCurrentEngineHandler(); | 351 IMEBridge::Get()->GetCurrentEngineHandler(); |
351 if (engine) | 352 if (engine) |
352 engine->Disable(); | 353 engine->Disable(); |
353 | 354 |
354 // Configure the next engine handler. | 355 // Configure the next engine handler. |
355 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { | 356 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) && |
357 !extension_ime_util::IsKeyboardLayoutExtension( | |
358 input_method_id_to_switch)) { | |
356 IMEBridge::Get()->SetCurrentEngineHandler(NULL); | 359 IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
357 } else { | 360 } else { |
358 IMEEngineHandlerInterface* next_engine = | 361 IMEEngineHandlerInterface* next_engine = |
359 IMEBridge::Get()->SetCurrentEngineHandlerById( | 362 IMEBridge::Get()->SetCurrentEngineHandlerById( |
360 input_method_id_to_switch); | 363 input_method_id_to_switch); |
361 | 364 |
362 if (next_engine) | 365 if (next_engine) |
363 next_engine->Enable(); | 366 next_engine->Enable(); |
364 } | 367 } |
365 | 368 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 } | 409 } |
407 | 410 |
408 void InputMethodManagerImpl::OnComponentExtensionInitialized( | 411 void InputMethodManagerImpl::OnComponentExtensionInitialized( |
409 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 412 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
410 DCHECK(thread_checker_.CalledOnValidThread()); | 413 DCHECK(thread_checker_.CalledOnValidThread()); |
411 component_extension_ime_manager_->Initialize(delegate.Pass()); | 414 component_extension_ime_manager_->Initialize(delegate.Pass()); |
412 util_.SetComponentExtensions( | 415 util_.SetComponentExtensions( |
413 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor()); | 416 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor()); |
414 | 417 |
415 LoadNecessaryComponentExtensions(); | 418 LoadNecessaryComponentExtensions(); |
419 component_extension_ime_manager_->NotifyInitialized(); | |
Yuki
2014/03/07 07:47:04
In general, This sort of methods (NotifyFoobar())
Shu Chen
2014/03/07 08:24:09
This NotifyInitialized() should be called only onc
Yuki
2014/03/07 09:02:28
Then, could you add a flag inside ComponentExtensi
| |
416 | 420 |
417 if (!pending_input_method_.empty()) | 421 if (!pending_input_method_.empty()) |
418 ChangeInputMethodInternal(pending_input_method_, false); | 422 ChangeInputMethodInternal(pending_input_method_, false); |
419 } | 423 } |
420 | 424 |
421 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { | 425 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { |
422 if (!component_extension_ime_manager_->IsInitialized()) | 426 if (!component_extension_ime_manager_->IsInitialized()) |
423 return; | 427 return; |
424 // Load component extensions but also update |active_input_method_ids_| as | 428 // Load component extensions but also update |active_input_method_ids_| as |
425 // some component extension IMEs may have been removed from the Chrome OS | 429 // some component extension IMEs may have been removed from the Chrome OS |
426 // image. If specified component extension IME no longer exists, falling back | 430 // image. If specified component extension IME no longer exists, falling back |
427 // to an existing IME. | 431 // to an existing IME. |
428 std::vector<std::string> unfiltered_input_method_ids = | 432 std::vector<std::string> unfiltered_input_method_ids = |
Yuki
2014/03/07 07:47:04
Just a nit:
std::vector unfiltered_ids; // empty
Shu Chen
2014/03/07 08:24:09
Done.
| |
429 active_input_method_ids_; | 433 active_input_method_ids_; |
430 active_input_method_ids_.clear(); | 434 active_input_method_ids_.clear(); |
431 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) { | 435 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) { |
432 if (!extension_ime_util::IsComponentExtensionIME( | 436 if (!extension_ime_util::IsComponentExtensionIME( |
433 unfiltered_input_method_ids[i])) { | 437 unfiltered_input_method_ids[i])) { |
434 // Legacy IMEs or xkb layouts are alwayes active. | 438 // Legacy IMEs or xkb layouts are alwayes active. |
435 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); | 439 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
436 } else if (component_extension_ime_manager_->IsWhitelisted( | 440 } else if (component_extension_ime_manager_->IsWhitelisted( |
437 unfiltered_input_method_ids[i])) { | 441 unfiltered_input_method_ids[i])) { |
438 component_extension_ime_manager_->LoadComponentExtensionIME( | 442 component_extension_ime_manager_->LoadComponentExtensionIME( |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 active_input_method_ids_ = saved_active_input_method_ids_; | 832 active_input_method_ids_ = saved_active_input_method_ids_; |
829 | 833 |
830 ChangeInputMethod(current_input_method_.id()); | 834 ChangeInputMethod(current_input_method_.id()); |
831 } | 835 } |
832 | 836 |
833 bool InputMethodManagerImpl::InputMethodIsActivated( | 837 bool InputMethodManagerImpl::InputMethodIsActivated( |
834 const std::string& input_method_id) { | 838 const std::string& input_method_id) { |
835 return Contains(active_input_method_ids_, input_method_id); | 839 return Contains(active_input_method_ids_, input_method_id); |
836 } | 840 } |
837 | 841 |
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() { | 842 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { |
848 if (candidate_window_controller_.get()) | 843 if (candidate_window_controller_.get()) |
849 return; | 844 return; |
850 | 845 |
851 candidate_window_controller_.reset( | 846 candidate_window_controller_.reset( |
852 CandidateWindowController::CreateCandidateWindowController()); | 847 CandidateWindowController::CreateCandidateWindowController()); |
853 candidate_window_controller_->AddObserver(this); | 848 candidate_window_controller_->AddObserver(this); |
854 } | 849 } |
855 | 850 |
856 } // namespace input_method | 851 } // namespace input_method |
857 } // namespace chromeos | 852 } // namespace chromeos |
OLD | NEW |