提交 d64dd5e0 编写于 作者: D dcherepanov

6991992: Need to forward-port AWT's part of the fix for 6691674

Reviewed-by: art
上级 f5d58309
...@@ -100,6 +100,12 @@ public abstract class AWTEvent extends EventObject { ...@@ -100,6 +100,12 @@ public abstract class AWTEvent extends EventObject {
transient boolean focusManagerIsDispatching = false; transient boolean focusManagerIsDispatching = false;
transient boolean isPosted; 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. * The event mask for selecting component events.
*/ */
...@@ -235,6 +241,12 @@ public abstract class AWTEvent extends EventObject { ...@@ -235,6 +241,12 @@ public abstract class AWTEvent extends EventObject {
public void setPosted(AWTEvent ev) { public void setPosted(AWTEvent ev) {
ev.isPosted = true; 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 { ...@@ -554,6 +566,7 @@ public abstract class AWTEvent extends EventObject {
} }
} }
} }
that.isSystemGenerated = this.isSystemGenerated;
} }
void dispatched() { void dispatched() {
......
...@@ -64,6 +64,9 @@ class SequencedEvent extends AWTEvent implements ActiveEvent { ...@@ -64,6 +64,9 @@ class SequencedEvent extends AWTEvent implements ActiveEvent {
public SequencedEvent(AWTEvent nested) { public SequencedEvent(AWTEvent nested) {
super(nested.getSource(), ID); super(nested.getSource(), ID);
this.nested = nested; 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) { synchronized (SequencedEvent.class) {
list.add(this); list.add(this);
} }
......
...@@ -302,6 +302,17 @@ public final class AWTAccessor { ...@@ -302,6 +302,17 @@ public final class AWTAccessor {
* Marks the event as posted. * Marks the event as posted.
*/ */
void setPosted(AWTEvent ev); 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 { public interface InputEventAccessor {
......
...@@ -591,6 +591,12 @@ public abstract class SunToolkit extends Toolkit ...@@ -591,6 +591,12 @@ public abstract class SunToolkit extends Toolkit
if (event == null) { if (event == null) {
throw new NullPointerException(); 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()); AppContext eventContext = targetToAppContext(event.getSource());
if (eventContext != null && !eventContext.equals(appContext)) { if (eventContext != null && !eventContext.equals(appContext)) {
log.fine("Event posted on wrong app context : " + event); log.fine("Event posted on wrong app context : " + event);
...@@ -2093,6 +2099,25 @@ public abstract class SunToolkit extends Toolkit ...@@ -2093,6 +2099,25 @@ public abstract class SunToolkit extends Toolkit
} }
return isInstanceOf(cls.getSuperclass(), type); 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 } // class SunToolkit
......
...@@ -432,7 +432,7 @@ public abstract class InfoWindow extends Window { ...@@ -432,7 +432,7 @@ public abstract class InfoWindow extends Window {
ActionEvent aev = new ActionEvent(target, ActionEvent.ACTION_PERFORMED, ActionEvent aev = new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
liveArguments.getActionCommand(), liveArguments.getActionCommand(),
e.getWhen(), e.getModifiers()); e.getWhen(), e.getModifiers());
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(aev); XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev);
} }
} }
} }
......
...@@ -61,6 +61,7 @@ import javax.swing.plaf.BorderUIResource; ...@@ -61,6 +61,7 @@ import javax.swing.plaf.BorderUIResource;
import java.awt.im.InputMethodRequests; import java.awt.im.InputMethodRequests;
import sun.awt.CausedFocusEvent; import sun.awt.CausedFocusEvent;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
...@@ -1318,13 +1319,18 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { ...@@ -1318,13 +1319,18 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
Component source, Point point, MouseEvent template ) Component source, Point point, MouseEvent template )
{ {
MouseEvent e = template; MouseEvent e = template;
return new MouseEvent( MouseEvent nme = new MouseEvent(
source, source,
e.getID(), e.getWhen(), e.getID(), e.getWhen(),
e.getModifiersEx() | e.getModifiers(), e.getModifiersEx() | e.getModifiers(),
point.x, point.y, point.x, point.y,
e.getXOnScreen(), e.getYOnScreen(), e.getXOnScreen(), e.getYOnScreen(),
e.getClickCount(), e.isPopupTrigger(), e.getButton() ); 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() { private void setCursor() {
......
...@@ -454,7 +454,7 @@ public class XTrayIconPeer implements TrayIconPeer, ...@@ -454,7 +454,7 @@ public class XTrayIconPeer implements TrayIconPeer,
ActionEvent aev = new ActionEvent(xtiPeer.target, ActionEvent.ACTION_PERFORMED, ActionEvent aev = new ActionEvent(xtiPeer.target, ActionEvent.ACTION_PERFORMED,
xtiPeer.target.getActionCommand(), e.getWhen(), xtiPeer.target.getActionCommand(), e.getWhen(),
e.getModifiers()); e.getModifiers());
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(aev); XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev);
} }
if (xtiPeer.balloon.isVisible()) { if (xtiPeer.balloon.isVisible()) {
xtiPeer.balloon.hide(); xtiPeer.balloon.hide();
......
...@@ -401,6 +401,8 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -401,6 +401,8 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
if (isPostedField == null) { if (isPostedField == null) {
isPostedField = SunToolkit.getField(AWTEvent.class, "isPosted"); 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() { PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
public void run() { public void run() {
try { try {
......
...@@ -604,7 +604,9 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, ...@@ -604,7 +604,9 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
public void handleWindowFocusIn_Dispatch() { public void handleWindowFocusIn_Dispatch() {
if (EventQueue.isDispatchThread()) { if (EventQueue.isDispatchThread()) {
XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target); 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);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册