on xenial help sign in
[TGA] Ignore touch events when in the rejected state

If a new touch event is a new touch, we don't care about it in rejected state because we won't recognize anything in this state. Thus, ignore it so that the item below can have it. Fixes https://github.com/ubports/ubuntu-touch/issues/1397

commitc36c2dc45542a993484d89ef46b14312971416cd authorRatchanan Srirattanamet <ratchanan@ubports.com> dateTue 24 Mar 2020, 01:02 (7 years ago) parent7d149cf
2 files changed+36
plugins/Ubuntu/Gestures/TouchGestureArea.cpp+6 tests/plugins/Ubuntu/Gestures/tst_TouchGestureArea.cpp+30
plugins/Ubuntu/Gestures/TouchGestureArea.cpp+6
@@ -328,6 +328,12 @@ void TouchGestureArea::touchEvent_rejected(QTouchEvent *event)
328328 }
329329 }
330330 }
331+
332+ // If this event is a new touch, ignore it and let the item below have it.
333+ // We won't recognize any new touch until the whole current gesture is done
334+ // i.e. we're in WaitingForTouch state.
335+ // And even if it isn't, just ignore it anyway; we don't care about it.
336+ event->ignore();
331337}
332338
333339void TouchGestureArea::unownedTouchEvent(QTouchEvent *unownedTouchEvent)
tests/plugins/Ubuntu/Gestures/tst_TouchGestureArea.cpp+30
@@ -45,6 +45,7 @@ private Q_SLOTS:
4545 void releaseAndPressRecognisedGestureDoesNotRejectForPeriod();
4646 void topAreaReceivesOwnershipFirstWithEqualPoints();
4747 void topAreaReceivesOwnershipFirstWithMorePoints();
48+ void newTouchAfterRejectionIsPassedThrough();
4849
4950private:
5051 void initGestureComponent(TouchGestureArea *area);
@@ -265,6 +266,35 @@ void tst_TouchGestureArea::topAreaReceivesOwnershipFirstWithMorePoints()
265266 QCOMPARE((int)m_gestureMiddle->status(), (int)TouchGestureArea::Rejected);
266267}
267268
269+void tst_TouchGestureArea::newTouchAfterRejectionIsPassedThrough() {
270+ m_gestureTop->setEnabled(true);
271+ m_gestureTop->setMinimumTouchPoints(2);
272+ m_gestureTop->setMaximumTouchPoints(2);
273+ m_gestureTop->setRecognitionPeriod(30);
274+
275+ m_gestureBottom->setEnabled(true);
276+ m_gestureBottom->setMinimumTouchPoints(2);
277+ m_gestureBottom->setMaximumTouchPoints(2);
278+ m_gestureBottom->setRecognitionPeriod(50);
279+
280+ QPointF touchPoint = calculateInitialTouchPos(m_gestureBottom);
281+
282+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
283+ QCOMPARE((int)m_gestureTop->status(), (int)TouchGestureArea::Undecided);
284+ QCOMPARE((int)m_gestureBottom->status(), (int)TouchGestureArea::Undecided);
285+
286+ passTime(40); // 10ms after top item's recognition period.
287+ QCOMPARE((int)m_gestureTop->status(), (int)TouchGestureArea::Rejected);
288+ QCOMPARE((int)m_gestureBottom->status(), (int)TouchGestureArea::Undecided);
289+
290+ // If the top item passes the event down the line, now the bottom one will
291+ // recognize the gesture.
292+ QTest::touchEvent(m_view, m_device).stationary(0)
293+ .press(1, touchPoint.toPoint());
294+ QCOMPARE((int)m_gestureTop->status(), (int)TouchGestureArea::Rejected);
295+ QCOMPARE((int)m_gestureBottom->status(), (int)TouchGestureArea::Recognized);
296+}
297+
268298QTEST_MAIN(tst_TouchGestureArea)
269299
270300#include "tst_TouchGestureArea.moc"