]> khamidou — GitHub mirrors - electron.git/commitdiff
Move event type functions to a common event_util file
authorNishanth Shanmugham <nishanth.gerrard@gmail.com>
Mon, 27 Jul 2015 07:41:20 +0000 (00:41 -0700)
committerNishanth Shanmugham <nishanth.gerrard@gmail.com>
Mon, 27 Jul 2015 07:41:20 +0000 (00:41 -0700)
atom/browser/ui/cocoa/atom_menu_controller.mm
atom/browser/ui/event_util.h [new file with mode: 0644]
atom/browser/ui/event_util_mac.mm [new file with mode: 0644]
filenames.gypi

index 176f2db7e1453b5a15df04936440ccd4eb624842..fbfaea94110f9ec5d932d14e81d46bd84fe4d2f0 100644 (file)
@@ -4,6 +4,7 @@
 // found in the LICENSE file.
 
 #import "atom/browser/ui/cocoa/atom_menu_controller.h"
+#import "atom/browser/ui/event_util.h"
 
 #include "base/logging.h"
 #include "base/strings/sys_string_conversions.h"
 #include "ui/base/models/simple_menu_model.h"
 #include "ui/gfx/image/image.h"
 
-namespace {
-
-bool isLeftButtonEvent(NSEvent* event) {
-  NSEventType type = [event type];
-  return type == NSLeftMouseDown ||
-    type == NSLeftMouseDragged ||
-    type == NSLeftMouseUp;
-}
-
-bool isRightButtonEvent(NSEvent* event) {
-  NSEventType type = [event type];
-  return type == NSRightMouseDown ||
-    type == NSRightMouseDragged ||
-    type == NSRightMouseUp;
-}
-
-bool isMiddleButtonEvent(NSEvent* event) {
-  if ([event buttonNumber] != 2)
-    return false;
-
-  NSEventType type = [event type];
-  return type == NSOtherMouseDown ||
-    type == NSOtherMouseDragged ||
-    type == NSOtherMouseUp;
-}
-
-int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
-  int flags = 0;
-  flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
-  flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
-  flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
-  flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
-  flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
-  flags |= isLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
-  flags |= isRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
-  flags |= isMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
-  return flags;
-}
-
-// Retrieves a bitsum of ui::EventFlags from NSEvent.
-int EventFlagsFromNSEvent(NSEvent* event) {
-  NSUInteger modifiers = [event modifierFlags];
-  return EventFlagsFromNSEventWithModifiers(event, modifiers);
-}
-
-}  // namespace
-
 @interface AtomMenuController (Private)
 - (void)addSeparatorToMenu:(NSMenu*)menu
                    atIndex:(int)index;
@@ -246,7 +200,7 @@ int EventFlagsFromNSEvent(NSEvent* event) {
           [[sender representedObject] pointerValue]);
   DCHECK(model);
   if (model) {
-    int event_flags = EventFlagsFromNSEvent([NSApp currentEvent]);
+    int event_flags = event_util::EventFlagsFromNSEvent([NSApp currentEvent]);
     model->ActivatedAt(modelIndex, event_flags);
   }
 }
diff --git a/atom/browser/ui/event_util.h b/atom/browser/ui/event_util.h
new file mode 100644 (file)
index 0000000..59a624d
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef ATOM_BROWSER_UI_EVENT_UTIL_H_
+#define ATOM_BROWSER_UI_EVENT_UTIL_H_
+
+#import <Cocoa/Cocoa.h>
+
+namespace event_util {
+
+bool isLeftButtonEvent(NSEvent* event);
+bool isRightButtonEvent(NSEvent* event);
+bool isMiddleButtonEvent(NSEvent* event);
+
+// Retrieves a bitsum of ui::EventFlags from NSEvent.
+int EventFlagsFromNSEvent(NSEvent* event);
+
+} // namespace event_util
+
+#endif // ATOM_BROWSER_UI_EVENT_UTIL_H_
diff --git a/atom/browser/ui/event_util_mac.mm b/atom/browser/ui/event_util_mac.mm
new file mode 100644 (file)
index 0000000..5226b15
--- /dev/null
@@ -0,0 +1,47 @@
+#include "atom/browser/ui/event_util.h"
+#include "ui/base/accelerators/accelerator.h"
+
+namespace event_util {
+    bool isLeftButtonEvent(NSEvent* event) {
+      NSEventType type = [event type];
+      return type == NSLeftMouseDown ||
+        type == NSLeftMouseDragged ||
+        type == NSLeftMouseUp;
+    }
+
+    bool isRightButtonEvent(NSEvent* event) {
+      NSEventType type = [event type];
+      return type == NSRightMouseDown ||
+        type == NSRightMouseDragged ||
+        type == NSRightMouseUp;
+    }
+
+    bool isMiddleButtonEvent(NSEvent* event) {
+      if ([event buttonNumber] != 2)
+        return false;
+
+      NSEventType type = [event type];
+      return type == NSOtherMouseDown ||
+        type == NSOtherMouseDragged ||
+        type == NSOtherMouseUp;
+    }
+
+    int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
+      int flags = 0;
+      flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
+      flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
+      flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
+      flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
+      flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
+      flags |= isLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
+      flags |= isRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
+      flags |= isMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
+      return flags;
+    }
+
+    // Retrieves a bitsum of ui::EventFlags from NSEvent.
+    int EventFlagsFromNSEvent(NSEvent* event) {
+      NSUInteger modifiers = [event modifierFlags];
+      return EventFlagsFromNSEventWithModifiers(event, modifiers);
+    }
+} // namespace event_util
index ed51fc8fb47b820e1f6dd0083fcd2dbc29487a67..7d756e3beb7d2ae24d4377cdf616279a02e61ab0 100644 (file)
       'atom/browser/ui/cocoa/atom_menu_controller.mm',
       'atom/browser/ui/cocoa/event_processing_window.h',
       'atom/browser/ui/cocoa/event_processing_window.mm',
+      'atom/browser/ui/event_util.h',
+      'atom/browser/ui/event_util_mac.mm',
       'atom/browser/ui/file_dialog.h',
       'atom/browser/ui/file_dialog_gtk.cc',
       'atom/browser/ui/file_dialog_mac.mm',