Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / input_method / input_method_engine_interface.h
blob5de7c2d423790909ae34d1dbedc257639e8cbcaa
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/ibus_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 IBusEngineHandlerInterface {
25 public:
26 struct KeyboardEvent {
27 KeyboardEvent();
28 virtual ~KeyboardEvent();
30 std::string type;
31 std::string key;
32 std::string code;
33 bool alt_key;
34 bool ctrl_key;
35 bool shift_key;
36 bool caps_lock;
39 enum {
40 MENU_ITEM_MODIFIED_LABEL = 0x0001,
41 MENU_ITEM_MODIFIED_STYLE = 0x0002,
42 MENU_ITEM_MODIFIED_VISIBLE = 0x0004,
43 MENU_ITEM_MODIFIED_ENABLED = 0x0008,
44 MENU_ITEM_MODIFIED_CHECKED = 0x0010,
45 MENU_ITEM_MODIFIED_ICON = 0x0020,
48 enum MenuItemStyle {
49 MENU_ITEM_STYLE_NONE,
50 MENU_ITEM_STYLE_CHECK,
51 MENU_ITEM_STYLE_RADIO,
52 MENU_ITEM_STYLE_SEPARATOR,
55 enum MouseButtonEvent {
56 MOUSE_BUTTON_LEFT,
57 MOUSE_BUTTON_RIGHT,
58 MOUSE_BUTTON_MIDDLE,
61 enum SegmentStyle {
62 SEGMENT_STYLE_UNDERLINE,
63 SEGMENT_STYLE_DOUBLE_UNDERLINE,
66 enum CandidateWindowPosition {
67 WINDOW_POS_CURSOR,
68 WINDOW_POS_COMPOSITTION,
71 struct MenuItem {
72 MenuItem();
73 virtual ~MenuItem();
75 std::string id;
76 std::string label;
77 MenuItemStyle style;
78 bool visible;
79 bool enabled;
80 bool checked;
82 unsigned int modified;
83 std::vector<MenuItem> children;
86 struct InputContext {
87 int id;
88 std::string type;
91 struct UsageEntry {
92 std::string title;
93 std::string body;
96 struct Candidate {
97 Candidate();
98 virtual ~Candidate();
100 std::string value;
101 int id;
102 std::string label;
103 std::string annotation;
104 UsageEntry usage;
105 std::vector<Candidate> candidates;
108 struct CandidateWindowProperty {
109 CandidateWindowProperty();
110 virtual ~CandidateWindowProperty();
111 int page_size;
112 bool is_cursor_visible;
113 bool is_vertical;
114 bool show_window_at_composition;
116 // Auxiliary text is typically displayed in the footer of the candidate
117 // window.
118 std::string auxiliary_text;
119 bool is_auxiliary_text_visible;
122 struct SegmentInfo {
123 int start;
124 int end;
125 SegmentStyle style;
128 class Observer {
129 public:
130 virtual ~Observer();
132 // Called when the IME becomes the active IME.
133 virtual void OnActivate(const std::string& engine_id) = 0;
135 // Called when the IME is no longer active.
136 virtual void OnDeactivated(const std::string& engine_id) = 0;
138 // Called when a text field gains focus, and will be sending key events.
139 virtual void OnFocus(const InputContext& context) = 0;
141 // Called when a text field loses focus, and will no longer generate events.
142 virtual void OnBlur(int context_id) = 0;
144 // Called when an InputContext's properties change while it is focused.
145 virtual void OnInputContextUpdate(const InputContext& context) = 0;
147 // Called when the user pressed a key with a text field focused.
148 virtual void OnKeyEvent(const std::string& engine_id,
149 const KeyboardEvent& event,
150 input_method::KeyEventHandle* key_data) = 0;
152 // Called when the user clicks on an item in the candidate list.
153 virtual void OnCandidateClicked(const std::string& engine_id,
154 int candidate_id,
155 MouseButtonEvent button) = 0;
157 // Called when a menu item for this IME is interacted with.
158 virtual void OnMenuItemActivated(const std::string& engine_id,
159 const std::string& menu_id) = 0;
161 // Called when a surrounding text is changed.
162 virtual void OnSurroundingTextChanged(const std::string& engine_id,
163 const std::string& text,
164 int cursor_pos,
165 int anchor_pos) = 0;
167 // Called when Chrome terminates on-going text input session.
168 virtual void OnReset(const std::string& engine_id) = 0;
171 virtual ~InputMethodEngineInterface() {}
173 virtual const input_method::InputMethodDescriptor& GetDescriptor() const = 0;
175 // Called when the input metho initialization is done.
176 // This function is called from private API.
177 // TODO(nona): Remove this function.
178 virtual void StartIme() = 0;
180 // Set the current composition and associated properties.
181 virtual bool SetComposition(int context_id,
182 const char* text,
183 int selection_start,
184 int selection_end,
185 int cursor,
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
193 // is not focused.
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
208 // window widget.
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
225 // active.
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 // Inform the engine that a key event has been processed.
235 virtual void KeyEventDone(input_method::KeyEventHandle* key_data,
236 bool handled) = 0;
238 // Deletes |number_of_chars| unicode characters as the basis of |offset| from
239 // the surrounding text. The |offset| is relative position based on current
240 // caret.
241 // NOTE: Currently we are falling back to backspace forwarding workaround,
242 // because delete_surrounding_text is not supported in Chrome. So this
243 // function is restricted for only preceding text.
244 // TODO(nona): Support full spec delete surrounding text.
245 virtual bool DeleteSurroundingText(int context_id,
246 int offset,
247 size_t number_of_chars,
248 std::string* error) = 0;
250 // Hides the input view window (from API call).
251 virtual void HideInputView() = 0;
254 } // namespace chromeos
256 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_