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 }; 67 68 enum CandidateWindowPosition { 69 WINDOW_POS_CURSOR, 70 WINDOW_POS_COMPOSITTION, 71 }; 72 73 struct MenuItem { 74 MenuItem(); 75 virtual ~MenuItem(); 76 77 std::string id; 78 std::string label; 79 MenuItemStyle style; 80 bool visible; 81 bool enabled; 82 bool checked; 83 84 unsigned int modified; 85 std::vector<MenuItem> children; 86 }; 87 88 struct InputContext { 89 int id; 90 std::string type; 91 }; 92 93 struct UsageEntry { 94 std::string title; 95 std::string body; 96 }; 97 98 struct Candidate { 99 Candidate(); 100 virtual ~Candidate(); 101 102 std::string value; 103 int id; 104 std::string label; 105 std::string annotation; 106 UsageEntry usage; 107 std::vector<Candidate> candidates; 108 }; 109 110 struct CandidateWindowProperty { 111 CandidateWindowProperty(); 112 virtual ~CandidateWindowProperty(); 113 int page_size; 114 bool is_cursor_visible; 115 bool is_vertical; 116 bool show_window_at_composition; 117 118 // Auxiliary text is typically displayed in the footer of the candidate 119 // window. 120 std::string auxiliary_text; 121 bool is_auxiliary_text_visible; 122 }; 123 124 struct SegmentInfo { 125 int start; 126 int end; 127 SegmentStyle style; 128 }; 129 130 class Observer { 131 public: 132 virtual ~Observer(); 133 134 // Called when the IME becomes the active IME. 135 virtual void OnActivate(const std::string& engine_id) = 0; 136 137 // Called when the IME is no longer active. 138 virtual void OnDeactivated(const std::string& engine_id) = 0; 139 140 // Called when a text field gains focus, and will be sending key events. 141 virtual void OnFocus(const InputContext& context) = 0; 142 143 // Called when a text field loses focus, and will no longer generate events. 144 virtual void OnBlur(int context_id) = 0; 145 146 // Called when an InputContext's properties change while it is focused. 147 virtual void OnInputContextUpdate(const InputContext& context) = 0; 148 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; 153 154 // Called when the user clicks on an item in the candidate list. 155 virtual void OnCandidateClicked(const std::string& engine_id, 156 int candidate_id, 157 MouseButtonEvent button) = 0; 158 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; 162 163 // Called when a surrounding text is changed. 164 virtual void OnSurroundingTextChanged(const std::string& engine_id, 165 const std::string& text, 166 int cursor_pos, 167 int anchor_pos) = 0; 168 169 // Called when Chrome terminates on-going text input session. 170 virtual void OnReset(const std::string& engine_id) = 0; 171 }; 172 173 virtual ~InputMethodEngineInterface() {} 174 175 // Set the current composition and associated properties. 176 virtual bool SetComposition(int context_id, 177 const char* text, 178 int selection_start, 179 int selection_end, 180 int cursor, 181 const std::vector<SegmentInfo>& segments, 182 std::string* error) = 0; 183 184 // Clear the current composition. 185 virtual bool ClearComposition(int context_id, std::string* error) = 0; 186 187 // Commit the specified text to the specified context. Fails if the context 188 // is not focused. 189 virtual bool CommitText(int context_id, const char* text, 190 std::string* error) = 0; 191 192 // Send the sequence of key events. 193 virtual bool SendKeyEvents(int context_id, 194 const std::vector<KeyboardEvent>& events) = 0; 195 196 // This function returns the current property of the candidate window. 197 // The caller can use the returned value as the default property and 198 // modify some of specified items. 199 virtual const CandidateWindowProperty& 200 GetCandidateWindowProperty() const = 0; 201 202 // Change the property of the candidate window and repaint the candidate 203 // window widget. 204 virtual void SetCandidateWindowProperty( 205 const CandidateWindowProperty& property) = 0; 206 207 // Show or hide the candidate window. 208 virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0; 209 210 // Set the list of entries displayed in the candidate window. 211 virtual bool SetCandidates(int context_id, 212 const std::vector<Candidate>& candidates, 213 std::string* error) = 0; 214 215 // Set the position of the cursor in the candidate window. 216 virtual bool SetCursorPosition(int context_id, int candidate_id, 217 std::string* error) = 0; 218 219 // Set the list of items that appears in the language menu when this IME is 220 // active. 221 virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0; 222 223 // Update the state of the menu items. 224 virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0; 225 226 // Returns true if this IME is active, false if not. 227 virtual bool IsActive() const = 0; 228 229 // Returns the current active input_component id. 230 virtual const std::string& GetActiveComponentId() const = 0; 231 232 // Deletes |number_of_chars| unicode characters as the basis of |offset| from 233 // the surrounding text. The |offset| is relative position based on current 234 // caret. 235 // NOTE: Currently we are falling back to backspace forwarding workaround, 236 // because delete_surrounding_text is not supported in Chrome. So this 237 // function is restricted for only preceding text. 238 // TODO(nona): Support full spec delete surrounding text. 239 virtual bool DeleteSurroundingText(int context_id, 240 int offset, 241 size_t number_of_chars, 242 std::string* error) = 0; 243 244 // Hides the input view window (from API call). 245 virtual void HideInputView() = 0; 246 }; 247 248 } // namespace chromeos 249 250 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_ 251