-
Notifications
You must be signed in to change notification settings - Fork 6k
Handle out-of-order add/remove pointer events #55740
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,45 @@ void PointerDataPacketConverter::ConvertPointerData( | |
| break; | ||
| } | ||
| case PointerData::Change::kAdd: { | ||
| FML_DCHECK(states_.find(pointer_data.device) == states_.end()); | ||
| auto iter = states_.find(pointer_data.device); | ||
| if (iter != states_.end()) { | ||
| // Synthesizes a remove event if the pointer was not previously | ||
| // removed. | ||
| PointerState state = iter->second; | ||
| PointerData synthesized_data = pointer_data; | ||
| synthesized_data.physical_x = state.physical_x; | ||
| synthesized_data.physical_y = state.physical_y; | ||
| synthesized_data.pan_x = state.pan_x; | ||
| synthesized_data.pan_y = state.pan_y; | ||
| synthesized_data.scale = state.scale; | ||
| synthesized_data.rotation = state.rotation; | ||
| synthesized_data.buttons = state.buttons; | ||
| synthesized_data.synthesized = 1; | ||
|
|
||
| // The framework expects an add event to always follow a remove event, | ||
| // and remove events with invalid views are ignored. | ||
| // To meet the framework's expectations, the view ID of the add event | ||
| // is used for the remove event if the old view has been destroyed. | ||
| if (delegate_.ViewExists(state.view_id)) { | ||
| synthesized_data.view_id = state.view_id; | ||
|
|
||
| if (state.is_down) { | ||
| // Synthesizes cancel event if the pointer is down. | ||
| PointerData synthesized_cancel_event = synthesized_data; | ||
| synthesized_cancel_event.change = PointerData::Change::kCancel; | ||
| UpdatePointerIdentifier(synthesized_cancel_event, state, false); | ||
|
|
||
| state.is_down = false; | ||
| converted_pointers.push_back(synthesized_cancel_event); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very familiar with this code. Could you explain why the cancel event is synthesized only if the view exists? That's not immediately obvious to me
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replicated the behavior of the non-synthesized/original remove event. When a non-synthesized "remove" is handled, a "cancel" is synthesized if the pointer is down, and a "hover" is synthesized if the pointer location has changed. Here, I replicate the synthesized "cancel" event, but not the "hover" event, since the pointer location is unchanged. My reasoning for synthesizing the "cancel" event only for valid views is that the framework will ignore events for non-existing views. |
||
| } | ||
| } | ||
|
|
||
| PointerData synthesized_remove_event = synthesized_data; | ||
| synthesized_remove_event.change = PointerData::Change::kRemove; | ||
|
|
||
| converted_pointers.push_back(synthesized_remove_event); | ||
| } | ||
|
|
||
| EnsurePointerState(pointer_data); | ||
| converted_pointers.push_back(pointer_data); | ||
| break; | ||
|
|
@@ -84,6 +122,11 @@ void PointerDataPacketConverter::ConvertPointerData( | |
| auto iter = states_.find(pointer_data.device); | ||
| FML_DCHECK(iter != states_.end()); | ||
| PointerState state = iter->second; | ||
| if (state.view_id != pointer_data.view_id) { | ||
| // Ignores remove event if the pointer was previously added to a | ||
| // different view. | ||
| break; | ||
loic-sharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (state.is_down) { | ||
| // Synthesizes cancel event if the pointer is down. | ||
|
|
@@ -362,6 +405,7 @@ PointerState PointerDataPacketConverter::EnsurePointerState( | |
| state.physical_y = pointer_data.physical_y; | ||
| state.pan_x = 0; | ||
| state.pan_y = 0; | ||
| state.view_id = pointer_data.view_id; | ||
| states_[pointer_data.device] = state; | ||
| return state; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.