WheelEvent class pimpling 58/241358/2
authorRichard Huang <r.huang@samsung.com>
Tue, 18 Aug 2020 17:12:18 +0000 (18:12 +0100)
committerRichard Huang <r.huang@samsung.com>
Wed, 19 Aug 2020 12:36:09 +0000 (13:36 +0100)
Change-Id: I8cccc95259e1ffed4ead5e5c746ba68c32d6ab0e

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window.h
automated-tests/src/dali-toolkit/utc-Dali-ItemView.cpp
automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp
dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp
dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp

index 5deb7a6..7c8ec1a 100644 (file)
@@ -33,7 +33,7 @@ class Layer;
 class RenderSurfaceInterface;
 struct KeyEvent;
 class TouchEvent;
 class RenderSurfaceInterface;
 struct KeyEvent;
 class TouchEvent;
-struct WheelEvent;
+class WheelEvent;
 
 typedef Dali::Rect<int> PositionSize;
 
 
 typedef Dali::Rect<int> PositionSize;
 
index 1ba8d0b..da5ce83 100644 (file)
@@ -24,7 +24,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/touch-event-integ.h>
-
+#include <dali/integration-api/events/wheel-event-integ.h>
 
 using namespace Dali;
 using namespace Toolkit;
 
 using namespace Dali;
 using namespace Toolkit;
@@ -50,6 +50,7 @@ const int RENDER_FRAME_INTERVAL = 16;                     ///< Duration of each
 static bool gObjectCreatedCallBackCalled;
 static bool gOnLayoutActivatedCalled;                     ///< Whether the LayoutActivated signal was invoked.
 static bool gOnScrollUpdateCalled;
 static bool gObjectCreatedCallBackCalled;
 static bool gOnLayoutActivatedCalled;                     ///< Whether the LayoutActivated signal was invoked.
 static bool gOnScrollUpdateCalled;
+static bool gOnWheelEventCalled;                          ///< Whether the WheelEventSignal signal was invoked.
 
 static void TestCallback(BaseHandle handle)
 {
 
 static void TestCallback(BaseHandle handle)
 {
@@ -66,6 +67,12 @@ static void OnScrollUpdate( const Vector2& position )
   gOnScrollUpdateCalled = true;
 }
 
   gOnScrollUpdateCalled = true;
 }
 
+static bool OnWheelEvent( Actor actor, const Dali::WheelEvent& wheelEvent )
+{
+  gOnWheelEventCalled = true;
+  return false;
+}
+
 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
 {
   Integration::TouchEvent touchEvent;
 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
 {
   Integration::TouchEvent touchEvent;
@@ -1323,3 +1330,40 @@ int UtcDaliItemEnableDisableRefresh(void)
 
   END_TEST;
 }
 
   END_TEST;
 }
+
+int UtcDaliItemViewWheelEvent(void)
+{
+  ToolkitTestApplication application;
+  Dali::Integration::Scene stage = application.GetScene();
+
+  // Create the ItemView actor
+  TestItemFactory factory;
+  ItemView view = ItemView::New( factory );
+
+  // Create a grid layout and add it to ItemView
+  ItemLayoutPtr gridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
+  view.AddLayout( *gridLayout );
+  stage.Add( view );
+
+  // Activate the grid layout so that the items will be created and added to ItemView
+  Vector3 stageSize( stage.GetSize() );
+  view.ActivateLayout (0, stageSize, 0.5f );
+
+  //Connect to wheel event signal
+  view.WheelEventSignal().Connect( &OnWheelEvent );
+
+  DALI_TEST_CHECK( !gOnWheelEventCalled );
+
+  // Render and notify
+  application.Render();
+  application.SendNotification();
+  application.Render();
+  application.SendNotification();
+
+  // Perform a wheel event
+  Dali::Integration::WheelEvent wheelEvent( Dali::Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, Vector2( 10.0f, 10.0f ), 1, 1000u );
+  application.ProcessEvent( wheelEvent );
+  DALI_TEST_CHECK( gOnWheelEventCalled );
+
+  END_TEST;
+}
index 4e3974d..4e050f3 100644 (file)
@@ -20,6 +20,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/events/wheel-event-integ.h>
 
 using namespace Dali;
 using namespace Toolkit;
 
 using namespace Dali;
 using namespace Toolkit;
