Expose a constructor for PointerEvent from PlatformTouchEvent
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Nov 2018 18:37:43 +0000 (18:37 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Nov 2018 18:37:43 +0000 (18:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191238
<rdar://problem/45795682>

Reviewed by Antoine Quint.

Implement a constructor that takes a PlatformTouchEvent to
create a PointerEvent. At the moment the code to call this
constructor will live in WebKitAdditions, so no new tests
yet.

* SourcesCocoa.txt: Add PointerEventIOS.cpp.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* dom/EventNames.h: Add macros for pointerdown, pointermove,
     pointerup, pointercancel.
* dom/PointerEvent.cpp: Remove JSC namespace.
* dom/PointerEvent.h: Add create and constructor that takes
     a PlatformTouchEvent.
* dom/ios/PointerEventIOS.cpp: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237816 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/PointerEvent.cpp
Source/WebCore/dom/PointerEvent.h
Source/WebCore/dom/ios/PointerEventIOS.cpp [new file with mode: 0644]

index c07afc5..cfe0ac9 100644 (file)
@@ -1,3 +1,25 @@
+2018-11-05  Dean Jackson  <dino@apple.com>
+
+        Expose a constructor for PointerEvent from PlatformTouchEvent
+        https://bugs.webkit.org/show_bug.cgi?id=191238
+        <rdar://problem/45795682>
+
+        Reviewed by Antoine Quint.
+
+        Implement a constructor that takes a PlatformTouchEvent to
+        create a PointerEvent. At the moment the code to call this
+        constructor will live in WebKitAdditions, so no new tests
+        yet.
+
+        * SourcesCocoa.txt: Add PointerEventIOS.cpp.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * dom/EventNames.h: Add macros for pointerdown, pointermove,
+             pointerup, pointercancel.
+        * dom/PointerEvent.cpp: Remove JSC namespace.
+        * dom/PointerEvent.h: Add create and constructor that takes
+             a PlatformTouchEvent.
+        * dom/ios/PointerEventIOS.cpp: Added.
+
 2018-11-05  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r237785.
index 49be3d1..1474e59 100644 (file)
@@ -73,6 +73,7 @@ crypto/mac/SerializedCryptoKeyWrapMac.mm
 
 dom/DataTransferMac.mm
 
+dom/ios/PointerEventIOS.cpp
 dom/ios/TouchEvents.cpp
 
 editing/SelectionRectGatherer.cpp
index ffe523b..86146c9 100644 (file)
                314BE3A21B30F6D100141982 /* CSSNamedImageValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSNamedImageValue.cpp; sourceTree = "<group>"; };
                314BE3A41B3103FB00141982 /* NamedImageGeneratedImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NamedImageGeneratedImage.cpp; sourceTree = "<group>"; };
                314BE3A51B3103FB00141982 /* NamedImageGeneratedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NamedImageGeneratedImage.h; sourceTree = "<group>"; };
+               315574CC218F66D000D88F66 /* PointerEventIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PointerEventIOS.cpp; sourceTree = "<group>"; };
                316BDB841E6E0A2100DE0D5A /* GPULegacyDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GPULegacyDevice.cpp; sourceTree = "<group>"; };
                316BDB851E6E0A2100DE0D5A /* GPULegacyDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPULegacyDevice.h; sourceTree = "<group>"; };
                316BDB881E6E141C00DE0D5A /* GPULegacyDeviceMetal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPULegacyDeviceMetal.mm; sourceTree = "<group>"; };
                CE2616A4187E65C1007955F3 /* ios */ = {
                        isa = PBXGroup;
                        children = (
+                               315574CC218F66D000D88F66 /* PointerEventIOS.cpp */,
                                A1DE712B18612AC100734192 /* TouchEvents.cpp */,
                        );
                        path = ios;
index 9353983..526e1d7 100644 (file)
@@ -198,6 +198,10 @@ namespace WebCore {
     macro(playing) \
     macro(pointerlockchange) \
     macro(pointerlockerror) \
+    macro(pointercancel) \
+    macro(pointerdown) \
+    macro(pointermove) \
+    macro(pointerup) \
     macro(popstate) \
     macro(previoustrack) \
     macro(progress) \
index 43001f7..f2d7670 100644 (file)
@@ -28,8 +28,6 @@
 
 namespace WebCore {
 
-using namespace JSC;
-
 PointerEvent::PointerEvent() = default;
 
 PointerEvent::PointerEvent(const AtomicString& type, Init&& initializer)
index e8fdada..58cfe50 100644 (file)
 #include "MouseEvent.h"
 #include <wtf/text/WTFString.h>
 
+#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
+#include "PlatformTouchEventIOS.h"
+#endif
+
 namespace WebCore {
 
 class PointerEvent final : public MouseEvent {
@@ -55,6 +59,10 @@ public:
         return adoptRef(*new PointerEvent);
     }
 
+#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
+    static Ref<PointerEvent> create(const PlatformTouchEvent&, unsigned touchIndex, Ref<WindowProxy>&&);
+#endif
+
     virtual ~PointerEvent();
 
     long pointerId() const { return m_pointerId; }
@@ -68,13 +76,16 @@ public:
     String pointerType() const { return m_pointerType; }
     bool isPrimary() const { return m_isPrimary; }
 
-    bool isPointerEvent() const override { return true; }
+    bool isPointerEvent() const final { return true; }
 
     EventInterface eventInterface() const override;
 
 private:
     PointerEvent();
     PointerEvent(const AtomicString&, Init&&);
+#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
+    PointerEvent(const AtomicString& type, const PlatformTouchEvent&, IsCancelable isCancelable, unsigned touchIndex, Ref<WindowProxy>&&);
+#endif
 
     long m_pointerId { 0 };
     double m_width { 1 };
diff --git a/Source/WebCore/dom/ios/PointerEventIOS.cpp b/Source/WebCore/dom/ios/PointerEventIOS.cpp
new file mode 100644 (file)
index 0000000..3e984a1
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "PointerEvent.h"
+
+#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
+
+#import "EventNames.h"
+
+namespace WebCore {
+
+static AtomicString eventType(PlatformTouchPoint::TouchPhaseType phase)
+{
+    switch (phase) {
+    case PlatformTouchPoint::TouchPhaseBegan:
+        return eventNames().pointerdownEvent;
+    case PlatformTouchPoint::TouchPhaseMoved:
+        return eventNames().pointermoveEvent;
+    case PlatformTouchPoint::TouchPhaseStationary:
+        return eventNames().pointermoveEvent;
+    case PlatformTouchPoint::TouchPhaseEnded:
+        return eventNames().pointerupEvent;
+    case PlatformTouchPoint::TouchPhaseCancelled:
+        return eventNames().pointercancelEvent;
+    }
+    ASSERT_NOT_REACHED();
+    return nullAtom();
+}
+
+static PointerEvent::IsCancelable phaseIsCancelable(PlatformTouchPoint::TouchPhaseType phase)
+{
+    if (phase == PlatformTouchPoint::TouchPhaseCancelled)
+        return PointerEvent::IsCancelable::No;
+    return PointerEvent::IsCancelable::Yes;
+}
+
+Ref<PointerEvent> PointerEvent::create(const PlatformTouchEvent& event, unsigned index, Ref<WindowProxy>&& view)
+{
+    auto phase = event.touchPhaseAtIndex(index);
+    return adoptRef(*new PointerEvent(eventType(phase), event, phaseIsCancelable(phase), index, WTFMove(view)));
+}
+
+PointerEvent::PointerEvent(const AtomicString& type, const PlatformTouchEvent& event, IsCancelable isCancelable, unsigned index, Ref<WindowProxy>&& view)
+    : MouseEvent(type, CanBubble::Yes, isCancelable, IsComposed::Yes, event.timestamp().approximateMonotonicTime(), WTFMove(view), 0, event.touchLocationAtIndex(index), event.touchLocationAtIndex(index), { }, event.modifiers(), 0, 0, nullptr, 0, 0, nullptr, IsSimulated::No, IsTrusted::Yes)
+    , m_pointerId(event.touchIdentifierAtIndex(index))
+    , m_width(2 * event.radiusXAtIndex(index))
+    , m_height(2 * event.radiusYAtIndex(index))
+    , m_pointerType(event.touchTypeAtIndex(index) == PlatformTouchPoint::TouchType::Stylus ? "pen"_s : "touch"_s)
+    , m_isPrimary(!index)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)