Skip to content

Commit 2ca2cde

Browse files
committed
Some code clean up in touch for Web
1 parent 84e71bd commit 2ca2cde

File tree

1 file changed

+5
-85
lines changed

1 file changed

+5
-85
lines changed

src/webdriver/extension_qt/web_view_executor.cc

Lines changed: 5 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -576,31 +576,8 @@ void QWebViewCmdExecutor::TouchClick(const ElementId& element, Error **error) {
576576

577577
QPoint point = QCommonUtil::ConvertPointToQPoint(location);
578578

579-
QList<QTouchEvent::TouchPoint> points;
580-
QTouchEvent::TouchPoint touchPoint(1);
581-
touchPoint.setPos(point);
582-
touchPoint.setScreenPos(view_->mapToGlobal(point));
583-
touchPoint.setStartScreenPos(view_->mapToGlobal(point));
584-
touchPoint.setState(Qt::TouchPointPressed);
585-
touchPoint.setPressure(1);
586-
points.append(touchPoint);
587-
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
588-
QTouchEvent *touchBeginEvent = new QTouchEvent(QEvent::TouchBegin, &touchDevice, Qt::NoModifier, Qt::TouchPointPressed, points);
589-
#else
590-
QTouchEvent *touchBeginEvent = new QTouchEvent(QEvent::TouchBegin, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointPressed, points);
591-
#endif
592-
points.clear();
593-
touchPoint.setPos(point);
594-
touchPoint.setScreenPos(view_->mapToGlobal(point));
595-
touchPoint.setStartScreenPos(view_->mapToGlobal(point));
596-
touchPoint.setState(Qt::TouchPointReleased);
597-
touchPoint.setPressure(1);
598-
points.append(touchPoint);
599-
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
600-
QTouchEvent *touchEndEvent = new QTouchEvent(QEvent::TouchEnd, &touchDevice, Qt::NoModifier, Qt::TouchPointReleased, points);
601-
#else
602-
QTouchEvent *touchEndEvent = new QTouchEvent(QEvent::TouchEnd, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointReleased, points);
603-
#endif
579+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, QPointF(point));
580+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, QPointF(point));
604581

605582
QApplication::postEvent(view_, touchBeginEvent);
606583
QApplication::postEvent(view_, touchEndEvent);
@@ -632,18 +609,7 @@ void QWebViewCmdExecutor::TouchDown(const int &x, const int &y, Error **error) {
632609

633610
QPoint point = QCommonUtil::ConvertPointToQPoint(Point(x, y));
634611

635-
QList<QTouchEvent::TouchPoint> points;
636-
QTouchEvent::TouchPoint touchPoint(1);
637-
touchPoint.setPos(point);
638-
touchPoint.setState(Qt::TouchPointPressed);
639-
touchPoint.setPressure(1);
640-
points.append(touchPoint);
641-
642-
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
643-
QTouchEvent *touchBeginEvent = new QTouchEvent(QEvent::TouchBegin, &touchDevice, Qt::NoModifier, Qt::TouchPointPressed, points);
644-
#else
645-
QTouchEvent *touchBeginEvent = new QTouchEvent(QEvent::TouchBegin, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointPressed, points);
646-
#endif
612+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
647613

648614
QApplication::postEvent(view_, touchBeginEvent);
649615
}
@@ -653,18 +619,7 @@ void QWebViewCmdExecutor::TouchUp(const int &x, const int &y, Error **error) {
653619

654620
QPoint point = QCommonUtil::ConvertPointToQPoint(Point(x, y));
655621

656-
QList<QTouchEvent::TouchPoint> points;
657-
QTouchEvent::TouchPoint touchPoint(1);
658-
touchPoint.setPos(point);
659-
touchPoint.setState(Qt::TouchPointPressed);
660-
touchPoint.setPressure(1);
661-
points.append(touchPoint);
662-
663-
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
664-
QTouchEvent *touchEndEvent = new QTouchEvent(QEvent::TouchEnd, &touchDevice, Qt::NoModifier, Qt::TouchPointReleased, points);
665-
#else
666-
QTouchEvent *touchEndEvent = new QTouchEvent(QEvent::TouchEnd, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointReleased, points);
667-
#endif
622+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
668623

669624
QApplication::postEvent(view_, touchEndEvent);
670625
}
@@ -674,18 +629,7 @@ void QWebViewCmdExecutor::TouchMove(const int &x, const int &y, Error **error) {
674629

675630
QPoint point = QCommonUtil::ConvertPointToQPoint(Point(x, y));
676631

677-
QList<QTouchEvent::TouchPoint> points;
678-
QTouchEvent::TouchPoint touchPoint(1);
679-
touchPoint.setPos(point);
680-
touchPoint.setState(Qt::TouchPointMoved);
681-
touchPoint.setPressure(1);
682-
points.append(touchPoint);
683-
684-
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
685-
QTouchEvent *touchMoveEvent = new QTouchEvent(QEvent::TouchUpdate, &touchDevice, Qt::NoModifier, Qt::TouchPointMoved, points);
686-
#else
687-
QTouchEvent *touchMoveEvent = new QTouchEvent(QEvent::TouchUpdate, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointMoved, points);
688-
#endif
632+
QTouchEvent *touchMoveEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, point);
689633

690634
QApplication::postEvent(view_, touchMoveEvent);
691635
}
@@ -700,30 +644,6 @@ void QWebViewCmdExecutor::TouchLongClick(const ElementId& element, Error **error
700644

701645
QPoint point = QCommonUtil::ConvertPointToQPoint(location);
702646

703-
// QList<QTouchEvent::TouchPoint> points;
704-
// QTouchEvent::TouchPoint touchPoint(1);
705-
// touchPoint.setPos(point);
706-
// touchPoint.setScreenPos(view_->mapToGlobal(point));
707-
// touchPoint.setStartScreenPos(view_->mapToGlobal(point));
708-
// touchPoint.setState(Qt::TouchPointPressed);
709-
// touchPoint.setPressure(1);
710-
// points.append(touchPoint);
711-
// QTouchEvent *touchBeginEvent = new QTouchEvent(QEvent::TouchBegin, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointPressed, points);
712-
713-
// points.clear();
714-
// touchPoint.setPos(point);
715-
// touchPoint.setScreenPos(view_->mapToGlobal(point));
716-
// touchPoint.setStartScreenPos(view_->mapToGlobal(point));
717-
// touchPoint.setState(Qt::TouchPointReleased);
718-
// touchPoint.setPressure(1);
719-
// points.append(touchPoint);
720-
// QTouchEvent *touchEndEvent = new QTouchEvent(QEvent::TouchEnd, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointReleased, points);
721-
722-
// QTimer::singleShot(1000, &loop, SLOT(quit()));
723-
// QApplication::postEvent(view_, touchBeginEvent);
724-
// loop.exec(QEventLoop::ExcludeUserInputEvents);
725-
// QApplication::postEvent(view_, touchEndEvent);
726-
727647
QContextMenuEvent *contextEvent = new QContextMenuEvent(QContextMenuEvent::Other, point, view_->mapToGlobal(point));
728648
qApp->postEvent(view_, contextEvent);
729649
}

0 commit comments

Comments
 (0)