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_
9 #include "base/basictypes.h"
10 #include "base/callback.h"
11 #include "base/strings/string16.h"
12 #include "ui/base/ime/text_input_mode.h"
13 #include "ui/base/ime/text_input_type.h"
14 #include "ui/base/ui_base_export.h"
21 class CandidateWindow
;
27 class CompositionText
;
29 class UI_BASE_EXPORT IMEInputContextHandlerInterface
{
31 // Called when the engine commit a text.
32 virtual void CommitText(const std::string
& text
) = 0;
34 // Called when the engine updates composition text.
35 virtual void UpdateCompositionText(const CompositionText
& text
,
39 // Called when the engine request deleting surrounding string.
40 virtual void DeleteSurroundingText(int32 offset
, uint32 length
) = 0;
44 // A interface to handle the engine handler method call.
45 class UI_BASE_EXPORT IMEEngineHandlerInterface
{
47 typedef base::Callback
<void (bool consumed
)> KeyEventDoneCallback
;
49 // A information about a focused text input field.
50 // A type of each member is based on the html spec, but InputContext can be
51 // used to specify about a non html text field like Omnibox.
53 InputContext(ui::TextInputType type_
, ui::TextInputMode mode_
) :
54 type(type_
), mode(mode_
) {}
56 // An attribute of the field defined at
57 // http://www.w3.org/TR/html401/interact/forms.html#input-control-types.
58 ui::TextInputType type
;
59 // An attribute of the field defined at
60 // http://www.whatwg.org/specs/web-apps/current-work/multipage/
61 // association-of-controls-and-forms.html#input-modalities
62 // :-the-inputmode-attribute.
63 ui::TextInputMode mode
;
66 virtual ~IMEEngineHandlerInterface() {}
68 // Called when the Chrome input field get the focus.
69 virtual void FocusIn(const InputContext
& input_context
) = 0;
71 // Called when the Chrome input field lose the focus.
72 virtual void FocusOut() = 0;
74 // Called when the IME is enabled.
75 virtual void Enable() = 0;
77 // Called when the IME is disabled.
78 virtual void Disable() = 0;
80 // Called when a property is activated or changed.
81 virtual void PropertyActivate(const std::string
& property_name
) = 0;
83 // Called when the IME is reset.
84 virtual void Reset() = 0;
86 // Called when the key event is received.
87 // Actual implementation must call |callback| after key event handling.
88 virtual void ProcessKeyEvent(const ui::KeyEvent
& key_event
,
89 const KeyEventDoneCallback
& callback
) = 0;
91 // Called when the candidate in lookup table is clicked. The |index| is 0
92 // based candidate index in lookup table.
93 virtual void CandidateClicked(uint32 index
) = 0;
95 // Called when a new surrounding text is set. The |text| is surrounding text
96 // and |cursor_pos| is 0 based index of cursor position in |text|. If there is
97 // selection range, |anchor_pos| represents opposite index from |cursor_pos|.
98 // Otherwise |anchor_pos| is equal to |cursor_pos|.
99 virtual void SetSurroundingText(const std::string
& text
, uint32 cursor_pos
,
100 uint32 anchor_pos
) = 0;
103 IMEEngineHandlerInterface() {}
106 // A interface to handle the candidate window related method call.
107 class UI_BASE_EXPORT IMECandidateWindowHandlerInterface
{
109 virtual ~IMECandidateWindowHandlerInterface() {}
111 // Called when the IME updates the lookup table.
112 virtual void UpdateLookupTable(const ui::CandidateWindow
& candidate_window
,
115 // Called when the IME updates the preedit text. The |text| is given in
117 virtual void UpdatePreeditText(const base::string16
& text
,
121 // Called when the application changes its caret bounds.
122 virtual void SetCursorBounds(const gfx::Rect
& cursor_bounds
,
123 const gfx::Rect
& composition_head
) = 0;
125 // Called when the text field's focus state is changed.
126 // |is_focused| is true when the text field gains the focus.
127 virtual void FocusStateChanged(bool is_focused
) {}
130 IMECandidateWindowHandlerInterface() {}
134 // IMEBridge provides access of each IME related handler. This class
135 // is used for IME implementation.
136 class UI_BASE_EXPORT IMEBridge
{
138 virtual ~IMEBridge();
140 // Allocates the global instance. Must be called before any calls to Get().
141 static void Initialize();
143 // Releases the global instance.
144 static void Shutdown();
146 // Returns IMEBridge global instance. Initialize() must be called first.
147 static IMEBridge
* Get();
149 // Returns current InputContextHandler. This function returns NULL if input
150 // context is not ready to use.
151 virtual IMEInputContextHandlerInterface
* GetInputContextHandler() const = 0;
153 // Updates current InputContextHandler. If there is no active input context,
154 // pass NULL for |handler|. Caller must release |handler|.
155 virtual void SetInputContextHandler(
156 IMEInputContextHandlerInterface
* handler
) = 0;
158 // Updates current EngineHandler. If there is no active engine service, pass
159 // NULL for |handler|. Caller must release |handler|.
160 virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface
* handler
) = 0;
162 // Returns current EngineHandler. This function returns NULL if current engine
163 // is not ready to use.
164 virtual IMEEngineHandlerInterface
* GetCurrentEngineHandler() const = 0;
166 // Returns current CandidateWindowHandler. This function returns NULL if
167 // current candidate window is not ready to use.
168 virtual IMECandidateWindowHandlerInterface
* GetCandidateWindowHandler()
171 // Updates current CandidatWindowHandler. If there is no active candidate
172 // window service, pass NULL for |handler|. Caller must release |handler|.
173 virtual void SetCandidateWindowHandler(
174 IMECandidateWindowHandlerInterface
* handler
) = 0;
176 // Updates current text input type.
177 virtual void SetCurrentTextInputType(ui::TextInputType input_type
) = 0;
179 // Returns the current text input type.
180 virtual ui::TextInputType
GetCurrentTextInputType() const = 0;
186 DISALLOW_COPY_AND_ASSIGN(IMEBridge
);
189 } // namespace chromeos
191 #endif // UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_