Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091151

Some Events shouldn't go through the EventTarget hierarchy when fired

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u20
    • javafx
    • None

      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.

            Unassigned Unassigned
            msladecek Martin Sládeček
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: