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
3 // found in the LICENSE file.
5 #include "ui/events/ozone/events_ozone.h"
7 #include "ui/events/event.h"
8 #include "ui/events/event_constants.h"
9 #include "ui/events/event_utils.h"
13 void UpdateDeviceList() { NOTIMPLEMENTED(); }
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();
20 int EventFlagsFromNative(const base::NativeEvent
& native_event
) {
21 const ui::Event
* event
= static_cast<const ui::Event
*>(native_event
);
22 return event
->flags();
25 EventType
EventTypeFromNative(const base::NativeEvent
& native_event
) {
26 const ui::Event
* event
= static_cast<const ui::Event
*>(native_event
);
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() ||
39 gfx::Point
EventLocationFromNative(const base::NativeEvent
& native_event
) {
40 return EventSystemLocationFromNative(native_event
);
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();
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();
57 DomCode
CodeFromNative(const base::NativeEvent
& native_event
) {
58 const ui::KeyEvent
* event
= static_cast<const ui::KeyEvent
*>(native_event
);
59 DCHECK(event
->IsKeyEvent());
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();
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();
76 base::NativeEvent
CopyNativeEvent(const base::NativeEvent
& event
) {
80 void ReleaseCopiedNativeEvent(const base::NativeEvent
& event
) {
83 void ClearTouchIdIfReleased(const base::NativeEvent
& xev
) {
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();
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();
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();
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();
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();
121 bool GetScrollOffsets(const base::NativeEvent
& native_event
,
124 float* x_offset_ordinal
,
125 float* y_offset_ordinal
,
127 const ui::ScrollEvent
* event
=
128 static_cast<const ui::ScrollEvent
*>(native_event
);
129 DCHECK(event
->IsScrollEvent());
131 *x_offset
= event
->x_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();
139 *finger_count
= event
->finger_count();
144 bool GetFlingData(const base::NativeEvent
& native_event
,
150 const ui::ScrollEvent
* event
=
151 static_cast<const ui::ScrollEvent
*>(native_event
);
152 DCHECK(event
->IsScrollEvent());
154 *vx
= event
->x_offset();
156 *vy
= event
->y_offset();
158 *vx_ordinal
= event
->x_offset_ordinal();
160 *vy_ordinal
= event
->y_offset_ordinal();
162 *is_cancel
= event
->type() == ET_SCROLL_FLING_CANCEL
;
167 int GetModifiersFromKeyState() {
172 void DispatchEventFromNativeUiEvent(const base::NativeEvent
& native_event
,
173 base::Callback
<void(ui::Event
*)> callback
) {
174 const ui::Event
* native_ui_event
= static_cast<ui::Event
*>(native_event
);
175 if (native_ui_event
->IsKeyEvent()) {
176 ui::KeyEvent
key_event(native_event
);
177 callback
.Run(&key_event
);
178 } else if (native_ui_event
->IsMouseWheelEvent()) {
179 ui::MouseWheelEvent
wheel_event(native_event
);
180 callback
.Run(&wheel_event
);
181 } else if (native_ui_event
->IsMouseEvent()) {
182 ui::MouseEvent
mouse_event(native_event
);
183 callback
.Run(&mouse_event
);
184 } else if (native_ui_event
->IsTouchEvent()) {
185 ui::TouchEvent
touch_event(native_event
);
186 callback
.Run(&touch_event
);
187 } else if (native_ui_event
->IsScrollEvent()) {
188 ui::ScrollEvent
scroll_event(native_event
);
189 callback
.Run(&scroll_event
);