dom: Firing "click" event as synthetic pointer event (#36274)

According to specification

https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-click-event
"Firing a click event at target means firing a synthetic pointer event
named click at target"

So need to replace synthetic mouse event with "click" type to pointer
event.

https://w3c.github.io/pointerevents/#the-click-auxclick-and-contextmenu-events
https://www.w3.org/TR/uievents/#event-type-click

Firing "click" event could be triggered from script or by UA:
- element.click()
(https://html.spec.whatwg.org/multipage/interaction.html#dom-click)
- form implicit submission
(https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission)
- keyboard activation (space)

---
- [x] ./mach build -d does not report any errors
- [x] ./mach test-tidy does not report any errors
- [x] There are tests for these changes
tests/wpt/tests/shadow-dom/event-composed.html
tests/wpt/tests/uievents/interface/click-event.htm

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-04-02 14:20:25 +03:00 committed by GitHub
parent b925c31424
commit 3bc0eeab8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 73 additions and 60 deletions

View file

@ -23,6 +23,13 @@ use crate::dom::mouseevent::MouseEvent;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
/// <https://w3c.github.io/pointerevents/#dom-pointerevent-pointerid>
#[derive(Clone, Copy, MallocSizeOf, PartialEq)]
pub(crate) enum PointerId {
NonPointerDevice = -1,
Mouse,
}
#[dom_struct]
pub(crate) struct PointerEvent {
mouseevent: MouseEvent,
@ -83,7 +90,6 @@ impl PointerEvent {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
window: &Window,
proto: Option<HandleObject>,
type_: DOMString,
can_bubble: EventBubbles,
cancelable: EventCancelable,
@ -119,7 +125,7 @@ impl PointerEvent {
) -> DomRoot<PointerEvent> {
Self::new_with_proto(
window,
proto,
None,
type_,
can_bubble,
cancelable,