Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / input_method / input_method_util.h
index 32f3efb..8b3b7d7 100644 (file)
@@ -13,6 +13,7 @@
 #include "base/containers/hash_tables.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/strings/string16.h"
+#include "base/threading/thread_checker.h"
 #include "chromeos/ime/input_method_descriptor.h"
 
 namespace chromeos {
@@ -28,17 +29,16 @@ enum InputMethodType {
 // A class which provides miscellaneous input method utility functions.
 class InputMethodUtil {
  public:
-  // |supported_input_methods| is a list of all input methods supported,
-  // including ones not active. The list is used to initialize member variables
-  // in this class.
-  InputMethodUtil(InputMethodDelegate* delegate,
-                  scoped_ptr<InputMethodDescriptors> supported_input_methods);
+  explicit InputMethodUtil(InputMethodDelegate* delegate);
   ~InputMethodUtil();
 
   // Converts a string sent from IBus IME engines, which is written in English,
   // into Chrome's string ID, then pulls internationalized resource string from
   // the resource bundle and returns it. These functions are not thread-safe.
   // Non-UI threads are not allowed to call them.
+  // The english_string to should be a xkb id with "xkb:...:...:..." format.
+  // TODO(shuchen): this method should be removed when finish the wrapping of
+  // xkb to extension.
   base::string16 TranslateString(const std::string& english_string) const;
 
   // Converts an input method ID to a language code of the IME. Returns "Eng"
@@ -57,6 +57,8 @@ class InputMethodUtil {
       const InputMethodDescriptor& input_method) const;
   base::string16 GetInputMethodMediumName(
       const InputMethodDescriptor& input_method) const;
+  base::string16 GetInputMethodLongNameStripped(
+      const InputMethodDescriptor& input_method) const;
   base::string16 GetInputMethodLongName(
       const InputMethodDescriptor& input_method) const;
 
@@ -93,9 +95,38 @@ class InputMethodUtil {
       const std::vector<std::string>& input_method_ids,
       std::vector<std::string>* out_language_codes) const;
 
-  // Returns the input method ID of the hardware keyboard. e.g. "xkb:us::eng"
-  // for the US Qwerty keyboard.
-  std::string GetHardwareInputMethodId() const;
+  // Gets first input method associated with the language.
+  // Returns empty string on error.
+  std::string GetLanguageDefaultInputMethodId(const std::string& language_code);
+
+  // Migrates the legacy xkb id to extension based xkb id.
+  // Returns true if the given input method id list is modified,
+  // returns false otherwise.
+  // This method should not be removed because it's required to transfer XKB
+  // input method ID from VPD into extension-based XKB input method ID.
+  bool MigrateInputMethods(std::vector<std::string>* input_method_ids);
+
+  // Updates the internal cache of hardware layouts.
+  void UpdateHardwareLayoutCache();
+
+  // Set hardware keyboard layout for testing purpose. This is for simulating
+  // "keyboard_layout" entry in VPD values.
+  void SetHardwareKeyboardLayoutForTesting(const std::string& layout);
+
+  // Fills the input method IDs of the hardware keyboard. e.g. "xkb:us::eng"
+  // for US Qwerty keyboard or "xkb:ru::rus" for Russian keyboard.
+  const std::vector<std::string>& GetHardwareInputMethodIds();
+
+  // Returns the login-allowed input method ID of the hardware keyboard, e.g.
+  // "xkb:us::eng" but not include non-login keyboard like "xkb:ru::rus". Please
+  // note that this is not a subset of returned value of
+  // GetHardwareInputMethodIds. If GetHardwareInputMethodIds returns only
+  // non-login keyboard, this function will returns "xkb:us::eng" as the
+  // fallback keyboard.
+  const std::vector<std::string>& GetHardwareLoginInputMethodIds();
+
+  // Returns true if given input method can be used to input login data.
+  bool IsLoginKeyboard(const std::string& input_method_id) const;
 
   // Returns true if the given input method id is supported.
   bool IsValidInputMethodId(const std::string& input_method_id) const;
@@ -103,8 +134,21 @@ class InputMethodUtil {
   // Returns true if the given input method id is for a keyboard layout.
   static bool IsKeyboardLayout(const std::string& input_method_id);
 
-  // Sets the list of component extension IMEs.
-  void SetComponentExtensions(const InputMethodDescriptors& imes);
+  // Resets the list of component extension IMEs.
+  void ResetInputMethods(const InputMethodDescriptors& imes);
+
+  // Appends the additional list of component extension IMEs.
+  void AppendInputMethods(const InputMethodDescriptors& imes);
+
+  // Initializes the extension based xkb IMEs for testing.
+  void InitXkbInputMethodsForTesting();
+
+  // Map from input method ID to associated input method descriptor.
+  typedef std::map<
+    std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap;
+
+  // Gets the id to desctiptor map for testing.
+  const InputMethodIdToDescriptorMap& GetIdToDesciptorMapForTesting();
 
   // Returns the fallback input method descriptor (the very basic US
   // keyboard). This function is mostly used for testing, but may be used
@@ -119,13 +163,6 @@ class InputMethodUtil {
       InputMethodType type,
       std::vector<std::string>* out_input_method_ids) const;
 
-  // protected: for unit testing as well.
-  void ReloadInternalMaps();
-
-  // All input methods that are supported, including ones not active.
-  // protected: for testing.
-  scoped_ptr<InputMethodDescriptors> supported_input_methods_;
-
   // Gets the keyboard layout name from the given input method ID.
   // If the ID is invalid, an empty string will be returned.
   // This function only supports xkb layouts.
@@ -142,27 +179,28 @@ class InputMethodUtil {
   bool TranslateStringInternal(const std::string& english_string,
                                base::string16 *out_string) const;
 
+  // Get long name of the given input method. |short_name| is to specify whether
+  // to get the long name for OOBE screen, because OOBE screen displays shorter
+  // name (e.g. 'US' instead of 'US keyboard').
+  base::string16 GetInputMethodLongNameInternal(
+      const InputMethodDescriptor& input_method, bool short_name) const;
+
   // Map from language code to associated input method IDs, etc.
   typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap;
-  // Map from input method ID to associated input method descriptor.
-  typedef std::map<
-    std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap;
-  // Map from XKB layout ID to associated input method descriptor.
-  typedef std::map<std::string, InputMethodDescriptor> XkbIdToDescriptorMap;
-  // Map from component extention IME id to associated input method descriptor.
-  typedef std::map<std::string, InputMethodDescriptor> ComponentExtIMEMap;
 
   LanguageCodeToIdsMap language_code_to_ids_;
-  std::map<std::string, std::string> id_to_language_code_;
   InputMethodIdToDescriptorMap id_to_descriptor_;
-  XkbIdToDescriptorMap xkb_id_to_descriptor_;
-  ComponentExtIMEMap component_extension_ime_id_to_descriptor_;
 
   typedef base::hash_map<std::string, int> HashType;
   HashType english_to_resource_id_;
 
   InputMethodDelegate* delegate_;
 
+  base::ThreadChecker thread_checker_;
+  std::vector<std::string> hardware_layouts_;
+  std::vector<std::string> hardware_login_layouts_;
+  std::vector<std::string> cached_hardware_layouts_;
+
   DISALLOW_COPY_AND_ASSIGN(InputMethodUtil);
 };