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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/threading/thread_checker.h" |
16 #include "chromeos/ime/input_method_descriptor.h" | 17 #include "chromeos/ime/input_method_descriptor.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 namespace input_method { | 20 namespace input_method { |
20 | 21 |
21 class InputMethodDelegate; | 22 class InputMethodDelegate; |
22 | 23 |
23 enum InputMethodType { | 24 enum InputMethodType { |
24 kKeyboardLayoutsOnly, | 25 kKeyboardLayoutsOnly, |
25 kAllInputMethods, | 26 kAllInputMethods, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Gets the language codes associated with the given input method IDs. | 91 // Gets the language codes associated with the given input method IDs. |
91 // The returned language codes won't have duplicates. | 92 // The returned language codes won't have duplicates. |
92 void GetLanguageCodesFromInputMethodIds( | 93 void GetLanguageCodesFromInputMethodIds( |
93 const std::vector<std::string>& input_method_ids, | 94 const std::vector<std::string>& input_method_ids, |
94 std::vector<std::string>* out_language_codes) const; | 95 std::vector<std::string>* out_language_codes) const; |
95 | 96 |
96 // Gets first input method associated with the language. | 97 // Gets first input method associated with the language. |
97 // Returns empty string on error. | 98 // Returns empty string on error. |
98 std::string GetLanguageDefaultInputMethodId(const std::string& language_code); | 99 std::string GetLanguageDefaultInputMethodId(const std::string& language_code); |
99 | 100 |
100 // Returns the input method ID of the hardware keyboard. e.g. "xkb:us::eng" | 101 // Updates the internal cache of hardware layouts. |
101 // for the US Qwerty keyboard. | 102 void UpdateHardwareLayoutCache(); |
102 std::string GetHardwareInputMethodId() const; | |
103 | 103 |
104 // Returns the login-allowed input method ID of the hardware keyboard. | 104 // Set hardware keyboard layout for testing purpose. This is for simulating |
105 std::string GetHardwareLoginInputMethodId() const; | 105 // "keyboard_layout" entry in VPD values. |
| 106 void SetHardwareKeyboardLayoutForTesting(const std::string& layout); |
| 107 |
| 108 // Fills the input method IDs of the hardware keyboard. e.g. "xkb:us::eng" |
| 109 // for US Qwerty keyboard or "xkb:ru::rus" for Russian keyboard. |
| 110 const std::vector<std::string>& GetHardwareInputMethodIds(); |
| 111 |
| 112 // Returns the login-allowed input method ID of the hardware keyboard, e.g. |
| 113 // "xkb:us::eng" but not include non-login keyboard like "xkb:ru::rus". Please |
| 114 // note that this is not a subset of returned value of |
| 115 // GetHardwareInputMethodIds. If GetHardwareInputMethodIds returns only |
| 116 // non-login keyboard, this function will returns "xkb:us::eng" as the |
| 117 // fallback keyboard. |
| 118 const std::vector<std::string>& GetHardwareLoginInputMethodIds(); |
106 | 119 |
107 // Returns true if given input method can be used to input login data. | 120 // Returns true if given input method can be used to input login data. |
108 bool IsLoginKeyboard(const std::string& input_method_id) const; | 121 bool IsLoginKeyboard(const std::string& input_method_id) const; |
109 | 122 |
110 // Returns true if the given input method id is supported. | 123 // Returns true if the given input method id is supported. |
111 bool IsValidInputMethodId(const std::string& input_method_id) const; | 124 bool IsValidInputMethodId(const std::string& input_method_id) const; |
112 | 125 |
113 // Returns true if the given input method id is for a keyboard layout. | 126 // Returns true if the given input method id is for a keyboard layout. |
114 static bool IsKeyboardLayout(const std::string& input_method_id); | 127 static bool IsKeyboardLayout(const std::string& input_method_id); |
115 | 128 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 std::map<std::string, std::string> id_to_language_code_; | 179 std::map<std::string, std::string> id_to_language_code_; |
167 InputMethodIdToDescriptorMap id_to_descriptor_; | 180 InputMethodIdToDescriptorMap id_to_descriptor_; |
168 XkbIdToDescriptorMap xkb_id_to_descriptor_; | 181 XkbIdToDescriptorMap xkb_id_to_descriptor_; |
169 ComponentExtIMEMap component_extension_ime_id_to_descriptor_; | 182 ComponentExtIMEMap component_extension_ime_id_to_descriptor_; |
170 | 183 |
171 typedef base::hash_map<std::string, int> HashType; | 184 typedef base::hash_map<std::string, int> HashType; |
172 HashType english_to_resource_id_; | 185 HashType english_to_resource_id_; |
173 | 186 |
174 InputMethodDelegate* delegate_; | 187 InputMethodDelegate* delegate_; |
175 | 188 |
| 189 base::ThreadChecker thread_checker_; |
| 190 std::vector<std::string> hardware_layouts_; |
| 191 std::vector<std::string> hardware_login_layouts_; |
| 192 |
176 DISALLOW_COPY_AND_ASSIGN(InputMethodUtil); | 193 DISALLOW_COPY_AND_ASSIGN(InputMethodUtil); |
177 }; | 194 }; |
178 | 195 |
179 } // namespace input_method | 196 } // namespace input_method |
180 } // namespace chromeos | 197 } // namespace chromeos |
181 | 198 |
182 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ | 199 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ |
OLD | NEW |