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

Commit cc768c2

Browse files
committed
Consistent behavior across platforms
Pin iOS pan/zoom origin Set iOS pan/zoom to seperate device ID Use seperate device ID for mac pointer and pan/zoom Fix missing comment in fl_engine.cc
1 parent 0a3c0f2 commit cc768c2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,8 +1749,13 @@ - (void)panEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4)) {
17491749
translation.x *= scale;
17501750
translation.y *= scale;
17511751

1752+
CGPoint location = [recognizer locationInView:self.view];
1753+
17521754
flutter::PointerData pointer_data = [self generatePointerDataForMouse];
17531755
pointer_data.kind = flutter::PointerData::DeviceKind::kTouch;
1756+
pointer_data.physical_x = location.x * scale;
1757+
pointer_data.physical_y = location.y * scale;
1758+
pointer_data.device = reinterpret_cast<int64_t>(recognizer);
17541759
if (recognizer.state == UIGestureRecognizerStateBegan) {
17551760
pointer_data.change = flutter::PointerData::Change::kPanZoomStart;
17561761
} else if (recognizer.state == UIGestureRecognizerStateChanged) {

shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
@"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
3333
static NSString* const EnhancedUserInterfaceKey = @"AXEnhancedUserInterface";
3434

35+
// Use different device ID for mouse and pan/zoom events, since we can't differentiate the actual
36+
// device (mouse v.s. trackpad)
37+
static constexpr int32_t kMousePointerDeviceId = 0;
38+
static constexpr int32_t kPointerPanZoomDeviceId = 1;
39+
3540
/**
3641
* State tracking for mouse events, to adapt between the events coming from the system and the
3742
* events that the embedding API expects.
@@ -612,15 +617,18 @@ - (void)dispatchMouseEvent:(NSEvent*)event phase:(FlutterPointerPhase)phase {
612617
.timestamp = static_cast<size_t>(event.timestamp * USEC_PER_SEC),
613618
.x = locationInBackingCoordinates.x,
614619
.y = -locationInBackingCoordinates.y, // convertPointToBacking makes this negative.
620+
.device = kMousePointerDeviceId,
615621
.device_kind = kFlutterPointerDeviceKindMouse,
616622
// If a click triggered a synthesized kAdd, don't pass the buttons in that event.
617623
.buttons = phase == kAdd ? 0 : _mouseState.buttons,
618624
};
619625

620626
if (phase == kPanZoomStart) {
621627
flutterEvent.device_kind = kFlutterPointerDeviceKindTouch;
628+
flutterEvent.device = kPointerPanZoomDeviceId;
622629
} else if (phase == kPanZoomUpdate) {
623630
flutterEvent.device_kind = kFlutterPointerDeviceKindTouch;
631+
flutterEvent.device = kPointerPanZoomDeviceId;
624632
if (event.type == NSEventTypeScrollWheel) {
625633
_mouseState.deltaX += event.scrollingDeltaX * self.flutterView.layer.contentsScale;
626634
_mouseState.deltaY += event.scrollingDeltaY * self.flutterView.layer.contentsScale;
@@ -636,6 +644,7 @@ - (void)dispatchMouseEvent:(NSEvent*)event phase:(FlutterPointerPhase)phase {
636644
flutterEvent.rotation = _mouseState.rotation;
637645
} else if (phase == kPanZoomEnd) {
638646
flutterEvent.device_kind = kFlutterPointerDeviceKindTouch;
647+
flutterEvent.device = kPointerPanZoomDeviceId;
639648
_mouseState.GestureReset();
640649
} else if (event.type == NSEventTypeScrollWheel) {
641650
flutterEvent.signal_kind = kFlutterPointerSignalKindScroll;

shell/platform/linux/fl_engine.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
// Unique number associated with platform tasks.
2525
static constexpr size_t kPlatformTaskRunnerIdentifier = 1;
2626

27-
//
27+
// Use different device ID for mouse and pan/zoom events, since we can't
28+
// differentiate the actual device (mouse v.s. trackpad)
2829
static constexpr int32_t kMousePointerDeviceId = 0;
2930
static constexpr int32_t kPointerPanZoomDeviceId = 1;
3031

0 commit comments

Comments
 (0)