Enable touch instead click

Having problems with building or using the JCEF Java binding? Ask your questions here.

Enable touch instead click

Postby raker » Sun Nov 16, 2014 5:24 am

Hi,
it is possible in JCEF to emulate touch events. There is some command line flag?.
I know that DevTools give that possibility but for some reason I can't fire that tool. I'm monitor all network via websocket and there is no possibility to read network with websocket and display standard devtools window.
Thanks for advice
raker
Techie
 
Posts: 14
Joined: Fri Jul 12, 2013 6:18 am

Re: Enable touch instead click

Postby magreenblatt » Mon Nov 17, 2014 12:00 pm

If you're using windowed rendering (the default on Win and Mac) you can specify the `--touch-events=enabled` command-line flag. If you're using off-screen rendering (the only supported method on Linux) you need to wait for https://code.google.com/p/chromiumembed ... il?id=1059 to be resolved and support to be added in JCEF.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Enable touch instead click

Postby TomDigitale » Thu Nov 20, 2014 9:14 am

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.
TomDigitale
Techie
 
Posts: 18
Joined: Fri Mar 14, 2014 6:00 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 14 guests