Fix KeyboardFocusManager ClearFocus bug 41/186741/4
authorminho.sun <minho.sun@samsung.com>
Tue, 14 Aug 2018 04:41:50 +0000 (13:41 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Thu, 27 Sep 2018 07:10:11 +0000 (16:10 +0900)
- Added 'mAlwaysShowIndicator' member variable to keep the initial value.
- 'mIsFocusIndicatorShown' should be the initial value
  even though ClearFocus() is called.

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

index 1b82c49..5822102 100755 (executable)
@@ -1182,10 +1182,68 @@ int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
 
+  // Clear the focus again
+  manager.ClearFocus();
+
+  // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
+  preFocusChangeCallback.Reset();
+  application.ProcessEvent(upEvent);
+  DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
+  DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
+  DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
+  DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
+
+  // Clear the focus again
+  manager.ClearFocus();
+
+  // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
+  preFocusChangeCallback.Reset();
+  application.ProcessEvent(downEvent);
+  DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
+  DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
+  DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
+  DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
+
   END_TEST;
 }
 
+int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
+
+  KeyboardFocusManager manager = KeyboardFocusManager::Get();
+  DALI_TEST_CHECK(manager);
+
+  bool preFocusChangeSignalVerified = false;
+  PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
+  manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
+
+  Integration::KeyEvent spaceEvent( "space", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
+
+  // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
+  // It makes mIsFocusIndicatorEnabled true
+  application.ProcessEvent(spaceEvent);
+
+  // Send the space event
+  application.ProcessEvent(spaceEvent);
+  DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
+  DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
+
+  // Clear the focus again
+  manager.ClearFocus();
+
+  // Send the space event again for line coverage
+  preFocusChangeCallback.Reset();
+  application.ProcessEvent(spaceEvent);
+  DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
+  DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
+  DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
+  DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
 
+  END_TEST;
+}
 
 
 
index 3555b3c..3653f5f 100644 (file)
@@ -119,16 +119,17 @@ KeyboardFocusManager::KeyboardFocusManager()
   mFocusedActorEnterKeySignal(),
   mCurrentFocusActor(),
   mFocusIndicatorActor(),
-  mIsFocusIndicatorEnabled( -1 ),
+  mIsFocusIndicatorShown( -1 ),
   mFocusGroupLoopEnabled( false ),
   mIsWaitingKeyboardFocusChangeCommit( false ),
   mClearFocusOnTouch( true ),
   mEnableFocusIndicator( true ),
+  mAlwaysShowIndicator( true ),
   mFocusHistory(),
   mSlotDelegate( this ),
   mCustomAlgorithmInterface(NULL)
 {
-  // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
+  // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorShown.
   Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
   Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
 }
@@ -143,8 +144,9 @@ void KeyboardFocusManager::GetConfigurationFromStyleManger()
     if( styleManager )
     {
       Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
-      mIsFocusIndicatorEnabled = static_cast<int>(config["alwaysShowFocus"].Get<bool>());
-      mClearFocusOnTouch = mIsFocusIndicatorEnabled ? false : true;
+      mAlwaysShowIndicator = config["alwaysShowFocus"].Get<bool>();
+      mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
+      mClearFocusOnTouch = mIsFocusIndicatorShown ? false : true;
     }
 }
 
@@ -152,7 +154,7 @@ bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
 {
   DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
 
-  if( mIsFocusIndicatorEnabled == -1 )
+  if( mIsFocusIndicatorShown == -1 )
   {
     GetConfigurationFromStyleManger();
   }
@@ -179,7 +181,7 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
   // Check whether the actor is in the stage and is keyboard focusable.
   if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
   {
-    if( mIsFocusIndicatorEnabled && mEnableFocusIndicator )
+    if( mIsFocusIndicatorShown && mEnableFocusIndicator )
     {
       actor.Add( GetFocusIndicatorActor() );
     }
@@ -555,7 +557,7 @@ void KeyboardFocusManager::ClearFocus()
   }
 
   mCurrentFocusActor.Reset();
-  mIsFocusIndicatorEnabled = 0;
+  mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
 }
 
 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
