| 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" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 static_assert(ui::mojom::kEventFlagRightMouseButton == | 111 static_assert(ui::mojom::kEventFlagRightMouseButton == |
| 112 static_cast<int32_t>(ui::EF_RIGHT_MOUSE_BUTTON), | 112 static_cast<int32_t>(ui::EF_RIGHT_MOUSE_BUTTON), |
| 113 "EVENT_FLAGS must match"); | 113 "EVENT_FLAGS must match"); |
| 114 static_assert(ui::mojom::kEventFlagBackMouseButton == | 114 static_assert(ui::mojom::kEventFlagBackMouseButton == |
| 115 static_cast<int32_t>(ui::EF_BACK_MOUSE_BUTTON), | 115 static_cast<int32_t>(ui::EF_BACK_MOUSE_BUTTON), |
| 116 "EVENT_FLAGS must match"); | 116 "EVENT_FLAGS must match"); |
| 117 static_assert(ui::mojom::kEventFlagForwardMouseButton == | 117 static_assert(ui::mojom::kEventFlagForwardMouseButton == |
| 118 static_cast<int32_t>(ui::EF_FORWARD_MOUSE_BUTTON), | 118 static_cast<int32_t>(ui::EF_FORWARD_MOUSE_BUTTON), |
| 119 "EVENT_FLAGS must match"); | 119 "EVENT_FLAGS must match"); |
| 120 | 120 |
| 121 ui::mojom::EventType StructTraits<ui::mojom::Event, EventUniquePtr>::action( | 121 ui::mojom::EventType |
| 122 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::action( |
| 122 const EventUniquePtr& event) { | 123 const EventUniquePtr& event) { |
| 123 return UIEventTypeToMojo(event->type()); | 124 return UIEventTypeToMojo(event->type()); |
| 124 } | 125 } |
| 125 | 126 |
| 126 int32_t StructTraits<ui::mojom::Event, EventUniquePtr>::flags( | 127 int32_t StructTraits<ui::mojom::EventDataView, EventUniquePtr>::flags( |
| 127 const EventUniquePtr& event) { | 128 const EventUniquePtr& event) { |
| 128 return event->flags(); | 129 return event->flags(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 int64_t StructTraits<ui::mojom::Event, EventUniquePtr>::time_stamp( | 132 int64_t StructTraits<ui::mojom::EventDataView, EventUniquePtr>::time_stamp( |
| 132 const EventUniquePtr& event) { | 133 const EventUniquePtr& event) { |
| 133 return event->time_stamp().ToInternalValue(); | 134 return event->time_stamp().ToInternalValue(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 ui::mojom::KeyDataPtr StructTraits<ui::mojom::Event, EventUniquePtr>::key_data( | 137 ui::mojom::KeyDataPtr |
| 138 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::key_data( |
| 137 const EventUniquePtr& event) { | 139 const EventUniquePtr& event) { |
| 138 if (!event->IsKeyEvent()) | 140 if (!event->IsKeyEvent()) |
| 139 return nullptr; | 141 return nullptr; |
| 140 | 142 |
| 141 const ui::KeyEvent* key_event = event->AsKeyEvent(); | 143 const ui::KeyEvent* key_event = event->AsKeyEvent(); |
| 142 ui::mojom::KeyDataPtr key_data(ui::mojom::KeyData::New()); | 144 ui::mojom::KeyDataPtr key_data(ui::mojom::KeyData::New()); |
| 143 key_data->key_code = key_event->GetConflatedWindowsKeyCode(); | 145 key_data->key_code = key_event->GetConflatedWindowsKeyCode(); |
| 144 key_data->native_key_code = | 146 key_data->native_key_code = |
| 145 ui::KeycodeConverter::DomCodeToNativeKeycode(key_event->code()); | 147 ui::KeycodeConverter::DomCodeToNativeKeycode(key_event->code()); |
| 146 key_data->is_char = key_event->is_char(); | 148 key_data->is_char = key_event->is_char(); |
| 147 key_data->character = key_event->GetCharacter(); | 149 key_data->character = key_event->GetCharacter(); |
| 148 key_data->windows_key_code = static_cast<ui::mojom::KeyboardCode>( | 150 key_data->windows_key_code = static_cast<ui::mojom::KeyboardCode>( |
| 149 key_event->GetLocatedWindowsKeyboardCode()); | 151 key_event->GetLocatedWindowsKeyboardCode()); |
| 150 key_data->text = key_event->GetText(); | 152 key_data->text = key_event->GetText(); |
| 151 key_data->unmodified_text = key_event->GetUnmodifiedText(); | 153 key_data->unmodified_text = key_event->GetUnmodifiedText(); |
| 152 | 154 |
| 153 return key_data; | 155 return key_data; |
| 154 } | 156 } |
| 155 | 157 |
| 156 ui::mojom::PointerDataPtr | 158 ui::mojom::PointerDataPtr |
| 157 StructTraits<ui::mojom::Event, EventUniquePtr>::pointer_data( | 159 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::pointer_data( |
| 158 const EventUniquePtr& event) { | 160 const EventUniquePtr& event) { |
| 159 if (!event->IsPointerEvent() && !event->IsMouseWheelEvent()) | 161 if (!event->IsPointerEvent() && !event->IsMouseWheelEvent()) |
| 160 return nullptr; | 162 return nullptr; |
| 161 | 163 |
| 162 ui::mojom::PointerDataPtr pointer_data(ui::mojom::PointerData::New()); | 164 ui::mojom::PointerDataPtr pointer_data(ui::mojom::PointerData::New()); |
| 163 | 165 |
| 164 const ui::PointerDetails* pointer_details = nullptr; | 166 const ui::PointerDetails* pointer_details = nullptr; |
| 165 if (event->IsPointerEvent()) { | 167 if (event->IsPointerEvent()) { |
| 166 const ui::PointerEvent* pointer_event = event->AsPointerEvent(); | 168 const ui::PointerEvent* pointer_event = event->AsPointerEvent(); |
| 167 pointer_data->pointer_id = pointer_event->pointer_id(); | 169 pointer_data->pointer_id = pointer_event->pointer_id(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 wheel_data->delta_x = wheel_event->x_offset(); | 227 wheel_data->delta_x = wheel_event->x_offset(); |
| 226 wheel_data->delta_y = wheel_event->y_offset(); | 228 wheel_data->delta_y = wheel_event->y_offset(); |
| 227 wheel_data->delta_z = 0; | 229 wheel_data->delta_z = 0; |
| 228 } | 230 } |
| 229 pointer_data->wheel_data = std::move(wheel_data); | 231 pointer_data->wheel_data = std::move(wheel_data); |
| 230 } | 232 } |
| 231 | 233 |
| 232 return pointer_data; | 234 return pointer_data; |
| 233 } | 235 } |
| 234 | 236 |
| 235 bool StructTraits<ui::mojom::Event, EventUniquePtr>::Read( | 237 bool StructTraits<ui::mojom::EventDataView, EventUniquePtr>::Read( |
| 236 ui::mojom::EventDataView event, | 238 ui::mojom::EventDataView event, |
| 237 EventUniquePtr* out) { | 239 EventUniquePtr* out) { |
| 238 switch (event.action()) { | 240 switch (event.action()) { |
| 239 case ui::mojom::EventType::KEY_PRESSED: | 241 case ui::mojom::EventType::KEY_PRESSED: |
| 240 case ui::mojom::EventType::KEY_RELEASED: { | 242 case ui::mojom::EventType::KEY_RELEASED: { |
| 241 ui::mojom::KeyDataPtr key_data; | 243 ui::mojom::KeyDataPtr key_data; |
| 242 if (!event.ReadKeyData<ui::mojom::KeyDataPtr>(&key_data)) | 244 if (!event.ReadKeyData<ui::mojom::KeyDataPtr>(&key_data)) |
| 243 return false; | 245 return false; |
| 244 | 246 |
| 245 if (key_data->is_char) { | 247 if (key_data->is_char) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 310 } |
| 309 } | 311 } |
| 310 case ui::mojom::EventType::UNKNOWN: | 312 case ui::mojom::EventType::UNKNOWN: |
| 311 return false; | 313 return false; |
| 312 } | 314 } |
| 313 | 315 |
| 314 return false; | 316 return false; |
| 315 } | 317 } |
| 316 | 318 |
| 317 } // namespace mojo | 319 } // namespace mojo |
| OLD | NEW |