diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 5e2b75c4393..107e3173977 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -141,7 +141,7 @@ impl Event { self.cancelable.set(cancelable); } - // https://dom.spec.whatwg.org/#event-path + /// // TODO: shadow roots put special flags in the path, // and it will stop just being a list of bare EventTargets fn construct_event_path(&self, target: &EventTarget) -> Vec> { @@ -178,7 +178,7 @@ impl Event { event_path } - // https://dom.spec.whatwg.org/#concept-event-dispatch + /// pub fn dispatch( &self, target: &EventTarget, @@ -400,7 +400,7 @@ impl Event { self.trusted.set(trusted); } - // https://html.spec.whatwg.org/multipage/#fire-a-simple-event + /// pub fn fire(&self, target: &EventTarget) -> EventStatus { self.set_trusted(true); target.dispatch_event(self) @@ -408,89 +408,98 @@ impl Event { } impl EventMethods for Event { - // https://dom.spec.whatwg.org/#dom-event-eventphase + /// fn EventPhase(&self) -> u16 { self.phase.get() as u16 } - // https://dom.spec.whatwg.org/#dom-event-type + /// fn Type(&self) -> DOMString { DOMString::from(&*self.type_()) // FIXME(ajeffrey): Directly convert from Atom to DOMString } - // https://dom.spec.whatwg.org/#dom-event-target + /// fn GetTarget(&self) -> Option> { self.target.get() } - // https://dom.spec.whatwg.org/#dom-event-srcelement + /// fn GetSrcElement(&self) -> Option> { self.target.get() } - // https://dom.spec.whatwg.org/#dom-event-currenttarget + /// fn GetCurrentTarget(&self) -> Option> { self.current_target.get() } - // https://dom.spec.whatwg.org/#dom-event-defaultprevented + /// + fn ComposedPath(&self) -> Vec> { + if let Some(target) = self.target.get() { + self.construct_event_path(&target) + } else { + vec![] + } + } + + /// fn DefaultPrevented(&self) -> bool { self.canceled.get() == EventDefault::Prevented } - // https://dom.spec.whatwg.org/#dom-event-preventdefault + /// fn PreventDefault(&self) { if self.cancelable.get() { self.canceled.set(EventDefault::Prevented) } } - // https://dom.spec.whatwg.org/#dom-event-stoppropagation + /// fn StopPropagation(&self) { self.stop_propagation.set(true); } - // https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + /// fn StopImmediatePropagation(&self) { self.stop_immediate.set(true); self.stop_propagation.set(true); } - // https://dom.spec.whatwg.org/#dom-event-bubbles + /// fn Bubbles(&self) -> bool { self.bubbles.get() } - // https://dom.spec.whatwg.org/#dom-event-cancelable + /// fn Cancelable(&self) -> bool { self.cancelable.get() } - // https://dom.spec.whatwg.org/#dom-event-returnvalue + /// fn ReturnValue(&self) -> bool { self.canceled.get() == EventDefault::Allowed } - // https://dom.spec.whatwg.org/#dom-event-returnvalue + /// fn SetReturnValue(&self, val: bool) { if !val { self.PreventDefault(); } } - // https://dom.spec.whatwg.org/#dom-event-cancelbubble + /// fn CancelBubble(&self) -> bool { self.stop_propagation.get() } - // https://dom.spec.whatwg.org/#dom-event-cancelbubble + /// fn SetCancelBubble(&self, value: bool) { if value { self.stop_propagation.set(true) } } - // https://dom.spec.whatwg.org/#dom-event-timestamp + /// fn TimeStamp(&self) -> DOMHighResTimeStamp { reduce_timing_resolution( (self.precise_time_ns - (*self.global().performance().TimeOrigin()).round() as u64) @@ -498,12 +507,12 @@ impl EventMethods for Event { ) } - // https://dom.spec.whatwg.org/#dom-event-initevent + /// fn InitEvent(&self, type_: DOMString, bubbles: bool, cancelable: bool) { self.init_event(Atom::from(type_), bubbles, cancelable) } - // https://dom.spec.whatwg.org/#dom-event-istrusted + /// fn IsTrusted(&self) -> bool { self.trusted.get() } @@ -597,7 +606,7 @@ pub enum EventStatus { NotCanceled, } -// https://dom.spec.whatwg.org/#concept-event-fire +/// pub struct EventTask { pub target: Trusted, pub name: Atom, @@ -614,7 +623,7 @@ impl TaskOnce for EventTask { } } -// https://html.spec.whatwg.org/multipage/#fire-a-simple-event +/// pub struct SimpleEventTask { pub target: Trusted, pub name: Atom, @@ -627,7 +636,7 @@ impl TaskOnce for SimpleEventTask { } } -// https://dom.spec.whatwg.org/#concept-event-listener-invoke +/// fn invoke( timeline_window: Option<&Window>, object: &EventTarget, @@ -674,7 +683,7 @@ fn invoke( } } -// https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke +/// fn inner_invoke( timeline_window: Option<&Window>, object: &EventTarget, diff --git a/components/script/dom/webidls/Event.webidl b/components/script/dom/webidls/Event.webidl index ae57dc1a8a8..89d12daea80 100644 --- a/components/script/dom/webidls/Event.webidl +++ b/components/script/dom/webidls/Event.webidl @@ -14,6 +14,7 @@ interface Event { readonly attribute EventTarget? target; readonly attribute EventTarget? srcElement; readonly attribute EventTarget? currentTarget; + sequence composedPath(); const unsigned short NONE = 0; const unsigned short CAPTURING_PHASE = 1; diff --git a/tests/wpt/meta-legacy-layout/dom/idlharness.any.js.ini b/tests/wpt/meta-legacy-layout/dom/idlharness.any.js.ini index 53522f04f26..d8a3e1f25dd 100644 --- a/tests/wpt/meta-legacy-layout/dom/idlharness.any.js.ini +++ b/tests/wpt/meta-legacy-layout/dom/idlharness.any.js.ini @@ -8,9 +8,6 @@ [EventTarget interface: new AbortController().signal must inherit property "addEventListener(DOMString, EventListener, [object Object\],[object Object\])" with the proper type] expected: FAIL - [Event interface: operation composedPath()] - expected: FAIL - [AbortSignal must be primary interface of new AbortController().signal] expected: FAIL @@ -83,9 +80,6 @@ [AbortSignal interface: new AbortController().signal must inherit property "onabort" with the proper type] expected: FAIL - [Event interface: new CustomEvent("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [AbortController interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL @@ -104,9 +98,6 @@ [EventTarget interface: calling dispatchEvent(Event) on new AbortController().signal with too few arguments must throw TypeError] expected: FAIL - [Event interface: new Event("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [AbortController must be primary interface of new AbortController()] expected: FAIL diff --git a/tests/wpt/meta-legacy-layout/dom/idlharness.window.js.ini b/tests/wpt/meta-legacy-layout/dom/idlharness.window.js.ini index 767c7e7b93d..d4f6446c1fc 100644 --- a/tests/wpt/meta-legacy-layout/dom/idlharness.window.js.ini +++ b/tests/wpt/meta-legacy-layout/dom/idlharness.window.js.ini @@ -74,9 +74,6 @@ [Element interface: operation attachShadow(ShadowRootInit)] expected: FAIL - [Event interface: new CustomEvent("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [AbortController interface: operation abort()] expected: FAIL @@ -101,18 +98,12 @@ [StaticRange interface: existence and properties of interface object] expected: FAIL - [Event interface: new Event("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [AbortSignal interface: attribute aborted] expected: FAIL [AbstractRange interface: existence and properties of interface prototype object] expected: FAIL - [Event interface: operation composedPath()] - expected: FAIL - [AbstractRange interface: attribute endContainer] expected: FAIL @@ -203,9 +194,6 @@ [Element interface: operation prepend([object Object\],[object Object\])] expected: FAIL - [Event interface: document.createEvent("Event") must inherit property "composedPath()" with the proper type] - expected: FAIL - [StaticRange interface object length] expected: FAIL diff --git a/tests/wpt/meta/dom/idlharness.any.js.ini b/tests/wpt/meta/dom/idlharness.any.js.ini index f8b71944105..6424f8a1253 100644 --- a/tests/wpt/meta/dom/idlharness.any.js.ini +++ b/tests/wpt/meta/dom/idlharness.any.js.ini @@ -5,24 +5,15 @@ expected: ERROR [idlharness.any.worker.html] - [Event interface: operation composedPath()] - expected: FAIL - [Event interface: attribute composed] expected: FAIL - [Event interface: new Event("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [Event interface: new Event("foo") must inherit property "composed" with the proper type] expected: FAIL [CustomEvent interface: operation initCustomEvent(DOMString, optional boolean, optional boolean, optional any)] expected: FAIL - [Event interface: new CustomEvent("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [Event interface: new CustomEvent("foo") must inherit property "composed" with the proper type] expected: FAIL diff --git a/tests/wpt/meta/dom/idlharness.window.js.ini b/tests/wpt/meta/dom/idlharness.window.js.ini index bd59f2f66a3..1fad2b5d94a 100644 --- a/tests/wpt/meta/dom/idlharness.window.js.ini +++ b/tests/wpt/meta/dom/idlharness.window.js.ini @@ -151,9 +151,6 @@ [XPathResult interface: constant ANY_TYPE on interface prototype object] expected: FAIL - [Event interface: new Event("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [CharacterData interface: operation before((Node or DOMString)...)] expected: FAIL @@ -166,9 +163,6 @@ [XPathResult interface: document.evaluate("//*", document.body) must inherit property "ANY_TYPE" with the proper type] expected: FAIL - [Event interface: operation composedPath()] - expected: FAIL - [XPathEvaluator interface: operation evaluate(DOMString, Node, optional XPathNSResolver?, optional unsigned short, optional XPathResult?)] expected: FAIL @@ -370,9 +364,6 @@ [XPathEvaluator interface: new XPathEvaluator() must inherit property "createNSResolver(Node)" with the proper type] expected: FAIL - [Event interface: document.createEvent("Event") must inherit property "composedPath()" with the proper type] - expected: FAIL - [StaticRange interface object length] expected: FAIL @@ -394,9 +385,6 @@ [AbortSignal interface: new AbortController().signal must inherit property "onabort" with the proper type] expected: FAIL - [Event interface: new CustomEvent("foo") must inherit property "composedPath()" with the proper type] - expected: FAIL - [Document interface: calling evaluate(DOMString, Node, optional XPathNSResolver?, optional unsigned short, optional XPathResult?) on xmlDoc with too few arguments must throw TypeError] expected: FAIL