OLD | NEW |
1 // Copyright 2014 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 "mojo/converters/input_events/input_events_type_converters.h" | 5 #include "mojo/converters/input_events/input_events_type_converters.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <utility> | 9 #include <utility> |
8 | 10 |
9 #if defined(USE_X11) | 11 #if defined(USE_X11) |
10 #include <X11/extensions/XInput2.h> | 12 #include <X11/extensions/XInput2.h> |
11 #include <X11/Xlib.h> | 13 #include <X11/Xlib.h> |
12 #endif | 14 #endif |
13 | 15 |
14 #include "components/mus/public/interfaces/input_events.mojom.h" | 16 #include "components/mus/public/interfaces/input_events.mojom.h" |
15 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
16 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" | 18 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 void SetPointerDataLocationFromEvent(const ui::LocatedEvent& located_event, | 80 void SetPointerDataLocationFromEvent(const ui::LocatedEvent& located_event, |
79 mus::mojom::LocationData* location_data) { | 81 mus::mojom::LocationData* location_data) { |
80 location_data->x = located_event.location_f().x(); | 82 location_data->x = located_event.location_f().x(); |
81 location_data->y = located_event.location_f().y(); | 83 location_data->y = located_event.location_f().y(); |
82 location_data->screen_x = located_event.root_location_f().x(); | 84 location_data->screen_x = located_event.root_location_f().x(); |
83 location_data->screen_y = located_event.root_location_f().y(); | 85 location_data->screen_y = located_event.root_location_f().y(); |
84 } | 86 } |
85 | 87 |
86 } // namespace | 88 } // namespace |
87 | 89 |
88 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_NONE) == | 90 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_NONE) == |
89 static_cast<int32>(ui::EF_NONE), | 91 static_cast<int32_t>(ui::EF_NONE), |
90 "EVENT_FLAGS must match"); | 92 "EVENT_FLAGS must match"); |
91 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_CAPS_LOCK_DOWN) == | 93 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_CAPS_LOCK_DOWN) == |
92 static_cast<int32>(ui::EF_CAPS_LOCK_DOWN), | 94 static_cast<int32_t>(ui::EF_CAPS_LOCK_DOWN), |
93 "EVENT_FLAGS must match"); | 95 "EVENT_FLAGS must match"); |
94 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_SHIFT_DOWN) == | 96 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_SHIFT_DOWN) == |
95 static_cast<int32>(ui::EF_SHIFT_DOWN), | 97 static_cast<int32_t>(ui::EF_SHIFT_DOWN), |
96 "EVENT_FLAGS must match"); | 98 "EVENT_FLAGS must match"); |
97 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_CONTROL_DOWN) == | 99 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_CONTROL_DOWN) == |
98 static_cast<int32>(ui::EF_CONTROL_DOWN), | 100 static_cast<int32_t>(ui::EF_CONTROL_DOWN), |
99 "EVENT_FLAGS must match"); | 101 "EVENT_FLAGS must match"); |
100 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_ALT_DOWN) == | 102 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_ALT_DOWN) == |
101 static_cast<int32>(ui::EF_ALT_DOWN), | 103 static_cast<int32_t>(ui::EF_ALT_DOWN), |
102 "EVENT_FLAGS must match"); | 104 "EVENT_FLAGS must match"); |
103 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON) == | 105 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON) == |
104 static_cast<int32>(ui::EF_LEFT_MOUSE_BUTTON), | 106 static_cast<int32_t>(ui::EF_LEFT_MOUSE_BUTTON), |
105 "EVENT_FLAGS must match"); | 107 "EVENT_FLAGS must match"); |
106 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON) == | 108 static_assert( |
107 static_cast<int32>(ui::EF_MIDDLE_MOUSE_BUTTON), | 109 static_cast<int32_t>(mus::mojom::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON) == |
| 110 static_cast<int32_t>(ui::EF_MIDDLE_MOUSE_BUTTON), |
| 111 "EVENT_FLAGS must match"); |
| 112 static_assert( |
| 113 static_cast<int32_t>(mus::mojom::EVENT_FLAGS_RIGHT_MOUSE_BUTTON) == |
| 114 static_cast<int32_t>(ui::EF_RIGHT_MOUSE_BUTTON), |
| 115 "EVENT_FLAGS must match"); |
| 116 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_COMMAND_DOWN) == |
| 117 static_cast<int32_t>(ui::EF_COMMAND_DOWN), |
108 "EVENT_FLAGS must match"); | 118 "EVENT_FLAGS must match"); |
109 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_RIGHT_MOUSE_BUTTON) == | 119 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_EXTENDED) == |
110 static_cast<int32>(ui::EF_RIGHT_MOUSE_BUTTON), | 120 static_cast<int32_t>(ui::EF_EXTENDED), |
111 "EVENT_FLAGS must match"); | 121 "EVENT_FLAGS must match"); |
112 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_COMMAND_DOWN) == | 122 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_IS_SYNTHESIZED) == |
113 static_cast<int32>(ui::EF_COMMAND_DOWN), | 123 static_cast<int32_t>(ui::EF_IS_SYNTHESIZED), |
114 "EVENT_FLAGS must match"); | 124 "EVENT_FLAGS must match"); |
115 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_EXTENDED) == | 125 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_ALTGR_DOWN) == |
116 static_cast<int32>(ui::EF_EXTENDED), | 126 static_cast<int32_t>(ui::EF_ALTGR_DOWN), |
117 "EVENT_FLAGS must match"); | 127 "EVENT_FLAGS must match"); |
118 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_IS_SYNTHESIZED) == | 128 static_assert(static_cast<int32_t>(mus::mojom::EVENT_FLAGS_MOD3_DOWN) == |
119 static_cast<int32>(ui::EF_IS_SYNTHESIZED), | 129 static_cast<int32_t>(ui::EF_MOD3_DOWN), |
120 "EVENT_FLAGS must match"); | |
121 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_ALTGR_DOWN) == | |
122 static_cast<int32>(ui::EF_ALTGR_DOWN), | |
123 "EVENT_FLAGS must match"); | |
124 static_assert(static_cast<int32>(mus::mojom::EVENT_FLAGS_MOD3_DOWN) == | |
125 static_cast<int32>(ui::EF_MOD3_DOWN), | |
126 "EVENT_FLAGS must match"); | 130 "EVENT_FLAGS must match"); |
127 | 131 |
128 // static | 132 // static |
129 mus::mojom::EventType | 133 mus::mojom::EventType |
130 TypeConverter<mus::mojom::EventType, ui::EventType>::Convert( | 134 TypeConverter<mus::mojom::EventType, ui::EventType>::Convert( |
131 ui::EventType type) { | 135 ui::EventType type) { |
132 switch (type) { | 136 switch (type) { |
133 case ui::ET_MOUSE_PRESSED: | 137 case ui::ET_MOUSE_PRESSED: |
134 case ui::ET_TOUCH_PRESSED: | 138 case ui::ET_TOUCH_PRESSED: |
135 return mus::mojom::EVENT_TYPE_POINTER_DOWN; | 139 return mus::mojom::EVENT_TYPE_POINTER_DOWN; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 mus::mojom::EventPtr event = mus::mojom::Event::New(); | 177 mus::mojom::EventPtr event = mus::mojom::Event::New(); |
174 event->action = type; | 178 event->action = type; |
175 event->flags = mus::mojom::EventFlags(input.flags()); | 179 event->flags = mus::mojom::EventFlags(input.flags()); |
176 event->time_stamp = input.time_stamp().ToInternalValue(); | 180 event->time_stamp = input.time_stamp().ToInternalValue(); |
177 | 181 |
178 if (input.IsMouseEvent()) { | 182 if (input.IsMouseEvent()) { |
179 const ui::LocatedEvent* located_event = | 183 const ui::LocatedEvent* located_event = |
180 static_cast<const ui::LocatedEvent*>(&input); | 184 static_cast<const ui::LocatedEvent*>(&input); |
181 mus::mojom::PointerDataPtr pointer_data(mus::mojom::PointerData::New()); | 185 mus::mojom::PointerDataPtr pointer_data(mus::mojom::PointerData::New()); |
182 // TODO(sky): come up with a better way to handle this. | 186 // TODO(sky): come up with a better way to handle this. |
183 pointer_data->pointer_id = std::numeric_limits<int32>::max(); | 187 pointer_data->pointer_id = std::numeric_limits<int32_t>::max(); |
184 pointer_data->kind = mus::mojom::POINTER_KIND_MOUSE; | 188 pointer_data->kind = mus::mojom::POINTER_KIND_MOUSE; |
185 mus::mojom::LocationDataPtr location_data(mus::mojom::LocationData::New()); | 189 mus::mojom::LocationDataPtr location_data(mus::mojom::LocationData::New()); |
186 SetPointerDataLocationFromEvent(*located_event, location_data.get()); | 190 SetPointerDataLocationFromEvent(*located_event, location_data.get()); |
187 pointer_data->location = std::move(location_data); | 191 pointer_data->location = std::move(location_data); |
188 | 192 |
189 if (input.IsMouseWheelEvent()) { | 193 if (input.IsMouseWheelEvent()) { |
190 const ui::MouseWheelEvent* wheel_event = | 194 const ui::MouseWheelEvent* wheel_event = |
191 static_cast<const ui::MouseWheelEvent*>(&input); | 195 static_cast<const ui::MouseWheelEvent*>(&input); |
192 | 196 |
193 mus::mojom::WheelDataPtr wheel_data(mus::mojom::WheelData::New()); | 197 mus::mojom::WheelDataPtr wheel_data(mus::mojom::WheelData::New()); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } break; | 363 } break; |
360 | 364 |
361 default: | 365 default: |
362 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
363 } | 367 } |
364 // TODO: need to support time_stamp. | 368 // TODO: need to support time_stamp. |
365 return nullptr; | 369 return nullptr; |
366 } | 370 } |
367 | 371 |
368 } // namespace mojo | 372 } // namespace mojo |
OLD | NEW |