Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/input_method/input_method_engine_base.h

Issue 1528483002: Add chrome.input.ime.activate and chrome.input.ime.deactivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_
6 #define CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11 #include "base/time/time.h"
12 #include "ui/base/ime/chromeos/input_method_descriptor.h"
13 #include "ui/base/ime/ime_engine_handler_interface.h"
14 #include "url/gurl.h"
15
16 class Profile;
17
18 namespace ui {
19 struct CompositionText;
20 class IMEEngineHandlerInterface;
21 class KeyEvent;
22 } // namespace ui
23
24 namespace input_method {
25
26 class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface {
27 public:
28 struct KeyboardEvent {
29 KeyboardEvent();
30 virtual ~KeyboardEvent();
31
32 std::string type;
33 std::string key;
34 std::string code;
35 int key_code; // only used by on-screen keyboards.
36 std::string extension_id;
37 bool alt_key;
38 bool ctrl_key;
39 bool shift_key;
40 bool caps_lock;
41 };
42
43 enum SegmentStyle {
44 SEGMENT_STYLE_UNDERLINE,
45 SEGMENT_STYLE_DOUBLE_UNDERLINE,
46 SEGMENT_STYLE_NO_UNDERLINE,
47 };
48
49 struct SegmentInfo {
50 int start;
51 int end;
52 SegmentStyle style;
53 };
54
55 #if defined(OS_CHROMEOS)
56 enum MouseButtonEvent {
57 MOUSE_BUTTON_LEFT,
58 MOUSE_BUTTON_RIGHT,
59 MOUSE_BUTTON_MIDDLE,
60 };
61 #endif
62
63 class Observer {
64 public:
65 virtual ~Observer() {}
66
67 // Called when the IME becomes the active IME.
68 virtual void OnActivate(const std::string& engine_id) = 0;
69
70 // Called when a text field gains focus, and will be sending key events.
71 virtual void OnFocus(
72 const IMEEngineHandlerInterface::InputContext& context) = 0;
73
74 // Called when a text field loses focus, and will no longer generate events.
75 virtual void OnBlur(int context_id) = 0;
76
77 // Called when the user pressed a key with a text field focused.
78 virtual void OnKeyEvent(
79 const std::string& engine_id,
80 const InputMethodEngineBase::KeyboardEvent& event,
81 ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) = 0;
82
83 // Called when Chrome terminates on-going text input session.
84 virtual void OnReset(const std::string& engine_id) = 0;
85
86 // Called when the IME is no longer active.
87 virtual void OnDeactivated(const std::string& engine_id) = 0;
88
89 // Called when composition bounds are changed.
90 virtual void OnCompositionBoundsChanged(
91 const std::vector<gfx::Rect>& bounds) = 0;
92
93 // Returns whether the observer is interested in key events.
94 virtual bool IsInterestedInKeyEvent() const = 0;
95
96 // Called when a surrounding text is changed.
97 virtual void OnSurroundingTextChanged(const std::string& engine_id,
98 const std::string& text,
99 int cursor_pos,
100 int anchor_pos,
101 int offset_pos) = 0;
102
103 #if defined(OS_CHROMEOS)
104
105 // Called when an InputContext's properties change while it is focused.
106 virtual void OnInputContextUpdate(
107 const IMEEngineHandlerInterface::InputContext& context) = 0;
108
109 // Called when the user clicks on an item in the candidate list.
110 virtual void OnCandidateClicked(
111 const std::string& component_id,
112 int candidate_id,
113 InputMethodEngineBase::MouseButtonEvent button) = 0;
114
115 // Called when a menu item for this IME is interacted with.
116 virtual void OnMenuItemActivated(const std::string& component_id,
117 const std::string& menu_id) = 0;
118 #endif // defined(OS_CHROMEOS)
119 };
120
121 InputMethodEngineBase();
122
123 ~InputMethodEngineBase() override;
124
125 void Initialize(scoped_ptr<InputMethodEngineBase::Observer> observer,
126 const char* extension_id,
127 Profile* profile);
128
129 // IMEEngineHandlerInterface overrides.
130 void FocusIn(const ui::IMEEngineHandlerInterface::InputContext& input_context)
131 override;
132 void FocusOut() override;
133 void Enable(const std::string& component_id) override;
134 void Disable() override;
135 void Reset() override;
136 void ProcessKeyEvent(const ui::KeyEvent& key_event,
137 KeyEventDoneCallback& callback) override;
138 void SetSurroundingText(const std::string& text,
139 uint32_t cursor_pos,
140 uint32_t anchor_pos,
141 uint32_t offset_pos) override;
142 void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
143 bool ClearComposition(int context_id, std::string* error) override;
144 bool CommitText(int context_id,
145 const char* text,
146 std::string* error) override;
147 const std::string& GetActiveComponentId() const override;
148 bool DeleteSurroundingText(int context_id,
149 int offset,
150 size_t number_of_chars,
151 std::string* error) override;
152 int GetCotextIdForTesting() { return context_id_; }
153 bool IsInterestedInKeyEvent() const override;
154
155 // Send the sequence of key events.
156 virtual bool SendKeyEvents(int context_id,
157 const std::vector<KeyboardEvent>& events) = 0;
158
159 // Set the current composition and associated properties.
160 bool SetComposition(int context_id,
161 const char* text,
162 int selection_start,
163 int selection_end,
164 int cursor,
165 const std::vector<SegmentInfo>& segments,
166 std::string* error);
167
168 protected:
169 ui::TextInputType current_input_type_;
170
171 // ID that is used for the current input context. False if there is no focus.
172 int context_id_;
173
174 // Next id that will be assigned to a context.
175 int next_context_id_;
176
177 // The input_component ID in IME extension's manifest.
178 std::string active_component_id_;
179
180 // The IME extension ID.
181 std::string extension_id_;
182
183 // The observer object recieving events for this IME.
184 scoped_ptr<InputMethodEngineBase::Observer> observer_;
185
186 // The current preedit text, and it's cursor position.
187 scoped_ptr<ui::CompositionText> composition_text_;
188 int composition_cursor_;
189
190 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event
191 // sent to ProcessKeyEvent is sent by SendKeyEvents.
192 const ui::KeyEvent* sent_key_event_;
193
194 Profile* profile_;
195 };
196
197 } // namespace input_method
198
199 #endif // CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/input_method/OWNERS ('k') | chrome/browser/input_method/input_method_engine_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698