/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
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::TOGGLE_BUTTON));
- });
+ self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::TOGGLE_BUTTON);
+}
+
+DevelControl::ControlAccessible* ToggleButton::CreateAccessibleObject()
+{
+ return new ToggleButtonAccessible(Self());
}
void ToggleButton::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value)
std::vector<std::string> tips;
size_t tipsCount = tipArray->Count();
tips.resize(tipsCount);
+
+ bool valid = true;
for(size_t i = 0; i != tipsCount; ++i)
{
- tipArray->GetElementAt(i).Get(tips[i]);
+ if(DALI_UNLIKELY(!tipArray->GetElementAt(i).Get(tips[i])))
+ {
+ // Given array is invalid. Fast out.
+ valid = false;
+ break;
+ }
+ }
+
+ if(DALI_LIKELY(valid))
+ {
+ toggleButtonImpl.SetToggleTooltips(tips);
}
- toggleButtonImpl.SetToggleTooltips(tips);
}
break;
}
{
case Toolkit::ToggleButton::Property::STATE_VISUALS:
{
- Property::Array array = toggleButtonImpl.GetToggleStates();
- value = Property::Value(array);
+ value = toggleButtonImpl.GetToggleStates();
break;
}
case Toolkit::ToggleButton::Property::TOOLTIPS:
DevelControl::UnregisterVisual(*this, index);
}
- DevelControl::RegisterVisual(*this, index, visual, enabled);
+ DevelControl::RegisterVisual(*this, index, visual, enabled, DepthIndex::CONTENT);
}
void ToggleButton::RelayoutVisual(Property::Index index, const Vector2& size)
{
DALI_LOG_INFO(gLogButtonFilter, Debug::General, "ToggleButton::OnPressed\n");
// State index will add 1 only when button is pressed.
- mCurrentToggleIndex = (mCurrentToggleIndex + 1) % mToggleVisuals.size();
+ mCurrentToggleIndex = (mCurrentToggleIndex + 1) % static_cast<uint32_t>(mToggleVisuals.size());
// Both create SelectedVisual and UnselectedVisual
PrepareVisual(Toolkit::Button::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex]);
RelayoutRequest();
}
-Dali::Accessibility::States ToggleButton::AccessibleImpl::CalculateStates()
+Dali::Accessibility::States ToggleButton::ToggleButtonAccessible::CalculateStates()
{
- auto states = Button::AccessibleImpl::CalculateStates();
+ auto states = Button::ButtonAccessible::CalculateStates();
auto button = Toolkit::ToggleButton::DownCast(Self());
if(button.GetProperty<int>(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX))
{
return states;
}
-std::string ToggleButton::AccessibleImpl::GetDescriptionRaw()
+std::string ToggleButton::ToggleButtonAccessible::GetDescriptionRaw() const
{
auto button = Toolkit::ToggleButton::DownCast(Self());
auto index = button.GetProperty<int>(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX);
return tooltips[index].Get<std::string>();
}
-Property::Index ToggleButton::AccessibleImpl::GetDescriptionPropertyIndex()
+Property::Index ToggleButton::ToggleButtonAccessible::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() && (Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
- && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
+ if(newState == SELECTED_STATE || newState == UNSELECTED_STATE)
{
- Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(Dali::Accessibility::State::CHECKED, mCurrentToggleIndex ? 1 : 0, 0);
- Dali::Accessibility::Accessible::Get(Self())->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+ auto accessible = GetAccessibleObject();
+ if(DALI_LIKELY(accessible) && accessible->IsHighlighted())
+ {
+ accessible->EmitStateChanged(Dali::Accessibility::State::CHECKED, mCurrentToggleIndex ? 1 : 0, 0);
+ accessible->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+ }
}
}