From d64dd5e054237912dcf5c9798a4b31c9dce6adb4 Mon Sep 17 00:00:00 2001 From: dcherepanov Date: Thu, 14 Oct 2010 18:24:36 +0400 Subject: [PATCH] 6991992: Need to forward-port AWT's part of the fix for 6691674 Reviewed-by: art --- src/share/classes/java/awt/AWTEvent.java | 13 ++++++++++ .../classes/java/awt/SequencedEvent.java | 3 +++ src/share/classes/sun/awt/AWTAccessor.java | 11 ++++++++ src/share/classes/sun/awt/SunToolkit.java | 25 +++++++++++++++++++ .../classes/sun/awt/X11/InfoWindow.java | 2 +- .../classes/sun/awt/X11/XTextAreaPeer.java | 8 +++++- .../classes/sun/awt/X11/XTrayIconPeer.java | 2 +- src/solaris/classes/sun/awt/X11/XWindow.java | 2 ++ .../classes/sun/awt/X11/XWindowPeer.java | 4 ++- 9 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/share/classes/java/awt/AWTEvent.java b/src/share/classes/java/awt/AWTEvent.java index d45e958b9..e52a8d7e5 100644 --- a/src/share/classes/java/awt/AWTEvent.java +++ b/src/share/classes/java/awt/AWTEvent.java @@ -100,6 +100,12 @@ public abstract class AWTEvent extends EventObject { transient boolean focusManagerIsDispatching = false; transient boolean isPosted; + /** + * Indicates whether this AWTEvent was generated by the system as + * opposed to by user code. + */ + private transient boolean isSystemGenerated; + /** * The event mask for selecting component events. */ @@ -235,6 +241,12 @@ public abstract class AWTEvent extends EventObject { public void setPosted(AWTEvent ev) { ev.isPosted = true; } + public void setSystemGenerated(AWTEvent ev) { + ev.isSystemGenerated = true; + } + public boolean isSystemGenerated(AWTEvent ev) { + return ev.isSystemGenerated; + } }); } @@ -554,6 +566,7 @@ public abstract class AWTEvent extends EventObject { } } } + that.isSystemGenerated = this.isSystemGenerated; } void dispatched() { diff --git a/src/share/classes/java/awt/SequencedEvent.java b/src/share/classes/java/awt/SequencedEvent.java index e8f2f7d5f..9072c5027 100644 --- a/src/share/classes/java/awt/SequencedEvent.java +++ b/src/share/classes/java/awt/SequencedEvent.java @@ -64,6 +64,9 @@ class SequencedEvent extends AWTEvent implements ActiveEvent { public SequencedEvent(AWTEvent nested) { super(nested.getSource(), ID); this.nested = nested; + // All AWTEvents that are wrapped in SequencedEvents are (at + // least currently) implicitly generated by the system + SunToolkit.setSystemGenerated(nested); synchronized (SequencedEvent.class) { list.add(this); } diff --git a/src/share/classes/sun/awt/AWTAccessor.java b/src/share/classes/sun/awt/AWTAccessor.java index 2b65f647d..b9171ce97 100644 --- a/src/share/classes/sun/awt/AWTAccessor.java +++ b/src/share/classes/sun/awt/AWTAccessor.java @@ -302,6 +302,17 @@ public final class AWTAccessor { * Marks the event as posted. */ void setPosted(AWTEvent ev); + + /** + * Sets the flag on this AWTEvent indicating that it was + * generated by the system. + */ + void setSystemGenerated(AWTEvent ev); + + /** + * Indicates whether this AWTEvent was generated by the system. + */ + boolean isSystemGenerated(AWTEvent ev); } public interface InputEventAccessor { diff --git a/src/share/classes/sun/awt/SunToolkit.java b/src/share/classes/sun/awt/SunToolkit.java index 21c0906d4..07b231951 100644 --- a/src/share/classes/sun/awt/SunToolkit.java +++ b/src/share/classes/sun/awt/SunToolkit.java @@ -591,6 +591,12 @@ public abstract class SunToolkit extends Toolkit if (event == null) { throw new NullPointerException(); } + // All events posted via this method are system-generated. + // Placing the following call here reduces considerably the + // number of places throughout the toolkit that would + // otherwise have to be modified to precisely identify + // system-generated events. + setSystemGenerated(event); AppContext eventContext = targetToAppContext(event.getSource()); if (eventContext != null && !eventContext.equals(appContext)) { log.fine("Event posted on wrong app context : " + event); @@ -2093,6 +2099,25 @@ public abstract class SunToolkit extends Toolkit } return isInstanceOf(cls.getSuperclass(), type); } + + /////////////////////////////////////////////////////////////////////////// + // + // The following methods help set and identify whether a particular + // AWTEvent object was produced by the system or by user code. As of this + // writing the only consumer is the Java Plug-In, although this information + // could be useful to more clients and probably should be formalized in + // the public API. + // + /////////////////////////////////////////////////////////////////////////// + + public static void setSystemGenerated(AWTEvent e) { + AWTAccessor.getAWTEventAccessor().setSystemGenerated(e); + } + + public static boolean isSystemGenerated(AWTEvent e) { + return AWTAccessor.getAWTEventAccessor().isSystemGenerated(e); + } + } // class SunToolkit diff --git a/src/solaris/classes/sun/awt/X11/InfoWindow.java b/src/solaris/classes/sun/awt/X11/InfoWindow.java index 6728e3565..a4ae0a739 100644 --- a/src/solaris/classes/sun/awt/X11/InfoWindow.java +++ b/src/solaris/classes/sun/awt/X11/InfoWindow.java @@ -432,7 +432,7 @@ public abstract class InfoWindow extends Window { ActionEvent aev = new ActionEvent(target, ActionEvent.ACTION_PERFORMED, liveArguments.getActionCommand(), e.getWhen(), e.getModifiers()); - Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(aev); + XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev); } } } diff --git a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java index fcc5659e5..a4ddea1f4 100644 --- a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java @@ -61,6 +61,7 @@ import javax.swing.plaf.BorderUIResource; import java.awt.im.InputMethodRequests; import sun.awt.CausedFocusEvent; import sun.awt.AWTAccessor; +import sun.awt.SunToolkit; class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { @@ -1318,13 +1319,18 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { Component source, Point point, MouseEvent template ) { MouseEvent e = template; - return new MouseEvent( + MouseEvent nme = new MouseEvent( source, e.getID(), e.getWhen(), e.getModifiersEx() | e.getModifiers(), point.x, point.y, e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton() ); + // Because these MouseEvents are dispatched directly to + // their target, we need to mark them as being + // system-generated here + SunToolkit.setSystemGenerated(nme); + return nme; } private void setCursor() { diff --git a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java index dc9130927..8b11f0e1c 100644 --- a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java @@ -454,7 +454,7 @@ public class XTrayIconPeer implements TrayIconPeer, ActionEvent aev = new ActionEvent(xtiPeer.target, ActionEvent.ACTION_PERFORMED, xtiPeer.target.getActionCommand(), e.getWhen(), e.getModifiers()); - Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(aev); + XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev); } if (xtiPeer.balloon.isVisible()) { xtiPeer.balloon.hide(); diff --git a/src/solaris/classes/sun/awt/X11/XWindow.java b/src/solaris/classes/sun/awt/X11/XWindow.java index c7626c3d4..d7b3eebb2 100644 --- a/src/solaris/classes/sun/awt/X11/XWindow.java +++ b/src/solaris/classes/sun/awt/X11/XWindow.java @@ -401,6 +401,8 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { if (isPostedField == null) { isPostedField = SunToolkit.getField(AWTEvent.class, "isPosted"); } + // The uses of this method imply that the incoming event is system-generated + SunToolkit.setSystemGenerated(e); PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() { public void run() { try { diff --git a/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/src/solaris/classes/sun/awt/X11/XWindowPeer.java index 058cf966a..579854d73 100644 --- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java +++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java @@ -604,7 +604,9 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, public void handleWindowFocusIn_Dispatch() { if (EventQueue.isDispatchThread()) { XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target); - target.dispatchEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS)); + WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS); + SunToolkit.setSystemGenerated(we); + target.dispatchEvent(we); } } -- GitLab