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.
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_
12 #include "base/logging.h" // for NOTIMPLEMENTED()
13 #include "chrome/browser/chromeos/input_method/input_method_config.h"
14 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h"
15 #include "chrome/browser/chromeos/input_method/input_method_property.h"
16 #include "chrome/browser/chromeos/input_method/input_method_util.h"
23 class InputMethodEngine
;
24 namespace input_method
{
28 // This class manages input methodshandles. Classes can add themselves as
29 // observers. Clients can get an instance of this library class by:
30 // InputMethodManager::GetInstance().
31 class InputMethodManager
{
34 STATE_LOGIN_SCREEN
= 0,
42 virtual ~Observer() {}
43 // Called when the current input method is changed. |show_message|
44 // indicates whether the user should be notified of this change.
45 virtual void InputMethodChanged(InputMethodManager
* manager
,
46 bool show_message
) = 0;
47 // Called when the list of properties is changed.
48 virtual void InputMethodPropertyChanged(InputMethodManager
* manager
) = 0;
51 // CandidateWindowObserver is notified of events related to the candidate
52 // window. The "suggestion window" used by IMEs such as ibus-mozc does not
53 // count as the candidate window (this may change if we later want suggestion
54 // window events as well). These events also won't occur when the virtual
55 // keyboard is used, since it controls its own candidate window.
56 class CandidateWindowObserver
{
58 virtual ~CandidateWindowObserver() {}
59 // Called when the candidate window is opened.
60 virtual void CandidateWindowOpened(InputMethodManager
* manager
) = 0;
61 // Called when the candidate window is closed.
62 virtual void CandidateWindowClosed(InputMethodManager
* manager
) = 0;
65 virtual ~InputMethodManager() {}
67 // Adds an observer to receive notifications of input method related
68 // changes as desribed in the Observer class above.
69 virtual void AddObserver(Observer
* observer
) = 0;
70 virtual void AddCandidateWindowObserver(
71 CandidateWindowObserver
* observer
) = 0;
72 virtual void RemoveObserver(Observer
* observer
) = 0;
73 virtual void RemoveCandidateWindowObserver(
74 CandidateWindowObserver
* observer
) = 0;
76 // Sets the current browser status.
77 virtual void SetState(State new_state
) = 0;
79 // Returns all input methods that are supported, including ones not active.
80 // Caller has to delete the returned list. This function never returns NULL.
81 // Note that input method extensions are NOT included in the result.
82 virtual InputMethodDescriptors
* GetSupportedInputMethods() const = 0;
84 // Returns the list of input methods we can select (i.e. active) including
85 // extension input methods. Caller has to delete the returned list.
86 virtual InputMethodDescriptors
* GetActiveInputMethods() const = 0;
88 // Returns the number of active input methods including extension input
90 virtual size_t GetNumActiveInputMethods() const = 0;
92 // Changes the current input method to |input_method_id|. If |input_method_id|
93 // is not active, switch to the first one in the active input method list.
94 virtual void ChangeInputMethod(const std::string
& input_method_id
) = 0;
96 // Enables keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that
97 // are necessary for the |language_code| and then switches to |initial_layout|
98 // if the string is not empty. For example, if |language_code| is "en-US", US
99 // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts
100 // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds
101 // to the hardware keyboard layout and several keyboard layouts for Germany
103 // This method is for setting up i18n keyboard layouts for the login screen.
104 virtual void EnableLayouts(const std::string
& language_code
,
105 const std::string
& initial_layout
) = 0;
107 // Activates the input method property specified by the |key|.
108 virtual void ActivateInputMethodProperty(const std::string
& key
) = 0;
110 // Updates the list of active input method IDs, and then starts or stops the
111 // system input method framework as needed.
112 virtual bool EnableInputMethods(
113 const std::vector
<std::string
>& new_active_input_method_ids
) = 0;
115 // Updates a configuration of a system input method engine with |value|.
116 // Returns true if the configuration is correctly set.
117 virtual bool SetInputMethodConfig(const std::string
& section
,
118 const std::string
& config_name
,
119 const InputMethodConfigValue
& value
) = 0;
121 // Adds an input method extension. This function does not takes ownership of
123 virtual void AddInputMethodExtension(const std::string
& id
,
124 const std::string
& name
,
125 const std::vector
<std::string
>& layouts
,
126 const std::string
& language
,
127 InputMethodEngine
* instance
) = 0;
129 // Removes an input method extension.
130 virtual void RemoveInputMethodExtension(const std::string
& id
) = 0;
132 // Returns a list of descriptors for all Input Method Extensions.
133 virtual void GetInputMethodExtensions(InputMethodDescriptors
* result
) = 0;
135 // Sets the list of extension IME ids which should not be enabled.
136 virtual void SetFilteredExtensionImes(std::vector
<std::string
>* ids
) = 0;
138 // Gets the descriptor of the input method which is currently selected.
139 virtual InputMethodDescriptor
GetCurrentInputMethod() const = 0;
141 // Gets the list of input method properties. The list could be empty().
142 virtual InputMethodPropertyList
GetCurrentInputMethodProperties() const = 0;
144 // Returns an X keyboard object which could be used to change the current XKB
145 // layout, change the caps lock status, and set the auto repeat rate/interval.
146 virtual XKeyboard
* GetXKeyboard() = 0;
148 // Returns an InputMethodUtil object.
149 virtual InputMethodUtil
* GetInputMethodUtil() = 0;
151 // Switches the current input method (or keyboard layout) to the next one.
152 virtual bool SwitchToNextInputMethod() = 0;
154 // Switches the current input method (or keyboard layout) to the previous one.
155 virtual bool SwitchToPreviousInputMethod() = 0;
157 // Switches to an input method (or keyboard layout) which is associated with
158 // the |accelerator|.
159 virtual bool SwitchInputMethod(const ui::Accelerator
& accelerator
) = 0;
161 // Sets the global instance. Must be called before any calls to GetInstance().
162 // We explicitly initialize and shut down the global object, rather than
163 // making it a Singleton, to ensure clean startup and shutdown.
164 static void Initialize();
166 // Similar to Initialize(), but can inject an alternative
167 // InputMethodManager such as MockInputMethodManager for testing.
168 // The injected object will be owned by the internal pointer and deleted
170 static void InitializeForTesting(InputMethodManager
* mock_manager
);
172 // Destroys the global instance.
173 static void Shutdown();
175 // Gets the global instance. Initialize() or InitializeForTesting() must be
177 static InputMethodManager
* GetInstance();
180 } // namespace input_method
181 } // namespace chromeos
183 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_