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|.
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;
114 IMEEngineHandlerInterface() {}
117 // A interface to handle the candidate window related method call.
118 class UI_BASE_IME_EXPORT IMECandidateWindowHandlerInterface
{
120 virtual ~IMECandidateWindowHandlerInterface() {}
122 // Called when the IME updates the lookup table.
123 virtual void UpdateLookupTable(const ui::CandidateWindow
& candidate_window
,
126 // Called when the IME updates the preedit text. The |text| is given in
128 virtual void UpdatePreeditText(const base::string16
& text
,
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
) {}
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
{
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()
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;
201 DISALLOW_COPY_AND_ASSIGN(IMEBridge
);
204 } // namespace chromeos
206 #endif // UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_