From 145b3b796944b5599bf8d3792b383cf7fd0c279d Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Tue, 18 May 2021 19:04:13 +0900 Subject: [PATCH] Fixed an issue the triple tap did not work. The mState value is wrong. So, only single and double taps are possible, and no more taps are called. And it removes unreachable code. uint32_t deltaBetweenTouchDownTouchUp = event.time - mTouchTime; if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED) { // mLastTapTime is equal to or greater than mTouchTime; // so If deltaBetweenTouchDownTouchUp is less than MAXIMUM_TIME_ALLOWED // then timeDelta is never it cannot be greater than MAXIMUM_TIME_ALLOWED. uint32_t timeDelta = event.time - mLastTapTime; if(timeDelta > MAXIMUM_TIME_ALLOWED) { // unreachable block } } Change-Id: Icd719bda146a82f0b25cb123e36395c9b5aa8f5f --- .../src/dali/utc-Dali-TapGestureRecognizer.cpp | 50 +++++++++++++++++++++- .../events/tap-gesture/tap-gesture-recognizer.cpp | 26 +++++------ 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp b/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp index bff9a08..403b252 100644 --- a/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp +++ b/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -511,3 +511,51 @@ int UtcDaliTapGestureRecognizerMultipleDetectors(void) END_TEST; } + +int UtcDaliTapGestureRecognizerTripleTap(void) +{ + TestApplication application; + + TapGestureDetector detector = TapGestureDetector::New(3); + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); + + // Render and notify + application.SendNotification(); + application.Render(); + + detector.Attach(actor); + + SignalData data; + GestureReceivedFunctor functor(data); + detector.DetectedSignal().Connect(&application, functor); + + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150)); + + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200)); + + application.SendNotification(); + + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250)); + + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300)); + + application.SendNotification(); + + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 350)); + + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 400)); + + application.SendNotification(); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + + END_TEST; +} diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp index a7edacd..336fc64 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp @@ -103,24 +103,18 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event) { if(pointState == PointState::UP) { + // This is a possible multiple tap, so has it been quick enough? + uint32_t timeDelta = event.time - mLastTapTime; uint32_t deltaBetweenTouchDownTouchUp = event.time - mTouchTime; - - if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED) + if(timeDelta > MAXIMUM_TIME_ALLOWED) // If exceeded time between taps then just a single tap + { + mLastTapTime = event.time; + EmitSingleTap(event.time, point); + } + else if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED) { - // This is a possible multiple tap, so has it been quick enough? - uint32_t timeDelta = event.time - mLastTapTime; - if(timeDelta > MAXIMUM_TIME_ALLOWED) // If exceeded time between taps then just a single tap - { - mLastTapTime = event.time; - EmitSingleTap(event.time, point); - mState = REGISTERED; - } - else - { - ++mTapsRegistered; - EmitGesture(GestureState::STARTED, event.time); - mState = CLEAR; - } + ++mTapsRegistered; + EmitGesture(GestureState::STARTED, event.time); } else // Delta between touch down and touch up too long to be considered a TAP event { -- 2.7.4