Home | History | Annotate | Download | only in ime
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
      6 #define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
      7 
      8 #include <map>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/memory/scoped_ptr.h"
     13 #include "chromeos/chromeos_export.h"
     14 #include "chromeos/ime/input_method_config.h"
     15 #include "chromeos/ime/input_method_descriptor.h"
     16 #include "chromeos/ime/input_method_property.h"
     17 
     18 namespace ui {
     19 class Accelerator;
     20 }  // namespace ui
     21 
     22 namespace chromeos {
     23 class ComponentExtensionIMEManager;
     24 class InputMethodEngine;
     25 namespace input_method {
     26 
     27 class InputMethodUtil;
     28 class XKeyboard;
     29 
     30 // This class manages input methodshandles.  Classes can add themselves as
     31 // observers. Clients can get an instance of this library class by:
     32 // GetInputMethodManager().
     33 class CHROMEOS_EXPORT InputMethodManager {
     34  public:
     35   enum State {
     36     STATE_LOGIN_SCREEN = 0,
     37     STATE_BROWSER_SCREEN,
     38     STATE_LOCK_SCREEN,
     39     STATE_TERMINATING,
     40   };
     41 
     42   class Observer {
     43    public:
     44     virtual ~Observer() {}
     45     // Called when the current input method is changed.  |show_message|
     46     // indicates whether the user should be notified of this change.
     47     virtual void InputMethodChanged(InputMethodManager* manager,
     48                                     bool show_message) = 0;
     49     // Called when the list of properties is changed.
     50     virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0;
     51   };
     52 
     53   // CandidateWindowObserver is notified of events related to the candidate
     54   // window.  The "suggestion window" used by IMEs such as ibus-mozc does not
     55   // count as the candidate window (this may change if we later want suggestion
     56   // window events as well).  These events also won't occur when the virtual
     57   // keyboard is used, since it controls its own candidate window.
     58   class CandidateWindowObserver {
     59    public:
     60     virtual ~CandidateWindowObserver() {}
     61     // Called when the candidate window is opened.
     62     virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
     63     // Called when the candidate window is closed.
     64     virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
     65   };
     66 
     67   virtual ~InputMethodManager() {}
     68 
     69   // Gets the global instance of InputMethodManager. Initialize() must be called
     70   // first.
     71   static CHROMEOS_EXPORT InputMethodManager* Get();
     72 
     73   // Sets the global instance. |instance| will be owned by the internal pointer
     74   // and deleted by Shutdown().
     75   // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
     76   //             crbug.com/164375 is fixed.
     77   static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance);
     78 
     79   // Destroy the global instance.
     80   static CHROMEOS_EXPORT void Shutdown();
     81 
     82   // Adds an observer to receive notifications of input method related
     83   // changes as desribed in the Observer class above.
     84   virtual void AddObserver(Observer* observer) = 0;
     85   virtual void AddCandidateWindowObserver(
     86       CandidateWindowObserver* observer) = 0;
     87   virtual void RemoveObserver(Observer* observer) = 0;
     88   virtual void RemoveCandidateWindowObserver(
     89       CandidateWindowObserver* observer) = 0;
     90 
     91   // Returns all input methods that are supported, including ones not active.
     92   // This function never returns NULL. Note that input method extensions are NOT
     93   // included in the result.
     94   virtual scoped_ptr<InputMethodDescriptors>
     95       GetSupportedInputMethods() const = 0;
     96 
     97   // Returns the list of input methods we can select (i.e. active) including
     98   // extension input methods.
     99   virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods() const = 0;
    100 
    101   // Returns the list of input methods we can select (i.e. active) including
    102   // extension input methods.
    103   // The same as GetActiveInputMethods but returns reference to internal list.
    104   virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0;
    105 
    106   // Returns the number of active input methods including extension input
    107   // methods.
    108   virtual size_t GetNumActiveInputMethods() const = 0;
    109 
    110   // Changes the current input method to |input_method_id|. If |input_method_id|
    111   // is not active, switch to the first one in the active input method list.
    112   virtual void ChangeInputMethod(const std::string& input_method_id) = 0;
    113 
    114   // Enables keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that
    115   // are necessary for the |language_code| and then switches to |initial_layout|
    116   // if the string is not empty. For example, if |language_code| is "en-US", US
    117   // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts
    118   // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds
    119   // to the hardware keyboard layout and several keyboard layouts for Germany
    120   // would be enabled.
    121   // This method is for setting up i18n keyboard layouts for the login screen.
    122   virtual void EnableLayouts(const std::string& language_code,
    123                              const std::string& initial_layout) = 0;
    124 
    125   // Activates the input method property specified by the |key|.
    126   virtual void ActivateInputMethodProperty(const std::string& key) = 0;
    127 
    128   // Updates the list of active input method IDs, and then starts or stops the
    129   // system input method framework as needed.
    130   virtual bool EnableInputMethods(
    131       const std::vector<std::string>& new_active_input_method_ids) = 0;
    132 
    133   // Adds one entry to the list of active input method IDs, and then starts or
    134   // stops the system input method framework as needed.
    135   virtual bool EnableInputMethod(
    136       const std::string& new_active_input_method_id) = 0;
    137 
    138   // Remaps old input methods like "mozc" to new input methods. Return true if
    139   // at least one IME is migrated.
    140   // TODO(nona): Remove this function after few milestones are passed.
    141   //             (http://crbug.com/236747)
    142   virtual bool MigrateOldInputMethods(
    143       std::vector<std::string>* input_method_ids) = 0;
    144   virtual bool MigrateKoreanKeyboard(
    145       const std::string& keyboard_id,
    146       std::vector<std::string>* input_method_ids) = 0;
    147 
    148   // Updates a configuration of a system input method engine with |value|.
    149   // Returns true if the configuration is correctly set.
    150   virtual bool SetInputMethodConfig(const std::string& section,
    151                                     const std::string& config_name,
    152                                     const InputMethodConfigValue& value) = 0;
    153 
    154   // Adds an input method extension. This function does not takes ownership of
    155   // |instance|.
    156   virtual void AddInputMethodExtension(
    157       const std::string& id,
    158       const std::string& name,
    159       const std::vector<std::string>& layouts,
    160       const std::vector<std::string>& languages,
    161       const GURL& options_url,
    162       InputMethodEngine* instance) = 0;
    163 
    164   // Removes an input method extension.
    165   virtual void RemoveInputMethodExtension(const std::string& id) = 0;
    166 
    167   // Returns a list of descriptors for all Input Method Extensions.
    168   virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
    169 
    170   // Sets the list of extension IME ids which should be enabled.
    171   virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;
    172 
    173   // Sets current input method to default (first owners, then hardware).
    174   virtual void SetInputMethodDefault() = 0;
    175 
    176   // Gets the descriptor of the input method which is currently selected.
    177   virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
    178 
    179   // Gets the list of input method properties. The list could be empty().
    180   virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0;
    181 
    182   // Returns an X keyboard object which could be used to change the current XKB
    183   // layout, change the caps lock status, and set the auto repeat rate/interval.
    184   virtual XKeyboard* GetXKeyboard() = 0;
    185 
    186   // Returns an InputMethodUtil object.
    187   virtual InputMethodUtil* GetInputMethodUtil() = 0;
    188 
    189   // Returns a ComponentExtentionIMEManager object.
    190   virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
    191 
    192   // Switches the current input method (or keyboard layout) to the next one.
    193   virtual bool SwitchToNextInputMethod() = 0;
    194 
    195   // Switches the current input method (or keyboard layout) to the previous one.
    196   virtual bool SwitchToPreviousInputMethod(
    197       const ui::Accelerator& accelerator) = 0;
    198 
    199   // Switches to an input method (or keyboard layout) which is associated with
    200   // the |accelerator|.
    201   virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
    202 
    203   // If keyboard layout can be uset at login screen
    204   virtual bool IsFullLatinKeyboard(const std::string& layout) const = 0;
    205 };
    206 
    207 }  // namespace input_method
    208 }  // namespace chromeos
    209 
    210 #endif  // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
    211