touch: add out of bounds checking for multi-touch
authorGiWoong Kim <giwoong.kim@samsung.com>
Sat, 9 May 2015 06:37:30 +0000 (15:37 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Mon, 11 May 2015 05:41:01 +0000 (14:41 +0900)
Change-Id: I8cfcca3449cc8d12fb9dbc8b94632fe1b0666b32
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/displaybase.cpp
tizen/src/ui/displaybase.h
tizen/src/ui/input/multitouchtracker.cpp

index 0a72b7f..0a21504 100644 (file)
@@ -90,6 +90,16 @@ void DisplayBase::updateGeometry()
         rect.height() * scaleFactor);
 }
 
+const QRect &DisplayBase::getGeometry()
+{
+    return widget->geometry();
+}
+
+QRegion DisplayBase::getMask()
+{
+    return widget->mask();
+}
+
 void DisplayBase::handlePaint(QPaintEvent *event)
 {
     /* do nothing */
index 893707a..a43df94 100644 (file)
@@ -47,6 +47,8 @@ public:
     void scaleForm(qreal scaleFactor);
     void update();
     void updateGeometry();
+    const QRect &getGeometry();
+    QRegion getMask();
 
     QPoint getGuestPos(QPoint hostPos);
     TouchScreenHelper *getTouchScreenHelper();
@@ -62,8 +64,6 @@ protected:
     void handleMouseRelease(QMouseEvent *event);
     void handleMouseMove(QMouseEvent *event);
 
-    QRect rect;
-    QPixmap maskImage;
     int rotateAngle;
     qreal scaleFactor;
     bool isDragging;
@@ -71,6 +71,9 @@ protected:
 private:
     QWidget *widget;
     TouchScreenHelper *tsHelper;
+
+    QRect rect;
+    QPixmap maskImage;
 };
 
 #endif
index 7bb6b49..cb1e1e5 100644 (file)
@@ -244,17 +244,38 @@ void MultiTouchTracker::processingPara(QPoint hostPos, QPoint guestPos)
         const int hostPosDiffX = hostPos.x() - grabTouchPoint->getHostPos().x();
         const int hostPosDiffY = hostPos.y() - grabTouchPoint->getHostPos().y();
 
-        /* bounds checking */
-        // TODO:
+        /* out of bounds checking */
+        const QRect screenRect(QPoint(0, 0),
+            ((DisplayBase *)parent->getParent())->getGeometry().size());
+        const QRegion screenRegion =
+            ((DisplayBase *)parent->getParent())->getMask();
+
+        for (int i = 0; i < touchPointList.count(); i++) {
+            point = touchPointList.at(i);
+            if (point != NULL) {
+                if (screenRegion.isNull() == false &&
+                    screenRegion.contains(QPoint(
+                        point->getHostPos().x() + hostPosDiffX,
+                        point->getHostPos().y() + hostPosDiffY)) == false) {
+                    /* do nothing */
+                    return;
+                } else if (screenRect.contains(
+                    point->getHostPos().x() + hostPosDiffX,
+                    point->getHostPos().y() + hostPosDiffY, false) == false) {
+                    /* do nothing */
+                    return;
+                }
+            }
+        }
 
         /* move whole touch points */
         for (int i = 0; i < touchPointList.count(); i++) {
             point = touchPointList.at(i);
             if (point != NULL) {
-                QPoint hostMovedPos(
+                const QPoint hostMovedPos(
                     point->getHostPos().x() + hostPosDiffX,
                     point->getHostPos().y() + hostPosDiffY);
-                QPoint guestMovedPos =
+                const QPoint guestMovedPos =
                     ((DisplayBase *)parent->getParent())->getGuestPos(hostMovedPos);
                 point->updatePos(hostMovedPos, guestMovedPos);
 
@@ -307,17 +328,38 @@ void MultiTouchTracker::processingSymm(QPoint hostPos, QPoint guestPos)
         virtio_touchscreen_event(guestPos.x(), guestPos.y(),
             grabTouchPoint->getID() - 1, 1);
 
-        /* bounds checking */
-        // TODO:
+        /* out of bounds checking */
+        const QRect screenRect(QPoint(0, 0),
+            ((DisplayBase *)parent->getParent())->getGeometry().size());
+        const QRegion screenRegion =
+            ((DisplayBase *)parent->getParent())->getMask();
+
+        for (int i = 0; i < touchPointList.count(); i++) {
+            point = touchPointList.at(i);
+            if (point != NULL && point != grabTouchPoint) {
+                if (screenRegion.isNull() == false &&
+                    screenRegion.contains(QPoint(
+                        point->getHostPos().x() - hostPosDiffX,
+                        point->getHostPos().y() - hostPosDiffY)) == false) {
+                    /* do nothing */
+                    return;
+                } else if (screenRect.contains(
+                    point->getHostPos().x() - hostPosDiffX,
+                    point->getHostPos().y() - hostPosDiffY, false) == false) {
+                    /* do nothing */
+                    return;
+                }
+            }
+        }
 
         /* move other points */
         for (int i = 0; i < touchPointList.count(); i++) {
             point = touchPointList.at(i);
             if (point != NULL && point != grabTouchPoint) {
-                QPoint hostMovedPos(
+                const QPoint hostMovedPos(
                     point->getHostPos().x() - hostPosDiffX,
                     point->getHostPos().y() - hostPosDiffY);
-                QPoint guestMovedPos =
+                const QPoint guestMovedPos =
                     ((DisplayBase *)parent->getParent())->getGuestPos(hostMovedPos);
                 point->updatePos(hostMovedPos, guestMovedPos);