I'll add there is a workaround for this specific need using off-screen rendering.
Instead of sending mouse click events, you can execute a javascript function that will dispatch your touches in your webpage.
Example:
C++ side (we are using c++ but it should not be difficult to port):
- Code: Select all
MyBrowser::injectTouchesDown(std::vector<Touch> touches)
{
stringstream ss;
ss << "injectTouchesDown([";
for (unsigned int i = 0; i < touches.size(); i++)
{
TouchEvent& touch = touches[i];
ss << "{id:" << touch.id << ", x:" << touch.x << ", y:" << touch.y << "},";
}
ss << "]);";
webview->executeJavascript(ss.str());
}
and HTML/javascript side, you must define "injectTouchesDown" function and handle them accordingly.
What we are doing is something like:
- Code: Select all
injectTouchesDown = function(touches)
{
var touchesDown;
for (var i = 0; i < touches.length; i++)
{
var touch = touches[i];
touch.pageX = touch.pageX + window.pageXOffset;
touch.pageY = touch.pageY + window.pageYOffset;
touch.screenX = touch.x;
touch.screenY = touch.y;
touch.clientX = touch.x;
touch.clientY = touch.y;
/* retrieve touched element */
touch.target = document.elementFromPoint(touch.x, touch.y);
touchesDown[i] = touch;
}
if (touchesDown.length > 0)
{
var evt = document.createEvent("Event");
evt.initEvent("touchdown", true, true);
evt.touches = touches;
evt.changedTouches = touchesDown;
evt.touch = touches[0];
targets[targetId].element.dispatchEvent(evt);
}
}
This code is really not correct, it's just the general idea. You should read about how touches event should be dispatched.
So this is how we are doing it currently and it works perfectly, you should give it a try if you really want multitouches.