Summary: Change `click`
, `auxclick`
and `contextmenu`
event class from `MouseEvent`
to `PointerEvent`
.
Those event types are dispatched as a `MouseEvent`
,
however, UI Events defines their event class as `PointerEvent`
right now. Therefore, we'll update all those event dispatchers in
C++ code and chrome script.
Note that the behavior is switchable with a new pref, `dom.w3c_pointer_events.dispatch_click_as_pointer_event`
.
Therefore, for a while, new event dispatchers in C++ need to do:
Maybe<WidgetPointerEvent> pointerEvent; Maybe<WidgetMouseEvent> mouseEvent; if (StaticPrefs::dom_w3c_pointer_events_dispatch_click_as_pointer_event()) { pointerEvent.emplace(true, ePointerClick, widget); } else { mouseEvent.emplace(true, ePointerClick, widget, WidgetMouseEvent::eReal); } WidgetMouseEvent& mouseOrPointerEvent = pointerEvent.isSome() ? pointerEvent.ref() : mouseEvent.ref(); mouseOrPointerEvent.mSomething = something; widget->DispatchInputEvent(mouseOrPointerEvent);
and chrome script and mochitest in chrome context need to do:
const ClickEventConstructor = SpecialPowers.getBoolPref( "dom.w3c_pointer_events.dispatch_click_as_pointer_event" ) ? PointerEvent : MouseEvent; const clickEvent = new ClickEventConstructor("click", { bubbles: true, cancelable: true, ... }); target.dispatchEvent(clickEvent);
Note that `document.createEvent("PointerEvent")`
does not work. Therefore, if you need to rewrite an event
dispatcher which uses `document.createEvent("MouseEvent")`
,
you need to stop using `initMouseEvent`
or `initNSMouseEvent`
.
Finally, if need to handle untrusted those events in C++
code, `ePointerClick`
, `ePointerAuxClick`
and `eContextMenu`
event messages are set to `WidgetEvent::mMessage`
when both the event class is `WidgetPointerEvent`
and `WidgetMouseEvent`
. Therefore, you can
keep using `switch`
statement with the event
message. However, you cannot use `AsPointerEvent()`
because it may be `WidgetMouseEvent`
.
The pref will be enabled in all channels immediately, i.e., the pref is for easier backout and checking whether regressions reports are caused by this change. So, once this change is shipped, the pref will be removed as soon as possible to make the dispatchers simpler.
Bug: Bug 1675847 - Update click/auxclick/contextmenu and click() to use PointerEvent
Pref: `dom.w3c_pointer_events.dispatch_click_as_pointer_event`
Spec: <https://w3c.github.io/uievents/#event-type-click>,
<https://w3c.github.io/uievents/#event-type-auxclick>
and <https://w3c.github.io/uievents/#event-type-contextmenu>
Other: Chrome has already updated, but Safari has not done that yet.
Web-platform tests: click,
auxclick
and contextmenu
-- Masayuki Nakano <masa...@d-toybox.com> Working on DOM, Events, editor and IME handling for Gecko