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

Side by Side Diff: ui/events/cocoa/events_mac.mm

Issue 251493002: MacViews: Implement basic NSEvent -> ui::Event conversion for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 7 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_unittest.mm ('k') | ui/events/cocoa/events_mac_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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/event_utils.h"
6
7 #include <Cocoa/Cocoa.h>
8
5 #include "base/logging.h" 9 #include "base/logging.h"
6 #include "base/time/time.h" 10 #include "base/time/time.h"
7 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "ui/events/cocoa/cocoa_event_utils.h"
8 #include "ui/events/event_utils.h" 13 #include "ui/events/event_utils.h"
14 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
9 #include "ui/gfx/point.h" 15 #include "ui/gfx/point.h"
10 #include "ui/gfx/vector2d.h" 16 #include "ui/gfx/vector2d.h"
11 17
12 namespace ui { 18 namespace ui {
13 19
14 // Stub implementations of platform-specific methods in events_util.h, built
15 // on platform sthat currently do not have a complete implementation of events.
16
17 void UpdateDeviceList() { 20 void UpdateDeviceList() {
18 NOTIMPLEMENTED(); 21 NOTIMPLEMENTED();
19 } 22 }
20 23
21 EventType EventTypeFromNative(const base::NativeEvent& native_event) { 24 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
22 NOTIMPLEMENTED(); 25 NSEventType type = [native_event type];
26 switch (type) {
27 case NSKeyDown:
28 return ET_KEY_PRESSED;
29 case NSKeyUp:
30 return ET_KEY_RELEASED;
31 case NSLeftMouseDown:
32 case NSRightMouseDown:
33 case NSOtherMouseDown:
34 return ET_MOUSE_PRESSED;
35 case NSLeftMouseUp:
36 case NSRightMouseUp:
37 case NSOtherMouseUp:
38 return ET_MOUSE_RELEASED;
39 case NSLeftMouseDragged:
40 case NSRightMouseDragged:
41 case NSOtherMouseDragged:
42 return ET_MOUSE_DRAGGED;
43 case NSMouseMoved:
44 case NSScrollWheel:
45 return ET_MOUSEWHEEL;
46 case NSMouseEntered:
47 return ET_MOUSE_ENTERED;
48 case NSMouseExited:
49 return ET_MOUSE_EXITED;
50 case NSEventTypeSwipe:
51 return ET_SCROLL_FLING_START;
52 case NSFlagsChanged:
53 case NSAppKitDefined:
54 case NSSystemDefined:
55 case NSApplicationDefined:
56 case NSPeriodic:
57 case NSCursorUpdate:
58 case NSTabletPoint:
59 case NSTabletProximity:
60 case NSEventTypeGesture:
61 case NSEventTypeMagnify:
62 case NSEventTypeRotate:
63 case NSEventTypeBeginGesture:
64 case NSEventTypeEndGesture:
65 NOTIMPLEMENTED() << type;
66 break;
67 default:
68 NOTIMPLEMENTED() << type;
69 break;
70 }
23 return ET_UNKNOWN; 71 return ET_UNKNOWN;
24 } 72 }
25 73
26 #if !defined(OS_MACOSX) 74 int EventFlagsFromNative(const base::NativeEvent& event) {
27 int EventFlagsFromNative(const base::NativeEvent& native_event) { 75 NSUInteger modifiers = [event modifierFlags];
28 NOTIMPLEMENTED(); 76 return EventFlagsFromNSEventWithModifiers(event, modifiers);
29 return 0;
30 } 77 }
31 #endif
32 78
33 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { 79 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
34 NOTIMPLEMENTED(); 80 NSTimeInterval since_system_startup = [native_event timestamp];
35 return base::TimeDelta(); 81 // Truncate to extract seconds before doing floating point arithmetic.
82 int64_t seconds = since_system_startup;
83 since_system_startup -= seconds;
84 int64_t microseconds = since_system_startup * 1000000;
85 return base::TimeDelta::FromSeconds(seconds) +
86 base::TimeDelta::FromMicroseconds(microseconds);
36 } 87 }
37 88
38 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { 89 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
39 NOTIMPLEMENTED(); 90 if (![native_event window]) {
40 return gfx::Point(); 91 NOTIMPLEMENTED(); // Point will be in screen coordinates.
92 return gfx::Point();
93 }
94 NSPoint location = [native_event locationInWindow];
95 return gfx::Point(location.x,
96 NSHeight([[native_event window] frame]) - location.y);
41 } 97 }
42 98
43 gfx::Point EventSystemLocationFromNative( 99 gfx::Point EventSystemLocationFromNative(
44 const base::NativeEvent& native_event) { 100 const base::NativeEvent& native_event) {
45 NOTIMPLEMENTED(); 101 NOTIMPLEMENTED();
46 return gfx::Point(); 102 return gfx::Point();
47 } 103 }
48 104
49 int EventButtonFromNative(const base::NativeEvent& native_event) { 105 int EventButtonFromNative(const base::NativeEvent& native_event) {
50 NOTIMPLEMENTED(); 106 NOTIMPLEMENTED();
51 return 0; 107 return 0;
52 } 108 }
53 109
54 int GetChangedMouseButtonFlagsFromNative( 110 int GetChangedMouseButtonFlagsFromNative(
55 const base::NativeEvent& native_event) { 111 const base::NativeEvent& native_event) {
56 NOTIMPLEMENTED(); 112 NSEventType type = [native_event type];
113 switch (type) {
114 case NSLeftMouseDown:
115 case NSLeftMouseUp:
116 case NSLeftMouseDragged:
117 return EF_LEFT_MOUSE_BUTTON;
118 case NSRightMouseDown:
119 case NSRightMouseUp:
120 case NSRightMouseDragged:
121 return EF_RIGHT_MOUSE_BUTTON;
122 case NSOtherMouseDown:
123 case NSOtherMouseUp:
124 case NSOtherMouseDragged:
125 return EF_MIDDLE_MOUSE_BUTTON;
126 }
57 return 0; 127 return 0;
58 } 128 }
59 129
60 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { 130 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& event) {
61 NOTIMPLEMENTED(); 131 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive
62 return gfx::Vector2d(); 132 // values when scrolling up or to the left. Scrolling quickly results in a
133 // higher delta per click, up to about 15.0. (Quartz documentation suggests
134 // +/-10).
135 // Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120).
136 const CGFloat kWheelDeltaMultiplier = 1000;
137 return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX],
138 kWheelDeltaMultiplier * [event deltaY]);
139 }
140
141 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
142 return [event copy];
143 }
144
145 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
146 [event release];
63 } 147 }
64 148
65 void ClearTouchIdIfReleased(const base::NativeEvent& native_event) { 149 void ClearTouchIdIfReleased(const base::NativeEvent& native_event) {
66 NOTIMPLEMENTED(); 150 NOTIMPLEMENTED();
67 } 151 }
68 152
69 int GetTouchId(const base::NativeEvent& native_event) { 153 int GetTouchId(const base::NativeEvent& native_event) {
70 NOTIMPLEMENTED(); 154 NOTIMPLEMENTED();
71 return 0; 155 return 0;
72 } 156 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 NOTIMPLEMENTED(); 210 NOTIMPLEMENTED();
127 return false; 211 return false;
128 } 212 }
129 213
130 bool IsTouchpadEvent(const base::NativeEvent& native_event) { 214 bool IsTouchpadEvent(const base::NativeEvent& native_event) {
131 NOTIMPLEMENTED(); 215 NOTIMPLEMENTED();
132 return false; 216 return false;
133 } 217 }
134 218
135 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { 219 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
136 NOTIMPLEMENTED(); 220 return KeyboardCodeFromNSEvent(native_event);
137 return static_cast<KeyboardCode>(0);
138 } 221 }
139 222
140 const char* CodeFromNative(const base::NativeEvent& native_event) { 223 const char* CodeFromNative(const base::NativeEvent& native_event) {
141 NOTIMPLEMENTED(); 224 return CodeFromNSEvent(native_event);
142 return "";
143 } 225 }
144 226
145 } // namespace ui 227 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/cocoa/cocoa_event_utils_unittest.mm ('k') | ui/events/cocoa/events_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698