| 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> | 
|   11  |   11  | 
|   12 #include "base/basictypes.h" |   12 #include "base/basictypes.h" | 
|   13 #include "base/memory/scoped_ptr.h" |   13 #include "base/memory/scoped_ptr.h" | 
|   14 #include "base/prefs/pref_service.h" |   14 #include "base/prefs/pref_service.h" | 
|   15 #include "base/string_util.h" |   15 #include "base/string_util.h" | 
|   16 #include "base/strings/string_split.h" |   16 #include "base/strings/string_split.h" | 
|   17 #include "base/utf_string_conversions.h" |   17 #include "base/utf_string_conversions.h" | 
 |   18 #include "chromeos/ime/extension_ime_util.h" | 
|   18 #include "chromeos/ime/input_method_delegate.h" |   19 #include "chromeos/ime/input_method_delegate.h" | 
|   19 #include "grit/generated_resources.h" |   20 #include "grit/generated_resources.h" | 
|   20 #include "third_party/icu/public/common/unicode/uloc.h" |   21 #include "third_party/icu/public/common/unicode/uloc.h" | 
|   21 #include "ui/base/l10n/l10n_util.h" |   22 #include "ui/base/l10n/l10n_util.h" | 
|   22 #include "ui/base/l10n/l10n_util_collator.h" |   23 #include "ui/base/l10n/l10n_util_collator.h" | 
|   23  |   24  | 
|   24 namespace { |   25 namespace { | 
|   25  |   26  | 
|   26 // A mapping from an input method id to a string for the language indicator. The |   27 // A mapping from an input method id to a string for the language indicator. The | 
|   27 // mapping is necessary since some input methods belong to the same language. |   28 // mapping is necessary since some input methods belong to the same language. | 
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  360     const std::string& input_method_id) const { |  361     const std::string& input_method_id) const { | 
|  361   return GetInputMethodDescriptorFromId(input_method_id) != NULL; |  362   return GetInputMethodDescriptorFromId(input_method_id) != NULL; | 
|  362 } |  363 } | 
|  363  |  364  | 
|  364 // static |  365 // static | 
|  365 bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { |  366 bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { | 
|  366   const bool kCaseInsensitive = false; |  367   const bool kCaseInsensitive = false; | 
|  367   return StartsWithASCII(input_method_id, "xkb:", kCaseInsensitive); |  368   return StartsWithASCII(input_method_id, "xkb:", kCaseInsensitive); | 
|  368 } |  369 } | 
|  369  |  370  | 
|  370 // static |  | 
|  371 bool InputMethodUtil::IsExtensionInputMethod( |  | 
|  372     const std::string& input_method_id) { |  | 
|  373   const bool kCaseInsensitive = false; |  | 
|  374   return StartsWithASCII(input_method_id, |  | 
|  375                          kExtensionImePrefix, |  | 
|  376                          kCaseInsensitive); |  | 
|  377 } |  | 
|  378  |  | 
|  379 std::string InputMethodUtil::GetLanguageCodeFromInputMethodId( |  371 std::string InputMethodUtil::GetLanguageCodeFromInputMethodId( | 
|  380     const std::string& input_method_id) const { |  372     const std::string& input_method_id) const { | 
|  381   // The code should be compatible with one of codes used for UI languages, |  373   // The code should be compatible with one of codes used for UI languages, | 
|  382   // defined in app/l10_util.cc. |  374   // defined in app/l10_util.cc. | 
|  383   const char kDefaultLanguageCode[] = "en-US"; |  375   const char kDefaultLanguageCode[] = "en-US"; | 
|  384   std::map<std::string, std::string>::const_iterator iter |  376   std::map<std::string, std::string>::const_iterator iter | 
|  385       = id_to_language_code_.find(input_method_id); |  377       = id_to_language_code_.find(input_method_id); | 
|  386   return (iter == id_to_language_code_.end()) ? |  378   return (iter == id_to_language_code_.end()) ? | 
|  387       // Returning |kDefaultLanguageCode| here is not for Chrome OS but for |  379       // Returning |kDefaultLanguageCode| here is not for Chrome OS but for | 
|  388       // Ubuntu where the ibus-xkb-layouts engine could be missing. |  380       // Ubuntu where the ibus-xkb-layouts engine could be missing. | 
|  389       kDefaultLanguageCode : iter->second; |  381       kDefaultLanguageCode : iter->second; | 
|  390 } |  382 } | 
|  391  |  383  | 
|  392 std::string InputMethodUtil::GetKeyboardLayoutName( |  384 std::string InputMethodUtil::GetKeyboardLayoutName( | 
|  393     const std::string& input_method_id) const { |  385     const std::string& input_method_id) const { | 
|  394   InputMethodIdToDescriptorMap::const_iterator iter |  386   InputMethodIdToDescriptorMap::const_iterator iter | 
|  395       = id_to_descriptor_.find(input_method_id); |  387       = id_to_descriptor_.find(input_method_id); | 
|  396   return (iter == id_to_descriptor_.end()) ? |  388   return (iter == id_to_descriptor_.end()) ? | 
|  397       "" : iter->second.keyboard_layout(); |  389       "" : iter->second.keyboard_layout(); | 
|  398 } |  390 } | 
|  399  |  391  | 
|  400 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( |  392 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( | 
|  401     const std::string& input_method_id) const { |  393     const std::string& input_method_id) const { | 
|  402   string16 display_name; |  394   string16 display_name; | 
|  403   if (!IsExtensionInputMethod(input_method_id) && |  395   if (!extension_ime_util::IsExtensionIME(input_method_id) && | 
|  404       TranslateStringInternal(input_method_id, &display_name)) { |  396       TranslateStringInternal(input_method_id, &display_name)) { | 
|  405     return UTF16ToUTF8(display_name); |  397     return UTF16ToUTF8(display_name); | 
|  406   } |  398   } | 
|  407   // Return an empty string if the display name is not found. |  399   // Return an empty string if the display name is not found. | 
|  408   return ""; |  400   return ""; | 
|  409 } |  401 } | 
|  410  |  402  | 
|  411 string16 InputMethodUtil::GetInputMethodShortName( |  403 string16 InputMethodUtil::GetInputMethodShortName( | 
|  412     const InputMethodDescriptor& input_method) const { |  404     const InputMethodDescriptor& input_method) const { | 
|  413   // For the status area, we use two-letter, upper-case language code like |  405   // For the status area, we use two-letter, upper-case language code like | 
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  717     } |  709     } | 
|  718   } |  710   } | 
|  719 } |  711 } | 
|  720  |  712  | 
|  721 void InputMethodUtil::OnLocaleChanged() { |  713 void InputMethodUtil::OnLocaleChanged() { | 
|  722   ReloadInternalMaps(); |  714   ReloadInternalMaps(); | 
|  723 } |  715 } | 
|  724  |  716  | 
|  725 }  // namespace input_method |  717 }  // namespace input_method | 
|  726 }  // namespace chromeos |  718 }  // namespace chromeos | 
| OLD | NEW |