From a9458909039cfd5890015bbfdb4494209afaa2b4 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 26 Jan 2023 12:15:18 -0800 Subject: [PATCH 01/24] working commit --- lib/ui/platform_dispatcher.dart | 3 +- lib/ui/pointer.dart | 16 ++++++ lib/ui/window/pointer_data.h | 11 +++- .../window/pointer_data_packet_converter.cc | 1 + .../framework/Source/FlutterViewController.mm | 52 +++++++++++++++++-- .../Source/FlutterViewControllerTest.mm | 2 + shell/platform/embedder/embedder.cc | 2 + shell/platform/embedder/embedder.h | 1 + 8 files changed, 83 insertions(+), 5 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index f348a4f8db00e..009b800c22a73 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -371,7 +371,7 @@ class PlatformDispatcher { // * pointer_data.cc // * pointer.dart // * AndroidTouchProcessor.java - static const int _kPointerDataFieldCount = 35; + static const int _kPointerDataFieldCount = 36; static PointerDataPacket _unpackPointerDataPacket(ByteData packet) { const int kStride = Int64List.bytesPerElement; @@ -417,6 +417,7 @@ class PlatformDispatcher { panDeltaY: packet.getFloat64(kStride * offset++, _kFakeHostEndian), scale: packet.getFloat64(kStride * offset++, _kFakeHostEndian), rotation: packet.getFloat64(kStride * offset++, _kFakeHostEndian), + preferredAction: PointerPreferredAction.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)], )); assert(offset == (i + 1) * _kPointerDataFieldCount); } diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 059e41ac6d316..54ddb7f7cf56f 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -132,11 +132,20 @@ enum PointerSignalKind { /// A pointer-generated scale event (e.g. trackpad pinch). scale, + + stylusAction, /// An unknown pointer signal kind. unknown } +enum PointerPreferredAction { + ignore, + showColorPalette, + switchEraser, + switchPrevious +} + /// Information about the state of a pointer. class PointerData { /// Creates an object that represents the state of a pointer. @@ -176,6 +185,7 @@ class PointerData { this.panDeltaY = 0.0, this.scale = 0.0, this.rotation = 0.0, + this.preferredAction = PointerPreferredAction.ignore, }); /// Unique identifier that ties the [PointerEvent] to embedder event created it. @@ -373,6 +383,11 @@ class PointerData { /// /// The current angle of the pan/zoom in radians, with 0.0 as the initial angle. final double rotation; + + /// For events with change of PointerChange.panZoomUpdate: + /// + /// The current angle of the pan/zoom in radians, with 0.0 as the initial angle. + final PointerPreferredAction preferredAction; @override String toString() => 'PointerData(x: $physicalX, y: $physicalY)'; @@ -414,6 +429,7 @@ class PointerData { 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' 'rotation: $rotation' + 'preferredAction: $preferredAction, ' ')'; } } diff --git a/lib/ui/window/pointer_data.h b/lib/ui/window/pointer_data.h index 1f323cc4f8169..b61c82705ad0a 100644 --- a/lib/ui/window/pointer_data.h +++ b/lib/ui/window/pointer_data.h @@ -11,7 +11,7 @@ namespace flutter { // If this value changes, update the pointer data unpacking code in // platform_dispatcher.dart. -static constexpr int kPointerDataFieldCount = 35; +static constexpr int kPointerDataFieldCount = 36; static constexpr int kBytesPerField = sizeof(int64_t); // Must match the button constants in events.dart. enum PointerButtonMouse : int64_t { @@ -63,6 +63,14 @@ struct alignas(8) PointerData { kScroll, kScrollInertiaCancel, kScale, + kStylusAction, + }; + + enum class PreferredAction : int64_t { + kIgnore, + kShowColorPalette, + kSwitchEraser, + kSwitchPrevious }; int64_t embedder_id; @@ -100,6 +108,7 @@ struct alignas(8) PointerData { double pan_delta_y; double scale; double rotation; + PreferredAction preferred_action; void Clear(); }; diff --git a/lib/ui/window/pointer_data_packet_converter.cc b/lib/ui/window/pointer_data_packet_converter.cc index 6750a7da22761..b6398fb07066e 100644 --- a/lib/ui/window/pointer_data_packet_converter.cc +++ b/lib/ui/window/pointer_data_packet_converter.cc @@ -293,6 +293,7 @@ void PointerDataPacketConverter::ConvertPointerData( switch (pointer_data.signal_kind) { case PointerData::SignalKind::kScroll: case PointerData::SignalKind::kScrollInertiaCancel: + case PointerData::SignalKind::kStylusAction: case PointerData::SignalKind::kScale: { // Makes sure we have an existing pointer auto iter = states_.find(pointer_data.device); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 7a80c937366cf..4e53641e2db92 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -31,6 +31,8 @@ #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" #import "flutter/shell/platform/embedder/embedder.h" +#import + static constexpr int kMicrosecondsPerSecond = 1000 * 1000; static constexpr CGFloat kScrollViewContentSize = 2.0; @@ -55,7 +57,7 @@ // This is left a FlutterBinaryMessenger privately for now to give people a chance to notice the // change. Unfortunately unless you have Werror turned on, incompatible pointers as arguments are // just a warning. -@interface FlutterViewController () +@interface FlutterViewController () @property(nonatomic, readwrite, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI; @property(nonatomic, assign) BOOL isHomeIndicatorHidden; @property(nonatomic, assign) BOOL isPresentingViewControllerAnimating; @@ -93,6 +95,8 @@ @interface FlutterViewController () *)presses #pragma mark - Orientation updates -- (void)onOrientationPreferencesUpdated:(NSNotification*)notification { +#pragma clang diagnostic push + +- (void)pencilInteractionDidTap:(UIPencilInteraction *)interaction API_AVAILABLE(ios(13.4)){ + + flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation]; + + switch (UIPencilInteraction.preferredTapAction) { + case UIPencilPreferredActionIgnore: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kIgnore; + break; + case UIPencilPreferredActionShowColorPalette: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kShowColorPalette; + break; + case UIPencilPreferredActionSwitchEraser: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchEraser; + break; + case UIPencilPreferredActionSwitchPrevious: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchPrevious; + default: + break; + } + + pointer_data.device = reinterpret_cast(_pencilInteraction); + pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; + pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAction; + + auto packet = std::make_unique(1); + packet->SetPointerData(/*index=*/0, pointer_data); + [_engine.get() dispatchPointerDataPacket:std::move(packet)]; +} + +#pragma clang diagnostic pop + + +- (void)onOrientationPreferencesUpdated:(NSNotification*)notification API_AVAILABLE(ios(12.1)) { // Notifications may not be on the iOS UI thread dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary* info = notification.userInfo; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 5d3c1c948df18..f3086d4a84652 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1479,6 +1479,8 @@ - (void)testMouseSupport API_AVAILABLE(ios(13.4)) { dispatchPointerDataPacket:std::make_unique(0)]; } + + - (void)testFakeEventTimeStamp { FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index 9888ad6676899..a9aebe31fc899 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -2019,6 +2019,8 @@ inline flutter::PointerData::SignalKind ToPointerDataSignalKind( return flutter::PointerData::SignalKind::kScrollInertiaCancel; case kFlutterPointerSignalKindScale: return flutter::PointerData::SignalKind::kScale; + case kFlutterPointerSignalKindStylusAction: + return flutter::PointerData::SignalKind::kStylusAction; } return flutter::PointerData::SignalKind::kNone; } diff --git a/shell/platform/embedder/embedder.h b/shell/platform/embedder/embedder.h index bff1be0df26c3..9163466e0ca96 100644 --- a/shell/platform/embedder/embedder.h +++ b/shell/platform/embedder/embedder.h @@ -888,6 +888,7 @@ typedef enum { kFlutterPointerSignalKindScroll, kFlutterPointerSignalKindScrollInertiaCancel, kFlutterPointerSignalKindScale, + kFlutterPointerSignalKindStylusAction, } FlutterPointerSignalKind; typedef struct { From 6b7061a0244d24094d1c6c6ff6d2f3688328d89c Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Sat, 28 Jan 2023 16:22:52 -0800 Subject: [PATCH 02/24] some clean up --- lib/ui/pointer.dart | 6 +- .../framework/Source/FlutterViewController.mm | 72 +++++++++---------- .../Source/FlutterViewControllerTest.mm | 23 ++++++ 3 files changed, 62 insertions(+), 39 deletions(-) diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 9e20d0b607a76..516a8e20ab521 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -133,12 +133,14 @@ enum PointerSignalKind { /// A pointer-generated scale event (e.g. trackpad pinch). scale, + /// A stylus generated action (e.g. double tap on Apple Pencil 2) stylusAction, /// An unknown pointer signal kind. unknown } +/// The preferred action for stylus action enum PointerPreferredAction { ignore, showColorPalette, @@ -384,9 +386,9 @@ class PointerData { /// The current angle of the pan/zoom in radians, with 0.0 as the initial angle. final double rotation; - /// For events with change of PointerChange.panZoomUpdate: + /// For events with signal kind of stylusAction /// - /// The current angle of the pan/zoom in radians, with 0.0 as the initial angle. + /// The current preferred action for stylusAction, with ignore as the default. final PointerPreferredAction preferredAction; @override diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 071275b9323f9..b7e3f74c4fd54 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -453,7 +453,6 @@ - (void)loadView { scrollView.contentOffset = CGPointMake(kScrollViewContentSize, kScrollViewContentSize); [self.view addSubview:scrollView]; _scrollView.reset(scrollView); - } - (flutter::PointerData)generatePointerDataForFake { @@ -697,7 +696,6 @@ - (void)surfaceUpdated:(BOOL)appeared { #pragma mark - UIViewController lifecycle notifications - (void)viewDidLoad { - NSLog(@"Detected"); TRACE_EVENT0("flutter", "viewDidLoad"); if (_engine && _engineNeedsLaunch) { @@ -893,7 +891,6 @@ - (void)dealloc { [_pinchGestureRecognizer release]; _rotationGestureRecognizer.delegate = nil; [_rotationGestureRecognizer release]; - [super dealloc]; } @@ -1223,6 +1220,41 @@ - (void)invalidateTouchRateCorrectionVSyncClient { _touchRateCorrectionVSyncClient = nil; } +#pragma mark - Stylus Events + +#pragma clang diagnostic push + +- (void)pencilInteractionDidTap:(UIPencilInteraction *)interaction API_AVAILABLE(ios(13.4)){ + + flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation]; + + switch (UIPencilInteraction.preferredTapAction) { + case UIPencilPreferredActionIgnore: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kIgnore; + break; + case UIPencilPreferredActionShowColorPalette: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kShowColorPalette; + break; + case UIPencilPreferredActionSwitchEraser: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchEraser; + break; + case UIPencilPreferredActionSwitchPrevious: + pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchPrevious; + default: + break; + } + + pointer_data.device = reinterpret_cast(_pencilInteraction); + pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; + pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAction; + + auto packet = std::make_unique(1); + packet->SetPointerData(/*index=*/0, pointer_data); + [_engine.get() dispatchPointerDataPacket:std::move(packet)]; +} + +#pragma clang diagnostic pop + #pragma mark - Handle view resizing - (void)updateViewportMetrics { @@ -1692,40 +1724,6 @@ - (void)pressesCancelled:(NSSet*)presses #pragma mark - Orientation updates -#pragma clang diagnostic push - -- (void)pencilInteractionDidTap:(UIPencilInteraction *)interaction API_AVAILABLE(ios(13.4)){ - - flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation]; - - switch (UIPencilInteraction.preferredTapAction) { - case UIPencilPreferredActionIgnore: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kIgnore; - break; - case UIPencilPreferredActionShowColorPalette: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kShowColorPalette; - break; - case UIPencilPreferredActionSwitchEraser: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchEraser; - break; - case UIPencilPreferredActionSwitchPrevious: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchPrevious; - default: - break; - } - - pointer_data.device = reinterpret_cast(_pencilInteraction); - pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; - pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAction; - - auto packet = std::make_unique(1); - packet->SetPointerData(/*index=*/0, pointer_data); - [_engine.get() dispatchPointerDataPacket:std::move(packet)]; -} - -#pragma clang diagnostic pop - - - (void)onOrientationPreferencesUpdated:(NSNotification*)notification API_AVAILABLE(ios(12.1)) { // Notifications may not be on the iOS UI thread dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index f3086d4a84652..7ff7893cc2ea6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -121,6 +121,7 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences; - (void)handlePressEvent:(FlutterUIPressProxy*)press nextAction:(void (^)())next API_AVAILABLE(ios(13.4)); - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer; +- (void)pencilInteractionDidTap:(UIPencilInteraction *)interaction; - (void)updateViewportMetrics; - (void)onUserSettingsChanged:(NSNotification*)notification; - (void)applicationWillTerminate:(NSNotification*)notification; @@ -1479,6 +1480,28 @@ - (void)testMouseSupport API_AVAILABLE(ios(13.4)) { dispatchPointerDataPacket:std::make_unique(0)]; } +- (void)testPencilSupport API_AVAILABLE(ios(13.4)) { + if (@available(iOS 13.4, *)) { + // noop + } else { + return; + } + + FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine + nibName:nil + bundle:nil]; + XCTAssertNotNil(vc); + + id mockPencilInteraction = OCMClassMock([UIPencilInteraction class]); + XCTAssertNotNil(mockPencilInteraction); + + [vc pencilInteractionDidTap:mockPencilInteraction]; + + [[[self.mockEngine verify] ignoringNonObjectArgs] + dispatchPointerDataPacket:std::make_unique(0)]; +} + + - (void)testFakeEventTimeStamp { From 3818c77866f755d39dc743125d1676a49e0eed62 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 30 Jan 2023 13:54:00 -0800 Subject: [PATCH 03/24] white space fixes --- lib/ui/pointer.dart | 6 +++--- lib/ui/window/pointer_data.h | 3 ++- .../darwin/ios/framework/Source/FlutterViewController.mm | 6 ++---- .../ios/framework/Source/FlutterViewControllerTest.mm | 2 -- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 516a8e20ab521..db54e7090dac6 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -132,7 +132,7 @@ enum PointerSignalKind { /// A pointer-generated scale event (e.g. trackpad pinch). scale, - + /// A stylus generated action (e.g. double tap on Apple Pencil 2) stylusAction, @@ -140,7 +140,7 @@ enum PointerSignalKind { unknown } -/// The preferred action for stylus action + /// The preferred action for stylus action enum PointerPreferredAction { ignore, showColorPalette, @@ -385,7 +385,7 @@ class PointerData { /// /// The current angle of the pan/zoom in radians, with 0.0 as the initial angle. final double rotation; - + /// For events with signal kind of stylusAction /// /// The current preferred action for stylusAction, with ignore as the default. diff --git a/lib/ui/window/pointer_data.h b/lib/ui/window/pointer_data.h index b61c82705ad0a..526393574b428 100644 --- a/lib/ui/window/pointer_data.h +++ b/lib/ui/window/pointer_data.h @@ -65,7 +65,8 @@ struct alignas(8) PointerData { kScale, kStylusAction, }; - + + // Must match the PointerPreferredAction enum in pointer.dart. enum class PreferredAction : int64_t { kIgnore, kShowColorPalette, diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index b7e3f74c4fd54..23f7995928507 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -713,11 +713,10 @@ - (void)viewDidLoad { [self createTouchRateCorrectionVSyncClientIfNeeded]; if (@available(iOS 13.4, *)) { - _pencilInteraction = [[UIPencilInteraction alloc] init]; _pencilInteraction.delegate = self; [_flutterView addInteraction:_pencilInteraction]; - + _hoverGestureRecognizer = [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverEvent:)]; _hoverGestureRecognizer.delegate = self; @@ -1225,9 +1224,8 @@ - (void)invalidateTouchRateCorrectionVSyncClient { #pragma clang diagnostic push - (void)pencilInteractionDidTap:(UIPencilInteraction *)interaction API_AVAILABLE(ios(13.4)){ - flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation]; - + switch (UIPencilInteraction.preferredTapAction) { case UIPencilPreferredActionIgnore: pointer_data.preferred_action = flutter::PointerData::PreferredAction::kIgnore; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 7ff7893cc2ea6..2e74f4898664a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1502,8 +1502,6 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { } - - - (void)testFakeEventTimeStamp { FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil From 1b6c8f535be4b658b190c0c3d0789c20b87c2053 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 30 Jan 2023 14:32:31 -0800 Subject: [PATCH 04/24] whitespace --- .../ios/framework/Source/FlutterViewController.mm | 10 +++++----- .../ios/framework/Source/FlutterViewControllerTest.mm | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 23f7995928507..ab24614a2a84c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -57,7 +57,9 @@ // This is left a FlutterBinaryMessenger privately for now to give people a chance to notice the // change. Unfortunately unless you have Werror turned on, incompatible pointers as arguments are // just a warning. -@interface FlutterViewController () +@interface FlutterViewController () @property(nonatomic, readwrite, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI; @property(nonatomic, assign) BOOL isHomeIndicatorHidden; @property(nonatomic, assign) BOOL isPresentingViewControllerAnimating; @@ -95,9 +97,7 @@ @interface FlutterViewController () (0)]; } - - (void)testFakeEventTimeStamp { FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil From 9c31bd1654c5d4c6599c5ee37fc158a185c19d1e Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 30 Jan 2023 14:46:28 -0800 Subject: [PATCH 05/24] remove unused import --- .../darwin/ios/framework/Source/FlutterViewController.mm | 2 -- 1 file changed, 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ab24614a2a84c..e7fc1004a87e5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -31,8 +31,6 @@ #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" #import "flutter/shell/platform/embedder/embedder.h" -#import - static constexpr int kMicrosecondsPerSecond = 1000 * 1000; static constexpr CGFloat kScrollViewContentSize = 2.0; From c2450d4fb3138e6ac525c9c3c170b8cffdcbd4fb Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 2 Feb 2023 16:46:09 -0800 Subject: [PATCH 06/24] Addressing PR comment, fix tests, update touch packet on Andriod --- lib/ui/platform_dispatcher.dart | 2 +- lib/ui/pointer.dart | 26 +++++++++++++------ lib/ui/window/pointer_data.h | 14 +++++----- .../window/pointer_data_packet_converter.cc | 2 +- .../android/AndroidTouchProcessor.java | 24 +++++++++++++++-- .../framework/Source/FlutterViewController.mm | 17 +++++++----- .../Source/FlutterViewControllerTest.mm | 11 +++++++- shell/platform/embedder/embedder.cc | 4 +-- shell/platform/embedder/embedder.h | 2 +- 9 files changed, 73 insertions(+), 29 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 86d22ca03f2b1..5f3e0812b12ea 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -417,7 +417,7 @@ class PlatformDispatcher { panDeltaY: packet.getFloat64(kStride * offset++, _kFakeHostEndian), scale: packet.getFloat64(kStride * offset++, _kFakeHostEndian), rotation: packet.getFloat64(kStride * offset++, _kFakeHostEndian), - preferredAction: PointerPreferredAction.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)], + preferredStylusAuxiliaryAction: PointerPreferredStylusAuxiliaryAction.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)], )); assert(offset == (i + 1) * _kPointerDataFieldCount); } diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index db54e7090dac6..9f7a97e5ddeeb 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -134,18 +134,28 @@ enum PointerSignalKind { scale, /// A stylus generated action (e.g. double tap on Apple Pencil 2) - stylusAction, + stylusAuxiliaryAction, /// An unknown pointer signal kind. unknown } /// The preferred action for stylus action -enum PointerPreferredAction { +enum PointerPreferredStylusAuxiliaryAction { + /// Ignore pointer input ignore, + + /// Show colour palette if available showColorPalette, + + /// Switch to eraser if available switchEraser, - switchPrevious + + /// Switch to previous tool + switchPrevious, + + /// unknown preferred action + unknown, } /// Information about the state of a pointer. @@ -187,7 +197,7 @@ class PointerData { this.panDeltaY = 0.0, this.scale = 0.0, this.rotation = 0.0, - this.preferredAction = PointerPreferredAction.ignore, + this.preferredStylusAuxiliaryAction = PointerPreferredStylusAuxiliaryAction.ignore, }); /// Unique identifier that ties the [PointerEvent] to embedder event created it. @@ -386,10 +396,10 @@ class PointerData { /// The current angle of the pan/zoom in radians, with 0.0 as the initial angle. final double rotation; - /// For events with signal kind of stylusAction + /// For events with signal kind of stylusAuxiliaryAction /// - /// The current preferred action for stylusAction, with ignore as the default. - final PointerPreferredAction preferredAction; + /// The current preferred action for stylusAuxiliaryAction, with ignore as the default. + final PointerPreferredStylusAuxiliaryAction preferredStylusAuxiliaryAction; @override String toString() => 'PointerData(x: $physicalX, y: $physicalY)'; @@ -431,7 +441,7 @@ class PointerData { 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' 'rotation: $rotation' - 'preferredAction: $preferredAction, ' + 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction, ' ')'; } } diff --git a/lib/ui/window/pointer_data.h b/lib/ui/window/pointer_data.h index 526393574b428..e2b3709de627e 100644 --- a/lib/ui/window/pointer_data.h +++ b/lib/ui/window/pointer_data.h @@ -63,15 +63,17 @@ struct alignas(8) PointerData { kScroll, kScrollInertiaCancel, kScale, - kStylusAction, + kStylusAuxiliaryAction, }; - - // Must match the PointerPreferredAction enum in pointer.dart. - enum class PreferredAction : int64_t { + + // Must match the PreferredStylusAuxiliaryAction enum in pointer.dart. + + enum class PreferredStylusAuxiliaryAction : int64_t { kIgnore, kShowColorPalette, kSwitchEraser, - kSwitchPrevious + kSwitchPrevious, + kUnknown }; int64_t embedder_id; @@ -109,7 +111,7 @@ struct alignas(8) PointerData { double pan_delta_y; double scale; double rotation; - PreferredAction preferred_action; + PreferredStylusAuxiliaryAction preferred_auxiliary_stylus_action; void Clear(); }; diff --git a/lib/ui/window/pointer_data_packet_converter.cc b/lib/ui/window/pointer_data_packet_converter.cc index b6398fb07066e..d3b19f64bea05 100644 --- a/lib/ui/window/pointer_data_packet_converter.cc +++ b/lib/ui/window/pointer_data_packet_converter.cc @@ -293,7 +293,7 @@ void PointerDataPacketConverter::ConvertPointerData( switch (pointer_data.signal_kind) { case PointerData::SignalKind::kScroll: case PointerData::SignalKind::kScrollInertiaCancel: - case PointerData::SignalKind::kStylusAction: + case PointerData::SignalKind::kStylusAuxiliaryAction: case PointerData::SignalKind::kScale: { // Makes sure we have an existing pointer auto iter = states_.find(pointer_data.device); diff --git a/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java b/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java index b3db5df1eb99b..7f2dc081e38e3 100644 --- a/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java +++ b/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java @@ -66,18 +66,36 @@ public class AndroidTouchProcessor { PointerSignalKind.SCROLL, PointerSignalKind.SCROLL_INERTIA_CANCEL, PointerSignalKind.SCALE, + PointerSignalKind.STYLUS_AUXILIARY_ACTION, PointerSignalKind.UNKNOWN }) public @interface PointerSignalKind { int NONE = 0; int SCROLL = 1; int SCROLL_INERTIA_CANCEL = 2; - int SCALE = 3; + int STYLUS_AUXILIARY_ACTION = 3; + int SCALE = 4; + int UNKNOWN = 5; + } + + // Must match the PointerPreferredStylusAuxiliaryAction enum in pointer.dart. + @IntDef({ + PointerPreferredStylusAuxiliaryAction.IGNORE, + PointerPreferredStylusAuxiliaryAction.SHOW_COLOR_PALETTE, + PointerPreferredStylusAuxiliaryAction.SWITCH_ERASER, + PointerPreferredStylusAuxiliaryAction.SWITCH_PREVIOUS, + PointerPreferredStylusAuxiliaryAction.UNKNOWN + }) + public @interface PointerPreferredStylusAuxiliaryAction { + int IGNORE = 0; + int SHOW_COLOR_PALETTE = 1; + int SWITCH_ERASER = 2; + int SWITCH_PREVIOUS = 3; int UNKNOWN = 4; } // Must match the unpacking code in hooks.dart. - private static final int POINTER_DATA_FIELD_COUNT = 35; + private static final int POINTER_DATA_FIELD_COUNT = 36; @VisibleForTesting static final int BYTES_PER_FIELD = 8; // This value must match the value in framework's platform_view.dart. @@ -355,6 +373,8 @@ private void addPointerForIndex( packet.putDouble(1.0); // scale packet.putDouble(0.0); // rotation + packet.putLong(PointerPreferredStylusAuxiliaryAction.IGNORE); // preferred stylus action + if (isTrackpadPan && getPointerChangeForPanZoom(pointerChange) == PointerChange.PAN_ZOOM_END) { ongoingPans.remove(event.getPointerId(pointerIndex)); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index e7fc1004a87e5..6a30923b2f184 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -888,6 +888,8 @@ - (void)dealloc { [_pinchGestureRecognizer release]; _rotationGestureRecognizer.delegate = nil; [_rotationGestureRecognizer release]; + _pencilInteraction.delegate = nil; + [_pencilInteraction release]; [super dealloc]; } @@ -1226,23 +1228,24 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( switch (UIPencilInteraction.preferredTapAction) { case UIPencilPreferredActionIgnore: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kIgnore; + pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; break; case UIPencilPreferredActionShowColorPalette: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kShowColorPalette; + pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; break; case UIPencilPreferredActionSwitchEraser: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchEraser; + pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser; break; case UIPencilPreferredActionSwitchPrevious: - pointer_data.preferred_action = flutter::PointerData::PreferredAction::kSwitchPrevious; + pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious; + break; default: + pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kUnknown; break; } - pointer_data.device = reinterpret_cast(_pencilInteraction); pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; - pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAction; + pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; auto packet = std::make_unique(1); packet->SetPointerData(/*index=*/0, pointer_data); @@ -1720,7 +1723,7 @@ - (void)pressesCancelled:(NSSet*)presses #pragma mark - Orientation updates -- (void)onOrientationPreferencesUpdated:(NSNotification*)notification API_AVAILABLE(ios(12.1)) { +- (void)onOrientationPreferencesUpdated:(NSNotification*)notification { // Notifications may not be on the iOS UI thread dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary* info = notification.userInfo; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 13196d0213e0e..95d9d7b8b552d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1496,9 +1496,18 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { XCTAssertNotNil(mockPencilInteraction); [vc pencilInteractionDidTap:mockPencilInteraction]; + + flutter::PointerData pointer_data; + + pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; + pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; + pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; + + auto packet = std::make_unique(1); + packet->SetPointerData(/*index=*/0, pointer_data); [[[self.mockEngine verify] ignoringNonObjectArgs] - dispatchPointerDataPacket:std::make_unique(0)]; + dispatchPointerDataPacket:std::move(packet)]; } - (void)testFakeEventTimeStamp { diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index cf9956b4ffcd8..90d6a95353de0 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -2019,8 +2019,8 @@ inline flutter::PointerData::SignalKind ToPointerDataSignalKind( return flutter::PointerData::SignalKind::kScrollInertiaCancel; case kFlutterPointerSignalKindScale: return flutter::PointerData::SignalKind::kScale; - case kFlutterPointerSignalKindStylusAction: - return flutter::PointerData::SignalKind::kStylusAction; + case kFlutterPointerSignalKindStylusAuxiliaryAction: + return flutter::PointerData::SignalKind::kStylusAuxiliaryAction; } return flutter::PointerData::SignalKind::kNone; } diff --git a/shell/platform/embedder/embedder.h b/shell/platform/embedder/embedder.h index 5a3e6e4c50e5a..9d8618c146635 100644 --- a/shell/platform/embedder/embedder.h +++ b/shell/platform/embedder/embedder.h @@ -888,7 +888,7 @@ typedef enum { kFlutterPointerSignalKindScroll, kFlutterPointerSignalKindScrollInertiaCancel, kFlutterPointerSignalKindScale, - kFlutterPointerSignalKindStylusAction, + kFlutterPointerSignalKindStylusAuxiliaryAction, } FlutterPointerSignalKind; typedef struct { From 0317a34215d539ab87a399332ef79db62e5a6260 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 2 Feb 2023 16:57:02 -0800 Subject: [PATCH 07/24] formatting n whitespace again --- lib/ui/pointer.dart | 8 ++++---- lib/ui/window/pointer_data.h | 4 ++-- .../embedding/android/AndroidTouchProcessor.java | 10 +++++----- .../ios/framework/Source/FlutterViewController.mm | 15 ++++++++++----- .../framework/Source/FlutterViewControllerTest.mm | 12 ++++++------ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 9f7a97e5ddeeb..c538aca204894 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -144,16 +144,16 @@ enum PointerSignalKind { enum PointerPreferredStylusAuxiliaryAction { /// Ignore pointer input ignore, - + /// Show colour palette if available showColorPalette, - + /// Switch to eraser if available switchEraser, - + /// Switch to previous tool switchPrevious, - + /// unknown preferred action unknown, } diff --git a/lib/ui/window/pointer_data.h b/lib/ui/window/pointer_data.h index e2b3709de627e..41a73ba26b24f 100644 --- a/lib/ui/window/pointer_data.h +++ b/lib/ui/window/pointer_data.h @@ -65,9 +65,9 @@ struct alignas(8) PointerData { kScale, kStylusAuxiliaryAction, }; - + // Must match the PreferredStylusAuxiliaryAction enum in pointer.dart. - + enum class PreferredStylusAuxiliaryAction : int64_t { kIgnore, kShowColorPalette, diff --git a/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java b/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java index 7f2dc081e38e3..8c1fe193746bb 100644 --- a/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java +++ b/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java @@ -80,11 +80,11 @@ public class AndroidTouchProcessor { // Must match the PointerPreferredStylusAuxiliaryAction enum in pointer.dart. @IntDef({ - PointerPreferredStylusAuxiliaryAction.IGNORE, - PointerPreferredStylusAuxiliaryAction.SHOW_COLOR_PALETTE, - PointerPreferredStylusAuxiliaryAction.SWITCH_ERASER, - PointerPreferredStylusAuxiliaryAction.SWITCH_PREVIOUS, - PointerPreferredStylusAuxiliaryAction.UNKNOWN + PointerPreferredStylusAuxiliaryAction.IGNORE, + PointerPreferredStylusAuxiliaryAction.SHOW_COLOR_PALETTE, + PointerPreferredStylusAuxiliaryAction.SWITCH_ERASER, + PointerPreferredStylusAuxiliaryAction.SWITCH_PREVIOUS, + PointerPreferredStylusAuxiliaryAction.UNKNOWN }) public @interface PointerPreferredStylusAuxiliaryAction { int IGNORE = 0; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 6a30923b2f184..39b2c839fe4d6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1228,19 +1228,24 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( switch (UIPencilInteraction.preferredTapAction) { case UIPencilPreferredActionIgnore: - pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; + pointer_data.preferred_auxiliary_stylus_action = + flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; break; case UIPencilPreferredActionShowColorPalette: - pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; + pointer_data.preferred_auxiliary_stylus_action = + flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; break; case UIPencilPreferredActionSwitchEraser: - pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser; + pointer_data.preferred_auxiliary_stylus_action = + flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser; break; case UIPencilPreferredActionSwitchPrevious: - pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious; + pointer_data.preferred_auxiliary_stylus_action = + flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious; break; default: - pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kUnknown; + pointer_data.preferred_auxiliary_stylus_action = + flutter::PointerData::PreferredStylusAuxiliaryAction::kUnknown; break; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 95d9d7b8b552d..c8ab38dfc5052 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1496,18 +1496,18 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { XCTAssertNotNil(mockPencilInteraction); [vc pencilInteractionDidTap:mockPencilInteraction]; - + flutter::PointerData pointer_data; - + pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; - pointer_data.preferred_auxiliary_stylus_action = flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; - + pointer_data.preferred_auxiliary_stylus_action = + flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; + auto packet = std::make_unique(1); packet->SetPointerData(/*index=*/0, pointer_data); - [[[self.mockEngine verify] ignoringNonObjectArgs] - dispatchPointerDataPacket:std::move(packet)]; + [[[self.mockEngine verify] ignoringNonObjectArgs] dispatchPointerDataPacket:std::move(packet)]; } - (void)testFakeEventTimeStamp { From 61296be720e6447afe8d23ebb76d5847874a38a1 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Fri, 3 Feb 2023 15:15:06 -0800 Subject: [PATCH 08/24] add new field to web ui pointer.dart --- lib/web_ui/lib/pointer.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/web_ui/lib/pointer.dart b/lib/web_ui/lib/pointer.dart index 542f5c70c90c3..6c15531df2e80 100644 --- a/lib/web_ui/lib/pointer.dart +++ b/lib/web_ui/lib/pointer.dart @@ -34,6 +34,24 @@ enum PointerSignalKind { unknown } + /// The preferred action for stylus action +enum PointerPreferredStylusAuxiliaryAction { + /// Ignore pointer input + ignore, + + /// Show colour palette if available + showColorPalette, + + /// Switch to eraser if available + switchEraser, + + /// Switch to previous tool + switchPrevious, + + /// unknown preferred action + unknown, +} + class PointerData { const PointerData({ this.embedderId = 0, @@ -71,6 +89,7 @@ class PointerData { this.panDeltaY = 0.0, this.scale = 0.0, this.rotation = 0.0, + this.preferredStylusAuxiliaryAction = PointerPreferredStylusAuxiliaryAction.ignore, }); final int embedderId; final Duration timeStamp; @@ -107,6 +126,7 @@ class PointerData { final double panDeltaY; final double scale; final double rotation; + final PointerPreferredStylusAuxiliaryAction preferredStylusAuxiliaryAction; @override String toString() => 'PointerData(x: $physicalX, y: $physicalY)'; @@ -146,6 +166,7 @@ class PointerData { 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' 'rotation: $rotation' + 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction, ' ')'; } } From 2b5a6b94c71a1b82dc5e74ea0e9a33ebd96ddc7f Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Fri, 3 Feb 2023 15:41:46 -0800 Subject: [PATCH 09/24] update test --- lib/ui/window/pointer_data_packet_converter_unittests.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ui/window/pointer_data_packet_converter_unittests.cc b/lib/ui/window/pointer_data_packet_converter_unittests.cc index 7c4c98162a3eb..fe717c1b44492 100644 --- a/lib/ui/window/pointer_data_packet_converter_unittests.cc +++ b/lib/ui/window/pointer_data_packet_converter_unittests.cc @@ -45,6 +45,7 @@ void CreateSimulatedPointerData(PointerData& data, // NOLINT data.platformData = 0; data.scroll_delta_x = 0.0; data.scroll_delta_y = 0.0; + data.preferred_auxiliary_stylus_action = PointerData::PreferredStylusAuxiliaryAction::kIgnore; } void CreateSimulatedMousePointerData(PointerData& data, // NOLINT @@ -84,6 +85,7 @@ void CreateSimulatedMousePointerData(PointerData& data, // NOLINT data.platformData = 0; data.scroll_delta_x = scroll_delta_x; data.scroll_delta_y = scroll_delta_y; + data.preferred_auxiliary_stylus_action = PointerData::PreferredStylusAuxiliaryAction::kIgnore; } void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT @@ -129,6 +131,7 @@ void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT data.pan_delta_y = 0.0; data.scale = scale; data.rotation = rotation; + data.preferred_auxiliary_stylus_action = PointerData::PreferredStylusAuxiliaryAction::kIgnore; } void UnpackPointerPacket(std::vector& output, // NOLINT From c18f4e997197f41bbd8eb8199eda3c3837b68d4a Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Fri, 3 Feb 2023 15:45:51 -0800 Subject: [PATCH 10/24] whitespace --- lib/ui/window/pointer_data_packet_converter_unittests.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ui/window/pointer_data_packet_converter_unittests.cc b/lib/ui/window/pointer_data_packet_converter_unittests.cc index fe717c1b44492..235f2f9a39c52 100644 --- a/lib/ui/window/pointer_data_packet_converter_unittests.cc +++ b/lib/ui/window/pointer_data_packet_converter_unittests.cc @@ -45,7 +45,8 @@ void CreateSimulatedPointerData(PointerData& data, // NOLINT data.platformData = 0; data.scroll_delta_x = 0.0; data.scroll_delta_y = 0.0; - data.preferred_auxiliary_stylus_action = PointerData::PreferredStylusAuxiliaryAction::kIgnore; + data.preferred_auxiliary_stylus_action = + PointerData::PreferredStylusAuxiliaryAction::kIgnore; } void CreateSimulatedMousePointerData(PointerData& data, // NOLINT @@ -85,7 +86,8 @@ void CreateSimulatedMousePointerData(PointerData& data, // NOLINT data.platformData = 0; data.scroll_delta_x = scroll_delta_x; data.scroll_delta_y = scroll_delta_y; - data.preferred_auxiliary_stylus_action = PointerData::PreferredStylusAuxiliaryAction::kIgnore; + data.preferred_auxiliary_stylus_action = + PointerData::PreferredStylusAuxiliaryAction::kIgnore; } void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT @@ -131,7 +133,8 @@ void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT data.pan_delta_y = 0.0; data.scale = scale; data.rotation = rotation; - data.preferred_auxiliary_stylus_action = PointerData::PreferredStylusAuxiliaryAction::kIgnore; + data.preferred_auxiliary_stylus_action = + PointerData::PreferredStylusAuxiliaryAction::kIgnore; } void UnpackPointerPacket(std::vector& output, // NOLINT From 9f780ceaf9e3d6841810fe11a97bb56043dfadfa Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Fri, 3 Feb 2023 16:15:36 -0800 Subject: [PATCH 11/24] fix test --- shell/common/input_events_unittests.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/common/input_events_unittests.cc b/shell/common/input_events_unittests.cc index 3f117c006c65f..d9d1e52618788 100644 --- a/shell/common/input_events_unittests.cc +++ b/shell/common/input_events_unittests.cc @@ -176,6 +176,8 @@ void CreateSimulatedPointerData(PointerData& data, data.platformData = 0; data.scroll_delta_x = 0.0; data.scroll_delta_y = 0.0; + data.preferred_auxiliary_stylus_action = + PointerData::PreferredStylusAuxiliaryAction::kIgnore; } TEST_F(ShellTest, MissAtMostOneFrameForIrregularInputEvents) { From 2ec968899fef841951c5b4d980ff92cad50caeda Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 6 Feb 2023 16:33:33 -0800 Subject: [PATCH 12/24] PR comments --- .../framework/Source/FlutterViewController.mm | 8 ++--- .../Source/FlutterViewControllerTest.mm | 35 ------------------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 39b2c839fe4d6..9158b7e496fcb 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1221,10 +1221,10 @@ - (void)invalidateTouchRateCorrectionVSyncClient { #pragma mark - Stylus Events -#pragma clang diagnostic push - - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { - flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation]; + flutter::PointerData pointer_data; + pointer_data.Clear(); + pointer_data.time_stamp = [[NSProcessInfo processInfo] systemUptime] * kMicrosecondsPerSecond; switch (UIPencilInteraction.preferredTapAction) { case UIPencilPreferredActionIgnore: @@ -1257,8 +1257,6 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( [_engine.get() dispatchPointerDataPacket:std::move(packet)]; } -#pragma clang diagnostic pop - #pragma mark - Handle view resizing - (void)updateViewportMetrics { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index c8ab38dfc5052..38b4acbfe802f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1324,11 +1324,6 @@ - (void)sendMessage:(id _Nullable)message reply:(FlutterReply _Nullable)callback } - (void)testValidKeyUpEvent API_AVAILABLE(ios(13.4)) { - if (@available(iOS 13.4, *)) { - // noop - } else { - return; - } FlutterEnginePartialMock* mockEngine = [[FlutterEnginePartialMock alloc] init]; mockEngine.keyEventChannel = OCMClassMock([FlutterBasicMessageChannel class]); OCMStub([mockEngine.keyEventChannel sendMessage:[OCMArg any] reply:[OCMArg any]]) @@ -1359,12 +1354,6 @@ - (void)testValidKeyUpEvent API_AVAILABLE(ios(13.4)) { } - (void)testValidKeyDownEvent API_AVAILABLE(ios(13.4)) { - if (@available(iOS 13.4, *)) { - // noop - } else { - return; - } - FlutterEnginePartialMock* mockEngine = [[FlutterEnginePartialMock alloc] init]; mockEngine.keyEventChannel = OCMClassMock([FlutterBasicMessageChannel class]); OCMStub([mockEngine.keyEventChannel sendMessage:[OCMArg any] reply:[OCMArg any]]) @@ -1396,11 +1385,6 @@ - (void)testValidKeyDownEvent API_AVAILABLE(ios(13.4)) { } - (void)testIgnoredKeyEvents API_AVAILABLE(ios(13.4)) { - if (@available(iOS 13.4, *)) { - // noop - } else { - return; - } id keyEventChannel = OCMClassMock([FlutterBasicMessageChannel class]); OCMStub([keyEventChannel sendMessage:[OCMArg any] reply:[OCMArg any]]) .andCall(self, @selector(sendMessage:reply:)); @@ -1434,12 +1418,6 @@ - (void)testIgnoredKeyEvents API_AVAILABLE(ios(13.4)) { } - (void)testPanGestureRecognizer API_AVAILABLE(ios(13.4)) { - if (@available(iOS 13.4, *)) { - // noop - } else { - return; - } - FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil bundle:nil]; @@ -1460,12 +1438,6 @@ - (void)testPanGestureRecognizer API_AVAILABLE(ios(13.4)) { } - (void)testMouseSupport API_AVAILABLE(ios(13.4)) { - if (@available(iOS 13.4, *)) { - // noop - } else { - return; - } - FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil bundle:nil]; @@ -1481,19 +1453,12 @@ - (void)testMouseSupport API_AVAILABLE(ios(13.4)) { } - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { - if (@available(iOS 13.4, *)) { - // noop - } else { - return; - } - FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil bundle:nil]; XCTAssertNotNil(vc); id mockPencilInteraction = OCMClassMock([UIPencilInteraction class]); - XCTAssertNotNil(mockPencilInteraction); [vc pencilInteractionDidTap:mockPencilInteraction]; From a50f55421fff714b1997a6530253553cc8bdfa2c Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 7 Feb 2023 11:07:57 -0800 Subject: [PATCH 13/24] fix test --- .../ios/framework/Source/FlutterViewControllerTest.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 38b4acbfe802f..c74d39f646be5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1460,19 +1460,22 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { id mockPencilInteraction = OCMClassMock([UIPencilInteraction class]); + OCMStub([mockPencilInteraction preferredTapAction]).andReturn(UIPencilPreferredActionShowColorPalette); + [vc pencilInteractionDidTap:mockPencilInteraction]; flutter::PointerData pointer_data; - + pointer_data.Clear(); pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; pointer_data.preferred_auxiliary_stylus_action = - flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; + flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; auto packet = std::make_unique(1); packet->SetPointerData(/*index=*/0, pointer_data); [[[self.mockEngine verify] ignoringNonObjectArgs] dispatchPointerDataPacket:std::move(packet)]; + [mockPencilInteraction stopMocking]; } - (void)testFakeEventTimeStamp { From a27ba22d53ad167a1d836f4b7a68ca0d2a8bc87e Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 7 Feb 2023 11:12:04 -0800 Subject: [PATCH 14/24] whitespace --- .../darwin/ios/framework/Source/FlutterViewControllerTest.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index c74d39f646be5..b8a53ef525500 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1460,7 +1460,8 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { id mockPencilInteraction = OCMClassMock([UIPencilInteraction class]); - OCMStub([mockPencilInteraction preferredTapAction]).andReturn(UIPencilPreferredActionShowColorPalette); + OCMStub([mockPencilInteraction preferredTapAction]) + .andReturn(UIPencilPreferredActionShowColorPalette); [vc pencilInteractionDidTap:mockPencilInteraction]; From 1cdf0ec7ec0dfc74049c8195dffc9f830de3058b Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 9 Feb 2023 13:54:41 -0800 Subject: [PATCH 15/24] fix test by factoring out logic into helper function --- .../framework/Source/FlutterViewController.mm | 14 +++++++--- .../Source/FlutterViewControllerTest.mm | 26 ++++++++++--------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 9158b7e496fcb..cfd96950ce2a5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1222,9 +1222,16 @@ - (void)invalidateTouchRateCorrectionVSyncClient { #pragma mark - Stylus Events - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { + flutter::PointerData pointer_data = [self createAuxillaryStylusActionData]; + + auto packet = std::make_unique(1); + packet->SetPointerData(/*index=*/0, pointer_data); + [_engine.get() dispatchPointerDataPacket:std::move(packet)]; +} + +- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)){ flutter::PointerData pointer_data; pointer_data.Clear(); - pointer_data.time_stamp = [[NSProcessInfo processInfo] systemUptime] * kMicrosecondsPerSecond; switch (UIPencilInteraction.preferredTapAction) { case UIPencilPreferredActionIgnore: @@ -1249,12 +1256,11 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( break; } + pointer_data.time_stamp = [[NSProcessInfo processInfo] systemUptime] * kMicrosecondsPerSecond; pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; - auto packet = std::make_unique(1); - packet->SetPointerData(/*index=*/0, pointer_data); - [_engine.get() dispatchPointerDataPacket:std::move(packet)]; + return pointer_data; } #pragma mark - Handle view resizing diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index b8a53ef525500..3ed4a342dbd0e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -122,6 +122,7 @@ - (void)handlePressEvent:(FlutterUIPressProxy*)press nextAction:(void (^)())next API_AVAILABLE(ios(13.4)); - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer; - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction; +- (flutter::PointerData)createAuxillaryStylusActionData; - (void)updateViewportMetrics; - (void)onUserSettingsChanged:(NSNotification*)notification; - (void)applicationWillTerminate:(NSNotification*)notification; @@ -1463,19 +1464,20 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { OCMStub([mockPencilInteraction preferredTapAction]) .andReturn(UIPencilPreferredActionShowColorPalette); - [vc pencilInteractionDidTap:mockPencilInteraction]; + // Check that the helper function is being called + FlutterViewController* viewControllerMock = OCMPartialMock(vc); + [viewControllerMock pencilInteractionDidTap:mockPencilInteraction]; + OCMVerify([viewControllerMock createAuxillaryStylusActionData]); + + // Check the return value of the helper function + flutter::PointerData pointer_data = [vc createAuxillaryStylusActionData]; + + XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); + XCTAssertEqual(pointer_data.signal_kind, + flutter::PointerData::SignalKind::kStylusAuxiliaryAction); + XCTAssertEqual(pointer_data.preferred_auxiliary_stylus_action, + flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette); - flutter::PointerData pointer_data; - pointer_data.Clear(); - pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; - pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; - pointer_data.preferred_auxiliary_stylus_action = - flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; - - auto packet = std::make_unique(1); - packet->SetPointerData(/*index=*/0, pointer_data); - - [[[self.mockEngine verify] ignoringNonObjectArgs] dispatchPointerDataPacket:std::move(packet)]; [mockPencilInteraction stopMocking]; } From b348378e62d25cca334bb32153c67b512e9fda36 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 9 Feb 2023 13:57:56 -0800 Subject: [PATCH 16/24] whitespace --- .../darwin/ios/framework/Source/FlutterViewController.mm | 2 +- .../darwin/ios/framework/Source/FlutterViewControllerTest.mm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index cfd96950ce2a5..f0dd989bae1ce 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1229,7 +1229,7 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( [_engine.get() dispatchPointerDataPacket:std::move(packet)]; } -- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)){ +- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { flutter::PointerData pointer_data; pointer_data.Clear(); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 3ed4a342dbd0e..e80638998fdad 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1468,10 +1468,10 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { FlutterViewController* viewControllerMock = OCMPartialMock(vc); [viewControllerMock pencilInteractionDidTap:mockPencilInteraction]; OCMVerify([viewControllerMock createAuxillaryStylusActionData]); - + // Check the return value of the helper function flutter::PointerData pointer_data = [vc createAuxillaryStylusActionData]; - + XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); XCTAssertEqual(pointer_data.signal_kind, flutter::PointerData::SignalKind::kStylusAuxiliaryAction); From 4e14bbf4c84a18c8718e73724e5c0a1683126388 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 9 Feb 2023 14:04:37 -0800 Subject: [PATCH 17/24] fix malformed string --- lib/ui/pointer.dart | 2 +- lib/web_ui/lib/pointer.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index c538aca204894..5475320d0e620 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -441,7 +441,7 @@ class PointerData { 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' 'rotation: $rotation' - 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction, ' + 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction' ')'; } } diff --git a/lib/web_ui/lib/pointer.dart b/lib/web_ui/lib/pointer.dart index 6c15531df2e80..d7694cf882e38 100644 --- a/lib/web_ui/lib/pointer.dart +++ b/lib/web_ui/lib/pointer.dart @@ -166,7 +166,7 @@ class PointerData { 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' 'rotation: $rotation' - 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction, ' + 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction' ')'; } } From c8a8cd7b6bb69b0a67a69161dd3d222c3737c237 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 9 Feb 2023 15:37:23 -0800 Subject: [PATCH 18/24] pr comments --- lib/ui/pointer.dart | 2 +- lib/web_ui/lib/pointer.dart | 2 +- .../ios/framework/Source/FlutterViewController.mm | 11 +++++------ .../ios/framework/Source/FlutterViewControllerTest.mm | 6 ++++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 5475320d0e620..4585fbcbf0a87 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -440,7 +440,7 @@ class PointerData { 'panDeltaX: $panDeltaX, ' 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' - 'rotation: $rotation' + 'rotation: $rotation, ' 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction' ')'; } diff --git a/lib/web_ui/lib/pointer.dart b/lib/web_ui/lib/pointer.dart index d7694cf882e38..fd7981bc354a7 100644 --- a/lib/web_ui/lib/pointer.dart +++ b/lib/web_ui/lib/pointer.dart @@ -165,7 +165,7 @@ class PointerData { 'panDeltaX: $panDeltaX, ' 'panDeltaY: $panDeltaY, ' 'scale: $scale, ' - 'rotation: $rotation' + 'rotation: $rotation, ' 'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction' ')'; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index f0dd989bae1ce..0d18ddbd882bd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1222,14 +1222,12 @@ - (void)invalidateTouchRateCorrectionVSyncClient { #pragma mark - Stylus Events - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { - flutter::PointerData pointer_data = [self createAuxillaryStylusActionData]; - - auto packet = std::make_unique(1); - packet->SetPointerData(/*index=*/0, pointer_data); + flutter::PointerDataPacket packet = [self createAuxillaryStylusActionData]; [_engine.get() dispatchPointerDataPacket:std::move(packet)]; } -- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { +- (flutter::PointerDataPacket)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { + auto packet = std::make_unique(1); flutter::PointerData pointer_data; pointer_data.Clear(); @@ -1260,7 +1258,8 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; - return pointer_data; + packet->SetPointerData(/*index=*/0, pointer_data); + return packet; } #pragma mark - Handle view resizing diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index e80638998fdad..485091cb90812 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -122,7 +122,7 @@ - (void)handlePressEvent:(FlutterUIPressProxy*)press nextAction:(void (^)())next API_AVAILABLE(ios(13.4)); - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer; - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction; -- (flutter::PointerData)createAuxillaryStylusActionData; +- (flutter::PointerDataPacket)createAuxillaryStylusActionData; - (void)updateViewportMetrics; - (void)onUserSettingsChanged:(NSNotification*)notification; - (void)applicationWillTerminate:(NSNotification*)notification; @@ -1470,7 +1470,9 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { OCMVerify([viewControllerMock createAuxillaryStylusActionData]); // Check the return value of the helper function - flutter::PointerData pointer_data = [vc createAuxillaryStylusActionData]; + flutter::PointerDataPacket packet = [vc createAuxillaryStylusActionData]; + + flutter::PointerData pointer_data = packet.GetPointerData(0); XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); XCTAssertEqual(pointer_data.signal_kind, From 69d1035356ec1ab18fb3c9cd34afad578d72e7a5 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 9 Feb 2023 16:09:27 -0800 Subject: [PATCH 19/24] fix type issue --- .../darwin/ios/framework/Source/FlutterViewController.mm | 4 ++-- .../ios/framework/Source/FlutterViewControllerTest.mm | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 0d18ddbd882bd..ab55c154c1737 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1222,11 +1222,11 @@ - (void)invalidateTouchRateCorrectionVSyncClient { #pragma mark - Stylus Events - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { - flutter::PointerDataPacket packet = [self createAuxillaryStylusActionData]; + auto packet = [self createAuxillaryStylusActionData]; [_engine.get() dispatchPointerDataPacket:std::move(packet)]; } -- (flutter::PointerDataPacket)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { +- (std::unique_ptr)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { auto packet = std::make_unique(1); flutter::PointerData pointer_data; pointer_data.Clear(); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 485091cb90812..37cc144830982 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -122,7 +122,7 @@ - (void)handlePressEvent:(FlutterUIPressProxy*)press nextAction:(void (^)())next API_AVAILABLE(ios(13.4)); - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer; - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction; -- (flutter::PointerDataPacket)createAuxillaryStylusActionData; +- (std::unique_ptr)createAuxillaryStylusActionData; - (void)updateViewportMetrics; - (void)onUserSettingsChanged:(NSNotification*)notification; - (void)applicationWillTerminate:(NSNotification*)notification; @@ -1470,9 +1470,9 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { OCMVerify([viewControllerMock createAuxillaryStylusActionData]); // Check the return value of the helper function - flutter::PointerDataPacket packet = [vc createAuxillaryStylusActionData]; + std::unique_ptr packet = [vc createAuxillaryStylusActionData]; - flutter::PointerData pointer_data = packet.GetPointerData(0); + flutter::PointerData pointer_data = packet->GetPointerData(0); XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); XCTAssertEqual(pointer_data.signal_kind, From b162cbca1574bdc656870ea8db4c7cbb0e95b33a Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 9 Feb 2023 16:11:52 -0800 Subject: [PATCH 20/24] sigh whitespace --- .../darwin/ios/framework/Source/FlutterViewController.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ab55c154c1737..d00cd91eb1016 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1226,7 +1226,8 @@ - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE( [_engine.get() dispatchPointerDataPacket:std::move(packet)]; } -- (std::unique_ptr)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { +- (std::unique_ptr) + createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { auto packet = std::make_unique(1); flutter::PointerData pointer_data; pointer_data.Clear(); From 912a4ccb8bd1d8a8c3a6f72d85f0366b88e4c116 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Fri, 10 Feb 2023 15:33:05 -0800 Subject: [PATCH 21/24] revert test changes :) --- .../ios/framework/Source/FlutterViewController.mm | 12 ++++++------ .../framework/Source/FlutterViewControllerTest.mm | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 5177aa2c0c9c3..27fa78f420282 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1231,13 +1231,14 @@ - (void)invalidateTouchRateCorrectionVSyncClient { #pragma mark - Stylus Events - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { - auto packet = [self createAuxillaryStylusActionData]; + flutter::PointerData pointer_data = [self createAuxillaryStylusActionData]; + + auto packet = std::make_unique(1); + packet->SetPointerData(/*index=*/0, pointer_data); [_engine.get() dispatchPointerDataPacket:std::move(packet)]; } -- (std::unique_ptr) - createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { - auto packet = std::make_unique(1); +- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { flutter::PointerData pointer_data; pointer_data.Clear(); @@ -1268,8 +1269,7 @@ createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; - packet->SetPointerData(/*index=*/0, pointer_data); - return packet; + return pointer_data; } #pragma mark - Handle view resizing diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 62a349a981b65..9a36419cebf4d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -111,7 +111,8 @@ @interface FlutterEmbedderKeyResponder (Tests) @property(nonatomic, copy, readonly) FlutterSendKeyEvent sendEvent; @end -@interface FlutterViewController (Tests) +@interface FlutterViewController (Tests) +; @property(nonatomic, assign) double targetViewInsetBottom; @property(nonatomic, assign) BOOL isKeyboardInOrTransitioningFromBackground; @@ -123,8 +124,7 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences; - (void)handlePressEvent:(FlutterUIPressProxy*)press nextAction:(void (^)())next API_AVAILABLE(ios(13.4)); - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer; -- (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction; -- (std::unique_ptr)createAuxillaryStylusActionData; +- (flutter::PointerData)createAuxillaryStylusActionData; - (void)updateViewportMetrics; - (void)onUserSettingsChanged:(NSNotification*)notification; - (void)applicationWillTerminate:(NSNotification*)notification; @@ -1621,9 +1621,7 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { OCMVerify([viewControllerMock createAuxillaryStylusActionData]); // Check the return value of the helper function - std::unique_ptr packet = [vc createAuxillaryStylusActionData]; - - flutter::PointerData pointer_data = packet->GetPointerData(0); + flutter::PointerData pointer_data = [vc createAuxillaryStylusActionData]; XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); XCTAssertEqual(pointer_data.signal_kind, From 1393faeb8bccb7521c598cc885f0de48ff8d60ac Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 13 Feb 2023 11:40:03 -0800 Subject: [PATCH 22/24] pr comments + separate out tests --- .../android/AndroidTouchProcessor.java | 4 +- .../Source/FlutterViewControllerTest.mm | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java b/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java index 8c1fe193746bb..ea36686e7c8b7 100644 --- a/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java +++ b/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java @@ -73,8 +73,8 @@ public class AndroidTouchProcessor { int NONE = 0; int SCROLL = 1; int SCROLL_INERTIA_CANCEL = 2; - int STYLUS_AUXILIARY_ACTION = 3; - int SCALE = 4; + int SCALE = 3; + int STYLUS_AUXILIARY_ACTION = 4; int UNKNOWN = 5; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 9a36419cebf4d..995238e65f5fe 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1620,6 +1620,20 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { [viewControllerMock pencilInteractionDidTap:mockPencilInteraction]; OCMVerify([viewControllerMock createAuxillaryStylusActionData]); + [mockPencilInteraction stopMocking]; +} + +- (void)testPencilHelperFunction API_AVAILABLE(ios(13.4)) { + FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine + nibName:nil + bundle:nil]; + XCTAssertNotNil(vc); + + id mockPencilInteraction = OCMClassMock([UIPencilInteraction class]); + + OCMExpect([mockPencilInteraction preferredTapAction]) + .andReturn(UIPencilPreferredActionShowColorPalette); + // Check the return value of the helper function flutter::PointerData pointer_data = [vc createAuxillaryStylusActionData]; @@ -1629,6 +1643,38 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { XCTAssertEqual(pointer_data.preferred_auxiliary_stylus_action, flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette); + OCMExpect([mockPencilInteraction preferredTapAction]) + .andReturn(UIPencilPreferredActionSwitchEraser); + + pointer_data = [vc createAuxillaryStylusActionData]; + + XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); + XCTAssertEqual(pointer_data.signal_kind, + flutter::PointerData::SignalKind::kStylusAuxiliaryAction); + XCTAssertEqual(pointer_data.preferred_auxiliary_stylus_action, + flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser); + + OCMExpect([mockPencilInteraction preferredTapAction]) + .andReturn(UIPencilPreferredActionSwitchPrevious); + + pointer_data = [vc createAuxillaryStylusActionData]; + + XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); + XCTAssertEqual(pointer_data.signal_kind, + flutter::PointerData::SignalKind::kStylusAuxiliaryAction); + XCTAssertEqual(pointer_data.preferred_auxiliary_stylus_action, + flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious); + + OCMExpect([mockPencilInteraction preferredTapAction]).andReturn(UIPencilPreferredActionIgnore); + + pointer_data = [vc createAuxillaryStylusActionData]; + + XCTAssertEqual(pointer_data.kind, flutter::PointerData::DeviceKind::kStylus); + XCTAssertEqual(pointer_data.signal_kind, + flutter::PointerData::SignalKind::kStylusAuxiliaryAction); + XCTAssertEqual(pointer_data.preferred_auxiliary_stylus_action, + flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore); + [mockPencilInteraction stopMocking]; } From 9527282ad63f04bfd0b9d05c12dad9eec7caa23a Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 13 Feb 2023 11:41:59 -0800 Subject: [PATCH 23/24] extra space --- lib/ui/window/pointer_data.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ui/window/pointer_data.h b/lib/ui/window/pointer_data.h index 41a73ba26b24f..1dc159554ad74 100644 --- a/lib/ui/window/pointer_data.h +++ b/lib/ui/window/pointer_data.h @@ -67,7 +67,6 @@ struct alignas(8) PointerData { }; // Must match the PreferredStylusAuxiliaryAction enum in pointer.dart. - enum class PreferredStylusAuxiliaryAction : int64_t { kIgnore, kShowColorPalette, From b09a991ffce544e833a216ee61ad0df756ba221e Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Mon, 13 Feb 2023 13:01:02 -0800 Subject: [PATCH 24/24] change test name --- .../darwin/ios/framework/Source/FlutterViewControllerTest.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 995238e65f5fe..21110edf73fe2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1623,7 +1623,7 @@ - (void)testPencilSupport API_AVAILABLE(ios(13.4)) { [mockPencilInteraction stopMocking]; } -- (void)testPencilHelperFunction API_AVAILABLE(ios(13.4)) { +- (void)testCreateAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil bundle:nil];