OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk/bubble/bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h" | 10 #include "chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 gboolean BubbleGtk::OnGtkAccelerator(GtkAccelGroup* group, | 395 gboolean BubbleGtk::OnGtkAccelerator(GtkAccelGroup* group, |
396 GObject* acceleratable, | 396 GObject* acceleratable, |
397 guint keyval, | 397 guint keyval, |
398 GdkModifierType modifier) { | 398 GdkModifierType modifier) { |
399 GdkEventKey msg; | 399 GdkEventKey msg; |
400 GdkKeymapKey* keys; | 400 GdkKeymapKey* keys; |
401 gint n_keys; | 401 gint n_keys; |
402 | 402 bool close_bubble = false; |
403 switch (keyval) { | 403 switch (keyval) { |
404 case GDK_Escape: | 404 case GDK_Escape: |
405 // Close on Esc and trap the accelerator | 405 // Close on Esc and trap the accelerator |
406 closed_by_escape_ = true; | 406 closed_by_escape_ = true; |
407 Close(); | 407 Close(); |
408 return TRUE; | 408 return TRUE; |
409 case GDK_w: | 409 case GDK_w: |
410 // Close on C-w and forward the accelerator | 410 // Close on C-w and forward the accelerator |
411 if (modifier & GDK_CONTROL_MASK) { | 411 if (modifier & GDK_CONTROL_MASK) { |
412 Close(); | 412 close_bubble = true; |
413 } | 413 } |
414 break; | 414 break; |
415 default: | 415 default: |
416 return FALSE; | 416 return FALSE; |
417 } | 417 } |
418 | 418 |
419 gdk_keymap_get_entries_for_keyval(NULL, | 419 gdk_keymap_get_entries_for_keyval(NULL, |
Evan Stade
2011/09/23 20:09:42
can you just move this entire block into the GDK_w
| |
420 keyval, | 420 keyval, |
421 &keys, | 421 &keys, |
422 &n_keys); | 422 &n_keys); |
423 if (n_keys) { | 423 if (n_keys) { |
424 // Forward the accelerator to root window the bubble is anchored | 424 // Forward the accelerator to root window the bubble is anchored |
425 // to for further processing | 425 // to for further processing |
426 msg.type = GDK_KEY_PRESS; | 426 msg.type = GDK_KEY_PRESS; |
427 msg.window = GTK_WIDGET(toplevel_window_)->window; | 427 msg.window = GTK_WIDGET(toplevel_window_)->window; |
428 msg.send_event = TRUE; | 428 msg.send_event = TRUE; |
429 msg.time = GDK_CURRENT_TIME; | 429 msg.time = GDK_CURRENT_TIME; |
430 msg.state = modifier | GDK_MOD2_MASK; | 430 msg.state = modifier | GDK_MOD2_MASK; |
431 msg.keyval = keyval; | 431 msg.keyval = keyval; |
432 // length and string are deprecated and thus zeroed out | 432 // length and string are deprecated and thus zeroed out |
433 msg.length = 0; | 433 msg.length = 0; |
434 msg.string = NULL; | 434 msg.string = NULL; |
435 msg.hardware_keycode = keys[0].keycode; | 435 msg.hardware_keycode = keys[0].keycode; |
436 msg.group = keys[0].group; | 436 msg.group = keys[0].group; |
437 msg.is_modifier = 0; | 437 msg.is_modifier = 0; |
438 | 438 |
439 g_free(keys); | 439 g_free(keys); |
440 | 440 |
441 gtk_main_do_event(reinterpret_cast<GdkEvent*>(&msg)); | 441 gtk_main_do_event(reinterpret_cast<GdkEvent*>(&msg)); |
442 } else { | 442 } else { |
443 // This means that there isn't a h/w code for the keyval in the | 443 // This means that there isn't a h/w code for the keyval in the |
444 // current keymap, which is weird but possible if the keymap just | 444 // current keymap, which is weird but possible if the keymap just |
445 // changed. This isn't a critical error, but might be indicative | 445 // changed. This isn't a critical error, but might be indicative |
446 // of something off if it happens regularly. | 446 // of something off if it happens regularly. |
447 DLOG(WARNING) << "Found no keys for value " << keyval; | 447 DLOG(WARNING) << "Found no keys for value " << keyval; |
448 } | 448 } |
449 if (close_bubble == true) | |
Evan Stade
2011/09/23 20:09:42
no == true
| |
450 Close(); | |
449 return TRUE; | 451 return TRUE; |
450 } | 452 } |
451 | 453 |
452 gboolean BubbleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) { | 454 gboolean BubbleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) { |
453 GdkDrawable* drawable = GDK_DRAWABLE(window_->window); | 455 GdkDrawable* drawable = GDK_DRAWABLE(window_->window); |
454 GdkGC* gc = gdk_gc_new(drawable); | 456 GdkGC* gc = gdk_gc_new(drawable); |
455 gdk_gc_set_rgb_fg_color(gc, &kFrameColor); | 457 gdk_gc_set_rgb_fg_color(gc, &kFrameColor); |
456 | 458 |
457 // Stroke the frame border. | 459 // Stroke the frame border. |
458 std::vector<GdkPoint> points = MakeFramePolygonPoints( | 460 std::vector<GdkPoint> points = MakeFramePolygonPoints( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 gboolean BubbleGtk::OnToplevelUnmap(GtkWidget* widget, GdkEvent* event) { | 527 gboolean BubbleGtk::OnToplevelUnmap(GtkWidget* widget, GdkEvent* event) { |
526 Close(); | 528 Close(); |
527 return FALSE; | 529 return FALSE; |
528 } | 530 } |
529 | 531 |
530 void BubbleGtk::OnAnchorAllocate(GtkWidget* widget, | 532 void BubbleGtk::OnAnchorAllocate(GtkWidget* widget, |
531 GtkAllocation* allocation) { | 533 GtkAllocation* allocation) { |
532 if (!UpdateArrowLocation(false)) | 534 if (!UpdateArrowLocation(false)) |
533 MoveWindow(); | 535 MoveWindow(); |
534 } | 536 } |
OLD | NEW |