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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #import "ui/events/cocoa/cocoa_event_utils.h"
6
7 #include "ui/events/event_constants.h"
8 #include "ui/events/event_utils.h"
9
10 namespace {
11
12 bool IsLeftButtonEvent(NSEvent* event) {
13 NSEventType type = [event type];
14 return type == NSLeftMouseDown || type == NSLeftMouseDragged ||
15 type == NSLeftMouseUp;
16 }
17
18 bool IsRightButtonEvent(NSEvent* event) {
19 NSEventType type = [event type];
20 return type == NSRightMouseDown || type == NSRightMouseDragged ||
21 type == NSRightMouseUp;
22 }
23
24 bool IsMiddleButtonEvent(NSEvent* event) {
25 if ([event buttonNumber] != 2)
26 return false;
27
28 NSEventType type = [event type];
29 return type == NSOtherMouseDown || type == NSOtherMouseDragged ||
30 type == NSOtherMouseUp;
31 }
32
33 } // namespace
34
35 namespace ui {
36
37 int EventFlagsFromNative(const base::NativeEvent& event) {
38 NSUInteger modifiers = [event modifierFlags];
39 return EventFlagsFromNSEventWithModifiers(event, modifiers);
40 }
41
42 int EventFlagsFromModifiers(NSUInteger modifiers) {
43 int flags = 0;
44 flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
45 flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
46 flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
47 flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
48 flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
49 return flags;
50 }
51
52 int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
53 int flags = EventFlagsFromModifiers(modifiers);
54 flags |= IsLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
55 flags |= IsRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
56 flags |= IsMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
57 return flags;
58 }
59
60 } // namespace ui
OLDNEW
« 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