[Tizen] Changed GetNearestFocusableActor interface to receive rootActor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.cpp
index 631e35c..16f7386 100644 (file)
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <cstring> // for strcmp
 #include <dali/public-api/actors/layer.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
 #include <dali/devel-api/common/singleton-service.h>
 #include <dali/devel-api/adaptor-framework/lifecycle-controller.h>
@@ -203,7 +204,23 @@ bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
 {
   bool success = false;
-  if( actor && actor.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) && actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
+
+  // If the parent's KEYBOARD_FOCUSABLE_CHILDREN is false, it cannot have focus.
+  if(actor)
+  {
+    Actor parent = actor.GetParent();
+    while(parent)
+    {
+      if(!parent.GetProperty<bool>(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN))
+      {
+        DALI_LOG_INFO(gLogFilter, Debug::General, "[%s:%d] Parent Actor has KEYBOARD_FOCUSABLE_CHILDREN false,\n", __FUNCTION__, __LINE__);
+        return false;
+      }
+      parent = parent.GetParent();
+    }
+  }
+
+  if(actor && actor.GetProperty<bool>(Actor::Property::KEYBOARD_FOCUSABLE) && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
   {
     Integration::SceneHolder currentWindow = Integration::SceneHolder::Get( actor );
 
@@ -505,7 +522,11 @@ bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction
       else if(mEnableDefaultAlgorithm)
       {
         // We should find it among the actors nearby.
-        nextFocusableActor = Toolkit::FocusFinder::GetNearestFocusableActor(currentFocusActor, direction);
+        Integration::SceneHolder window = Integration::SceneHolder::Get(currentFocusActor);
+        if(window)
+        {
+          nextFocusableActor = Toolkit::FocusFinder::GetNearestFocusableActor(window.GetRootLayer(), currentFocusActor, direction);
+        }
       }
     }
 
@@ -991,10 +1012,20 @@ void KeyboardFocusManager::OnTouch(const TouchEvent& touch)
 
   // Clear the focus when user touch the screen.
   // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
-  // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
-  if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
+  if(((touch.GetPointCount() < 1) || (touch.GetState(0) == PointState::DOWN)))
   {
-    ClearFocus();
+    // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
+    if(mClearFocusOnTouch)
+    {
+      ClearFocus();
+    }
+
+    // If KEYBOARD_FOCUSABLE and TOUCH_FOCUSABLE is true, set focus actor
+    Actor hitActor = touch.GetHitActor(0);
+    if(hitActor && hitActor.GetProperty<bool>(Actor::Property::KEYBOARD_FOCUSABLE) && hitActor.GetProperty<bool>(DevelActor::Property::TOUCH_FOCUSABLE))
+    {
+      SetCurrentFocusActor(hitActor);
+    }
   }
 }