1 // Copyright 2013 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 CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_
11 #include "ui/base/ime/chromeos/ime_bridge.h"
17 namespace input_method
{
18 class InputMethodDescriptor
;
19 struct KeyEventHandle
;
20 } // namespace input_method
22 // InputMethodEngine is used to translate from the Chrome IME API to the native
24 class InputMethodEngineInterface
: public IMEEngineHandlerInterface
{
26 struct KeyboardEvent
{
28 virtual ~KeyboardEvent();
33 std::string extension_id
;
41 MENU_ITEM_MODIFIED_LABEL
= 0x0001,
42 MENU_ITEM_MODIFIED_STYLE
= 0x0002,
43 MENU_ITEM_MODIFIED_VISIBLE
= 0x0004,
44 MENU_ITEM_MODIFIED_ENABLED
= 0x0008,
45 MENU_ITEM_MODIFIED_CHECKED
= 0x0010,
46 MENU_ITEM_MODIFIED_ICON
= 0x0020,
51 MENU_ITEM_STYLE_CHECK
,
52 MENU_ITEM_STYLE_RADIO
,
53 MENU_ITEM_STYLE_SEPARATOR
,
56 enum MouseButtonEvent
{
63 SEGMENT_STYLE_UNDERLINE
,
64 SEGMENT_STYLE_DOUBLE_UNDERLINE
,
67 enum CandidateWindowPosition
{
69 WINDOW_POS_COMPOSITTION
,
83 unsigned int modified
;
84 std::vector
<MenuItem
> children
;
104 std::string annotation
;
106 std::vector
<Candidate
> candidates
;
109 struct CandidateWindowProperty
{
110 CandidateWindowProperty();
111 virtual ~CandidateWindowProperty();
113 bool is_cursor_visible
;
115 bool show_window_at_composition
;
117 // Auxiliary text is typically displayed in the footer of the candidate
119 std::string auxiliary_text
;
120 bool is_auxiliary_text_visible
;
133 // Called when the IME becomes the active IME.
134 virtual void OnActivate(const std::string
& engine_id
) = 0;
136 // Called when the IME is no longer active.
137 virtual void OnDeactivated(const std::string
& engine_id
) = 0;
139 // Called when a text field gains focus, and will be sending key events.
140 virtual void OnFocus(const InputContext
& context
) = 0;
142 // Called when a text field loses focus, and will no longer generate events.
143 virtual void OnBlur(int context_id
) = 0;
145 // Called when an InputContext's properties change while it is focused.
146 virtual void OnInputContextUpdate(const InputContext
& context
) = 0;
148 // Called when the user pressed a key with a text field focused.
149 virtual void OnKeyEvent(const std::string
& engine_id
,
150 const KeyboardEvent
& event
,
151 input_method::KeyEventHandle
* key_data
) = 0;
153 // Called when the user clicks on an item in the candidate list.
154 virtual void OnCandidateClicked(const std::string
& engine_id
,
156 MouseButtonEvent button
) = 0;
158 // Called when a menu item for this IME is interacted with.
159 virtual void OnMenuItemActivated(const std::string
& engine_id
,
160 const std::string
& menu_id
) = 0;
162 // Called when a surrounding text is changed.
163 virtual void OnSurroundingTextChanged(const std::string
& engine_id
,
164 const std::string
& text
,
168 // Called when Chrome terminates on-going text input session.
169 virtual void OnReset(const std::string
& engine_id
) = 0;
172 virtual ~InputMethodEngineInterface() {}
174 virtual const input_method::InputMethodDescriptor
& GetDescriptor() const = 0;
176 // Called when the input metho initialization is done.
177 virtual void NotifyImeReady() = 0;
179 // Set the current composition and associated properties.
180 virtual bool SetComposition(int context_id
,
185 const std::vector
<SegmentInfo
>& segments
,
186 std::string
* error
) = 0;
188 // Clear the current composition.
189 virtual bool ClearComposition(int context_id
, std::string
* error
) = 0;
191 // Commit the specified text to the specified context. Fails if the context
193 virtual bool CommitText(int context_id
, const char* text
,
194 std::string
* error
) = 0;
196 // Send the sequence of key events.
197 virtual bool SendKeyEvents(int context_id
,
198 const std::vector
<KeyboardEvent
>& events
) = 0;
200 // This function returns the current property of the candidate window.
201 // The caller can use the returned value as the default property and
202 // modify some of specified items.
203 virtual const CandidateWindowProperty
&
204 GetCandidateWindowProperty() const = 0;
206 // Change the property of the candidate window and repaint the candidate
208 virtual void SetCandidateWindowProperty(
209 const CandidateWindowProperty
& property
) = 0;
211 // Show or hide the candidate window.
212 virtual bool SetCandidateWindowVisible(bool visible
, std::string
* error
) = 0;
214 // Set the list of entries displayed in the candidate window.
215 virtual bool SetCandidates(int context_id
,
216 const std::vector
<Candidate
>& candidates
,
217 std::string
* error
) = 0;
219 // Set the position of the cursor in the candidate window.
220 virtual bool SetCursorPosition(int context_id
, int candidate_id
,
221 std::string
* error
) = 0;
223 // Set the list of items that appears in the language menu when this IME is
225 virtual bool SetMenuItems(const std::vector
<MenuItem
>& items
) = 0;
227 // Update the state of the menu items.
228 virtual bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) = 0;
230 // Returns true if this IME is active, false if not.
231 virtual bool IsActive() const = 0;
233 // Inform the engine that a key event has been processed.
234 virtual void KeyEventDone(input_method::KeyEventHandle
* key_data
,
237 // Deletes |number_of_chars| unicode characters as the basis of |offset| from
238 // the surrounding text. The |offset| is relative position based on current
240 // NOTE: Currently we are falling back to backspace forwarding workaround,
241 // because delete_surrounding_text is not supported in Chrome. So this
242 // function is restricted for only preceding text.
243 // TODO(nona): Support full spec delete surrounding text.
244 virtual bool DeleteSurroundingText(int context_id
,
246 size_t number_of_chars
,
247 std::string
* error
) = 0;
249 // Hides the input view window (from API call).
250 virtual void HideInputView() = 0;
253 } // namespace chromeos
255 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_