@@ -113,6 +114,7 @@ static bool gOnScrollStartCalled;                       ///< Whether the OnScrol
 static bool gOnScrollUpdateCalled;                      ///< Whether the OnScrollUpdate signal was invoked.
 static bool gOnScrollCompleteCalled;                    ///< Whether the OnScrollComplete signal was invoked.
 static bool gOnSnapStartCalled;                         ///< Whether the OnSnapStart signal was invoked.
 static bool gOnScrollUpdateCalled;                      ///< Whether the OnScrollUpdate signal was invoked.
 static bool gOnScrollCompleteCalled;                    ///< Whether the OnScrollComplete signal was invoked.
 static bool gOnSnapStartCalled;                         ///< Whether the OnSnapStart signal was invoked.
+static bool gOnWheelEventCalled;                        ///< Whether the WheelEventSignal signal was invoked.
 static SnapType gLastSnapType;                          ///< Snaping information from SnapEvent.
 static Vector3 gConstraintResult;                       ///< Result from constraint.
 
 static SnapType gLastSnapType;                          ///< Snaping information from SnapEvent.
 static Vector3 gConstraintResult;                       ///< Result from constraint.
 
@@ -158,6 +160,19 @@ static void OnSnapStart( const ScrollView::SnapEvent& event )
 }
 
 /**
 }
 
 /**
+ * Invoked after a wheel-event is received
+ *
+ * @param[in] actor The owing actor
+ * @param[in] event The wheel event
+ * @return True if the event should be consumed
+ */
+static bool OnWheelEvent( Actor actor, const Dali::WheelEvent& wheelEvent )
+{
+  gOnWheelEventCalled = true;
+  return false;
+}
+
+/**
  * TestSumConstraint
  *
  * Summation of current value, property, and offset.
  * TestSumConstraint
  *
  * Summation of current value, property, and offset.
@@ -2993,3 +3008,81 @@ int UtcDaliScrollViewSetGetProperty(void)
 
   END_TEST;
 }
 
   END_TEST;
 }
+
+int UtcDaliToolkitScrollViewWheelEvent(void)
+{
+  ToolkitTestApplication application;
+
+  // Set up a scrollView.
+  ScrollView scrollView = ScrollView::New();
+
+  // Do not rely on stage size for UTC tests.
+  Vector2 viewPageSize( 720.0f, 1280.0f );
+  scrollView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+  scrollView.SetProperty( Actor::Property::SIZE, viewPageSize );
+  scrollView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+  scrollView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+  scrollView.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ));
+
+  // Position rulers.
+  // We set the X ruler to fixed to give us pages to snap to.
+  Dali::Toolkit::FixedRuler* rulerX = new Dali::Toolkit::FixedRuler( viewPageSize.width );
+  // Note: The 3x page width is arbitary, but we need enough to show that we are
+  // capping page movement by the page limiter, and not the domain.
+  rulerX->SetDomain( Dali::Toolkit::RulerDomain( 0.0f, viewPageSize.width * 3.0f, false ) );
+  Dali::Toolkit::RulerPtr rulerY = new Dali::Toolkit::DefaultRuler();
+  rulerY->Disable();
+  scrollView.SetRulerX( rulerX );
+  scrollView.SetRulerY( rulerY );
+
+  scrollView.SetWrapMode( false );
+
+  application.GetScene().Add( scrollView );
+
+  //Connect to wheel event signal
+  scrollView.WheelEventSignal().Connect( &OnWheelEvent );
+
+  DALI_TEST_CHECK( !gOnWheelEventCalled );
+
+  // Render and notify
+  application.Render();
+  application.SendNotification();
+  application.Render();
+  application.SendNotification();
+
+  // Perform a wheel event
+  Dali::Integration::WheelEvent wheelEvent( Dali::Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, Vector2( 10.0f, 10.0f ), 1, 1000u );
+  application.ProcessEvent( wheelEvent );
+  DALI_TEST_CHECK( gOnWheelEventCalled );
+
+  // Set X ruler to free
+  Dali::Toolkit::DefaultRuler* defaultRuler = new Dali::Toolkit::DefaultRuler();
+  scrollView.SetRulerX( defaultRuler );
+
+  // Perform a wheel event
+  gOnWheelEventCalled = false;
+  application.ProcessEvent( wheelEvent );
+  DALI_TEST_CHECK( gOnWheelEventCalled );
+
+  // Enable Y ruler
+  rulerY->Enable();
+
+  // Perform a wheel event
+  gOnWheelEventCalled = false;
+  application.ProcessEvent( wheelEvent );
+  DALI_TEST_CHECK( gOnWheelEventCalled );
+
+  // Wait until it finishes scrolling
+  Wait(application, RENDER_DELAY_SCROLL);
+
+  // Set Y ruler to fixed
+  Dali::Toolkit::FixedRuler* fixedRulerY = new Dali::Toolkit::FixedRuler( viewPageSize.height );
+  scrollView.SetRulerY( fixedRulerY );
+
+  // Perform a wheel event
+  gOnWheelEventCalled = false;
+  application.ProcessEvent( wheelEvent );
+  DALI_TEST_CHECK( gOnWheelEventCalled );
+
+  END_TEST;
+}
index 36d00d7..939ab67 100644 (file)
@@ -1029,7 +1029,7 @@ bool ItemView::OnWheelEvent(const WheelEvent& event)
   {
     Actor self = Self();
     const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
   {
     Actor self = Self();
     const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
-    float layoutPositionDelta = GetCurrentLayoutPosition(0) - (event.z * mWheelScrollDistanceStep * mActiveLayout->GetScrollSpeedFactor());
+    float layoutPositionDelta = GetCurrentLayoutPosition(0) - (event.GetDelta() * mWheelScrollDistanceStep * mActiveLayout->GetScrollSpeedFactor());
     float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout);
 
     self.SetProperty(Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition );
     float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout);
 
     self.SetProperty(Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition );
index 3e4039e..a4ebfa9 100644 (file)
@@ -2144,14 +2144,14 @@ bool ScrollView::OnWheelEvent(const WheelEvent& event)
     if(mRulerX->GetType() == Ruler::Free)
     {
       // Free panning mode
     if(mRulerX->GetType() == Ruler::Free)
     {
       // Free panning mode
-      targetScrollPosition.x += event.z * mWheelScrollDistanceStep.x;
+      targetScrollPosition.x += event.GetDelta() * mWheelScrollDistanceStep.x;
       ClampPosition(targetScrollPosition);
       ScrollTo(-targetScrollPosition);
     }
     else if(!mScrolling)
     {
       // Snap mode, only respond to the event when the previous snap animation is finished.
       ClampPosition(targetScrollPosition);
       ScrollTo(-targetScrollPosition);
     }
     else if(!mScrolling)
     {
       // Snap mode, only respond to the event when the previous snap animation is finished.
-      ScrollTo(GetCurrentPage() - event.z);
+      ScrollTo(GetCurrentPage() - event.GetDelta());
     }
   }
   else
     }
   }
   else
@@ -2160,14 +2160,14 @@ bool ScrollView::OnWheelEvent(const WheelEvent& event)
     if(mRulerY->GetType() == Ruler::Free)
     {
       // Free panning mode
     if(mRulerY->GetType() == Ruler::Free)
     {
       // Free panning mode
-      targetScrollPosition.y += event.z * mWheelScrollDistanceStep.y;
+      targetScrollPosition.y += event.GetDelta() * mWheelScrollDistanceStep.y;
       ClampPosition(targetScrollPosition);
       ScrollTo(-targetScrollPosition);
     }
     else if(!mScrolling)
     {
       // Snap mode, only respond to the event when the previous snap animation is finished.
       ClampPosition(targetScrollPosition);
       ScrollTo(-targetScrollPosition);
     }
     else if(!mScrolling)
     {
       // Snap mode, only respond to the event when the previous snap animation is finished.
-      ScrollTo(GetCurrentPage() - event.z * mRulerX->GetTotalPages());
+      ScrollTo(GetCurrentPage() - event.GetDelta() * mRulerX->GetTotalPages());
     }
   }
 
     }
   }