| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mojo/event_struct_traits.h" | 5 #include "ui/events/mojo/event_struct_traits.h" |
| 6 | 6 |
| 7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
| 8 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
| 9 #include "ui/events/keycodes/dom/keycode_converter.h" | 9 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 10 #include "ui/events/mojo/event_constants.mojom.h" | 10 #include "ui/events/mojo/event_constants.mojom.h" |
| 11 #include "ui/events/mojo/latency_info_struct_traits.h" |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace mojo { |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 ui::mojom::EventType UIEventTypeToMojo(ui::EventType type) { | 16 ui::mojom::EventType UIEventTypeToMojo(ui::EventType type) { |
| 16 switch (type) { | 17 switch (type) { |
| 17 case ui::ET_POINTER_DOWN: | 18 case ui::ET_POINTER_DOWN: |
| 18 return ui::mojom::EventType::POINTER_DOWN; | 19 return ui::mojom::EventType::POINTER_DOWN; |
| 19 | 20 |
| 20 case ui::ET_POINTER_MOVED: | 21 case ui::ET_POINTER_MOVED: |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 int32_t StructTraits<ui::mojom::EventDataView, EventUniquePtr>::flags( | 131 int32_t StructTraits<ui::mojom::EventDataView, EventUniquePtr>::flags( |
| 131 const EventUniquePtr& event) { | 132 const EventUniquePtr& event) { |
| 132 return event->flags(); | 133 return event->flags(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 int64_t StructTraits<ui::mojom::EventDataView, EventUniquePtr>::time_stamp( | 136 int64_t StructTraits<ui::mojom::EventDataView, EventUniquePtr>::time_stamp( |
| 136 const EventUniquePtr& event) { | 137 const EventUniquePtr& event) { |
| 137 return event->time_stamp().ToInternalValue(); | 138 return event->time_stamp().ToInternalValue(); |
| 138 } | 139 } |
| 139 | 140 |
| 141 const ui::LatencyInfo& |
| 142 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::latency( |
| 143 const EventUniquePtr& event) { |
| 144 return *event->latency(); |
| 145 } |
| 146 |
| 140 ui::mojom::KeyDataPtr | 147 ui::mojom::KeyDataPtr |
| 141 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::key_data( | 148 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::key_data( |
| 142 const EventUniquePtr& event) { | 149 const EventUniquePtr& event) { |
| 143 if (!event->IsKeyEvent()) | 150 if (!event->IsKeyEvent()) |
| 144 return nullptr; | 151 return nullptr; |
| 145 | 152 |
| 146 const ui::KeyEvent* key_event = event->AsKeyEvent(); | 153 const ui::KeyEvent* key_event = event->AsKeyEvent(); |
| 147 ui::mojom::KeyDataPtr key_data(ui::mojom::KeyData::New()); | 154 ui::mojom::KeyDataPtr key_data(ui::mojom::KeyData::New()); |
| 148 key_data->key_code = key_event->GetConflatedWindowsKeyCode(); | 155 key_data->key_code = key_event->GetConflatedWindowsKeyCode(); |
| 149 key_data->native_key_code = | 156 key_data->native_key_code = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 231 } |
| 225 pointer_data->wheel_data = std::move(wheel_data); | 232 pointer_data->wheel_data = std::move(wheel_data); |
| 226 } | 233 } |
| 227 | 234 |
| 228 return pointer_data; | 235 return pointer_data; |
| 229 } | 236 } |
| 230 | 237 |
| 231 bool StructTraits<ui::mojom::EventDataView, EventUniquePtr>::Read( | 238 bool StructTraits<ui::mojom::EventDataView, EventUniquePtr>::Read( |
| 232 ui::mojom::EventDataView event, | 239 ui::mojom::EventDataView event, |
| 233 EventUniquePtr* out) { | 240 EventUniquePtr* out) { |
| 241 DCHECK(!out->get()); |
| 242 |
| 234 switch (event.action()) { | 243 switch (event.action()) { |
| 235 case ui::mojom::EventType::KEY_PRESSED: | 244 case ui::mojom::EventType::KEY_PRESSED: |
| 236 case ui::mojom::EventType::KEY_RELEASED: { | 245 case ui::mojom::EventType::KEY_RELEASED: { |
| 237 ui::mojom::KeyDataPtr key_data; | 246 ui::mojom::KeyDataPtr key_data; |
| 238 if (!event.ReadKeyData<ui::mojom::KeyDataPtr>(&key_data)) | 247 if (!event.ReadKeyData<ui::mojom::KeyDataPtr>(&key_data)) |
| 239 return false; | 248 return false; |
| 240 | 249 |
| 241 if (key_data->is_char) { | 250 if (key_data->is_char) { |
| 242 out->reset(new ui::KeyEvent( | 251 out->reset(new ui::KeyEvent( |
| 243 static_cast<base::char16>(key_data->character), | 252 static_cast<base::char16>(key_data->character), |
| 244 static_cast<ui::KeyboardCode>(key_data->key_code), event.flags())); | 253 static_cast<ui::KeyboardCode>(key_data->key_code), event.flags())); |
| 245 return true; | 254 |
| 255 } else { |
| 256 out->reset(new ui::KeyEvent( |
| 257 event.action() == ui::mojom::EventType::KEY_PRESSED |
| 258 ? ui::ET_KEY_PRESSED |
| 259 : ui::ET_KEY_RELEASED, |
| 260 static_cast<ui::KeyboardCode>(key_data->key_code), event.flags())); |
| 246 } | 261 } |
| 247 out->reset(new ui::KeyEvent( | 262 break; |
| 248 event.action() == ui::mojom::EventType::KEY_PRESSED | |
| 249 ? ui::ET_KEY_PRESSED | |
| 250 : ui::ET_KEY_RELEASED, | |
| 251 | |
| 252 static_cast<ui::KeyboardCode>(key_data->key_code), event.flags())); | |
| 253 return true; | |
| 254 } | 263 } |
| 255 case ui::mojom::EventType::POINTER_DOWN: | 264 case ui::mojom::EventType::POINTER_DOWN: |
| 256 case ui::mojom::EventType::POINTER_UP: | 265 case ui::mojom::EventType::POINTER_UP: |
| 257 case ui::mojom::EventType::POINTER_MOVE: | 266 case ui::mojom::EventType::POINTER_MOVE: |
| 258 case ui::mojom::EventType::POINTER_CANCEL: | 267 case ui::mojom::EventType::POINTER_CANCEL: |
| 259 case ui::mojom::EventType::MOUSE_EXIT: | 268 case ui::mojom::EventType::MOUSE_EXIT: |
| 260 case ui::mojom::EventType::POINTER_WHEEL_CHANGED: { | 269 case ui::mojom::EventType::POINTER_WHEEL_CHANGED: { |
| 261 ui::mojom::PointerDataPtr pointer_data; | 270 ui::mojom::PointerDataPtr pointer_data; |
| 262 if (!event.ReadPointerData<ui::mojom::PointerDataPtr>(&pointer_data)) | 271 if (!event.ReadPointerData<ui::mojom::PointerDataPtr>(&pointer_data)) |
| 263 return false; | 272 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 276 event.action() == ui::mojom::EventType::POINTER_WHEEL_CHANGED | 285 event.action() == ui::mojom::EventType::POINTER_WHEEL_CHANGED |
| 277 ? ui::PointerDetails( | 286 ? ui::PointerDetails( |
| 278 ui::EventPointerType::POINTER_TYPE_MOUSE, | 287 ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 279 gfx::Vector2d( | 288 gfx::Vector2d( |
| 280 static_cast<int>(pointer_data->wheel_data->delta_x), | 289 static_cast<int>(pointer_data->wheel_data->delta_x), |
| 281 static_cast<int>( | 290 static_cast<int>( |
| 282 pointer_data->wheel_data->delta_y))) | 291 pointer_data->wheel_data->delta_y))) |
| 283 : ui::PointerDetails( | 292 : ui::PointerDetails( |
| 284 ui::EventPointerType::POINTER_TYPE_MOUSE), | 293 ui::EventPointerType::POINTER_TYPE_MOUSE), |
| 285 ui::EventTimeForNow())); | 294 ui::EventTimeForNow())); |
| 286 return true; | 295 break; |
| 287 } | 296 } |
| 288 case ui::mojom::PointerKind::TOUCH: { | 297 case ui::mojom::PointerKind::TOUCH: { |
| 289 out->reset(new ui::PointerEvent( | 298 out->reset(new ui::PointerEvent( |
| 290 MojoPointerEventTypeToUIEvent(event.action()), location, | 299 MojoPointerEventTypeToUIEvent(event.action()), location, |
| 291 screen_location, event.flags(), pointer_data->pointer_id, | 300 screen_location, event.flags(), pointer_data->pointer_id, |
| 292 pointer_data->changed_button_flags, | 301 pointer_data->changed_button_flags, |
| 293 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, | 302 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, |
| 294 pointer_data->brush_data->width, | 303 pointer_data->brush_data->width, |
| 295 pointer_data->brush_data->height, | 304 pointer_data->brush_data->height, |
| 296 pointer_data->brush_data->pressure, | 305 pointer_data->brush_data->pressure, |
| 297 pointer_data->brush_data->tilt_x, | 306 pointer_data->brush_data->tilt_x, |
| 298 pointer_data->brush_data->tilt_y), | 307 pointer_data->brush_data->tilt_y), |
| 299 ui::EventTimeForNow())); | 308 ui::EventTimeForNow())); |
| 300 return true; | 309 break; |
| 301 } | 310 } |
| 302 case ui::mojom::PointerKind::PEN: | 311 case ui::mojom::PointerKind::PEN: |
| 303 NOTIMPLEMENTED(); | 312 NOTIMPLEMENTED(); |
| 304 return false; | 313 return false; |
| 305 } | 314 } |
| 315 break; |
| 306 } | 316 } |
| 307 case ui::mojom::EventType::UNKNOWN: | 317 case ui::mojom::EventType::UNKNOWN: |
| 308 return false; | 318 return false; |
| 309 } | 319 } |
| 310 | 320 |
| 311 return false; | 321 if (!out->get()) |
| 322 return false; |
| 323 |
| 324 return event.ReadLatency((*out)->latency()); |
| 312 } | 325 } |
| 313 | 326 |
| 314 } // namespace mojo | 327 } // namespace mojo |
| OLD | NEW |