Remove the indicator
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / accessibility-manager / accessibility-manager-impl.cpp
index 3e14751..aee1bc0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
 
 namespace Dali
 {
@@ -57,8 +58,7 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FOC
 const char* const ACTOR_FOCUSABLE("focusable");
 const char* const IS_FOCUS_GROUP("isFocusGroup");
 
-const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "B16-8_TTS_focus.png";
-const Vector4 FOCUS_BORDER_IMAGE_BORDER = Vector4(7.0f, 7.0f, 7.0f, 7.0f);
+const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "B16-8_TTS_focus.9.png";
 
 const char* FOCUS_SOUND_FILE = DALI_SOUND_DIR "Focus.ogg";
 const char* FOCUS_CHAIN_END_SOUND_FILE = DALI_SOUND_DIR "End_of_List.ogg";
@@ -108,7 +108,9 @@ bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType
 
 AccessibilityManager::AccessibilityManager()
 : mCurrentFocusActor(FocusIDPair(0, 0)),
-  mFocusIndicatorActor(Actor()),
+  mCurrentGesturedActor(),
+  mFocusIndicatorActor(),
+  mPreviousPosition( 0.0f, 0.0f ),
   mRecursiveFocusMoveCounter(0),
   mIsWrapped(false),
   mIsFocusWithinGroup(false),
@@ -127,8 +129,6 @@ AccessibilityManager::~AccessibilityManager()
 
 void AccessibilityManager::Initialise()
 {
-  CreateDefaultFocusIndicatorActor();
-
   AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
   adaptor.SetActionHandler(*this);
   adaptor.SetGestureHandler(*this);
@@ -191,12 +191,8 @@ void AccessibilityManager::SetFocusOrder(Actor actor, const unsigned int order)
     // Firstly delete the actor from the focus chain if it's already there with a different focus order.
     mFocusIDContainer.erase(GetFocusOrder(actor));
 
-    // Create actor focusable property if not already created.
-    Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
-    if(propertyActorFocusable == Property::INVALID_INDEX)
-    {
-      propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE );
-    }
+    // Create/retrieve actor focusable property
+    Property::Index propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE );
 
     if(order == 0)
     {
@@ -345,9 +341,9 @@ bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID)
     if(actorVisible && actorFocusable && actorOpaque)
     {
       // Draw the focus indicator upon the focused actor
-      if(mIsFocusIndicatorEnabled && mFocusIndicatorActor)
+      if( mIsFocusIndicatorEnabled )
       {
-        actor.Add(mFocusIndicatorActor);
+        actor.Add( GetFocusIndicatorActor() );
       }
 
       // Send notification for the change of focus actor
@@ -483,9 +479,9 @@ void AccessibilityManager::DoActivate(Actor actor)
 void AccessibilityManager::ClearFocus()
 {
   Actor actor = GetCurrentFocusActor();
-  if(actor)
+  if( actor && mFocusIndicatorActor )
   {
-    actor.Remove(mFocusIndicatorActor);
+    actor.Remove( mFocusIndicatorActor );
   }
 
   mCurrentFocusActor = FocusIDPair(0, 0);
@@ -512,16 +508,8 @@ void AccessibilityManager::SetFocusGroup(Actor actor, bool isFocusGroup)
 {
   if(actor)
   {
-    // Create focus group property if not already created.
-    Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP);
-    if(propertyIsFocusGroup == Property::INVALID_INDEX)
-    {
-      actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE );
-    }
-    else
-    {
-      actor.SetProperty(propertyIsFocusGroup, isFocusGroup);
-    }
+    // Create/Set focus group property.
+    actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE );
   }
 }
 
@@ -581,11 +569,40 @@ bool AccessibilityManager::GetWrapMode() const
 
 void AccessibilityManager::SetFocusIndicatorActor(Actor indicator)
 {
-  mFocusIndicatorActor = indicator;
+  if( mFocusIndicatorActor != indicator )
+  {
+    Actor currentFocusActor = GetCurrentFocusActor();
+    if( currentFocusActor )
+    {
+      // The new focus indicator should be added to the current focused actor immediately
+      if( mFocusIndicatorActor )
+      {
+        currentFocusActor.Remove( mFocusIndicatorActor );
+      }
+
+      if( indicator )
+      {
+        currentFocusActor.Add( indicator );
+      }
+    }
+
+    mFocusIndicatorActor = indicator;
+  }
 }
 
 Actor AccessibilityManager::GetFocusIndicatorActor()
 {
+  if( ! mFocusIndicatorActor )
+  {
+    // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
+    mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
+    mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
+    mFocusIndicatorActor.SetZ( 1.0f );
+
+    // Apply size constraint to the focus indicator
+    mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  }
+
   return mFocusIndicatorActor;
 }
 
