base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / ozone / events_ozone.cc
blob932600da3f00449f98f88750823406c812af235a
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 IncrementTouchIdRefCount(const base::NativeEvent& event) {
92 void ClearTouchIdIfReleased(const base::NativeEvent& xev) {
95 int GetTouchId(const base::NativeEvent& native_event) {
96 const ui::TouchEvent* event =
97 static_cast<const ui::TouchEvent*>(native_event);
98 DCHECK(event->IsTouchEvent());
99 return event->touch_id();
102 float GetTouchRadiusX(const base::NativeEvent& native_event) {
103 const ui::TouchEvent* event =
104 static_cast<const ui::TouchEvent*>(native_event);
105 DCHECK(event->IsTouchEvent());
106 return event->radius_x();
109 float GetTouchRadiusY(const base::NativeEvent& native_event) {
110 const ui::TouchEvent* event =
111 static_cast<const ui::TouchEvent*>(native_event);
112 DCHECK(event->IsTouchEvent());
113 return event->radius_y();
116 float GetTouchAngle(const base::NativeEvent& native_event) {
117 const ui::TouchEvent* event =
118 static_cast<const ui::TouchEvent*>(native_event);
119 DCHECK(event->IsTouchEvent());
120 return event->rotation_angle();
123 float GetTouchForce(const base::NativeEvent& native_event) {
124 const ui::TouchEvent* event =
125 static_cast<const ui::TouchEvent*>(native_event);
126 DCHECK(event->IsTouchEvent());
127 return event->force();
130 bool GetScrollOffsets(const base::NativeEvent& native_event,
131 float* x_offset,
132 float* y_offset,
133 float* x_offset_ordinal,
134 float* y_offset_ordinal,
135 int* finger_count) {
136 const ui::ScrollEvent* event =
137 static_cast<const ui::ScrollEvent*>(native_event);
138 DCHECK(event->IsScrollEvent());
139 if (x_offset)
140 *x_offset = event->x_offset();
141 if (y_offset)
142 *y_offset = event->y_offset();
143 if (x_offset_ordinal)
144 *x_offset_ordinal = event->x_offset_ordinal();
145 if (y_offset_ordinal)
146 *y_offset_ordinal = event->y_offset_ordinal();
147 if (finger_count)
148 *finger_count = event->finger_count();
150 return true;
153 bool GetFlingData(const base::NativeEvent& native_event,
154 float* vx,
155 float* vy,
156 float* vx_ordinal,
157 float* vy_ordinal,
158 bool* is_cancel) {
159 const ui::ScrollEvent* event =
160 static_cast<const ui::ScrollEvent*>(native_event);
161 DCHECK(event->IsScrollEvent());
162 if (vx)
163 *vx = event->x_offset();
164 if (vy)
165 *vy = event->y_offset();
166 if (vx_ordinal)
167 *vx_ordinal = event->x_offset_ordinal();
168 if (vy_ordinal)
169 *vy_ordinal = event->y_offset_ordinal();
170 if (is_cancel)
171 *is_cancel = event->type() == ET_SCROLL_FLING_CANCEL;
173 return true;
176 int GetModifiersFromKeyState() {
177 NOTIMPLEMENTED();
178 return 0;
181 void DispatchEventFromNativeUiEvent(const base::NativeEvent& native_event,
182 base::Callback<void(ui::Event*)> callback) {
183 const ui::Event* native_ui_event = static_cast<ui::Event*>(native_event);
184 if (native_ui_event->IsKeyEvent()) {
185 ui::KeyEvent key_event(native_event);
186 callback.Run(&key_event);
187 } else if (native_ui_event->IsMouseWheelEvent()) {
188 ui::MouseWheelEvent wheel_event(native_event);
189 callback.Run(&wheel_event);
190 } else if (native_ui_event->IsMouseEvent()) {
191 ui::MouseEvent mouse_event(native_event);
192 callback.Run(&mouse_event);
193 } else if (native_ui_event->IsTouchEvent()) {
194 ui::TouchEvent touch_event(native_event);
195 callback.Run(&touch_event);
196 } else if (native_ui_event->IsScrollEvent()) {
197 ui::ScrollEvent scroll_event(native_event);
198 callback.Run(&scroll_event);
199 } else {
200 NOTREACHED();
204 } // namespace ui