Bug 32434 - [Qt] Add support for mocking touch events with Q(GV)Launcher
: [Qt] Add support for mocking touch events with Q(GV)Launcher
Status: RESOLVED FIXED
Product: WebKit
Classification: Unclassified
Component: New Bugs
: 528+ (Nightly build)
: Other Mac OS X 10.5
: P3 Normal
Assigned To: Nobody
: Qt
Depends on: 32432
Blocks: 32485
  Show dependency treegraph
 
Reported: 2009-12-11 08:04 PST by Simon Hausmann
Modified: 2009-12-17 09:21 PST (History)
4 users (show)

See Also:


Attachments
Adds multitouch mocking to QtLauncher (6.61 KB, patch)
2009-12-16 01:17 PST, Kim Grönholm
hausmann: review-
Details | Formatted Diff | Diff
Test page for Touch DOM events. Supports two touchpoints. (4.81 KB, text/html)
2009-12-16 01:22 PST, Kim Grönholm
no flags Details
Adds multitouch mocking to QtLauncher (6.54 KB, patch)
2009-12-17 05:36 PST, Kim Grönholm
no flags Details | Formatted Diff | Diff
The event delivery should go through the normal path (1.13 KB, patch)
2009-12-17 08:14 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hausmann 2009-12-11 08:04:17 PST
It would be nice to be able to simulate touch events with a mouse from Q(GV)Launcher.

Kim's idea was to have a menu item to toggle mocking. When enabled a single mouse click is converted to be a single touch event instead. Pressing Ctrl + F (as in "finger") will make the last mouse position a stationary touch point and any subsequence mouse clicks produce a second touch point. Pressing Ctrl+F again would remove the second point again.
Comment 1 Kim Grönholm 2009-12-16 01:17:51 PST
Created attachment 44954 [details]
Adds multitouch mocking to QtLauncher

This is pretty much what I had in mind. Now the mocking is switched on by default and can be switched off from the 'Tools'-menu or by pressing Ctrl+Alt+T.
The other finger is pressed and released by pressing Ctrl+F and the other is controlled with mouse.
Comment 2 WebKit Review Bot 2009-12-16 01:20:59 PST
style-queue ran check-webkit-style on attachment 44954 [details] without any errors.
Comment 3 Kim Grönholm 2009-12-16 01:22:58 PST
Created attachment 44955 [details]
Test page for Touch DOM events. Supports two touchpoints.

This test page can be used to test the multi-touch mocking with QtLauncher.
Comment 4 Simon Hausmann 2009-12-16 03:27:23 PST
Comment on attachment 44954 [details]
Adds multitouch mocking to QtLauncher


> +#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
> +#include <qevent.h>
> +#endif

This #if isn't necessary, qevent.h has been there since Qt 1.0 :-)
  
