summaryrefslogtreecommitdiffstats
path: root/chromeos/ime/input_method_manager.h
blob: 5a94455882babc296193f8e1897e66b89546d3eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
#define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_

#include <map>
#include <string>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/ime/input_method_config.h"
#include "chromeos/ime/input_method_descriptor.h"
#include "chromeos/ime/input_method_property.h"

namespace ui {
class Accelerator;
}  // namespace ui

namespace chromeos {
class ComponentExtensionIMEManager;
class InputMethodEngine;
namespace input_method {

class InputMethodUtil;
class XKeyboard;

// This class manages input methodshandles.  Classes can add themselves as
// observers. Clients can get an instance of this library class by:
// GetInputMethodManager().
class CHROMEOS_EXPORT InputMethodManager {
 public:
  enum State {
    STATE_LOGIN_SCREEN = 0,
    STATE_BROWSER_SCREEN,
    STATE_LOCK_SCREEN,
    STATE_TERMINATING,
  };

  class Observer {
   public:
    virtual ~Observer() {}
    // Called when the current input method is changed.  |show_message|
    // indicates whether the user should be notified of this change.
    virtual void InputMethodChanged(InputMethodManager* manager,
                                    bool show_message) = 0;
    // Called when the list of properties is changed.
    virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0;
  };

  // CandidateWindowObserver is notified of events related to the candidate
  // window.  The "suggestion window" used by IMEs such as ibus-mozc does not
  // count as the candidate window (this may change if we later want suggestion
  // window events as well).  These events also won't occur when the virtual
  // keyboard is used, since it controls its own candidate window.
  class CandidateWindowObserver {
   public:
    virtual ~CandidateWindowObserver() {}
    // Called when the candidate window is opened.
    virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
    // Called when the candidate window is closed.
    virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
  };

  virtual ~InputMethodManager() {}

  // Gets the global instance of InputMethodManager. Initialize() must be called
  // first.
  static CHROMEOS_EXPORT InputMethodManager* Get();

  // Sets the global instance. |instance| will be owned by the internal pointer
  // and deleted by Shutdown().
  // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
  //             crbug.com/164375 is fixed.
  static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance);

  // Destroy the global instance.
  static CHROMEOS_EXPORT void Shutdown();

  // Adds an observer to receive notifications of input method related
  // changes as desribed in the Observer class above.
  virtual void AddObserver(Observer* observer) = 0;
  virtual void AddCandidateWindowObserver(
      CandidateWindowObserver* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;
  virtual void RemoveCandidateWindowObserver(
      CandidateWindowObserver* observer) = 0;

  // Returns all input methods that are supported, including ones not active.
  // This function never returns NULL. Note that input method extensions are NOT
  // included in the result.
  virtual scoped_ptr<InputMethodDescriptors>
      GetSupportedInputMethods() const = 0;

  // Returns the list of input methods we can select (i.e. active) including
  // extension input methods.
  virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods() const = 0;

  // Returns the list of input methods we can select (i.e. active) including
  // extension input methods.
  // The same as GetActiveInputMethods but returns reference to internal list.
  virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0;

  // Returns the number of active input methods including extension input
  // methods.
  virtual size_t GetNumActiveInputMethods() const = 0;

  // Changes the current input method to |input_method_id|. If |input_method_id|
  // is not active, switch to the first one in the active input method list.
  virtual void ChangeInputMethod(const std::string& input_method_id) = 0;

  // Enables keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that
  // are necessary for the |language_code| and then switches to |initial_layout|
  // if the string is not empty. For example, if |language_code| is "en-US", US
  // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts
  // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds
  // to the hardware keyboard layout and several keyboard layouts for Germany
  // would be enabled.
  // This method is for setting up i18n keyboard layouts for the login screen.
  virtual void EnableLayouts(const std::string& language_code,
                             const std::string& initial_layout) = 0;

  // Activates the input method property specified by the |key|.
  virtual void ActivateInputMethodProperty(const std::string& key) = 0;

  // Updates the list of active input method IDs, and then starts or stops the
  // system input method framework as needed.
  virtual bool EnableInputMethods(
      const std::vector<std::string>& new_active_input_method_ids) = 0;

  // Adds one entry to the list of active input method IDs, and then starts or
  // stops the system input method framework as needed.
  virtual bool EnableInputMethod(
      const std::string& new_active_input_method_id) = 0;

  // Remaps old input methods like "mozc" to new input methods. Return true if
  // at least one IME is migrated.
  // TODO(nona): Remove this function after few milestones are passed.
  //             (http://crbug.com/236747)
  virtual bool MigrateOldInputMethods(
      std::vector<std::string>* input_method_ids) = 0;
  virtual bool MigrateKoreanKeyboard(
      const std::string& keyboard_id,
      std::vector<std::string>* input_method_ids) = 0;

  // Updates a configuration of a system input method engine with |value|.
  // Returns true if the configuration is correctly set.
  virtual bool SetInputMethodConfig(const std::string& section,
                                    const std::string& config_name,
                                    const InputMethodConfigValue& value) = 0;

  // Adds an input method extension. This function does not takes ownership of
  // |instance|.
  virtual void AddInputMethodExtension(
      const std::string& id,
      const std::string& name,
      const std::vector<std::string>& layouts,
      const std::vector<std::string>& languages,
      const GURL& options_url,
      InputMethodEngine* instance) = 0;

  // Removes an input method extension.
  virtual void RemoveInputMethodExtension(const std::string& id) = 0;

  // Returns a list of descriptors for all Input Method Extensions.
  virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;

  // Sets the list of extension IME ids which should be enabled.
  virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;

  // Gets the descriptor of the input method which is currently selected.
  virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;

  // Gets the list of input method properties. The list could be empty().
  virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0;

  // Returns an X keyboard object which could be used to change the current XKB
  // layout, change the caps lock status, and set the auto repeat rate/interval.
  virtual XKeyboard* GetXKeyboard() = 0;

  // Returns an InputMethodUtil object.
  virtual InputMethodUtil* GetInputMethodUtil() = 0;

  // Returns a ComponentExtentionIMEManager object.
  virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;

  // Switches the current input method (or keyboard layout) to the next one.
  virtual bool SwitchToNextInputMethod() = 0;

  // Switches the current input method (or keyboard layout) to the previous one.
  virtual bool SwitchToPreviousInputMethod(
      const ui::Accelerator& accelerator) = 0;

  // Switches to an input method (or keyboard layout) which is associated with
  // the |accelerator|.
  virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0;

  // If keyboard layout can be uset at login screen
  virtual bool IsFullLatinKeyboard(const std::string& layout) const = 0;
};

}  // namespace input_method
}  // namespace chromeos

#endif  // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_