diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-15 08:59:51 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-15 08:59:51 +0000 |
commit | 3b02cb018e84740ad105ad99c63abd1d0853fe58 (patch) | |
tree | 0e44ca4486e75427dcca4b3af455f40cc6e70060 /views | |
parent | 6df23c4e5e5cfdc831fed3939337d2a1caf0ac3d (diff) | |
download | chromium_src-3b02cb018e84740ad105ad99c63abd1d0853fe58.zip chromium_src-3b02cb018e84740ad105ad99c63abd1d0853fe58.tar.gz chromium_src-3b02cb018e84740ad105ad99c63abd1d0853fe58.tar.bz2 |
Forward unhandled KeyEvents to WidgetGtk's HandleKeyboardEvent() in native textfields.
BUG=chromium-os:6990,chromium-os:9738
TEST=Click on the omnibox's star. Press enter. Check that the bookmark bubble closes.
Review URL: http://codereview.chromium.org/5254011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69241 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 37 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.h | 4 |
2 files changed, 39 insertions, 2 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index b52a50b..e1c000c 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> #include "views/controls/textfield/native_textfield_gtk.h" @@ -14,6 +15,7 @@ #include "views/controls/textfield/gtk_views_entry.h" #include "views/controls/textfield/gtk_views_textview.h" #include "views/controls/textfield/textfield.h" +#include "views/widget/widget_gtk.h" namespace views { @@ -361,6 +363,34 @@ gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { } // static +gboolean NativeTextfieldGtk::OnActivateHandler( + GtkWidget* widget, + NativeTextfieldGtk* textfield) { + return textfield->OnActivate(); +} + +gboolean NativeTextfieldGtk::OnActivate() { + GdkEvent* event = gtk_get_current_event(); + if (!event || event->type != GDK_KEY_PRESS) + return false; + + GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); + gboolean handled = false; + + Textfield::Controller* controller = textfield_->GetController(); + if (controller) { + Textfield::Keystroke ks(key_event); + handled = controller->HandleKeystroke(textfield_, ks); + } + + WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); + if (!handled && widget) + handled = widget->HandleKeyboardEvent(key_event); + + return handled; +} + +// static gboolean NativeTextfieldGtk::OnChangedHandler( GtkWidget* widget, NativeTextfieldGtk* textfield) { @@ -407,8 +437,11 @@ void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { g_signal_connect(widget, "changed", G_CALLBACK(OnChangedHandler), this); } - g_signal_connect(widget, "key-press-event", - G_CALLBACK(OnKeyPressEventHandler), this); + g_signal_connect_after(widget, "key-press-event", + G_CALLBACK(OnKeyPressEventHandler), this); + // In order to properly trigger Accelerators bound to VKEY_RETURN, we need to + // send an event when the widget gets the activate signal. + g_signal_connect(widget, "activate", G_CALLBACK(OnActivateHandler), this); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h index 707af3d..7e1f7e8 100644 --- a/views/controls/textfield/native_textfield_gtk.h +++ b/views/controls/textfield/native_textfield_gtk.h @@ -63,6 +63,10 @@ class NativeTextfieldGtk : public NativeControlGtk, GdkEventKey* event, NativeTextfieldGtk* textfield); gboolean OnKeyPressEvent(GdkEventKey* event); + static gboolean OnActivateHandler( + GtkWidget* entry, + NativeTextfieldGtk* textfield); + gboolean OnActivate(); static gboolean OnChangedHandler( GtkWidget* entry, NativeTextfieldGtk* textfield); |