Use constants for pointer types
authorgraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Feb 2019 22:28:32 +0000 (22:28 +0000)
committergraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Feb 2019 22:28:32 +0000 (22:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194232

Reviewed by Dean Jackson.

We cannot use an enum for the pointer type since a custom pointer type can be created by developers when creating a
pointer event using JavaScript, but we can at least used string constants for the ones created internally.

* dom/PointerEvent.cpp:
(WebCore::PointerEvent::mousePointerType):
(WebCore::PointerEvent::penPointerType):
(WebCore::PointerEvent::touchPointerType):
* dom/PointerEvent.h:
* dom/ios/PointerEventIOS.cpp:

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

Source/WebCore/ChangeLog
Source/WebCore/dom/PointerEvent.cpp
Source/WebCore/dom/PointerEvent.h
Source/WebCore/dom/ios/PointerEventIOS.cpp

index c5b6723..de55a28 100644 (file)
@@ -1,3 +1,20 @@
+2019-02-04  Antoine Quint  <graouts@apple.com>
+
+        Use constants for pointer types
+        https://bugs.webkit.org/show_bug.cgi?id=194232
+
+        Reviewed by Dean Jackson.
+
+        We cannot use an enum for the pointer type since a custom pointer type can be created by developers when creating a
+        pointer event using JavaScript, but we can at least used string constants for the ones created internally.
+
+        * dom/PointerEvent.cpp:
+        (WebCore::PointerEvent::mousePointerType):
+        (WebCore::PointerEvent::penPointerType):
+        (WebCore::PointerEvent::touchPointerType):
+        * dom/PointerEvent.h:
+        * dom/ios/PointerEventIOS.cpp:
+
 2019-02-04  Zalan Bujtas  <zalan@apple.com>
 
         [First paint] Adjust "finishedParsingMainDocument" flag by taking deferred and async scripts into account.
index 5184b28..fb62c35 100644 (file)
 
 namespace WebCore {
 
+const String& PointerEvent::mousePointerType()
+{
+    static NeverDestroyed<const String> mouseType(MAKE_STATIC_STRING_IMPL("mouse"));
+    return mouseType;
+}
+
+const String& PointerEvent::penPointerType()
+{
+    static NeverDestroyed<const String> penType(MAKE_STATIC_STRING_IMPL("pen"));
+    return penType;
+}
+
+const String& PointerEvent::touchPointerType()
+{
+    static NeverDestroyed<const String> touchType(MAKE_STATIC_STRING_IMPL("touch"));
+    return touchType;
+}
+
 PointerEvent::PointerEvent() = default;
 
 PointerEvent::PointerEvent(const AtomicString& type, Init&& initializer)
index 64fac5f..de78093 100644 (file)
@@ -48,7 +48,7 @@ public:
         long tiltX { 0 };
         long tiltY { 0 };
         long twist { 0 };
-        String pointerType { "mouse"_s };
+        String pointerType { PointerEvent::mousePointerType() };
         bool isPrimary { false };
     };
 
@@ -85,6 +85,10 @@ public:
     static Ref<PointerEvent> create(const PlatformTouchEvent&, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
 #endif
 
+    static const String& mousePointerType();
+    static const String& penPointerType();
+    static const String& touchPointerType();
+
     virtual ~PointerEvent();
 
     PointerID pointerId() const { return m_pointerId; }
@@ -117,7 +121,7 @@ private:
     long m_tiltX { 0 };
     long m_tiltY { 0 };
     long m_twist { 0 };
-    String m_pointerType { "mouse"_s };
+    String m_pointerType { PointerEvent::mousePointerType() };
     bool m_isPrimary { false };
 };
 
index 805ad34..4502400 100644 (file)
@@ -69,7 +69,7 @@ PointerEvent::PointerEvent(const AtomicString& type, const PlatformTouchEvent& e
     , m_width(2 * event.radiusXAtIndex(index))
     , m_height(2 * event.radiusYAtIndex(index))
     , m_pressure(event.forceAtIndex(index))
-    , m_pointerType(event.touchTypeAtIndex(index) == PlatformTouchPoint::TouchType::Stylus ? "pen"_s : "touch"_s)
+    , m_pointerType(event.touchTypeAtIndex(index) == PlatformTouchPoint::TouchType::Stylus ? PointerEvent::penPointerType() : PointerEvent::touchPointerType())
     , m_isPrimary(isPrimary)
 {
     // See https://github.com/w3c/pointerevents/issues/274. We might expose the azimuth and altitude