Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / chrome / browser / chromeos / input_method / input_method_engine_interface.h
blob67a972cab03238b7c81eebea42c946ac9572c77c
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_
8 #include <string>
9 #include <vector>
11 #include "ui/base/ime/chromeos/ime_bridge.h"
13 class GURL;
15 namespace chromeos {
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
23 // API.
24 class InputMethodEngineInterface : public IMEEngineHandlerInterface {
25 public:
26 struct KeyboardEvent {
27 KeyboardEvent();
28 virtual ~KeyboardEvent();
30 std::string type;
31 std::string key;
32 std::string code;
33 std::string extension_id;
34 bool alt_key;
35 bool ctrl_key;
36 bool shift_key;
37 bool caps_lock;
40 enum {
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,
49 enum MenuItemStyle {
50 MENU_ITEM_STYLE_NONE,
51 MENU_ITEM_STYLE_CHECK,
52 MENU_ITEM_STYLE_RADIO,
53 MENU_ITEM_STYLE_SEPARATOR,
56 enum MouseButtonEvent {
57 MOUSE_BUTTON_LEFT,
58 MOUSE_BUTTON_RIGHT,
59 MOUSE_BUTTON_MIDDLE,
62 enum SegmentStyle {
63 SEGMENT_STYLE_UNDERLINE,
64 SEGMENT_STYLE_DOUBLE_UNDERLINE,
67 enum CandidateWindowPosition {
68 WINDOW_POS_CURSOR,
69 WINDOW_POS_COMPOSITTION,
72 struct MenuItem {
73 MenuItem();
74 virtual ~MenuItem();
76 std::string id;
77 std::string label;
78 MenuItemStyle style;
79 bool visible;
80 bool enabled;
81 bool checked;
83 unsigned int modified;
84 std::vector<MenuItem> children;
87 struct InputContext {
88 int id;
89 std::string type;
92 struct UsageEntry {
93 std::string title;
94 std::string body;
97 struct Candidate {
98 Candidate();
99 virtual ~Candidate();
101 std::string value;
102 int id;
103 std::string label;
104 std::string annotation;
105 UsageEntry usage;
106 std::vector<Candidate> candidates;
109 struct CandidateWindowProperty {
110 CandidateWindowProperty();
111 virtual ~CandidateWindowProperty();
112 int page_size;
113 bool is_cursor_visible;
114 bool is_vertical;
115 bool show_window_at_composition;
117 // Auxiliary text is typically displayed in the footer of the candidate
118 // window.
119 std::string auxiliary_text;
120 bool is_auxiliary_text_visible;
123 struct SegmentInfo {
124 int start;
125 int end;
126 SegmentStyle style;
129 class Observer {
130 public:
131 virtual ~Observer();
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,
155 int candidate_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,
165 int cursor_pos,
166 int anchor_pos) = 0;
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,
181 const char* text,
182 int selection_start,
183 int selection_end,
184 int cursor,
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
192 // is not focused.
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
207 // window widget.
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
224 // active.
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,
235 bool handled) = 0;
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
239 // caret.
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,
245 int offset,
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_