OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cros/input_method_library.h" | 5 #include "chrome/browser/chromeos/cros/input_method_library.h" |
6 | 6 |
7 #include <glib.h> | 7 #include <glib.h> |
8 #include <signal.h> | 8 #include <signal.h> |
9 | 9 |
10 #include "unicode/uloc.h" | 10 #include "unicode/uloc.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return previous_input_method_; | 184 return previous_input_method_; |
185 } | 185 } |
186 virtual const InputMethodDescriptor& current_input_method() const { | 186 virtual const InputMethodDescriptor& current_input_method() const { |
187 return current_input_method_; | 187 return current_input_method_; |
188 } | 188 } |
189 | 189 |
190 virtual const ImePropertyList& current_ime_properties() const { | 190 virtual const ImePropertyList& current_ime_properties() const { |
191 return current_ime_properties_; | 191 return current_ime_properties_; |
192 } | 192 } |
193 | 193 |
| 194 virtual std::string GetKeyboardOverlayId(const std::string& input_method_id) { |
| 195 if (EnsureLoadedAndStarted()) { |
| 196 return chromeos::GetKeyboardOverlayId(input_method_id); |
| 197 } |
| 198 return ""; |
| 199 } |
| 200 |
194 private: | 201 private: |
195 // Starts input method processes based on the |defer_ime_startup_| flag and | 202 // Starts input method processes based on the |defer_ime_startup_| flag and |
196 // input method configuration being updated. |section| is a section name of | 203 // input method configuration being updated. |section| is a section name of |
197 // the input method configuration (e.g. "general", "general/hotkey"). | 204 // the input method configuration (e.g. "general", "general/hotkey"). |
198 // |config_name| is a name of the configuration (e.g. "preload_engines", | 205 // |config_name| is a name of the configuration (e.g. "preload_engines", |
199 // "previous_engine"). |value| is the configuration value to be set. | 206 // "previous_engine"). |value| is the configuration value to be set. |
200 void MaybeStartInputMethodProcesses(const std::string& section, | 207 void MaybeStartInputMethodProcesses(const std::string& section, |
201 const std::string& config_name, | 208 const std::string& config_name, |
202 const ImeConfigValue& value) { | 209 const ImeConfigValue& value) { |
203 if (section == language_prefs::kGeneralSectionName && | 210 if (section == language_prefs::kGeneralSectionName && |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 678 |
672 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); | 679 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); |
673 }; | 680 }; |
674 | 681 |
675 InputMethodLibraryImpl::Observer::~Observer() {} | 682 InputMethodLibraryImpl::Observer::~Observer() {} |
676 | 683 |
677 class InputMethodLibraryStubImpl : public InputMethodLibrary { | 684 class InputMethodLibraryStubImpl : public InputMethodLibrary { |
678 public: | 685 public: |
679 InputMethodLibraryStubImpl() | 686 InputMethodLibraryStubImpl() |
680 : previous_input_method_("", "", "", ""), | 687 : previous_input_method_("", "", "", ""), |
681 current_input_method_("", "", "", "") { | 688 current_input_method_("", "", "", ""), |
| 689 keyboard_overlay_map_( |
| 690 CreateRealisticKeyboardOverlayMap()) { |
682 } | 691 } |
683 | 692 |
684 ~InputMethodLibraryStubImpl() {} | 693 ~InputMethodLibraryStubImpl() {} |
685 void AddObserver(Observer* observer) {} | 694 void AddObserver(Observer* observer) {} |
686 void RemoveObserver(Observer* observer) {} | 695 void RemoveObserver(Observer* observer) {} |
687 | 696 |
688 InputMethodDescriptors* GetActiveInputMethods() { | 697 InputMethodDescriptors* GetActiveInputMethods() { |
689 return CreateRealisticInputMethodDescriptors(); | 698 return CreateRealisticInputMethodDescriptors(); |
690 } | 699 } |
691 | 700 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 738 |
730 virtual const ImePropertyList& current_ime_properties() const { | 739 virtual const ImePropertyList& current_ime_properties() const { |
731 return current_ime_properties_; | 740 return current_ime_properties_; |
732 } | 741 } |
733 | 742 |
734 virtual void StartInputMethodProcesses() {} | 743 virtual void StartInputMethodProcesses() {} |
735 virtual void StopInputMethodProcesses() {} | 744 virtual void StopInputMethodProcesses() {} |
736 virtual void SetDeferImeStartup(bool defer) {} | 745 virtual void SetDeferImeStartup(bool defer) {} |
737 virtual void SetEnableAutoImeShutdown(bool enable) {} | 746 virtual void SetEnableAutoImeShutdown(bool enable) {} |
738 | 747 |
| 748 virtual std::string GetKeyboardOverlayId(const std::string& input_method_id) { |
| 749 KeyboardOverlayMap::const_iterator iter = |
| 750 keyboard_overlay_map_->find(input_method_id); |
| 751 return (iter != keyboard_overlay_map_->end()) ? |
| 752 iter->second : ""; |
| 753 } |
| 754 |
739 private: | 755 private: |
| 756 typedef std::map<std::string, std::string> KeyboardOverlayMap; |
| 757 |
740 // Creates realistic input method descriptors that can be used for | 758 // Creates realistic input method descriptors that can be used for |
741 // testing Chrome OS version of chrome on regular Linux desktops. | 759 // testing Chrome OS version of chrome on regular Linux desktops. |
742 InputMethodDescriptors* CreateRealisticInputMethodDescriptors() { | 760 InputMethodDescriptors* CreateRealisticInputMethodDescriptors() { |
743 InputMethodDescriptors* descriptions = new InputMethodDescriptors; | 761 InputMethodDescriptors* descriptions = new InputMethodDescriptors; |
744 // The list is created from output of gen_engines.py in libcros. | 762 // The list is created from output of gen_engines.py in libcros. |
745 descriptions->push_back(InputMethodDescriptor( | 763 descriptions->push_back(InputMethodDescriptor( |
746 "chewing", "Chewing", "us", "zh_TW")); | 764 "chewing", "Chewing", "us", "zh_TW")); |
747 descriptions->push_back(InputMethodDescriptor( | 765 descriptions->push_back(InputMethodDescriptor( |
748 "hangul", "Korean", "us", "ko")); | 766 "hangul", "Korean", "us", "ko")); |
749 descriptions->push_back(InputMethodDescriptor( | 767 descriptions->push_back(InputMethodDescriptor( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 descriptions->push_back(InputMethodDescriptor( | 876 descriptions->push_back(InputMethodDescriptor( |
859 "xkb:tr::tur", "Turkey", "tr", "tur")); | 877 "xkb:tr::tur", "Turkey", "tr", "tur")); |
860 descriptions->push_back(InputMethodDescriptor( | 878 descriptions->push_back(InputMethodDescriptor( |
861 "xkb:ua::ukr", "Ukraine", "ua", "ukr")); | 879 "xkb:ua::ukr", "Ukraine", "ua", "ukr")); |
862 descriptions->push_back(InputMethodDescriptor( | 880 descriptions->push_back(InputMethodDescriptor( |
863 "xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys", "gb(extd)", | 881 "xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys", "gb(extd)", |
864 "eng")); | 882 "eng")); |
865 return descriptions; | 883 return descriptions; |
866 } | 884 } |
867 | 885 |
| 886 std::map<std::string, std::string>* CreateRealisticKeyboardOverlayMap() { |
| 887 KeyboardOverlayMap* keyboard_overlay_map = |
| 888 new KeyboardOverlayMap; |
| 889 (*keyboard_overlay_map)["xkb:nl::nld"] = "nl"; |
| 890 (*keyboard_overlay_map)["xkb:be::nld"] = "nl"; |
| 891 (*keyboard_overlay_map)["xkb:fr::fra"] = "fr"; |
| 892 (*keyboard_overlay_map)["xkb:be::fra"] = "fr"; |
| 893 (*keyboard_overlay_map)["xkb:ca::fra"] = "fr_CA"; |
| 894 (*keyboard_overlay_map)["xkb:ch:fr:fra"] = "fr"; |
| 895 (*keyboard_overlay_map)["xkb:de::ger"] = "de"; |
| 896 (*keyboard_overlay_map)["xkb:be::ger"] = "de"; |
| 897 (*keyboard_overlay_map)["xkb:ch::ger"] = "de"; |
| 898 (*keyboard_overlay_map)["mozc"] = "en_US"; |
| 899 (*keyboard_overlay_map)["mozc-jp"] = "ja"; |
| 900 (*keyboard_overlay_map)["mozc-dv"] = "en_US_dvorak"; |
| 901 (*keyboard_overlay_map)["xkb:jp::jpn"] = "ja"; |
| 902 (*keyboard_overlay_map)["xkb:ru::rus"] = "ru"; |
| 903 (*keyboard_overlay_map)["xkb:ru:phonetic:rus"] = "ru"; |
| 904 (*keyboard_overlay_map)["m17n:th:kesmanee"] = "th"; |
| 905 (*keyboard_overlay_map)["m17n:th:pattachote"] = "th"; |
| 906 (*keyboard_overlay_map)["m17n:th:tis820"] = "th"; |
| 907 (*keyboard_overlay_map)["chewing"] = "zh_TW"; |
| 908 (*keyboard_overlay_map)["m17n:zh:cangjie"] = "zh_TW"; |
| 909 (*keyboard_overlay_map)["m17n:zh:quick"] = "zh_TW"; |
| 910 (*keyboard_overlay_map)["m17n:vi:tcvn"] = "vi"; |
| 911 (*keyboard_overlay_map)["m17n:vi:telex"] = "vi"; |
| 912 (*keyboard_overlay_map)["m17n:vi:viqr"] = "vi"; |
| 913 (*keyboard_overlay_map)["m17n:vi:vni"] = "vi"; |
| 914 (*keyboard_overlay_map)["xkb:us::eng"] = "en_US"; |
| 915 (*keyboard_overlay_map)["xkb:us:intl:eng"] = "en_US"; |
| 916 (*keyboard_overlay_map)["xkb:us:altgr-intl:eng"] = "en_US"; |
| 917 (*keyboard_overlay_map)["xkb:us:dvorak:eng"] = |
| 918 "en_US_dvorak"; |
| 919 (*keyboard_overlay_map)["xkb:us:colemak:eng"] = |
| 920 "en_US"; |
| 921 (*keyboard_overlay_map)["hangul"] = "ko"; |
| 922 (*keyboard_overlay_map)["pinyin"] = "zh_CN"; |
| 923 (*keyboard_overlay_map)["m17n:ar:kbd"] = "ar"; |
| 924 (*keyboard_overlay_map)["m17n:hi:itrans"] = "hi"; |
| 925 (*keyboard_overlay_map)["m17n:fa:isiri"] = "ar"; |
| 926 (*keyboard_overlay_map)["xkb:br::por"] = "pt_BR"; |
| 927 (*keyboard_overlay_map)["xkb:bg::bul"] = "bg"; |
| 928 (*keyboard_overlay_map)["xkb:bg:phonetic:bul"] = "bg"; |
| 929 (*keyboard_overlay_map)["xkb:ca:eng:eng"] = "ca"; |
| 930 (*keyboard_overlay_map)["xkb:cz::cze"] = "cs"; |
| 931 (*keyboard_overlay_map)["xkb:ee::est"] = "et"; |
| 932 (*keyboard_overlay_map)["xkb:es::spa"] = "es"; |
| 933 (*keyboard_overlay_map)["xkb:es:cat:cat"] = "ca"; |
| 934 (*keyboard_overlay_map)["xkb:dk::dan"] = "da"; |
| 935 (*keyboard_overlay_map)["xkb:gr::gre"] = "el"; |
| 936 (*keyboard_overlay_map)["xkb:il::heb"] = "iw"; |
| 937 (*keyboard_overlay_map)["xkb:kr:kr104:kor"] = "ko"; |
| 938 (*keyboard_overlay_map)["xkb:latam::spa"] = "es_419"; |
| 939 (*keyboard_overlay_map)["xkb:lt::lit"] = "lt"; |
| 940 (*keyboard_overlay_map)["xkb:lv:apostrophe:lav"] = "lv"; |
| 941 (*keyboard_overlay_map)["xkb:hr::scr"] = "hr"; |
| 942 (*keyboard_overlay_map)["xkb:gb:extd:eng"] = "en_GB"; |
| 943 (*keyboard_overlay_map)["xkb:fi::fin"] = "fi"; |
| 944 (*keyboard_overlay_map)["xkb:hu::hun"] = "hu"; |
| 945 (*keyboard_overlay_map)["xkb:it::ita"] = "it"; |
| 946 (*keyboard_overlay_map)["xkb:no::nob"] = "no"; |
| 947 (*keyboard_overlay_map)["xkb:pl::pol"] = "pl"; |
| 948 (*keyboard_overlay_map)["xkb:pt::por"] = "pt_PT"; |
| 949 (*keyboard_overlay_map)["xkb:ro::rum"] = "ro"; |
| 950 (*keyboard_overlay_map)["xkb:se::swe"] = "sv"; |
| 951 (*keyboard_overlay_map)["xkb:sk::slo"] = "sk"; |
| 952 (*keyboard_overlay_map)["xkb:si::slv"] = "sl"; |
| 953 (*keyboard_overlay_map)["xkb:rs::srp"] = "sr"; |
| 954 (*keyboard_overlay_map)["xkb:tr::tur"] = "tr"; |
| 955 (*keyboard_overlay_map)["xkb:ua::ukr"] = "uk"; |
| 956 return keyboard_overlay_map; |
| 957 } |
| 958 |
868 InputMethodDescriptor previous_input_method_; | 959 InputMethodDescriptor previous_input_method_; |
869 InputMethodDescriptor current_input_method_; | 960 InputMethodDescriptor current_input_method_; |
870 ImePropertyList current_ime_properties_; | 961 ImePropertyList current_ime_properties_; |
| 962 scoped_ptr<KeyboardOverlayMap> keyboard_overlay_map_; |
871 | 963 |
872 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl); | 964 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl); |
873 }; | 965 }; |
874 | 966 |
875 // static | 967 // static |
876 InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) { | 968 InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) { |
877 if (stub) | 969 if (stub) |
878 return new InputMethodLibraryStubImpl(); | 970 return new InputMethodLibraryStubImpl(); |
879 else | 971 else |
880 return new InputMethodLibraryImpl(); | 972 return new InputMethodLibraryImpl(); |
881 } | 973 } |
882 | 974 |
883 } // namespace chromeos | 975 } // namespace chromeos |
884 | 976 |
885 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 977 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
886 // won't be deleted until it's last InvokeLater is run. | 978 // won't be deleted until it's last InvokeLater is run. |
887 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); | 979 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); |
OLD | NEW |