]> khamidou — GitHub mirrors - electron.git/commitdiff
Use the global_shortcut_listener_x11 from chrome36.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 4 Aug 2014 12:52:42 +0000 (12:52 +0000)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 4 Aug 2014 12:52:42 +0000 (12:52 +0000)
This fixes compilation error on Linux.

chromium_src/chrome/browser/extensions/global_shortcut_listener_x11.cc
chromium_src/chrome/browser/extensions/global_shortcut_listener_x11.h

index 556bd707a54aa4838c2faa3e0ad9aa61cdb2745c..5a3ad1a7a6cec33d98611d1d46dbbad141412f35 100644 (file)
@@ -7,15 +7,10 @@
 #include "content/public/browser/browser_thread.h"
 #include "ui/base/accelerators/accelerator.h"
 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
+#include "ui/events/platform/x11/x11_event_source.h"
 #include "ui/gfx/x/x11_error_tracker.h"
 #include "ui/gfx/x/x11_types.h"
 
-#if defined(TOOLKIT_GTK)
-#include <gdk/gdkx.h>
-#else
-#include "base/message_loop/message_pump_x11.h"
-#endif
-
 using content::BrowserThread;
 
 namespace {
@@ -72,13 +67,8 @@ void GlobalShortcutListenerX11::StartListening() {
   DCHECK(!is_listening_);  // Don't start twice.
   DCHECK(!registered_hot_keys_.empty());  // Also don't start if no hotkey is
                                           // registered.
-#if defined(TOOLKIT_GTK)
-  gdk_window_add_filter(gdk_get_default_root_window(),
-                        &GlobalShortcutListenerX11::OnXEventThunk,
-                        this);
-#else
-  base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this);
-#endif
+
+  ui::X11EventSource::GetInstance()->AddPlatformEventDispatcher(this);
 
   is_listening_ = true;
 }
@@ -88,25 +78,23 @@ void GlobalShortcutListenerX11::StopListening() {
   DCHECK(registered_hot_keys_.empty());  // Make sure the set is clean before
                                          // ending.
 
-#if defined(TOOLKIT_GTK)
-  gdk_window_remove_filter(NULL,
-                           &GlobalShortcutListenerX11::OnXEventThunk,
-                           this);
-#else
-  base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this);
-#endif
+  ui::X11EventSource::GetInstance()->RemovePlatformEventDispatcher(this);
 
   is_listening_ = false;
 }
 
-#if !defined(TOOLKIT_GTK)
-uint32_t GlobalShortcutListenerX11::Dispatch(const base::NativeEvent& event) {
-  if (event->type == KeyPress)
-    OnXKeyPressEvent(event);
+bool GlobalShortcutListenerX11::CanDispatchEvent(
+    const ui::PlatformEvent& event) {
+  return event->type == KeyPress;
+}
+
+uint32_t GlobalShortcutListenerX11::DispatchEvent(
+    const ui::PlatformEvent& event) {
+  CHECK_EQ(KeyPress, event->type);
+  OnXKeyPressEvent(event);
 
-  return POST_DISPATCH_NONE;
+  return ui::POST_DISPATCH_NONE;
 }
-#endif
 
 bool GlobalShortcutListenerX11::RegisterAcceleratorImpl(
     const ui::Accelerator& accelerator) {
@@ -154,17 +142,6 @@ void GlobalShortcutListenerX11::UnregisterAcceleratorImpl(
   registered_hot_keys_.erase(accelerator);
 }
 
-#if defined(TOOLKIT_GTK)
-GdkFilterReturn GlobalShortcutListenerX11::OnXEvent(GdkXEvent* gdk_x_event,
-                                                    GdkEvent* gdk_event) {
-  XEvent* x_event = static_cast<XEvent*>(gdk_x_event);
-  if (x_event->type == KeyPress)
-    OnXKeyPressEvent(x_event);
-
-  return GDK_FILTER_CONTINUE;
-}
-#endif
-
 void GlobalShortcutListenerX11::OnXKeyPressEvent(::XEvent* x_event) {
   DCHECK(x_event->type == KeyPress);
   int modifiers = 0;
index 69ebca1474395c96a52967a039fd38e8641eaa7a..cc21ccb7454e6540b555367bb207136348a31fb8 100644 (file)
@@ -8,33 +8,23 @@
 #include <X11/Xlib.h>
 #include <set>
 
-#include "base/message_loop/message_pump_dispatcher.h"
 #include "chrome/browser/extensions/global_shortcut_listener.h"
-
-#if defined(TOOLKIT_GTK)
-#include <gtk/gtk.h>
-#include "ui/base/gtk/gtk_signal.h"
-#endif  // defined(TOOLKIT_GTK)
+#include "ui/events/platform/platform_event_dispatcher.h"
 
 namespace extensions {
 
 // X11-specific implementation of the GlobalShortcutListener class that
 // listens for global shortcuts. Handles basic keyboard intercepting and
 // forwards its output to the base class for processing.
-class GlobalShortcutListenerX11
-    :
-#if !defined(TOOLKIT_GTK)
-      public base::MessagePumpDispatcher,
-#endif
-      public GlobalShortcutListener {
+class GlobalShortcutListenerX11 : public GlobalShortcutListener,
+                                  public ui::PlatformEventDispatcher {
  public:
   GlobalShortcutListenerX11();
   virtual ~GlobalShortcutListenerX11();
 
-#if !defined(TOOLKIT_GTK)
-  // base::MessagePumpDispatcher implementation.
-  virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE;
-#endif
+  // ui::PlatformEventDispatcher implementation.
+  virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
+  virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
 
  private:
   // GlobalShortcutListener implementation.
@@ -45,12 +35,6 @@ class GlobalShortcutListenerX11
   virtual void UnregisterAcceleratorImpl(
       const ui::Accelerator& accelerator) OVERRIDE;
 
-#if defined(TOOLKIT_GTK)
-  // Callback for XEvents of the default root window.
-  CHROMEG_CALLBACK_1(GlobalShortcutListenerX11, GdkFilterReturn,
-                     OnXEvent, GdkXEvent*, GdkEvent*);
-#endif
-
   // Invoked when a global shortcut is pressed.
   void OnXKeyPressEvent(::XEvent* x_event);