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/libgtk2ui/x11_input_method_context_impl_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.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 | 10 |
11 #include <gtk/gtk.h> | 11 #include <gtk/gtk.h> |
12 | 12 |
13 #include <X11/X.h> | 13 #include <X11/X.h> |
14 #include <X11/Xlib.h> | 14 #include <X11/Xlib.h> |
15 | 15 |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "ui/base/ime/composition_text.h" | 18 #include "ui/base/ime/composition_text.h" |
19 #include "ui/base/ime/composition_text_util_pango.h" | 19 #include "ui/base/ime/composition_text_util_pango.h" |
20 #include "ui/base/ime/text_input_client.h" | 20 #include "ui/base/ime/text_input_client.h" |
21 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 22 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
22 #include "ui/gfx/x/x11_types.h" | 23 #include "ui/gfx/x/x11_types.h" |
23 | 24 |
24 namespace libgtk2ui { | 25 namespace libgtk2ui { |
25 | 26 |
26 X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2( | 27 X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2( |
27 ui::LinuxInputMethodContextDelegate* delegate) | 28 ui::LinuxInputMethodContextDelegate* delegate) |
28 : delegate_(delegate), | 29 : delegate_(delegate), |
29 gtk_context_simple_(NULL), | 30 gtk_context_simple_(NULL), |
30 gtk_multicontext_(NULL), | 31 gtk_multicontext_(NULL), |
31 gtk_context_(NULL), | 32 gtk_context_(NULL), |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 break; | 185 break; |
185 } | 186 } |
186 } | 187 } |
187 } | 188 } |
188 XFree(const_cast<KeySym*>(keysyms)); | 189 XFree(const_cast<KeySym*>(keysyms)); |
189 XFreeModifiermap(const_cast<XModifierKeymap*>(modmap)); | 190 XFreeModifiermap(const_cast<XModifierKeymap*>(modmap)); |
190 } | 191 } |
191 | 192 |
192 GdkEvent* X11InputMethodContextImplGtk2::GdkEventFromNativeEvent( | 193 GdkEvent* X11InputMethodContextImplGtk2::GdkEventFromNativeEvent( |
193 const base::NativeEvent& native_event) { | 194 const base::NativeEvent& native_event) { |
194 const XKeyEvent& xkey = native_event->xkey; | 195 XEvent xkeyevent; |
195 DCHECK(xkey.type == KeyPress || xkey.type == KeyRelease); | 196 if (native_event->type == GenericEvent) { |
| 197 // If this is an XI2 key event, build a matching core X event, to avoid |
| 198 // having two cases for every use. |
| 199 ui::InitXKeyEventFromXIDeviceEvent(*native_event, &xkeyevent); |
| 200 } else { |
| 201 DCHECK(native_event->type == KeyPress || native_event->type == KeyRelease); |
| 202 xkeyevent.xkey = native_event->xkey; |
| 203 } |
| 204 XKeyEvent& xkey = xkeyevent.xkey; |
196 | 205 |
197 // Get a GdkDisplay. | 206 // Get a GdkDisplay. |
198 GdkDisplay* display = gdk_x11_lookup_xdisplay(xkey.display); | 207 GdkDisplay* display = gdk_x11_lookup_xdisplay(xkey.display); |
199 if (!display) { | 208 if (!display) { |
200 // Fall back to the default display. | 209 // Fall back to the default display. |
201 display = gdk_display_get_default(); | 210 display = gdk_display_get_default(); |
202 } | 211 } |
203 if (!display) { | 212 if (!display) { |
204 LOG(ERROR) << "Cannot get a GdkDisplay for a key event."; | 213 LOG(ERROR) << "Cannot get a GdkDisplay for a key event."; |
205 return NULL; | 214 return NULL; |
206 } | 215 } |
207 // Get a keysym and group. | 216 // Get a keysym and group. |
208 KeySym keysym = NoSymbol; | 217 KeySym keysym = NoSymbol; |
209 guint8 keyboard_group = 0; | 218 guint8 keyboard_group = 0; |
210 XLookupString(&native_event->xkey, NULL, 0, &keysym, NULL); | 219 XLookupString(&xkey, NULL, 0, &keysym, NULL); |
211 GdkKeymap* keymap = gdk_keymap_get_for_display(display); | 220 GdkKeymap* keymap = gdk_keymap_get_for_display(display); |
212 GdkKeymapKey* keys = NULL; | 221 GdkKeymapKey* keys = NULL; |
213 guint* keyvals = NULL; | 222 guint* keyvals = NULL; |
214 gint n_entries = 0; | 223 gint n_entries = 0; |
215 if (keymap && | 224 if (keymap && |
216 gdk_keymap_get_entries_for_keycode(keymap, xkey.keycode, | 225 gdk_keymap_get_entries_for_keycode(keymap, xkey.keycode, |
217 &keys, &keyvals, &n_entries)) { | 226 &keys, &keyvals, &n_entries)) { |
218 for (gint i = 0; i < n_entries; ++i) { | 227 for (gint i = 0; i < n_entries; ++i) { |
219 if (keyvals[i] == keysym) { | 228 if (keyvals[i] == keysym) { |
220 keyboard_group = keys[i].group; | 229 keyboard_group = keys[i].group; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 text.length() == 1 && | 369 text.length() == 1 && |
361 text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { | 370 text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { |
362 is_signal_caught_ = true; | 371 is_signal_caught_ = true; |
363 return true; | 372 return true; |
364 } else { | 373 } else { |
365 return false; | 374 return false; |
366 } | 375 } |
367 } | 376 } |
368 | 377 |
369 } // namespace libgtk2ui | 378 } // namespace libgtk2ui |
OLD | NEW |