OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk2.h" | 5 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 #include <gdk/gdkx.h> | 9 #include <gdk/gdkx.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <gtk/gtk.h> | 12 #include <gtk/gtk.h> |
13 | 13 |
14 #include <X11/X.h> | 14 #include <X11/X.h> |
15 #include <X11/Xlib.h> | 15 #include <X11/Xlib.h> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (event->key.window != gdk_last_set_client_window_) { | 74 if (event->key.window != gdk_last_set_client_window_) { |
75 gtk_im_context_set_client_window(gtk_context_, event->key.window); | 75 gtk_im_context_set_client_window(gtk_context_, event->key.window); |
76 gdk_last_set_client_window_ = event->key.window; | 76 gdk_last_set_client_window_ = event->key.window; |
77 } | 77 } |
78 | 78 |
79 // Convert the last known caret bounds relative to the screen coordinates | 79 // Convert the last known caret bounds relative to the screen coordinates |
80 // to a GdkRectangle relative to the client window. | 80 // to a GdkRectangle relative to the client window. |
81 gint x = 0; | 81 gint x = 0; |
82 gint y = 0; | 82 gint y = 0; |
83 gdk_window_get_origin(event->key.window, &x, &y); | 83 gdk_window_get_origin(event->key.window, &x, &y); |
84 GdkRectangle rect = {last_caret_bounds_.x() - x, | 84 GdkRectangle rect = {last_caret_bounds_.x() - x, last_caret_bounds_.y() - y, |
85 last_caret_bounds_.y() - y, | 85 last_caret_bounds_.width(), last_caret_bounds_.height()}; |
86 last_caret_bounds_.width(), | |
87 last_caret_bounds_.height()}; | |
88 gtk_im_context_set_cursor_location(gtk_context_, &rect); | 86 gtk_im_context_set_cursor_location(gtk_context_, &rect); |
89 | 87 |
90 const bool handled = | 88 const bool handled = |
91 gtk_im_context_filter_keypress(gtk_context_, &event->key); | 89 gtk_im_context_filter_keypress(gtk_context_, &event->key); |
92 gdk_event_free(event); | 90 gdk_event_free(event); |
93 return handled; | 91 return handled; |
94 } | 92 } |
95 | 93 |
96 void X11InputMethodContextImplGtk2::Reset() { | 94 void X11InputMethodContextImplGtk2::Reset() { |
97 gtk_im_context_reset(gtk_context_); | 95 gtk_im_context_reset(gtk_context_); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return NULL; | 182 return NULL; |
185 } | 183 } |
186 // Get a keysym and group. | 184 // Get a keysym and group. |
187 KeySym keysym = NoSymbol; | 185 KeySym keysym = NoSymbol; |
188 guint8 keyboard_group = 0; | 186 guint8 keyboard_group = 0; |
189 XLookupString(&xkey, NULL, 0, &keysym, NULL); | 187 XLookupString(&xkey, NULL, 0, &keysym, NULL); |
190 GdkKeymap* keymap = gdk_keymap_get_for_display(display); | 188 GdkKeymap* keymap = gdk_keymap_get_for_display(display); |
191 GdkKeymapKey* keys = NULL; | 189 GdkKeymapKey* keys = NULL; |
192 guint* keyvals = NULL; | 190 guint* keyvals = NULL; |
193 gint n_entries = 0; | 191 gint n_entries = 0; |
194 if (keymap && | 192 if (keymap && gdk_keymap_get_entries_for_keycode(keymap, xkey.keycode, &keys, |
195 gdk_keymap_get_entries_for_keycode(keymap, xkey.keycode, | 193 &keyvals, &n_entries)) { |
196 &keys, &keyvals, &n_entries)) { | |
197 for (gint i = 0; i < n_entries; ++i) { | 194 for (gint i = 0; i < n_entries; ++i) { |
198 if (keyvals[i] == keysym) { | 195 if (keyvals[i] == keysym) { |
199 keyboard_group = keys[i].group; | 196 keyboard_group = keys[i].group; |
200 break; | 197 break; |
201 } | 198 } |
202 } | 199 } |
203 } | 200 } |
204 g_free(keys); | 201 g_free(keys); |
205 keys = NULL; | 202 keys = NULL; |
206 g_free(keyvals); | 203 g_free(keyvals); |
207 keyvals = NULL; | 204 keyvals = NULL; |
208 // Get a GdkWindow. | 205 // Get a GdkWindow. |
209 #if GTK_CHECK_VERSION(2,24,0) | 206 #if GTK_CHECK_VERSION(2, 24, 0) |
210 GdkWindow* window = gdk_x11_window_lookup_for_display(display, xkey.window); | 207 GdkWindow* window = gdk_x11_window_lookup_for_display(display, xkey.window); |
211 #else | 208 #else |
212 GdkWindow* window = gdk_window_lookup_for_display(display, xkey.window); | 209 GdkWindow* window = gdk_window_lookup_for_display(display, xkey.window); |
213 #endif | 210 #endif |
214 if (window) | 211 if (window) |
215 g_object_ref(window); | 212 g_object_ref(window); |
216 else | 213 else |
217 #if GTK_CHECK_VERSION(2,24,0) | 214 #if GTK_CHECK_VERSION(2, 24, 0) |
218 window = gdk_x11_window_foreign_new_for_display(display, xkey.window); | 215 window = gdk_x11_window_foreign_new_for_display(display, xkey.window); |
219 #else | 216 #else |
220 window = gdk_window_foreign_new_for_display(display, xkey.window); | 217 window = gdk_window_foreign_new_for_display(display, xkey.window); |
221 #endif | 218 #endif |
222 if (!window) { | 219 if (!window) { |
223 LOG(ERROR) << "Cannot get a GdkWindow for a key event."; | 220 LOG(ERROR) << "Cannot get a GdkWindow for a key event."; |
224 return NULL; | 221 return NULL; |
225 } | 222 } |
226 | 223 |
227 // Create a GdkEvent. | 224 // Create a GdkEvent. |
228 GdkEventType event_type = xkey.type == KeyPress ? | 225 GdkEventType event_type = |
229 GDK_KEY_PRESS : GDK_KEY_RELEASE; | 226 xkey.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE; |
230 GdkEvent* event = gdk_event_new(event_type); | 227 GdkEvent* event = gdk_event_new(event_type); |
231 event->key.type = event_type; | 228 event->key.type = event_type; |
232 event->key.window = window; | 229 event->key.window = window; |
233 // GdkEventKey and XKeyEvent share the same definition for time and state. | 230 // GdkEventKey and XKeyEvent share the same definition for time and state. |
234 event->key.send_event = xkey.send_event; | 231 event->key.send_event = xkey.send_event; |
235 event->key.time = xkey.time; | 232 event->key.time = xkey.time; |
236 event->key.state = xkey.state; | 233 event->key.state = xkey.state; |
237 event->key.keyval = keysym; | 234 event->key.keyval = keysym; |
238 event->key.length = 0; | 235 event->key.length = 0; |
239 event->key.string = NULL; | 236 event->key.string = NULL; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 304 } |
308 | 305 |
309 void X11InputMethodContextImplGtk2::OnPreeditStart(GtkIMContext* context) { | 306 void X11InputMethodContextImplGtk2::OnPreeditStart(GtkIMContext* context) { |
310 if (context != gtk_context_) | 307 if (context != gtk_context_) |
311 return; | 308 return; |
312 | 309 |
313 delegate_->OnPreeditStart(); | 310 delegate_->OnPreeditStart(); |
314 } | 311 } |
315 | 312 |
316 } // namespace libgtkui | 313 } // namespace libgtkui |
OLD | NEW |