1 // Copyright (c) 2012 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.
4 // TODO(nona): Rename this file to ime_bridge.h
6 #ifndef CHROMEOS_IME_IBUS_BRIDGE_H_
7 #define CHROMEOS_IME_IBUS_BRIDGE_H_
10 #include "base/basictypes.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h"
13 #include "chromeos/ime/ime_constants.h"
14 #include "chromeos/ime/input_method_property.h"
17 namespace input_method {
18 class CandidateWindow;
19 } // namespace input_method
23 class CHROMEOS_EXPORT IBusInputContextHandlerInterface {
25 // Called when the engine commit a text.
26 virtual void CommitText(const std::string& text) = 0;
28 // Called when the engine forward a key event.
29 virtual void ForwardKeyEvent(uint32 keyval, uint32 keycode, uint32 state) = 0;
31 // Called when the engine update preedit stroing.
32 virtual void UpdatePreeditText(const IBusText& text,
36 // Called when the engine request showing preedit string.
37 virtual void ShowPreeditText() = 0;
39 // Called when the engine request hiding preedit string.
40 virtual void HidePreeditText() = 0;
42 // Called when the engine request deleting surrounding string.
43 virtual void DeleteSurroundingText(int32 offset, uint32 length) = 0;
47 // A interface to handle the engine handler method call.
48 class CHROMEOS_EXPORT IBusEngineHandlerInterface {
50 typedef base::Callback<void (bool consumed)> KeyEventDoneCallback;
52 // Following capability mask is introduced from
53 // http://ibus.googlecode.com/svn/docs/ibus-1.4/ibus-ibustypes.html#IBusCapabilite
54 // TODO(nona): Move to ibus_contants and merge one in ui/base/ime/*
56 IBUS_CAPABILITY_PREEDIT_TEXT = 1U,
57 IBUS_CAPABILITY_FOCUS = 8U,
60 virtual ~IBusEngineHandlerInterface() {}
62 // Called when the Chrome input field get the focus.
63 virtual void FocusIn(ibus::TextInputType text_input_type) = 0;
65 // Called when the Chrome input field lose the focus.
66 virtual void FocusOut() = 0;
68 // Called when the IME is enabled.
69 virtual void Enable() = 0;
71 // Called when the IME is disabled.
72 virtual void Disable() = 0;
74 // Called when a property is activated or changed.
75 virtual void PropertyActivate(const std::string& property_name) = 0;
77 // Called when a property is shown.
78 virtual void PropertyShow(const std::string& property_name) = 0;
80 // Called when a property is hidden.
81 virtual void PropertyHide(const std::string& property_name) = 0;
83 // Called when the Chrome input field set their capabilities.
84 virtual void SetCapability(IBusCapability capability) = 0;
86 // Called when the IME is reset.
87 virtual void Reset() = 0;
89 // Called when the key event is received. The |keycode| is raw layout
90 // independent keycode. The |keysym| is result of XLookupString function
91 // which translate |keycode| to keyboard layout dependent symbol value.
92 // Actual implementation must call |callback| after key event handling.
93 // For example: key press event for 'd' key on us layout and dvorak layout.
94 // keyval keycode state
95 // us layout : 0x64 0x20 0x00
96 // dvorak layout : 0x65 0x20 0x00
97 virtual void ProcessKeyEvent(uint32 keysym, uint32 keycode, uint32 state,
98 const KeyEventDoneCallback& callback) = 0;
100 // Called when the candidate in lookup table is clicked. The |index| is 0
101 // based candidate index in lookup table. The |state| is same value as
102 // GdkModifierType in
103 // http://developer.gnome.org/gdk/stable/gdk-Windows.html#GdkModifierType
104 virtual void CandidateClicked(uint32 index, ibus::IBusMouseButton button,
107 // Called when a new surrounding text is set. The |text| is surrounding text
108 // and |cursor_pos| is 0 based index of cursor position in |text|. If there is
109 // selection range, |anchor_pos| represents opposite index from |cursor_pos|.
110 // Otherwise |anchor_pos| is equal to |cursor_pos|.
111 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos,
112 uint32 anchor_pos) = 0;
115 IBusEngineHandlerInterface() {}
118 // A interface to handle the candidate window related method call.
119 class CHROMEOS_EXPORT IBusPanelCandidateWindowHandlerInterface {
121 virtual ~IBusPanelCandidateWindowHandlerInterface() {}
123 // Called when the IME updates the lookup table.
124 virtual void UpdateLookupTable(
125 const input_method::CandidateWindow& candidate_window,
128 // Called when the IME hides the lookup table.
129 virtual void HideLookupTable() = 0;
131 // Called when the IME updates the auxiliary text. The |text| is given in
133 virtual void UpdateAuxiliaryText(const std::string& text, bool visible) = 0;
135 // Called when the IME hides the auxiliary text.
136 virtual void HideAuxiliaryText() = 0;
138 // Called when the IME updates the preedit text. The |text| is given in
140 virtual void UpdatePreeditText(const std::string& text, uint32 cursor_pos,
143 // Called when the IME hides the preedit text.
144 virtual void HidePreeditText() = 0;
146 // Called when the application changes its caret location.
147 virtual void SetCursorLocation(const ibus::Rect& cursor_location,
148 const ibus::Rect& composition_head) = 0;
151 IBusPanelCandidateWindowHandlerInterface() {}
154 // A interface to handle the property related method call.
155 class CHROMEOS_EXPORT IBusPanelPropertyHandlerInterface {
157 virtual ~IBusPanelPropertyHandlerInterface() {}
159 // Called when a new property is registered.
160 virtual void RegisterProperties(
161 const chromeos::input_method::InputMethodPropertyList& properties) = 0;
164 IBusPanelPropertyHandlerInterface() {}
168 // IBusBridge provides access of each IME related handler. This class is used
169 // for IME implementation without ibus-daemon. The legacy ibus IME communicates
170 // their engine with dbus protocol, but new implementation doesn't. Instead of
171 // dbus communcation, new implementation calls target service(e.g. PanelService
172 // or EngineService) directly by using this class.
175 virtual ~IBusBridge();
177 // Allocates the global instance. Must be called before any calls to Get().
178 static CHROMEOS_EXPORT void Initialize();
180 // Releases the global instance.
181 static CHROMEOS_EXPORT void Shutdown();
183 // Returns IBusBridge global instance. Initialize() must be called first.
184 static CHROMEOS_EXPORT IBusBridge* Get();
186 // Returns current InputContextHandler. This function returns NULL if input
187 // context is not ready to use.
188 virtual IBusInputContextHandlerInterface* GetInputContextHandler() const = 0;
190 // Updates current InputContextHandler. If there is no active input context,
191 // pass NULL for |handler|. Caller must release |handler|.
192 virtual void SetInputContextHandler(
193 IBusInputContextHandlerInterface* handler) = 0;
195 // Returns current EngineHandler. This function returns NULL if current engine
196 // is not ready to use.
197 virtual IBusEngineHandlerInterface* GetEngineHandler() const = 0;
199 // Updates current EngineHandler. If there is no active engine service, pass
200 // NULL for |handler|. Caller must release |handler|.
201 virtual void SetEngineHandler(IBusEngineHandlerInterface* handler) = 0;
203 // Returns current CandidateWindowHandler. This function returns NULL if
204 // current candidate window is not ready to use.
205 virtual IBusPanelCandidateWindowHandlerInterface*
206 GetCandidateWindowHandler() const = 0;
208 // Updates current CandidatWindowHandler. If there is no active candidate
209 // window service, pass NULL for |handler|. Caller must release |handler|.
210 virtual void SetCandidateWindowHandler(
211 IBusPanelCandidateWindowHandlerInterface* handler) = 0;
213 // Returns current PropertyHandler. This function returns NULL if panel window
214 // is not ready to use.
215 virtual IBusPanelPropertyHandlerInterface* GetPropertyHandler() const = 0;
217 // Updates current PropertyHandler. If there is no active property service,
218 // pass NULL for |handler|. Caller must release |handler|.
219 virtual void SetPropertyHandler(
220 IBusPanelPropertyHandlerInterface* handler) = 0;
222 // Sets create engine handler for |engine_id|. |engine_id| must not be empty
223 // and |handler| must not be null.
224 virtual void SetCreateEngineHandler(
225 const std::string& engine_id,
226 const IBusEngineFactoryService::CreateEngineHandler& handler) = 0;
228 // Unsets create engine handler for |engine_id|. |engine_id| must not be
230 virtual void UnsetCreateEngineHandler(const std::string& engine_id) = 0;
232 // Creates engine. Do not call this function before SetCreateEngineHandler
233 // call with |engine_id|.
234 virtual void CreateEngine(const std::string& engine_id) = 0;
240 DISALLOW_COPY_AND_ASSIGN(IBusBridge);
243 } // namespace chromeos
245 #endif // CHROMEOS_IME_IBUS_BRIDGE_H_