8378385: Remove AppContext from AWT Windows implementation classes

Reviewed-by: dnguyen, serb
This commit is contained in:
Phil Race 2026-02-26 20:29:51 +00:00
parent 5e85d99c36
commit cd462a88c6
6 changed files with 14 additions and 40 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -902,7 +902,7 @@ public abstract class WComponentPeer extends WObjectPeer
*/
void postEvent(AWTEvent event) {
preprocessPostEvent(event);
WToolkit.postEvent(WToolkit.targetToAppContext(target), event);
WToolkit.postEvent(event);
}
void preprocessPostEvent(AWTEvent event) {}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -238,8 +238,7 @@ public final class WEmbeddedFrame extends EmbeddedFrame {
peer.emulateActivation(true);
}
};
WToolkit.postEvent(WToolkit.targetToAppContext(this),
new InvocationEvent(this, r));
WToolkit.postEvent(new InvocationEvent(this, r));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -602,7 +602,7 @@ final class WInputMethod extends InputMethodAdapter
commitedTextLength,
TextHitInfo.leading(caretPos),
TextHitInfo.leading(visiblePos));
WToolkit.postEvent(WToolkit.targetToAppContext(source), event);
WToolkit.postEvent(event);
}
public void inquireCandidatePosition()
@ -641,8 +641,7 @@ final class WInputMethod extends InputMethodAdapter
openCandidateWindow(awtFocussedComponentPeer, x, y);
}
};
WToolkit.postEvent(WToolkit.targetToAppContext(source),
new InvocationEvent(source, r));
WToolkit.postEvent(new InvocationEvent(source, r));
}
// java.awt.Toolkit#getNativeContainer() is not available

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -123,7 +123,7 @@ class WMenuItemPeer extends WObjectPeer implements MenuItemPeer {
* Post an event. Queue it for execution by the callback thread.
*/
void postEvent(AWTEvent event) {
WToolkit.postEvent(WToolkit.targetToAppContext(target), event);
WToolkit.postEvent(event);
}
native void create(WMenuPeer parent);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -123,7 +123,6 @@ import javax.swing.text.JTextComponent;
import sun.awt.AWTAccessor;
import sun.awt.AWTAutoShutdown;
import sun.awt.AppContext;
import sun.awt.DisplayChangedListener;
import sun.awt.LightweightFrame;
import sun.awt.SunToolkit;
@ -777,20 +776,7 @@ public final class WToolkit extends SunToolkit implements Runnable {
((DisplayChangedListener) lge).displayChanged();
}
};
if (AppContext.getAppContext() != null) {
// Common case, standalone application
EventQueue.invokeLater(runnable);
} else {
if (displayChangeExecutor == null) {
// No synchronization, called on the Toolkit thread only
displayChangeExecutor = Executors.newFixedThreadPool(1, r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
});
}
displayChangeExecutor.submit(runnable);
}
EventQueue.invokeLater(runnable);
}
/**
@ -910,17 +896,7 @@ public final class WToolkit extends SunToolkit implements Runnable {
}
updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
if (AppContext.getAppContext() == null) {
// We cannot post the update to any EventQueue. Listeners will
// be called on EDTs by DesktopPropertyChangeSupport
updateProperties(props);
} else {
// Cannot update on Toolkit thread.
// DesktopPropertyChangeSupport will call listeners on Toolkit
// thread if it has AppContext (standalone mode)
EventQueue.invokeLater(() -> updateProperties(props));
}
EventQueue.invokeLater(() -> updateProperties(props));
}
private synchronized void updateProperties(final Map<String, Object> props) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -181,7 +181,7 @@ final class WTrayIconPeer extends WObjectPeer implements TrayIconPeer {
}
void postEvent(AWTEvent event) {
WToolkit.postEvent(WToolkit.targetToAppContext(target), event);
WToolkit.postEvent(event);
}
native void create();