Title: [202178] trunk
Revision
202178
Author
[email protected]
Date
2016-06-17 13:51:11 -0700 (Fri, 17 Jun 2016)

Log Message

TouchEvent should have a constructor
https://bugs.webkit.org/show_bug.cgi?id=158883
<rdar://problem/26063585>

Reviewed by Benjamin Poulain.

Source/WebCore:

TouchEvent should have a constructor:
- https://w3c.github.io/touch-events/#touchevent-interface

Chrome already ships this:
- https://bugs.chromium.org/p/chromium/issues/detail?id=508675

Test: fast/events/touch/touch-event-constructor.html

* bindings/js/JSDictionary.cpp:
(WebCore::JSDictionary::convertValue):
* bindings/js/JSDictionary.h:
* dom/TouchEvent.cpp:
(WebCore::TouchEvent::TouchEvent):
* dom/TouchEvent.h:
* dom/TouchEvent.idl:

LayoutTests:

Add layout test coverage for the TouchEvent constructor.

* fast/events/touch/touch-event-constructor-expected.txt: Added.
* fast/events/touch/touch-event-constructor.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (202177 => 202178)


--- trunk/LayoutTests/ChangeLog	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/LayoutTests/ChangeLog	2016-06-17 20:51:11 UTC (rev 202178)
@@ -1,5 +1,18 @@
 2016-06-17  Chris Dumez  <[email protected]>
 
+        TouchEvent should have a constructor
+        https://bugs.webkit.org/show_bug.cgi?id=158883
+        <rdar://problem/26063585>
+
+        Reviewed by Benjamin Poulain.
+
+        Add layout test coverage for the TouchEvent constructor.
+
+        * fast/events/touch/touch-event-constructor-expected.txt: Added.
+        * fast/events/touch/touch-event-constructor.html: Added.
+
+2016-06-17  Chris Dumez  <[email protected]>
+
         URL hash setter does not remove fragment identifier if argument is an empty string
         https://bugs.webkit.org/show_bug.cgi?id=158869
         <rdar://problem/26863430>

Added: trunk/LayoutTests/fast/events/touch/touch-event-constructor-expected.txt (0 => 202178)


--- trunk/LayoutTests/fast/events/touch/touch-event-constructor-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/touch-event-constructor-expected.txt	2016-06-17 20:51:11 UTC (rev 202178)
@@ -0,0 +1,44 @@
+Test the TouchEvent constructor
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS ev = new TouchEvent('touchstart') did not throw exception.
+PASS ev.__proto__ is TouchEvent.prototype
+PASS ev.type is "touchstart"
+PASS ev.touches.length is 0
+PASS ev.targetTouches.length is 0
+PASS ev.changedTouches.length is 0
+PASS ev.bubbles is false
+PASS ev = new TouchEvent('touchmove', { touches: listA, bubbles: true }) did not throw exception.
+PASS ev.__proto__ is TouchEvent.prototype
+PASS ev.type is "touchmove"
+PASS ev.touches.length is 1
+PASS ev.targetTouches.length is 0
+PASS ev.changedTouches.length is 0
+PASS ev.bubbles is true
+PASS ev = new TouchEvent('touchmove', { targetTouches: listB, bubbles: true }) did not throw exception.
+PASS ev.__proto__ is TouchEvent.prototype
+PASS ev.type is "touchmove"
+PASS ev.touches.length is 0
+PASS ev.targetTouches.length is 2
+PASS ev.changedTouches.length is 0
+PASS ev.bubbles is true
+PASS ev = new TouchEvent('touchmove', { changedTouches: listC, bubbles: true }) did not throw exception.
+PASS ev.__proto__ is TouchEvent.prototype
+PASS ev.type is "touchmove"
+PASS ev.touches.length is 0
+PASS ev.targetTouches.length is 0
+PASS ev.changedTouches.length is 3
+PASS ev.bubbles is true
+PASS ev = new TouchEvent('touchmove', { touches: listA, targetTouches: listB, changedTouches: listC, bubbles: true }) did not throw exception.
+PASS ev.__proto__ is TouchEvent.prototype
+PASS ev.type is "touchmove"
+PASS ev.touches.length is 1
+PASS ev.targetTouches.length is 2
+PASS ev.changedTouches.length is 3
+PASS ev.bubbles is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/touch/touch-event-constructor.html (0 => 202178)


