Add ICU message format support
[chromium-blink-merge.git] / ui / base / ime / chromeos / ime_bridge.h
blob09dd33f31a21b13a1565235960a852eebfd67b27
1 // Copyright 2014 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 UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_
6 #define UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_
8 #include <string>
9 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/strings/string16.h"
13 #include "ui/base/ime/text_input_mode.h"
14 #include "ui/base/ime/text_input_type.h"
15 #include "ui/base/ime/ui_base_ime_export.h"
17 namespace gfx {
18 class Rect;
19 } // namespace gfx
21 namespace ui {
22 class CandidateWindow;
23 class KeyEvent;
24 } // namespace ui
26 namespace chromeos {
28 class CompositionText;
30 class UI_BASE_IME_EXPORT IMEInputContextHandlerInterface {
31 public:
32 // Called when the engine commit a text.
33 virtual void CommitText(const std::string& text) = 0;
35 // Called when the engine updates composition text.
36 virtual void UpdateCompositionText(const CompositionText& text,
37 uint32 cursor_pos,
38 bool visible) = 0;
40 // Called when the engine request deleting surrounding string.
41 virtual void DeleteSurroundingText(int32 offset, uint32 length) = 0;
45 // A interface to handle the engine handler method call.
46 class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
47 public:
48 typedef base::Callback<void (bool consumed)> KeyEventDoneCallback;
50 // A information about a focused text input field.
51 // A type of each member is based on the html spec, but InputContext can be
52 // used to specify about a non html text field like Omnibox.
53 struct InputContext {
54 InputContext(ui::TextInputType type_, ui::TextInputMode mode_, int flags_) :
55 type(type_), mode(mode_), flags(flags_) {}
57 // An attribute of the field defined at
58 // http://www.w3.org/TR/html401/interact/forms.html#input-control-types.
59 ui::TextInputType type;
60 // An attribute of the field defined at
61 // http://www.whatwg.org/specs/web-apps/current-work/multipage/
62 // association-of-controls-and-forms.html#input-modalities
63 // :-the-inputmode-attribute.
64 ui::TextInputMode mode;
65 // An antribute to indicate the flags for web input fields. Please refer to
66 // WebTextInputType.
67 int flags;
70 virtual ~IMEEngineHandlerInterface() {}
72 // Called when the Chrome input field get the focus.
73 virtual void FocusIn(const InputContext& input_context) = 0;
75 // Called when the Chrome input field lose the focus.
76 virtual void FocusOut() = 0;
78 // Called when the IME is enabled.
79 virtual void Enable(const std::string& component_id) = 0;
81 // Called when the IME is disabled.
82 virtual void Disable() = 0;
84 // Called when a property is activated or changed.
85 virtual void PropertyActivate(const std::string& property_name) = 0;
87 // Called when the IME is reset.
88 virtual void Reset() = 0;
90 // Called when the key event is received.
91 // Actual implementation must call |callback| after key event handling.
92 virtual void ProcessKeyEvent(const ui::KeyEvent& key_event,
93 const KeyEventDoneCallback& callback) = 0;
95 // Called when the candidate in lookup table is clicked. The |index| is 0
96 // based candidate index in lookup table.
97 virtual void CandidateClicked(uint32 index) = 0;
99 // Called when a new surrounding text is set. The |text| is surrounding text
100 // and |cursor_pos| is 0 based index of cursor position in |text|. If there is
101 // selection range, |anchor_pos| represents opposite index from |cursor_pos|.
102 // Otherwise |anchor_pos| is equal to |cursor_pos|.
103 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos,
104 uint32 anchor_pos) = 0;
106 // Called when the composition bounds changed.
107 virtual void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) = 0;
109 // Returns whether the engine is interested in key events.
110 // If not, InputMethodChromeOS won't feed it with key events.
111 virtual bool IsInterestedInKeyEvent() const = 0;
113 protected:
114 IMEEngineHandlerInterface() {}
117 // A interface to handle the candidate window related method call.
118 class UI_BASE_IME_EXPORT IMECandidateWindowHandlerInterface {
119 public:
120 virtual ~IMECandidateWindowHandlerInterface() {}
122 // Called when the IME updates the lookup table.
123 virtual void UpdateLookupTable(const ui::CandidateWindow& candidate_window,
124 bool visible) = 0;
126 // Called when the IME updates the preedit text. The |text| is given in
127 // UTF-16 encoding.
128 virtual void UpdatePreeditText(const base::string16& text,
129 uint32 cursor_pos,
130 bool visible) = 0;
132 // Called when the application changes its caret bounds.
133 virtual void SetCursorBounds(const gfx::Rect& cursor_bounds,
134 const gfx::Rect& composition_head) = 0;
136 // Called when the text field's focus state is changed.
137 // |is_focused| is true when the text field gains the focus.
138 virtual void FocusStateChanged(bool is_focused) {}
140 protected:
141 IMECandidateWindowHandlerInterface() {}
145 // IMEBridge provides access of each IME related handler. This class
146 // is used for IME implementation.
147 class UI_BASE_IME_EXPORT IMEBridge {
148 public:
149 virtual ~IMEBridge();
151 // Allocates the global instance. Must be called before any calls to Get().
152 static void Initialize();
154 // Releases the global instance.
155 static void Shutdown();
157 // Returns IMEBridge global instance. Initialize() must be called first.
158 static IMEBridge* Get();
160 // Returns current InputContextHandler. This function returns NULL if input
161 // context is not ready to use.
162 virtual IMEInputContextHandlerInterface* GetInputContextHandler() const = 0;
164 // Updates current InputContextHandler. If there is no active input context,
165 // pass NULL for |handler|. Caller must release |handler|.
166 virtual void SetInputContextHandler(
167 IMEInputContextHandlerInterface* handler) = 0;
169 // Updates current EngineHandler. If there is no active engine service, pass
170 // NULL for |handler|. Caller must release |handler|.
171 virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) = 0;
173 // Returns current EngineHandler. This function returns NULL if current engine
174 // is not ready to use.
175 virtual IMEEngineHandlerInterface* GetCurrentEngineHandler() const = 0;
177 // Returns current CandidateWindowHandler. This function returns NULL if
178 // current candidate window is not ready to use.
179 virtual IMECandidateWindowHandlerInterface* GetCandidateWindowHandler()
180 const = 0;
182 // Updates current CandidatWindowHandler. If there is no active candidate
183 // window service, pass NULL for |handler|. Caller must release |handler|.
184 virtual void SetCandidateWindowHandler(
185 IMECandidateWindowHandlerInterface* handler) = 0;
187 // Updates the current input context.
188 // This is called from InputMethodChromeOS.
189 virtual void SetCurrentInputContext(
190 const IMEEngineHandlerInterface::InputContext& input_context) = 0;
192 // Returns the current input context.
193 // This is called from InputMethodEngine.
194 virtual const IMEEngineHandlerInterface::InputContext&
195 GetCurrentInputContext() const = 0;
197 protected:
198 IMEBridge();
200 private:
201 DISALLOW_COPY_AND_ASSIGN(IMEBridge);
204 } // namespace chromeos
206 #endif // UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_