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 | |
201 private: | 194 private: |
202 // Starts input method processes based on the |defer_ime_startup_| flag and | 195 // Starts input method processes based on the |defer_ime_startup_| flag and |
203 // input method configuration being updated. |section| is a section name of | 196 // input method configuration being updated. |section| is a section name of |
204 // the input method configuration (e.g. "general", "general/hotkey"). | 197 // the input method configuration (e.g. "general", "general/hotkey"). |
205 // |config_name| is a name of the configuration (e.g. "preload_engines", | 198 // |config_name| is a name of the configuration (e.g. "preload_engines", |
206 // "previous_engine"). |value| is the configuration value to be set. | 199 // "previous_engine"). |value| is the configuration value to be set. |
207 void MaybeStartInputMethodProcesses(const std::string& section, | 200 void MaybeStartInputMethodProcesses(const std::string& section, |
208 const std::string& config_name, | 201 const std::string& config_name, |
209 const ImeConfigValue& value) { | 202 const ImeConfigValue& value) { |
210 if (section == language_prefs::kGeneralSectionName && | 203 if (section == language_prefs::kGeneralSectionName && |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 671 |
679 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); | 672 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); |
680 }; | 673 }; |
681 | 674 |
682 InputMethodLibraryImpl::Observer::~Observer() {} | 675 InputMethodLibraryImpl::Observer::~Observer() {} |
683 | 676 |
684 class InputMethodLibraryStubImpl : public InputMethodLibrary { | 677 class InputMethodLibraryStubImpl : public InputMethodLibrary { |
685 public: | 678 public: |
686 InputMethodLibraryStubImpl() | 679 InputMethodLibraryStubImpl() |
687 : previous_input_method_("", "", "", ""), | 680 : previous_input_method_("", "", "", ""), |
688 current_input_method_("", "", "", ""), | 681 current_input_method_("", "", "", "") { |
689 keyboard_overlay_map_( | |
690 CreateRealisticKeyboardOverlayMap()) { | |
691 } | 682 } |
692 | 683 |
693 ~InputMethodLibraryStubImpl() {} | 684 ~InputMethodLibraryStubImpl() {} |
694 void AddObserver(Observer* observer) {} | 685 void AddObserver(Observer* observer) {} |
695 void RemoveObserver(Observer* observer) {} | 686 void RemoveObserver(Observer* observer) {} |
696 | 687 |
697 InputMethodDescriptors* GetActiveInputMethods() { | 688 InputMethodDescriptors* GetActiveInputMethods() { |
698 return CreateRealisticInputMethodDescriptors(); | 689 return CreateRealisticInputMethodDescriptors(); |
699 } | 690 } |
700 | 691 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 729 |
739 virtual const ImePropertyList& current_ime_properties() const { | 730 virtual const ImePropertyList& current_ime_properties() const { |
740 return current_ime_properties_; | 731 return current_ime_properties_; |
741 } | 732 } |
742 | 733 |
743 virtual void StartInputMethodProcesses() {} | 734 virtual void StartInputMethodProcesses() {} |
744 virtual void StopInputMethodProcesses() {} | 735 virtual void StopInputMethodProcesses() {} |
745 virtual void SetDeferImeStartup(bool defer) {} | 736 virtual void SetDeferImeStartup(bool defer) {} |
746 virtual void SetEnableAutoImeShutdown(bool enable) {} | 737 virtual void SetEnableAutoImeShutdown(bool enable) {} |
747 | 738 |
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 | |
755 private: | 739 private: |
756 typedef std::map<std::string, std::string> KeyboardOverlayMap; | |
757 | |
758 // Creates realistic input method descriptors that can be used for | 740 // Creates realistic input method descriptors that can be used for |
759 // testing Chrome OS version of chrome on regular Linux desktops. | 741 // testing Chrome OS version of chrome on regular Linux desktops. |
760 InputMethodDescriptors* CreateRealisticInputMethodDescriptors() { | 742 InputMethodDescriptors* CreateRealisticInputMethodDescriptors() { |
761 InputMethodDescriptors* descriptions = new InputMethodDescriptors; | 743 InputMethodDescriptors* descriptions = new InputMethodDescriptors; |
762 // The list is created from output of gen_engines.py in libcros. | 744 // The list is created from output of gen_engines.py in libcros. |
763 descriptions->push_back(InputMethodDescriptor( | 745 descriptions->push_back(InputMethodDescriptor( |
764 "chewing", "Chewing", "us", "zh_TW")); | 746 "chewing", "Chewing", "us", "zh_TW")); |
765 descriptions->push_back(InputMethodDescriptor( | 747 descriptions->push_back(InputMethodDescriptor( |
766 "hangul", "Korean", "us", "ko")); | 748 "hangul", "Korean", "us", "ko")); |
767 descriptions->push_back(InputMethodDescriptor( | 749 descriptions->push_back(InputMethodDescriptor( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 descriptions->push_back(InputMethodDescriptor( | 858 descriptions->push_back(InputMethodDescriptor( |
877 "xkb:tr::tur", "Turkey", "tr", "tur")); | 859 "xkb:tr::tur", "Turkey", "tr", "tur")); |
878 descriptions->push_back(InputMethodDescriptor( | 860 descriptions->push_back(InputMethodDescriptor( |
879 "xkb:ua::ukr", "Ukraine", "ua", "ukr")); | 861 "xkb:ua::ukr", "Ukraine", "ua", "ukr")); |
880 descriptions->push_back(InputMethodDescriptor( | 862 descriptions->push_back(InputMethodDescriptor( |
881 "xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys", "gb(extd)", | 863 "xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys", "gb(extd)", |
882 "eng")); | 864 "eng")); |
883 return descriptions; | 865 return descriptions; |
884 } | 866 } |
885 | 867 |
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 | |
959 InputMethodDescriptor previous_input_method_; | 868 InputMethodDescriptor previous_input_method_; |
960 InputMethodDescriptor current_input_method_; | 869 InputMethodDescriptor current_input_method_; |
961 ImePropertyList current_ime_properties_; | 870 ImePropertyList current_ime_properties_; |
962 scoped_ptr<KeyboardOverlayMap> keyboard_overlay_map_; | |
963 | 871 |
964 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl); | 872 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl); |
965 }; | 873 }; |
966 | 874 |
967 // static | 875 // static |
968 InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) { | 876 InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) { |
969 if (stub) | 877 if (stub) |
970 return new InputMethodLibraryStubImpl(); | 878 return new InputMethodLibraryStubImpl(); |
971 else | 879 else |
972 return new InputMethodLibraryImpl(); | 880 return new InputMethodLibraryImpl(); |
973 } | 881 } |
974 | 882 |
975 } // namespace chromeos | 883 } // namespace chromeos |
976 | 884 |
977 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 885 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
978 // won't be deleted until it's last InvokeLater is run. | 886 // won't be deleted until it's last InvokeLater is run. |
979 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); | 887 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); |
OLD | NEW |