JDK-8091151 : Some Events shouldn't go through the EventTarget hierarchy when fired
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: scenegraph
  • Affected Version: 8u20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-03-27
  • Updated: 2019-08-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
Currently, all Events on a Node are first dispatched to Window, Scene and all Parent ancestors of a Node. This is very useful for all input events (or maybe only to input events?), but other events like ActionEvent are really meant to be fired just on their target.

What we would need is a different dispatch chain depending on the Event type. This is currently not possible, since EventTarget has the following method:

EventDispatchChain buildEventDispatchChain(EventDispatchChain tail);

So I propose adding a default method:

default EventDispatchChain buildEventDispatchChain(EventDispatchChain tail, EventType<? extends Event> type) { return buildEventDispatchChain(tail); }

It's not perfect since it basically changes the entry point for building the dispatch chain as the original method should not be really called anymore. But when building a new dispatch chain, this call is done by FX side. Although theoretically, somebody could fire an Event by calling node.buildEventDispatchChain(chain).dispatchEvent(event);


Another alternative would be to expose event dispatcher for the EventTarget, using it directly for some Events. Window, Scene and Node already have this public (getEventDispatcher(), eventDispatcherProperty()), it's just not part of any interface (EventTarget?). But this extension of EvenTarget wouldn't be very smooth since default implementation cannot return anything meaningful. 

This is not just because of performance as currently it is possible to intercept events like ActionEvent on Window or Scene, which is confusing. Like this:

stage.addEventFilter(ActionEvent.ACTION, event -> event.consume());

would make all buttons on Stage incapable of handling an ActionEvent.