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

Side by Side Diff: chrome/browser/chromeos/input_method/ibus_controller.h

Issue 7046069: Copy chromeos_input_method* from libcros as-is. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/ibus_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium OS 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 CHROMEOS_INPUT_METHOD_H_
6 #define CHROMEOS_INPUT_METHOD_H_
7
8 #include <sstream>
9 #include <string>
10 #include <utility>
11 #include <vector>
12
13 #include <base/basictypes.h>
14 #include <base/logging.h> // DCHECK
15 #include <base/string_split.h>
16
17 namespace chromeos {
18
19 // A structure which represents an input method. All methods in this class have
20 // to be in chromeos_input_method.h since Chrome also creates an instance of
21 // the class.
22 struct InputMethodDescriptor {
23 InputMethodDescriptor() {
24 }
25
26 // Do not call this function directly. Use CreateInputMethodDescriptor() in
27 // chromeos_input_method.cc whenever possible.
28 InputMethodDescriptor(const std::string& in_id,
29 const std::string& in_display_name,
30 const std::string& in_keyboard_layout,
31 const std::string& in_virtual_keyboard_layouts,
32 const std::string& in_language_code)
33 : virtual_keyboard_layouts_(in_virtual_keyboard_layouts),
34 id(in_id),
35 display_name(in_display_name),
36 keyboard_layout(in_keyboard_layout),
37 language_code(in_language_code) {
38 DCHECK(keyboard_layout.find(",") == std::string::npos);
39 }
40
41 bool operator==(const InputMethodDescriptor& other) const {
42 return (id == other.id);
43 }
44
45 // Debug print function.
46 std::string ToString() const {
47 std::stringstream stream;
48 stream << "id=" << id
49 << ", display_name=" << display_name
50 << ", keyboard_layout=" << keyboard_layout
51 << ", virtual_keyboard_layouts=" << virtual_keyboard_layouts_
52 << ", language_code=" << language_code;
53 return stream.str();
54 }
55
56 // TODO(yusukes): When libcros is moved to Chrome, do the following:
57 // 1. Change the type of the virtual_keyboard_layouts_ variable to
58 // std::vector<std::string> and rename it back to virtual_keyboard_layouts.
59 // 2. Remove the virtual_keyboard_layouts() function.
60 // We can't do them right now because it will break ABI compatibility...
61 std::vector<std::string> virtual_keyboard_layouts() const {
62 std::vector<std::string> layout_names;
63 base::SplitString(virtual_keyboard_layouts_, ',', &layout_names);
64 return layout_names;
65 }
66
67 // Preferred virtual keyboard layouts for the input method. Comma separated
68 // layout names in order of priority, such as "handwriting,us", could appear.
69 // Note: DO NOT ACCESS THIS VARIABLE DIRECTLY. USE virtual_keyboard_layouts()
70 // INSTEAD. SEE THE TODO ABOVE.
71 std::string virtual_keyboard_layouts_;
72
73 // An ID that identifies an input method engine (e.g., "t:latn-post",
74 // "pinyin", "hangul").
75 std::string id;
76 // An input method name which can be used in the UI (e.g., "Pinyin").
77 std::string display_name;
78 // A preferred physical keyboard layout for the input method (e.g., "us",
79 // "us(dvorak)", "jp"). Comma separated layout names do NOT appear.
80 std::string keyboard_layout;
81 // Language codes like "ko", "ja", "zh_CN", and "t".
82 // "t" is used for languages in the "Others" category.
83 std::string language_code;
84 };
85 typedef std::vector<InputMethodDescriptor> InputMethodDescriptors;
86
87 // A structure which represents a property for an input method engine. For
88 // details, please check a comment for the LanguageRegisterImePropertiesFunction
89 // typedef below.
90 // TODO(yusukes): Rename this struct. "InputMethodProperty" might be better?
91 struct ImeProperty {
92 ImeProperty(const std::string& in_key,
93 const std::string& in_label,
94 bool in_is_selection_item,
95 bool in_is_selection_item_checked,
96 int in_selection_item_id)
97 : key(in_key),
98 label(in_label),
99 is_selection_item(in_is_selection_item),
100 is_selection_item_checked(in_is_selection_item_checked),
101 selection_item_id(in_selection_item_id) {
102 DCHECK(!key.empty());
103 }
104
105 ImeProperty()
106 : is_selection_item(false),
107 is_selection_item_checked(false),
108 selection_item_id(kInvalidSelectionItemId) {
109 }
110
111 // Debug print function.
112 std::string ToString() const {
113 std::stringstream stream;
114 stream << "key=" << key
115 << ", label=" << label
116 << ", is_selection_item=" << is_selection_item
117 << ", is_selection_item_checked=" << is_selection_item_checked
118 << ", selection_item_id=" << selection_item_id;
119 return stream.str();
120 }
121
122 std::string key; // A key which identifies the property. Non-empty string.
123 // (e.g. "InputMode.HalfWidthKatakana")
124 // DEPRECATED: TODO(yusukes): Remove this when it's ready.
125 std::string deprecated_icon_path;
126 std::string label; // A description of the property. Non-empty string.
127 // (e.g. "Switch to full punctuation mode", "Hiragana")
128 bool is_selection_item; // true if the property is a selection item.
129 bool is_selection_item_checked; // true if |is_selection_item| is true and
130 // the selection_item is selected.
131 int selection_item_id; // A group ID (>= 0) of the selection item.
132 // kInvalidSelectionItemId if |is_selection_item| is
133 // false.
134 static const int kInvalidSelectionItemId = -1;
135 };
136 typedef std::vector<ImeProperty> ImePropertyList;
137
138 // A structure which represents a value of an input method configuration item.
139 // This struct is used by SetImeConfig().
140 // TODO(yusukes): Rename this struct. "InputMethodConfigValue" might be better?
141 struct ImeConfigValue {
142 ImeConfigValue()
143 : type(kValueTypeString),
144 int_value(0),
145 bool_value(false) {
146 }
147
148 // Debug print function.
149 std::string ToString() const {
150 std::stringstream stream;
151 stream << "type=" << type;
152 switch (type) {
153 case kValueTypeString:
154 stream << ", string_value=" << string_value;
155 break;
156 case kValueTypeInt:
157 stream << ", int_value=" << int_value;
158 break;
159 case kValueTypeBool:
160 stream << ", bool_value=" << (bool_value ? "true" : "false");
161 break;
162 case kValueTypeStringList:
163 stream << ", string_list_value=";
164 for (size_t i = 0; i < string_list_value.size(); ++i) {
165 if (i) {
166 stream << ",";
167 }
168 stream << string_list_value[i];
169 }
170 break;
171 }
172 return stream.str();
173 }
174
175 enum ValueType {
176 kValueTypeString = 0,
177 kValueTypeInt,
178 kValueTypeBool,
179 kValueTypeStringList,
180 };
181
182 // A value is stored on |string_value| member if |type| is kValueTypeString.
183 // The same is true for other enum values.
184 ValueType type;
185
186 std::string string_value;
187 int int_value;
188 bool bool_value;
189 std::vector<std::string> string_list_value;
190 };
191
192 // A monitor function which is called when current input method is changed by a
193 // user.
194 typedef void(*LanguageCurrentInputMethodMonitorFunction)(
195 void* language_library, const InputMethodDescriptor& current_input_method);
196
197 // A monitor function which is called when "RegisterProperties" signal is sent
198 // from ibus-daemon. The signal contains a list of properties for a specific
199 // input method engine. For example, Japanese input method might have the
200 // following properties:
201 //
202 // ----------------------------------
203 // key: InputMode.Hiragana
204 // label: Hiragana
205 // is_selection_item: true
206 // is_selection_item_checked: true
207 // selection_item_id: 1
208 // ----------------------------------
209 // key: InputMode.Katakana
210 // label: Katakana
211 // is_selection_item: true
212 // is_selection_item_checked: false
213 // selection_item_id: 1
214 // ----------------------------------
215 // ...
216 // ----------------------------------
217 typedef void(*LanguageRegisterImePropertiesFunction)(
218 void* language_library, const ImePropertyList& prop_list);
219
220 // A monitor function which is called when "UpdateProperty" signal is sent
221 // from ibus-daemon. The signal contains one or more properties which is updated
222 // recently. Keys the signal contains are a subset of keys registered by the
223 // "RegisterProperties" signal above. For example,
224 // Japanese input method might send the following properties:
225 //
226 // ----------------------------------
227 // key: InputMode.Hiragana
228 // label: Hiragana
229 // is_selection_item: true
230 // is_selection_item_checked: false
231 // selection_item_id: ...
232 // ----------------------------------
233 // key: InputMode.Katakana
234 // label: Katakana
235 // is_selection_item: true
236 // is_selection_item_checked: true
237 // selection_item_id: ...
238 // ----------------------------------
239 //
240 // Note: Please do not use selection_item_ids in |prop_list|. Dummy values are
241 // filled in the field.
242 typedef void(*LanguageUpdateImePropertyFunction)(
243 void* language_library, const ImePropertyList& prop_list);
244
245 // A monitor function which is called when ibus connects or disconnects.
246 typedef void(*LanguageConnectionChangeMonitorFunction)(
247 void* language_library, bool connected);
248
249 // Establishes IBus connection to the ibus-daemon. LanguageXXXFunction functions
250 // will be called when status of input method engines is changed.
251 class InputMethodStatusConnection;
252 extern InputMethodStatusConnection* (*MonitorInputMethodStatus)(
253 void* language_library,
254 LanguageCurrentInputMethodMonitorFunction current_input_method,
255 LanguageRegisterImePropertiesFunction register_ime_properties,
256 LanguageUpdateImePropertyFunction update_ime_property,
257 LanguageConnectionChangeMonitorFunction connection_changed);
258
259 // Stops ibus-daemon. Returns true on success.
260 extern bool (*StopInputMethodProcess)(InputMethodStatusConnection* connection);
261
262 // Gets all input method engines that are supported, including ones not active.
263 // Caller has to delete the returned list. This function never returns NULL.
264 extern InputMethodDescriptors* (*GetSupportedInputMethodDescriptors)();
265
266 // Changes the current input method engine to |name|. Returns true on success.
267 // Examples of names: "pinyin", "m17n:ar:kbd", "xkb:us:dvorak:eng".
268 extern bool (*ChangeInputMethod)(
269 InputMethodStatusConnection* connection, const char* name);
270
271 // Sets whether the input method property specified by |key| is activated.
272 // If |activated| is true, activates the property. If |activated| is false,
273 // deactivates the property.
274 // TODO(yusukes): "SetInputMethodPropertyActivated" might be better?
275 extern void (*SetImePropertyActivated)(InputMethodStatusConnection* connection,
276 const char* key,
277 bool activated);
278
279 // Sets a configuration of ibus-daemon or IBus engines to |value|.
280 // Returns true if the configuration is successfully set.
281 //
282 // To set 'panel/custom_font', |section| should be "panel", and
283 // |config_name| should be "custom_font".
284 // TODO(yusukes): "SetInputMethodConfig" might be better?
285 extern bool (*SetImeConfig)(InputMethodStatusConnection* connection,
286 const char* section,
287 const char* config_name,
288 const ImeConfigValue& value);
289
290 // Returns the keyboard overlay ID corresponding to |input_method_id|.
291 // Returns an empty string if there is no corresponding keyboard overlay ID.
292 extern std::string (*GetKeyboardOverlayId)(
293 const std::string& input_method_id);
294
295 // Sends a handwriting stroke to ibus-daemon. The std::pair contains x and y
296 // coordinates. (0.0, 0.0) represents the top-left corner of a handwriting area,
297 // and (1.0, 1.0) does the bottom-right. For example, the second stroke for ロ
298 // (Katakana character Ro) would be something like [(0,0), (1,0), (1,1)].
299 // stroke.size() should always be >= 2 (i.e. a single dot is not allowed).
300 typedef std::vector<std::pair<double, double> > HandwritingStroke;
301 extern void (*SendHandwritingStroke)(
302 InputMethodStatusConnection* connection, const HandwritingStroke& stroke);
303
304 // Clears the last N handwriting strokes. Pass zero for clearing all strokes.
305 // TODO(yusukes): Currently ibus-daemon only accepts 0 for |n_strokes|.
306 extern void (*CancelHandwriting)(InputMethodStatusConnection* connection,
307 int n_strokes);
308
309 //
310 // FUNCTIONS BELOW ARE ONLY FOR UNIT TESTS. DO NOT USE THEM.
311 //
312 bool InputMethodIdIsWhitelisted(const std::string& input_method_id);
313 bool XkbLayoutIsSupported(const std::string& xkb_layout);
314 InputMethodDescriptor CreateInputMethodDescriptor(
315 const std::string& id,
316 const std::string& display_name,
317 const std::string& raw_layout,
318 const std::string& language_code);
319
320 } // namespace chromeos
321
322 #endif // CHROMEOS_INPUT_METHOD_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/ibus_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698