@@ -667,36 +684,11 @@ void AccessibilityManager::SetFocusable(Actor actor, bool focusable)
 {
   if(actor)
   {
-    // Create actor focusable property if not already created.
-    Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
-    if(propertyActorFocusable == Property::INVALID_INDEX)
-    {
-      actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE );
-    }
-    else
-    {
-      actor.SetProperty(propertyActorFocusable, focusable);
-    }
+    // Create/Set actor focusable property.
+    actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE );
   }
 }
 
-void AccessibilityManager::CreateDefaultFocusIndicatorActor()
-{
-  // Create a focus indicator actor shared by all the focusable actors
-  Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH);
-
-  ImageActor focusIndicator = ImageActor::New(borderImage);
-  focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
-  focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
-  focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER);
-  focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
-
-  // Apply size constraint to the focus indicator
-  focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-
-  SetFocusIndicatorActor(focusIndicator);
-}
-
 bool AccessibilityManager::ChangeAccessibilityStatus()
 {
   AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
@@ -709,10 +701,7 @@ bool AccessibilityManager::ChangeAccessibilityStatus()
     Actor actor = GetCurrentFocusActor();
     if(actor)
     {
-      if(mFocusIndicatorActor)
-      {
-        actor.Add(mFocusIndicatorActor);
-      }
+      actor.Add( GetFocusIndicatorActor() );
     }
     mIsFocusIndicatorEnabled = true;
 
@@ -725,9 +714,9 @@ bool AccessibilityManager::ChangeAccessibilityStatus()
   {
     // Hide indicator when tts turned off
     Actor actor = GetCurrentFocusActor();
-    if(actor)
+    if( actor && mFocusIndicatorActor )
     {
-      actor.Remove(mFocusIndicatorActor);
+      actor.Remove( mFocusIndicatorActor );
     }
     mIsFocusIndicatorEnabled = false;
 
@@ -1251,19 +1240,6 @@ bool AccessibilityManager::AccessibilityActionZoom()
   return ret;
 }
 
-bool AccessibilityManager::AccessibilityActionReadIndicatorInformation()
-{
-  Dali::Toolkit::AccessibilityManager handle( this );
-  if( !mActionReadIndicatorInformationSignal.Empty() )
-  {
-    mActionReadIndicatorInformationSignal.Emit( handle );
-  }
-
-  // TODO: Read the information in the indicator
-
-  return mIsAccessibilityTtsEnabled;
-}
-
 bool AccessibilityManager::AccessibilityActionReadPauseResume()
 {
   Dali::Toolkit::AccessibilityManager handle( this );
@@ -1337,7 +1313,7 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent&
 
     if(!mCurrentGesturedActor)
     {
-      DALI_LOG_ERROR("Gesture detected, but no hit actor");
+      DALI_LOG_ERROR("Gesture detected, but no hit actor\n");
     }
   }
 
@@ -1386,7 +1362,7 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent&
 
       if(!mCurrentGesturedActor)
       {
-        DALI_LOG_ERROR("no more gestured actor");
+        DALI_LOG_ERROR("no more gestured actor\n");
       }
     }
     else
@@ -1414,34 +1390,6 @@ Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& AccessibilityMan
   return mFocusedActorActivatedSignal;
 }
 
-bool AccessibilityManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
-{
-  Dali::BaseHandle handle( object );
-
-  bool connected( true );
-  AccessibilityManager* manager = dynamic_cast<AccessibilityManager*>( object );
-
-  if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
-  {
-    manager->FocusChangedSignal().Connect( tracker, functor );
-  }
-  else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_OVERSHOT ) )
-  {
-    manager->FocusOvershotSignal().Connect( tracker, functor );
-  }
-  else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ACTIVATED ) )
-  {
-    manager->FocusedActorActivatedSignal().Connect( tracker, functor );
-  }
-  else
-  {
-    // signalName does not match any signal
-    connected = false;
-  }
-
-  return connected;
-}
-
 } // namespace Internal
 
 } // namespace Toolkit