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 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 keyboard_group = keys[i].group; | 229 keyboard_group = keys[i].group; |
230 break; | 230 break; |
231 } | 231 } |
232 } | 232 } |
233 } | 233 } |
234 g_free(keys); | 234 g_free(keys); |
235 keys = NULL; | 235 keys = NULL; |
236 g_free(keyvals); | 236 g_free(keyvals); |
237 keyvals = NULL; | 237 keyvals = NULL; |
238 // Get a GdkWindow. | 238 // Get a GdkWindow. |
239 #if GTK_CHECK_VERSION(2,24,0) | |
240 GdkWindow* window = gdk_x11_window_lookup_for_display(display, xkey.window); | 239 GdkWindow* window = gdk_x11_window_lookup_for_display(display, xkey.window); |
241 #else | |
242 GdkWindow* window = gdk_window_lookup_for_display(display, xkey.window); | |
243 #endif | |
244 if (window) | 240 if (window) |
245 g_object_ref(window); | 241 g_object_ref(window); |
246 else | 242 else |
247 #if GTK_CHECK_VERSION(2,24,0) | |
248 window = gdk_x11_window_foreign_new_for_display(display, xkey.window); | 243 window = gdk_x11_window_foreign_new_for_display(display, xkey.window); |
249 #else | |
250 window = gdk_window_foreign_new_for_display(display, xkey.window); | |
251 #endif | |
252 if (!window) { | 244 if (!window) { |
253 LOG(ERROR) << "Cannot get a GdkWindow for a key event."; | 245 LOG(ERROR) << "Cannot get a GdkWindow for a key event."; |
254 return NULL; | 246 return NULL; |
255 } | 247 } |
256 | 248 |
257 // Create a GdkEvent. | 249 // Create a GdkEvent. |
258 GdkEventType event_type = xkey.type == KeyPress ? | 250 GdkEventType event_type = xkey.type == KeyPress ? |
259 GDK_KEY_PRESS : GDK_KEY_RELEASE; | 251 GDK_KEY_PRESS : GDK_KEY_RELEASE; |
260 GdkEvent* event = gdk_event_new(event_type); | 252 GdkEvent* event = gdk_event_new(event_type); |
261 event->key.type = event_type; | 253 event->key.type = event_type; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (context != gtk_context_) | 341 if (context != gtk_context_) |
350 return; | 342 return; |
351 | 343 |
352 delegate_->OnPreeditStart(); | 344 delegate_->OnPreeditStart(); |
353 } | 345 } |
354 | 346 |
355 // GtkCommitSignalTrap | 347 // GtkCommitSignalTrap |
356 | 348 |
357 X11InputMethodContextImplGtk2::GtkCommitSignalTrap::GtkCommitSignalTrap() | 349 X11InputMethodContextImplGtk2::GtkCommitSignalTrap::GtkCommitSignalTrap() |
358 : is_trap_enabled_(false), | 350 : is_trap_enabled_(false), |
359 #if GTK_CHECK_VERSION (2,22,0) | |
360 gdk_event_key_keyval_(GDK_KEY_VoidSymbol), | 351 gdk_event_key_keyval_(GDK_KEY_VoidSymbol), |
361 #else | |
362 gdk_event_key_keyval_(GDK_VoidSymbol), | |
363 #endif | |
364 is_signal_caught_(false) {} | 352 is_signal_caught_(false) {} |
365 | 353 |
366 void X11InputMethodContextImplGtk2::GtkCommitSignalTrap::StartTrap( | 354 void X11InputMethodContextImplGtk2::GtkCommitSignalTrap::StartTrap( |
367 guint keyval) { | 355 guint keyval) { |
368 is_signal_caught_ = false; | 356 is_signal_caught_ = false; |
369 gdk_event_key_keyval_ = keyval; | 357 gdk_event_key_keyval_ = keyval; |
370 is_trap_enabled_ = true; | 358 is_trap_enabled_ = true; |
371 } | 359 } |
372 | 360 |
373 void X11InputMethodContextImplGtk2::GtkCommitSignalTrap::StopTrap() { | 361 void X11InputMethodContextImplGtk2::GtkCommitSignalTrap::StopTrap() { |
374 is_trap_enabled_ = false; | 362 is_trap_enabled_ = false; |
375 } | 363 } |
376 | 364 |
377 bool X11InputMethodContextImplGtk2::GtkCommitSignalTrap::Trap( | 365 bool X11InputMethodContextImplGtk2::GtkCommitSignalTrap::Trap( |
378 const base::string16& text) { | 366 const base::string16& text) { |
379 DCHECK(!is_signal_caught_); | 367 DCHECK(!is_signal_caught_); |
380 if (is_trap_enabled_ && | 368 if (is_trap_enabled_ && |
381 text.length() == 1 && | 369 text.length() == 1 && |
382 text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { | 370 text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { |
383 is_signal_caught_ = true; | 371 is_signal_caught_ = true; |
384 return true; | 372 return true; |
385 } else { | 373 } else { |
386 return false; | 374 return false; |
387 } | 375 } |
388 } | 376 } |
389 | 377 |
390 } // namespace libgtk2ui | 378 } // namespace libgtk2ui |
OLD | NEW |