summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 18:56:08 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 18:56:08 +0000
commitc5874d55686f444954222f604bd79ff15d7a4325 (patch)
treeb7a6fae22d166b600743895b0288b0edaf5c1736 /views
parent64e8a5a584671b47f39e08e3c308b308da57eb94 (diff)
downloadchromium_src-c5874d55686f444954222f604bd79ff15d7a4325.zip
chromium_src-c5874d55686f444954222f604bd79ff15d7a4325.tar.gz
chromium_src-c5874d55686f444954222f604bd79ff15d7a4325.tar.bz2
* WidgetGtk::OnKeyPressed never called on window because the signal handler
was connected to the content, but the focus was set to GtkWindow by FocusManager. * Enable IgnoreKeyupForAccelerators for linux. BUG=40140 TEST=IgnoreKeyupForAccelerators shoud pass now on linux. Review URL: http://codereview.chromium.org/1575001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43506 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/focus/focus_manager_unittest.cc58
-rw-r--r--views/widget/widget_gtk.cc27
-rw-r--r--views/widget/widget_gtk.h3
3 files changed, 76 insertions, 12 deletions
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index 9d71ea1..cd89d5c 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -37,7 +37,8 @@
#if defined(OS_WIN)
#include "views/widget/widget_win.h"
#include "views/window/window_win.h"
-#else
+#elif defined(OS_LINUX)
+#include "base/keyboard_code_conversion_gtk.h"
#include "views/window/window_gtk.h"
#endif
@@ -105,7 +106,6 @@ const int kThumbnailSuperStarID = count++;
namespace views {
-
class FocusManagerTest : public testing::Test, public WindowDelegate {
public:
FocusManagerTest()
@@ -218,6 +218,46 @@ class FocusManagerTest : public testing::Test, public WindowDelegate {
void PostKeyUp(base::KeyboardCode key_code) {
::PostMessage(window_->GetNativeWindow(), WM_KEYUP, key_code, 0);
}
+#elif defined(OS_LINUX)
+ void PostKeyDown(base::KeyboardCode key_code) {
+ PostKeyEvent(key_code, true);
+ }
+
+ void PostKeyUp(base::KeyboardCode key_code) {
+ PostKeyEvent(key_code, false);
+ }
+
+ void PostKeyEvent(base::KeyboardCode key_code, bool pressed) {
+ int keyval = GdkKeyCodeForWindowsKeyCode(key_code, false);
+ GdkKeymapKey* keys;
+ gint n_keys;
+ gdk_keymap_get_entries_for_keyval(
+ gdk_keymap_get_default(),
+ keyval,
+ &keys,
+ &n_keys);
+ GdkEvent* event = gdk_event_new(pressed ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
+ GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event);
+ int modifier = 0;
+ if (pressed)
+ key_event->state = modifier | GDK_KEY_PRESS_MASK;
+ else
+ key_event->state = modifier | GDK_KEY_RELEASE_MASK;
+
+ key_event->window = GTK_WIDGET(window_->GetNativeWindow())->window;
+ DCHECK(key_event->window != NULL);
+ g_object_ref(key_event->window);
+ key_event->send_event = true;
+ key_event->time = GDK_CURRENT_TIME;
+ key_event->keyval = keyval;
+ key_event->hardware_keycode = keys[0].keycode;
+ key_event->group = keys[0].group;
+
+ g_free(keys);
+
+ gdk_event_put(event);
+ gdk_event_free(event);
+ }
#endif
private:
@@ -1224,7 +1264,6 @@ class MessageTrackingView : public View {
DISALLOW_COPY_AND_ASSIGN(MessageTrackingView);
};
-#if defined(OS_WIN)
// Tests that the keyup messages are eaten for accelerators.
TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) {
FocusManager* focus_manager = GetFocusManager();
@@ -1241,9 +1280,9 @@ TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) {
MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
MessageLoopForUI::current()->Run(&accelerator_handler);
// Make sure we get a key-up and key-down.
- ASSERT_EQ(1, mtv->keys_pressed().size());
+ ASSERT_EQ(1U, mtv->keys_pressed().size());
EXPECT_EQ(base::VKEY_9, mtv->keys_pressed().at(0));
- ASSERT_EQ(1, mtv->keys_released().size());
+ ASSERT_EQ(1U, mtv->keys_released().size());
EXPECT_EQ(base::VKEY_9, mtv->keys_released().at(0));
EXPECT_FALSE(mtv->accelerator_pressed());
mtv->Reset();
@@ -1260,13 +1299,13 @@ TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) {
MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
MessageLoopForUI::current()->Run(&accelerator_handler);
// Make sure we get a key-up and key-down.
- ASSERT_EQ(5, mtv->keys_pressed().size());
+ ASSERT_EQ(5U, mtv->keys_pressed().size());
EXPECT_EQ(base::VKEY_9, mtv->keys_pressed().at(0));
EXPECT_EQ(base::VKEY_9, mtv->keys_pressed().at(1));
EXPECT_EQ(base::VKEY_8, mtv->keys_pressed().at(2));
EXPECT_EQ(base::VKEY_9, mtv->keys_pressed().at(3));
EXPECT_EQ(base::VKEY_7, mtv->keys_pressed().at(4));
- ASSERT_EQ(3, mtv->keys_released().size());
+ ASSERT_EQ(3U, mtv->keys_released().size());
EXPECT_EQ(base::VKEY_9, mtv->keys_released().at(0));
EXPECT_EQ(base::VKEY_7, mtv->keys_released().at(1));
EXPECT_EQ(base::VKEY_8, mtv->keys_released().at(2));
@@ -1293,12 +1332,15 @@ TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) {
PostKeyUp(base::VKEY_0);
MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
MessageLoopForUI::current()->Run(&accelerator_handler);
+#if defined(OS_WIN)
+ // Linux eats only last accelerator's release event.
+ // See http://crbug.com/23383 for details.
EXPECT_TRUE(mtv->keys_pressed().empty());
EXPECT_TRUE(mtv->keys_released().empty());
+#endif
EXPECT_TRUE(mtv->accelerator_pressed());
mtv->Reset();
}
-#endif
#if defined(OS_WIN)
// Test that the focus manager is created successfully for the first view
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 6ad0c4c..a057382 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -337,10 +337,6 @@ void WidgetGtk::Init(GtkWidget* parent,
G_CALLBACK(&OnGrabBrokeEventThunk), this);
g_signal_connect(window_contents_, "grab_notify",
G_CALLBACK(&OnGrabNotifyThunk), this);
- g_signal_connect(window_contents_, "key_press_event",
- G_CALLBACK(&OnKeyPressThunk), this);
- g_signal_connect(window_contents_, "key_release_event",
- G_CALLBACK(&OnKeyReleaseThunk), this);
g_signal_connect(window_contents_, "scroll_event",
G_CALLBACK(&OnScrollThunk), this);
g_signal_connect(window_contents_, "visibility_notify_event",
@@ -359,6 +355,19 @@ void WidgetGtk::Init(GtkWidget* parent,
G_CALLBACK(&OnShowThunk), this);
g_signal_connect(widget_, "hide",
G_CALLBACK(&OnHideThunk), this);
+
+ // Views/FocusManager (re)sets the focus to the root window,
+ // so we need to connect signal handlers to the gtk window.
+ // See views::Views::Focus and views::FocusManager::ClearNativeFocus
+ // for more details.
+ g_signal_connect(widget_, "key_press_event",
+ G_CALLBACK(&OnKeyPressThunk), this);
+ g_signal_connect(widget_, "key_release_event",
+ G_CALLBACK(&OnKeyReleaseThunk), this);
+ g_signal_connect(window_contents_, "key_press_event",
+ G_CALLBACK(&OnKeyPressToFailThunk), this);
+ g_signal_connect(window_contents_, "key_release_event",
+ G_CALLBACK(&OnKeyReleaseToFailThunk), this);
if (transparent_) {
g_signal_connect(widget_, "expose_event",
G_CALLBACK(&OnWindowPaintThunk), this);
@@ -905,6 +914,16 @@ gboolean WidgetGtk::OnKeyRelease(GtkWidget* widget, GdkEventKey* event) {
return root_view_->ProcessKeyEvent(key_event);
}
+gboolean WidgetGtk::OnKeyPressToFail(GtkWidget* widget, GdkEventKey* event) {
+ NOTREACHED() << "Unexpected key press event on window_contents";
+ return false;
+}
+
+gboolean WidgetGtk::OnKeyReleaseToFail(GtkWidget* widget, GdkEventKey* event) {
+ NOTREACHED() << "Unexpected key release event on window_contents";
+ return false;
+}
+
gboolean WidgetGtk::OnQueryTooltip(GtkWidget* widget,
gint x,
gint y,
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 075d873..c621fae 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -261,6 +261,9 @@ class WidgetGtk
CHROMEGTK_CALLBACK_0(WidgetGtk, void, OnShow);
CHROMEGTK_CALLBACK_0(WidgetGtk, void, OnHide);
+ CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnKeyPressToFail, GdkEventKey*);
+ CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnKeyReleaseToFail, GdkEventKey*);
+
void set_mouse_down(bool mouse_down) { is_mouse_down_ = mouse_down; }
// Do we own the mouse grab?