Skip to content

Commit b14e085

Browse files
Jose PeredaJohan Vos
authored andcommitted
8244735: Error on iOS passing keys with unicode values greater than 255
Reviewed-by: jvos
1 parent b0d66d0 commit b14e085

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

modules/javafx.graphics/src/main/java/com/sun/glass/ui/ios/IosView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,10 @@ static int _getMultiClickMaxY() {
8282
@Override protected void _uploadPixels(long ptr, Pixels pixels) {
8383
throw new RuntimeException("IosView._uploadPixels() UNIMPLEMENTED.");
8484
}
85+
86+
private void notifyUnicode(int type, int keyCode, int unicode, int modifiers) {
87+
notifyKey(type, keyCode, new char[] {(char) unicode}, modifiers);
88+
}
89+
8590
}
8691

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,12 @@ - (void)dealloc {
664664

665665
// view specific
666666
mat_jViewClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/sun/glass/ui/ios/IosView"));
667+
mat_jViewNotifyKey = (*env)->GetMethodID(env, mat_jViewClass, "notifyUnicode", "(IIII)V");
667668
jclass mat_jViewBaseClass = (*env)->FindClass(env, "com/sun/glass/ui/View");
668669
GLASS_CHECK_EXCEPTION(env);
669670

670671
mat_jViewNotifyResize = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyResize", "(II)V");
671672
mat_jViewNotifyRepaint = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyRepaint", "(IIII)V");
672-
mat_jViewNotifyKey = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyKey", "(II[CI)V");
673673
mat_jViewNotifyMouse = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMouse", "(IIIIIIIZZ)V");
674674
mat_jViewNotifyInputMethod = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyInputMethod", "(Ljava/lang/String;[I[I[BIII)V");
675675
mat_jViewNotifyView = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyView", "(I)V");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef __attribute__((NSObject)) CFMutableDictionaryRef GlassMutableDictionaryR
7474
- (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button;
7575

7676
// Java events callbacks
77-
- (void)sendJavaKeyEventWithType:(int)type keyCode:(int)code chars:(char)chr modifiers:(int)modif;
77+
- (void)sendJavaKeyEventWithType:(int)type keyCode:(int)code unicode:(int)unicode modifiers:(int)modif;
7878

7979
- (void)sendJavaTouchEvent:(UIEvent *)theEvent;
8080

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,11 @@ - (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button
554554
}
555555

556556

557-
- (void)sendJavaKeyEventWithType:(int)type keyCode:(int)code chars:(char)chr modifiers:(int)modif;
557+
- (void)sendJavaKeyEventWithType:(int)type keyCode:(int)code unicode:(int)unicode modifiers:(int)modif
558558
{
559559
GET_MAIN_JENV;
560560

561-
jchar jc[1] = {(jchar) chr};
562-
jcharArray jChars = (*env)->NewCharArray(env, 1);
563-
(*env)->SetCharArrayRegion(env, jChars, 0, 1, jc);
564-
565-
(*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyKey, type, code, jChars, modif);
566-
567-
(*env)->DeleteLocalRef(env, jChars);
561+
(*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyKey, type, code, unicode, modif);
568562

569563
GLASS_CHECK_EXCEPTION(env);
570564
}
@@ -715,7 +709,7 @@ - (BOOL)suppressMouseEnterExitOnMouseDown
715709
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
716710
[self sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_PRESS
717711
keyCode:com_sun_glass_events_KeyEvent_VK_ENTER
718-
chars:(char)13
712+
unicode:(char)13
719713
modifiers:0];
720714

721715
[[GlassWindow getMasterWindow] resignFocusOwner];

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,27 @@ - (void)dealloc {
125125
@implementation GlassViewGL : GLView
126126

127127
-(void) doInsertText:(NSString*)myText {
128-
int asciiCode = [myText characterAtIndex:0];
129-
[self->delegate sendJavaKeyEventWithType:111 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
130-
[self->delegate sendJavaKeyEventWithType:113 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
131-
[self->delegate sendJavaKeyEventWithType:112 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
128+
int unicode = [myText characterAtIndex:0];
129+
int code = com_sun_glass_events_KeyEvent_VK_UNDEFINED;
130+
if (unicode == com_sun_glass_events_KeyEvent_VK_ENTER) {
131+
code = unicode;
132+
}
133+
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_PRESS
134+
keyCode:code unicode:unicode modifiers:0];
135+
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_TYPED
136+
keyCode:code unicode:unicode modifiers:0];
137+
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_RELEASE
138+
keyCode:code unicode:unicode modifiers:0];
132139
}
133140

134141
-(void) doDeleteBackward {
135-
int asciiCode = 8;
136-
[self->delegate sendJavaKeyEventWithType:111 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
137-
[self->delegate sendJavaKeyEventWithType:113 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
138-
[self->delegate sendJavaKeyEventWithType:112 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
142+
int unicode = com_sun_glass_events_KeyEvent_VK_BACKSPACE;
143+
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_PRESS
144+
keyCode:unicode unicode:unicode modifiers:0];
145+
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_TYPED
146+
keyCode:unicode unicode:unicode modifiers:0];
147+
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_RELEASE
148+
keyCode:unicode unicode:unicode modifiers:0];
139149
}
140150

141151
-(BOOL) touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ - (id)initWithScreen:(UIScreen *)screen jwindow:(jobject)jwindow
327327
return self;
328328
}
329329

330+
- (UIKeyboardType) keyboardType
331+
{
332+
return UIKeyboardTypeASCIICapable;
333+
}
330334

331335
#pragma mark ---
332336

0 commit comments

Comments
 (0)