Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: views/focus/accelerator_handler_gtk.cc

Issue 159046: Implementing accelerators for Linux toolkit_views (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/focus/accelerator_handler.h ('k') | views/focus/accelerator_handler_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/focus/accelerator_handler_gtk.cc
===================================================================
--- views/focus/accelerator_handler_gtk.cc (revision 0)
+++ views/focus/accelerator_handler_gtk.cc (revision 0)
@@ -0,0 +1,61 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <gtk/gtk.h>
+
+#include "views/focus/accelerator_handler.h"
+
+#include "views/focus/focus_manager.h"
+#include "views/widget/widget_gtk.h"
+#include "views/window/window_gtk.h"
+
+namespace views {
+
+AcceleratorHandler::AcceleratorHandler() : last_key_pressed_(0) {
+}
+
+bool AcceleratorHandler::Dispatch(GdkEvent* event) {
+ if (event->type != GDK_KEY_PRESS && event->type != GDK_KEY_RELEASE) {
+ gtk_main_do_event(event);
+ return true;
+ }
+
+ GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event);
+ // Let's retrieve the focus manager for the GdkWindow.
+ GdkWindow* window = gdk_window_get_toplevel(key_event->window);
+ gpointer ptr;
+ gdk_window_get_user_data(window, &ptr);
+ DCHECK(ptr); // The top-level window is expected to always be associated
+ // with the top-level gtk widget.
+ WindowGtk* widget =
+ WidgetGtk::GetWindowForNative(reinterpret_cast<GtkWidget*>(ptr));
+ FocusManager* focus_manager = widget->GetFocusManager();
+ if (!focus_manager) {
+ NOTREACHED();
+ return true;
+ }
+
+ if (event->type == GDK_KEY_PRESS) {
+ KeyEvent view_key_event(key_event, true);
+ // FocusManager::OnKeyPressed and OnKeyReleased return false if this
+ // message has been consumed and should not be propagated further.
+ if (!focus_manager->OnKeyEvent(view_key_event)) {
+ last_key_pressed_ = key_event->keyval;
+ return true;
+ }
+ }
+
+ // Key release, make sure to filter-out the key release for key press consumed
+ // as accelerators to avoid unpaired key release.
+ if (event->type == GDK_KEY_RELEASE &&
+ key_event->keyval == last_key_pressed_) {
+ last_key_pressed_ = 0;
+ return true;
+ }
+
+ gtk_main_do_event(event);
+ return true;
+}
+
+} // namespace views
Property changes on: views/focus/accelerator_handler_gtk.cc
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « views/focus/accelerator_handler.h ('k') | views/focus/accelerator_handler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698