--- trunk/LayoutTests/fast/events/touch/touch-event-constructor.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/touch-event-constructor.html	2016-06-17 20:51:11 UTC (rev 202178)
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("Test the TouchEvent constructor");
+
+// No dictionary.
+shouldNotThrow("ev = new TouchEvent('touchstart')");
+shouldBe("ev.__proto__", "TouchEvent.prototype");
+shouldBeEqualToString("ev.type", "touchstart");
+shouldBe("ev.touches.length", "0");
+shouldBe("ev.targetTouches.length", "0");
+shouldBe("ev.changedTouches.length", "0");
+shouldBeFalse("ev.bubbles");
+
+// With dictionary.
+var touch = document.createTouch(window, document.body, 12341, 60, 65, 100, 105);
+var listA = document.createTouchList(touch);
+var listB = document.createTouchList(touch, touch);
+var listC = document.createTouchList(touch, touch, touch);
+shouldNotThrow("ev = new TouchEvent('touchmove', { touches: listA, bubbles: true })");
+shouldBe("ev.__proto__", "TouchEvent.prototype");
+shouldBeEqualToString("ev.type", "touchmove");
+shouldBe("ev.touches.length", "1");
+shouldBe("ev.targetTouches.length", "0");
+shouldBe("ev.changedTouches.length", "0");
+shouldBeTrue("ev.bubbles");
+
+shouldNotThrow("ev = new TouchEvent('touchmove', { targetTouches: listB, bubbles: true })");
+shouldBe("ev.__proto__", "TouchEvent.prototype");
+shouldBeEqualToString("ev.type", "touchmove");
+shouldBe("ev.touches.length", "0");
+shouldBe("ev.targetTouches.length", "2");
+shouldBe("ev.changedTouches.length", "0");
+shouldBeTrue("ev.bubbles");
+
+shouldNotThrow("ev = new TouchEvent('touchmove', { changedTouches: listC, bubbles: true })");
+shouldBe("ev.__proto__", "TouchEvent.prototype");
+shouldBeEqualToString("ev.type", "touchmove");
+shouldBe("ev.touches.length", "0");
+shouldBe("ev.targetTouches.length", "0");
+shouldBe("ev.changedTouches.length", "3");
+shouldBeTrue("ev.bubbles");
+
+shouldNotThrow("ev = new TouchEvent('touchmove', { touches: listA, targetTouches: listB, changedTouches: listC, bubbles: true })");
+shouldBe("ev.__proto__", "TouchEvent.prototype");
+shouldBeEqualToString("ev.type", "touchmove");
+shouldBe("ev.touches.length", "1");
+shouldBe("ev.targetTouches.length", "2");
+shouldBe("ev.changedTouches.length", "3");
+shouldBeTrue("ev.bubbles");
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (202177 => 202178)


--- trunk/Source/WebCore/ChangeLog	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/Source/WebCore/ChangeLog	2016-06-17 20:51:11 UTC (rev 202178)
@@ -1,3 +1,27 @@
+2016-06-17  Chris Dumez  <[email protected]>
+
+        TouchEvent should have a constructor
+        https://bugs.webkit.org/show_bug.cgi?id=158883
+        <rdar://problem/26063585>
+
+        Reviewed by Benjamin Poulain.
+
+        TouchEvent should have a constructor:
+        - https://w3c.github.io/touch-events/#touchevent-interface
+
+        Chrome already ships this:
+        - https://bugs.chromium.org/p/chromium/issues/detail?id=508675
+
+        Test: fast/events/touch/touch-event-constructor.html
+
+        * bindings/js/JSDictionary.cpp:
+        (WebCore::JSDictionary::convertValue):
+        * bindings/js/JSDictionary.h:
+        * dom/TouchEvent.cpp:
+        (WebCore::TouchEvent::TouchEvent):
+        * dom/TouchEvent.h:
+        * dom/TouchEvent.idl:
+
 2016-06-17  Zalan Bujtas  <[email protected]>
 
         Potential null dereferencing on a detached positioned renderer.

Modified: trunk/Source/WebCore/bindings/js/JSDictionary.cpp (202177 => 202178)


--- trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2016-06-17 20:51:11 UTC (rev 202178)
@@ -67,6 +67,10 @@
 #include "JSGamepad.h"
 #endif
 
+#if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(TOUCH_EVENTS)
+#include "JSTouchList.h"
+#endif
+
 using namespace JSC;
 
 namespace WebCore {
@@ -326,6 +330,13 @@
 }
 #endif
 
