Merge "Add UserInteractionEnabled property on actor for controlling user interaction...
authorSangHyeon Lee <sh10233.lee@samsung.com>
Thu, 17 Mar 2022 10:46:02 +0000 (10:46 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 17 Mar 2022 10:46:02 +0000 (10:46 +0000)
automated-tests/src/dali/utc-Dali-Actor.cpp
automated-tests/src/dali/utc-Dali-HoverProcessing.cpp
automated-tests/src/dali/utc-Dali-TouchProcessing.cpp
dali/devel-api/actors/actor-devel.h
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/actor-impl.h
dali/internal/event/actors/actor-property-handler.cpp

index 0071883..9873aa7 100644 (file)
@@ -2606,6 +2606,29 @@ int UtcDaliActorIsTouchFocusable(void)
   END_TEST;
 }
 
+int UtcDaliActorSetUserInteractionEnabled(void)
+{
+  TestApplication application;
+  Actor           actor = Actor::New();
+
+  bool enabled = !actor.GetProperty<bool>(DevelActor::Property::USER_INTERACTION_ENABLED);
+
+  actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, enabled);
+
+  DALI_TEST_CHECK(enabled == actor.GetProperty<bool>(DevelActor::Property::USER_INTERACTION_ENABLED));
+  END_TEST;
+}
+
+int UtcDaliActorIsUserInteractionEnabled(void)
+{
+  TestApplication application;
+  Actor           actor = Actor::New();
+  actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, true);
+
+  DALI_TEST_CHECK(true == actor.GetProperty<bool>(DevelActor::Property::USER_INTERACTION_ENABLED));
+  END_TEST;
+}
+
 int UtcDaliActorRemoveConstraints(void)
 {
   tet_infoline(" UtcDaliActorRemoveConstraints");
index 70393de..6c07092 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <dali-test-suite-utils.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/events/hover-event-devel.h>
 #include <dali/integration-api/events/hover-event-integ.h>
 #include <dali/integration-api/render-task-list-integ.h>
@@ -756,6 +757,41 @@ int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
   END_TEST;
 }
 
+int UtcDaliHoverActorBecomesUserInteractionDisabled(void)
+{
+  TestApplication application;
+
+  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();
+
+  // Connect to actor's hovered signal
+  SignalData        data;
+  HoverEventFunctor functor(data);
+  actor.HoveredSignal().Connect(&application, functor);
+
+  // Emit a started signal
+  application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
+  data.Reset();
+
+  // Change actor to disable user interaction.
+  actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
+
+  // Emit a motion signal, signalled with an interrupted
+  application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::INTERRUPTED, data.hoverEvent.GetState(0), TEST_LOCATION);
+  data.Reset();
+  END_TEST;
+}
+
 int UtcDaliHoverMultipleLayers(void)
 {
   TestApplication application;
index 26e4aa5..d39266a 100644 (file)
@@ -944,6 +944,41 @@ int UtcDaliTouchEventActorBecomesInsensitiveParentConsumer(void)
   END_TEST;
 }
 
+int UtcDaliTouchEventActorBecomesUserInteractionDisabled(void)
+{
+  TestApplication application;
+
+  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();
+
+  // Connect to actor's touched signal
+  SignalData        data;
+  TouchEventFunctor functor(data);
+  actor.TouchedSignal().Connect(&application, functor);
+
+  // Emit a down signal
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
+  data.Reset();
+
+  // Change actor to disable user interaction.
+  actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
+
+  // Emit a motion signal, signalled with an interrupted
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
+  data.Reset();
+  END_TEST;
+}
+
 int UtcDaliTouchEventMultipleLayers(void)
 {
   TestApplication application;
index 5cda265..9d4f0ae 100644 (file)
@@ -177,7 +177,14 @@ enum Type
    * @details Name "keyboardFocusableChildren", type Property::BOOLEAN.
    * @note Default value is true.
    */
-  KEYBOARD_FOCUSABLE_CHILDREN
+  KEYBOARD_FOCUSABLE_CHILDREN,
+
+  /**
+  * @brief The flag whether the actor should be enabled all user interaction including touch, focus and activation. this value have higher priority over the sensitve and focusable in negative action.
+  * @details Name "userInteractionEnabled", type Property::BOOLEAN.
+  * @note Default value is true.
+  */
+  USER_INTERACTION_ENABLED,
 };
 
 } // namespace Property
