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 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F | 57 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F |
58 // For Hangul input method. | 58 // For Hangul input method. |
59 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C | 59 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C |
60 }; | 60 }; |
61 | 61 |
62 const size_t kMappingFromIdToIndicatorTextLen = | 62 const size_t kMappingFromIdToIndicatorTextLen = |
63 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); | 63 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); |
64 } | 64 } |
65 | 65 |
66 namespace chromeos { | 66 namespace chromeos { |
| 67 |
| 68 extern const char* kExtensionImePrefix; |
| 69 |
67 namespace input_method { | 70 namespace input_method { |
68 | 71 |
69 namespace { | 72 namespace { |
70 | 73 |
71 const struct EnglishToResouceId { | 74 const struct EnglishToResouceId { |
72 const char* english_string_from_ibus; | 75 const char* english_string_from_ibus; |
73 int resource_id; | 76 int resource_id; |
74 } kEnglishToResourceIdArray[] = { | 77 } kEnglishToResourceIdArray[] = { |
75 // For ibus-mozc. | 78 // For ibus-mozc. |
76 { "Direct input", IDS_STATUSBAR_IME_JAPANESE_IME_STATUS_DIRECT_INPUT }, | 79 { "Direct input", IDS_STATUSBAR_IME_JAPANESE_IME_STATUS_DIRECT_INPUT }, |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 string16 localized_string; | 323 string16 localized_string; |
321 return TranslateStringInternal(english_string, &localized_string); | 324 return TranslateStringInternal(english_string, &localized_string); |
322 } | 325 } |
323 | 326 |
324 // static | 327 // static |
325 bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { | 328 bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { |
326 const bool kCaseInsensitive = false; | 329 const bool kCaseInsensitive = false; |
327 return StartsWithASCII(input_method_id, "xkb:", kCaseInsensitive); | 330 return StartsWithASCII(input_method_id, "xkb:", kCaseInsensitive); |
328 } | 331 } |
329 | 332 |
| 333 // static |
| 334 bool InputMethodUtil::IsExtensionInputMethod( |
| 335 const std::string& input_method_id) { |
| 336 const bool kCaseInsensitive = false; |
| 337 return StartsWithASCII(input_method_id, |
| 338 kExtensionImePrefix, |
| 339 kCaseInsensitive); |
| 340 } |
| 341 |
330 std::string InputMethodUtil::GetLanguageCodeFromInputMethodId( | 342 std::string InputMethodUtil::GetLanguageCodeFromInputMethodId( |
331 const std::string& input_method_id) const { | 343 const std::string& input_method_id) const { |
332 // The code should be compatible with one of codes used for UI languages, | 344 // The code should be compatible with one of codes used for UI languages, |
333 // defined in app/l10_util.cc. | 345 // defined in app/l10_util.cc. |
334 const char kDefaultLanguageCode[] = "en-US"; | 346 const char kDefaultLanguageCode[] = "en-US"; |
335 std::map<std::string, std::string>::const_iterator iter | 347 std::map<std::string, std::string>::const_iterator iter |
336 = id_to_language_code_.find(input_method_id); | 348 = id_to_language_code_.find(input_method_id); |
337 return (iter == id_to_language_code_.end()) ? | 349 return (iter == id_to_language_code_.end()) ? |
338 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for | 350 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for |
339 // Ubuntu where the ibus-xkb-layouts engine could be missing. | 351 // Ubuntu where the ibus-xkb-layouts engine could be missing. |
340 kDefaultLanguageCode : iter->second; | 352 kDefaultLanguageCode : iter->second; |
341 } | 353 } |
342 | 354 |
343 std::string InputMethodUtil::GetKeyboardLayoutName( | 355 std::string InputMethodUtil::GetKeyboardLayoutName( |
344 const std::string& input_method_id) const { | 356 const std::string& input_method_id) const { |
345 InputMethodIdToDescriptorMap::const_iterator iter | 357 InputMethodIdToDescriptorMap::const_iterator iter |
346 = id_to_descriptor_.find(input_method_id); | 358 = id_to_descriptor_.find(input_method_id); |
347 return (iter == id_to_descriptor_.end()) ? | 359 return (iter == id_to_descriptor_.end()) ? |
348 "" : iter->second.keyboard_layout(); | 360 "" : iter->second.keyboard_layout(); |
349 } | 361 } |
350 | 362 |
351 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( | 363 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( |
352 const std::string& input_method_id) const { | 364 const std::string& input_method_id) const { |
353 string16 display_name; | 365 string16 display_name; |
354 if (TranslateStringInternal(input_method_id, &display_name)) { | 366 if (!IsExtensionInputMethod(input_method_id) && |
| 367 TranslateStringInternal(input_method_id, &display_name)) { |
355 return UTF16ToUTF8(display_name); | 368 return UTF16ToUTF8(display_name); |
356 } | 369 } |
357 // Return an empty string if the display name is not found. | 370 // Return an empty string if the display name is not found. |
358 return ""; | 371 return ""; |
359 } | 372 } |
360 | 373 |
361 string16 InputMethodUtil::GetInputMethodShortName( | 374 string16 InputMethodUtil::GetInputMethodShortName( |
362 const InputMethodDescriptor& input_method) const { | 375 const InputMethodDescriptor& input_method) const { |
363 // For the status area, we use two-letter, upper-case language code like | 376 // For the status area, we use two-letter, upper-case language code like |
364 // "US" and "JP". | 377 // "US" and "JP". |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 ReloadInternalMaps(); | 646 ReloadInternalMaps(); |
634 } | 647 } |
635 | 648 |
636 void InputMethodUtil::SetHardwareInputMethodIdForTesting( | 649 void InputMethodUtil::SetHardwareInputMethodIdForTesting( |
637 const std::string& input_method_id) { | 650 const std::string& input_method_id) { |
638 hardware_input_method_id_for_testing_ = input_method_id; | 651 hardware_input_method_id_for_testing_ = input_method_id; |
639 } | 652 } |
640 | 653 |
641 } // namespace input_method | 654 } // namespace input_method |
642 } // namespace chromeos | 655 } // namespace chromeos |
OLD | NEW |