718 OCMStub([engineMock renderer]).andReturn(renderer_);
719 __block
bool called =
false;
720 __block FlutterPointerEvent last_event;
722 .andDo((^(NSInvocation* invocation) {
723 FlutterPointerEvent* event;
724 [invocation getArgument:&event atIndex:2];
732 [viewController loadView];
736 CGEventRef cgEventStart = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
737 CGEventSetType(cgEventStart, kCGEventScrollWheel);
738 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventScrollPhase, kCGScrollPhaseBegan);
739 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventIsContinuous, 1);
742 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventStart]];
744 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
745 EXPECT_EQ(last_event.phase, kPanZoomStart);
746 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
747 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
750 CGEventRef cgEventUpdate = CGEventCreateCopy(cgEventStart);
751 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventScrollPhase, kCGScrollPhaseChanged);
752 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis2, 1);
753 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis1, 2);
756 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
758 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
759 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
760 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
761 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
762 EXPECT_EQ(last_event.pan_x, 8 * viewController.flutterView.layer.contentsScale);
763 EXPECT_EQ(last_event.pan_y, 16 * viewController.flutterView.layer.contentsScale);
767 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
769 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
770 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
771 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
772 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
773 EXPECT_EQ(last_event.pan_x, 16 * viewController.flutterView.layer.contentsScale);
774 EXPECT_EQ(last_event.pan_y, 32 * viewController.flutterView.layer.contentsScale);
777 CGEventRef cgEventEnd = CGEventCreateCopy(cgEventStart);
778 CGEventSetIntegerValueField(cgEventEnd, kCGScrollWheelEventScrollPhase, kCGScrollPhaseEnded);
781 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventEnd]];
783 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
784 EXPECT_EQ(last_event.phase, kPanZoomEnd);
785 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
786 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
789 CGEventRef cgEventMomentumStart = CGEventCreateCopy(cgEventStart);
790 CGEventSetIntegerValueField(cgEventMomentumStart, kCGScrollWheelEventScrollPhase, 0);
791 CGEventSetIntegerValueField(cgEventMomentumStart, kCGScrollWheelEventMomentumPhase,
792 kCGMomentumScrollPhaseBegin);
795 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumStart]];
796 EXPECT_FALSE(called);
799 CGEventRef cgEventMomentumUpdate = CGEventCreateCopy(cgEventStart);
800 CGEventSetIntegerValueField(cgEventMomentumUpdate, kCGScrollWheelEventScrollPhase, 0);
801 CGEventSetIntegerValueField(cgEventMomentumUpdate, kCGScrollWheelEventMomentumPhase,
802 kCGMomentumScrollPhaseContinue);
805 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumUpdate]];
806 EXPECT_FALSE(called);
809 id touchMock = OCMClassMock([NSTouch
class]);
810 NSSet* touchSet = [NSSet setWithObject:touchMock];
811 id touchEventMock1 = OCMClassMock([NSEvent
class]);
812 OCMStub([touchEventMock1 allTouches]).andReturn(touchSet);
813 CGPoint touchLocation = {0, 0};
814 OCMStub([touchEventMock1 locationInWindow]).andReturn(touchLocation);
815 OCMStub([(NSEvent*)touchEventMock1 timestamp]).andReturn(0.150);
819 [viewController touchesBeganWithEvent:touchEventMock1];
820 EXPECT_FALSE(called);
823 id touchEventMock2 = OCMClassMock([NSEvent
class]);
824 OCMStub([touchEventMock2 allTouches]).andReturn(touchSet);
825 OCMStub([touchEventMock2 locationInWindow]).andReturn(touchLocation);
826 OCMStub([(NSEvent*)touchEventMock2 timestamp]).andReturn(0.005);
830 [viewController touchesBeganWithEvent:touchEventMock2];
832 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScrollInertiaCancel);
833 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
836 CGEventRef cgEventMomentumEnd = CGEventCreateCopy(cgEventStart);
837 CGEventSetIntegerValueField(cgEventMomentumEnd, kCGScrollWheelEventScrollPhase, 0);
838 CGEventSetIntegerValueField(cgEventMomentumEnd, kCGScrollWheelEventMomentumPhase,
839 kCGMomentumScrollPhaseEnd);
842 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumEnd]];
843 EXPECT_FALSE(called);
846 CGEventRef cgEventMayBegin = CGEventCreateCopy(cgEventStart);
847 CGEventSetIntegerValueField(cgEventMayBegin, kCGScrollWheelEventScrollPhase,
848 kCGScrollPhaseMayBegin);
851 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMayBegin]];
853 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
854 EXPECT_EQ(last_event.phase, kPanZoomStart);
855 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
856 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
859 CGEventRef cgEventCancel = CGEventCreateCopy(cgEventStart);
860 CGEventSetIntegerValueField(cgEventCancel, kCGScrollWheelEventScrollPhase,
861 kCGScrollPhaseCancelled);
864 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventCancel]];
866 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
867 EXPECT_EQ(last_event.phase, kPanZoomEnd);
868 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
869 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
872 CGEventRef cgEventDiscrete = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
873 CGEventSetType(cgEventDiscrete, kCGEventScrollWheel);
874 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventIsContinuous, 0);
875 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventDeltaAxis2, 1);
876 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventDeltaAxis1, 2);
879 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventDiscrete]];
881 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScroll);
883 EXPECT_EQ(last_event.scroll_delta_x, -40 * viewController.flutterView.layer.contentsScale);
884 EXPECT_EQ(last_event.scroll_delta_y, -80 * viewController.flutterView.layer.contentsScale);
888 CGEventRef cgEventDiscreteShift =
889 CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
890 CGEventSetType(cgEventDiscreteShift, kCGEventScrollWheel);
892 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventIsContinuous, 0);
893 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventDeltaAxis2,
895 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventDeltaAxis1,
899 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventDiscreteShift]];
901 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScroll);
903 EXPECT_FLOAT_EQ(last_event.scroll_delta_x, 0.0 * viewController.flutterView.layer.contentsScale);
904 EXPECT_FLOAT_EQ(last_event.scroll_delta_y,
905 -80.0 * viewController.flutterView.layer.contentsScale);
910 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
911 NSEventPhaseBegan, 1, 0)];
913 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
914 EXPECT_EQ(last_event.phase, kPanZoomStart);
915 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
916 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
920 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
921 NSEventPhaseChanged, 1, 0)];
923 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
924 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
925 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
926 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
927 EXPECT_EQ(last_event.pan_x, 0);
928 EXPECT_EQ(last_event.pan_y, 0);
929 EXPECT_EQ(last_event.scale, 2);
931 EXPECT_EQ(last_event.rotation, 0);
935 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
936 NSEventPhaseChanged, 1, 0)];
938 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
939 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
940 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
941 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
942 EXPECT_EQ(last_event.pan_x, 0);
943 EXPECT_EQ(last_event.pan_y, 0);
944 EXPECT_EQ(last_event.scale, 4);
946 EXPECT_EQ(last_event.rotation, 0);
950 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
951 NSEventPhaseEnded, 0, 0)];
953 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
954 EXPECT_EQ(last_event.phase, kPanZoomEnd);
955 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
956 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
961 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
962 NSEventPhaseBegan, 1, 0)];
964 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
965 EXPECT_EQ(last_event.phase, kPanZoomStart);
966 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
967 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
971 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
972 NSEventTypeRotate, NSEventPhaseChanged, 0, -180)];
974 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
975 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
976 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
977 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
978 EXPECT_EQ(last_event.pan_x, 0);
979 EXPECT_EQ(last_event.pan_y, 0);
980 EXPECT_EQ(last_event.scale, 1);
981 EXPECT_EQ(last_event.rotation, M_PI);
985 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
986 NSEventTypeRotate, NSEventPhaseChanged, 0, -360)];
988 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
989 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
990 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
991 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
992 EXPECT_EQ(last_event.pan_x, 0);
993 EXPECT_EQ(last_event.pan_y, 0);
994 EXPECT_EQ(last_event.scale, 1);
995 EXPECT_EQ(last_event.rotation, 3 * M_PI);
999 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
1000 NSEventPhaseEnded, 0, 0)];
1001 EXPECT_TRUE(called);
1002 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1003 EXPECT_EQ(last_event.phase, kPanZoomEnd);
1004 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
1005 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1009 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
1010 NSEventPhaseCancelled, 0, 0)];
1011 EXPECT_FALSE(called);