Skip to content

Commit a7c24df

Browse files
committed
Edge browser sends KeyEvent asynchronously
Edge:handleAcceleratorKeyPressed must handle Browser:sendKeyEvent asynchronously as KeyEvent's Listeners can cause deadlock. Hence, the Handled of this event is set if there exists a listener for the event or a Display filter.
1 parent 8b10d1c commit a7c24df

File tree

7 files changed

+92
-9
lines changed

7 files changed

+92
-9
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,9 +1573,12 @@ int handleAcceleratorKeyPressed(long pView, long pArgs) {
15731573
return COM.S_OK;
15741574
}
15751575

1576-
if (!sendKeyEvent(keyEvent)) {
1577-
args.put_Handled(true);
1578-
}
1576+
asyncExec(() -> {
1577+
sendKeyEvent(keyEvent);
1578+
});
1579+
1580+
boolean hasListener = browser.getListeners(keyEvent.type).length != 0 || browser.getDisplay().filters(keyEvent.type);
1581+
args.put_Handled(hasListener);
15791582
} else {
15801583
keyEvent.type = SWT.KeyUp;
15811584
browser.notifyListeners (keyEvent.type, keyEvent);

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,33 @@ boolean filterEvent (Event event) {
12241224
return false;
12251225
}
12261226

1227-
boolean filters (int eventType) {
1227+
/**
1228+
* Checks for if there exists a listener in the collection of listeners who will
1229+
* be notified when an event of the given type occurs anywhere in a widget. The event type is one of the event constants
1230+
* defined in class <code>SWT</code>. When the event does occur,
1231+
* the listener is notified by sending it the <code>handleEvent()</code>
1232+
* message.
1233+
*
1234+
* <p>
1235+
* Filters are listeners which are registered at display level by calling {@link Display#addFilter(int, Listener)}. These listeners are triggered when there happens an event of the type they are registered with, anywhere in an SWT application.
1236+
* </p>
1237+
*
1238+
* <p>
1239+
* Needs to be public as the consumers of display can register a filter from any package using public method <code>addFilter</code> and might need to check if there exists a filter for an event.
1240+
* </p>
1241+
*
1242+
* @param eventType the type of an event to check if there exists a listener registered using <code>addFilter</code>
1243+
* @return true if there exists a listener which reacts to the eventType otherwise false
1244+
*
1245+
* @see Listener
1246+
* @see SWT
1247+
* @see #addFilter
1248+
* @see #removeFilter
1249+
* @see #removeListener
1250+
*
1251+
* @since 3.133
1252+
*/
1253+
public boolean filters (int eventType) {
12281254
if (filterTable == null) return false;
12291255
return filterTable.hooks (eventType);
12301256
}

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ NSRect expansionFrameWithFrame_inView(long id, long sel, NSRect cellRect, long v
870870
return result;
871871
}
872872

873-
public boolean filters (int eventType) {
873+
boolean filters (int eventType) {
874874
return display.filters (eventType);
875875
}
876876

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,33 @@ boolean filterEvent (Event event) {
19871987
return false;
19881988
}
19891989

1990-
boolean filters (int eventType) {
1990+
/**
1991+
* Checks for if there exists a listener in the collection of listeners who will
1992+
* be notified when an event of the given type occurs anywhere in a widget. The event type is one of the event constants
1993+
* defined in class <code>SWT</code>. When the event does occur,
1994+
* the listener is notified by sending it the <code>handleEvent()</code>
1995+
* message.
1996+
*
1997+
* <p>
1998+
* Filters are listeners which are registered at display level by calling {@link Display#addFilter(int, Listener)}. These listeners are triggered when there happens an event of the type they are registered with, anywhere in an SWT application.
1999+
* </p>
2000+
*
2001+
* <p>
2002+
* Needs to be public as the consumers of display can register a filter from any package using public method <code>addFilter</code> and might need to check if there exists a filter for an event.
2003+
* </p>
2004+
*
2005+
* @param eventType the type of an event to check if there exists a listener registered using <code>addFilter</code>
2006+
* @return true if there exists a listener which reacts to the eventType otherwise false
2007+
*
2008+
* @see Listener
2009+
* @see SWT
2010+
* @see #addFilter
2011+
* @see #removeFilter
2012+
* @see #removeListener
2013+
*
2014+
* @since 3.133
2015+
*/
2016+
public boolean filters (int eventType) {
19912017
if (filterTable == null) return false;
19922018
return filterTable.hooks (eventType);
19932019
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ long filterProc(long xEvent, long gdkEvent, long data2) {
11941194
return 0;
11951195
}
11961196

1197-
public boolean filters (int eventType) {
1197+
boolean filters (int eventType) {
11981198
return display.filters (eventType);
11991199
}
12001200

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,35 @@ boolean filterEvent (Event event) {
13471347
return false;
13481348
}
13491349

1350-
boolean filters (int eventType) {
1350+
1351+
1352+
/**
1353+
* Checks for if there exists a listener in the collection of listeners who will
1354+
* be notified when an event of the given type occurs anywhere in a widget. The event type is one of the event constants
1355+
* defined in class <code>SWT</code>. When the event does occur,
1356+
* the listener is notified by sending it the <code>handleEvent()</code>
1357+
* message.
1358+
*
1359+
* <p>
1360+
* Filters are listeners which are registered at display level by calling {@link Display#addFilter(int, Listener)}. These listeners are triggered when there happens an event of the type they are registered with, anywhere in an SWT application.
1361+
* </p>
1362+
*
1363+
* <p>
1364+
* Needs to be public as the consumers of display can register a filter from any package using public method <code>addFilter</code> and might need to check if there exists a filter for an event.
1365+
* </p>
1366+
*
1367+
* @param eventType the type of an event to check if there exists a listener registered using <code>addFilter</code>
1368+
* @return true if there exists a listener which reacts to the eventType otherwise false
1369+
*
1370+
* @see Listener
1371+
* @see SWT
1372+
* @see #addFilter
1373+
* @see #removeFilter
1374+
* @see #removeListener
1375+
*
1376+
* @since 3.133
1377+
*/
1378+
public boolean filters (int eventType) {
13511379
if (filterTable == null) return false;
13521380
return filterTable.hooks (eventType);
13531381
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ void error (int code) {
510510
SWT.error(code);
511511
}
512512

513-
public boolean filters (int eventType) {
513+
boolean filters (int eventType) {
514514
return display.filters (eventType);
515515
}
516516

0 commit comments

Comments
 (0)