> +    bool eventFilter(QObject* obj, QEvent* event)
> +    {
> +        if (!touchMocking || obj != view)
> +            return QObject::eventFilter(obj, event);
> +
> +        if (event->type() == QEvent::MouseButtonPress
> +            || event->type() == QEvent::MouseButtonRelease
> +            || event->type() == QEvent::MouseButtonDblClick
> +            || event->type() == QEvent::MouseMove) {
> +
> +            QMouseEvent* ev = static_cast<QMouseEvent *>(event);

Coding style nitpick: No space before the * :)

> +            if (ev->type() == QEvent::MouseMove
> +                && !(ev->buttons() & Qt::LeftButton))
> +                return false;
> +
> +            QTouchEvent::TouchPoint touchPoint;
> +            touchPoint.setState(Qt::TouchPointMoved);
> +            if ((ev->type() == QEvent::MouseButtonPress
> +                 || ev->type() == QEvent::MouseButtonDblClick))
> +                touchPoint.setState(Qt::TouchPointPressed);
> +            else if (ev->type() == QEvent::MouseButtonRelease)
> +                touchPoint.setState(Qt::TouchPointReleased);
> +
> +            touchPoint.setId(0);
> +            touchPoint.setScreenPos(ev->globalPos());
> +            touchPoint.setPos(ev->pos());
> +            touchPoint.setPressure(1);
> +
> +            // If the point already exists, update it. Otherwise create it.
> +            if (touchPoints.size()>0 && !touchPoints[0].id()) 

Coding style: There should be a space before and after the > character

> +                touchPoints[0] = touchPoint;
> +            else if (touchPoints.size()>1 && !touchPoints[1].id()) 

Ditto.

> +                touchPoints[1] = touchPoint;
> +            else 
> +                touchPoints.append(touchPoint);
> +
> +            sendTouchEvent();
> +        } else if (event->type() == QEvent::KeyPress
> +            && ((QKeyEvent*)event)->key() == Qt::Key_F
> +            && ((QKeyEvent*)event)->modifiers() == Qt::ControlModifier) {

Please use a static_cast.

> +            // If the keyboard point is already pressed, release it.
> +            // Otherwise create it and append to touchPoints.
> +            if (touchPoints.size()>0 && touchPoints[0].id() == 1) {

Coding style: There should be a space before and after the > character

> +                touchPoints[0].setState(Qt::TouchPointReleased);
> +                sendTouchEvent();
> +            } else if (touchPoints.size()>1 && touchPoints[1].id() == 1) {

Ditto.

> +                touchPoints[1].setState(Qt::TouchPointReleased);
> +                sendTouchEvent();
> +            } else {
> +                QTouchEvent::TouchPoint touchPoint;
> +                touchPoint.setState(Qt::TouchPointPressed);
> +                touchPoint.setId(1);
> +                touchPoint.setScreenPos(QCursor::pos());
> +                touchPoint.setPos(view->mapFromGlobal(QCursor::pos()));

I suggest to remember the last mouse point. Just a thought :)

> +                touchPoint.setPressure(1);            
> +                touchPoints.append(touchPoint);
> +                sendTouchEvent();
> +
> +                // After sending the event, change the touchpoint state to stationary
> +                touchPoints.last().setState(Qt::TouchPointStationary);


Shouldn't we disable mocking by default?
Comment 5 Kim Grönholm 2009-12-17 05:36:44 PST
Created attachment 45057 [details]
Adds multitouch mocking to QtLauncher

Updated patch according to Simon's comments except remembering the last mouse point. It would just add lines of code and make it slightly more complicated. I don't see any downsides in using QCursor::pos() to get the mouse position. It's simple and works :) However, I will change that as well if demanded?
Comment 6 WebKit Review Bot 2009-12-17 05:39:15 PST
style-queue ran check-webkit-style on attachment 45057 [details] without any errors.
Comment 7 Simon Hausmann 2009-12-17 05:51:41 PST
Comment on attachment 45057 [details]
Adds multitouch mocking to QtLauncher

r=me
Comment 8 WebKit Commit Bot 2009-12-17 06:01:56 PST
Comment on attachment 45057 [details]
Adds multitouch mocking to QtLauncher

Clearing flags on attachment: 45057

Committed r52250: <http://trac.webkit.org/changeset/52250>
Comment 9 WebKit Commit Bot 2009-12-17 06:02:02 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Benjamin Poulain 2009-12-17 08:14:41 PST
Created attachment 45071 [details]
The event delivery should go through the normal path
Comment 11 WebKit Review Bot 2009-12-17 08:15:15 PST
style-queue ran check-webkit-style on attachment 45071 [details] without any errors.
Comment 12 Benjamin Poulain 2009-12-17 09:06:17 PST
Reopening.

The event should go through the normal path. We need to simulate touch events are if they were sent by the system (with filtering in some cases).

I'd prefer to see something like this in Qt. This feature could be useful in many more cases.
Comment 13 WebKit Commit Bot 2009-12-17 09:21:47 PST
Comment on attachment 45071 [details]
The event delivery should go through the normal path

Clearing flags on attachment: 45071

Committed r52257: <http://trac.webkit.org/changeset/52257>
Comment 14 WebKit Commit Bot 2009-12-17 09:21:54 PST
All reviewed patches have been landed.  Closing bug.