Skip to content

Commit afa805f

Browse files
Jose PeredaJohan Vos
authored andcommitted
8245575: Show the ContextMenu of input controls with long press gesture on iOS
Reviewed-by: jvos
1 parent 5304266 commit afa805f

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

modules/javafx.graphics/src/main/native-glass/ios/GlassApplication.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
jmethodID mat_jViewNotifyRepaint = 0;
6363
jmethodID mat_jViewNotifyKey = 0;
6464
jmethodID mat_jViewNotifyMouse = 0;
65+
jmethodID mat_jViewNotifyMenu = 0;
6566
jmethodID mat_jViewNotifyInputMethod = 0;
6667
jmethodID mat_jViewNotifyView = 0;
6768

@@ -671,6 +672,7 @@ - (void)dealloc {
671672
mat_jViewNotifyResize = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyResize", "(II)V");
672673
mat_jViewNotifyRepaint = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyRepaint", "(IIII)V");
673674
mat_jViewNotifyMouse = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMouse", "(IIIIIIIZZ)V");
675+
mat_jViewNotifyMenu = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMenu", "(IIIIZ)V");
674676
mat_jViewNotifyInputMethod = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyInputMethod", "(Ljava/lang/String;[I[I[BIII)V");
675677
mat_jViewNotifyView = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyView", "(I)V");
676678
GLASS_CHECK_EXCEPTION(env);

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,19 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer*)sender {
375375
}
376376

377377

378+
- (void)handleLongPressGesture:(UILongPressGestureRecognizer*)sender {
379+
if (sender.state == UIGestureRecognizerStateBegan) {
380+
// Simulate right-click
381+
CGPoint viewPoint = [sender locationInView:self.uiView.superview];
382+
[self sendJavaMouseEvent:viewPoint type:com_sun_glass_events_MouseEvent_ENTER button:com_sun_glass_events_MouseEvent_BUTTON_NONE];
383+
[self sendJavaMouseEvent:viewPoint type:com_sun_glass_events_MouseEvent_DOWN button:com_sun_glass_events_MouseEvent_BUTTON_RIGHT];
384+
} else if (sender.state == UIGestureRecognizerStateEnded) {
385+
// Prevent touch ended event
386+
self.mouseTouch = nil;
387+
}
388+
}
389+
390+
378391
- (id)initWithView:(UIScrollView*)view withJview:(jobject)jview
379392
{
380393
self = [super init];
@@ -422,6 +435,15 @@ - (id)initWithView:(UIScrollView*)view withJview:(jobject)jview
422435
[panGestureRecognizer setCancelsTouchesInView:NO];
423436
[panGestureRecognizer setDelaysTouchesBegan:NO];
424437
[panGestureRecognizer setDelaysTouchesEnded:NO];
438+
//LongPress
439+
UILongPressGestureRecognizer *longPressGesture =
440+
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
441+
[longPressGesture setCancelsTouchesInView:NO];
442+
[longPressGesture setDelaysTouchesEnded:NO];
443+
[longPressGesture setDelaysTouchesBegan:NO];
444+
[self.uiView addGestureRecognizer:longPressGesture];
445+
[longPressGesture setDelegate:ggDelegate];
446+
[longPressGesture release];
425447
}
426448
return self;
427449
}
@@ -551,6 +573,13 @@ - (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button
551573
(jint)viewPoint.x, (jint)viewPoint.y, (jint)viewPoint.x, (jint)viewPoint.y,
552574
modifiers, isPopupTrigger, isSynthesized);
553575
GLASS_CHECK_EXCEPTION(env);
576+
577+
if (isPopupTrigger) {
578+
jboolean isKeyboardTrigger = JNI_FALSE;
579+
(*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyMenu,
580+
(jint)viewPoint.x, (jint)viewPoint.y, (jint)viewPoint.x, (jint)viewPoint.y, isKeyboardTrigger);
581+
GLASS_CHECK_EXCEPTION(env);
582+
}
554583
}
555584

556585

modules/javafx.graphics/src/main/native-glass/ios/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern jmethodID mat_jViewNotifyResize;
5353
extern jmethodID mat_jViewNotifyRepaint;
5454
extern jmethodID mat_jViewNotifyKey;
5555
extern jmethodID mat_jViewNotifyMouse;
56+
extern jmethodID mat_jViewNotifyMenu;
5657
extern jmethodID mat_jViewNotifyInputMethod;
5758
extern jmethodID mat_jViewNotifyView;
5859

0 commit comments

Comments
 (0)