[AT-SPI] EmitStateChanged for togglable PushButton
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.cpp
index d09f781..2fadac4 100644 (file)
@@ -99,6 +99,11 @@ void PushButton::OnInitialize()
   // Push button requires the Leave event.
   Actor self = Self();
   self.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
+
+  DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) {
+    return std::unique_ptr< Dali::Accessibility::Accessible >(
+        new AccessibleImpl( actor, Dali::Accessibility::Role::PUSH_BUTTON ) );
+  } );
 }
 
 void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment )
@@ -194,6 +199,32 @@ Property::Value PushButton::GetProperty( BaseObject* object, Property::Index pro
   return value;
 }
 
+Dali::Accessibility::States PushButton::AccessibleImpl::CalculateStates()
+{
+  auto tmp = Button::AccessibleImpl::CalculateStates();
+  auto slf = Toolkit::Button::DownCast( self );
+  tmp[Dali::Accessibility::State::PRESSED] = slf.GetProperty<bool>( Toolkit::Button::Property::SELECTED );
+  return tmp;
+}
+
+void PushButton::OnStateChange( State newState )
+{
+  // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
+  if (Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
+  {
+    Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
+      Dali::Accessibility::State::PRESSED, newState == SELECTED_STATE ? 1 : 0, 0
+    );
+
+    if (Self().GetProperty<bool>(Toolkit::Button::Property::TOGGLABLE))
+    {
+      Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
+        Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0
+      );
+    }
+  }
+}
+
 } // namespace Internal
 
 } // namespace Toolkit