Skip to content

Commit 247a65d

Browse files
8236971: [macos] Gestures handled incorrectly due to missing events
Reviewed-by: mpaus, arapte
1 parent 560ef17 commit 247a65d

File tree

4 files changed

+97
-32
lines changed

4 files changed

+97
-32
lines changed

modules/javafx.graphics/src/main/native-glass/mac/GlassView2D.m

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -215,32 +215,22 @@ - (void)otherMouseUp:(NSEvent *)theEvent
215215

216216
- (void)rotateWithEvent:(NSEvent *)theEvent
217217
{
218-
[self->delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_ROTATE];
218+
[self->delegate doRotateWithEvent:theEvent];
219219
}
220220

221221
- (void)swipeWithEvent:(NSEvent *)theEvent
222222
{
223-
[self->delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_SWIPE];
223+
[self->delegate doSwipeWithEvent:theEvent];
224224
}
225225

226226
- (void)magnifyWithEvent:(NSEvent *)theEvent
227227
{
228-
[self->delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_MAGNIFY];
229-
}
230-
231-
- (void)endGestureWithEvent:(NSEvent *)theEvent
232-
{
233-
[self->delegate sendJavaGestureEndEvent:theEvent];
234-
}
235-
236-
- (void)beginGestureWithEvent:(NSEvent *)theEvent
237-
{
238-
[self->delegate sendJavaGestureBeginEvent:theEvent];
228+
[self->delegate doMagnifyWithEvent:theEvent];
239229
}
240230

241231
- (void)scrollWheel:(NSEvent *)theEvent
242232
{
243-
[self->delegate sendJavaMouseEvent:theEvent];
233+
[self->delegate doScrollWheel:theEvent];
244234
}
245235

246236
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent

modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -441,33 +441,23 @@ - (void)otherMouseUp:(NSEvent *)theEvent
441441

442442
- (void)rotateWithEvent:(NSEvent *)theEvent
443443
{
444-
[self->_delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_ROTATE];
444+
[self->_delegate doRotateWithEvent:theEvent];
445445
}
446446

447447
- (void)swipeWithEvent:(NSEvent *)theEvent
448448
{
449-
[self->_delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_SWIPE];
449+
[self->_delegate doSwipeWithEvent:theEvent];
450450
}
451451

452452
- (void)magnifyWithEvent:(NSEvent *)theEvent
453453
{
454-
[self->_delegate sendJavaGestureEvent:theEvent type:com_sun_glass_ui_mac_MacGestureSupport_GESTURE_MAGNIFY];
455-
}
456-
457-
- (void)endGestureWithEvent:(NSEvent *)theEvent
458-
{
459-
[self->_delegate sendJavaGestureEndEvent:theEvent];
460-
}
461-
462-
- (void)beginGestureWithEvent:(NSEvent *)theEvent
463-
{
464-
[self->_delegate sendJavaGestureBeginEvent:theEvent];
454+
[self->_delegate doMagnifyWithEvent:theEvent];
465455
}
466456

467457
- (void)scrollWheel:(NSEvent *)theEvent
468458
{
469459
MOUSELOG("scrollWheel");
470-
[self->_delegate sendJavaMouseEvent:theEvent];
460+
[self->_delegate doScrollWheel:theEvent];
471461
}
472462

473463
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent

modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,14 @@
3131
#import "GlassDragSource.h"
3232
#import "GlassAccessible.h"
3333

34+
// Bit mask for tracking gesture begin / end
35+
typedef enum GestureMaskType {
36+
GESTURE_MASK_SCROLL = 1 << 0,
37+
GESTURE_MASK_SWIPE = 1 << 1,
38+
GESTURE_MASK_ROTATE = 1 << 2,
39+
GESTURE_MASK_MAGNIFY = 1 << 3,
40+
} GestureMaskType;
41+
3442
// helper class that implements the custom GlassView functionality
3543
@interface GlassViewDelegate : NSObject <GlassDragSourceDelegate>
3644
{
@@ -51,6 +59,7 @@
5159
int mouseDownMask; // bit 0 - left, 1 - right, 2 - other button
5260

5361
BOOL gestureInProgress;
62+
GestureMaskType gesturesBeganMask;
5463

5564
NSEvent *lastEvent;
5665

@@ -84,6 +93,10 @@
8493
- (void)sendJavaGestureEvent:(NSEvent *)theEvent type:(int)type;
8594
- (void)sendJavaGestureBeginEvent:(NSEvent *)theEvent;
8695
- (void)sendJavaGestureEndEvent:(NSEvent *)theEvent;
96+
- (void)doRotateWithEvent:(NSEvent *)theEvent;
97+
- (void)doSwipeWithEvent:(NSEvent *)theEvent;
98+
- (void)doMagnifyWithEvent:(NSEvent *)theEvent;
99+
- (void)doScrollWheel:(NSEvent *)theEvent;
87100

88101
- (NSDragOperation)sendJavaDndEvent:(id <NSDraggingInfo>)info type:(jint)type;
89102

modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -69,6 +69,11 @@
6969
// Tracks pressed modifier keys
7070
static NSUInteger s_modifierFlags = 0;
7171

72+
@interface GlassViewDelegate (hidden)
73+
- (void)maybeBeginGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask;
74+
- (void)maybeEndGestureWithEvent:(NSEvent *)theEvent withMask:(GestureMaskType)theMask;
75+
@end
76+
7277
// Extracted from class-dump utility output for NSEvent class
7378
@interface NSEvent (hidden)
7479

@@ -150,6 +155,7 @@ - (id)initWithView:(NSView*)view withJview:(jobject)jview
150155
self->mouseDownMask = 0;
151156

152157
self->gestureInProgress = NO;
158+
self->gesturesBeganMask = 0;
153159

154160
self->nativeFullScreenModeWindow = nil;
155161

@@ -845,6 +851,72 @@ - (void)sendJavaGestureEndEvent:(NSEvent *)theEvent
845851
GLASS_CHECK_EXCEPTION(env);
846852
}
847853

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+
848920
- (NSDragOperation)sendJavaDndEvent:(id <NSDraggingInfo>)info type:(jint)type
849921
{
850922
GET_MAIN_JENV;

0 commit comments

Comments
 (0)