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> |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 // Resets the list of component extension IMEs. | 139 // Resets the list of component extension IMEs. |
140 void ResetInputMethods(const InputMethodDescriptors& imes); | 140 void ResetInputMethods(const InputMethodDescriptors& imes); |
141 | 141 |
142 // Appends the additional list of component extension IMEs. | 142 // Appends the additional list of component extension IMEs. |
143 void AppendInputMethods(const InputMethodDescriptors& imes); | 143 void AppendInputMethods(const InputMethodDescriptors& imes); |
144 | 144 |
145 // Initializes the extension based xkb IMEs for testing. | 145 // Initializes the extension based xkb IMEs for testing. |
146 void InitXkbInputMethodsForTesting(); | 146 void InitXkbInputMethodsForTesting(); |
147 | 147 |
| 148 // Map from input method ID to associated input method descriptor. |
| 149 typedef std::map< |
| 150 std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap; |
| 151 |
| 152 // Gets the id to desctiptor map for testing. |
| 153 const InputMethodIdToDescriptorMap& GetIdToDesciptorMapForTesting(); |
| 154 |
148 // Returns the fallback input method descriptor (the very basic US | 155 // Returns the fallback input method descriptor (the very basic US |
149 // keyboard). This function is mostly used for testing, but may be used | 156 // keyboard). This function is mostly used for testing, but may be used |
150 // as the fallback, when there is no other choice. | 157 // as the fallback, when there is no other choice. |
151 static InputMethodDescriptor GetFallbackInputMethodDescriptor(); | 158 static InputMethodDescriptor GetFallbackInputMethodDescriptor(); |
152 | 159 |
153 protected: | 160 protected: |
154 // protected: for unit testing as well. | 161 // protected: for unit testing as well. |
155 bool GetInputMethodIdsFromLanguageCodeInternal( | 162 bool GetInputMethodIdsFromLanguageCodeInternal( |
156 const std::multimap<std::string, std::string>& language_code_to_ids, | 163 const std::multimap<std::string, std::string>& language_code_to_ids, |
157 const std::string& normalized_language_code, | 164 const std::string& normalized_language_code, |
158 InputMethodType type, | 165 InputMethodType type, |
159 std::vector<std::string>* out_input_method_ids) const; | 166 std::vector<std::string>* out_input_method_ids) const; |
160 | 167 |
161 // protected: for unit testing as well. | |
162 void ReloadInternalMaps(); | |
163 | |
164 // All input methods that are supported, including ones not active. | |
165 // protected: for testing. | |
166 scoped_ptr<InputMethodDescriptors> supported_input_methods_; | |
167 | |
168 // Gets the keyboard layout name from the given input method ID. | 168 // Gets the keyboard layout name from the given input method ID. |
169 // If the ID is invalid, an empty string will be returned. | 169 // If the ID is invalid, an empty string will be returned. |
170 // This function only supports xkb layouts. | 170 // This function only supports xkb layouts. |
171 // | 171 // |
172 // Examples: | 172 // Examples: |
173 // | 173 // |
174 // "xkb:us::eng" => "us" | 174 // "xkb:us::eng" => "us" |
175 // "xkb:us:dvorak:eng" => "us(dvorak)" | 175 // "xkb:us:dvorak:eng" => "us(dvorak)" |
176 // "xkb:gb::eng" => "gb" | 176 // "xkb:gb::eng" => "gb" |
177 // "pinyin" => "us" (because Pinyin uses US keyboard layout) | 177 // "pinyin" => "us" (because Pinyin uses US keyboard layout) |
178 std::string GetKeyboardLayoutName(const std::string& input_method_id) const; | 178 std::string GetKeyboardLayoutName(const std::string& input_method_id) const; |
179 | 179 |
180 private: | 180 private: |
181 bool TranslateStringInternal(const std::string& english_string, | 181 bool TranslateStringInternal(const std::string& english_string, |
182 base::string16 *out_string) const; | 182 base::string16 *out_string) const; |
183 | 183 |
184 // Map from language code to associated input method IDs, etc. | 184 // Map from language code to associated input method IDs, etc. |
185 typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap; | 185 typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap; |
186 // Map from input method ID to associated input method descriptor. | |
187 typedef std::map< | |
188 std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap; | |
189 // Map from component extention IME id to associated input method descriptor. | |
190 typedef std::map<std::string, InputMethodDescriptor> ComponentExtIMEMap; | |
191 | 186 |
192 LanguageCodeToIdsMap language_code_to_ids_; | 187 LanguageCodeToIdsMap language_code_to_ids_; |
193 std::map<std::string, std::string> id_to_language_code_; | |
194 InputMethodIdToDescriptorMap id_to_descriptor_; | 188 InputMethodIdToDescriptorMap id_to_descriptor_; |
195 std::map<std::string, std::string> xkb_layout_to_indicator_; | 189 std::map<std::string, std::string> xkb_layout_to_indicator_; |
196 | 190 |
197 typedef base::hash_map<std::string, int> HashType; | 191 typedef base::hash_map<std::string, int> HashType; |
198 HashType english_to_resource_id_; | 192 HashType english_to_resource_id_; |
199 | 193 |
200 InputMethodDelegate* delegate_; | 194 InputMethodDelegate* delegate_; |
201 | 195 |
202 base::ThreadChecker thread_checker_; | 196 base::ThreadChecker thread_checker_; |
203 std::vector<std::string> hardware_layouts_; | 197 std::vector<std::string> hardware_layouts_; |
204 std::vector<std::string> hardware_login_layouts_; | 198 std::vector<std::string> hardware_login_layouts_; |
205 std::vector<std::string> cached_hardware_layouts_; | 199 std::vector<std::string> cached_hardware_layouts_; |
206 | 200 |
207 DISALLOW_COPY_AND_ASSIGN(InputMethodUtil); | 201 DISALLOW_COPY_AND_ASSIGN(InputMethodUtil); |
208 }; | 202 }; |
209 | 203 |
210 } // namespace input_method | 204 } // namespace input_method |
211 } // namespace chromeos | 205 } // namespace chromeos |
212 | 206 |
213 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ | 207 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_UTIL_H_ |
OLD | NEW |