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 <https://bugzilla.mozilla.org/show_bug.cgi?id=1675847>

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 <https://wpt.fyi/results/pointerevents/pointerevent_click_is_a_pointerevent.html%3Fmouse?label=master&label=experimental&aligned>, auxclick <https://wpt.fyi/results/pointerevents/pointerevent_auxclick_is_a_pointerevent.html%3Fmouse?label=master&label=experimental&aligned> and contextmenu <https://wpt.fyi/results/pointerevents/pointerevent_contextmenu_is_a_pointerevent.html%3Fmouse?label=master&label=experimental&aligned>

--
Masayuki Nakano<[email protected]>
Working on DOM, Events, editor and IME handling for Gecko

--
You received this message because you are subscribed to the Google Groups 
"[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/mozilla.org/d/msgid/dev-platform/0201fd63-5996-4416-b9a6-46921d15a075%40d-toybox.com.

Reply via email to