OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ozone/events_ozone.h" | 5 #include "ui/events/ozone/events_ozone.h" |
6 | 6 |
7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/event_constants.h" | |
9 #include "ui/events/event_utils.h" | |
10 | 8 |
11 namespace ui { | 9 namespace ui { |
12 | 10 |
13 void UpdateDeviceList() { NOTIMPLEMENTED(); } | |
14 | |
15 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { | |
16 const ui::Event* event = static_cast<const ui::Event*>(native_event); | |
17 return event->time_stamp(); | |
18 } | |
19 | |
20 int EventFlagsFromNative(const base::NativeEvent& native_event) { | |
21 const ui::Event* event = static_cast<const ui::Event*>(native_event); | |
22 return event->flags(); | |
23 } | |
24 | |
25 EventType EventTypeFromNative(const base::NativeEvent& native_event) { | |
26 const ui::Event* event = static_cast<const ui::Event*>(native_event); | |
27 return event->type(); | |
28 } | |
29 | |
30 gfx::Point EventSystemLocationFromNative( | |
31 const base::NativeEvent& native_event) { | |
32 const ui::LocatedEvent* e = | |
33 static_cast<const ui::LocatedEvent*>(native_event); | |
34 DCHECK(e->IsMouseEvent() || e->IsTouchEvent() || e->IsGestureEvent() || | |
35 e->IsScrollEvent()); | |
36 return e->location(); | |
37 } | |
38 | |
39 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | |
40 return EventSystemLocationFromNative(native_event); | |
41 } | |
42 | |
43 int GetChangedMouseButtonFlagsFromNative( | |
44 const base::NativeEvent& native_event) { | |
45 const ui::MouseEvent* event = | |
46 static_cast<const ui::MouseEvent*>(native_event); | |
47 DCHECK(event->IsMouseEvent() || event->IsScrollEvent()); | |
48 return event->changed_button_flags(); | |
49 } | |
50 | |
51 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | |
52 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event); | |
53 DCHECK(event->IsKeyEvent()); | |
54 return event->key_code(); | |
55 } | |
56 | |
57 DomCode CodeFromNative(const base::NativeEvent& native_event) { | |
58 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event); | |
59 DCHECK(event->IsKeyEvent()); | |
60 return event->code(); | |
61 } | |
62 | |
63 bool IsCharFromNative(const base::NativeEvent& native_event) { | |
64 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event); | |
65 DCHECK(event->IsKeyEvent()); | |
66 return event->is_char(); | |
67 } | |
68 | |
69 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { | |
70 const ui::MouseWheelEvent* event = | |
71 static_cast<const ui::MouseWheelEvent*>(native_event); | |
72 DCHECK(event->type() == ET_MOUSEWHEEL); | |
73 return event->offset(); | |
74 } | |
75 | |
76 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | |
77 return NULL; | |
78 } | |
79 | |
80 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { | |
81 } | |
82 | |
83 void ClearTouchIdIfReleased(const base::NativeEvent& xev) { | |
84 } | |
85 | |
86 int GetTouchId(const base::NativeEvent& native_event) { | |
87 const ui::TouchEvent* event = | |
88 static_cast<const ui::TouchEvent*>(native_event); | |
89 DCHECK(event->IsTouchEvent()); | |
90 return event->touch_id(); | |
91 } | |
92 | |
93 float GetTouchRadiusX(const base::NativeEvent& native_event) { | |
94 const ui::TouchEvent* event = | |
95 static_cast<const ui::TouchEvent*>(native_event); | |
96 DCHECK(event->IsTouchEvent()); | |
97 return event->pointer_details().radius_x(); | |
98 } | |
99 | |
100 float GetTouchRadiusY(const base::NativeEvent& native_event) { | |
101 const ui::TouchEvent* event = | |
102 static_cast<const ui::TouchEvent*>(native_event); | |
103 DCHECK(event->IsTouchEvent()); | |
104 return event->pointer_details().radius_y(); | |
105 } | |
106 | |
107 float GetTouchAngle(const base::NativeEvent& native_event) { | |
108 const ui::TouchEvent* event = | |
109 static_cast<const ui::TouchEvent*>(native_event); | |
110 DCHECK(event->IsTouchEvent()); | |
111 return event->rotation_angle(); | |
112 } | |
113 | |
114 float GetTouchForce(const base::NativeEvent& native_event) { | |
115 const ui::TouchEvent* event = | |
116 static_cast<const ui::TouchEvent*>(native_event); | |
117 DCHECK(event->IsTouchEvent()); | |
118 return event->pointer_details().force(); | |
119 } | |
120 | |
121 bool GetScrollOffsets(const base::NativeEvent& native_event, | |
122 float* x_offset, | |
123 float* y_offset, | |
124 float* x_offset_ordinal, | |
125 float* y_offset_ordinal, | |
126 int* finger_count) { | |
127 const ui::ScrollEvent* event = | |
128 static_cast<const ui::ScrollEvent*>(native_event); | |
129 DCHECK(event->IsScrollEvent()); | |
130 if (x_offset) | |
131 *x_offset = event->x_offset(); | |
132 if (y_offset) | |
133 *y_offset = event->y_offset(); | |
134 if (x_offset_ordinal) | |
135 *x_offset_ordinal = event->x_offset_ordinal(); | |
136 if (y_offset_ordinal) | |
137 *y_offset_ordinal = event->y_offset_ordinal(); | |
138 if (finger_count) | |
139 *finger_count = event->finger_count(); | |
140 | |
141 return true; | |
142 } | |
143 | |
144 bool GetFlingData(const base::NativeEvent& native_event, | |
145 float* vx, | |
146 float* vy, | |
147 float* vx_ordinal, | |
148 float* vy_ordinal, | |
149 bool* is_cancel) { | |
150 const ui::ScrollEvent* event = | |
151 static_cast<const ui::ScrollEvent*>(native_event); | |
152 DCHECK(event->IsScrollEvent()); | |
153 if (vx) | |
154 *vx = event->x_offset(); | |
155 if (vy) | |
156 *vy = event->y_offset(); | |
157 if (vx_ordinal) | |
158 *vx_ordinal = event->x_offset_ordinal(); | |
159 if (vy_ordinal) | |
160 *vy_ordinal = event->y_offset_ordinal(); | |
161 if (is_cancel) | |
162 *is_cancel = event->type() == ET_SCROLL_FLING_CANCEL; | |
163 | |
164 return true; | |
165 } | |
166 | |
167 int GetModifiersFromKeyState() { | |
168 NOTIMPLEMENTED(); | |
169 return 0; | |
170 } | |
171 | |
172 void DispatchEventFromNativeUiEvent(const base::NativeEvent& native_event, | 11 void DispatchEventFromNativeUiEvent(const base::NativeEvent& native_event, |
173 base::Callback<void(ui::Event*)> callback) { | 12 base::Callback<void(ui::Event*)> callback) { |
174 ui::Event* native_ui_event = static_cast<ui::Event*>(native_event); | 13 ui::Event* native_ui_event = static_cast<ui::Event*>(native_event); |
175 if (native_ui_event->IsKeyEvent()) { | 14 if (native_ui_event->IsKeyEvent()) { |
176 ui::KeyEvent key_event(native_event); | 15 ui::KeyEvent key_event(native_event); |
177 callback.Run(&key_event); | 16 callback.Run(&key_event); |
178 } else if (native_ui_event->IsMouseWheelEvent()) { | 17 } else if (native_ui_event->IsMouseWheelEvent()) { |
179 ui::MouseWheelEvent wheel_event(native_event); | 18 ui::MouseWheelEvent wheel_event(native_event); |
180 callback.Run(&wheel_event); | 19 callback.Run(&wheel_event); |
181 } else if (native_ui_event->IsMouseEvent()) { | 20 } else if (native_ui_event->IsMouseEvent()) { |
182 ui::MouseEvent mouse_event(native_event); | 21 ui::MouseEvent mouse_event(native_event); |
183 callback.Run(&mouse_event); | 22 callback.Run(&mouse_event); |
184 } else if (native_ui_event->IsTouchEvent()) { | 23 } else if (native_ui_event->IsTouchEvent()) { |
185 ui::TouchEvent touch_event(native_event); | 24 ui::TouchEvent touch_event(native_event); |
186 callback.Run(&touch_event); | 25 callback.Run(&touch_event); |
187 } else if (native_ui_event->IsScrollEvent()) { | 26 } else if (native_ui_event->IsScrollEvent()) { |
188 ui::ScrollEvent scroll_event(native_event); | 27 ui::ScrollEvent scroll_event(native_event); |
189 callback.Run(&scroll_event); | 28 callback.Run(&scroll_event); |
190 } else if (native_ui_event->IsGestureEvent()) { | 29 } else if (native_ui_event->IsGestureEvent()) { |
191 callback.Run(native_ui_event); | 30 callback.Run(native_ui_event); |
192 // TODO(mohsen): Use the same pattern for scroll/touch/wheel events. | 31 // TODO(mohsen): Use the same pattern for scroll/touch/wheel events. |
193 // Apparently, there is no need for them to wrap the |native_event|. | 32 // Apparently, there is no need for them to wrap the |native_event|. |
194 } else { | 33 } else { |
195 NOTREACHED(); | 34 NOTREACHED(); |
196 } | 35 } |
197 } | 36 } |
198 | 37 |
199 } // namespace ui | 38 } // namespace ui |
OLD | NEW |