[iOS] Compatibility mouse events aren't prevented by calling preventDefault() on pointerdown
https://bugs.webkit.org/show_bug.cgi?id=198124
<rdar://problem/50410863>

Reviewed by Tim Horton.

LayoutTests/imported/w3c:

We add basic support to run a test that wasn't specifically designed for a touch-based interaction such that the test
at imported/w3c/web-platform-tests/pointerevents/pointerevent_suppress_compat_events_on_click.html may run on iOS. The
trick here is to add a pause after a touch ends to avoid the likelihood or two tap gestures triggering a double tap.

* web-platform-tests/resources/testdriver-vendor.js:

Source/WebCore:

This fix builds atop the one made for wkb.ug/198072 which fixes this bug on macOS alone.

In order to correctly prevent "compatibility" mouse events from being dispatched when the initial "pointerdown" event had preventDefault()
called while handled, we need to pass the PointerID for the touch that triggered a tap gesture in the UI process down in the Web process
and into the resulting PlatformMouseEvent. This will allow upon dispatch of a PlatformMouseEvent to call into PointerCaptureController
to identify if the dispatch of mouse events is allowed for the event's PointerID.

To support this, some refactoring was required. The PointerID header is now under platform/ such that PlatformMouseEvent may safely use it.
Additionally, PointerEvent::defaultMousePointerIdentifier() is now a global mousePointerID defined in PointerID.h.

Finally, PointerCaptureController::touchEndedOrWasCancelledForIdentifier() has been renamed to PointerCaptureController::touchWithIdentifierWasRemoved() and
has WEBCORE_EXPORT such that it may be called from WebKit as the indication that a pointer is no longer active will now be initiated in WebKit
on the UI process side.

Testing is covered by the pre-existing imported/w3c/web-platform-tests/pointerevents/pointerevent_suppress_compat_events_on_click.html
which will now run on iOS through a change to WebKitAdditions.

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
* dom/Element.cpp:
(WebCore::Element::dispatchMouseEvent): When dealing with a mouse event on iOS, check whether the mouse event's PointerID allows for compatibility
mouse events to be dispatched using PointerCaptureController::preventsCompatibilityMouseEventsForIdentifier(). The "click" event is not a compatibility
mouse event.
* dom/PointerEvent.h:
* page/PointerCaptureController.cpp:
(WebCore::PointerCaptureController::PointerCaptureController):
(WebCore::PointerCaptureController::touchWithIdentifierWasRemoved):
(WebCore::PointerCaptureController::touchEndedOrWasCancelledForIdentifier): Deleted.
* page/PointerCaptureController.h:
* platform/PlatformMouseEvent.h:
(WebCore::PlatformMouseEvent::PlatformMouseEvent):
(WebCore::PlatformMouseEvent::pointerId const):
* platform/PointerID.h: Renamed from Source/WebCore/dom/PointerID.h.
(WebCore::mousePointerID):

Source/WebKit:

In order to correctly prevent "compatibility" mouse events from being dispatched when the initial "pointerdown" event had preventDefault()
called while handled, we need to pass the PointerID for the touch that triggered a tap gesture in the UI process down in the Web process
and into the resulting PlatformMouseEvent.

This means we need to identify the touch identifier, which is the same as the PointerID used for Pointer Events, in the single tap gesture
recognizer, an instance of WKSyntheticTapGestureRecognizer. To do this, we subclass the -[UIResponder touchesEnded:withEvent:] method and
track the touch identifier as the lastActiveTouchIdentifier, a new public property of WKSyntheticTapGestureRecognizer. To allow for this,
we need the support of the content view's UIWebTouchEventsGestureRecognizer which is exposed to the WKSyntheticTapGestureRecognizer as its
supportingWebTouchEventsGestureRecognizer property. This lastActiveTouchIdentifier property is cleared as the gesture recognizer is reset.

This allows the content view to pass the PointerID down to the Web process starting from -[WKContentView _singleTapRecognized:], going
through WebPageProxy::commitPotentialTap() and eventually WebPage::completeSyntheticClick().

While we used to tell the PointerCaptureController that a PointerID was no longer active when a given touch ended or was canceled (in
WebKitAdditions code), we can no longer do this as the dispatch of a synthetic tap is performed asynchronously and will happen past the
dispatch of "pointerup" and "pointercancel" Pointer Events. To clear inactive PointerIDs from the PointerCaptureController, we add a new
touchWithIdentifierWasRemoved() method on the WebPage and its proxy. When the WKSyntheticTapGestureRecognizer resets and -[WKContentView _singleTapDidReset:]
is called, we call that method which allows for only active PointerIDs to be tracked by the PointerCaptureController.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setupInteraction]):
(-[WKContentView cleanupInteraction]):
(-[WKContentView _singleTapDidReset:]):
(-[WKContentView _singleTapRecognized:]):
* UIProcess/ios/WKSyntheticTapGestureRecognizer.h:
* UIProcess/ios/WKSyntheticTapGestureRecognizer.m:
(-[WKSyntheticTapGestureRecognizer reset]):
(-[WKSyntheticTapGestureRecognizer touchesEnded:withEvent:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::touchWithIdentifierWasRemoved):
(WebKit::WebPageProxy::commitPotentialTap):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::dispatchSyntheticMouseMove):
(WebKit::WebPage::handleSyntheticClick):
(WebKit::WebPage::completePendingSyntheticClickForContentChangeObserver):
(WebKit::WebPage::completeSyntheticClick):
(WebKit::WebPage::commitPotentialTap):
(WebKit::WebPage::touchWithIdentifierWasRemoved):

LayoutTests:

We're adding an iOS-specific expectation since this test prints out the pointer type detected while it runs, which is "touch"
on iOS and "mouse" in the expectation that already exists for macOS.

* platform/ios/imported/w3c/web-platform-tests/pointerevents/pointerevent_suppress_compat_events_on_click-expected.txt: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245639 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/PointerEvent.h b/Source/WebCore/dom/PointerEvent.h
index d51de26..3da0f93 100644
--- a/Source/WebCore/dom/PointerEvent.h
+++ b/Source/WebCore/dom/PointerEvent.h
@@ -40,7 +40,7 @@
 class PointerEvent final : public MouseEvent {
 public:
     struct Init : MouseEventInit {
-        PointerID pointerId { PointerEvent::defaultMousePointerIdentifier() };
+        PointerID pointerId { mousePointerID };
         double width { 1 };
         double height { 1 };
         float pressure { 0 };
@@ -85,7 +85,6 @@
     static const String& mousePointerType();
     static const String& penPointerType();
     static const String& touchPointerType();
-    static PointerID defaultMousePointerIdentifier() { return 1; }
 
     virtual ~PointerEvent();
 
@@ -113,7 +112,7 @@
     PointerEvent(const AtomicString& type, const PlatformTouchEvent&, IsCancelable isCancelable, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
 #endif
 
-    PointerID m_pointerId { PointerEvent::defaultMousePointerIdentifier() };
+    PointerID m_pointerId { mousePointerID };
     double m_width { 1 };
     double m_height { 1 };
     float m_pressure { 0 };