diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java index 64d8a101d69f6..edeb62d8e9fca 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java @@ -623,7 +623,7 @@ public void run() { synchronized(retString) { retString[0] = new String(selectedText); }} - }, fAwtFocussedComponent); + }, fAwtFocussedComponent, true); } catch (InvocationTargetException ite) { ite.printStackTrace(); } synchronized(retString) { return retString[0]; } @@ -671,7 +671,7 @@ public void run() { synchronized(returnValue) { returnValue[1] = theIterator.getEndIndex() - theIterator.getBeginIndex(); }} - }, fAwtFocussedComponent); + }, fAwtFocussedComponent, true); } catch (InvocationTargetException ite) { ite.printStackTrace(); } synchronized(returnValue) { return returnValue; } @@ -696,7 +696,7 @@ public void run() { synchronized(returnValue) { // insert spot less the length of the composed text. returnValue[0] = fIMContext.getInsertPositionOffset(); }} - }, fAwtFocussedComponent); + }, fAwtFocussedComponent, true); } catch (InvocationTargetException ite) { ite.printStackTrace(); } returnValue[1] = fCurrentTextLength; @@ -743,7 +743,7 @@ public void run() { synchronized(rect) { } } }} - }, fAwtFocussedComponent); + }, fAwtFocussedComponent, true); } catch (InvocationTargetException ite) { ite.printStackTrace(); } synchronized(rect) { return rect; } @@ -763,7 +763,7 @@ public void run() { synchronized(offsetInfo) { offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY); insertPositionOffset[0] = fIMContext.getInsertPositionOffset(); }} - }, fAwtFocussedComponent); + }, fAwtFocussedComponent, true); } catch (InvocationTargetException ite) { ite.printStackTrace(); } // This bit of gymnastics ensures that the returned location is within the composed text. diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index d430825bb8565..fba31e2f9a754 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -720,6 +720,25 @@ public T getResult() throws Exception { */ public static void invokeAndWait(Runnable runnable, Component component) throws InvocationTargetException { + invokeAndWait(runnable, component, false); + } + + /** + * Package-scope version of invokeAndWait that takes a processEvents + * flag to decide whether to dispatch native events while in the loop. + * Currently, only the IME handlers set processEvents to true. See + * the warning in doAWTRunLoop about using this flag. + * + * Kicks an event over to the appropriate event queue and waits for it to + * finish To avoid deadlocking, we manually run the NSRunLoop while waiting + * Any selector invoked using ThreadUtilities performOnMainThread will be + * processed in doAWTRunLoop The InvocationEvent will call + * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual + * run loop. Does not dispatch native events while in the loop unless + * the processEvents flag is set to true. + */ + static void invokeAndWait(Runnable runnable, Component component, boolean processEvents) + throws InvocationTargetException { Objects.requireNonNull(component, "Null component provided to invokeAndWait"); long mediator = createAWTRunLoopMediator(); @@ -737,7 +756,7 @@ public static void invokeAndWait(Runnable runnable, Component component) SunToolkit.postEvent(appContext, invocationEvent); // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock SunToolkit.flushPendingEvents(appContext); - doAWTRunLoop(mediator, false); + doAWTRunLoop(mediator, processEvents); checkException(invocationEvent); } @@ -927,7 +946,7 @@ public boolean canPopupOverlapTaskBar() { * Method to run a nested run-loop. The nested loop is spinned in the javaRunLoop mode, so selectors sent * by [JNFRunLoop performOnMainThreadWaiting] are processed. * @param mediator a native pointer to the mediator object created by createAWTRunLoopMediator - * @param processEvents if true - dispatches event while in the nested loop. Used in DnD. + * @param processEvents if true - dispatches event while in the nested loop. Used in DnD and IME. * Additional attention is needed when using this feature as we short-circuit normal event * processing which could break Appkit. * (One known example is when the window is resized with the mouse)