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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); | 284 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); |
285 DCHECK(!input_methods->empty()); | 285 DCHECK(!input_methods->empty()); |
286 input_method_id_to_switch = input_methods->at(0).id(); | 286 input_method_id_to_switch = input_methods->at(0).id(); |
287 if (!input_method_id.empty()) { | 287 if (!input_method_id.empty()) { |
288 DVLOG(1) << "Can't change the current input method to " | 288 DVLOG(1) << "Can't change the current input method to " |
289 << input_method_id << " since the engine is not enabled. " | 289 << input_method_id << " since the engine is not enabled. " |
290 << "Switch to " << input_method_id_to_switch << " instead."; | 290 << "Switch to " << input_method_id_to_switch << " instead."; |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 if (!component_extension_ime_manager_->IsInitialized()) { | 294 if (!component_extension_ime_manager_->IsInitialized() && |
295 !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { | |
295 // We can't change input method before the initialization of | 296 // We can't change input method before the initialization of |
296 // component extension ime manager. ChangeInputMethod will be | 297 // component extension ime manager. ChangeInputMethod will be |
297 // called with |pending_input_method_| when the initialization is | 298 // called with |pending_input_method_| when the initialization is |
298 // done. | 299 // done. |
299 pending_input_method_ = input_method_id_to_switch; | 300 pending_input_method_ = input_method_id_to_switch; |
300 return false; | 301 return false; |
301 } | 302 } |
302 | |
303 pending_input_method_.clear(); | 303 pending_input_method_.clear(); |
304 IBusEngineHandlerInterface* engine = | |
305 IBusBridge::Get()->GetCurrentEngineHandler(); | |
306 | 304 |
307 // Hide candidate window and info list. | 305 // Hide candidate window and info list. |
308 if (candidate_window_controller_.get()) | 306 if (candidate_window_controller_.get()) |
309 candidate_window_controller_->Hide(); | 307 candidate_window_controller_->Hide(); |
310 | 308 |
311 const std::string current_input_method_id = current_input_method_.id(); | 309 // Disable the current engine handler. |
310 IBusEngineHandlerInterface* engine = | |
311 IBusBridge::Get()->GetCurrentEngineHandler(); | |
312 if (engine) | |
313 engine->Disable(); | |
314 | |
315 // Configure the next engine handler. | |
312 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { | 316 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { |
313 if (engine) { | 317 IBusBridge::Get()->SetCurrentEngineHandler(NULL); |
314 engine->Disable(); | |
315 IBusBridge::Get()->SetCurrentEngineHandler(NULL); | |
316 } | |
317 } else { | 318 } else { |
318 // Disable the current engine and enable the next engine. | |
319 if (engine) | |
320 engine->Disable(); | |
321 | |
322 IBusEngineHandlerInterface* next_engine = | 319 IBusEngineHandlerInterface* next_engine = |
323 IBusBridge::Get()->SetCurrentEngineHandlerById( | 320 IBusBridge::Get()->SetCurrentEngineHandlerById( |
324 input_method_id_to_switch); | 321 input_method_id_to_switch); |
325 | 322 |
326 if (next_engine) | 323 if (next_engine) |
327 next_engine->Enable(); | 324 next_engine->Enable(); |
328 } | 325 } |
329 | 326 |
330 if (current_input_method_id != input_method_id_to_switch) { | 327 // TODO(komatsu): Check if it is necessary to perform the above routine |
328 // when the current input method is equal to |input_method_id_to_swich|. | |
329 if (current_input_method_.id() != input_method_id_to_switch) { | |
Seigo Nonaka
2013/12/19 03:41:12
How about remove this condition?
This condition c
Hiro Komatsu
2013/12/19 04:32:04
This can be false when the sanity check from line:
| |
331 // Clear property list. Property list would be updated by | 330 // Clear property list. Property list would be updated by |
332 // extension IMEs via InputMethodEngineIBus::(Set|Update)MenuItems. | 331 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. |
333 // If the current input method is a keyboard layout, empty | 332 // If the current input method is a keyboard layout, empty |
334 // properties are sufficient. | 333 // properties are sufficient. |
335 const InputMethodPropertyList empty_property_list; | 334 const InputMethodPropertyList empty_property_list; |
336 SetCurrentInputMethodProperties(empty_property_list); | 335 SetCurrentInputMethodProperties(empty_property_list); |
337 | 336 |
338 const InputMethodDescriptor* descriptor = NULL; | 337 const InputMethodDescriptor* descriptor = NULL; |
339 if (!extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { | 338 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { |
339 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != | |
340 extra_input_methods_.end()); | |
341 descriptor = &(extra_input_methods_[input_method_id_to_switch]); | |
342 } else { | |
340 descriptor = | 343 descriptor = |
341 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 344 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
342 } else { | |
343 std::map<std::string, InputMethodDescriptor>::const_iterator i = | |
344 extra_input_methods_.find(input_method_id_to_switch); | |
345 DCHECK(i != extra_input_methods_.end()); | |
346 descriptor = &(i->second); | |
347 } | 345 } |
348 DCHECK(descriptor); | 346 DCHECK(descriptor); |
349 | 347 |
350 previous_input_method_ = current_input_method_; | 348 previous_input_method_ = current_input_method_; |
351 current_input_method_ = *descriptor; | 349 current_input_method_ = *descriptor; |
352 } | 350 } |
353 | 351 |
354 // Change the keyboard layout to a preferred layout for the input method. | 352 // Change the keyboard layout to a preferred layout for the input method. |
355 if (!xkeyboard_->SetCurrentKeyboardLayoutByName( | 353 if (!xkeyboard_->SetCurrentKeyboardLayoutByName( |
356 current_input_method_.GetPreferredKeyboardLayout())) { | 354 current_input_method_.GetPreferredKeyboardLayout())) { |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 if (iter != input_method_ids.end()) | 659 if (iter != input_method_ids.end()) |
662 ++iter; | 660 ++iter; |
663 if (iter == input_method_ids.end()) | 661 if (iter == input_method_ids.end()) |
664 iter = input_method_ids.begin(); | 662 iter = input_method_ids.begin(); |
665 ChangeInputMethodInternal(*iter, true); | 663 ChangeInputMethodInternal(*iter, true); |
666 } | 664 } |
667 | 665 |
668 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { | 666 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { |
669 if (current_input_method_.id().empty()) | 667 if (current_input_method_.id().empty()) |
670 return InputMethodUtil::GetFallbackInputMethodDescriptor(); | 668 return InputMethodUtil::GetFallbackInputMethodDescriptor(); |
669 | |
671 return current_input_method_; | 670 return current_input_method_; |
672 } | 671 } |
673 | 672 |
674 InputMethodPropertyList | 673 InputMethodPropertyList |
675 InputMethodManagerImpl::GetCurrentInputMethodProperties() const { | 674 InputMethodManagerImpl::GetCurrentInputMethodProperties() const { |
676 // This check is necessary since an IME property (e.g. for Pinyin) might be | 675 // This check is necessary since an IME property (e.g. for Pinyin) might be |
677 // sent from ibus-daemon AFTER the current input method is switched to XKB. | 676 // sent from ibus-daemon AFTER the current input method is switched to XKB. |
678 if (InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id())) | 677 if (InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id())) |
679 return InputMethodPropertyList(); // Empty list. | 678 return InputMethodPropertyList(); // Empty list. |
680 return property_list_; | 679 return property_list_; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 if (candidate_window_controller_.get()) | 816 if (candidate_window_controller_.get()) |
818 return; | 817 return; |
819 | 818 |
820 candidate_window_controller_.reset( | 819 candidate_window_controller_.reset( |
821 CandidateWindowController::CreateCandidateWindowController()); | 820 CandidateWindowController::CreateCandidateWindowController()); |
822 candidate_window_controller_->AddObserver(this); | 821 candidate_window_controller_->AddObserver(this); |
823 } | 822 } |
824 | 823 |
825 } // namespace input_method | 824 } // namespace input_method |
826 } // namespace chromeos | 825 } // namespace chromeos |
OLD | NEW |