/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
// EXTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
-#include <dali/public-api/images/resource-image.h>
#include <dali/devel-api/scripting/scripting.h>
#include <dali/public-api/object/property-array.h>
#include <dali/integration-api/debug.h>
// Toggle button requires the Leave event.
Actor self = Self();
- self.SetLeaveRequired( true );
+ 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::TOGGLE_BUTTON ) );
+ } );
}
void ToggleButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
}
case Toolkit::ToggleButton::Property::TOOLTIPS:
{
- Property::Array* tipArray = value.GetArray();
+ const Property::Array* tipArray = value.GetArray();
if( tipArray )
{
std::vector<std::string> tips;
RelayoutRequest();
}
+Dali::Accessibility::States ToggleButton::AccessibleImpl::CalculateStates()
+{
+ auto states = Button::AccessibleImpl::CalculateStates();
+ auto button = Toolkit::ToggleButton::DownCast( self );
+ if( button.GetProperty<int>( Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX ) )
+ states[Dali::Accessibility::State::CHECKED] = true;
+ return states;
+}
+
+std::string ToggleButton::AccessibleImpl::GetDescriptionRaw()
+{
+ auto button = Toolkit::ToggleButton::DownCast( self );
+ auto index = button.GetProperty<int>( Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX );
+ auto tooltips = button.GetProperty<Property::Array>( Toolkit::ToggleButton::Property::TOOLTIPS );
+
+ return tooltips[index].Get<std::string>();
+}
+
+Property::Index ToggleButton::AccessibleImpl::GetDescriptionPropertyIndex()
+{
+ return Toolkit::ToggleButton::Property::TOOLTIPS;
+}
+
+void ToggleButton::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::CHECKED, mCurrentToggleIndex ? 1 : 0, 0
+ );
+
+ if(Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
+ {
+ Dali::Accessibility::Accessible::Get(Self())->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+ }
+ }
+}
+
} // namespace Internal
} // namespace Toolkit