X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Ftoggle-button-impl.cpp;h=1479e35fb164fcff8758a7306160cbb41ec55a15;hb=HEAD;hp=8ec931ffbe745d2a12dd31bcf3f6f99a57b54678;hpb=83f49e40397f82907ba6f0d2b7a39904c17d321c;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp index 8ec931f..5dd9b87 100644 --- a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -106,10 +106,12 @@ void ToggleButton::OnInitialize() Actor self = Self(); self.SetProperty(Actor::Property::LEAVE_REQUIRED, true); - DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) { - return std::unique_ptr( - 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) @@ -142,11 +144,22 @@ void ToggleButton::SetProperty(BaseObject* object, Property::Index propertyIndex std::vector 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; } @@ -174,8 +187,7 @@ Property::Value ToggleButton::GetProperty(BaseObject* object, Property::Index pr { case Toolkit::ToggleButton::Property::STATE_VISUALS: { - Property::Array array = toggleButtonImpl.GetToggleStates(); - value = Property::Value(array); + value = toggleButtonImpl.GetToggleStates(); break; } case Toolkit::ToggleButton::Property::TOOLTIPS: @@ -313,7 +325,7 @@ void ToggleButton::PrepareVisual(Property::Index index, Toolkit::Visual::Base& v 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) @@ -355,7 +367,7 @@ void ToggleButton::OnPressed() { 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(mToggleVisuals.size()); // Both create SelectedVisual and UnselectedVisual PrepareVisual(Toolkit::Button::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex]); @@ -372,25 +384,27 @@ void ToggleButton::OnPressed() RelayoutRequest(); } -Dali::Accessibility::States ToggleButton::AccessibleImpl::CalculateStates() +Dali::Accessibility::States ToggleButton::ToggleButtonAccessible::CalculateStates() { - auto states = Button::AccessibleImpl::CalculateStates(); - auto button = Toolkit::ToggleButton::DownCast(self); + auto states = Button::ButtonAccessible::CalculateStates(); + auto button = Toolkit::ToggleButton::DownCast(Self()); if(button.GetProperty(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX)) + { states[Dali::Accessibility::State::CHECKED] = true; + } return states; } -std::string ToggleButton::AccessibleImpl::GetDescriptionRaw() +std::string ToggleButton::ToggleButtonAccessible::GetDescriptionRaw() const { - auto button = Toolkit::ToggleButton::DownCast(self); + auto button = Toolkit::ToggleButton::DownCast(Self()); auto index = button.GetProperty(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX); auto tooltips = button.GetProperty(Toolkit::ToggleButton::Property::TOOLTIPS); return tooltips[index].Get(); } -Property::Index ToggleButton::AccessibleImpl::GetDescriptionPropertyIndex() +Property::Index ToggleButton::ToggleButtonAccessible::GetDescriptionPropertyIndex() { return Toolkit::ToggleButton::Property::TOOLTIPS; } @@ -398,12 +412,14 @@ Property::Index ToggleButton::AccessibleImpl::GetDescriptionPropertyIndex() 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); + } } }