diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassView2D.m b/modules/javafx.graphics/src/main/native-glass/mac/GlassView2D.m index c6878103819..e79f78e6b8a 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassView2D.m +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassView2D.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -215,32 +215,22 @@ - (void)otherMouseUp:(NSEvent *)theEvent - (void)rotateWithEvent:(NSEvent *)theEvent { - [self->delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_ROTATE]; + [self->delegate doRotateWithEvent:theEvent]; } - (void)swipeWithEvent:(NSEvent *)theEvent { - [self->delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_SWIPE]; + [self->delegate doSwipeWithEvent:theEvent]; } - (void)magnifyWithEvent:(NSEvent *)theEvent { - [self->delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_MAGNIFY]; -} - -- (void)endGestureWithEvent:(NSEvent *)theEvent -{ - [self->delegate sendJavaGestureEndEvent:theEvent]; -} - -- (void)beginGestureWithEvent:(NSEvent *)theEvent -{ - [self->delegate sendJavaGestureBeginEvent:theEvent]; + [self->delegate doMagnifyWithEvent:theEvent]; } - (void)scrollWheel:(NSEvent *)theEvent { - [self->delegate sendJavaMouseEvent:theEvent]; + [self->delegate doScrollWheel:theEvent]; } - (BOOL)performKeyEquivalent:(NSEvent *)theEvent diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m b/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m index b4ccd9c1a3c..9001f78d91d 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -441,33 +441,23 @@ - (void)otherMouseUp:(NSEvent *)theEvent - (void)rotateWithEvent:(NSEvent *)theEvent { - [self->_delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_ROTATE]; + [self->_delegate doRotateWithEvent:theEvent]; } - (void)swipeWithEvent:(NSEvent *)theEvent { - [self->_delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_SWIPE]; + [self->_delegate doSwipeWithEvent:theEvent]; } - (void)magnifyWithEvent:(NSEvent *)theEvent { - [self->_delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_MAGNIFY]; -} - -- (void)endGestureWithEvent:(NSEvent *)theEvent -{ - [self->_delegate sendJavaGestureEndEvent:theEvent]; -} - -- (void)beginGestureWithEvent:(NSEvent *)theEvent -{ - [self->_delegate sendJavaGestureBeginEvent:theEvent]; + [self->_delegate doMagnifyWithEvent:theEvent]; } - (void)scrollWheel:(NSEvent *)theEvent { MOUSELOG("scrollWheel"); - [self->_delegate sendJavaMouseEvent:theEvent]; + [self->_delegate doScrollWheel:theEvent]; } - (BOOL)performKeyEquivalent:(NSEvent *)theEvent diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.h b/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.h index 5a06a290a38..88bda213f5d 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.h +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,6 +31,14 @@ #import "GlassDragSource.h" #import "GlassAccessible.h" +// Bit mask for tracking gesture begin / end +typedef enum GestureMaskType { + GESTURE_MASK_SCROLL = 1 << 0, + GESTURE_MASK_SWIPE = 1 << 1, + GESTURE_MASK_ROTATE = 1 << 2, + GESTURE_MASK_MAGNIFY = 1 << 3, +} GestureMaskType; + // helper class that implements the custom GlassView functionality @interface GlassViewDelegate : NSObject { @@ -51,6 +59,7 @@ int mouseDownMask; // bit 0 - left, 1 - right, 2 - other button BOOL gestureInProgress; + GestureMaskType gesturesBeganMask; NSEvent *lastEvent; @@ -84,6 +93,10 @@ - (void)sendJavaGestureEvent:(NSEvent *)theEvent type:(int)type; - (void)sendJavaGestureBeginEvent:(NSEvent *)theEvent; - (void)sendJavaGestureEndEvent:(NSEvent *)theEvent; +- (void)doRotateWithEvent:(NSEvent *)theEvent; +- (void)doSwipeWithEvent:(NSEvent *)theEvent; +- (void)doMagnifyWithEvent:(NSEvent *)theEvent; +- (void)doScrollWheel:(NSEvent *)theEvent; - (NSDragOperation)sendJavaDndEvent:(id )info type:(jint)type; diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m b/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m index 004bf8aacc0..54da01544eb 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -69,6 +69,11 @@ // Tracks pressed modifier keys static NSUInteger s_modifierFlags = 0; +@interface GlassViewDelegate (hidden) +- (void)maybeBeginGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask; +- (void)maybeEndGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask; +@end + // Extracted from class-dump utility output for NSEvent class @interface NSEvent (hidden) @@ -150,6 +155,7 @@ - (id)initWithView:(NSView*)view withJview:(jobject)jview self->mouseDownMask = 0; self->gestureInProgress = NO; + self->gesturesBeganMask = 0; self->nativeFullScreenModeWindow = nil; @@ -845,6 +851,72 @@ - (void)sendJavaGestureEndEvent:(NSEvent *)theEvent GLASS_CHECK_EXCEPTION(env); } +/* + * This method is a replacement for the deprecated beginGestureWithEvent + * method, which is no longer delivered to a View by macOS. This + * is called for each gesture event to track the beginning of a + * gesture using the phase of the event. We call sendJavaGestureBeginEvent + * if there are no other gestures active. + */ +- (void)maybeBeginGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask +{ + NSEventPhase phase = [theEvent phase]; + if (phase == NSEventPhaseBegan) { + if (gesturesBeganMask == 0) { + [self sendJavaGestureBeginEvent:theEvent]; + } + gesturesBeganMask |= theMask; + } +} + +/* + * This method is a replacement for the deprecated endGestureWithEvent + * method, which is no longer delivered to a View by macOS. This + * is called for each gesture event to track the end of a + * gesture using the phase of the event. We call sendJavaGestureEndEvent + * if there are no other gestures active. + */ +- (void)maybeEndGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask +{ + NSEventPhase phase = [theEvent phase]; + if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled) { + if ((gesturesBeganMask & theMask) != 0) { + gesturesBeganMask &= ~theMask; + if (gesturesBeganMask == 0) { + [self sendJavaGestureEndEvent:theEvent]; + } + } + } +} + +- (void)doRotateWithEvent:(NSEvent *)theEvent +{ + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_ROTATE]; + [self sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_ROTATE]; + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_ROTATE]; +} + +- (void)doSwipeWithEvent:(NSEvent *)theEvent +{ + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_SWIPE]; + [self sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_SWIPE]; + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_SWIPE]; +} + +- (void)doMagnifyWithEvent:(NSEvent *)theEvent +{ + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_MAGNIFY]; + [self sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_MAGNIFY]; + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_MAGNIFY]; +} + +- (void)doScrollWheel:(NSEvent *)theEvent +{ + [self maybeBeginGestureWithEvent:theEvent withMask:GESTURE_MASK_SCROLL]; + [self sendJavaMouseEvent:theEvent]; + [self maybeEndGestureWithEvent:theEvent withMask:GESTURE_MASK_SCROLL]; +} + - (NSDragOperation)sendJavaDndEvent:(id )info type:(jint)type { GET_MAIN_JENV;