OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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 // The header files provides APIs for monitoring and controlling input | |
6 // method UI status. The APIs encapsulate the APIs of IBus, the underlying | |
7 // input method framework. | |
8 | |
9 #ifndef CHROMEOS_INPUT_METHOD_UI_H_ | |
10 #define CHROMEOS_INPUT_METHOD_UI_H_ | |
11 | |
12 #include <base/basictypes.h> | |
13 | |
14 #include <sstream> | |
15 #include <string> | |
16 #include <vector> | |
17 | |
18 namespace chromeos { | |
19 | |
20 // A key for attaching the |ibus_service_panel_| object to |ibus_|. | |
21 const char kPanelObjectKey[] = "panel-object"; | |
22 | |
23 // The struct represents the input method lookup table (list of candidates). | |
24 // Used for InputMethodUpdateLookupTableMonitorFunction. | |
25 struct InputMethodLookupTable { | |
26 enum Orientation { | |
27 kVertical, | |
28 kHorizontal, | |
29 }; | |
30 | |
31 InputMethodLookupTable() | |
32 : visible(false), | |
33 cursor_absolute_index(0), | |
34 page_size(0), | |
35 orientation(kHorizontal) { | |
36 } | |
37 | |
38 // Returns a string representation of the class. Used for debugging. | |
39 // The function has to be defined here rather than in the .cc file. If | |
40 // it's defined in the .cc file, the code will be part of libcros.so, | |
41 // which cannot be accessed from clients directly. libcros.so is loaded | |
42 // by dlopen() so all functions are unbound unless explicitly bound by | |
43 // dlsym(). | |
44 std::string ToString() const { | |
45 std::stringstream stream; | |
46 stream << "visible: " << visible << "\n"; | |
47 stream << "cursor_absolute_index: " << cursor_absolute_index << "\n"; | |
48 stream << "page_size: " << page_size << "\n"; | |
49 stream << "orientation: " << orientation << "\n"; | |
50 stream << "candidates:"; | |
51 for (size_t i = 0; i < candidates.size(); ++i) { | |
52 stream << " [" << candidates[i] << "]"; | |
53 } | |
54 stream << "\nlabels:"; | |
55 for (size_t i = 0; i < labels.size(); ++i) { | |
56 stream << " [" << labels[i] << "]"; | |
57 } | |
58 return stream.str(); | |
59 } | |
60 | |
61 // True if the lookup table is visible. | |
62 bool visible; | |
63 | |
64 // Zero-origin index of the current cursor position in the all | |
65 // candidates. If the cursor is pointing to the third candidate in the | |
66 // second page when the page size is 10, the value will be 12 as it's | |
67 // 13th candidate. | |
68 int cursor_absolute_index; | |
69 | |
70 // Page size is the max number of candidates shown in a page. Usually | |
71 // it's about 10, depending on the backend conversion engine. | |
72 int page_size; | |
73 | |
74 // Candidate strings in UTF-8. | |
75 std::vector<std::string> candidates; | |
76 | |
77 // The orientation of the candidates in the candidate window. | |
78 Orientation orientation; | |
79 | |
80 // Label strings in UTF-8 (ex. "1", "2", "3", ...). | |
81 std::vector<std::string> labels; | |
82 | |
83 // Annotation strings in UTF-8 (ex. "Hankaku Katakana"). | |
84 std::vector<std::string> annotations; | |
85 }; | |
86 | |
87 // Callback function type for handling IBus's |HideAuxiliaryText| signal. | |
88 typedef void (*InputMethodHideAuxiliaryTextMonitorFunction)( | |
89 void* input_method_library); | |
90 | |
91 // Callback function type for handling IBus's |HideLookupTable| signal. | |
92 typedef void (*InputMethodHideLookupTableMonitorFunction)( | |
93 void* input_method_library); | |
94 | |
95 // Callback function type for handling IBus's |SetCandidateText| signal. | |
96 typedef void (*InputMethodSetCursorLocationMonitorFunction)( | |
97 void* input_method_library, | |
98 int x, int y, int width, int height); | |
99 | |
100 // Callback function type for handling IBus's |UpdateAuxiliaryText| signal. | |
101 typedef void (*InputMethodUpdateAuxiliaryTextMonitorFunction)( | |
102 void* input_method_library, | |
103 const std::string& text, | |
104 bool visible); | |
105 | |
106 // Callback function type for handling IBus's |UpdateLookupTable| signal. | |
107 typedef void (*InputMethodUpdateLookupTableMonitorFunction)( | |
108 void* input_method_library, | |
109 const InputMethodLookupTable& table); | |
110 | |
111 // A monitor function which is called when ibus connects or disconnects. | |
112 typedef void(*InputMethodConnectionChangeMonitorFunction)( | |
113 void* input_method_library, bool connected); | |
114 | |
115 // A set of function pointers used for monitoring the input method UI status. | |
116 struct InputMethodUiStatusMonitorFunctions { | |
117 InputMethodUiStatusMonitorFunctions() | |
118 : hide_auxiliary_text(NULL), | |
119 hide_lookup_table(NULL), | |
120 set_cursor_location(NULL), | |
121 update_auxiliary_text(NULL), | |
122 update_lookup_table(NULL) { | |
123 } | |
124 | |
125 InputMethodHideAuxiliaryTextMonitorFunction hide_auxiliary_text; | |
126 InputMethodHideLookupTableMonitorFunction hide_lookup_table; | |
127 InputMethodSetCursorLocationMonitorFunction set_cursor_location; | |
128 InputMethodUpdateAuxiliaryTextMonitorFunction update_auxiliary_text; | |
129 InputMethodUpdateLookupTableMonitorFunction update_lookup_table; | |
130 }; | |
131 | |
132 // Establishes IBus connection to the ibus-daemon. | |
133 // | |
134 // Returns an InputMethodUiStatusConnection object that is used for | |
135 // maintaining and monitoring an IBus connection. The implementation | |
136 // details of InputMethodUiStatusConnection is not exposed. | |
137 // | |
138 // Function pointers in |monitor_functions| are registered in the returned | |
139 // InputMethodUiStatusConnection object. These functions will be called, | |
140 // unless the pointers are NULL, when certain signals are received from | |
141 // ibus-daemon. | |
142 // | |
143 // The client can pass a pointer to an abitrary object as | |
144 // |input_method_library|. The pointer passed as |input_method_library| | |
145 // will be passed to the registered callback functions as the first | |
146 // parameter. | |
147 class InputMethodUiStatusConnection; | |
148 extern InputMethodUiStatusConnection* (*MonitorInputMethodUiStatus)( | |
149 const InputMethodUiStatusMonitorFunctions& monitor_functions, | |
150 void* input_method_library); | |
151 | |
152 // Disconnects the input method UI status connection, as well as the | |
153 // underlying IBus connection. | |
154 extern void (*DisconnectInputMethodUiStatus)( | |
155 InputMethodUiStatusConnection* connection); | |
156 | |
157 // Notifies that a candidate is clicked. |CandidateClicked| signal will be | |
158 // sent to the ibus-daemon. | |
159 // | |
160 // - |index| Index in the Lookup table. The semantics is same with | |
161 // |cursor_absolute_index|. | |
162 // - |button| GdkEventButton::button (1: left button, etc.) | |
163 // - |state| GdkEventButton::state (key modifier flags) | |
164 extern void (*NotifyCandidateClicked)( | |
165 InputMethodUiStatusConnection* connection, | |
166 int index, int button, int flags); | |
167 | |
168 // Notifies that the cursor up button is clicked. |CursorUp| signal will be | |
169 // sent to the ibus-daemon | |
170 extern void (*NotifyCursorUp)( | |
171 InputMethodUiStatusConnection* connection); | |
172 | |
173 // Notifies that the cursor down button is clicked. |CursorDown| signal will be | |
174 // sent to the ibus-daemon | |
175 extern void (*NotifyCursorDown)( | |
176 InputMethodUiStatusConnection* connection); | |
177 | |
178 // Notifies that the page up button is clicked. |PageUp| signal will be | |
179 // sent to the ibus-daemon | |
180 extern void (*NotifyPageUp)( | |
181 InputMethodUiStatusConnection* connection); | |
182 | |
183 // Notifies that the page down button is clicked. |PageDown| signal will be | |
184 // sent to the ibus-daemon | |
185 extern void (*NotifyPageDown)( | |
186 InputMethodUiStatusConnection* connection); | |
187 | |
188 // Set a notification function for changes to an ibus connection. | |
189 extern void (*MonitorInputMethodConnection)( | |
190 InputMethodUiStatusConnection* connection, | |
191 InputMethodConnectionChangeMonitorFunction connection_change_handler); | |
192 | |
193 } // namespace chromeos | |
194 | |
195 #endif // CHROMEOS_INPUT_METHOD_UI_H_ | |
OLD | NEW |