changeset 2865:8022709a306d

6991992: Need to forward-port AWT's part of the fix for 6691674 Reviewed-by: art
author dcherepanov
date Thu, 14 Oct 2010 18:24:36 +0400
parents c595c2730226
children f55be3060347
files src/share/classes/java/awt/AWTEvent.java src/share/classes/java/awt/SequencedEvent.java src/share/classes/sun/awt/AWTAccessor.java src/share/classes/sun/awt/SunToolkit.java src/solaris/classes/sun/awt/X11/InfoWindow.java src/solaris/classes/sun/awt/X11/XTextAreaPeer.java src/solaris/classes/sun/awt/X11/XTrayIconPeer.java src/solaris/classes/sun/awt/X11/XWindow.java src/solaris/classes/sun/awt/X11/XWindowPeer.java
diffstat 9 files changed, 66 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/AWTEvent.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/share/classes/java/awt/AWTEvent.java	Thu Oct 14 18:24:36 2010 +0400
@@ -101,6 +101,12 @@
     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.
      */
     public final static long COMPONENT_EVENT_MASK = 0x01;
@@ -235,6 +241,12 @@
                 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 @@
                 }
             }
         }
+        that.isSystemGenerated = this.isSystemGenerated;
     }
 
     void dispatched() {
--- a/src/share/classes/java/awt/SequencedEvent.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/share/classes/java/awt/SequencedEvent.java	Thu Oct 14 18:24:36 2010 +0400
@@ -64,6 +64,9 @@
     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);
         }
--- a/src/share/classes/sun/awt/AWTAccessor.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/share/classes/sun/awt/AWTAccessor.java	Thu Oct 14 18:24:36 2010 +0400
@@ -302,6 +302,17 @@
          * 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 {
--- a/src/share/classes/sun/awt/SunToolkit.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/share/classes/sun/awt/SunToolkit.java	Thu Oct 14 18:24:36 2010 +0400
@@ -591,6 +591,12 @@
         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 @@
         }
         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
 
 
--- a/src/solaris/classes/sun/awt/X11/InfoWindow.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/solaris/classes/sun/awt/X11/InfoWindow.java	Thu Oct 14 18:24:36 2010 +0400
@@ -432,7 +432,7 @@
                     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);
                 }
             }
         }
--- a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java	Thu Oct 14 18:24:36 2010 +0400
@@ -61,6 +61,7 @@
 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 @@
             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() {
--- a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java	Thu Oct 14 18:24:36 2010 +0400
@@ -454,7 +454,7 @@
                 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();
--- a/src/solaris/classes/sun/awt/X11/XWindow.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/solaris/classes/sun/awt/X11/XWindow.java	Thu Oct 14 18:24:36 2010 +0400
@@ -401,6 +401,8 @@
         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 {
--- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java	Thu Oct 14 14:07:50 2010 +0400
+++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java	Thu Oct 14 18:24:36 2010 +0400
@@ -604,7 +604,9 @@
     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);
         }
     }