Stop observing visuals when a control is destroyed
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / control / control-data-impl.cpp
index b498259..9182c1f 100755 (executable)
@@ -189,71 +189,64 @@ void MoveVisual( RegisteredVisualContainer::Iterator sourceIter, RegisteredVisua
  * @param[in] attributes The attributes with which to perfrom this action.
  * @return true if action has been accepted by this control
  */
-const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
-const char* ACTION_ACCESSIBILITY_READING_SKIPPED = "ReadingSkipped";
+const char* ACTION_ACCESSIBILITY_ACTIVATED         = "accessibilityActivated";
 const char* ACTION_ACCESSIBILITY_READING_CANCELLED = "ReadingCancelled";
-const char* ACTION_ACCESSIBILITY_READING_STOPPED = "ReadingStopped";
+const char* ACTION_ACCESSIBILITY_READING_PAUSED    = "ReadingPaused";
+const char* ACTION_ACCESSIBILITY_READING_RESUMED   = "ReadingResumed";
+const char* ACTION_ACCESSIBILITY_READING_SKIPPED   = "ReadingSkipped";
+const char* ACTION_ACCESSIBILITY_READING_STOPPED   = "ReadingStopped";
 
 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
 {
-  bool ret = false;
+  bool ret = true;
 
-  if( object &&
-      ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ||
-        actionName == "activate" ) )
+  Dali::BaseHandle handle( object );
+
+  Toolkit::Control control = Toolkit::Control::DownCast( handle );
+
+  DALI_ASSERT_ALWAYS( control );
+
+  if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ||
+     actionName == "activate" )
   {
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-    if( control )
-    {
-      // if cast succeeds there is an implementation so no need to check
-      if (!DevelControl::AccessibilityActivateSignal( control ).Empty()) {
-        DevelControl::AccessibilityActivateSignal( control ).Emit();
-        ret = true;
-      }
-      else
-        ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
-    }
+    // if cast succeeds there is an implementation so no need to check
+    if( !DevelControl::AccessibilityActivateSignal( control ).Empty() )
+      DevelControl::AccessibilityActivateSignal( control ).Emit();
+    else ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
   }
-  else if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_SKIPPED ) ) )
+  else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_SKIPPED ) )
   {
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-    if( control )
-    {
-      // if cast succeeds there is an implementation so no need to check
-      if (!DevelControl::AccessibilityReadingSkippedSignal( control ).Empty())
-      {
-        DevelControl::AccessibilityReadingSkippedSignal( control ).Emit();
-        ret = true;
-      }
-    }
+    // if cast succeeds there is an implementation so no need to check
+    if( !DevelControl::AccessibilityReadingSkippedSignal( control ).Empty() )
+      DevelControl::AccessibilityReadingSkippedSignal( control ).Emit();
   }
-  else if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_CANCELLED ) ) )
+  else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_PAUSED ) )
   {
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-    if( control )
-    {
-      // if cast succeeds there is an implementation so no need to check
-      if (!DevelControl::AccessibilityReadingCancelledSignal( control ).Empty())
-      {
-        DevelControl::AccessibilityReadingCancelledSignal( control ).Emit();
-        ret = true;
-      }
-    }
+    // if cast succeeds there is an implementation so no need to check
+    if( !DevelControl::AccessibilityReadingPausedSignal( control ).Empty() )
+      DevelControl::AccessibilityReadingPausedSignal( control ).Emit();
   }
-  else if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_STOPPED ) ) )
+  else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_RESUMED ) )
   {
-    Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-    if( control )
-    {
-      // if cast succeeds there is an implementation so no need to check
-      if (!DevelControl::AccessibilityReadingStoppedSignal( control ).Empty())
-      {
-        DevelControl::AccessibilityReadingStoppedSignal( control ).Emit();
-        ret = true;
-      }
-    }
+    // if cast succeeds there is an implementation so no need to check
+    if( !DevelControl::AccessibilityReadingResumedSignal( control ).Empty() )
+      DevelControl::AccessibilityReadingResumedSignal( control ).Emit();
+  }
+  else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_CANCELLED ) )
+  {
+    // if cast succeeds there is an implementation so no need to check
+    if( !DevelControl::AccessibilityReadingCancelledSignal( control ).Empty() )
+      DevelControl::AccessibilityReadingCancelledSignal( control ).Emit();
+  }
+  else if( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_READING_STOPPED ) )
+  {
+    // if cast succeeds there is an implementation so no need to check
+    if(!DevelControl::AccessibilityReadingStoppedSignal( control ).Empty())
+      DevelControl::AccessibilityReadingStoppedSignal( control ).Emit();
+  } else
+  {
+    ret = false;
   }
-
   return ret;
 }
 
