Skip to content

Commit 3a7cffa

Browse files
committed
Proper IM window cleanup when focus moves from one node to another
1 parent 359ffb9 commit 3a7cffa

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

modules/javafx.graphics/src/main/java/com/sun/glass/ui/mac/MacView.java

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static int getMultiClickMaxY_impl() {
7878
@Override native protected boolean _enterFullscreen(long ptr, boolean animate, boolean keepRatio, boolean hideCursor);
7979
@Override native protected void _exitFullscreen(long ptr, boolean animate);
8080
@Override native protected void _enableInputMethodEvents(long ptr, boolean enable);
81+
@Override native protected void _finishInputMethodComposition(long ptr);
8182

8283
@Override protected void _uploadPixels(long ptr, Pixels pixels) {
8384
Buffer data = pixels.getPixels();

modules/javafx.graphics/src/main/native-glass/mac/GlassView.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
- (GlassViewDelegate*)delegate;
4949
- (void)setInputMethodEnabled:(BOOL)enabled;
50+
- (void)finishInputMethodComposition;
5051

5152
- (void)notifyScaleFactorChanged:(CGFloat)scale;
5253

modules/javafx.graphics/src/main/native-glass/mac/GlassView.m

+21
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,24 @@
712712
GLASS_POOL_EXIT;
713713
GLASS_CHECK_EXCEPTION(env);
714714
}
715+
716+
/*
717+
* Class: com_sun_glass_ui_mac_MacView
718+
* Method: _finishInputMethodComposition
719+
* Signature: (J)V
720+
*/
721+
JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1finishInputMethodComposition
722+
(JNIEnv *env, jobject jView, jlong ptr)
723+
{
724+
LOG("Java_com_sun_glass_ui_mac_MacView__1finishInputMethodComposition");
725+
if (!ptr) return;
726+
727+
GLASS_ASSERT_MAIN_JAVA_THREAD(env);
728+
GLASS_POOL_ENTER;
729+
{
730+
NSView<GlassView> *view = getGlassView(env, ptr);
731+
[view finishInputMethodComposition];
732+
}
733+
GLASS_POOL_EXIT;
734+
GLASS_CHECK_EXCEPTION(env);
735+
}

modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m

+17-4
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,23 @@ - (void)setInputMethodEnabled:(BOOL)enabled
717717
self->imEnabled = enabled;
718718
}
719719

720+
- (void)finishInputMethodComposition
721+
{
722+
IMLOG("finishInputMethodComposition called");
723+
[self unmarkText];
724+
[self.inputContext discardMarkedText];
725+
}
726+
720727
/*
721728
NSTextInputClient protocol implementation follows here.
722729
*/
723730

731+
// Utility function, not part of protocol
732+
- (void)commitString:(NSString*)aString
733+
{
734+
[self->_delegate notifyInputMethod:aString attr:4 length:(int)[aString length] cursor:(int)[aString length] selectedRange: NSMakeRange(NSNotFound, 0)];
735+
}
736+
724737
- (void)doCommandBySelector:(SEL)aSelector
725738
{
726739
IMLOG("doCommandBySelector called ");
@@ -733,7 +746,7 @@ - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
733746
{
734747
IMLOG("insertText called with string: %s", [aString UTF8String]);
735748
if ([self->nsAttrBuffer length] > 0 || [aString length] > 1) {
736-
[self->_delegate notifyInputMethod:aString attr:4 length:(int)[aString length] cursor:(int)[aString length] selectedRange: NSMakeRange(NSNotFound, 0)];
749+
[self commitString: aString];
737750
self->shouldProcessKeyEvent = NO;
738751
} else {
739752
self->shouldProcessKeyEvent = YES;
@@ -760,9 +773,9 @@ - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replace
760773
- (void) unmarkText
761774
{
762775
IMLOG("unmarkText called\n");
763-
if (self->nsAttrBuffer != nil && self->nsAttrBuffer.length != 0) {
764-
self->nsAttrBuffer = [self->nsAttrBuffer initWithString:@""];
765-
[self->_delegate notifyInputMethod:@"" attr:4 length:0 cursor:0 selectedRange: NSMakeRange(NSNotFound, 0)];
776+
if (nsAttrBuffer.length != 0) {
777+
[self commitString: nsAttrBuffer.string];
778+
nsAttrBuffer = [nsAttrBuffer initWithString:@""];
766779
}
767780
self->shouldProcessKeyEvent = YES;
768781
}

0 commit comments

Comments
 (0)