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 int key_code
; // only used by on-screen keyboards.
34 std::string extension_id
;
42 MENU_ITEM_MODIFIED_LABEL
= 0x0001,
43 MENU_ITEM_MODIFIED_STYLE
= 0x0002,
44 MENU_ITEM_MODIFIED_VISIBLE
= 0x0004,
45 MENU_ITEM_MODIFIED_ENABLED
= 0x0008,
46 MENU_ITEM_MODIFIED_CHECKED
= 0x0010,
47 MENU_ITEM_MODIFIED_ICON
= 0x0020,
52 MENU_ITEM_STYLE_CHECK
,
53 MENU_ITEM_STYLE_RADIO
,
54 MENU_ITEM_STYLE_SEPARATOR
,
57 enum MouseButtonEvent
{
64 SEGMENT_STYLE_UNDERLINE
,
65 SEGMENT_STYLE_DOUBLE_UNDERLINE
,
66 SEGMENT_STYLE_NO_UNDERLINE
,
69 enum CandidateWindowPosition
{
71 WINDOW_POS_COMPOSITTION
,
85 unsigned int modified
;
86 std::vector
<MenuItem
> children
;
104 virtual ~Candidate();
109 std::string annotation
;
111 std::vector
<Candidate
> candidates
;
114 struct CandidateWindowProperty
{
115 CandidateWindowProperty();
116 virtual ~CandidateWindowProperty();
118 bool is_cursor_visible
;
120 bool show_window_at_composition
;
122 // Auxiliary text is typically displayed in the footer of the candidate
124 std::string auxiliary_text
;
125 bool is_auxiliary_text_visible
;
138 // Called when the IME becomes the active IME.
139 virtual void OnActivate(const std::string
& engine_id
) = 0;
141 // Called when the IME is no longer active.
142 virtual void OnDeactivated(const std::string
& engine_id
) = 0;
144 // Called when a text field gains focus, and will be sending key events.
145 virtual void OnFocus(const InputContext
& context
) = 0;
147 // Called when a text field loses focus, and will no longer generate events.
148 virtual void OnBlur(int context_id
) = 0;
150 // Called when an InputContext's properties change while it is focused.
151 virtual void OnInputContextUpdate(const InputContext
& context
) = 0;
153 // Called when the user pressed a key with a text field focused.
154 virtual void OnKeyEvent(const std::string
& engine_id
,
155 const KeyboardEvent
& event
,
156 input_method::KeyEventHandle
* key_data
) = 0;
158 // Called when the user clicks on an item in the candidate list.
159 virtual void OnCandidateClicked(const std::string
& engine_id
,
161 MouseButtonEvent button
) = 0;
163 // Called when a menu item for this IME is interacted with.
164 virtual void OnMenuItemActivated(const std::string
& engine_id
,
165 const std::string
& menu_id
) = 0;
167 // Called when a surrounding text is changed.
168 virtual void OnSurroundingTextChanged(const std::string
& engine_id
,
169 const std::string
& text
,
173 // Called when composition bounds are changed.
174 virtual void OnCompositionBoundsChanged(
175 const std::vector
<gfx::Rect
>& bounds
) = 0;
177 // Called when Chrome terminates on-going text input session.
178 virtual void OnReset(const std::string
& engine_id
) = 0;
181 ~InputMethodEngineInterface() override
{}
183 // Set the current composition and associated properties.
184 virtual bool SetComposition(int context_id
,
189 const std::vector
<SegmentInfo
>& segments
,
190 std::string
* error
) = 0;
192 // Clear the current composition.
193 virtual bool ClearComposition(int context_id
, std::string
* error
) = 0;
195 // Commit the specified text to the specified context. Fails if the context
197 virtual bool CommitText(int context_id
, const char* text
,
198 std::string
* error
) = 0;
200 // Send the sequence of key events.
201 virtual bool SendKeyEvents(int context_id
,
202 const std::vector
<KeyboardEvent
>& events
) = 0;
204 // This function returns the current property of the candidate window.
205 // The caller can use the returned value as the default property and
206 // modify some of specified items.
207 virtual const CandidateWindowProperty
&
208 GetCandidateWindowProperty() const = 0;
210 // Change the property of the candidate window and repaint the candidate
212 virtual void SetCandidateWindowProperty(
213 const CandidateWindowProperty
& property
) = 0;
215 // Show or hide the candidate window.
216 virtual bool SetCandidateWindowVisible(bool visible
, std::string
* error
) = 0;
218 // Set the list of entries displayed in the candidate window.
219 virtual bool SetCandidates(int context_id
,
220 const std::vector
<Candidate
>& candidates
,
221 std::string
* error
) = 0;
223 // Set the position of the cursor in the candidate window.
224 virtual bool SetCursorPosition(int context_id
, int candidate_id
,
225 std::string
* error
) = 0;
227 // Set the list of items that appears in the language menu when this IME is
229 virtual bool SetMenuItems(const std::vector
<MenuItem
>& items
) = 0;
231 // Update the state of the menu items.
232 virtual bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) = 0;
234 // Returns true if this IME is active, false if not.
235 virtual bool IsActive() const = 0;
237 // Returns the current active input_component id.
238 virtual const std::string
& GetActiveComponentId() const = 0;
240 // Deletes |number_of_chars| unicode characters as the basis of |offset| from
241 // the surrounding text. The |offset| is relative position based on current
243 // NOTE: Currently we are falling back to backspace forwarding workaround,
244 // because delete_surrounding_text is not supported in Chrome. So this
245 // function is restricted for only preceding text.
246 // TODO(nona): Support full spec delete surrounding text.
247 virtual bool DeleteSurroundingText(int context_id
,
249 size_t number_of_chars
,
250 std::string
* error
) = 0;
252 // Hides the input view window (from API call).
253 virtual void HideInputView() = 0;
256 } // namespace chromeos
258 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_