changeset 17820:dbb5b171a16b

8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true Reviewed-by: kcr
author azvegint
date Thu, 31 Aug 2017 09:28:21 +0530
parents 892a8e0b5834
children cd9b04ac647e
files src/java.desktop/share/classes/java/awt/EventDispatchThread.java src/java.desktop/share/classes/java/awt/EventQueue.java
diffstat 2 files changed, 48 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/java/awt/EventDispatchThread.java	Tue Aug 01 14:18:14 2017 +0800
+++ b/src/java.desktop/share/classes/java/awt/EventDispatchThread.java	Thu Aug 31 09:28:21 2017 +0530
@@ -161,6 +161,23 @@
         }
     }
 
+    boolean filterAndCheckEvent(AWTEvent event) {
+        boolean eventOK = true;
+        synchronized (eventFilters) {
+            for (int i = eventFilters.size() - 1; i >= 0; i--) {
+                EventFilter f = eventFilters.get(i);
+                EventFilter.FilterAction accept = f.acceptEvent(event);
+                if (accept == EventFilter.FilterAction.REJECT) {
+                    eventOK = false;
+                    break;
+                } else if (accept == EventFilter.FilterAction.ACCEPT_IMMEDIATELY) {
+                    break;
+                }
+            }
+        }
+        return eventOK && SunDragSourceContextPeer.checkEvent(event);
+    }
+
     void pumpOneEventForFilters(int id) {
         AWTEvent event = null;
         boolean eventOK = false;
@@ -172,20 +189,7 @@
 
                 event = (id == ANY_EVENT) ? eq.getNextEvent() : eq.getNextEvent(id);
 
-                eventOK = true;
-                synchronized (eventFilters) {
-                    for (int i = eventFilters.size() - 1; i >= 0; i--) {
-                        EventFilter f = eventFilters.get(i);
-                        EventFilter.FilterAction accept = f.acceptEvent(event);
-                        if (accept == EventFilter.FilterAction.REJECT) {
-                            eventOK = false;
-                            break;
-                        } else if (accept == EventFilter.FilterAction.ACCEPT_IMMEDIATELY) {
-                            break;
-                        }
-                    }
-                }
-                eventOK = eventOK && SunDragSourceContextPeer.checkEvent(event);
+                eventOK = filterAndCheckEvent(event);
                 if (!eventOK) {
                     event.consume();
                 }
--- a/src/java.desktop/share/classes/java/awt/EventQueue.java	Tue Aug 01 14:18:14 2017 +0800
+++ b/src/java.desktop/share/classes/java/awt/EventQueue.java	Thu Aug 31 09:28:21 2017 +0530
@@ -719,7 +719,9 @@
                     fwDispatcher.scheduleDispatch(new Runnable() {
                         @Override
                         public void run() {
-                            dispatchEventImpl(event, src);
+                            if (dispatchThread.filterAndCheckEvent(event)) {
+                                dispatchEventImpl(event, src);
+                            }
                         }
                     });
                 }
@@ -1008,6 +1010,32 @@
         return createSecondaryLoop(null, null, 0);
     }
 
+    private class FwSecondaryLoopWrapper implements SecondaryLoop {
+        final private SecondaryLoop loop;
+        final private EventFilter filter;
+
+        public FwSecondaryLoopWrapper(SecondaryLoop loop, EventFilter filter) {
+            this.loop = loop;
+            this.filter = filter;
+        }
+
+        @Override
+        public boolean enter() {
+            if (filter != null) {
+                dispatchThread.addEventFilter(filter);
+            }
+            return loop.enter();
+        }
+
+        @Override
+        public boolean exit() {
+            if (filter != null) {
+                dispatchThread.removeEventFilter(filter);
+            }
+            return loop.exit();
+        }
+    }
+
     SecondaryLoop createSecondaryLoop(Conditional cond, EventFilter filter, long interval) {
         pushPopLock.lock();
         try {
@@ -1016,7 +1044,7 @@
                 return nextQueue.createSecondaryLoop(cond, filter, interval);
             }
             if (fwDispatcher != null) {
-                return fwDispatcher.createSecondaryLoop();
+                return new FwSecondaryLoopWrapper(fwDispatcher.createSecondaryLoop(), filter);
             }
             if (dispatchThread == null) {
                 initDispatchThread();