WIP on touch support

Change-Id: I2ae5b0eb7e1271cc3cca5dad5acbe4cf24fe40d8
diff --git a/Source/WebKit/fuchsia/WebView.cpp b/Source/WebKit/fuchsia/WebView.cpp
index 4266059..4a7dba9 100644
--- a/Source/WebKit/fuchsia/WebView.cpp
+++ b/Source/WebKit/fuchsia/WebView.cpp
@@ -38,6 +38,7 @@
 #include <WebCore/PageConfiguration.h>
 #include <WebCore/PlatformCookieJar.h>
 #include <WebCore/PlatformKeyboardEvent.h>
+#include <WebCore/PlatformTouchEvent.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/Settings.h>
 #include <WebCore/URLParser.h>
@@ -293,6 +294,32 @@
     }
 }
 
+void WebView::handleTouchEvent(uint32_t touchId, int x, int y, TouchEventKind eventType)
+{
+#if ENABLE(TOUCH_EVENTS)
+    auto& mainFrame = m_page->mainFrame();
+    IntPoint touchPosition(x, y);
+    auto now = std::chrono::steady_clock::now().time_since_epoch();
+    auto timeSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(now).count();
+    if (eventType == kTouchDown) {
+        WebCore::PlatformTouchEvent mouseEvent(touchPosition, touchPosition,
+            WebCore::MouseButton::LeftButton, PlatformEvent::MousePressed,
+            1, false, false, false, false, timeSinceEpoch, 0, SyntheticClickType::NoTap);
+        mainFrame.eventHandler().handleMousePressEvent(mouseEvent);
+    } else if (eventType == kTouchUp) {
+        WebCore::PlatformTouchEvent mouseEvent(touchPosition, touchPosition,
+            WebCore::MouseButton::LeftButton, PlatformEvent::MouseReleased,
+            1, false, false, false, false, timeSinceEpoch, 0, SyntheticClickType::NoTap);
+        mainFrame.eventHandler().handleMouseReleaseEvent(mouseEvent);
+    } else {
+        WebCore::PlatformTouchEvent mouseEvent(touchPosition, touchPosition,
+            WebCore::MouseButton::NoButton, PlatformEvent::MouseMoved,
+            0, false, false, false, false, timeSinceEpoch, 0, SyntheticClickType::NoTap);
+        mainFrame.eventHandler().mouseMoved(mouseEvent);
+    }
+#endif
+}
+
 bool WebView::handleKeyEvent(uint8_t keycode, uint8_t charValue, bool pressed, bool repeat)
 {
     string identifier;
diff --git a/Source/WebKit/fuchsia/WebView.h b/Source/WebKit/fuchsia/WebView.h
index f5363df..e93e05b 100644
--- a/Source/WebKit/fuchsia/WebView.h
+++ b/Source/WebKit/fuchsia/WebView.h
@@ -50,6 +50,9 @@
     enum MouseEventKind { kMouseDown,
         kMouseMoved,
         kMouseUp };
+    enum TouchEventKind { kTouchDown,
+        kTouchMoved,
+        kTouchUp };
     ~WebView();
 
     bool setup(unsigned char* pixelBuffer, int pixelFormat, size_t targetWidth, size_t targetHeight, size_t rowbytes);
@@ -73,6 +76,7 @@
     void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor);
 
     void handleMouseEvent(int x, int y, MouseEventKind eventType);
+    void handleTouchEvent(uint32_t touchId, int x, int y, TouchEventKind eventType);
     bool handleKeyEvent(uint8_t keycode, uint8_t charValue, bool pressed, bool repeat);
 
     void setWebRequestDelegate(WebRequestDelegate delegate);
diff --git a/Tools/fuchsia/build_webkit.sh b/Tools/fuchsia/build_webkit.sh
index 5842487..73f1608 100755
--- a/Tools/fuchsia/build_webkit.sh
+++ b/Tools/fuchsia/build_webkit.sh
@@ -82,7 +82,7 @@
     --no-jit \
     --no-web-sockets \
     --no-3d-rendering \
-    --no-css-compositing \
+    --touch-events \
     --video \
     --video-track \
     --cmakeargs="-DCMAKE_TOOLCHAIN_FILE=$script_dir/FuchsiaClangToolchain.txt -DENABLE_XSLT=OFF -DENABLE_DRAG_SUPPORT=OFF -DENABLE_STATIC_JSC=ON"