mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-28 08:39:56 +00:00
8381019: Remove AppContext usage from AccessBridge
Reviewed-by: serb, kizune
This commit is contained in:
parent
79668b007d
commit
7ffc4a4fb4
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2020, 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
|
||||
@ -34,7 +34,6 @@ import java.beans.PropertyChangeSupport;
|
||||
import java.util.Locale;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
/**
|
||||
* {@code AccessibleContext} represents the minimum information all accessible
|
||||
@ -84,24 +83,8 @@ public abstract class AccessibleContext {
|
||||
*/
|
||||
protected AccessibleContext() {}
|
||||
|
||||
/**
|
||||
* The {@code AppContext} that should be used to dispatch events for this
|
||||
* {@code AccessibleContext}.
|
||||
*/
|
||||
private volatile AppContext targetAppContext;
|
||||
|
||||
static {
|
||||
AWTAccessor.setAccessibleContextAccessor(new AWTAccessor.AccessibleContextAccessor() {
|
||||
@Override
|
||||
public void setAppContext(AccessibleContext accessibleContext, AppContext appContext) {
|
||||
accessibleContext.targetAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppContext getAppContext(AccessibleContext accessibleContext) {
|
||||
return accessibleContext.targetAppContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getNativeAXResource(AccessibleContext accessibleContext) {
|
||||
return accessibleContext.nativeAXResource;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
@ -115,7 +115,6 @@ module java.desktop {
|
||||
// qualified exports may be inserted at build time
|
||||
// see make/GensrcModuleInfo.gmk
|
||||
exports sun.awt to
|
||||
jdk.accessibility,
|
||||
jdk.unsupported.desktop;
|
||||
|
||||
exports java.awt.dnd.peer to jdk.unsupported.desktop;
|
||||
|
||||
@ -755,8 +755,6 @@ public final class AWTAccessor {
|
||||
* An accessor object for the AccessibleContext class
|
||||
*/
|
||||
public interface AccessibleContextAccessor {
|
||||
void setAppContext(AccessibleContext accessibleContext, AppContext appContext);
|
||||
AppContext getAppContext(AccessibleContext accessibleContext);
|
||||
Object getNativeAXResource(AccessibleContext accessibleContext);
|
||||
void setNativeAXResource(AccessibleContext accessibleContext, Object value);
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -120,9 +120,6 @@ import com.sun.java.accessibility.util.AccessibilityEventMonitor;
|
||||
import com.sun.java.accessibility.util.EventQueueMonitor;
|
||||
import com.sun.java.accessibility.util.SwingEventMonitor;
|
||||
import com.sun.java.accessibility.util.Translator;
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.awt.AppContext;
|
||||
import sun.awt.SunToolkit;
|
||||
|
||||
/*
|
||||
* Note: This class has to be public. It's loaded from the VM like this:
|
||||
@ -5292,7 +5289,6 @@ public final class AccessBridge {
|
||||
ac = a.getAccessibleContext();
|
||||
}
|
||||
if (ac != null) {
|
||||
InvocationUtils.registerAccessibleContext(ac, AppContext.getAppContext());
|
||||
|
||||
accessBridge.debugString("[INFO]: AccessibleContext: " + ac);
|
||||
String propertyName = e.getPropertyName();
|
||||
@ -5385,11 +5381,9 @@ public final class AccessBridge {
|
||||
|
||||
if (e.getOldValue() instanceof AccessibleContext) {
|
||||
oldAC = (AccessibleContext) e.getOldValue();
|
||||
InvocationUtils.registerAccessibleContext(oldAC, AppContext.getAppContext());
|
||||
}
|
||||
if (e.getNewValue() instanceof AccessibleContext) {
|
||||
newAC = (AccessibleContext) e.getNewValue();
|
||||
InvocationUtils.registerAccessibleContext(newAC, AppContext.getAppContext());
|
||||
}
|
||||
accessBridge.debugString("[INFO]: - about to call propertyChildChange() old AC: " + oldAC + "new AC: " + newAC);
|
||||
accessBridge.propertyChildChange(e, ac, oldAC, newAC);
|
||||
@ -5455,8 +5449,6 @@ public final class AccessBridge {
|
||||
prevAC = newAC;
|
||||
|
||||
accessBridge.debugString("[INFO]: - about to call propertyActiveDescendentChange() AC: " + ac + " old AC: " + oldAC + "new AC: " + newAC);
|
||||
InvocationUtils.registerAccessibleContext(oldAC, AppContext.getAppContext());
|
||||
InvocationUtils.registerAccessibleContext(newAC, AppContext.getAppContext());
|
||||
accessBridge.propertyActiveDescendentChange(e, ac, oldAC, newAC);
|
||||
}
|
||||
|
||||
@ -5493,14 +5485,12 @@ public final class AccessBridge {
|
||||
// selected. The menu itself is selected.
|
||||
FocusEvent e = new FocusEvent(penult, FocusEvent.FOCUS_GAINED);
|
||||
AccessibleContext context = penult.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, SunToolkit.targetToAppContext(penult));
|
||||
accessBridge.focusGained(e, context);
|
||||
} else if (penult instanceof JPopupMenu) {
|
||||
// This is a popup with an item selected
|
||||
FocusEvent e =
|
||||
new FocusEvent(last, FocusEvent.FOCUS_GAINED);
|
||||
AccessibleContext focusedAC = last.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(focusedAC, SunToolkit.targetToAppContext(last));
|
||||
accessBridge.debugString("[INFO]: - about to call focusGained() AC: " + focusedAC);
|
||||
accessBridge.focusGained(e, focusedAC);
|
||||
}
|
||||
@ -5511,7 +5501,6 @@ public final class AccessBridge {
|
||||
FocusEvent e = new FocusEvent(focusOwner,
|
||||
FocusEvent.FOCUS_GAINED);
|
||||
AccessibleContext focusedAC = focusOwner.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(focusedAC, SunToolkit.targetToAppContext(focusOwner));
|
||||
accessBridge.debugString("[INFO]: - about to call focusGained() AC: " + focusedAC);
|
||||
accessBridge.focusGained(e, focusedAC);
|
||||
}
|
||||
@ -5524,7 +5513,6 @@ public final class AccessBridge {
|
||||
if (a != null) {
|
||||
accessBridge.debugString("[INFO]: - about to call focusLost() AC: " + a.getAccessibleContext());
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.focusLost(e, context);
|
||||
}
|
||||
}
|
||||
@ -5538,7 +5526,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.caretUpdate(e, context);
|
||||
}
|
||||
}
|
||||
@ -5553,7 +5540,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.mouseClicked(e, context);
|
||||
}
|
||||
}
|
||||
@ -5564,7 +5550,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.mouseEntered(e, context);
|
||||
}
|
||||
}
|
||||
@ -5575,7 +5560,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.mouseExited(e, context);
|
||||
}
|
||||
}
|
||||
@ -5586,7 +5570,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.mousePressed(e, context);
|
||||
}
|
||||
}
|
||||
@ -5597,7 +5580,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.mouseReleased(e, context);
|
||||
}
|
||||
}
|
||||
@ -5611,7 +5593,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.menuCanceled(e, context);
|
||||
}
|
||||
}
|
||||
@ -5622,7 +5603,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.menuDeselected(e, context);
|
||||
}
|
||||
}
|
||||
@ -5633,7 +5613,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.menuSelected(e, context);
|
||||
}
|
||||
}
|
||||
@ -5644,7 +5623,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.popupMenuCanceled(e, context);
|
||||
}
|
||||
}
|
||||
@ -5655,7 +5633,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.popupMenuWillBecomeInvisible(e, context);
|
||||
}
|
||||
}
|
||||
@ -5666,7 +5643,6 @@ public final class AccessBridge {
|
||||
Accessible a = Translator.getAccessible(e.getSource());
|
||||
if (a != null) {
|
||||
AccessibleContext context = a.getAccessibleContext();
|
||||
InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
|
||||
accessBridge.popupMenuWillBecomeVisible(e, context);
|
||||
}
|
||||
}
|
||||
@ -7227,8 +7203,7 @@ public final class AccessBridge {
|
||||
private static class InvocationUtils {
|
||||
|
||||
/**
|
||||
* Invokes a {@code Callable} in the {@code AppContext} of the given {@code Accessible}
|
||||
* and waits for it to finish blocking the caller thread.
|
||||
* Invokes a {@code Callable} and waits for it to finish blocking the caller thread.
|
||||
*
|
||||
* @param callable the {@code Callable} to invoke
|
||||
* @param accessibleTable the {@code AccessibleExtendedTable} which would be used to find the right context
|
||||
@ -7246,8 +7221,7 @@ public final class AccessBridge {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a {@code Callable} in the {@code AppContext} of the given {@code Accessible}
|
||||
* and waits for it to finish blocking the caller thread.
|
||||
* Invokes a {@code Callable} and waits for it to finish blocking the caller thread.
|
||||
*
|
||||
* @param callable the {@code Callable} to invoke
|
||||
* @param accessible the {@code Accessible} which would be used to find the right context
|
||||
@ -7269,8 +7243,7 @@ public final class AccessBridge {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a {@code Callable} in the {@code AppContext} of the given {@code Component}
|
||||
* and waits for it to finish blocking the caller thread.
|
||||
* Invokes a {@code Callable} and waits for it to finish blocking the caller thread.
|
||||
*
|
||||
* @param callable the {@code Callable} to invoke
|
||||
* @param component the {@code Component} which would be used to find the right context
|
||||
@ -7281,12 +7254,11 @@ public final class AccessBridge {
|
||||
*/
|
||||
public static <T> T invokeAndWait(final Callable<T> callable,
|
||||
final Component component) {
|
||||
return invokeAndWait(callable, SunToolkit.targetToAppContext(component));
|
||||
return invokeAndWait(callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a {@code Callable} in the {@code AppContext} mapped to the given {@code AccessibleContext}
|
||||
* and waits for it to finish blocking the caller thread.
|
||||
* Invokes a {@code Callable} and waits for it to finish blocking the caller thread.
|
||||
*
|
||||
* @param callable the {@code Callable} to invoke
|
||||
* @param accessibleContext the {@code AccessibleContext} which would be used to determine the right
|
||||
@ -7297,45 +7269,26 @@ public final class AccessBridge {
|
||||
*/
|
||||
public static <T> T invokeAndWait(final Callable<T> callable,
|
||||
final AccessibleContext accessibleContext) {
|
||||
AppContext targetContext = AWTAccessor.getAccessibleContextAccessor()
|
||||
.getAppContext(accessibleContext);
|
||||
if (targetContext != null) {
|
||||
return invokeAndWait(callable, targetContext);
|
||||
} else {
|
||||
// Normally this should not happen, unmapped context provided and
|
||||
// the target AppContext is unknown.
|
||||
|
||||
// Try to recover in case the context is a translator.
|
||||
if (accessibleContext instanceof Translator) {
|
||||
Object source = ((Translator)accessibleContext).getSource();
|
||||
if (source instanceof Component) {
|
||||
return invokeAndWait(callable, (Component)source);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Unmapped AccessibleContext used to dispatch event: " + accessibleContext);
|
||||
return invokeAndWait(callable);
|
||||
}
|
||||
|
||||
private static <T> T invokeAndWait(final Callable<T> callable,
|
||||
final AppContext targetAppContext) {
|
||||
private static <T> T invokeAndWait(final Callable<T> callable) {
|
||||
final CallableWrapper<T> wrapper = new CallableWrapper<T>(callable);
|
||||
try {
|
||||
invokeAndWait(wrapper, targetAppContext);
|
||||
invokeAndWait(wrapper);
|
||||
T result = wrapper.getResult();
|
||||
updateAppContextMap(result, targetAppContext);
|
||||
return result;
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void invokeAndWait(final Runnable runnable,
|
||||
final AppContext appContext)
|
||||
private static void invokeAndWait(final Runnable runnable)
|
||||
throws InterruptedException, InvocationTargetException {
|
||||
|
||||
EventQueue eq = SunToolkit.getSystemEventQueueImplPP(appContext);
|
||||
Object lock = new Object();
|
||||
Toolkit source = Toolkit.getDefaultToolkit();
|
||||
EventQueue eq = source.getSystemEventQueue();
|
||||
InvocationEvent event =
|
||||
new InvocationEvent(source, runnable, lock, true);
|
||||
synchronized (lock) {
|
||||
@ -7349,26 +7302,6 @@ public final class AccessBridge {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the {@code AccessibleContext} to the {@code AppContext} which should be used
|
||||
* to dispatch events related to the {@code AccessibleContext}
|
||||
* @param accessibleContext the {@code AccessibleContext} for the mapping
|
||||
* @param targetContext the {@code AppContext} for the mapping
|
||||
*/
|
||||
public static void registerAccessibleContext(final AccessibleContext accessibleContext,
|
||||
final AppContext targetContext) {
|
||||
if (accessibleContext != null) {
|
||||
AWTAccessor.getAccessibleContextAccessor().setAppContext(accessibleContext, targetContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void updateAppContextMap(final T accessibleContext,
|
||||
final AppContext targetContext) {
|
||||
if (accessibleContext instanceof AccessibleContext) {
|
||||
registerAccessibleContext((AccessibleContext)accessibleContext, targetContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CallableWrapper<T> implements Runnable {
|
||||
private final Callable<T> callable;
|
||||
private volatile T object;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user