Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/chromeos/cros/input_method_library.cc

Issue 5981001: Use libcros to convert input method ID to keyboard overlay ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return previous_input_method_; 175 return previous_input_method_;
176 } 176 }
177 virtual const InputMethodDescriptor& current_input_method() const { 177 virtual const InputMethodDescriptor& current_input_method() const {
178 return current_input_method_; 178 return current_input_method_;
179 } 179 }
180 180
181 virtual const ImePropertyList& current_ime_properties() const { 181 virtual const ImePropertyList& current_ime_properties() const {
182 return current_ime_properties_; 182 return current_ime_properties_;
183 } 183 }
184 184
185 virtual std::string GetKeyboardOverlayId(const std::string& input_method_id) {
186 if (EnsureLoadedAndStarted()) {
187 return chromeos::GetKeyboardOverlayId(input_method_id);
188 }
189 return "";
190 }
191
185 private: 192 private:
186 // Starts or stops the input method processes based on the current state. 193 // Starts or stops the input method processes based on the current state.
187 void MaybeStartOrStopInputMethodProcesses( 194 void MaybeStartOrStopInputMethodProcesses(
188 const char* section, 195 const char* section,
189 const char* config_name, 196 const char* config_name,
190 const ImeConfigValue& value) { 197 const ImeConfigValue& value) {
191 if (!strcmp(language_prefs::kGeneralSectionName, section) && 198 if (!strcmp(language_prefs::kGeneralSectionName, section) &&
192 !strcmp(language_prefs::kPreloadEnginesConfigName, config_name)) { 199 !strcmp(language_prefs::kPreloadEnginesConfigName, config_name)) {
193 if (EnsureLoadedAndStarted()) { 200 if (EnsureLoadedAndStarted()) {
194 // If there are no input methods other than one for the hardware 201 // If there are no input methods other than one for the hardware
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 608
602 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); 609 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl);
603 }; 610 };
604 611
605 InputMethodLibraryImpl::Observer::~Observer() {} 612 InputMethodLibraryImpl::Observer::~Observer() {}
606 613
607 class InputMethodLibraryStubImpl : public InputMethodLibrary { 614 class InputMethodLibraryStubImpl : public InputMethodLibrary {
608 public: 615 public:
609 InputMethodLibraryStubImpl() 616 InputMethodLibraryStubImpl()
610 : previous_input_method_("", "", "", ""), 617 : previous_input_method_("", "", "", ""),
611 current_input_method_("", "", "", "") { 618 current_input_method_("", "", "", ""),
619 keyboard_overlay_map_(
620 CreateRealisticKeyboardOverlayMap()) {
612 } 621 }
613 622
614 ~InputMethodLibraryStubImpl() {} 623 ~InputMethodLibraryStubImpl() {}
615 void AddObserver(Observer* observer) {} 624 void AddObserver(Observer* observer) {}
616 void RemoveObserver(Observer* observer) {} 625 void RemoveObserver(Observer* observer) {}
617 626
618 InputMethodDescriptors* GetActiveInputMethods() { 627 InputMethodDescriptors* GetActiveInputMethods() {
619 return CreateRealisticInputMethodDescriptors(); 628 return CreateRealisticInputMethodDescriptors();
620 } 629 }
621 630
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 668
660 virtual const ImePropertyList& current_ime_properties() const { 669 virtual const ImePropertyList& current_ime_properties() const {
661 return current_ime_properties_; 670 return current_ime_properties_;
662 } 671 }
663 672
664 virtual void StartInputMethodProcesses() {} 673 virtual void StartInputMethodProcesses() {}
665 virtual void StopInputMethodProcesses() {} 674 virtual void StopInputMethodProcesses() {}
666 virtual void SetDeferImeStartup(bool defer) {} 675 virtual void SetDeferImeStartup(bool defer) {}
667 virtual void SetEnableAutoImeShutdown(bool enable) {} 676 virtual void SetEnableAutoImeShutdown(bool enable) {}
668 677
678 virtual std::string GetKeyboardOverlayId(const std::string& input_method_id) {
679 KeyboardOverlayMap::const_iterator iter =
680 keyboard_overlay_map_->find(input_method_id);
681 return (iter != keyboard_overlay_map_->end()) ?
682 iter->second : "";
683 }
684
669 private: 685 private:
686 typedef std::map<std::string, std::string> KeyboardOverlayMap;
687
670 // Creates realistic input method descriptors that can be used for 688 // Creates realistic input method descriptors that can be used for
671 // testing Chrome OS version of chrome on regular Linux desktops. 689 // testing Chrome OS version of chrome on regular Linux desktops.
672 InputMethodDescriptors* CreateRealisticInputMethodDescriptors() { 690 InputMethodDescriptors* CreateRealisticInputMethodDescriptors() {
673 InputMethodDescriptors* descriptions = new InputMethodDescriptors; 691 InputMethodDescriptors* descriptions = new InputMethodDescriptors;
674 // The list is created from output of gen_engines.py in libcros. 692 // The list is created from output of gen_engines.py in libcros.
675 descriptions->push_back(InputMethodDescriptor( 693 descriptions->push_back(InputMethodDescriptor(
676 "chewing", "Chewing", "us", "zh_TW")); 694 "chewing", "Chewing", "us", "zh_TW"));
677 descriptions->push_back(InputMethodDescriptor( 695 descriptions->push_back(InputMethodDescriptor(
678 "hangul", "Korean", "us", "ko")); 696 "hangul", "Korean", "us", "ko"));
679 descriptions->push_back(InputMethodDescriptor( 697 descriptions->push_back(InputMethodDescriptor(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 descriptions->push_back(InputMethodDescriptor( 806 descriptions->push_back(InputMethodDescriptor(
789 "xkb:tr::tur", "Turkey", "tr", "tur")); 807 "xkb:tr::tur", "Turkey", "tr", "tur"));
790 descriptions->push_back(InputMethodDescriptor( 808 descriptions->push_back(InputMethodDescriptor(
791 "xkb:ua::ukr", "Ukraine", "ua", "ukr")); 809 "xkb:ua::ukr", "Ukraine", "ua", "ukr"));
792 descriptions->push_back(InputMethodDescriptor( 810 descriptions->push_back(InputMethodDescriptor(
793 "xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys", "gb(extd)", 811 "xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys", "gb(extd)",
794 "eng")); 812 "eng"));
795 return descriptions; 813 return descriptions;
796 } 814 }
797 815
816 std::map<std::string, std::string>* CreateRealisticKeyboardOverlayMap() {
817 KeyboardOverlayMap* keyboard_overlay_map =
818 new KeyboardOverlayMap;
819 (*keyboard_overlay_map)["xkb:nl::nld"] = "nl";
820 (*keyboard_overlay_map)["xkb:be::nld"] = "nl";
821 (*keyboard_overlay_map)["xkb:fr::fra"] = "fr";
822 (*keyboard_overlay_map)["xkb:be::fra"] = "fr";
823 (*keyboard_overlay_map)["xkb:ca::fra"] = "fr_CA";
824 (*keyboard_overlay_map)["xkb:ch:fr:fra"] = "fr";
825 (*keyboard_overlay_map)["xkb:de::ger"] = "de";
826 (*keyboard_overlay_map)["xkb:be::ger"] = "de";
827 (*keyboard_overlay_map)["xkb:ch::ger"] = "de";
828 (*keyboard_overlay_map)["mozc"] = "en_US";
829 (*keyboard_overlay_map)["mozc-jp"] = "ja";
830 (*keyboard_overlay_map)["mozc-dv"] = "en_US_dvorak";
831 (*keyboard_overlay_map)["xkb:jp::jpn"] = "ja";
832 (*keyboard_overlay_map)["xkb:ru::rus"] = "ru";
833 (*keyboard_overlay_map)["xkb:ru:phonetic:rus"] = "ru";
834 (*keyboard_overlay_map)["m17n:th:kesmanee"] = "th";
835 (*keyboard_overlay_map)["m17n:th:pattachote"] = "th";
836 (*keyboard_overlay_map)["m17n:th:tis820"] = "th";
837 (*keyboard_overlay_map)["chewing"] = "zh_TW";
838 (*keyboard_overlay_map)["m17n:zh:cangjie"] = "zh_TW";
839 (*keyboard_overlay_map)["m17n:zh:quick"] = "zh_TW";
840 (*keyboard_overlay_map)["m17n:vi:tcvn"] = "vi";
841 (*keyboard_overlay_map)["m17n:vi:telex"] = "vi";
842 (*keyboard_overlay_map)["m17n:vi:viqr"] = "vi";
843 (*keyboard_overlay_map)["m17n:vi:vni"] = "vi";
844 (*keyboard_overlay_map)["xkb:us::eng"] = "en_US";
845 (*keyboard_overlay_map)["xkb:us:intl:eng"] = "en_US";
846 (*keyboard_overlay_map)["xkb:us:altgr-intl:eng"] = "en_US";
847 (*keyboard_overlay_map)["xkb:us:dvorak:eng"] =
848 "en_US_dvorak";
849 (*keyboard_overlay_map)["xkb:us:colemak:eng"] =
850 "en_US";
851 (*keyboard_overlay_map)["hangul"] = "ko";
852 (*keyboard_overlay_map)["pinyin"] = "zh_CN";
853 (*keyboard_overlay_map)["m17n:ar:kbd"] = "ar";
854 (*keyboard_overlay_map)["m17n:hi:itrans"] = "hi";
855 (*keyboard_overlay_map)["m17n:fa:isiri"] = "ar";
856 (*keyboard_overlay_map)["xkb:br::por"] = "pt_BR";
857 (*keyboard_overlay_map)["xkb:bg::bul"] = "bg";
858 (*keyboard_overlay_map)["xkb:bg:phonetic:bul"] = "bg";
859 (*keyboard_overlay_map)["xkb:ca:eng:eng"] = "ca";
860 (*keyboard_overlay_map)["xkb:cz::cze"] = "cs";
861 (*keyboard_overlay_map)["xkb:ee::est"] = "et";
862 (*keyboard_overlay_map)["xkb:es::spa"] = "es";
863 (*keyboard_overlay_map)["xkb:es:cat:cat"] = "ca";
864 (*keyboard_overlay_map)["xkb:dk::dan"] = "da";
865 (*keyboard_overlay_map)["xkb:gr::gre"] = "el";
866 (*keyboard_overlay_map)["xkb:il::heb"] = "iw";
867 (*keyboard_overlay_map)["xkb:kr:kr104:kor"] = "ko";
868 (*keyboard_overlay_map)["xkb:latam::spa"] = "es_419";
869 (*keyboard_overlay_map)["xkb:lt::lit"] = "lt";
870 (*keyboard_overlay_map)["xkb:lv:apostrophe:lav"] = "lv";
871 (*keyboard_overlay_map)["xkb:hr::scr"] = "hr";
872 (*keyboard_overlay_map)["xkb:gb:extd:eng"] = "en_GB";
873 (*keyboard_overlay_map)["xkb:fi::fin"] = "fi";
874 (*keyboard_overlay_map)["xkb:hu::hun"] = "hu";
875 (*keyboard_overlay_map)["xkb:it::ita"] = "it";
876 (*keyboard_overlay_map)["xkb:no::nob"] = "no";
877 (*keyboard_overlay_map)["xkb:pl::pol"] = "pl";
878 (*keyboard_overlay_map)["xkb:pt::por"] = "pt_PT";
879 (*keyboard_overlay_map)["xkb:ro::rum"] = "ro";
880 (*keyboard_overlay_map)["xkb:se::swe"] = "sv";
881 (*keyboard_overlay_map)["xkb:sk::slo"] = "sk";
882 (*keyboard_overlay_map)["xkb:si::slv"] = "sl";
883 (*keyboard_overlay_map)["xkb:rs::srp"] = "sr";
884 (*keyboard_overlay_map)["xkb:tr::tur"] = "tr";
885 (*keyboard_overlay_map)["xkb:ua::ukr"] = "uk";
886 return keyboard_overlay_map;
887 }
888
798 InputMethodDescriptor previous_input_method_; 889 InputMethodDescriptor previous_input_method_;
799 InputMethodDescriptor current_input_method_; 890 InputMethodDescriptor current_input_method_;
800 ImePropertyList current_ime_properties_; 891 ImePropertyList current_ime_properties_;
892 scoped_ptr<KeyboardOverlayMap> keyboard_overlay_map_;
801 893
802 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl); 894 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl);
803 }; 895 };
804 896
805 // static 897 // static
806 InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) { 898 InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) {
807 if (stub) 899 if (stub)
808 return new InputMethodLibraryStubImpl(); 900 return new InputMethodLibraryStubImpl();
809 else 901 else
810 return new InputMethodLibraryImpl(); 902 return new InputMethodLibraryImpl();
811 } 903 }
812 904
813 } // namespace chromeos 905 } // namespace chromeos
814 906
815 // Allows InvokeLater without adding refcounting. This class is a Singleton and 907 // Allows InvokeLater without adding refcounting. This class is a Singleton and
816 // won't be deleted until it's last InvokeLater is run. 908 // won't be deleted until it's last InvokeLater is run.
817 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); 909 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698