@@ -655,7 +657,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
 
   std::string keyName = event.keyPressedName;
 
-  if( mIsFocusIndicatorEnabled == -1 )
+  if( mIsFocusIndicatorShown == -1 )
   {
     GetConfigurationFromStyleManger();
   }
@@ -668,10 +670,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     {
       if(!isAccessibilityEnabled)
       {
-        if(!mIsFocusIndicatorEnabled)
+        if(!mIsFocusIndicatorShown)
         {
           // Show focus indicator
-          mIsFocusIndicatorEnabled = 1;
+          mIsFocusIndicatorShown = 1;
         }
         else
         {
@@ -691,10 +693,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     {
       if(!isAccessibilityEnabled)
       {
-        if(!mIsFocusIndicatorEnabled)
+        if(!mIsFocusIndicatorShown)
         {
           // Show focus indicator
-          mIsFocusIndicatorEnabled = 1;
+          mIsFocusIndicatorShown = 1;
         }
         else
         {
@@ -712,10 +714,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
     else if (keyName == "Up" && !isAccessibilityEnabled)
     {
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
       else
       {
@@ -727,10 +729,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
     else if (keyName == "Down" && !isAccessibilityEnabled)
     {
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
       else
       {
@@ -742,10 +744,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
     else if (keyName == "Prior" && !isAccessibilityEnabled)
     {
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
       else
       {
@@ -757,10 +759,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
     else if (keyName == "Next" && !isAccessibilityEnabled)
     {
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
       else
       {
@@ -772,10 +774,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
     else if (keyName == "Tab" && !isAccessibilityEnabled)
     {
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
       else
       {
@@ -788,10 +790,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
     else if (keyName == "space" && !isAccessibilityEnabled)
     {
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
 
       isFocusStartableKey = true;
@@ -799,10 +801,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     else if (keyName == "" && !isAccessibilityEnabled)
     {
       // Check the fake key event for evas-plugin case
-      if(!mIsFocusIndicatorEnabled)
+      if(!mIsFocusIndicatorShown)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
 
       isFocusStartableKey = true;
@@ -819,10 +821,10 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
   {
     if (keyName == "Return")
     {
-      if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
+      if(!mIsFocusIndicatorShown && !isAccessibilityEnabled)
       {
         // Show focus indicator
-        mIsFocusIndicatorEnabled = 1;
+        mIsFocusIndicatorShown = 1;
       }
       else
       {
@@ -847,7 +849,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
     }
   }
 
-  if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
+  if(isFocusStartableKey && mIsFocusIndicatorShown && !isAccessibilityEnabled)
   {
     Actor actor = GetCurrentFocusActor();
     if( actor )
@@ -869,9 +871,9 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
 
 void KeyboardFocusManager::OnTouch(const TouchData& touch)
 {
-  // if mIsFocusIndicatorEnabled is -1, it means Configuration is not loaded.
+  // if mIsFocusIndicatorShown is -1, it means Configuration is not loaded.
   // Try to load configuration.
-  if( mIsFocusIndicatorEnabled == -1 )
+  if( mIsFocusIndicatorShown == -1 )
   {
     GetConfigurationFromStyleManger();
   }
index be69ce0..9e4d96e 100644 (file)
@@ -269,7 +269,7 @@ private:
 
   Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
 
-  int mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed.
+  int mIsFocusIndicatorShown; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed.
 
   bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
 
@@ -279,6 +279,8 @@ private:
 
   bool mEnableFocusIndicator;  ///< Whether use focus indicator
 
+  bool mAlwaysShowIndicator; ///< Whether always show indicator. If true, the indicator would be directly shown when focused.
+
   FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
 
   SlotDelegate< KeyboardFocusManager > mSlotDelegate;