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_
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"
22 class CandidateWindow
;
28 class CompositionText
;
30 class UI_BASE_IME_EXPORT IMEInputContextHandlerInterface
{
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
,
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
{
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.
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
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|. If not all surrounding
103 // text is given |offset_pos| indicates the starting offset of |text|.
104 virtual void SetSurroundingText(const std::string
& text
,
107 uint32 offset_pos
) = 0;
109 // Called when the composition bounds changed.
110 virtual void SetCompositionBounds(const std::vector
<gfx::Rect
>& bounds
) = 0;
112 // Returns whether the engine is interested in key events.
113 // If not, InputMethodChromeOS won't feed it with key events.
114 virtual bool IsInterestedInKeyEvent() const = 0;
117 IMEEngineHandlerInterface() {}
120 // A interface to handle the candidate window related method call.
121 class UI_BASE_IME_EXPORT IMECandidateWindowHandlerInterface
{
123 virtual ~IMECandidateWindowHandlerInterface() {}
125 // Called when the IME updates the lookup table.
126 virtual void UpdateLookupTable(const ui::CandidateWindow
& candidate_window
,
129 // Called when the IME updates the preedit text. The |text| is given in
131 virtual void UpdatePreeditText(const base::string16
& text
,
135 // Called when the application changes its caret bounds.
136 virtual void SetCursorBounds(const gfx::Rect
& cursor_bounds
,
137 const gfx::Rect
& composition_head
) = 0;
139 // Called when the text field's focus state is changed.
140 // |is_focused| is true when the text field gains the focus.
141 virtual void FocusStateChanged(bool is_focused
) {}
144 IMECandidateWindowHandlerInterface() {}
148 // IMEBridge provides access of each IME related handler. This class
149 // is used for IME implementation.
150 class UI_BASE_IME_EXPORT IMEBridge
{
152 virtual ~IMEBridge();
154 // Allocates the global instance. Must be called before any calls to Get().
155 static void Initialize();
157 // Releases the global instance.
158 static void Shutdown();
160 // Returns IMEBridge global instance. Initialize() must be called first.
161 static IMEBridge
* Get();
163 // Returns current InputContextHandler. This function returns NULL if input
164 // context is not ready to use.
165 virtual IMEInputContextHandlerInterface
* GetInputContextHandler() const = 0;
167 // Updates current InputContextHandler. If there is no active input context,
168 // pass NULL for |handler|. Caller must release |handler|.
169 virtual void SetInputContextHandler(
170 IMEInputContextHandlerInterface
* handler
) = 0;
172 // Updates current EngineHandler. If there is no active engine service, pass
173 // NULL for |handler|. Caller must release |handler|.
174 virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface
* handler
) = 0;
176 // Returns current EngineHandler. This function returns NULL if current engine
177 // is not ready to use.
178 virtual IMEEngineHandlerInterface
* GetCurrentEngineHandler() const = 0;
180 // Returns current CandidateWindowHandler. This function returns NULL if
181 // current candidate window is not ready to use.
182 virtual IMECandidateWindowHandlerInterface
* GetCandidateWindowHandler()
185 // Updates current CandidatWindowHandler. If there is no active candidate
186 // window service, pass NULL for |handler|. Caller must release |handler|.
187 virtual void SetCandidateWindowHandler(
188 IMECandidateWindowHandlerInterface
* handler
) = 0;
190 // Updates the current input context.
191 // This is called from InputMethodChromeOS.
192 virtual void SetCurrentInputContext(
193 const IMEEngineHandlerInterface::InputContext
& input_context
) = 0;
195 // Returns the current input context.
196 // This is called from InputMethodEngine.
197 virtual const IMEEngineHandlerInterface::InputContext
&
198 GetCurrentInputContext() const = 0;
204 DISALLOW_COPY_AND_ASSIGN(IMEBridge
);
207 } // namespace chromeos
209 #endif // UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_