OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ |
7 | 7 |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "chrome/browser/extensions/global_shortcut_listener.h" | 11 #include "chrome/browser/extensions/global_shortcut_listener.h" |
12 | |
13 #if defined(TOOLKIT_GTK) | |
14 #include <gtk/gtk.h> | |
15 #include "ui/base/gtk/gtk_signal.h" | |
16 #else | |
17 #include "ui/events/platform/platform_event_dispatcher.h" | 12 #include "ui/events/platform/platform_event_dispatcher.h" |
18 #endif // defined(TOOLKIT_GTK) | |
19 | 13 |
20 namespace extensions { | 14 namespace extensions { |
21 | 15 |
22 // X11-specific implementation of the GlobalShortcutListener class that | 16 // X11-specific implementation of the GlobalShortcutListener class that |
23 // listens for global shortcuts. Handles basic keyboard intercepting and | 17 // listens for global shortcuts. Handles basic keyboard intercepting and |
24 // forwards its output to the base class for processing. | 18 // forwards its output to the base class for processing. |
25 class GlobalShortcutListenerX11 : public GlobalShortcutListener | 19 class GlobalShortcutListenerX11 : public GlobalShortcutListener, |
26 #if !defined(TOOLKIT_GTK) | 20 public ui::PlatformEventDispatcher { |
27 , | |
28 public ui::PlatformEventDispatcher | |
29 #endif | |
30 { | |
31 public: | 21 public: |
32 GlobalShortcutListenerX11(); | 22 GlobalShortcutListenerX11(); |
33 virtual ~GlobalShortcutListenerX11(); | 23 virtual ~GlobalShortcutListenerX11(); |
34 | 24 |
35 #if !defined(TOOLKIT_GTK) | |
36 // ui::PlatformEventDispatcher implementation. | 25 // ui::PlatformEventDispatcher implementation. |
37 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; | 26 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; |
38 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; | 27 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; |
39 #endif | |
40 | 28 |
41 private: | 29 private: |
42 // GlobalShortcutListener implementation. | 30 // GlobalShortcutListener implementation. |
43 virtual void StartListening() OVERRIDE; | 31 virtual void StartListening() OVERRIDE; |
44 virtual void StopListening() OVERRIDE; | 32 virtual void StopListening() OVERRIDE; |
45 virtual bool RegisterAcceleratorImpl( | 33 virtual bool RegisterAcceleratorImpl( |
46 const ui::Accelerator& accelerator) OVERRIDE; | 34 const ui::Accelerator& accelerator) OVERRIDE; |
47 virtual void UnregisterAcceleratorImpl( | 35 virtual void UnregisterAcceleratorImpl( |
48 const ui::Accelerator& accelerator) OVERRIDE; | 36 const ui::Accelerator& accelerator) OVERRIDE; |
49 | 37 |
50 #if defined(TOOLKIT_GTK) | |
51 // Callback for XEvents of the default root window. | |
52 CHROMEG_CALLBACK_1(GlobalShortcutListenerX11, GdkFilterReturn, | |
53 OnXEvent, GdkXEvent*, GdkEvent*); | |
54 #endif | |
55 | |
56 // Invoked when a global shortcut is pressed. | 38 // Invoked when a global shortcut is pressed. |
57 void OnXKeyPressEvent(::XEvent* x_event); | 39 void OnXKeyPressEvent(::XEvent* x_event); |
58 | 40 |
59 // Whether this object is listening for global shortcuts. | 41 // Whether this object is listening for global shortcuts. |
60 bool is_listening_; | 42 bool is_listening_; |
61 | 43 |
62 // The x11 default display and the native root window. | 44 // The x11 default display and the native root window. |
63 ::Display* x_display_; | 45 ::Display* x_display_; |
64 ::Window x_root_window_; | 46 ::Window x_root_window_; |
65 | 47 |
66 // A set of registered accelerators. | 48 // A set of registered accelerators. |
67 typedef std::set<ui::Accelerator> RegisteredHotKeys; | 49 typedef std::set<ui::Accelerator> RegisteredHotKeys; |
68 RegisteredHotKeys registered_hot_keys_; | 50 RegisteredHotKeys registered_hot_keys_; |
69 | 51 |
70 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerX11); | 52 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerX11); |
71 }; | 53 }; |
72 | 54 |
73 } // namespace extensions | 55 } // namespace extensions |
74 | 56 |
75 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ | 57 #endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ |
OLD | NEW |