[Tizen] Be a bit smarter with SetFocusedActorPosition
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / accessibility-manager / accessibility-manager-impl.cpp
index 3a23214..e856ec2 100644 (file)
@@ -175,6 +175,15 @@ void AccessibilityManager::SetAccessibilityAttribute(Actor actor, Toolkit::Acces
   }
 }
 
+void AccessibilityManager::DeleteAccessibilityAttribute(Actor actor)
+{
+  if(actor)
+  {
+    unsigned int actorID = actor.GetProperty< int >( Actor::Property::ID );
+    mIDAdditionalInfoContainer.erase(actorID);
+  }
+}
+
 std::string AccessibilityManager::GetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type) const
 {
   std::string text;
@@ -351,6 +360,24 @@ bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID)
         actor.Add( GetFocusIndicatorActor() );
       }
 
+      auto adaptor = AccessibilityAdaptor::Get();
+      Vector2 readPosition = adaptor.GetReadPosition();
+      auto actorPosition = actor.GetCurrentProperty<Vector2>(Actor::Property::SCREEN_POSITION);
+      auto actorSize = actor.GetCurrentProperty<Vector2>(Actor::Property::SIZE);
+      Rect<> actorRect(actorPosition.x, actorPosition.y, actorSize.width, actorSize.height);
+
+      if(actorRect.Contains(Rect<>(readPosition.x, readPosition.y, 0, 0)))
+      {
+        // If the last touched position is within the extents of the actor,
+        // then use that position. (The center may be covered by some other actor).
+        adaptor.SetFocusedActorPosition(readPosition);
+      }
+      else
+      {
+        // Otherwise, use the center point.
+        adaptor.SetFocusedActorPosition(actorPosition + actorSize / 2);
+      }
+
       // Send notification for the change of focus actor
       mFocusChangedSignal.Emit( GetCurrentFocusActor(), actor );
 
@@ -560,6 +587,7 @@ Vector2 AccessibilityManager::GetReadPosition() const
 
 void AccessibilityManager::EnableAccessibility(bool enabled)
 {
+  DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Set Enabled Forcibly : %d \n", __FUNCTION__, __LINE__, enabled );
   AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
   adaptor.EnableAccessibility(enabled);
 }
@@ -727,6 +755,8 @@ bool AccessibilityManager::ChangeAccessibilityStatus()
   mIsAccessibilityTtsEnabled = adaptor.IsEnabled();
   Dali::Toolkit::AccessibilityManager handle( this );
 
+  DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] TtsEnabled : %d \n", __FUNCTION__, __LINE__, mIsAccessibilityTtsEnabled );
+
   if(mIsAccessibilityTtsEnabled)
   {
     // Show indicator when tts turned on if there is focused actor.
@@ -1315,6 +1345,17 @@ bool AccessibilityManager::AccessibilityActionStartStop()
   return mIsAccessibilityTtsEnabled;
 }
 
+bool AccessibilityManager::AccessibilityActionForwardToApp()
+{
+  Dali::Toolkit::AccessibilityManager handle( this );
+  if( !mActionForwardSignal.Empty() )
+  {
+    mActionForwardSignal.Emit( handle );
+  }
+
+  return mIsAccessibilityTtsEnabled;
+}
+
 bool AccessibilityManager::HandlePanGesture(const AccessibilityGestureEvent& panEvent)
 {
   bool handled = false;
@@ -1349,7 +1390,11 @@ bool AccessibilityManager::HandlePanGesture(const AccessibilityGestureEvent& pan
   DevelPanGesture::SetNumberOfTouches( pan, panEvent.numberOfTouches  );
   DevelPanGesture::SetScreenPosition( pan, panEvent.currentPosition );
   DevelPanGesture::SetScreenDisplacement( pan, mPreviousPosition - panEvent.currentPosition );
-  DevelPanGesture::SetScreenVelocity( pan, Vector2( pan.GetScreenDisplacement().x / panEvent.timeDelta, pan.GetScreenDisplacement().y / panEvent.timeDelta ) );
+  // Avoid dividing by 0
+  if(panEvent.timeDelta > 0)
+  {
+    DevelPanGesture::SetScreenVelocity( pan, Vector2( pan.GetScreenDisplacement().x / panEvent.timeDelta, pan.GetScreenDisplacement().y / panEvent.timeDelta ) );
+  }
 
   // Only handle the pan gesture when the current focused actor is scrollable or within a scrollable actor
   while(mCurrentGesturedActor && mCurrentGesturedActor != rootActor && !handled)
@@ -1365,7 +1410,11 @@ bool AccessibilityManager::HandlePanGesture(const AccessibilityGestureEvent& pan
       control.ScreenToLocal( localPrevious.x, localPrevious.y, mPreviousPosition.x, mPreviousPosition.y );
 
       DevelPanGesture::SetDisplacement( pan, localCurrent - localPrevious );
-      DevelPanGesture::SetVelocity( pan, Vector2( pan.GetDisplacement().x / panEvent.timeDelta, pan.GetDisplacement().y / panEvent.timeDelta ));
+      // Avoid dividing by 0
+      if(panEvent.timeDelta > 0)
+      {
+        DevelPanGesture::SetVelocity( pan, Vector2( pan.GetDisplacement().x / panEvent.timeDelta, pan.GetDisplacement().y / panEvent.timeDelta ));
+      }
 
       handled = GetImplementation( control ).OnAccessibilityPan(pan);
     }