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