From b1ab72e589b502ec1e5652396166fa29c622e86f Mon Sep 17 00:00:00 2001 From: Jo Steven Novaryo <65610990+stevennovaryo@users.noreply.github.com> Date: Mon, 15 Sep 2025 16:50:16 +0800 Subject: [PATCH] Set composed flag for `TouchEvent` (#39138) Following the definition of `TouchEvent` in https://w3c.github.io/touch-events/#list-of-touchevent-types, all `TouchEvent` should have its `composed` flag set to be able to propagate past a shadow root layer. Part of #35997 Testing: Would require a testdriver. Signed-off-by: Jo Steven Novaryo --- .../script/dom/document_event_handler.rs | 3 ++- components/script/dom/touchevent.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/script/dom/document_event_handler.rs b/components/script/dom/document_event_handler.rs index 4bf5ee54e34..734a081a1fd 100644 --- a/components/script/dom/document_event_handler.rs +++ b/components/script/dom/document_event_handler.rs @@ -44,7 +44,7 @@ use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::root::MutNullableDom; use crate::dom::clipboardevent::ClipboardEventType; use crate::dom::document::{FireMouseEventType, FocusInitiator, TouchEventResult}; -use crate::dom::event::{EventBubbles, EventCancelable, EventDefault}; +use crate::dom::event::{EventBubbles, EventCancelable, EventComposed, EventDefault}; use crate::dom::gamepad::gamepad::{Gamepad, contains_user_gesture}; use crate::dom::gamepad::gamepadevent::GamepadEventType; use crate::dom::inputevent::HitTestResult; @@ -870,6 +870,7 @@ impl DocumentEventHandler { DOMString::from(event_name), EventBubbles::Bubbles, EventCancelable::from(event.is_cancelable()), + EventComposed::Composed, Some(window), 0i32, &touches, diff --git a/components/script/dom/touchevent.rs b/components/script/dom/touchevent.rs index 4f8dfb334c1..f0895de4e19 100644 --- a/components/script/dom/touchevent.rs +++ b/components/script/dom/touchevent.rs @@ -12,21 +12,36 @@ use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::root::{DomRoot, MutDom}; use crate::dom::bindings::str::DOMString; -use crate::dom::event::{EventBubbles, EventCancelable}; +use crate::dom::event::{Event, EventBubbles, EventCancelable, EventComposed}; use crate::dom::touchlist::TouchList; use crate::dom::uievent::UIEvent; use crate::dom::window::Window; use crate::script_runtime::CanGc; +/// #[dom_struct] pub(crate) struct TouchEvent { uievent: UIEvent, + + /// touches: MutDom, + + /// target_touches: MutDom, + + /// changed_touches: MutDom, + + /// alt_key: Cell, + + /// meta_key: Cell, + + /// ctrl_key: Cell, + + /// shift_key: Cell, } @@ -72,6 +87,7 @@ impl TouchEvent { type_: DOMString, can_bubble: EventBubbles, cancelable: EventCancelable, + composed: EventComposed, view: Option<&Window>, detail: i32, touches: &TouchList, @@ -92,6 +108,7 @@ impl TouchEvent { view, detail, ); + ev.upcast::().set_composed(bool::from(composed)); ev.ctrl_key.set(ctrl_key); ev.alt_key.set(alt_key); ev.shift_key.set(shift_key);