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

Unified Diff: ui/events/cocoa/cocoa_event_utils.mm

Issue 160083003: Split cocoa_event_utils in two parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: still works? Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/cocoa/cocoa_event_utils.h ('k') | ui/events/cocoa/cocoa_event_utils_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/cocoa/cocoa_event_utils.mm
diff --git a/ui/events/cocoa/cocoa_event_utils.mm b/ui/events/cocoa/cocoa_event_utils.mm
new file mode 100644
index 0000000000000000000000000000000000000000..9d156f6e78b5464af3e9882a88db01fe90c42403
--- /dev/null
+++ b/ui/events/cocoa/cocoa_event_utils.mm
@@ -0,0 +1,60 @@
+// Copyright 2013 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.
+
+#import "ui/events/cocoa/cocoa_event_utils.h"
+
+#include "ui/events/event_constants.h"
+#include "ui/events/event_utils.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;
+}
+
+} // namespace
+
+namespace ui {
+
+int EventFlagsFromNative(const base::NativeEvent& event) {
+ NSUInteger modifiers = [event modifierFlags];
+ return EventFlagsFromNSEventWithModifiers(event, modifiers);
+}
+
+int EventFlagsFromModifiers(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;
+ return flags;
+}
+
+int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
+ int flags = EventFlagsFromModifiers(modifiers);
+ 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;
+}
+
+} // namespace ui
« no previous file with comments | « ui/events/cocoa/cocoa_event_utils.h ('k') | ui/events/cocoa/cocoa_event_utils_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698