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,
68 enum CandidateWindowPosition {
70 WINDOW_POS_COMPOSITTION,
84 unsigned int modified;
85 std::vector<MenuItem> children;
100 virtual ~Candidate();
105 std::string annotation;
107 std::vector<Candidate> candidates;
110 struct CandidateWindowProperty {
111 CandidateWindowProperty();
112 virtual ~CandidateWindowProperty();
114 bool is_cursor_visible;
116 bool show_window_at_composition;
118 // Auxiliary text is typically displayed in the footer of the candidate
120 std::string auxiliary_text;
121 bool is_auxiliary_text_visible;
134 // Called when the IME becomes the active IME.
135 virtual void OnActivate(const std::string& engine_id) = 0;
137 // Called when the IME is no longer active.
138 virtual void OnDeactivated(const std::string& engine_id) = 0;
140 // Called when a text field gains focus, and will be sending key events.
141 virtual void OnFocus(const InputContext& context) = 0;
143 // Called when a text field loses focus, and will no longer generate events.
144 virtual void OnBlur(int context_id) = 0;
146 // Called when an InputContext's properties change while it is focused.
147 virtual void OnInputContextUpdate(const InputContext& context) = 0;
149 // Called when the user pressed a key with a text field focused.
150 virtual void OnKeyEvent(const std::string& engine_id,
151 const KeyboardEvent& event,
152 input_method::KeyEventHandle* key_data) = 0;
154 // Called when the user clicks on an item in the candidate list.
155 virtual void OnCandidateClicked(const std::string& engine_id,
157 MouseButtonEvent button) = 0;
159 // Called when a menu item for this IME is interacted with.
160 virtual void OnMenuItemActivated(const std::string& engine_id,
161 const std::string& menu_id) = 0;
163 // Called when a surrounding text is changed.
164 virtual void OnSurroundingTextChanged(const std::string& engine_id,
165 const std::string& text,
169 // Called when Chrome terminates on-going text input session.
170 virtual void OnReset(const std::string& engine_id) = 0;
173 virtual ~InputMethodEngineInterface() {}
175 virtual const input_method::InputMethodDescriptor& GetDescriptor() const = 0;
177 // Called when the input metho initialization is done.
178 virtual void NotifyImeReady() = 0;
180 // Set the current composition and associated properties.
181 virtual bool SetComposition(int context_id,
186 const std::vector<SegmentInfo>& segments,
187 std::string* error) = 0;
189 // Clear the current composition.
190 virtual bool ClearComposition(int context_id, std::string* error) = 0;
192 // Commit the specified text to the specified context. Fails if the context
194 virtual bool CommitText(int context_id, const char* text,
195 std::string* error) = 0;
197 // Send the sequence of key events.
198 virtual bool SendKeyEvents(int context_id,
199 const std::vector<KeyboardEvent>& events) = 0;
201 // This function returns the current property of the candidate window.
202 // The caller can use the returned value as the default property and
203 // modify some of specified items.
204 virtual const CandidateWindowProperty&
205 GetCandidateWindowProperty() const = 0;
207 // Change the property of the candidate window and repaint the candidate
209 virtual void SetCandidateWindowProperty(
210 const CandidateWindowProperty& property) = 0;
212 // Show or hide the candidate window.
213 virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0;
215 // Set the list of entries displayed in the candidate window.
216 virtual bool SetCandidates(int context_id,
217 const std::vector<Candidate>& candidates,
218 std::string* error) = 0;
220 // Set the position of the cursor in the candidate window.
221 virtual bool SetCursorPosition(int context_id, int candidate_id,
222 std::string* error) = 0;
224 // Set the list of items that appears in the language menu when this IME is
226 virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0;
228 // Update the state of the menu items.
229 virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0;
231 // Returns true if this IME is active, false if not.
232 virtual bool IsActive() const = 0;
234 // Deletes |number_of_chars| unicode characters as the basis of |offset| from
235 // the surrounding text. The |offset| is relative position based on current
237 // NOTE: Currently we are falling back to backspace forwarding workaround,
238 // because delete_surrounding_text is not supported in Chrome. So this
239 // function is restricted for only preceding text.
240 // TODO(nona): Support full spec delete surrounding text.
241 virtual bool DeleteSurroundingText(int context_id,
243 size_t number_of_chars,
244 std::string* error) = 0;
246 // Hides the input view window (from API call).
247 virtual void HideInputView() = 0;
250 } // namespace chromeos
252 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_