OLD | NEW |
---|---|
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_GESTURE_MULTIFINGER_SWIPE; | |
sadrul
2014/04/24 19:47:12
MULTIFINGER_SWIPE currently represent multi-finger
tapted
2014/04/25 03:44:55
Done.
| |
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 break; | |
69 } | |
23 return ET_UNKNOWN; | 70 return ET_UNKNOWN; |
24 } | 71 } |
25 | 72 |
26 #if !defined(OS_MACOSX) | 73 int EventFlagsFromNative(const base::NativeEvent& event) { |
27 int EventFlagsFromNative(const base::NativeEvent& native_event) { | 74 NSUInteger modifiers = [event modifierFlags]; |
28 NOTIMPLEMENTED(); | 75 return EventFlagsFromNSEventWithModifiers(event, modifiers); |
29 return 0; | |
30 } | 76 } |
31 #endif | |
32 | 77 |
33 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { | 78 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { |
34 NOTIMPLEMENTED(); | 79 NSTimeInterval since_system_startup = [native_event timestamp]; |
35 return base::TimeDelta(); | 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); | |
36 } | 85 } |
37 | 86 |
38 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 87 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
39 NOTIMPLEMENTED(); | 88 if (![native_event window]) { |
40 return gfx::Point(); | 89 NOTIMPLEMENTED(); // Point will be in screen coordinates. |
sadrul
2014/04/24 19:47:12
return after this?
tapted
2014/04/25 03:44:55
Done - now returns (0,0) rather than relying on [n
| |
90 } | |
91 NSPoint location = [native_event locationInWindow]; | |
92 return gfx::Point(location.x, | |
93 NSHeight([[native_event window] frame]) - location.y); | |
41 } | 94 } |
42 | 95 |
43 gfx::Point EventSystemLocationFromNative( | 96 gfx::Point EventSystemLocationFromNative( |
44 const base::NativeEvent& native_event) { | 97 const base::NativeEvent& native_event) { |
45 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
46 return gfx::Point(); | 99 return gfx::Point(); |
47 } | 100 } |
48 | 101 |
49 int EventButtonFromNative(const base::NativeEvent& native_event) { | 102 int EventButtonFromNative(const base::NativeEvent& native_event) { |
50 NOTIMPLEMENTED(); | 103 NOTIMPLEMENTED(); |
51 return 0; | 104 return 0; |
52 } | 105 } |
53 | 106 |
54 int GetChangedMouseButtonFlagsFromNative( | 107 int GetChangedMouseButtonFlagsFromNative( |
55 const base::NativeEvent& native_event) { | 108 const base::NativeEvent& native_event) { |
56 NOTIMPLEMENTED(); | 109 NSEventType type = [native_event type]; |
110 switch (type) { | |
111 case NSLeftMouseDown: | |
112 case NSLeftMouseUp: | |
113 case NSLeftMouseDragged: | |
114 return EF_LEFT_MOUSE_BUTTON; | |
115 case NSRightMouseDown: | |
116 case NSRightMouseUp: | |
117 case NSRightMouseDragged: | |
118 return EF_RIGHT_MOUSE_BUTTON; | |
119 case NSOtherMouseDown: | |
120 case NSOtherMouseUp: | |
121 case NSOtherMouseDragged: | |
122 return EF_MIDDLE_MOUSE_BUTTON; | |
123 } | |
57 return 0; | 124 return 0; |
58 } | 125 } |
59 | 126 |
60 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { | 127 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& event) { |
61 NOTIMPLEMENTED(); | 128 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive |
62 return gfx::Vector2d(); | 129 // values when scrolling up or to the left. Scrolling quickly results in a |
130 // higher delta per click, up to about 15.0. (Quartz documentation suggests | |
131 // +/-10). | |
132 // Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120). | |
133 const CGFloat kWheelDeltaMultiplier = 1000; | |
134 return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX], | |
135 kWheelDeltaMultiplier * [event deltaY]); | |
136 } | |
137 | |
138 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | |
139 return [event copy]; | |
140 } | |
141 | |
142 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { | |
143 [event release]; | |
63 } | 144 } |
64 | 145 |
65 void ClearTouchIdIfReleased(const base::NativeEvent& native_event) { | 146 void ClearTouchIdIfReleased(const base::NativeEvent& native_event) { |
66 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
67 } | 148 } |
68 | 149 |
69 int GetTouchId(const base::NativeEvent& native_event) { | 150 int GetTouchId(const base::NativeEvent& native_event) { |
70 NOTIMPLEMENTED(); | 151 NOTIMPLEMENTED(); |
71 return 0; | 152 return 0; |
72 } | 153 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 NOTIMPLEMENTED(); | 207 NOTIMPLEMENTED(); |
127 return false; | 208 return false; |
128 } | 209 } |
129 | 210 |
130 bool IsTouchpadEvent(const base::NativeEvent& native_event) { | 211 bool IsTouchpadEvent(const base::NativeEvent& native_event) { |
131 NOTIMPLEMENTED(); | 212 NOTIMPLEMENTED(); |
132 return false; | 213 return false; |
133 } | 214 } |
134 | 215 |
135 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 216 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
136 NOTIMPLEMENTED(); | 217 return KeyboardCodeFromNSEvent(native_event); |
137 return static_cast<KeyboardCode>(0); | |
138 } | 218 } |
139 | 219 |
140 const char* CodeFromNative(const base::NativeEvent& native_event) { | 220 const char* CodeFromNative(const base::NativeEvent& native_event) { |
141 NOTIMPLEMENTED(); | 221 return CodeFromNSEvent(native_event); |
142 return ""; | |
143 } | 222 } |
144 | 223 |
145 } // namespace ui | 224 } // namespace ui |
OLD | NEW |