Add TOUCH_FOCUSABLE property 58/259258/15
authorJoogab Yun <joogab.yun@samsung.com>
Thu, 3 Jun 2021 06:43:05 +0000 (15:43 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Fri, 11 Jun 2021 06:43:33 +0000 (15:43 +0900)
This is a property that allows you to have focus even when touched.

It works only when KEYBOARD_FOCUSABLE is set to true.

KEYBOARD_FOCUSABLE :  whether the view can have focus or not
TOUCH_FOCUSABLE    :  Whether the user can focus by touch

Change-Id: Id991d7a0bd734718164b874f013e24235476e789

automated-tests/src/dali/utc-Dali-Actor.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
dali/internal/event/events/hit-test-algorithm-impl.cpp

index 12dc2b7..4037c13 100644 (file)
@@ -2524,6 +2524,30 @@ int UtcDaliActorIsKeyboardFocusable(void)
   END_TEST;
 }
 
+int UtcDaliActorSetTouchFocusable(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+
+  actor.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
+  DALI_TEST_CHECK(actor.GetProperty<bool>(DevelActor::Property::TOUCH_FOCUSABLE) == true);
+
+  actor.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, false);
+  DALI_TEST_CHECK(actor.GetProperty<bool>(DevelActor::Property::TOUCH_FOCUSABLE) == false);
+  END_TEST;
+}
+
+int UtcDaliActorIsTouchFocusable(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+
+  DALI_TEST_CHECK(actor.GetProperty<bool>(DevelActor::Property::TOUCH_FOCUSABLE) == false);
+  END_TEST;
+}
+
 int UtcDaliActorRemoveConstraints(void)
 {
   tet_infoline(" UtcDaliActorRemoveConstraints");
index f46478e..338a293 100644 (file)
@@ -159,7 +159,18 @@ enum Type
    * @note Color of each renderer will be blended with rendering framebuffer.
    * @note To check the blend equation is supported in the system, use Dali::Capabilities::IsBlendEquationSupported
    */
-  BLEND_EQUATION
+  BLEND_EQUATION,
+
+  /**
+   * @brief Sets whether this view can focus by touch. If user sets this to true, the actor will be focused when user touch it.
+   * @code
+   * Actor actor = Actor::New();
+   * actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); // whether the view can have focus or not with keyboard navigation.
+   * actor.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true); // Whether the user can focus by touch, user can set focus by touching the actor.
+   * @endcode
+   * @details Name "touchFocusable", type Property::BOOLEAN.
+   */
+  TOUCH_FOCUSABLE
 };
 
 } // namespace Property
index c06b2a4..c669199 100644 (file)
@@ -148,6 +148,7 @@ DALI_PROPERTY("updateSizeHint", VECTOR2, true, false, false, Dali::DevelActor::P
 DALI_PROPERTY("captureAllTouchAfterStart", BOOLEAN, true, false, false, Dali::DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START)
 DALI_PROPERTY("touchAreaOffset", RECTANGLE, true, false, false, Dali::DevelActor::Property::TOUCH_AREA_OFFSET)
 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_TABLE_END(DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultProperties)
 
 // Signals
@@ -1332,6 +1333,7 @@ Actor::Actor(DerivedType derivedType, const SceneGraph::Node& node)
   mSensitive(true),
   mLeaveRequired(false),
   mKeyboardFocusable(false),
+  mTouchFocusable(false),
   mOnSceneSignalled(false),
   mInsideOnSizeSet(false),
   mInheritPosition(true),
index 2857f87..99236a3 100644 (file)
@@ -1319,6 +1319,24 @@ public:
   }
 
   /**
+   * Set whether this view can focus by touch.
+   * @param[in] focusable focuable by touch.
+   */
+  void SetTouchFocusable(bool focusable)
+  {
+    mTouchFocusable = focusable;
+  }
+
+  /**
+   * This returns whether this actor can focus by touch.
+   * @return true if this actor can focus by touch.
+   */
+  bool IsTouchFocusable() const
+  {
+    return mTouchFocusable;
+  }
+
+  /**
    * Query whether the application or derived actor type requires intercept touch events.
    * @return True if intercept touch events are required.
    */
@@ -2048,6 +2066,7 @@ protected:
   bool                     mSensitive : 1;                 ///< Whether the actor emits touch event signals
   bool                     mLeaveRequired : 1;             ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
   bool                     mKeyboardFocusable : 1;         ///< Whether the actor should be focusable by keyboard navigation
+  bool                     mTouchFocusable : 1;            ///< Whether the actor should be focusable by touch
   bool                     mOnSceneSignalled : 1;          ///< Set to true before OnSceneConnection signal is emitted, and false before OnSceneDisconnection
   bool                     mInsideOnSizeSet : 1;           ///< Whether we are inside OnSizeSet
   bool                     mInheritPosition : 1;           ///< Cached: Whether the parent's position should be inherited.
index 111a088..9c28f27 100644 (file)
@@ -597,6 +597,16 @@ void Actor::PropertyHandler::SetDefaultProperty(Internal::Actor& actor, Property
       break;
     }
 
+    case Dali::DevelActor::Property::TOUCH_FOCUSABLE:
+    {
+      bool value = false;
+      if(property.Get(value))
+      {
+        actor.SetTouchFocusable(value);
+      }
+      break;
+    }
+
     default:
     {
       // this can happen in the case of a non-animatable default property so just do nothing
@@ -1646,6 +1656,12 @@ bool Actor::PropertyHandler::GetCachedPropertyValue(const Internal::Actor& actor
       break;
     }
 
+    case Dali::DevelActor::Property::TOUCH_FOCUSABLE:
+    {
+      value = actor.IsTouchFocusable();
+      break;
+    }
+
     default:
     {
       // Must be a scene-graph only property
index 2cb7b42..1576efe 100644 (file)
@@ -100,8 +100,8 @@ struct ActorTouchableCheck : public HitTestInterface
 {
   bool IsActorHittable(Actor* actor) override
   {
-    return actor->GetTouchRequired() && // Does the Application or derived actor type require a touch event?
-           actor->IsHittable();         // Is actor sensitive, visible and on the scene?
+    return (actor->GetTouchRequired() || actor->IsTouchFocusable()) && // Does the Application or derived actor type require a touch event? or focusable by touch?
+           actor->IsHittable();                                        // Is actor sensitive, visible and on the scene?
   }
 
   bool DescendActorHierarchy(Actor* actor) override