Skip to content

Commit 0788613

Browse files
Andrii BoichukAndrii Boichuk
authored andcommitted
Merge branch 'WD_1.X_dev' of https://portal-ua.globallogic.com/git/wd into WD_1.X_dev
2 parents 7739884 + 5dcd3ed commit 0788613

File tree

4 files changed

+317
-11
lines changed

4 files changed

+317
-11
lines changed

inc/extension_qt/quick2_view_executor.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ class Quick2ViewCmdExecutor : public QWindowViewCmdExecutor {
8585
virtual void GetAlertMessage(std::string* text, Error** error) NOT_SUPPORTED_IMPL;
8686
virtual void SetAlertPromptText(const std::string& alert_prompt_text, Error** error) NOT_SUPPORTED_IMPL;
8787
virtual void AcceptOrDismissAlert(bool accept, Error** error) NOT_SUPPORTED_IMPL;
88-
virtual void TouchClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
89-
virtual void TouchDoubleClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
90-
virtual void TouchDown(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
91-
virtual void TouchUp(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
92-
virtual void TouchMove(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
93-
virtual void TouchLongClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
88+
virtual void TouchClick(const ElementId& element, Error **error);
89+
virtual void TouchDoubleClick(const ElementId& element, Error **error);
90+
virtual void TouchDown(const int &x, const int &y, Error **error);
91+
virtual void TouchUp(const int &x, const int &y, Error **error);
92+
virtual void TouchMove(const int &x, const int &y, Error **error);
93+
virtual void TouchLongClick(const ElementId& element, Error **error);
9494
virtual void TouchScroll(const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
95-
virtual void TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
95+
virtual void TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error);
9696
virtual void TouchFlick(const int &xSpeed, const int &ySpeed, Error **error) NOT_SUPPORTED_IMPL;
97-
virtual void TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error) NOT_SUPPORTED_IMPL;
97+
virtual void TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error);
9898
virtual void GetPlayerState(const ElementId& element, PlayerState*, Error** error);
9999
virtual void SetPlayerState(const ElementId& element, PlayerState, Error** error);
100100
virtual void GetPlayerVolume(const ElementId& element, double*, Error** error);

inc/extension_qt/qwindow_view_executor.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "webdriver_error.h"
1111

1212
#include <QtCore/QDebug>
13-
#include <QtGui/QTouchDevice>
13+
#include <QtGui/QTouchEvent>
14+
#include <QtGui/QTouchDevice>
1415
#include <QtGui/QWindow>
1516

1617
namespace webdriver {
@@ -43,10 +44,12 @@ class QWindowViewCmdExecutor : public ViewCmdExecutor {
4344
QRect ConvertRectToQRect(const Rect &rect);
4445
QPoint ConvertPointToQPoint(const Point &p);
4546
Qt::MouseButton ConvertMouseButtonToQtMouseButton(MouseButton button);
46-
47-
QTouchDevice touchDevice;
47+
QTouchEvent::TouchPoint createTouchPoint(Qt::TouchPointState state, QPointF &point, QVector2D velocity = QVector2D());
48+
QTouchEvent* createSimpleTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, QPointF &point, QVector2D velocity = QVector2D());
49+
QTouchEvent* createTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, const QList<QTouchEvent::TouchPoint> &touchPoints);
4850

4951
private:
52+
QTouchDevice touchDevice;
5053
DISALLOW_COPY_AND_ASSIGN(QWindowViewCmdExecutor);
5154
};
5255

src/webdriver/extension_qt/quick2_view_executor.cc

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
#include <QtCore/QBuffer>
2121
#include <QtCore/QDebug>
22+
#include <QtCore/QTimer>
2223
#include <QtGui/QGuiApplication>
2324
#include <QtQml/QQmlExpression>
2425
#include <QtQml/QQmlEngine>
26+
#include <QtGui/QStyleHints>
2527

2628
#include "third_party/pugixml/pugixml.hpp"
2729

@@ -1039,6 +1041,269 @@ void Quick2ViewCmdExecutor::GetPlaybackSpeed(const ElementId &element, double *s
10391041
positionValue->GetAsDouble(speed);
10401042
}
10411043

1044+
void Quick2ViewCmdExecutor::TouchClick(const ElementId& element, Error **error)
1045+
{
1046+
QQuickView* view = getView(view_id_, error);
1047+
if (NULL == view)
1048+
return;
1049+
1050+
Point location(0,0);
1051+
1052+
// calculate the half of the element size and translate by it.
1053+
Size size;
1054+
GetElementSize(element, &size, error);
1055+
if (*error)
1056+
return;
1057+
1058+
location.Offset(size.width() / 2, size.height() / 2);
1059+
1060+
QPointF point = ConvertPointToQPoint(location);
1061+
1062+
QQuickItem* pItem = getElement(element, error);
1063+
if (*error)
1064+
return;
1065+
1066+
point = pItem->mapToScene(point);
1067+
1068+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1069+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1070+
1071+
QGuiApplication::postEvent(view, touchBeginEvent);
1072+
QGuiApplication::postEvent(view, touchEndEvent);
1073+
1074+
QGuiApplication::processEvents();
1075+
}
1076+
1077+
void Quick2ViewCmdExecutor::TouchDoubleClick(const ElementId& element, Error **error)
1078+
{
1079+
QQuickView* view = getView(view_id_, error);
1080+
if (NULL == view)
1081+
return;
1082+
1083+
Point location(0,0);
1084+
1085+
// calculate the half of the element size and translate by it.
1086+
Size size;
1087+
GetElementSize(element, &size, error);
1088+
if (*error)
1089+
return;
1090+
1091+
location.Offset(size.width() / 2, size.height() / 2);
1092+
1093+
QPointF point = ConvertPointToQPoint(location);
1094+
1095+
QQuickItem* pItem = getElement(element, error);
1096+
if (*error)
1097+
return;
1098+
1099+
point = pItem->mapToScene(point);
1100+
1101+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1102+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1103+
QTouchEvent *touchBeginEvent2 = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1104+
QTouchEvent *touchEndEvent2 = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1105+
1106+
QGuiApplication::postEvent(view, touchBeginEvent);
1107+
QGuiApplication::postEvent(view, touchEndEvent);
1108+
QGuiApplication::postEvent(view, touchBeginEvent2);
1109+
QGuiApplication::postEvent(view, touchEndEvent2);
1110+
1111+
1112+
QGuiApplication::processEvents();
1113+
}
1114+
1115+
void Quick2ViewCmdExecutor::TouchDown(const int &x, const int &y, Error **error)
1116+
{
1117+
QQuickView* view = getView(view_id_, error);
1118+
if (NULL == view)
1119+
return;
1120+
1121+
QPointF point = ConvertPointToQPoint(Point(x, y));
1122+
1123+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1124+
1125+
QGuiApplication::postEvent(view, touchBeginEvent);
1126+
1127+
QGuiApplication::processEvents();
1128+
}
1129+
1130+
void Quick2ViewCmdExecutor::TouchUp(const int &x, const int &y, Error **error)
1131+
{
1132+
QQuickView* view = getView(view_id_, error);
1133+
if (NULL == view)
1134+
return;
1135+
1136+
QPointF point = ConvertPointToQPoint(Point(x, y));
1137+
1138+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1139+
1140+
QGuiApplication::postEvent(view, touchEndEvent);
1141+
1142+
QGuiApplication::processEvents();
1143+
}
1144+
1145+
void Quick2ViewCmdExecutor::TouchMove(const int &x, const int &y, Error **error)
1146+
{
1147+
QQuickView* view = getView(view_id_, error);
1148+
if (NULL == view)
1149+
return;
1150+
1151+
QPointF point = ConvertPointToQPoint(Point(x, y));
1152+
1153+
QTouchEvent *touchMoveEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, point);
1154+
1155+
QGuiApplication::postEvent(view, touchMoveEvent);
1156+
1157+
QGuiApplication::processEvents();
1158+
}
1159+
1160+
void Quick2ViewCmdExecutor::TouchLongClick(const ElementId& element, Error **error)
1161+
{
1162+
QQuickView* view = getView(view_id_, error);
1163+
if (NULL == view)
1164+
return;
1165+
1166+
Point location(0,0);
1167+
1168+
// calculate the half of the element size and translate by it.
1169+
Size size;
1170+
GetElementSize(element, &size, error);
1171+
if (*error)
1172+
return;
1173+
1174+
location.Offset(size.width() / 2, size.height() / 2);
1175+
1176+
QPointF point = ConvertPointToQPoint(location);
1177+
1178+
QEventLoop loop;
1179+
QTimer::singleShot(1000, &loop, SLOT(quit()));
1180+
1181+
QQuickItem* pItem = getElement(element, error);
1182+
if (*error)
1183+
return;
1184+
1185+
point = pItem->mapToScene(point);
1186+
1187+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1188+
QGuiApplication::postEvent(view, touchBeginEvent);
1189+
1190+
loop.exec();
1191+
1192+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1193+
QGuiApplication::postEvent(view, touchEndEvent);
1194+
1195+
QGuiApplication::processEvents();
1196+
1197+
}
1198+
1199+
void Quick2ViewCmdExecutor::TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error)
1200+
{
1201+
QQuickView* view = getView(view_id_, error);
1202+
if (NULL == view)
1203+
return;
1204+
1205+
Point location(0,0);
1206+
1207+
// calculate the half of the element size and translate by it.
1208+
Size sizel;
1209+
GetElementSize(element, &sizel, error);
1210+
if (*error)
1211+
return;
1212+
1213+
location.Offset(sizel.width() / 2, sizel.height() / 2);
1214+
1215+
QPointF startPoint = ConvertPointToQPoint(location);
1216+
1217+
QQuickItem* pItem = getElement(element, error);
1218+
if (*error)
1219+
return;
1220+
1221+
startPoint = pItem->mapToScene(startPoint);
1222+
1223+
Point offset(xoffset, yoffset);
1224+
QPointF offsetPoint = ConvertPointToQPoint(offset);
1225+
int stepCount = 20;
1226+
int timeBetweenEvent = 30;
1227+
QEventLoop loop;
1228+
1229+
for (int i = 0; i <= stepCount; ++i)
1230+
{
1231+
QPointF touchPoint(startPoint.x()+offsetPoint.x()*i/stepCount, startPoint.y()+offsetPoint.y()*i/stepCount);
1232+
1233+
QTouchEvent *touchEvent;
1234+
if (i == 0)
1235+
touchEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, touchPoint);
1236+
else if (i == stepCount)
1237+
touchEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, touchPoint);
1238+
else
1239+
touchEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, touchPoint);
1240+
1241+
1242+
QGuiApplication::postEvent(view, touchEvent);
1243+
QTimer::singleShot(timeBetweenEvent, &loop, SLOT(quit()));
1244+
loop.exec();
1245+
}
1246+
QGuiApplication::processEvents();
1247+
}
1248+
1249+
void Quick2ViewCmdExecutor::TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error)
1250+
{
1251+
QQuickView* view = getView(view_id_, error);
1252+
if (NULL == view)
1253+
return;
1254+
1255+
Point location(0,0);
1256+
1257+
// calculate the half of the element size and translate by it.
1258+
Size size;
1259+
GetElementSize(element, &size, error);
1260+
if (*error)
1261+
return;
1262+
1263+
location.Offset(size.width() / 2, size.height() / 2);
1264+
QPointF startPoint = ConvertPointToQPoint(location);
1265+
1266+
QQuickItem* pItem = getElement(element, error);
1267+
if (*error)
1268+
return;
1269+
1270+
startPoint = pItem->mapToScene(startPoint);
1271+
1272+
QPointF offsetPoint = ConvertPointToQPoint(Point(xoffset, yoffset));
1273+
1274+
QEventLoop loop;
1275+
1276+
//some magic numbers
1277+
int stepCount = 20;
1278+
int timeBetweenEvent = 30/(speed+1);
1279+
1280+
QVector2D velocity(xoffset*1000/(stepCount*timeBetweenEvent), yoffset*1000/(stepCount*timeBetweenEvent));
1281+
1282+
for (int i = 0; i <= stepCount; ++i)
1283+
{
1284+
QPointF touchPoint(startPoint.x()+offsetPoint.x()*i/stepCount, startPoint.y()+offsetPoint.y()*i/stepCount);
1285+
1286+
QTouchEvent *touchEvent;
1287+
if (i == 0)
1288+
touchEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, touchPoint, velocity);
1289+
else if (i == stepCount)
1290+
touchEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, touchPoint, velocity);
1291+
else
1292+
touchEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, touchPoint, velocity);
1293+
1294+
QGuiApplication::postEvent(view, touchEvent);
1295+
QTimer::singleShot(timeBetweenEvent, &loop, SLOT(quit()));
1296+
loop.exec();
1297+
if (i == stepCount)
1298+
{
1299+
QPointF touchPoint(startPoint);
1300+
touchEvent = createSimpleTouchEvent(QEvent::TouchCancel, Qt::TouchPointPressed, touchPoint);
1301+
QGuiApplication::postEvent(view, touchEvent);
1302+
}
1303+
}
1304+
QGuiApplication::processEvents();
1305+
}
1306+
10421307
QQuickItem* Quick2ViewCmdExecutor::getFocusItem(QQuickView* view) {
10431308
QQuickItem* pFocusItem = view->activeFocusItem();
10441309
if (NULL != pFocusItem) return pFocusItem;

src/webdriver/extension_qt/qwindow_view_executor.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <QtCore/QDebug>
1111
#include <QtGui/QGuiApplication>
12+
#include <QtCore/QDateTime>
1213
#ifdef OS_ANDROID
1314
#include <qpa/qplatformnativeinterface.h>
1415
#include <jni.h>
@@ -18,6 +19,7 @@ namespace webdriver {
1819

1920
QWindowViewCmdExecutor::QWindowViewCmdExecutor(Session* session, ViewId viewId)
2021
: ViewCmdExecutor(session, viewId) {
22+
touchDevice.setCapabilities(QTouchDevice::Velocity);
2123
}
2224

2325
QWindowViewCmdExecutor::~QWindowViewCmdExecutor() {
@@ -283,4 +285,40 @@ Qt::MouseButton QWindowViewCmdExecutor::ConvertMouseButtonToQtMouseButton(MouseB
283285
return result;
284286
}
285287

288+
QTouchEvent::TouchPoint QWindowViewCmdExecutor::createTouchPoint(Qt::TouchPointState state, QPointF &point, QVector2D velocity)
289+
{
290+
QTouchEvent::TouchPoint touchPoint(1);
291+
touchPoint.setPos(point);
292+
touchPoint.setState(state);
293+
touchPoint.setPressure(1);
294+
295+
touchPoint.setVelocity(velocity);
296+
return touchPoint;
297+
}
298+
299+
QTouchEvent* QWindowViewCmdExecutor::createSimpleTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, QPointF &point, QVector2D velocity)
300+
{
301+
QList<QTouchEvent::TouchPoint> points;
302+
Qt::TouchPointState touchPointState;
303+
if (touchPointStates & Qt::TouchPointPressed)
304+
touchPointState = Qt::TouchPointPressed;
305+
else if (touchPointStates & Qt::TouchPointReleased)
306+
touchPointState = Qt::TouchPointReleased;
307+
else {
308+
touchPointState = Qt::TouchPointMoved;
309+
}
310+
QTouchEvent::TouchPoint touchPoint = createTouchPoint(touchPointState, point, velocity);
311+
points.append(touchPoint);
312+
return createTouchEvent(eventType, touchPointStates, points);
313+
}
314+
315+
QTouchEvent* QWindowViewCmdExecutor::createTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, const QList<QTouchEvent::TouchPoint> &touchPoints)
316+
{
317+
QTouchEvent *touchEvent = new QTouchEvent(eventType, &touchDevice, Qt::NoModifier, touchPointStates, touchPoints);
318+
QDateTime current = QDateTime::currentDateTime();
319+
ulong timestame = current.toMSecsSinceEpoch() & (((qint64)1<<(sizeof(ulong)*8))-1);
320+
touchEvent->setTimestamp(timestame);
321+
return touchEvent;
322+
}
323+
286324
} // namespace webdriver

0 commit comments

Comments
 (0)