From 5bbf7496930ac17a9cf81c5e0a3dfec5a3cbd91e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Apr 2014 19:21:18 +0800 Subject: [PATCH] gtk: Handle accelerators after renderer handled them. The key-press signal captured the key events before renderer handles, which violated the behavior on OS X and Windows. Fixes #221. --- atom/browser/native_window_gtk.cc | 22 +++++++++++++--------- atom/browser/native_window_gtk.h | 8 +++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/atom/browser/native_window_gtk.cc b/atom/browser/native_window_gtk.cc index ff79eee..375f4d8 100644 --- a/atom/browser/native_window_gtk.cc +++ b/atom/browser/native_window_gtk.cc @@ -13,6 +13,7 @@ #include "base/nix/xdg_util.h" #include "base/values.h" #include "chrome/browser/ui/gtk/gtk_window_util.h" +#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/public/common/renderer_preferences.h" @@ -104,8 +105,6 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, G_CALLBACK(OnWindowDeleteEventThunk), this); g_signal_connect(window_, "focus-out-event", G_CALLBACK(OnFocusOutThunk), this); - g_signal_connect(window_, "key-press-event", - G_CALLBACK(OnKeyPressThunk), this); if (!has_frame_) { gtk_window_set_decorated(window_, false); @@ -343,6 +342,18 @@ void NativeWindowGtk::UpdateDraggableRegions( } } +void NativeWindowGtk::HandleKeyboardEvent( + content::WebContents*, + const content::NativeWebKeyboardEvent& event) { + if (event.type == WebKit::WebInputEvent::RawKeyDown) { + GdkEventKey* os_event = reinterpret_cast(event.os_event); + ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier( + os_event->keyval, static_cast(os_event->state)); + accelerator_util::TriggerAcceleratorTableCommand(&accelerator_table_, + accelerator); + } +} + void NativeWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { is_active_ = gtk_widget_get_window(GTK_WIDGET(window_)) == active_window; } @@ -505,13 +516,6 @@ gboolean NativeWindowGtk::OnButtonPress(GtkWidget* widget, return FALSE; } -gboolean NativeWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { - ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier( - event->keyval, static_cast(event->state)); - return accelerator_util::TriggerAcceleratorTableCommand( - &accelerator_table_, accelerator) ? TRUE: FALSE; -} - // static NativeWindow* NativeWindow::Create(content::WebContents* web_contents, base::DictionaryValue* options) { diff --git a/atom/browser/native_window_gtk.h b/atom/browser/native_window_gtk.h index 9ff0cac..6cd75ef 100644 --- a/atom/browser/native_window_gtk.h +++ b/atom/browser/native_window_gtk.h @@ -71,6 +71,11 @@ class NativeWindowGtk : public NativeWindow, virtual void UpdateDraggableRegions( const std::vector& regions) OVERRIDE; + // Overridden from content::WebContentsDelegate: + virtual void HandleKeyboardEvent( + content::WebContents*, + const content::NativeWebKeyboardEvent&) OVERRIDE; + // Overridden from ActiveWindowWatcherXObserver. virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; @@ -101,9 +106,6 @@ class NativeWindowGtk : public NativeWindow, CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnButtonPress, GdkEventButton*); - // Key press event callback. - CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnKeyPress, GdkEventKey*); - GtkWindow* window_; GtkWidget* vbox_; -- 2.7.4