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

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, 8 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
OLDNEW
(Empty)
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.
4
5 #include "ui/events/event_utils.h"
6
7 #include <Cocoa/Cocoa.h>
8
9 #include "base/logging.h"
10 #include "base/time/time.h"
11 #include "build/build_config.h"
12 #include "ui/events/cocoa/cocoa_event_utils.h"
13 #include "ui/events/event_utils.h"
14 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
15 #include "ui/gfx/point.h"
16 #include "ui/gfx/vector2d.h"
17
18 namespace ui {
19
20 void UpdateDeviceList() {
21 NOTIMPLEMENTED();
22 }
23
24 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
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:
Robert Sesek 2014/04/25 15:39:23 Shouldn't the default case also be NOTIMPLEMENTED(
tapted 2014/04/28 07:39:49 events_win and events_x do not do this. However, I
68 break;
69 }
70 return ET_UNKNOWN;
71 }
72
73 int EventFlagsFromNative(const base::NativeEvent& event) {
74 NSUInteger modifiers = [event modifierFlags];
75 return EventFlagsFromNSEventWithModifiers(event, modifiers);
76 }
77
78 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
Robert Sesek 2014/04/25 15:39:23 It's not clear to me what this function is trying
tapted 2014/04/28 07:39:49 It's a somewhat paranoid equivalent of return bas
Robert Sesek 2014/04/28 18:51:32 That makes sense. I don't think it needs to be tha
79 NSTimeInterval since_system_startup = [native_event timestamp];
80 int64_t seconds = since_system_startup;
81 since_system_startup -= seconds;
82 int64_t microseconds = since_system_startup * 1000000;
83 return base::TimeDelta::FromSeconds(seconds) +
84 base::TimeDelta::FromMicroseconds(microseconds);
85 }
86
87 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
88 if (![native_event window]) {
89 NOTIMPLEMENTED(); // Point will be in screen coordinates.
90 return gfx::Point(0, 0);
sadrul 2014/04/25 11:40:28 You can just do gfx::Point()
tapted 2014/04/28 07:39:49 Done.
91 }
92 NSPoint location = [native_event locationInWindow];
93 return gfx::Point(location.x,
94 NSHeight([[native_event window] frame]) - location.y);
95 }
96
97 gfx::Point EventSystemLocationFromNative(
98 const base::NativeEvent& native_event) {
99 NOTIMPLEMENTED();
100 return gfx::Point();
101 }
102
103 int EventButtonFromNative(const base::NativeEvent& native_event) {
104 NOTIMPLEMENTED();
105 return 0;
106 }
107
108 int GetChangedMouseButtonFlagsFromNative(
109 const base::NativeEvent& native_event) {
110 NSEventType type = [native_event type];
111 switch (type) {
112 case NSLeftMouseDown:
113 case NSLeftMouseUp:
114 case NSLeftMouseDragged:
115 return EF_LEFT_MOUSE_BUTTON;
116 case NSRightMouseDown:
117 case NSRightMouseUp:
118 case NSRightMouseDragged:
119 return EF_RIGHT_MOUSE_BUTTON;
120 case NSOtherMouseDown:
121 case NSOtherMouseUp:
122 case NSOtherMouseDragged:
123 return EF_MIDDLE_MOUSE_BUTTON;
124 }
125 return 0;
126 }
127
128 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& event) {
129 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive
130 // values when scrolling up or to the left. Scrolling quickly results in a
131 // higher delta per click, up to about 15.0. (Quartz documentation suggests
132 // +/-10).
133 // Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120).
134 const CGFloat kWheelDeltaMultiplier = 1000;
135 return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX],
136 kWheelDeltaMultiplier * [event deltaY]);
137 }
138
139 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
140 return [event copy];
141 }
142
143 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
144 [event release];
145 }
146
147 void ClearTouchIdIfReleased(const base::NativeEvent& native_event) {
148 NOTIMPLEMENTED();
149 }
150
151 int GetTouchId(const base::NativeEvent& native_event) {
152 NOTIMPLEMENTED();
153 return 0;
154 }
155
156 float GetTouchRadiusX(const base::NativeEvent& native_event) {
157 NOTIMPLEMENTED();
158 return 0.f;
159 }
160
161 float GetTouchRadiusY(const base::NativeEvent& native_event) {
162 NOTIMPLEMENTED();
163 return 0.f;
164 }
165
166 float GetTouchAngle(const base::NativeEvent& native_event) {
167 NOTIMPLEMENTED();
168 return 0.f;
169 }
170
171 float GetTouchForce(const base::NativeEvent& native_event) {
172 NOTIMPLEMENTED();
173 return 0.f;
174 }
175
176 bool GetScrollOffsets(const base::NativeEvent& native_event,
177 float* x_offset,
178 float* y_offset,
179 float* x_offset_ordinal,
180 float* y_offset_ordinal,
181 int* finger_count) {
182 NOTIMPLEMENTED();
183 return false;
184 }
185
186 bool GetFlingData(const base::NativeEvent& native_event,
187 float* vx,
188 float* vy,
189 float* vx_ordinal,
190 float* vy_ordinal,
191 bool* is_cancel) {
192 NOTIMPLEMENTED();
193 return false;
194 }
195
196 bool GetGestureTimes(const base::NativeEvent& native_event,
197 double* start_time,
198 double* end_time) {
199 NOTIMPLEMENTED();
200 return false;
201 }
202
203 void SetNaturalScroll(bool enabled) {
204 NOTIMPLEMENTED();
205 }
206
207 bool IsNaturalScrollEnabled() {
208 NOTIMPLEMENTED();
209 return false;
210 }
211
212 bool IsTouchpadEvent(const base::NativeEvent& native_event) {
213 NOTIMPLEMENTED();
214 return false;
215 }
216
217 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
218 return KeyboardCodeFromNSEvent(native_event);
219 }
220
221 const char* CodeFromNative(const base::NativeEvent& native_event) {
222 return CodeFromNSEvent(native_event);
223 }
224
225 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698