5#include "flutter/lib/ui/window/pointer_data_packet_converter.h"
10#include "flutter/fml/logging.h"
21 std::vector<PointerData> converted_pointers;
26 ConvertPointerData(pointer_data, converted_pointers);
30 auto converted_packet =
31 std::make_unique<flutter::PointerDataPacket>(converted_pointers.size());
33 for (
auto& converted_pointer : converted_pointers) {
34 converted_packet->SetPointerData(
count++, converted_pointer);
37 return converted_packet;
40void PointerDataPacketConverter::ConvertPointerData(
42 std::vector<PointerData>& converted_pointers) {
48 switch (pointer_data.
change) {
54 auto iter = states_.find(pointer_data.
device);
55 if (iter != states_.end()) {
56 PointerState
state = iter->second;
58 UpdatePointerIdentifier(pointer_data,
state,
false);
60 if (LocationNeedsUpdate(pointer_data,
state)) {
62 PointerData synthesized_move_event = pointer_data;
64 synthesized_move_event.synthesized = 1;
66 UpdateDeltaAndState(synthesized_move_event,
state);
67 converted_pointers.push_back(synthesized_move_event);
70 state.is_down =
false;
72 converted_pointers.push_back(pointer_data);
78 EnsurePointerState(pointer_data);
79 converted_pointers.push_back(pointer_data);
84 auto iter = states_.find(pointer_data.
device);
86 PointerState
state = iter->second;
90 PointerData synthesized_cancel_event = pointer_data;
92 synthesized_cancel_event.synthesized = 1;
93 UpdatePointerIdentifier(synthesized_cancel_event,
state,
false);
95 state.is_down =
false;
96 states_[synthesized_cancel_event.device] =
state;
97 converted_pointers.push_back(synthesized_cancel_event);
100 if (LocationNeedsUpdate(pointer_data,
state)) {
102 PointerData synthesized_hover_event = pointer_data;
104 synthesized_hover_event.synthesized = 1;
106 UpdateDeltaAndState(synthesized_hover_event,
state);
107 converted_pointers.push_back(synthesized_hover_event);
110 states_.erase(pointer_data.
device);
111 converted_pointers.push_back(pointer_data);
115 auto iter = states_.find(pointer_data.
device);
117 if (iter == states_.end()) {
119 PointerData synthesized_add_event = pointer_data;
121 synthesized_add_event.synthesized = 1;
122 synthesized_add_event.buttons = 0;
123 state = EnsurePointerState(synthesized_add_event);
124 converted_pointers.push_back(synthesized_add_event);
126 state = iter->second;
131 if (LocationNeedsUpdate(pointer_data,
state)) {
132 UpdateDeltaAndState(pointer_data,
state);
133 converted_pointers.push_back(pointer_data);
138 auto iter = states_.find(pointer_data.
device);
140 if (iter == states_.end()) {
142 PointerData synthesized_add_event = pointer_data;
144 synthesized_add_event.synthesized = 1;
145 synthesized_add_event.buttons = 0;
146 state = EnsurePointerState(synthesized_add_event);
147 converted_pointers.push_back(synthesized_add_event);
149 state = iter->second;
153 if (LocationNeedsUpdate(pointer_data,
state)) {
155 PointerData synthesized_hover_event = pointer_data;
157 synthesized_hover_event.synthesized = 1;
158 synthesized_hover_event.buttons = 0;
160 UpdateDeltaAndState(synthesized_hover_event,
state);
161 converted_pointers.push_back(synthesized_hover_event);
164 UpdatePointerIdentifier(pointer_data,
state,
true);
165 state.is_down =
true;
168 converted_pointers.push_back(pointer_data);
173 auto iter = states_.find(pointer_data.
device);
175 PointerState
state = iter->second;
178 UpdatePointerIdentifier(pointer_data,
state,
false);
179 UpdateDeltaAndState(pointer_data,
state);
181 converted_pointers.push_back(pointer_data);
186 auto iter = states_.find(pointer_data.
device);
188 PointerState
state = iter->second;
191 UpdatePointerIdentifier(pointer_data,
state,
false);
193 if (LocationNeedsUpdate(pointer_data,
state)) {
195 PointerData synthesized_move_event = pointer_data;
197 synthesized_move_event.buttons =
state.buttons;
198 synthesized_move_event.synthesized = 1;
200 UpdateDeltaAndState(synthesized_move_event,
state);
201 converted_pointers.push_back(synthesized_move_event);
204 state.is_down =
false;
207 converted_pointers.push_back(pointer_data);
212 auto iter = states_.find(pointer_data.
device);
214 if (iter == states_.end()) {
216 PointerData synthesized_add_event = pointer_data;
218 synthesized_add_event.synthesized = 1;
219 synthesized_add_event.buttons = 0;
220 state = EnsurePointerState(synthesized_add_event);
221 converted_pointers.push_back(synthesized_add_event);
223 state = iter->second;
227 if (LocationNeedsUpdate(pointer_data,
state)) {
229 PointerData synthesized_hover_event = pointer_data;
231 synthesized_hover_event.synthesized = 1;
232 synthesized_hover_event.buttons = 0;
234 UpdateDeltaAndState(synthesized_hover_event,
state);
235 converted_pointers.push_back(synthesized_hover_event);
238 UpdatePointerIdentifier(pointer_data,
state,
true);
239 state.is_pan_zoom_active =
true;
245 converted_pointers.push_back(pointer_data);
250 auto iter = states_.find(pointer_data.
device);
252 PointerState
state = iter->second;
256 UpdatePointerIdentifier(pointer_data,
state,
false);
257 UpdateDeltaAndState(pointer_data,
state);
259 converted_pointers.push_back(pointer_data);
264 auto iter = states_.find(pointer_data.
device);
266 PointerState
state = iter->second;
269 UpdatePointerIdentifier(pointer_data,
state,
false);
271 if (LocationNeedsUpdate(pointer_data,
state)) {
273 PointerData synthesized_move_event = pointer_data;
275 synthesized_move_event.pan_x =
state.pan_x;
276 synthesized_move_event.pan_y =
state.pan_y;
277 synthesized_move_event.pan_delta_x = 0;
278 synthesized_move_event.pan_delta_y = 0;
279 synthesized_move_event.scale =
state.scale;
280 synthesized_move_event.rotation =
state.rotation;
281 synthesized_move_event.synthesized = 1;
283 UpdateDeltaAndState(synthesized_move_event,
state);
284 converted_pointers.push_back(synthesized_move_event);
287 state.is_pan_zoom_active =
false;
289 converted_pointers.push_back(pointer_data);
293 converted_pointers.push_back(pointer_data);
303 auto iter = states_.find(pointer_data.
device);
306 if (iter == states_.end()) {
308 PointerData synthesized_add_event = pointer_data;
311 synthesized_add_event.synthesized = 1;
312 synthesized_add_event.buttons = 0;
313 state = EnsurePointerState(synthesized_add_event);
314 converted_pointers.push_back(synthesized_add_event);
316 state = iter->second;
319 if (LocationNeedsUpdate(pointer_data,
state)) {
322 PointerData synthesized_move_event = pointer_data;
325 synthesized_move_event.buttons =
state.buttons;
326 synthesized_move_event.synthesized = 1;
328 UpdateDeltaAndState(synthesized_move_event,
state);
329 converted_pointers.push_back(synthesized_move_event);
332 PointerData synthesized_hover_event = pointer_data;
336 synthesized_hover_event.buttons = 0;
337 synthesized_hover_event.synthesized = 1;
339 UpdateDeltaAndState(synthesized_hover_event,
state);
340 converted_pointers.push_back(synthesized_hover_event);
344 converted_pointers.push_back(pointer_data);
355PointerState PointerDataPacketConverter::EnsurePointerState(
356 PointerData pointer_data) {
358 state.pointer_identifier = 0;
359 state.is_down =
false;
360 state.is_pan_zoom_active =
false;
361 state.physical_x = pointer_data.physical_x;
362 state.physical_y = pointer_data.physical_y;
365 states_[pointer_data.device] =
state;
369void PointerDataPacketConverter::UpdateDeltaAndState(PointerData& pointer_data,
370 PointerState&
state) {
371 pointer_data.physical_delta_x = pointer_data.physical_x -
state.physical_x;
372 pointer_data.physical_delta_y = pointer_data.physical_y -
state.physical_y;
373 pointer_data.pan_delta_x = pointer_data.pan_x -
state.pan_x;
374 pointer_data.pan_delta_y = pointer_data.pan_y -
state.pan_y;
375 state.physical_x = pointer_data.physical_x;
376 state.physical_y = pointer_data.physical_y;
377 state.pan_x = pointer_data.pan_x;
378 state.pan_y = pointer_data.pan_y;
379 state.scale = pointer_data.scale;
380 state.rotation = pointer_data.rotation;
381 states_[pointer_data.device] =
state;
384bool PointerDataPacketConverter::LocationNeedsUpdate(
385 const PointerData pointer_data,
386 const PointerState
state) {
387 return state.physical_x != pointer_data.physical_x ||
388 state.physical_y != pointer_data.physical_y;
391void PointerDataPacketConverter::UpdatePointerIdentifier(
392 PointerData& pointer_data,
394 bool start_new_pointer) {
395 if (start_new_pointer) {
396 state.pointer_identifier = ++pointer_;
397 states_[pointer_data.device] =
state;
399 pointer_data.pointer_identifier =
state.pointer_identifier;
virtual bool ViewExists(int64_t view_id) const =0
~PointerDataPacketConverter()
PointerDataPacketConverter(const Delegate &delegate)
Create a PointerDataPacketConverter.
std::unique_ptr< PointerDataPacket > Convert(const PointerDataPacket &packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
PointerData GetPointerData(size_t i) const
#define FML_DCHECK(condition)