script: Stop handling native mousedown and mouseup for disabled elements (#38671)

According to spec of
[hit-test](https://w3c.github.io/uievents/#hit-test) for native mouse
event, mousedown/mouseup should also be excluded when interacting with
disabled element, even tho it may be the frontmost of
[elementFromPoint](https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint).

Testing: Now it matches the behaviour of other browsers in #38670 for
disabled element. Also testdriver test:
`tests\wpt\tests\html\semantics\disabled-elements\disabled-event-dispatch.tentative.html`
has 4 more passing tests.
Fixes: Part of #38670.

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
Euclid Ye 2025-08-15 09:24:47 +08:00 committed by GitHub
parent 89bd01a3b4
commit dafb0abf31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -530,13 +530,13 @@ impl DocumentEventHandler {
let node = el.upcast::<Node>();
debug!("{:?} on {:?}", event.action, node.debug_str());
// Prevent click event if form control element is disabled.
if let MouseButtonAction::Click = event.action {
// The click event is filtered by the disabled state.
// https://w3c.github.io/uievents/#hit-test
// Prevent mouse event if element is disabled.
// TODO: also inert.
if el.is_actually_disabled() {
return;
}
}
let dom_event = DomRoot::upcast::<Event>(MouseEvent::for_platform_mouse_event(
event,