Skip to content

Commit

Permalink
8236971: [macos] Gestures handled incorrectly due to missing events
Browse files Browse the repository at this point in the history
Reviewed-by: mpaus, arapte
  • Loading branch information
kevinrushforth committed Apr 6, 2020
1 parent 560ef17 commit 247a65d
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 32 deletions.
20 changes: 5 additions & 15 deletions modules/javafx.graphics/src/main/native-glass/mac/GlassView2D.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 5 additions & 15 deletions modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <GlassDragSourceDelegate>
{
Expand All @@ -51,6 +59,7 @@
int mouseDownMask; // bit 0 - left, 1 - right, 2 - other button

BOOL gestureInProgress;
GestureMaskType gesturesBeganMask;

NSEvent *lastEvent;

Expand Down Expand Up @@ -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 <NSDraggingInfo>)info type:(jint)type;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

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

self->gestureInProgress = NO;
self->gesturesBeganMask = 0;

self->nativeFullScreenModeWindow = nil;

Expand Down Expand Up @@ -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 <NSDraggingInfo>)info type:(jint)type
{
GET_MAIN_JENV;
Expand Down

0 comments on commit 247a65d

Please sign in to comment.