1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ui/events/cocoa/cocoa_event_utils.h"
7 #include "ui/events/event_constants.h"
8 #include "ui/events/event_utils.h"
12 bool IsLeftButtonEvent(NSEvent* event) {
13 NSEventType type = [event type];
14 return type == NSLeftMouseDown || type == NSLeftMouseDragged ||
15 type == NSLeftMouseUp;
18 bool IsRightButtonEvent(NSEvent* event) {
19 NSEventType type = [event type];
20 return type == NSRightMouseDown || type == NSRightMouseDragged ||
21 type == NSRightMouseUp;
24 bool IsMiddleButtonEvent(NSEvent* event) {
25 if ([event buttonNumber] != 2)
28 NSEventType type = [event type];
29 return type == NSOtherMouseDown || type == NSOtherMouseDragged ||
30 type == NSOtherMouseUp;
37 int EventFlagsFromModifiers(NSUInteger modifiers) {
39 flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
40 flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
41 flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
42 flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
43 flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
47 int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
48 int flags = EventFlagsFromModifiers(modifiers);
49 flags |= IsLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
50 flags |= IsRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
51 flags |= IsMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;