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.
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_
15 namespace input_method {
16 struct KeyEventHandle;
17 } // namespace input_method
19 // InputMethodEngine is used to translate from the Chrome IME API to the native
21 class InputMethodEngine {
23 struct KeyboardEvent {
25 virtual ~KeyboardEvent();
37 MENU_ITEM_MODIFIED_LABEL = 0x0001,
38 MENU_ITEM_MODIFIED_STYLE = 0x0002,
39 MENU_ITEM_MODIFIED_VISIBLE = 0x0004,
40 MENU_ITEM_MODIFIED_ENABLED = 0x0008,
41 MENU_ITEM_MODIFIED_CHECKED = 0x0010,
42 MENU_ITEM_MODIFIED_ICON = 0x0020,
47 MENU_ITEM_STYLE_CHECK,
48 MENU_ITEM_STYLE_RADIO,
49 MENU_ITEM_STYLE_SEPARATOR,
52 enum MouseButtonEvent {
59 SEGMENT_STYLE_UNDERLINE,
60 SEGMENT_STYLE_DOUBLE_UNDERLINE,
63 enum CandidateWindowPosition {
65 WINDOW_POS_COMPOSITTION,
79 unsigned int modified;
80 std::vector<MenuItem> children;
100 std::string annotation;
102 std::vector<Candidate> candidates;
105 struct CandidateWindowProperty {
106 CandidateWindowProperty();
107 virtual ~CandidateWindowProperty();
109 bool is_cursor_visible;
111 bool show_window_at_composition;
124 // Called when the IME becomes the active IME.
125 virtual void OnActivate(const std::string& engine_id) = 0;
127 // Called when the IME is no longer active.
128 virtual void OnDeactivated(const std::string& engine_id) = 0;
130 // Called when a text field gains focus, and will be sending key events.
131 virtual void OnFocus(const InputContext& context) = 0;
133 // Called when a text field loses focus, and will no longer generate events.
134 virtual void OnBlur(int context_id) = 0;
136 // Called when an InputContext's properties change while it is focused.
137 virtual void OnInputContextUpdate(const InputContext& context) = 0;
139 // Called when the user pressed a key with a text field focused.
140 virtual void OnKeyEvent(const std::string& engine_id,
141 const KeyboardEvent& event,
142 input_method::KeyEventHandle* key_data) = 0;
144 // Called when the user clicks on an item in the candidate list.
145 virtual void OnCandidateClicked(const std::string& engine_id,
147 MouseButtonEvent button) = 0;
149 // Called when a menu item for this IME is interacted with.
150 virtual void OnMenuItemActivated(const std::string& engine_id,
151 const std::string& menu_id) = 0;
153 // Called when a surrounding text is changed.
154 virtual void OnSurroundingTextChanged(const std::string& engine_id,
155 const std::string& text,
159 // Called when Chrome terminates on-going text input session.
160 virtual void OnReset(const std::string& engine_id) = 0;
163 virtual ~InputMethodEngine() {}
165 // Called when the input metho initialization is done.
166 // This function is called from private API.
167 // TODO(nona): Remove this function.
168 virtual void StartIme() = 0;
170 // Set the current composition and associated properties.
171 virtual bool SetComposition(int context_id,
176 const std::vector<SegmentInfo>& segments,
177 std::string* error) = 0;
179 // Clear the current composition.
180 virtual bool ClearComposition(int context_id, std::string* error) = 0;
182 // Commit the specified text to the specified context. Fails if the context
184 virtual bool CommitText(int context_id, const char* text,
185 std::string* error) = 0;
187 // This function returns the current property of the candidate window.
188 // The caller can use the returned value as the default property and
189 // modify some of specified items.
190 virtual const CandidateWindowProperty&
191 GetCandidateWindowProperty() const = 0;
193 // Change the property of the candidate window and repaint the candidate
195 virtual void SetCandidateWindowProperty(
196 const CandidateWindowProperty& property) = 0;
198 // Show or hide the candidate window.
199 virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0;
201 // Set the text that appears as a label in the candidate window.
202 virtual void SetCandidateWindowAuxText(const char* text) = 0;
204 // Show or hide the extra text in the candidate window.
205 virtual void SetCandidateWindowAuxTextVisible(bool visible) = 0;
207 // Set the list of entries displayed in the candidate window.
208 virtual bool SetCandidates(int context_id,
209 const std::vector<Candidate>& candidates,
210 std::string* error) = 0;
212 // Set the position of the cursor in the candidate window.
213 virtual bool SetCursorPosition(int context_id, int candidate_id,
214 std::string* error) = 0;
216 // Set the list of items that appears in the language menu when this IME is
218 virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0;
220 // Update the state of the menu items.
221 virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0;
223 // Returns true if this IME is active, false if not.
224 virtual bool IsActive() const = 0;
226 // Inform the engine that a key event has been processed.
227 virtual void KeyEventDone(input_method::KeyEventHandle* key_data,
230 // Deletes |number_of_chars| unicode characters as the basis of |offset| from
231 // the surrounding text. The |offset| is relative position based on current
233 // NOTE: Currently we are falling back to backspace forwarding workaround,
234 // because delete_surrounding_text is not supported in Chrome. So this
235 // function is restricted for only preceding text.
236 // TODO(nona): Support full spec delete surrounding text.
237 virtual bool DeleteSurroundingText(int context_id,
239 size_t number_of_chars,
240 std::string* error) = 0;
242 // Create an IME engine.
243 static InputMethodEngine* CreateEngine(
244 InputMethodEngine::Observer* observer,
245 const char* engine_name,
246 const char* extension_id,
247 const char* engine_id,
248 const char* description,
249 const std::vector<std::string>& language,
250 const std::vector<std::string>& layouts,
251 const GURL& options_page,
255 } // namespace chromeos
257 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_