index 73756a6..6dc060a 100644 (file)
@@ -148,6 +148,7 @@ DALI_PROPERTY("touchAreaOffset", RECTANGLE, true, false, false, Dali::DevelActor
 DALI_PROPERTY("blendEquation", INTEGER, true, false, false, Dali::DevelActor::Property::BLEND_EQUATION)
 DALI_PROPERTY("touchFocusable", BOOLEAN, true, false, false, Dali::DevelActor::Property::TOUCH_FOCUSABLE)
 DALI_PROPERTY("keyboardFocusableChildren", BOOLEAN, true, false, false, Dali::DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN)
+DALI_PROPERTY("userInteractionEnabled", BOOLEAN, true, false, false, Dali::DevelActor::Property::USER_INTERACTION_ENABLED)
 DALI_PROPERTY_TABLE_END(DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultProperties)
 
 // Signals
@@ -1092,6 +1093,7 @@ Actor::Actor(DerivedType derivedType, const SceneGraph::Node& node)
   mCaptureAllTouchAfterStart(false),
   mIsBlendEquationSet(false),
   mNeedGesturePropagation(false),
+  mUserInteractionEnabled(true),
   mLayoutDirection(LayoutDirection::LEFT_TO_RIGHT),
   mDrawMode(DrawMode::NORMAL),
   mColorMode(Node::DEFAULT_COLOR_MODE),
index bade273..3392d0d 100644 (file)
@@ -646,6 +646,41 @@ public:
   }
 
   /**
+   * Sets whether an actor should be enabled all user interaction including touch, focus and activation.
+   * This value have higher priority over the sensitve and focusable in negative action,
+   * which means IsSensitive() or IsFocusable() and enable is false, actor will not emits touch or focus event.
+   * An actor is enabled by default.
+   *
+   * If the application wishes to temporarily disable user interaction:
+   * @code
+   * actor.SetUserInteractionEnabled(false);
+   * @endcode
+   *
+   * Then, to re-enable user interaction, the application should call:
+   * @code
+   * actor.SetUserInteractionEnabled(true);
+   * @endcode
+   *
+   * @see IsSensitive(), IsHittable(), IsKeyboardFocusable() and IsTouchFocusable().
+   * @note If an actor's disabled, child still can be enabled.
+   * @param[in]  enabled  true to enable user interaction, false otherwise.
+   */
+  void SetUserInteractionEnabled(bool enabled)
+  {
+    mUserInteractionEnabled = enabled;
+  }
+
+  /**
+   * Query whether an actor is enabled user interaction.
+   * @see SetSensitive(bool)
+   * @return true, if user interaction is enabled, false otherwise.
+   */
+  bool IsUserInteractionEnabled() const
+  {
+    return mUserInteractionEnabled;
+  }
+
+  /**
    * @copydoc Dali::Actor::SetDrawMode
    */
   void SetDrawMode(DrawMode::Type drawMode);
@@ -1258,7 +1293,7 @@ public:
    */
   bool IsHittable() const
   {
-    return IsSensitive() && IsVisible() && (GetCurrentWorldColor().a > FULLY_TRANSPARENT) && IsNodeConnected();
+    return (IsUserInteractionEnabled()) && IsSensitive() && IsVisible() && (GetCurrentWorldColor().a > FULLY_TRANSPARENT) && IsNodeConnected();
   }
 
   /**
@@ -1888,6 +1923,7 @@ protected:
   bool                     mCaptureAllTouchAfterStart : 1; ///< Whether the actor should capture all touch after touch starts even if the motion moves outside of the actor area.
   bool                     mIsBlendEquationSet : 1;        ///< Flag to identify whether the Blend equation is set
   bool                     mNeedGesturePropagation : 1;    ///< Whether the parent listens for gesture events or not
+  bool                     mUserInteractionEnabled : 1;    ///< Whether the actor should be enabled user interaction.
   LayoutDirection::Type    mLayoutDirection : 2;           ///< Layout direction, Left to Right or Right to Left.
   DrawMode::Type           mDrawMode : 3;                  ///< Cached: How the actor and its children should be drawn
   ColorMode                mColorMode : 3;                 ///< Cached: Determines whether mWorldColor is inherited
index 2012ed1..4a7dacc 100644 (file)
@@ -619,6 +619,16 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property
       break;
     }
 
+    case Dali::DevelActor::Property::USER_INTERACTION_ENABLED:
+    {
+      bool value = false;
+      if(property.Get(value))
+      {
+        actor.SetUserInteractionEnabled(value);
+      }
+      break;
+    }
+
     default:
     {
       // this can happen in the case of a non-animatable default property so just do nothing
@@ -1656,6 +1666,12 @@ bool Actor::PropertyHandler::GetCachedPropertyValue(const Internal::Actor& actor
       break;
     }
 
+    case Dali::DevelActor::Property::USER_INTERACTION_ENABLED:
+    {
+      value = actor.IsUserInteractionEnabled();
+      break;
+    }
+
     default:
     {
       // Must be a scene-graph only property