Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / input_method / input_method_engine_interface.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "ui/base/ime/chromeos/ime_bridge.h"
12
13 class GURL;
14
15 namespace chromeos {
16
17 namespace input_method {
18 class InputMethodDescriptor;
19 struct KeyEventHandle;
20 }  // namespace input_method
21
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();
29
30     std::string type;
31     std::string key;
32     std::string code;
33     int key_code; // only used by on-screen keyboards.
34     std::string extension_id;
35     bool alt_key;
36     bool ctrl_key;
37     bool shift_key;
38     bool caps_lock;
39   };
40
41   enum {
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,
48   };
49
50   enum MenuItemStyle {
51     MENU_ITEM_STYLE_NONE,
52     MENU_ITEM_STYLE_CHECK,
53     MENU_ITEM_STYLE_RADIO,
54     MENU_ITEM_STYLE_SEPARATOR,
55   };
56
57   enum MouseButtonEvent {
58     MOUSE_BUTTON_LEFT,
59     MOUSE_BUTTON_RIGHT,
60     MOUSE_BUTTON_MIDDLE,
61   };
62
63   enum SegmentStyle {
64     SEGMENT_STYLE_UNDERLINE,
65     SEGMENT_STYLE_DOUBLE_UNDERLINE,
66     SEGMENT_STYLE_NO_UNDERLINE,
67   };
68
69   enum CandidateWindowPosition {
70     WINDOW_POS_CURSOR,
71     WINDOW_POS_COMPOSITTION,
72   };
73
74   struct MenuItem {
75     MenuItem();
76     virtual ~MenuItem();
77
78     std::string id;
79     std::string label;
80     MenuItemStyle style;
81     bool visible;
82     bool enabled;
83     bool checked;
84
85     unsigned int modified;
86     std::vector<MenuItem> children;
87   };
88
89   struct InputContext {
90     int id;
91     std::string type;
92     bool auto_correct;
93     bool auto_complete;
94     bool spell_check;
95   };
96
97   struct UsageEntry {
98     std::string title;
99     std::string body;
100   };
101
102   struct Candidate {
103     Candidate();
104     virtual ~Candidate();
105
106     std::string value;
107     int id;
108     std::string label;
109     std::string annotation;
110     UsageEntry usage;
111     std::vector<Candidate> candidates;
112   };
113
114   struct CandidateWindowProperty {
115     CandidateWindowProperty();
116     virtual ~CandidateWindowProperty();
117     int page_size;
118     bool is_cursor_visible;
119     bool is_vertical;
120     bool show_window_at_composition;
121
122     // Auxiliary text is typically displayed in the footer of the candidate
123     // window.
124     std::string auxiliary_text;
125     bool is_auxiliary_text_visible;
126   };
127
128   struct SegmentInfo {
129     int start;
130     int end;
131     SegmentStyle style;
132   };
133
134   class Observer {
135    public:
136     virtual ~Observer();
137
138     // Called when the IME becomes the active IME.
139     virtual void OnActivate(const std::string& engine_id) = 0;
140
141     // Called when the IME is no longer active.
142     virtual void OnDeactivated(const std::string& engine_id) = 0;
143
144     // Called when a text field gains focus, and will be sending key events.
145     virtual void OnFocus(const InputContext& context) = 0;
146
147     // Called when a text field loses focus, and will no longer generate events.
148     virtual void OnBlur(int context_id) = 0;
149
150     // Called when an InputContext's properties change while it is focused.
151     virtual void OnInputContextUpdate(const InputContext& context) = 0;
152
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;
157
158     // Called when the user clicks on an item in the candidate list.
159     virtual void OnCandidateClicked(const std::string& engine_id,
160                                     int candidate_id,
161                                     MouseButtonEvent button) = 0;
162
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;
166
167     // Called when a surrounding text is changed.
168     virtual void OnSurroundingTextChanged(const std::string& engine_id,
169                                           const std::string& text,
170                                           int cursor_pos,
171                                           int anchor_pos) = 0;
172
173     // Called when composition bounds are changed.
174     virtual void OnCompositionBoundsChanged(const gfx::Rect& bounds) = 0;
175
176     // Called when Chrome terminates on-going text input session.
177     virtual void OnReset(const std::string& engine_id) = 0;
178   };
179
180   virtual ~InputMethodEngineInterface() {}
181
182   // Set the current composition and associated properties.
183   virtual bool SetComposition(int context_id,
184                               const char* text,
185                               int selection_start,
186                               int selection_end,
187                               int cursor,
188                               const std::vector<SegmentInfo>& segments,
189                               std::string* error) = 0;
190
191   // Clear the current composition.
192   virtual bool ClearComposition(int context_id, std::string* error) = 0;
193
194   // Commit the specified text to the specified context.  Fails if the context
195   // is not focused.
196   virtual bool CommitText(int context_id, const char* text,
197                           std::string* error) = 0;
198
199   // Send the sequence of key events.
200   virtual bool SendKeyEvents(int context_id,
201                              const std::vector<KeyboardEvent>& events) = 0;
202
203   // This function returns the current property of the candidate window.
204   // The caller can use the returned value as the default property and
205   // modify some of specified items.
206   virtual const CandidateWindowProperty&
207     GetCandidateWindowProperty() const = 0;
208
209   // Change the property of the candidate window and repaint the candidate
210   // window widget.
211   virtual void SetCandidateWindowProperty(
212       const CandidateWindowProperty& property) = 0;
213
214   // Show or hide the candidate window.
215   virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0;
216
217   // Set the list of entries displayed in the candidate window.
218   virtual bool SetCandidates(int context_id,
219                              const std::vector<Candidate>& candidates,
220                              std::string* error) = 0;
221
222   // Set the position of the cursor in the candidate window.
223   virtual bool SetCursorPosition(int context_id, int candidate_id,
224                                  std::string* error) = 0;
225
226   // Set the list of items that appears in the language menu when this IME is
227   // active.
228   virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0;
229
230   // Update the state of the menu items.
231   virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0;
232
233   // Returns true if this IME is active, false if not.
234   virtual bool IsActive() const = 0;
235
236   // Returns the current active input_component id.
237   virtual const std::string& GetActiveComponentId() const = 0;
238
239   // Deletes |number_of_chars| unicode characters as the basis of |offset| from
240   // the surrounding text. The |offset| is relative position based on current
241   // caret.
242   // NOTE: Currently we are falling back to backspace forwarding workaround,
243   // because delete_surrounding_text is not supported in Chrome. So this
244   // function is restricted for only preceding text.
245   // TODO(nona): Support full spec delete surrounding text.
246   virtual bool DeleteSurroundingText(int context_id,
247                                      int offset,
248                                      size_t number_of_chars,
249                                      std::string* error) = 0;
250
251   // Hides the input view window (from API call).
252   virtual void HideInputView() = 0;
253 };
254
255 }  // namespace chromeos
256
257 #endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_