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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/focus/accelerator_handler.h ('k') | views/focus/accelerator_handler_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gtk/gtk.h>
6
7 #include "views/focus/accelerator_handler.h"
8
9 #include "views/focus/focus_manager.h"
10 #include "views/widget/widget_gtk.h"
11 #include "views/window/window_gtk.h"
12
13 namespace views {
14
15 AcceleratorHandler::AcceleratorHandler() : last_key_pressed_(0) {
16 }
17
18 bool AcceleratorHandler::Dispatch(GdkEvent* event) {
19 if (event->type != GDK_KEY_PRESS && event->type != GDK_KEY_RELEASE) {
20 gtk_main_do_event(event);
21 return true;
22 }
23
24 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event);
25 // Let's retrieve the focus manager for the GdkWindow.
26 GdkWindow* window = gdk_window_get_toplevel(key_event->window);
27 gpointer ptr;
28 gdk_window_get_user_data(window, &ptr);
29 DCHECK(ptr); // The top-level window is expected to always be associated
30 // with the top-level gtk widget.
31 WindowGtk* widget =
32 WidgetGtk::GetWindowForNative(reinterpret_cast<GtkWidget*>(ptr));
33 FocusManager* focus_manager = widget->GetFocusManager();
34 if (!focus_manager) {
35 NOTREACHED();
36 return true;
37 }
38
39 if (event->type == GDK_KEY_PRESS) {
40 KeyEvent view_key_event(key_event, true);
41 // FocusManager::OnKeyPressed and OnKeyReleased return false if this
42 // message has been consumed and should not be propagated further.
43 if (!focus_manager->OnKeyEvent(view_key_event)) {
44 last_key_pressed_ = key_event->keyval;
45 return true;
46 }
47 }
48
49 // Key release, make sure to filter-out the key release for key press consumed
50 // as accelerators to avoid unpaired key release.
51 if (event->type == GDK_KEY_RELEASE &&
52 key_event->keyval == last_key_pressed_) {
53 last_key_pressed_ = 0;
54 return true;
55 }
56
57 gtk_main_do_event(event);
58 return true;
59 }
60
61 } // namespace views
OLDNEW
« 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