From fe21f73c06eadb5e63cb43b859b8472e2a4463d2 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Mon, 24 Apr 2023 18:13:38 +0900 Subject: [PATCH] [Tizen] Add SetTapRecognizerTime This is the time from touch down to touch up to recognize a tap gesture. If set to 300ms, a touch up after a touch down must occur within 300ms to be recognized as a tap gesture. Change-Id: I1b7be723938a32f4009232553671bda17503c782 --- .../src/dali/utc-Dali-TapGestureRecognizer.cpp | 59 +++++++++++++++++++++- dali/integration-api/input-options.cpp | 6 +++ dali/integration-api/input-options.h | 26 +++++++++- .../event/events/gesture-event-processor.cpp | 7 ++- .../event/events/gesture-event-processor.h | 11 +++- .../events/tap-gesture/tap-gesture-processor.cpp | 28 +++++++++- .../events/tap-gesture/tap-gesture-processor.h | 12 ++++- .../events/tap-gesture/tap-gesture-recognizer.cpp | 16 ++++-- .../events/tap-gesture/tap-gesture-recognizer.h | 13 ++++- 9 files changed, 164 insertions(+), 14 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp b/automated-tests/src/dali/utc-Dali-TapGestureRecognizer.cpp index 165fbc4..0d2064b 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) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -628,3 +628,60 @@ int UtcDaliTapGestureSetMaximumAllowedTime(void) END_TEST; } + +int UtcDaliTapGestureSetRecognizerTime(void) +{ + TestApplication application; + + TapGestureDetector detector = TapGestureDetector::New(); + + 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); + + try + { + Integration::SetTapRecognizerTime(0); + } + catch(...) + { + DALI_TEST_CHECK(false); // Should not get here + } + + // Reduce the recognizer time. 500 -> 100 + Integration::SetTapRecognizerTime(100); + + 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(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 300)); + + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 450)); + + application.SendNotification(); + + // The tap fails because the recognizer time has been exceeded + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + // reset recognizer time + Integration::SetTapRecognizerTime(500); + + END_TEST; +} diff --git a/dali/integration-api/input-options.cpp b/dali/integration-api/input-options.cpp index e77ab70..48a2a19 100644 --- a/dali/integration-api/input-options.cpp +++ b/dali/integration-api/input-options.cpp @@ -154,6 +154,12 @@ void SetTapMaximumAllowedTime(uint32_t time) eventProcessor.SetTapMaximumAllowedTime(time); } +void SetTapRecognizerTime(uint32_t time) +{ + GestureEventProcessor& eventProcessor = ThreadLocalStorage::Get().GetGestureEventProcessor(); + eventProcessor.SetTapRecognizerTime(time); +} + } // namespace Integration } // namespace Dali diff --git a/dali/integration-api/input-options.h b/dali/integration-api/input-options.h index a585e03..f35de12 100644 --- a/dali/integration-api/input-options.h +++ b/dali/integration-api/input-options.h @@ -2,7 +2,7 @@ #define DALI_INTEGRATION_INPUT_OPTIONS_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -201,10 +201,34 @@ DALI_CORE_API void SetLongPressMinimumHoldingTime(unsigned int value); /** * @brief Sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond) * + * Recognizes how many tap gestures occurred within the maximum allowed time interval. + * If there are two tap gestures within this time, it is a double tap gesture. + * + * @note If it's a double tap, it's like this: + * |<--- maximumAllowedTime --->| + * |(touch down <--recognizerTime--> touch up) <-- maximumAllowedTime --> (touch down <--recognizerTime--> touch up)| + * + * @see SetTapRecognizerTime() + * * @param[in] time The time value in milliseconds */ DALI_CORE_API void SetTapMaximumAllowedTime(uint32_t time); +/** + * @brief Sets the recognizer time required to be recognized as a tap gesture (millisecond) + * + * This time is from touch down to touch up to recognize the tap gesture. + * + * @note The tab is like below: + * touch down <--recognizerTime--> touch up + * If the time between touch down and touch up is longer than recognizer time, it is not recognized as a tap gesture. + * + * @see SetTapMaximumAllowedTime() + * + * @param[in] time The time value in milliseconds + */ +DALI_CORE_API void SetTapRecognizerTime(uint32_t time); + } // namespace Integration } // namespace Dali diff --git a/dali/internal/event/events/gesture-event-processor.cpp b/dali/internal/event/events/gesture-event-processor.cpp index 118c783..260170f 100644 --- a/dali/internal/event/events/gesture-event-processor.cpp +++ b/dali/internal/event/events/gesture-event-processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -339,6 +339,11 @@ void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time) mTapGestureProcessor.SetMaximumAllowedTime(time); } +void GestureEventProcessor::SetTapRecognizerTime(uint32_t time) +{ + mTapGestureProcessor.SetRecognizerTime(time); +} + } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/events/gesture-event-processor.h b/dali/internal/event/events/gesture-event-processor.h index d2b1930..9731fe6 100644 --- a/dali/internal/event/events/gesture-event-processor.h +++ b/dali/internal/event/events/gesture-event-processor.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -291,6 +291,15 @@ public: // Called by Core */ void SetTapMaximumAllowedTime(uint32_t time); + /** + * @brief Sets the recognizer time required to be recognized as a tap gesture (millisecond) + * + * This time is from touch down to touch up to recognize the tap gesture. + * + * @param[in] time The time value in milliseconds + */ + void SetTapRecognizerTime(uint32_t time); + public: // needed for PanGesture /** * @return the pan gesture processor diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp b/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp index bbdac01..04574ba 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp @@ -44,6 +44,7 @@ namespace { DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false); constexpr uint32_t DEFAULT_MAXIMUM_ALLOWED_TIME = 500u; +constexpr uint32_t DEFAULT_RECOGNIZER_TIME = 500u; /** * Creates a TapGesture and asks the specified detector to emit its detected signal. @@ -88,7 +89,8 @@ TapGestureProcessor::TapGestureProcessor() mMaxTouchesRequired(1), mCurrentTapEvent(nullptr), mPossibleProcessed(false), - mMaximumAllowedTime(DEFAULT_MAXIMUM_ALLOWED_TIME) + mMaximumAllowedTime(DEFAULT_MAXIMUM_ALLOWED_TIME), + mRecognizerTime(DEFAULT_RECOGNIZER_TIME) { } @@ -189,7 +191,7 @@ void TapGestureProcessor::AddGestureDetector(TapGestureDetector* gestureDetector request.maxTouches = mMaxTouchesRequired; Size size = scene.GetSize(); - mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast(request), mMaximumAllowedTime); + mGestureRecognizer = new TapGestureRecognizer(*this, Vector2(size.width, size.height), static_cast(request), mMaximumAllowedTime, mRecognizerTime); } else { @@ -273,6 +275,28 @@ void TapGestureProcessor::SetMaximumAllowedTime(uint32_t time) } } +void TapGestureProcessor::SetRecognizerTime(uint32_t time) +{ + if(time == 0u) + { + DALI_LOG_WARNING("RecognizerTime must be greater than zero."); + return; + } + if(mRecognizerTime != time) + { + mRecognizerTime = time; + + if(mGestureRecognizer) + { + TapGestureRecognizer* tapRecognizer = dynamic_cast(mGestureRecognizer.Get()); + if(tapRecognizer) + { + tapRecognizer->SetRecognizerTime(time); + } + } + } +} + void TapGestureProcessor::UpdateDetection() { DALI_ASSERT_DEBUG(!mTapGestureDetectors.empty()); diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-processor.h b/dali/internal/event/events/tap-gesture/tap-gesture-processor.h index 9804679..726d77e 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-processor.h +++ b/dali/internal/event/events/tap-gesture/tap-gesture-processor.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -91,6 +91,15 @@ public: // To be called by GestureEventProcessor */ void SetMaximumAllowedTime(uint32_t time); + /** + * @brief This method sets the recognizer time required to be recognized as a tap gesture (millisecond) + * + * This time is from touch down to touch up to recognize the tap gesture. + * + * @param[in] time The time value in milliseconds + */ + void SetRecognizerTime(uint32_t time); + private: // Undefined TapGestureProcessor(const TapGestureProcessor&); @@ -135,6 +144,7 @@ private: bool mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond) + uint32_t mRecognizerTime; ///< The recognizer time required to be recognized as a tap gesture (millisecond) }; } // namespace Internal 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 33ce529..609c161 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -39,7 +39,7 @@ namespace constexpr float MAXIMUM_MOTION_ALLOWED = 20.0f; } // unnamed namespace -TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime) +TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime) : GestureRecognizer(screenSize, GestureType::TAP), mObserver(observer), mState(CLEAR), @@ -50,7 +50,8 @@ TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSiz mTouchTime(0u), mLastTapTime(0u), mLastTouchTime(0u), - mMaximumAllowedTime(maximumAllowedTime) + mMaximumAllowedTime(maximumAllowedTime), + mRecognizerTime(recognizerTime) { } @@ -83,7 +84,7 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event) if(pointState == PointState::UP) { - if(deltaBetweenTouchDownTouchUp < mMaximumAllowedTime) + if(deltaBetweenTouchDownTouchUp < mRecognizerTime) { mLastTapTime = event.time; EmitSingleTap(event.time, point); @@ -107,7 +108,7 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event) { uint32_t deltaBetweenLastTouchDownTouchUp = event.time - mLastTouchTime; // Clear if the time between touch down and touch up is long. - if(deltaBetweenLastTouchDownTouchUp > mMaximumAllowedTime) + if(deltaBetweenLastTouchDownTouchUp > mRecognizerTime) { mState = CLEAR; } @@ -194,6 +195,11 @@ void TapGestureRecognizer::SetMaximumAllowedTime(uint32_t time) mMaximumAllowedTime = time; } +void TapGestureRecognizer::SetRecognizerTime(uint32_t time) +{ + mRecognizerTime = time; +} + void TapGestureRecognizer::EmitGesture(GestureState state, uint32_t time) { if((state == GestureState::CANCELLED) || diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h index 293c1c9..e8e36a8 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h +++ b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -52,8 +52,9 @@ public: * @param[in] screenSize The size of the screen. * @param[in] request The tap gesture request. * @param[in] maximumAllowedTime The maximum allowed time required in milliseconds. + * @param[in] recognizerTime This recognizer time required in milliseconds. */ - TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime); + TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime); /** * Virtual destructor. @@ -78,6 +79,13 @@ public: */ void SetMaximumAllowedTime(uint32_t time); + /** + * @brief This method sets the recognizer time required to be recognized as a tap gesture (millisecond) + * + * @param[in] time The time value in milliseconds + */ + void SetRecognizerTime(uint32_t time); + private: /** * Checks if registered taps are within required bounds and emits tap gesture if they are. @@ -152,6 +160,7 @@ private: uint32_t mLastTouchTime; ///< The last touch down time. uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond) + uint32_t mRecognizerTime; ///< The recognizer time required to be recognized as a tap gesture (millisecond) }; } // namespace Internal -- 2.7.4