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

Side by Side Diff: ui/base/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/base/cocoa/cocoa_event_utils.h ('k') | ui/base/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/base/cocoa/cocoa_event_utils.h"
6
7 #include "ui/base/window_open_disposition.h"
8 #include "ui/events/event_constants.h"
9
10 namespace {
11
12 bool isLeftButtonEvent(NSEvent* event) {
13 NSEventType type = [event type];
14 return type == NSLeftMouseDown ||
15 type == NSLeftMouseDragged ||
16 type == NSLeftMouseUp;
17 }
18
19 bool isRightButtonEvent(NSEvent* event) {
20 NSEventType type = [event type];
21 return type == NSRightMouseDown ||
22 type == NSRightMouseDragged ||
23 type == NSRightMouseUp;
24 }
25
26 bool isMiddleButtonEvent(NSEvent* event) {
27 if ([event buttonNumber] != 2)
28 return false;
29
30 NSEventType type = [event type];
31 return type == NSOtherMouseDown ||
32 type == NSOtherMouseDragged ||
33 type == NSOtherMouseUp;
34 }
35
36 } // namespace
37
38 namespace ui {
39
40 // Retrieves a bitsum of ui::EventFlags from NSEvent.
41 int EventFlagsFromNSEvent(NSEvent* event) {
42 NSUInteger modifiers = [event modifierFlags];
43 return EventFlagsFromNSEventWithModifiers(event, modifiers);
44 }
45
46 int EventFlagsFromModifiers(NSUInteger modifiers) {
47 int flags = 0;
48 flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
49 flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
50 flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
51 flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
52 flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
53 return flags;
54 }
55
56 int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
57 int flags = EventFlagsFromModifiers(modifiers);
58 flags |= isLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
59 flags |= isRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
60 flags |= isMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
61 return flags;
62 }
63
64 WindowOpenDisposition WindowOpenDispositionFromNSEvent(NSEvent* event) {
65 NSUInteger modifiers = [event modifierFlags];
66 return WindowOpenDispositionFromNSEventWithFlags(event, modifiers);
67 }
68
69 WindowOpenDisposition WindowOpenDispositionFromNSEventWithFlags(
70 NSEvent* event, NSUInteger modifiers) {
71 int event_flags = EventFlagsFromNSEventWithModifiers(event, modifiers);
72 return ui::DispositionFromEventFlags(event_flags);
73 }
74
75 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/cocoa/cocoa_event_utils.h ('k') | ui/base/cocoa/cocoa_event_utils_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698