Skip to content

Commit

Permalink
8245575: Show the ContextMenu of input controls with long press gestu…
Browse files Browse the repository at this point in the history
…re on iOS

Reviewed-by: jvos
  • Loading branch information
Jose Pereda authored and Johan Vos committed Jun 9, 2020
1 parent 5304266 commit afa805f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
jmethodID mat_jViewNotifyRepaint = 0;
jmethodID mat_jViewNotifyKey = 0;
jmethodID mat_jViewNotifyMouse = 0;
jmethodID mat_jViewNotifyMenu = 0;
jmethodID mat_jViewNotifyInputMethod = 0;
jmethodID mat_jViewNotifyView = 0;

Expand Down Expand Up @@ -671,6 +672,7 @@ - (void)dealloc {
mat_jViewNotifyResize = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyResize", "(II)V");
mat_jViewNotifyRepaint = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyRepaint", "(IIII)V");
mat_jViewNotifyMouse = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMouse", "(IIIIIIIZZ)V");
mat_jViewNotifyMenu = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMenu", "(IIIIZ)V");
mat_jViewNotifyInputMethod = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyInputMethod", "(Ljava/lang/String;[I[I[BIII)V");
mat_jViewNotifyView = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyView", "(I)V");
GLASS_CHECK_EXCEPTION(env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,19 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer*)sender {
}


- (void)handleLongPressGesture:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
// Simulate right-click
CGPoint viewPoint = [sender locationInView:self.uiView.superview];
[self sendJavaMouseEvent:viewPoint type:com_sun_glass_events_MouseEvent_ENTER button:com_sun_glass_events_MouseEvent_BUTTON_NONE];
[self sendJavaMouseEvent:viewPoint type:com_sun_glass_events_MouseEvent_DOWN button:com_sun_glass_events_MouseEvent_BUTTON_RIGHT];
} else if (sender.state == UIGestureRecognizerStateEnded) {
// Prevent touch ended event
self.mouseTouch = nil;
}
}


- (id)initWithView:(UIScrollView*)view withJview:(jobject)jview
{
self = [super init];
Expand Down Expand Up @@ -422,6 +435,15 @@ - (id)initWithView:(UIScrollView*)view withJview:(jobject)jview
[panGestureRecognizer setCancelsTouchesInView:NO];
[panGestureRecognizer setDelaysTouchesBegan:NO];
[panGestureRecognizer setDelaysTouchesEnded:NO];
//LongPress
UILongPressGestureRecognizer *longPressGesture =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[longPressGesture setCancelsTouchesInView:NO];
[longPressGesture setDelaysTouchesEnded:NO];
[longPressGesture setDelaysTouchesBegan:NO];
[self.uiView addGestureRecognizer:longPressGesture];
[longPressGesture setDelegate:ggDelegate];
[longPressGesture release];
}
return self;
}
Expand Down Expand Up @@ -551,6 +573,13 @@ - (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button
(jint)viewPoint.x, (jint)viewPoint.y, (jint)viewPoint.x, (jint)viewPoint.y,
modifiers, isPopupTrigger, isSynthesized);
GLASS_CHECK_EXCEPTION(env);

if (isPopupTrigger) {
jboolean isKeyboardTrigger = JNI_FALSE;
(*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyMenu,
(jint)viewPoint.x, (jint)viewPoint.y, (jint)viewPoint.x, (jint)viewPoint.y, isKeyboardTrigger);
GLASS_CHECK_EXCEPTION(env);
}
}


Expand Down
1 change: 1 addition & 0 deletions modules/javafx.graphics/src/main/native-glass/ios/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern jmethodID mat_jViewNotifyResize;
extern jmethodID mat_jViewNotifyRepaint;
extern jmethodID mat_jViewNotifyKey;
extern jmethodID mat_jViewNotifyMouse;
extern jmethodID mat_jViewNotifyMenu;
extern jmethodID mat_jViewNotifyInputMethod;
extern jmethodID mat_jViewNotifyView;

Expand Down

0 comments on commit afa805f

Please sign in to comment.