7124375: [macosx] Focus isn't transfered as expected between components
Reviewed-by: art, ant, serb
This commit is contained in:
parent
31ec802d7e
commit
18e3872928
@ -40,6 +40,7 @@ import java.awt.image.VolatileImage;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.ContainerPeer;
|
||||
|
||||
import java.awt.peer.KeyboardFocusManagerPeer;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.AccessController;
|
||||
@ -894,15 +895,15 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
|
||||
", focusedWindowChangeAllowed=" + focusedWindowChangeAllowed +
|
||||
", time= " + time + ", cause=" + cause);
|
||||
}
|
||||
if (LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
|
||||
processSynchronousLightweightTransfer(getTarget(), lightweightChild, temporary,
|
||||
focusedWindowChangeAllowed, time)) {
|
||||
if (LWKeyboardFocusManagerPeer.processSynchronousLightweightTransfer(
|
||||
getTarget(), lightweightChild, temporary,
|
||||
focusedWindowChangeAllowed, time)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int result = LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
|
||||
shouldNativelyFocusHeavyweight(getTarget(), lightweightChild, temporary,
|
||||
focusedWindowChangeAllowed, time, cause);
|
||||
int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight(
|
||||
getTarget(), lightweightChild, temporary,
|
||||
focusedWindowChangeAllowed, time, cause);
|
||||
switch (result) {
|
||||
case LWKeyboardFocusManagerPeer.SNFH_FAILURE:
|
||||
return false;
|
||||
@ -951,14 +952,13 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
|
||||
return false;
|
||||
}
|
||||
|
||||
LWComponentPeer focusOwnerPeer =
|
||||
LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
|
||||
getFocusOwner();
|
||||
Component focusOwner = (focusOwnerPeer != null) ? focusOwnerPeer.getTarget() : null;
|
||||
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
|
||||
Component focusOwner = kfmPeer.getCurrentFocusOwner();
|
||||
return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
|
||||
getTarget(), temporary,
|
||||
focusedWindowChangeAllowed,
|
||||
time, cause, focusOwner);
|
||||
|
||||
case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
|
||||
return true;
|
||||
}
|
||||
@ -1263,8 +1263,8 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
|
||||
protected void handleJavaFocusEvent(FocusEvent e) {
|
||||
// Note that the peer receives all the FocusEvents from
|
||||
// its lightweight children as well
|
||||
LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
|
||||
setFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? this : null);
|
||||
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
|
||||
kfmPeer.setCurrentFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? getTarget() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,85 +26,47 @@
|
||||
package sun.lwawt;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Window;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.awt.AppContext;
|
||||
import sun.awt.KeyboardFocusManagerPeerImpl;
|
||||
|
||||
public class LWKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
|
||||
private static final LWKeyboardFocusManagerPeer inst = new LWKeyboardFocusManagerPeer();
|
||||
|
||||
private Object lock = new Object();
|
||||
private LWWindowPeer focusedWindow;
|
||||
private LWComponentPeer focusOwner;
|
||||
private Window focusedWindow;
|
||||
private Component focusOwner;
|
||||
|
||||
private static Map<KeyboardFocusManager, LWKeyboardFocusManagerPeer> instances =
|
||||
new HashMap<KeyboardFocusManager, LWKeyboardFocusManagerPeer>();
|
||||
|
||||
public static synchronized LWKeyboardFocusManagerPeer getInstance(AppContext ctx) {
|
||||
return getInstance(AWTAccessor.getKeyboardFocusManagerAccessor().
|
||||
getCurrentKeyboardFocusManager(ctx));
|
||||
public static LWKeyboardFocusManagerPeer getInstance() {
|
||||
return inst;
|
||||
}
|
||||
|
||||
public static synchronized LWKeyboardFocusManagerPeer getInstance(KeyboardFocusManager manager) {
|
||||
LWKeyboardFocusManagerPeer instance = instances.get(manager);
|
||||
if (instance == null) {
|
||||
instance = new LWKeyboardFocusManagerPeer(manager);
|
||||
instances.put(manager, instance);
|
||||
private LWKeyboardFocusManagerPeer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentFocusedWindow(Window win) {
|
||||
synchronized (this) {
|
||||
focusedWindow = win;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public LWKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getCurrentFocusedWindow() {
|
||||
synchronized (lock) {
|
||||
return (focusedWindow != null) ? (Window)focusedWindow.getTarget() : null;
|
||||
synchronized (this) {
|
||||
return focusedWindow;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getCurrentFocusOwner() {
|
||||
synchronized (lock) {
|
||||
return (focusOwner != null) ? focusOwner.getTarget() : null;
|
||||
synchronized (this) {
|
||||
return focusOwner;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentFocusOwner(Component comp) {
|
||||
synchronized (lock) {
|
||||
focusOwner = (comp != null) ? (LWComponentPeer)comp.getPeer() : null;
|
||||
}
|
||||
}
|
||||
|
||||
void setFocusedWindow(LWWindowPeer peer) {
|
||||
synchronized (lock) {
|
||||
focusedWindow = peer;
|
||||
}
|
||||
}
|
||||
|
||||
LWWindowPeer getFocusedWindow() {
|
||||
synchronized (lock) {
|
||||
return focusedWindow;
|
||||
}
|
||||
}
|
||||
|
||||
void setFocusOwner(LWComponentPeer peer) {
|
||||
synchronized (lock) {
|
||||
focusOwner = peer;
|
||||
}
|
||||
}
|
||||
|
||||
LWComponentPeer getFocusOwner() {
|
||||
synchronized (lock) {
|
||||
return focusOwner;
|
||||
synchronized (this) {
|
||||
focusOwner = comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -415,8 +415,8 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
|
||||
return LWKeyboardFocusManagerPeer.getInstance(manager);
|
||||
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
|
||||
return LWKeyboardFocusManagerPeer.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,8 +238,7 @@ public class LWWindowPeer
|
||||
// TODO: update graphicsConfig, see 4868278
|
||||
platformWindow.setVisible(visible);
|
||||
if (isSimpleWindow()) {
|
||||
LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
|
||||
getInstance(getAppContext());
|
||||
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
|
||||
|
||||
if (visible) {
|
||||
if (!getTarget().isAutoRequestFocus()) {
|
||||
@ -248,7 +247,7 @@ public class LWWindowPeer
|
||||
requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
|
||||
}
|
||||
// Focus the owner in case this window is focused.
|
||||
} else if (manager.getCurrentFocusedWindow() == getTarget()) {
|
||||
} else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
|
||||
// Transfer focus to the owner.
|
||||
LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
|
||||
if (owner != null) {
|
||||
@ -915,9 +914,8 @@ public class LWWindowPeer
|
||||
public void dispatchKeyEvent(int id, long when, int modifiers,
|
||||
int keyCode, char keyChar, int keyLocation)
|
||||
{
|
||||
LWComponentPeer focusOwner =
|
||||
LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
|
||||
getFocusOwner();
|
||||
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
|
||||
Component focusOwner = kfmPeer.getCurrentFocusOwner();
|
||||
|
||||
// Null focus owner may receive key event when
|
||||
// application hides the focused window upon ESC press
|
||||
@ -925,9 +923,10 @@ public class LWWindowPeer
|
||||
// may come to already hidden window. This check eliminates NPE.
|
||||
if (focusOwner != null) {
|
||||
KeyEvent event =
|
||||
new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
|
||||
new KeyEvent(focusOwner, id, when, modifiers,
|
||||
keyCode, keyChar, keyLocation);
|
||||
focusOwner.postEvent(event);
|
||||
LWComponentPeer peer = (LWComponentPeer)focusOwner.getPeer();
|
||||
peer.postEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1244,10 +1243,8 @@ public class LWWindowPeer
|
||||
}
|
||||
}
|
||||
|
||||
LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
|
||||
getInstance(getAppContext());
|
||||
|
||||
Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
|
||||
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
|
||||
Window oppositeWindow = becomesFocused ? kfmPeer.getCurrentFocusedWindow() : null;
|
||||
|
||||
// Note, the method is not called:
|
||||
// - when the opposite (gaining focus) window is an owned/owner window.
|
||||
@ -1260,7 +1257,7 @@ public class LWWindowPeer
|
||||
grabbingWindow.ungrab();
|
||||
}
|
||||
|
||||
manager.setFocusedWindow(becomesFocused ? LWWindowPeer.this : null);
|
||||
kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
|
||||
|
||||
int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
|
||||
WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, oppositeWindow);
|
||||
|
@ -56,7 +56,6 @@ import java.util.WeakHashMap;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
import sun.awt.HeadlessToolkit;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.CausedFocusEvent;
|
||||
import sun.awt.KeyboardFocusManagerPeerProvider;
|
||||
@ -443,7 +442,7 @@ public abstract class KeyboardFocusManager
|
||||
private void initPeer() {
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
KeyboardFocusManagerPeerProvider peerProvider = (KeyboardFocusManagerPeerProvider)tk;
|
||||
peer = peerProvider.createKeyboardFocusManagerPeer(this);
|
||||
peer = peerProvider.getKeyboardFocusManagerPeer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,14 @@ import java.awt.Window;
|
||||
*/
|
||||
public interface KeyboardFocusManagerPeer {
|
||||
|
||||
/**
|
||||
* Sets the window that should become the focused window.
|
||||
*
|
||||
* @param win the window that should become the focused window
|
||||
*
|
||||
*/
|
||||
void setCurrentFocusedWindow(Window win);
|
||||
|
||||
/**
|
||||
* Returns the currently focused window.
|
||||
*
|
||||
|
@ -44,6 +44,14 @@ import java.util.Properties;
|
||||
public class HToolkit extends SunToolkit
|
||||
implements ComponentFactory {
|
||||
|
||||
private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {
|
||||
public void setCurrentFocusedWindow(Window win) {}
|
||||
public Window getCurrentFocusedWindow() { return null; }
|
||||
public void setCurrentFocusOwner(Component comp) {}
|
||||
public Component getCurrentFocusOwner() { return null; }
|
||||
public void clearGlobalFocusOwner(Window activeWindow) {}
|
||||
};
|
||||
|
||||
public HToolkit() {
|
||||
}
|
||||
|
||||
@ -152,15 +160,9 @@ public class HToolkit extends SunToolkit
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
|
||||
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
|
||||
// See 6833019.
|
||||
return
|
||||
new KeyboardFocusManagerPeer() {
|
||||
public Window getCurrentFocusedWindow() { return null; }
|
||||
public void setCurrentFocusOwner(Component comp) {}
|
||||
public Component getCurrentFocusOwner() { return null; }
|
||||
public void clearGlobalFocusOwner(Window activeWindow) {}
|
||||
};
|
||||
return kfmPeer;
|
||||
}
|
||||
|
||||
public TrayIconPeer createTrayIcon(TrayIcon target)
|
||||
|
@ -30,22 +30,25 @@ import java.awt.dnd.*;
|
||||
import java.awt.dnd.peer.DragSourceContextPeer;
|
||||
import java.awt.event.*;
|
||||
import java.awt.im.InputMethodHighlight;
|
||||
import java.awt.im.spi.InputMethodDescriptor;
|
||||
import java.awt.image.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.peer.*;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import sun.awt.im.InputContext;
|
||||
import sun.awt.image.ImageRepresentation;
|
||||
|
||||
public class HeadlessToolkit extends Toolkit
|
||||
implements ComponentFactory, KeyboardFocusManagerPeerProvider {
|
||||
|
||||
private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {
|
||||
public void setCurrentFocusedWindow(Window win) {}
|
||||
public Window getCurrentFocusedWindow() { return null; }
|
||||
public void setCurrentFocusOwner(Component comp) {}
|
||||
public Component getCurrentFocusOwner() { return null; }
|
||||
public void clearGlobalFocusOwner(Window activeWindow) {}
|
||||
};
|
||||
|
||||
private Toolkit tk;
|
||||
private ComponentFactory componentFactory;
|
||||
|
||||
@ -179,15 +182,9 @@ public class HeadlessToolkit extends Toolkit
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
|
||||
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
|
||||
// See 6833019.
|
||||
return
|
||||
new KeyboardFocusManagerPeer() {
|
||||
public Window getCurrentFocusedWindow() { return null; }
|
||||
public void setCurrentFocusOwner(Component comp) {}
|
||||
public Component getCurrentFocusOwner() { return null; }
|
||||
public void clearGlobalFocusOwner(Window activeWindow) {}
|
||||
};
|
||||
return kfmPeer;
|
||||
}
|
||||
|
||||
public TrayIconPeer createTrayIcon(TrayIcon target)
|
||||
|
@ -53,12 +53,6 @@ public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManag
|
||||
public static final int SNFH_SUCCESS_HANDLED = 1;
|
||||
public static final int SNFH_SUCCESS_PROCEED = 2;
|
||||
|
||||
protected KeyboardFocusManager manager;
|
||||
|
||||
public KeyboardFocusManagerPeerImpl(KeyboardFocusManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearGlobalFocusOwner(Window activeWindow) {
|
||||
if (activeWindow != null) {
|
||||
|
@ -25,20 +25,19 @@
|
||||
|
||||
package sun.awt;
|
||||
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.peer.KeyboardFocusManagerPeer;
|
||||
|
||||
/**
|
||||
* {@link KeyboardFocusManagerPeerProvider} is required to be implemented by
|
||||
* the currently used {@link java.awt.Toolkit} instance. In order to initialize
|
||||
* {@link java.awt.KeyboardFocusManager}, an instance of {@link KeyboardFocusManagerPeer}
|
||||
* is needed. To create that instance, the {@link #createKeyboardFocusManagerPeer}
|
||||
* {@link java.awt.KeyboardFocusManager}, a singleton instance of {@link KeyboardFocusManagerPeer}
|
||||
* is needed. To obtain that instance, the {@link #getKeyboardFocusManagerPeer}
|
||||
* method of the current toolkit is called.
|
||||
*/
|
||||
public interface KeyboardFocusManagerPeerProvider {
|
||||
|
||||
/**
|
||||
* Creates a KeyboardFocusManagerPeer for the specified KeyboardFocusManager.
|
||||
* Gets a singleton KeyboardFocusManagerPeer instance.
|
||||
*/
|
||||
KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager);
|
||||
KeyboardFocusManagerPeer getKeyboardFocusManagerPeer();
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ import sun.security.action.GetPropertyAction;
|
||||
import sun.security.action.GetBooleanAction;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
@ -204,7 +203,7 @@ public abstract class SunToolkit extends Toolkit
|
||||
public abstract RobotPeer createRobot(Robot target, GraphicsDevice screen)
|
||||
throws AWTException;
|
||||
|
||||
public abstract KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
|
||||
public abstract KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
|
||||
throws HeadlessException;
|
||||
|
||||
/**
|
||||
|
@ -601,7 +601,7 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
|
||||
final XWindowPeer parentXWindow = getParentTopLevel();
|
||||
Window parentWindow = (Window)parentXWindow.getTarget();
|
||||
if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() &&
|
||||
XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow)
|
||||
XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() != parentWindow)
|
||||
{
|
||||
postEvent(new InvocationEvent(parentWindow, new Runnable() {
|
||||
public void run() {
|
||||
|
@ -1108,7 +1108,7 @@ abstract class XDecoratedPeer extends XWindowPeer {
|
||||
focusLog.fine("Request for decorated window focus");
|
||||
// If this is Frame or Dialog we can't assure focus request success - but we still can try
|
||||
// If this is Window and its owner Frame is active we can be sure request succedded.
|
||||
Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
|
||||
Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
|
||||
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
|
||||
|
||||
focusLog.finer("Current window is: active={0}, focused={1}",
|
||||
@ -1201,7 +1201,7 @@ abstract class XDecoratedPeer extends XWindowPeer {
|
||||
}
|
||||
|
||||
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
|
||||
Window actualFocusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
|
||||
Window actualFocusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
|
||||
|
||||
// If the actual focused window is not this decorated window then retain it.
|
||||
if (actualFocusedWindow != null && actualFocusedWindow != target) {
|
||||
|
@ -135,7 +135,7 @@ class XDialogPeer extends XDecoratedPeer implements DialogPeer {
|
||||
* Thus we don't have to perform any transitive (a blocker of a blocker) checks.
|
||||
*/
|
||||
boolean isFocusedWindowModalBlocker() {
|
||||
Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
|
||||
Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
|
||||
XWindowPeer focusedWindowPeer = null;
|
||||
|
||||
if (focusedWindow != null) {
|
||||
|
@ -96,11 +96,11 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{
|
||||
public void handleEvent(AWTEvent e) {
|
||||
switch (e.getID()) {
|
||||
case FocusEvent.FOCUS_GAINED:
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(proxy);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(proxy);
|
||||
container.focusGained(handle);
|
||||
break;
|
||||
case FocusEvent.FOCUS_LOST:
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
|
||||
container.focusLost(handle);
|
||||
break;
|
||||
case KeyEvent.KEY_PRESSED:
|
||||
@ -172,7 +172,7 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{
|
||||
if (lightweightChild == null) {
|
||||
lightweightChild = (Component)proxy;
|
||||
}
|
||||
Component currentOwner = XKeyboardFocusManagerPeer.getCurrentNativeFocusOwner();
|
||||
Component currentOwner = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusOwner();
|
||||
if (currentOwner != null && currentOwner.getPeer() == null) {
|
||||
currentOwner = null;
|
||||
}
|
||||
@ -224,7 +224,8 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{
|
||||
if (parent != null) {
|
||||
Window parentWindow = (Window)parent;
|
||||
// and check that it is focused
|
||||
if (!parentWindow.isFocused() && XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() == parentWindow) {
|
||||
if (!parentWindow.isFocused() &&
|
||||
XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == parentWindow) {
|
||||
// if it is not - skip requesting focus on Solaris
|
||||
// but return true for compatibility.
|
||||
return true;
|
||||
|
@ -204,7 +204,7 @@ public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher
|
||||
// XEMBED_FOCUS_OUT client messages), so we first need to check if
|
||||
// embedded is an active window before sending WINDOW_LOST_FOCUS
|
||||
// to shared code
|
||||
if (XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() == embedded.target) {
|
||||
if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == embedded.target) {
|
||||
embedded.handleWindowFocusOut(null, 0);
|
||||
}
|
||||
}
|
||||
|
@ -25,66 +25,48 @@
|
||||
package sun.awt.X11;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Window;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
|
||||
import java.awt.peer.KeyboardFocusManagerPeer;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
import sun.awt.CausedFocusEvent;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.KeyboardFocusManagerPeerImpl;
|
||||
|
||||
public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
|
||||
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XKeyboardFocusManagerPeer");
|
||||
private static final XKeyboardFocusManagerPeer inst = new XKeyboardFocusManagerPeer();
|
||||
|
||||
private static Object lock = new Object() {};
|
||||
private static Component currentFocusOwner;
|
||||
private static Window currentFocusedWindow;
|
||||
private Component currentFocusOwner;
|
||||
private Window currentFocusedWindow;
|
||||
|
||||
XKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
|
||||
super(manager);
|
||||
public static XKeyboardFocusManagerPeer getInstance() {
|
||||
return inst;
|
||||
}
|
||||
|
||||
private XKeyboardFocusManagerPeer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentFocusOwner(Component comp) {
|
||||
setCurrentNativeFocusOwner(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getCurrentFocusOwner() {
|
||||
return getCurrentNativeFocusOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getCurrentFocusedWindow() {
|
||||
return getCurrentNativeFocusedWindow();
|
||||
}
|
||||
|
||||
public static void setCurrentNativeFocusOwner(Component comp) {
|
||||
synchronized (lock) {
|
||||
synchronized (this) {
|
||||
currentFocusOwner = comp;
|
||||
}
|
||||
}
|
||||
|
||||
public static Component getCurrentNativeFocusOwner() {
|
||||
synchronized(lock) {
|
||||
@Override
|
||||
public Component getCurrentFocusOwner() {
|
||||
synchronized(this) {
|
||||
return currentFocusOwner;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCurrentNativeFocusedWindow(Window win) {
|
||||
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Setting current native focused window " + win);
|
||||
@Override
|
||||
public void setCurrentFocusedWindow(Window win) {
|
||||
if (focusLog.isLoggable(PlatformLogger.FINER)) {
|
||||
focusLog.finer("Setting current focused window " + win);
|
||||
}
|
||||
|
||||
XWindowPeer from = null, to = null;
|
||||
|
||||
synchronized(lock) {
|
||||
synchronized(this) {
|
||||
if (currentFocusedWindow != null) {
|
||||
from = (XWindowPeer)currentFocusedWindow.getPeer();
|
||||
}
|
||||
@ -104,8 +86,9 @@ public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public static Window getCurrentNativeFocusedWindow() {
|
||||
synchronized(lock) {
|
||||
@Override
|
||||
public Window getCurrentFocusedWindow() {
|
||||
synchronized(this) {
|
||||
return currentFocusedWindow;
|
||||
}
|
||||
}
|
||||
@ -124,6 +107,6 @@ public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
|
||||
focusedWindowChangeAllowed,
|
||||
time,
|
||||
cause,
|
||||
getCurrentNativeFocusOwner());
|
||||
getInstance().getCurrentFocusOwner());
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIDefaults;
|
||||
import sun.awt.*;
|
||||
import sun.font.FontConfigManager;
|
||||
import sun.font.FontManager;
|
||||
import sun.java2d.SunGraphicsEnvironment;
|
||||
import sun.misc.PerformanceLogger;
|
||||
import sun.print.PrintJob2D;
|
||||
@ -667,7 +666,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
long w = 0;
|
||||
if (windowToXWindow(ev.get_xany().get_window()) != null) {
|
||||
Component owner =
|
||||
XKeyboardFocusManagerPeer.getCurrentNativeFocusOwner();
|
||||
XKeyboardFocusManagerPeer.getInstance().getCurrentFocusOwner();
|
||||
if (owner != null) {
|
||||
XWindow ownerWindow = (XWindow) AWTAccessor.getComponentAccessor().getPeer(owner);
|
||||
if (ownerWindow != null) {
|
||||
@ -1159,9 +1158,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
return peer;
|
||||
}
|
||||
|
||||
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) throws HeadlessException {
|
||||
XKeyboardFocusManagerPeer peer = new XKeyboardFocusManagerPeer(manager);
|
||||
return peer;
|
||||
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() throws HeadlessException {
|
||||
return XKeyboardFocusManagerPeer.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -617,7 +617,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
|
||||
public void handleWindowFocusIn_Dispatch() {
|
||||
if (EventQueue.isDispatchThread()) {
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
|
||||
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
|
||||
SunToolkit.setSystemGenerated(we);
|
||||
target.dispatchEvent(we);
|
||||
@ -626,7 +626,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
|
||||
public void handleWindowFocusInSync(long serial) {
|
||||
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
|
||||
sendEvent(we);
|
||||
}
|
||||
// NOTE: This method may be called by privileged threads.
|
||||
@ -634,7 +634,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
public void handleWindowFocusIn(long serial) {
|
||||
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
|
||||
/* wrap in Sequenced, then post*/
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
|
||||
postEvent(wrapInSequenced((AWTEvent) we));
|
||||
}
|
||||
|
||||
@ -642,15 +642,15 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
|
||||
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
|
||||
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow(null);
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
|
||||
/* wrap in Sequenced, then post*/
|
||||
postEvent(wrapInSequenced((AWTEvent) we));
|
||||
}
|
||||
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
|
||||
WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow(null);
|
||||
XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
|
||||
XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
|
||||
sendEvent(we);
|
||||
}
|
||||
|
||||
@ -1138,7 +1138,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
// getWMState() always returns 0 (Withdrawn) for simple windows. Hence
|
||||
// we ignore the state for such windows.
|
||||
if (isVisible() && (state == XUtilConstants.NormalState || isSimpleWindow())) {
|
||||
if (XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() ==
|
||||
if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() ==
|
||||
getTarget())
|
||||
{
|
||||
show = true;
|
||||
@ -1185,7 +1185,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
* receive WM_TAKE_FOCUS.
|
||||
*/
|
||||
if (isSimpleWindow()) {
|
||||
if (target == XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow()) {
|
||||
if (target == XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow()) {
|
||||
Window owner = getDecoratedOwner((Window)target);
|
||||
((XWindowPeer)AWTAccessor.getComponentAccessor().getPeer(owner)).requestWindowFocus();
|
||||
}
|
||||
@ -1825,7 +1825,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
// If this is Frame or Dialog we can't assure focus request success - but we still can try
|
||||
// If this is Window and its owner Frame is active we can be sure request succedded.
|
||||
Window ownerWindow = XWindowPeer.getDecoratedOwner((Window)target);
|
||||
Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
|
||||
Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
|
||||
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
|
||||
|
||||
if (isWMStateNetHidden()) {
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package sun.awt.windows;
|
||||
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Window;
|
||||
import java.awt.Component;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
@ -37,8 +36,13 @@ class WKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
|
||||
static native Component getNativeFocusOwner();
|
||||
static native Window getNativeFocusedWindow();
|
||||
|
||||
WKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
|
||||
super(manager);
|
||||
private static final WKeyboardFocusManagerPeer inst = new WKeyboardFocusManagerPeer();
|
||||
|
||||
public static WKeyboardFocusManagerPeer getInstance() {
|
||||
return inst;
|
||||
}
|
||||
|
||||
private WKeyboardFocusManagerPeer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,6 +55,12 @@ class WKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
|
||||
return getNativeFocusOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentFocusedWindow(Window win) {
|
||||
// Not used on Windows
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getCurrentFocusedWindow() {
|
||||
return getNativeFocusedWindow();
|
||||
|
@ -506,10 +506,10 @@ public class WToolkit extends SunToolkit implements Runnable {
|
||||
return true;
|
||||
}
|
||||
|
||||
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
|
||||
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
|
||||
throws HeadlessException
|
||||
{
|
||||
return new WKeyboardFocusManagerPeer(manager);
|
||||
return WKeyboardFocusManagerPeer.getInstance();
|
||||
}
|
||||
|
||||
protected native void setDynamicLayoutNative(boolean b);
|
||||
|
Loading…
Reference in New Issue
Block a user