OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include <glib.h> | 9 #include <glib.h> |
10 | 10 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // Before calling FlushImeConfig(), start input method process if necessary. | 377 // Before calling FlushImeConfig(), start input method process if necessary. |
378 MaybeStartInputMethodDaemon(section, config_name, value); | 378 MaybeStartInputMethodDaemon(section, config_name, value); |
379 | 379 |
380 const ConfigKeyType key = std::make_pair(section, config_name); | 380 const ConfigKeyType key = std::make_pair(section, config_name); |
381 current_config_values_[key] = value; | 381 current_config_values_[key] = value; |
382 if (ime_connected_) { | 382 if (ime_connected_) { |
383 pending_config_requests_[key] = value; | 383 pending_config_requests_[key] = value; |
384 FlushImeConfig(); | 384 FlushImeConfig(); |
385 } | 385 } |
386 | 386 |
387 // Stop input method process if necessary. | 387 if (section == language_prefs::kGeneralSectionName && |
388 MaybeStopInputMethodDaemon(section, config_name, value); | 388 config_name == language_prefs::kPreloadEnginesConfigName) { |
| 389 // Stop input method process if necessary. |
| 390 MaybeStopInputMethodDaemon(); |
| 391 } |
389 // Change the current keyboard layout if necessary. | 392 // Change the current keyboard layout if necessary. |
390 MaybeChangeCurrentKeyboardLayout(section, config_name, value); | 393 MaybeChangeCurrentKeyboardLayout(section, config_name, value); |
391 return pending_config_requests_.empty(); | 394 return pending_config_requests_.empty(); |
392 } | 395 } |
393 | 396 |
394 // TODO(yusukes): Support input method specific hotkeys. | 397 // TODO(yusukes): Support input method specific hotkeys. |
395 virtual void AddActiveIme(const std::string& id, | 398 virtual void AddActiveIme(const std::string& id, |
396 const std::string& name, | 399 const std::string& name, |
397 const std::vector<std::string>& layouts, | 400 const std::vector<std::string>& layouts, |
398 const std::string& language) { | 401 const std::string& language) { |
399 std::string virtual_layouts = JoinString(layouts, ','); | 402 std::string virtual_layouts = JoinString(layouts, ','); |
400 | 403 |
401 extra_input_method_ids_[id] = ibus_controller_->CreateInputMethodDescriptor( | 404 extra_input_method_ids_[id] = ibus_controller_->CreateInputMethodDescriptor( |
402 id, name, virtual_layouts, language); | 405 id, name, virtual_layouts, language); |
403 active_input_method_ids_.push_back(id); | 406 active_input_method_ids_.push_back(id); |
404 // TODO(yusukes): Call UpdateInputMethodSpecificHotkeys() here once IME | 407 // TODO(yusukes): Call UpdateInputMethodSpecificHotkeys() here once IME |
405 // extension supports hotkeys. | 408 // extension supports hotkeys. |
| 409 |
| 410 // Ensure that the input method daemon is running. |
| 411 StartInputMethodDaemon(); |
406 } | 412 } |
407 | 413 |
408 virtual void RemoveActiveIme(const std::string& id) { | 414 virtual void RemoveActiveIme(const std::string& id) { |
409 std::vector<std::string>::iterator ix = | 415 std::vector<std::string>::iterator ix = |
410 std::find(active_input_method_ids_.begin(), | 416 std::find(active_input_method_ids_.begin(), |
411 active_input_method_ids_.end(), | 417 active_input_method_ids_.end(), |
412 id); | 418 id); |
413 if (ix != active_input_method_ids_.end()) { | 419 if (ix != active_input_method_ids_.end()) { |
414 active_input_method_ids_.erase(ix); | 420 active_input_method_ids_.erase(ix); |
415 } | 421 } |
416 extra_input_method_ids_.erase(id); | 422 extra_input_method_ids_.erase(id); |
417 // TODO(yusukes): Call UpdateInputMethodSpecificHotkeys() here once IME | 423 // TODO(yusukes): Call UpdateInputMethodSpecificHotkeys() here once IME |
418 // extension supports hotkeys. | 424 // extension supports hotkeys. |
| 425 |
| 426 // Stop the IME daemon if needed. |
| 427 MaybeStopInputMethodDaemon(); |
419 } | 428 } |
420 | 429 |
421 virtual bool GetExtraDescriptor(const std::string& id, | 430 virtual bool GetExtraDescriptor(const std::string& id, |
422 InputMethodDescriptor* descriptor) { | 431 InputMethodDescriptor* descriptor) { |
423 std::map<std::string, InputMethodDescriptor>::const_iterator ix = | 432 std::map<std::string, InputMethodDescriptor>::const_iterator ix = |
424 extra_input_method_ids_.find(id); | 433 extra_input_method_ids_.find(id); |
425 if (ix != extra_input_method_ids_.end()) { | 434 if (ix != extra_input_method_ids_.end()) { |
426 *descriptor = ix->second; | 435 *descriptor = ix->second; |
427 return true; | 436 return true; |
428 } else { | 437 } else { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 static InputMethodManagerImpl* GetInstance() { | 590 static InputMethodManagerImpl* GetInstance() { |
582 return Singleton<InputMethodManagerImpl, | 591 return Singleton<InputMethodManagerImpl, |
583 DefaultSingletonTraits<InputMethodManagerImpl> >::get(); | 592 DefaultSingletonTraits<InputMethodManagerImpl> >::get(); |
584 } | 593 } |
585 | 594 |
586 private: | 595 private: |
587 friend struct DefaultSingletonTraits<InputMethodManagerImpl>; | 596 friend struct DefaultSingletonTraits<InputMethodManagerImpl>; |
588 | 597 |
589 // Returns true if the given input method config value is a string list | 598 // Returns true if the given input method config value is a string list |
590 // that only contains an input method ID of a keyboard layout. | 599 // that only contains an input method ID of a keyboard layout. |
591 bool ContainOnlyKeyboardLayout(const ImeConfigValue& value) { | 600 bool ContainOnlyKeyboardLayout(const std::vector<std::string>& value) { |
592 if (value.type != ImeConfigValue::kValueTypeStringList) { | 601 for (size_t i = 0; i < value.size(); ++i) { |
593 return false; | 602 if (!InputMethodUtil::IsKeyboardLayout(value[i])) { |
594 } | |
595 for (size_t i = 0; i < value.string_list_value.size(); ++i) { | |
596 if (!InputMethodUtil::IsKeyboardLayout(value.string_list_value[i])) { | |
597 return false; | 603 return false; |
598 } | 604 } |
599 } | 605 } |
600 return true; | 606 return true; |
601 } | 607 } |
602 | 608 |
603 // Starts input method daemon based on the |defer_ime_startup_| flag and | 609 // Starts input method daemon based on the |defer_ime_startup_| flag and |
604 // input method configuration being updated. |section| is a section name of | 610 // input method configuration being updated. |section| is a section name of |
605 // the input method configuration (e.g. "general", "general/hotkey"). | 611 // the input method configuration (e.g. "general", "general/hotkey"). |
606 // |config_name| is a name of the configuration (e.g. "preload_engines", | 612 // |config_name| is a name of the configuration (e.g. "preload_engines", |
607 // "previous_engine"). |value| is the configuration value to be set. | 613 // "previous_engine"). |value| is the configuration value to be set. |
608 void MaybeStartInputMethodDaemon(const std::string& section, | 614 void MaybeStartInputMethodDaemon(const std::string& section, |
609 const std::string& config_name, | 615 const std::string& config_name, |
610 const ImeConfigValue& value) { | 616 const ImeConfigValue& value) { |
611 if (section == language_prefs::kGeneralSectionName && | 617 if (section == language_prefs::kGeneralSectionName && |
612 config_name == language_prefs::kPreloadEnginesConfigName && | 618 config_name == language_prefs::kPreloadEnginesConfigName && |
613 value.type == ImeConfigValue::kValueTypeStringList && | 619 value.type == ImeConfigValue::kValueTypeStringList && |
614 !value.string_list_value.empty()) { | 620 !value.string_list_value.empty()) { |
615 // If there is only one input method which is a keyboard layout, | 621 // If there is only one input method which is a keyboard layout, |
616 // we don't start the input method processes. When | 622 // we don't start the input method processes. When |
617 // |defer_ime_startup_| is true, we don't start it either. | 623 // |defer_ime_startup_| is true, we don't start it either. |
618 if (ContainOnlyKeyboardLayout(value) || defer_ime_startup_) { | 624 if (ContainOnlyKeyboardLayout(value.string_list_value) || |
| 625 defer_ime_startup_) { |
619 // Do not start the input method daemon. | 626 // Do not start the input method daemon. |
620 return; | 627 return; |
621 } | 628 } |
622 | 629 |
623 // Otherwise, start the input method daemon. | 630 // Otherwise, start the input method daemon. |
624 const bool just_started = StartInputMethodDaemon(); | 631 const bool just_started = StartInputMethodDaemon(); |
625 if (!just_started) { | 632 if (!just_started) { |
626 // The daemon is already running. | 633 // The daemon is already running. |
627 // Do not |update tentative_current_input_method_id_|. | 634 // Do not |update tentative_current_input_method_id_|. |
628 return; | 635 return; |
(...skipping 23 matching lines...) Expand all Loading... |
652 // in the list, |value.string_list_value[0]|, and send global engine | 659 // in the list, |value.string_list_value[0]|, and send global engine |
653 // changed signal to Chrome. See crosbug.com/13406. | 660 // changed signal to Chrome. See crosbug.com/13406. |
654 tentative_current_input_method_id_.clear(); | 661 tentative_current_input_method_id_.clear(); |
655 } | 662 } |
656 } | 663 } |
657 } | 664 } |
658 | 665 |
659 // Stops input method daemon based on the |enable_auto_ime_shutdown_| flag | 666 // Stops input method daemon based on the |enable_auto_ime_shutdown_| flag |
660 // and input method configuration being updated. | 667 // and input method configuration being updated. |
661 // See also: MaybeStartInputMethodDaemon(). | 668 // See also: MaybeStartInputMethodDaemon(). |
662 void MaybeStopInputMethodDaemon(const std::string& section, | 669 void MaybeStopInputMethodDaemon() { |
663 const std::string& config_name, | |
664 const ImeConfigValue& value) { | |
665 // If there is only one input method which is a keyboard layout, | 670 // If there is only one input method which is a keyboard layout, |
666 // and |enable_auto_ime_shutdown_| is true, we'll stop the input | 671 // and |enable_auto_ime_shutdown_| is true, we'll stop the input |
667 // method daemon. | 672 // method daemon. |
668 if (section == language_prefs::kGeneralSectionName && | 673 if (ContainOnlyKeyboardLayout(active_input_method_ids_) && |
669 config_name == language_prefs::kPreloadEnginesConfigName && | |
670 ContainOnlyKeyboardLayout(value) && | |
671 enable_auto_ime_shutdown_) { | 674 enable_auto_ime_shutdown_) { |
672 if (StopInputMethodDaemon()) { | 675 if (StopInputMethodDaemon()) { |
673 // The process is killed. Change the current keyboard layout. | 676 // The process is killed. Change the current keyboard layout. |
674 // We shouldn't use SetCurrentKeyboardLayoutByName() here. See | 677 // We shouldn't use SetCurrentKeyboardLayoutByName() here. See |
675 // comments at ChangeCurrentInputMethod() for details. | 678 // comments at ChangeCurrentInputMethod() for details. |
676 ChangeCurrentInputMethodFromId(value.string_list_value[0]); | 679 ChangeCurrentInputMethodFromId(active_input_method_ids_[0]); |
677 } | 680 } |
678 } | 681 } |
679 } | 682 } |
680 | 683 |
681 // Change the keyboard layout per input method configuration being | 684 // Change the keyboard layout per input method configuration being |
682 // updated, if necessary. See also: MaybeStartInputMethodDaemon(). | 685 // updated, if necessary. See also: MaybeStartInputMethodDaemon(). |
683 void MaybeChangeCurrentKeyboardLayout(const std::string& section, | 686 void MaybeChangeCurrentKeyboardLayout(const std::string& section, |
684 const std::string& config_name, | 687 const std::string& config_name, |
685 const ImeConfigValue& value) { | 688 const ImeConfigValue& value) { |
686 if (section == language_prefs::kGeneralSectionName && | 689 if (section == language_prefs::kGeneralSectionName && |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 return InputMethodManagerImpl::GetInstance(); | 1392 return InputMethodManagerImpl::GetInstance(); |
1390 } | 1393 } |
1391 | 1394 |
1392 } // namespace input_method | 1395 } // namespace input_method |
1393 } // namespace chromeos | 1396 } // namespace chromeos |
1394 | 1397 |
1395 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 1398 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
1396 // won't be deleted until it's last InvokeLater is run. | 1399 // won't be deleted until it's last InvokeLater is run. |
1397 DISABLE_RUNNABLE_METHOD_REFCOUNT( | 1400 DISABLE_RUNNABLE_METHOD_REFCOUNT( |
1398 chromeos::input_method::InputMethodManagerImpl); | 1401 chromeos::input_method::InputMethodManagerImpl); |
OLD | NEW |