Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8244735: Error on iOS passing keys with unicode values greater than 255
Reviewed-by: jvos
  • Loading branch information
Jose Pereda authored and Johan Vos committed May 12, 2020
1 parent b0d66d0 commit b14e085
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
Expand Up @@ -82,5 +82,10 @@ static int _getMultiClickMaxY() {
@Override protected void _uploadPixels(long ptr, Pixels pixels) {
throw new RuntimeException("IosView._uploadPixels() UNIMPLEMENTED.");
}

private void notifyUnicode(int type, int keyCode, int unicode, int modifiers) {
notifyKey(type, keyCode, new char[] {(char) unicode}, modifiers);
}

}

Expand Up @@ -664,12 +664,12 @@ - (void)dealloc {

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

mat_jViewNotifyResize = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyResize", "(II)V");
mat_jViewNotifyRepaint = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyRepaint", "(IIII)V");
mat_jViewNotifyKey = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyKey", "(II[CI)V");
mat_jViewNotifyMouse = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMouse", "(IIIIIIIZZ)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");
Expand Down
Expand Up @@ -74,7 +74,7 @@ typedef __attribute__((NSObject)) CFMutableDictionaryRef GlassMutableDictionaryR
- (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button;

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

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

Expand Down
Expand Up @@ -554,17 +554,11 @@ - (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button
}


- (void)sendJavaKeyEventWithType:(int)type keyCode:(int)code chars:(char)chr modifiers:(int)modif;
- (void)sendJavaKeyEventWithType:(int)type keyCode:(int)code unicode:(int)unicode modifiers:(int)modif
{
GET_MAIN_JENV;

jchar jc[1] = {(jchar) chr};
jcharArray jChars = (*env)->NewCharArray(env, 1);
(*env)->SetCharArrayRegion(env, jChars, 0, 1, jc);

(*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyKey, type, code, jChars, modif);

(*env)->DeleteLocalRef(env, jChars);
(*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyKey, type, code, unicode, modif);

GLASS_CHECK_EXCEPTION(env);
}
Expand Down Expand Up @@ -715,7 +709,7 @@ - (BOOL)suppressMouseEnterExitOnMouseDown
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_PRESS
keyCode:com_sun_glass_events_KeyEvent_VK_ENTER
chars:(char)13
unicode:(char)13
modifiers:0];

[[GlassWindow getMasterWindow] resignFocusOwner];
Expand Down
26 changes: 18 additions & 8 deletions modules/javafx.graphics/src/main/native-glass/ios/GlassViewGL.m
Expand Up @@ -125,17 +125,27 @@ - (void)dealloc {
@implementation GlassViewGL : GLView

-(void) doInsertText:(NSString*)myText {
int asciiCode = [myText characterAtIndex:0];
[self->delegate sendJavaKeyEventWithType:111 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
[self->delegate sendJavaKeyEventWithType:113 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
[self->delegate sendJavaKeyEventWithType:112 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
int unicode = [myText characterAtIndex:0];
int code = com_sun_glass_events_KeyEvent_VK_UNDEFINED;
if (unicode == com_sun_glass_events_KeyEvent_VK_ENTER) {
code = unicode;
}
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_PRESS
keyCode:code unicode:unicode modifiers:0];
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_TYPED
keyCode:code unicode:unicode modifiers:0];
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_RELEASE
keyCode:code unicode:unicode modifiers:0];
}

-(void) doDeleteBackward {
int asciiCode = 8;
[self->delegate sendJavaKeyEventWithType:111 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
[self->delegate sendJavaKeyEventWithType:113 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
[self->delegate sendJavaKeyEventWithType:112 keyCode:asciiCode chars:(char)asciiCode modifiers:0];
int unicode = com_sun_glass_events_KeyEvent_VK_BACKSPACE;
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_PRESS
keyCode:unicode unicode:unicode modifiers:0];
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_TYPED
keyCode:unicode unicode:unicode modifiers:0];
[self->delegate sendJavaKeyEventWithType:com_sun_glass_events_KeyEvent_RELEASE
keyCode:unicode unicode:unicode modifiers:0];
}

-(BOOL) touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
Expand Down
Expand Up @@ -327,6 +327,10 @@ - (id)initWithScreen:(UIScreen *)screen jwindow:(jobject)jwindow
return self;
}

- (UIKeyboardType) keyboardType
{
return UIKeyboardTypeASCIICapable;
}

#pragma mark ---

Expand Down

0 comments on commit b14e085

Please sign in to comment.