Added UseFocusIndicator API to devel keyboard-focus-manager 01/183901/7
authorminho.sun <minho.sun@samsung.com>
Thu, 12 Jul 2018 06:58:12 +0000 (15:58 +0900)
committerminho.sun <minho.sun@samsung.com>
Tue, 7 Aug 2018 00:07:42 +0000 (09:07 +0900)
Added UseFocusIndicator API to devel keyboard-focus-manager.

Some developers want to use other way to indicate focus state instead of using focus indicator.
In this case, currently they use work-around which is setting transparent actor as focus indicator.

For convenience, support UseFocusIndicator API.

If user sets state to false, focus indicator will disapear immediately
and not be shown until setting state to true.

Change-Id: I0678f56e17e76751fe6a365b2d565f7b592c6d36
Signed-off-by: minho.sun <minho.sun@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp
dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.cpp
dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h

index 8b9547a..1b82c49 100755 (executable)
@@ -1425,3 +1425,39 @@ int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
 
   END_TEST;
 }
 
   END_TEST;
 }
+
+int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline( "Ensure we cannot set an actor to be focused if it is not staged and that we do not retrieve an actor if it has been unstaged" );
+
+  KeyboardFocusManager manager = KeyboardFocusManager::Get();
+  DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
+
+  Actor actor = Actor::New();
+  actor.SetKeyboardFocusable( true );
+  Stage::GetCurrent().Add( actor );
+  manager.SetCurrentFocusActor( actor );
+
+  // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
+  // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
+  Integration::KeyEvent rightEvent( "Right", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
+  application.ProcessEvent(rightEvent);
+
+  Actor indicatorActor = manager.GetFocusIndicatorActor();
+
+  tet_infoline( "Indicator is added to focused actor" );
+  DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
+
+  Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
+  DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
+
+  tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
+  DALI_TEST_CHECK( !indicatorActor.GetParent() );
+
+  END_TEST;
+}
+
+
+
index a56ece5..17645b9 100644 (file)
@@ -33,6 +33,16 @@ void SetCustomAlgorithm(KeyboardFocusManager keyboardFocusManager, CustomAlgorit
   GetImpl(keyboardFocusManager).SetCustomAlgorithm(interface);
 }
 
   GetImpl(keyboardFocusManager).SetCustomAlgorithm(interface);
 }
 
+void EnableFocusIndicator(KeyboardFocusManager keyboardFocusManager, bool enable)
+{
+  GetImpl(keyboardFocusManager).EnableFocusIndicator(enable);
+}
+
+bool IsFocusIndicatorEnabled(KeyboardFocusManager keyboardFocusManager)
+{
+  return GetImpl(keyboardFocusManager).IsFocusIndicatorEnabled();
+}
+
 } // namespace DevelKeyboardFocusManager
 
 } // namespace Toolkit
 } // namespace DevelKeyboardFocusManager
 
 } // namespace Toolkit
index 4aa1887..dd59fcd 100644 (file)
@@ -71,6 +71,22 @@ public:
  */
 DALI_TOOLKIT_API void SetCustomAlgorithm(KeyboardFocusManager keyboardFocusManager, CustomAlgorithmInterface& interface);
 
  */
 DALI_TOOLKIT_API void SetCustomAlgorithm(KeyboardFocusManager keyboardFocusManager, CustomAlgorithmInterface& interface);
 
+/**
+ * @brief Decide using focus indicator or not
+ *
+ * @param[in] keyboardFocusManager The instance of KeyboardFocusManager
+ * @param[in] enable Whether using focus indicator or not
+ */
+DALI_TOOLKIT_API void EnableFocusIndicator(KeyboardFocusManager keyboardFocusManager, bool enable);
+
+/**
+ * @brief Check focus indicator is enabled or not
+ *
+ * @param[in] keyboardFocusManager The instance of KeyboardFocusManager
+ * @return True when focus indicator is enabled
+ */
+DALI_TOOLKIT_API bool IsFocusIndicatorEnabled(KeyboardFocusManager keyboardFocusManager);
+
 } // namespace DevelKeyboardFocusManager
 
 } // namespace Toolkit
 } // namespace DevelKeyboardFocusManager
 
 } // namespace Toolkit
index 9e34984..a20808c 100644 (file)
@@ -123,6 +123,7 @@ KeyboardFocusManager::KeyboardFocusManager()
   mFocusGroupLoopEnabled( false ),
   mIsWaitingKeyboardFocusChangeCommit( false ),
   mClearFocusOnTouch( true ),
   mFocusGroupLoopEnabled( false ),
   mIsWaitingKeyboardFocusChangeCommit( false ),
   mClearFocusOnTouch( true ),
+  mEnableFocusIndicator( true ),
   mFocusHistory(),
   mSlotDelegate( this ),
   mCustomAlgorithmInterface(NULL)
   mFocusHistory(),
   mSlotDelegate( this ),
   mCustomAlgorithmInterface(NULL)
@@ -178,7 +179,7 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
   // Check whether the actor is in the stage and is keyboard focusable.
   if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
   {
   // Check whether the actor is in the stage and is keyboard focusable.
   if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
   {
-    if( mIsFocusIndicatorEnabled )
+    if( mIsFocusIndicatorEnabled && mEnableFocusIndicator )
     {
       actor.Add( GetFocusIndicatorActor() );
     }
     {
       actor.Add( GetFocusIndicatorActor() );
     }
@@ -836,8 +837,11 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     Actor actor = GetCurrentFocusActor();
     if( actor )
     {
     Actor actor = GetCurrentFocusActor();
     if( actor )
     {
-      // Make sure the focused actor is highlighted
-      actor.Add( GetFocusIndicatorActor() );
+      if( mEnableFocusIndicator )
+      {
+        // Make sure the focused actor is highlighted
+        actor.Add( GetFocusIndicatorActor() );
+      }
     }
     else
     {
     }
     else
     {
@@ -923,6 +927,21 @@ void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interfac
   mCustomAlgorithmInterface = &interface;
 }
 
   mCustomAlgorithmInterface = &interface;
 }
 
+void KeyboardFocusManager::EnableFocusIndicator(bool enable)
+{
+  if( !enable && mFocusIndicatorActor )
+  {
+    mFocusIndicatorActor.Unparent();
+  }
+
+  mEnableFocusIndicator = enable;
+}
+
+bool KeyboardFocusManager::IsFocusIndicatorEnabled() const
+{
+  return mEnableFocusIndicator;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
 } // namespace Internal
 
 } // namespace Toolkit
index ad87b55..be69ce0 100644 (file)
@@ -120,6 +120,16 @@ public:
    */
   void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
 
    */
   void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
 
+  /**
+   * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
+   */
+  void EnableFocusIndicator(bool enable);
+
+  /**
+   * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
+   */
+  bool IsFocusIndicatorEnabled() const;
+
 public:
 
   /**
 public:
 
   /**
@@ -267,6 +277,8 @@ private:
 
   bool mClearFocusOnTouch:1; ///< Whether clear focus on touch.
 
 
   bool mClearFocusOnTouch:1; ///< Whether clear focus on touch.
 
+  bool mEnableFocusIndicator;  ///< Whether use focus indicator
+
   FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
 
   SlotDelegate< KeyboardFocusManager > mSlotDelegate;
   FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
 
   SlotDelegate< KeyboardFocusManager > mSlotDelegate;