Different mouse button types must be handled as separate events. 44/317344/4
authorjoogab.yun <joogab.yun@samsung.com>
Mon, 9 Sep 2024 07:23:01 +0000 (16:23 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Wed, 11 Sep 2024 01:21:38 +0000 (10:21 +0900)
Change-Id: I7081ca145f61dd1240cc9f8f2b662001dae3b393

automated-tests/src/dali/utc-Dali-TouchEventCombiner.cpp
dali/integration-api/events/touch-event-combiner.cpp

index 8c8fc30..46f46b5 100644 (file)
@@ -1034,3 +1034,67 @@ int UtcDaliTouchEventCombinerHoverDownAfterTouchUp(void)
 
   END_TEST;
 }
+
+
+int UtcDaliTouchEventCombinerMultipleMouseButton(void)
+{
+  TouchEventCombiner combiner;
+  unsigned long      time(0u);
+
+  // Primary down
+  {
+    Integration::TouchEvent touchEvent;
+    Integration::HoverEvent hoverEvent;
+    Integration::Point      point = GeneratePoint(1, PointState::DOWN, 100.0f, 100.0f);
+    point.SetMouseButton(MouseButton::PRIMARY);
+
+    DALI_TEST_EQUALS(Integration::TouchEventCombiner::DISPATCH_TOUCH, combiner.GetNextTouchEvent(point, time, touchEvent, hoverEvent), TEST_LOCATION);
+    DALI_TEST_EQUALS(touchEvent.GetPointCount(), 1, TEST_LOCATION);
+  }
+
+  // secondary down
+  {
+    Integration::TouchEvent touchEvent;
+    Integration::HoverEvent hoverEvent;
+    Integration::Point      point = GeneratePoint(1, PointState::DOWN, 100.0f, 100.0f);
+    point.SetMouseButton(MouseButton::SECONDARY);
+
+    DALI_TEST_EQUALS(Integration::TouchEventCombiner::DISPATCH_TOUCH, combiner.GetNextTouchEvent(point, ++time, touchEvent, hoverEvent), TEST_LOCATION);
+    DALI_TEST_EQUALS(touchEvent.GetPointCount(), 2, TEST_LOCATION);
+  }
+
+  // move
+  {
+    Integration::TouchEvent touchEvent;
+    Integration::HoverEvent hoverEvent;
+    Integration::Point      point = GeneratePoint(1, PointState::MOTION, 150.0f, 150.0f);
+    point.SetMouseButton(MouseButton::PRIMARY);
+
+    DALI_TEST_EQUALS(Integration::TouchEventCombiner::DISPATCH_TOUCH, combiner.GetNextTouchEvent(point, ++time, touchEvent, hoverEvent), TEST_LOCATION);
+    DALI_TEST_EQUALS(touchEvent.GetPointCount(), 2, TEST_LOCATION);
+  }
+
+  // up event
+  {
+    Integration::TouchEvent touchEvent;
+    Integration::HoverEvent hoverEvent;
+    Integration::Point      point = GeneratePoint(1, PointState::UP, 150.0f, 150.0f);
+    point.SetMouseButton(MouseButton::PRIMARY);
+
+    DALI_TEST_EQUALS(Integration::TouchEventCombiner::DISPATCH_TOUCH, combiner.GetNextTouchEvent(point, ++time, touchEvent, hoverEvent), TEST_LOCATION);
+    DALI_TEST_EQUALS(touchEvent.GetPointCount(), 2, TEST_LOCATION);
+  }
+
+    // up event
+  {
+    Integration::TouchEvent touchEvent;
+    Integration::HoverEvent hoverEvent;
+    Integration::Point      point = GeneratePoint(1, PointState::UP, 150.0f, 150.0f);
+    point.SetMouseButton(MouseButton::SECONDARY);
+
+    DALI_TEST_EQUALS(Integration::TouchEventCombiner::DISPATCH_TOUCH, combiner.GetNextTouchEvent(point, ++time, touchEvent, hoverEvent), TEST_LOCATION);
+    DALI_TEST_EQUALS(touchEvent.GetPointCount(), 1, TEST_LOCATION);
+  }
+
+  END_TEST;
+}
index 879df14..a9e4231 100644 (file)
@@ -35,6 +35,13 @@ namespace
 {
 const unsigned long DEFAULT_MINIMUM_MOTION_TIME(1u);
 const Vector2       DEFAULT_MINIMUM_MOTION_DISTANCE(1.0f, 1.0f);
+
+inline bool CheckEqualInputSource(const Point& lhs, const int deviceId, const MouseButton::Type mouseButton)
+{
+  return (lhs.GetDeviceId() == deviceId) &&        /// Check device id is equal and
+         ((mouseButton == MouseButton::INVALID) || /// ...Check whether input point is not from mouse
+          (mouseButton == lhs.GetMouseButton()));  /// ...or from same mouse button
+}
 } // unnamed namespace
 
 struct TouchEventCombiner::PointInfo
@@ -86,6 +93,7 @@ TouchEventCombiner::EventDispatchType TouchEventCombiner::GetNextTouchEvent(cons
   const PointState::Type                state    = point.GetState();
   const int                             deviceId = point.GetDeviceId();
   const Device::Class::Type             deviceType = point.GetDeviceClass();
+  const MouseButton::Type               mouseButton = point.GetMouseButton();
 
   switch(state)
   {
@@ -97,7 +105,7 @@ TouchEventCombiner::EventDispatchType TouchEventCombiner::GetNextTouchEvent(cons
       // Iterate through already stored touch points and add to TouchEvent
       for(PointInfoContainer::iterator iter = mPressedPoints.begin(), endIter = mPressedPoints.end(); iter != endIter; ++iter)
       {
-        if(iter->point.GetDeviceId() != deviceId)
+        if(!CheckEqualInputSource(iter->point, deviceId, mouseButton))
         {
           if(!isMultiTouchEvent)
           {
@@ -164,7 +172,7 @@ TouchEventCombiner::EventDispatchType TouchEventCombiner::GetNextTouchEvent(cons
       PointInfoContainer::iterator match(mPressedPoints.end());
       for(PointInfoContainer::iterator iter = mPressedPoints.begin(), endIter = mPressedPoints.end(); iter != endIter; ++iter)
       {
-        if(deviceId == iter->point.GetDeviceId())
+        if(CheckEqualInputSource(iter->point, deviceId, mouseButton))
         {
           match = iter;
 
@@ -259,6 +267,7 @@ TouchEventCombiner::EventDispatchType TouchEventCombiner::GetNextTouchEvent(cons
         if(match != mPressedPoints.end())
         {
           PointInfo matchedPoint(point, time);
+          matchedPoint.point.SetMouseButton(match->point.GetMouseButton());
           std::swap(*match, matchedPoint);
 
           dispatchEvent = TouchEventCombiner::DISPATCH_TOUCH; // Dispatch touch event