|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
69 | 69 | // Tracks pressed modifier keys
|
70 | 70 | static NSUInteger s_modifierFlags = 0;
|
71 | 71 |
|
| 72 | +@interface GlassViewDelegate (hidden) |
| 73 | +- (void)maybeBeginGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask; |
| 74 | +- (void)maybeEndGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask; |
| 75 | +@end |
| 76 | + |
72 | 77 | // Extracted from class-dump utility output for NSEvent class
|
73 | 78 | @interface NSEvent (hidden)
|
74 | 79 |
|
@@ -150,6 +155,7 @@ - (id)initWithView:(NSView*)view withJview:(jobject)jview
|
150 | 155 | self->mouseDownMask = 0;
|
151 | 156 |
|
152 | 157 | self->gestureInProgress = NO;
|
| 158 | + self->gesturesBeganMask = 0; |
153 | 159 |
|
154 | 160 | self->nativeFullScreenModeWindow = nil;
|
155 | 161 |
|
@@ -845,6 +851,72 @@ - (void)sendJavaGestureEndEvent:(NSEvent *)theEvent
|
845 | 851 | GLASS_CHECK_EXCEPTION(env);
|
846 | 852 | }
|
847 | 853 |
|
| 854 | +/* |
| 855 | + * This method is a replacement for the deprecated beginGestureWithEvent |
| 856 | + * method, which is no longer delivered to a View by macOS. This |
| 857 | + * is called for each gesture event to track the beginning of a |
| 858 | + * gesture using the phase of the event. We call sendJavaGestureBeginEvent |
| 859 | + * if there are no other gestures active. |
| 860 | + */ |
| 861 | +- (void)maybeBeginGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask |
| 862 | +{ |
| 863 | + NSEventPhase phase = [theEvent phase]; |
| 864 | + if (phase == NSEventPhaseBegan) { |
| 865 | + if (gesturesBeganMask == 0) { |
| 866 | + [self sendJavaGestureBeginEvent:theEvent]; |
| 867 | + } |
| 868 | + gesturesBeganMask |= theMask; |
| 869 | + } |
| 870 | +} |
| 871 | + |
| 872 | +/* |
| 873 | + * This method is a replacement for the deprecated endGestureWithEvent |
| 874 | + * method, which is no longer delivered to a View by macOS. This |
| 875 | + * is called for each gesture event to track the end of a |
| 876 | + * gesture using the phase of the event. We call sendJavaGestureEndEvent |
| 877 | + * if there are no other gestures active. |
| 878 | + */ |
| 879 | +- (void)maybeEndGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask |
| 880 | +{ |
| 881 | + NSEventPhase phase = [theEvent phase]; |
| 882 | + if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled) { |
| 883 | + if ((gesturesBeganMask & theMask) != 0) { |
| 884 | + gesturesBeganMask &= ~theMask; |
| 885 | + if (gesturesBeganMask == 0) { |
| 886 | + [self sendJavaGestureEndEvent:theEvent]; |
| 887 | + } |
| 888 | + } |
| 889 | + } |
| 890 | +} |
| 891 | + |
| 892 | +- (void)doRotateWithEvent:(NSEvent *)theEvent |
| 893 | +{ |
| 894 | + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_ROTATE]; |
| 895 | + [self sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_ROTATE]; |
| 896 | + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_ROTATE]; |
| 897 | +} |
| 898 | + |
| 899 | +- (void)doSwipeWithEvent:(NSEvent *)theEvent |
| 900 | +{ |
| 901 | + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_SWIPE]; |
| 902 | + [self sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_SWIPE]; |
| 903 | + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_SWIPE]; |
| 904 | +} |
| 905 | + |
| 906 | +- (void)doMagnifyWithEvent:(NSEvent *)theEvent |
| 907 | +{ |
| 908 | + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_MAGNIFY]; |
| 909 | + [self sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_MAGNIFY]; |
| 910 | + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_MAGNIFY]; |
| 911 | +} |
| 912 | + |
| 913 | +- (void)doScrollWheel:(NSEvent *)theEvent |
| 914 | +{ |
| 915 | + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_SCROLL]; |
| 916 | + [self sendJavaMouseEvent:theEvent]; |
| 917 | + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_SCROLL]; |
| 918 | +} |
| 919 | + |
848 | 920 | - (NSDragOperation)sendJavaDndEvent:(id <NSDraggingInfo>)info type:(jint)type
|
849 | 921 | {
|
850 | 922 | GET_MAIN_JENV;
|
|
0 commit comments