Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5f17818

Browse files
committed
Correct button state on synthetic pointer events
This corrects the button state emitted on synthetic pointer move and hover events generated by the engine. When an embedder notifies the engine of a pointer up or down event, and the pointer's position has changed since the last move or hover event, `PointerDataPacketConverter` generates a synthetic move or hover to notify the framework of the change in position. In these cases, the current event from the embedder contains the new button state *after* the pointer up/down event, but the move/over needs to be synthesized such that it occurs *before* the pointer up/down, with the previous button state. This patch stores the button state after each pointer down, up, move, or hover event such that it can be used by the next event if a synthetic event must be issued. The bug in the previous logic was revealed by the release of macOS 11 (Big Sur), which appears to issue move events between mouse down and mouse up, which did not use to be the case. This fixes flutter/flutter#64961, which is the desktop-specific tracking bug for the more general Big Sur mouse click umbrella issue flutter/flutter#71190.
1 parent f0655e0 commit 5f17818

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/ui/window/pointer_data_packet_converter.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void PointerDataPacketConverter::ConvertPointerData(
126126
}
127127

128128
FML_DCHECK(!state.isDown);
129+
state.buttons = pointer_data.buttons;
129130
if (LocationNeedsUpdate(pointer_data, state)) {
130131
UpdateDeltaAndState(pointer_data, state);
131132
converted_pointers.push_back(pointer_data);
@@ -152,13 +153,15 @@ void PointerDataPacketConverter::ConvertPointerData(
152153
PointerData synthesized_hover_event = pointer_data;
153154
synthesized_hover_event.change = PointerData::Change::kHover;
154155
synthesized_hover_event.synthesized = 1;
156+
synthesized_hover_event.buttons = 0;
155157

156158
UpdateDeltaAndState(synthesized_hover_event, state);
157159
converted_pointers.push_back(synthesized_hover_event);
158160
}
159161

160162
UpdatePointerIdentifier(pointer_data, state, true);
161163
state.isDown = true;
164+
state.buttons = pointer_data.buttons;
162165
states_[pointer_data.device] = state;
163166
converted_pointers.push_back(pointer_data);
164167
break;
@@ -172,6 +175,7 @@ void PointerDataPacketConverter::ConvertPointerData(
172175

173176
UpdatePointerIdentifier(pointer_data, state, false);
174177
UpdateDeltaAndState(pointer_data, state);
178+
state.buttons = pointer_data.buttons;
175179
converted_pointers.push_back(pointer_data);
176180
break;
177181
}
@@ -188,13 +192,15 @@ void PointerDataPacketConverter::ConvertPointerData(
188192
// Synthesizes a move event if the location does not match.
189193
PointerData synthesized_move_event = pointer_data;
190194
synthesized_move_event.change = PointerData::Change::kMove;
195+
synthesized_move_event.buttons = state.buttons;
191196
synthesized_move_event.synthesized = 1;
192197

193198
UpdateDeltaAndState(synthesized_move_event, state);
194199
converted_pointers.push_back(synthesized_move_event);
195200
}
196201

197202
state.isDown = false;
203+
state.buttons = pointer_data.buttons;
198204
states_[pointer_data.device] = state;
199205
converted_pointers.push_back(pointer_data);
200206
break;

lib/ui/window/pointer_data_packet_converter.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616
namespace flutter {
1717

1818
//------------------------------------------------------------------------------
19-
/// The current information about a pointer. This struct is used by
20-
/// PointerDataPacketConverter to fill in necesarry information for raw pointer
21-
/// packet sent from embedding.
19+
/// The current information about a pointer.
20+
///
21+
/// This struct is used by PointerDataPacketConverter to fill in necessary
22+
/// information for the raw pointer packet sent from embedding. This struct also
23+
/// stores the button state of the last pointer down, up, move, or hover event.
24+
/// When an embedder issues a pointer up or down event where the pointer's
25+
/// position has changed since the last move or hover event,
26+
/// PointerDataPacketConverter generates a synthetic move or hover to notify the
27+
/// framework. In these cases, these events must be issued with the button state
28+
/// prior to the pointer up or down.
2229
///
2330
struct PointerState {
2431
int64_t pointer_identifier;
2532
bool isDown;
2633
double physical_x;
2734
double physical_y;
35+
int64_t buttons;
2836
};
2937

3038
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)