From 984f8bd16257de4ddf4c5bed636f216a93972197 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 26 Oct 2017 16:29:10 -0500 Subject: [PATCH 1/2] Add window.event for web compatibility Tests: https://github.com/web-platform-tests/wpt/pull/4790 & https://github.com/web-platform-tests/wpt/pull/10329. Fixes #334. Co-authored-by: Anne van Kesteren --- dom.bs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/dom.bs b/dom.bs index 2f00ca5a..a656846b 100644 --- a/dom.bs +++ b/dom.bs @@ -482,7 +482,8 @@ empty list.

An event has an associated path. A path is a list of structs. Each struct consists of an -item (an {{EventTarget}} object), target (a +item (an {{EventTarget}} object), an +item-in-shadow-tree (a boolean), a target (a potential event target), a relatedTarget (a potential event target), a touch target list (a list @@ -751,6 +752,25 @@ method, when invoked, must run these steps:

incapable of setting {{Event/composed}}. It has to be supported for legacy content. +

Legacy extensions to the {{Window}} interface

+ +
+partial interface Window {
+  [Replaceable] readonly attribute any event; // historical
+};
+
+ +

Each {{Window}} object has an associated current event (undefined or an +{{Event}} object). Unless stated otherwise it is undefined. + +

The event attribute's getter, when invoked, must +return the context object's current event. + +

Web developers are strongly encouraged to instead rely on {{Event}} object passed to +event listeners as that will result in more portable code. This attribute is not available in +workers or worklets, and is inaccurate for events dispatched in shadow trees. + +

Interface {{CustomEvent}}

@@ -1366,14 +1386,20 @@ for discussion).
 touchTargets, and a slot-in-closed-tree, run these steps:

    +
  1. Let item-in-shadow-tree be false. + +

  2. If target is a node and its root is a + shadow root, then set item-in-shadow-tree to true. +

  3. Let root-of-closed-tree be false.

  4. If target is a shadow root whose mode is "closed", then set root-of-closed-tree to true.

  5. Append a new struct to event's path - whose item is target, target is - targetOverride, relatedTarget is relatedTarget, + whose item is target, item-in-shadow-tree is + item-in-shadow-tree, target is targetOverride, + relatedTarget is relatedTarget, touch target list is touchTargets, root-of-closed-tree is root-of-closed-tree, and slot-in-closed-tree is slot-in-closed-tree. @@ -1395,16 +1421,29 @@ for discussion).

  6. If event's stop propagation flag is set, then return. -

  7. Let object be tuple's item. +

  8. Initialize event's {{Event/currentTarget}} attribute to tuple's + item.

  9. -

    Let listeners be a clone of object's - event listener list. +

    Let listeners be a clone of event's + {{Event/currentTarget}} attribute value's event listener list.

    This avoids event listeners added after this point from being run. Note that removal still has an effect due to the removed field. -

  10. Initialize event's {{Event/currentTarget}} attribute to object. +

  11. Let global be the current global object. + +

  12. Let currentEvent be undefined. + +

  13. +

    If global is a {{Window}} object, then: + +

      +
    1. Set currentEvent to global's current event. + +

    2. If tuple's item-in-shadow-tree is false, then set + global's current event to event. +

  14. Let found be the result of running inner invoke with event, listeners, and legacyOutputDidListenersThrowFlag if given. @@ -1436,6 +1475,9 @@ for discussion).

  15. Set event's {{Event/type}} attribute value to originalEventType.

+ +
  • If global is a {{Window}} object, then set global's + current event to currentEvent.

    To inner invoke, given an From acc8ede74780b93a626d8303ff31cd5584d8047d Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 4 Jun 2018 12:17:48 +0200 Subject: [PATCH 2/2] derive global from the listener's callback --- dom.bs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/dom.bs b/dom.bs index a656846b..494e1769 100644 --- a/dom.bs +++ b/dom.bs @@ -766,8 +766,8 @@ partial interface Window {

    The event attribute's getter, when invoked, must return the context object's current event. -

    Web developers are strongly encouraged to instead rely on {{Event}} object passed to -event listeners as that will result in more portable code. This attribute is not available in +

    Web developers are strongly encouraged to instead rely on the {{Event}} object passed +to event listeners, as that will result in more portable code. This attribute is not available in workers or worklets, and is inaccurate for events dispatched in shadow trees. @@ -1431,20 +1431,6 @@ for discussion).

    This avoids event listeners added after this point from being run. Note that removal still has an effect due to the removed field. -

  • Let global be the current global object. - -

  • Let currentEvent be undefined. - -

  • -

    If global is a {{Window}} object, then: - -

      -
    1. Set currentEvent to global's current event. - -

    2. If tuple's item-in-shadow-tree is false, then set - global's current event to event. -

    -
  • Let found be the result of running inner invoke with event, listeners, and legacyOutputDidListenersThrowFlag if given. @@ -1475,9 +1461,6 @@ for discussion).

  • Set event's {{Event/type}} attribute value to originalEventType. - -

  • If global is a {{Window}} object, then set global's - current event to currentEvent.

    To inner invoke, given an @@ -1511,6 +1494,21 @@ for discussion). +

  • Let global be listener callback's + associated Realm's global object. + +

  • Let currentEvent be undefined. + +

  • +

    If global is a {{Window}} object, then: + +

      +
    1. Set currentEvent to global's current event. + +

    2. If tuple's item-in-shadow-tree is false, then set + global's current event to event. +

    +
  • If listener's passive is true, then set event's in passive listener flag. @@ -1531,6 +1529,9 @@ for discussion).

  • Unset event's in passive listener flag. +

  • If global is a {{Window}} object, then set global's + current event to currentEvent. +

  • If event's stop immediate propagation flag is set, then return found.