+#if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(TOUCH_EVENTS)
+void JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, RefPtr<TouchList>& result)
+{
+    result = JSTouchList::toWrapped(value);
+}
+#endif
+
 void JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, JSC::JSFunction*& result)
 {
     result = jsDynamicCast<JSC::JSFunction*>(value);

Modified: trunk/Source/WebCore/bindings/js/JSDictionary.h (202177 => 202178)


--- trunk/Source/WebCore/bindings/js/JSDictionary.h	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.h	2016-06-17 20:51:11 UTC (rev 202178)
@@ -57,6 +57,7 @@
 class Node;
 class SerializedScriptValue;
 class Storage;
+class TouchList;
 class TrackBase;
 class VoidCallback;
 
@@ -165,6 +166,9 @@
     static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Gamepad>&);
 #endif
     static void convertValue(JSC::ExecState*, JSC::JSValue, JSC::JSFunction*&);
+#if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(TOUCH_EVENTS)
+    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<TouchList>&);
+#endif
 
     JSC::ExecState* m_exec;
     JSC::Strong<JSC::JSObject> m_initializerObject;

Modified: trunk/Source/WebCore/dom/TouchEvent.cpp (202177 => 202178)


--- trunk/Source/WebCore/dom/TouchEvent.cpp	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/Source/WebCore/dom/TouchEvent.cpp	2016-06-17 20:51:11 UTC (rev 202178)
@@ -55,6 +55,14 @@
 {
 }
 
+TouchEvent::TouchEvent(const AtomicString& type, const TouchEventInit& initializer)
+    : MouseRelatedEvent(type, initializer)
+    , m_touches(initializer.touches ? initializer.touches : TouchList::create())
+    , m_targetTouches(initializer.targetTouches ? initializer.targetTouches : TouchList::create())
+    , m_changedTouches(initializer.changedTouches ? initializer.changedTouches : TouchList::create())
+{
+}
+
 TouchEvent::~TouchEvent()
 {
 }

Modified: trunk/Source/WebCore/dom/TouchEvent.h (202177 => 202178)


--- trunk/Source/WebCore/dom/TouchEvent.h	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/Source/WebCore/dom/TouchEvent.h	2016-06-17 20:51:11 UTC (rev 202178)
@@ -36,6 +36,12 @@
 
 namespace WebCore {
 
+struct TouchEventInit : public MouseRelatedEventInit {
+    RefPtr<TouchList> touches;
+    RefPtr<TouchList> targetTouches;
+    RefPtr<TouchList> changedTouches;
+};
+
 class TouchEvent final : public MouseRelatedEvent {
 public:
     virtual ~TouchEvent();
@@ -54,6 +60,10 @@
     {
         return adoptRef(*new TouchEvent);
     }
+    static Ref<TouchEvent> createForBindings(const AtomicString& type, const TouchEventInit& initializer)
+    {
+        return adoptRef(*new TouchEvent(type, initializer));
+    }
 
     void initTouchEvent(TouchList* touches, TouchList* targetTouches,
             TouchList* changedTouches, const AtomicString& type, 
@@ -80,6 +90,7 @@
             AbstractView*, int screenX, int screenY, int pageX,
             int pageY,
             bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
+    TouchEvent(const AtomicString&, const TouchEventInit&);
 
     RefPtr<TouchList> m_touches;
     RefPtr<TouchList> m_targetTouches;

Modified: trunk/Source/WebCore/dom/TouchEvent.idl (202177 => 202178)


--- trunk/Source/WebCore/dom/TouchEvent.idl	2016-06-17 20:21:17 UTC (rev 202177)
+++ trunk/Source/WebCore/dom/TouchEvent.idl	2016-06-17 20:51:11 UTC (rev 202178)
@@ -25,10 +25,11 @@
 
 [
     Conditional=TOUCH_EVENTS,
+    ConstructorTemplate=Event,
 ] interface TouchEvent : UIEvent {
-    readonly attribute TouchList touches;
-    readonly attribute TouchList targetTouches;
-    readonly attribute TouchList changedTouches;
+    [InitializedByEventConstructor] readonly attribute TouchList touches;
+    [InitializedByEventConstructor] readonly attribute TouchList targetTouches;
+    [InitializedByEventConstructor] readonly attribute TouchList changedTouches;
     readonly attribute boolean ctrlKey;
     readonly attribute boolean shiftKey;
     readonly attribute boolean altKey;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to