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