@@ -364,6 +357,8 @@ TypeAction registerAction2( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &D
 TypeAction registerAction3( typeRegistration, ACTION_ACCESSIBILITY_READING_SKIPPED, &DoAction );
 TypeAction registerAction4( typeRegistration, ACTION_ACCESSIBILITY_READING_CANCELLED, &DoAction );
 TypeAction registerAction5( typeRegistration, ACTION_ACCESSIBILITY_READING_STOPPED, &DoAction );
+TypeAction registerAction6( typeRegistration, ACTION_ACCESSIBILITY_READING_PAUSED, &DoAction );
+TypeAction registerAction7( typeRegistration, ACTION_ACCESSIBILITY_READING_RESUMED, &DoAction );
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -464,6 +459,16 @@ Control::Impl::Impl( Control& controlImpl )
 
 Control::Impl::~Impl()
 {
+  for( auto&& iter : mVisuals )
+  {
+    StopObservingVisual( iter->visual );
+  }
+
+  for( auto&& iter : mRemoveVisuals )
+  {
+    StopObservingVisual( iter->visual );
+  }
+
   AccessibilityDeregister();
   // All gesture detectors will be destroyed so no need to disconnect.
   delete mStartingPinchScale;
@@ -1889,6 +1894,32 @@ Control::Impl::AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibil
   Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get( internalControl );
   if( controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN )
     controlImpl.mAccessibilityRole = role;
+
+  self.PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle &handle, Dali::Property::Index index, Dali::Property::Value value)
+  {
+    if (this->self != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
+    {
+      return;
+    }
+
+    if (index == DevelControl::Property::ACCESSIBILITY_NAME
+      || (index == GetNamePropertyIndex() && !controlImpl.mAccessibilityNameSet))
+    {
+      if (controlImpl.mAccessibilityGetNameSignal.Empty())
+      {
+        Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME);
+      }
+    }
+
+    if (index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION
+      || (index == GetDescriptionPropertyIndex() && !controlImpl.mAccessibilityDescriptionSet))
+    {
+      if (controlImpl.mAccessibilityGetDescriptionSignal.Empty())
+      {
+        Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+      }
+    }
+  });
 }
 
 std::string Control::Impl::AccessibleImpl::GetName()
@@ -1991,12 +2022,14 @@ Dali::Accessibility::States Control::Impl::AccessibleImpl::CalculateStates()
   s[Dali::Accessibility::State::ENABLED] = true;
   s[Dali::Accessibility::State::SENSITIVE] = true;
   s[Dali::Accessibility::State::ANIMATED] = self.GetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ANIMATED ).Get< bool >();
-  s[Dali::Accessibility::State::VISIBLE] = self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
+  s[Dali::Accessibility::State::VISIBLE] = true;
   if( modal )
   {
     s[Dali::Accessibility::State::MODAL] = true;
   }
-  s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >();
+  s[Dali::Accessibility::State::SHOWING] = !self.GetProperty( Dali::DevelActor::Property::CULLED ).Get< bool >()
+                                         && self.GetCurrentProperty< bool >( Actor::Property::VISIBLE );
+
   s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty( Dali::DevelActor::Property::CONNECTED_TO_SCENE ).Get< bool >();
   return s;
 }
@@ -2108,6 +2141,7 @@ bool Control::Impl::AccessibleImpl::GrabHighlight()
   highlight.SetProperty( Actor::Property::POSITION_Z, 1.0f );
   highlight.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
 
+  EnsureSelfVisible();
   self.Add( highlight );
   SetCurrentlyHighlightedActor( self );
   EmitHighlighted( true );
@@ -2131,11 +2165,6 @@ bool Control::Impl::AccessibleImpl::ClearHighlight()
   return false;
 }
 
-int Control::Impl::AccessibleImpl::GetHighlightIndex()
-{
-  return 0;
-}
-
 std::string Control::Impl::AccessibleImpl::GetActionName( size_t index )
 {
   if ( index >= GetActionCount() ) return "";
@@ -2211,6 +2240,29 @@ std::vector<Dali::Accessibility::Relation> Control::Impl::AccessibleImpl::GetRel
   return ret;
 }
 
+void Control::Impl::AccessibleImpl::EnsureChildVisible(Actor child)
+{
+}
+
+void Control::Impl::AccessibleImpl::EnsureSelfVisible()
+{
+  auto parent = dynamic_cast<Control::Impl::AccessibleImpl*>(GetParent());
+  if (parent)
+  {
+    parent->EnsureChildVisible(self);
+  }
+}
+
+Property::Index Control::Impl::AccessibleImpl::GetNamePropertyIndex()
+{
+  return Actor::Property::NAME;
+}
+
+Property::Index Control::Impl::AccessibleImpl::GetDescriptionPropertyIndex()
+{
+  return Property::INVALID_INDEX;
+}
+
 void Control::Impl::PositionOrSizeChangedCallback( PropertyNotification &p )
 {
   auto self = Dali::Actor::DownCast(p.GetTarget());