Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / ui / events / ozone / events_ozone.cc
blobd29f9da022a54e5330a84e1294ff1495afbf650e
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"
11 namespace ui {
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);
27 return event->type();
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();
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());
60 return event->code();
63 uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) {
64 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event);
65 DCHECK(event->IsKeyEvent());
66 return event->platform_keycode();
69 bool IsCharFromNative(const base::NativeEvent& native_event) {
70 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event);
71 DCHECK(event->IsKeyEvent());
72 return event->is_char();
75 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
76 const ui::MouseWheelEvent* event =
77 static_cast<const ui::MouseWheelEvent*>(native_event);
78 DCHECK(event->type() == ET_MOUSEWHEEL);
79 return event->offset();
82 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
83 return NULL;
86 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
89 void ClearTouchIdIfReleased(const base::NativeEvent& xev) {
92 int GetTouchId(const base::NativeEvent& native_event) {
93 const ui::TouchEvent* event =
94 static_cast<const ui::TouchEvent*>(native_event);
95 DCHECK(event->IsTouchEvent());
96 return event->touch_id();
99 float GetTouchRadiusX(const base::NativeEvent& native_event) {
100 const ui::TouchEvent* event =
101 static_cast<const ui::TouchEvent*>(native_event);
102 DCHECK(event->IsTouchEvent());
103 return event->radius_x();
106 float GetTouchRadiusY(const base::NativeEvent& native_event) {
107 const ui::TouchEvent* event =
108 static_cast<const ui::TouchEvent*>(native_event);
109 DCHECK(event->IsTouchEvent());
110 return event->radius_y();
113 float GetTouchAngle(const base::NativeEvent& native_event) {
114 const ui::TouchEvent* event =
115 static_cast<const ui::TouchEvent*>(native_event);
116 DCHECK(event->IsTouchEvent());
117 return event->rotation_angle();
120 float GetTouchForce(const base::NativeEvent& native_event) {
121 const ui::TouchEvent* event =
122 static_cast<const ui::TouchEvent*>(native_event);
123 DCHECK(event->IsTouchEvent());
124 return event->force();
127 bool GetScrollOffsets(const base::NativeEvent& native_event,
128 float* x_offset,
129 float* y_offset,
130 float* x_offset_ordinal,
131 float* y_offset_ordinal,
132 int* finger_count) {
133 const ui::ScrollEvent* event =
134 static_cast<const ui::ScrollEvent*>(native_event);
135 DCHECK(event->IsScrollEvent());
136 if (x_offset)
137 *x_offset = event->x_offset();
138 if (y_offset)
139 *y_offset = event->y_offset();
140 if (x_offset_ordinal)
141 *x_offset_ordinal = event->x_offset_ordinal();
142 if (y_offset_ordinal)
143 *y_offset_ordinal = event->y_offset_ordinal();
144 if (finger_count)
145 *finger_count = event->finger_count();
147 return true;
150 bool GetFlingData(const base::NativeEvent& native_event,
151 float* vx,
152 float* vy,
153 float* vx_ordinal,
154 float* vy_ordinal,
155 bool* is_cancel) {
156 const ui::ScrollEvent* event =
157 static_cast<const ui::ScrollEvent*>(native_event);
158 DCHECK(event->IsScrollEvent());
159 if (vx)
160 *vx = event->x_offset();
161 if (vy)
162 *vy = event->y_offset();
163 if (vx_ordinal)
164 *vx_ordinal = event->x_offset_ordinal();
165 if (vy_ordinal)
166 *vy_ordinal = event->y_offset_ordinal();
167 if (is_cancel)
168 *is_cancel = event->type() == ET_SCROLL_FLING_CANCEL;
170 return true;
173 int GetModifiersFromKeyState() {
174 NOTIMPLEMENTED();
175 return 0;
178 void DispatchEventFromNativeUiEvent(const base::NativeEvent& native_event,
179 base::Callback<void(ui::Event*)> callback) {
180 const ui::Event* native_ui_event = static_cast<ui::Event*>(native_event);
181 if (native_ui_event->IsKeyEvent()) {
182 ui::KeyEvent key_event(native_event);
183 callback.Run(&key_event);
184 } else if (native_ui_event->IsMouseWheelEvent()) {
185 ui::MouseWheelEvent wheel_event(native_event);
186 callback.Run(&wheel_event);
187 } else if (native_ui_event->IsMouseEvent()) {
188 ui::MouseEvent mouse_event(native_event);
189 callback.Run(&mouse_event);
190 } else if (native_ui_event->IsTouchEvent()) {
191 ui::TouchEvent touch_event(native_event);
192 callback.Run(&touch_event);
193 } else if (native_ui_event->IsScrollEvent()) {
194 ui::ScrollEvent scroll_event(native_event);
195 callback.Run(&scroll_event);
196 } else {
197 NOTREACHED();
201 } // namespace ui