]> khamidou — GitHub mirrors - electron.git/commitdiff
gtk: Add event_utils from Chromium.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 14 Mar 2014 12:23:17 +0000 (20:23 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 14 Mar 2014 12:23:17 +0000 (20:23 +0800)
atom.gyp
browser/ui/gtk/event_utils.cc [new file with mode: 0644]
browser/ui/gtk/event_utils.h [new file with mode: 0644]

index b2f65d5d32d824f66751c0e37d83e1b398bfc33e..99f7a795905d430ea2e865c54862100d9c913467 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'browser/ui/gtk/gtk_util.h',
       'browser/ui/gtk/gtk_window_util.cc',
       'browser/ui/gtk/gtk_window_util.h',
+      'browser/ui/gtk/event_utils.cc',
+      'browser/ui/gtk/event_utils.h',
       'browser/ui/message_box.h',
       'browser/ui/message_box_gtk.cc',
       'browser/ui/message_box_mac.mm',
diff --git a/browser/ui/gtk/event_utils.cc b/browser/ui/gtk/event_utils.cc
new file mode 100644 (file)
index 0000000..c21e154
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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 "browser/ui/gtk/event_utils.h"
+
+#include "base/logging.h"
+#include "ui/base/window_open_disposition.h"
+#include "ui/events/event_constants.h"
+
+namespace event_utils {
+
+int EventFlagsFromGdkState(guint state) {
+  int flags = ui::EF_NONE;
+  flags |= (state & GDK_LOCK_MASK) ? ui::EF_CAPS_LOCK_DOWN : ui::EF_NONE;
+  flags |= (state & GDK_CONTROL_MASK) ? ui::EF_CONTROL_DOWN : ui::EF_NONE;
+  flags |= (state & GDK_SHIFT_MASK) ? ui::EF_SHIFT_DOWN : ui::EF_NONE;
+  flags |= (state & GDK_MOD1_MASK) ? ui::EF_ALT_DOWN : ui::EF_NONE;
+  flags |= (state & GDK_BUTTON1_MASK) ? ui::EF_LEFT_MOUSE_BUTTON : ui::EF_NONE;
+  flags |= (state & GDK_BUTTON2_MASK) ? ui::EF_MIDDLE_MOUSE_BUTTON
+                                      : ui::EF_NONE;
+  flags |= (state & GDK_BUTTON3_MASK) ? ui::EF_RIGHT_MOUSE_BUTTON : ui::EF_NONE;
+  return flags;
+}
+
+// TODO(shinyak) This function will be removed after refactoring.
+WindowOpenDisposition DispositionFromGdkState(guint state) {
+  int event_flags = EventFlagsFromGdkState(state);
+  return ui::DispositionFromEventFlags(event_flags);
+}
+
+WindowOpenDisposition DispositionForCurrentButtonPressEvent() {
+  GdkEvent* event = gtk_get_current_event();
+  if (!event) {
+    NOTREACHED();
+    return NEW_FOREGROUND_TAB;
+  }
+
+  guint state = event->button.state;
+  gdk_event_free(event);
+  return DispositionFromGdkState(state);
+}
+
+}  // namespace event_utils
diff --git a/browser/ui/gtk/event_utils.h b/browser/ui/gtk/event_utils.h
new file mode 100644 (file)
index 0000000..135075c
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (c) 2012 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.
+
+#ifndef CHROME_BROWSER_UI_GTK_EVENT_UTILS_H_
+#define CHROME_BROWSER_UI_GTK_EVENT_UTILS_H_
+
+#include <gtk/gtk.h>
+
+#include "ui/base/window_open_disposition.h"
+
+namespace event_utils {
+
+// Translates event flags into plaform independent event flags.
+int EventFlagsFromGdkState(guint state);
+
+// Translates GdkEvent state into what kind of disposition they represent.
+// For example, a middle click would mean to open a background tab.
+WindowOpenDisposition DispositionFromGdkState(guint state);
+
+// Get the window open disposition from the state in gtk_get_current_event().
+// This is designed to be called inside a "clicked" event handler. It is an
+// error to call it when gtk_get_current_event() won't return a GdkEventButton*.
+WindowOpenDisposition DispositionForCurrentButtonPressEvent();
+
+}  // namespace event_utils
+
+#endif  // CHROME_BROWSER_UI_GTK_EVENT_UTILS_H_
\ No newline at end of file