X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Ftoggle-button-impl.cpp;h=a756a22e71796395bc6386cdf7e615c586b845c0;hp=0ecae06eb5c1f61564da2d555bbe900bd109556c;hb=e3d6a0a27fd980a4ced6e7257abdc32bc192e871;hpb=ca4209fb071e5c353a7e528098a2e497765118d8 diff --git a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp old mode 100755 new mode 100644 index 0ecae06..a756a22 --- 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) 2017 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. @@ -21,7 +21,6 @@ // EXTERNAL INCLUDES #include #include -#include #include #include #include @@ -30,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -111,7 +109,12 @@ void ToggleButton::OnInitialize() // 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 ) @@ -138,7 +141,7 @@ void ToggleButton::SetProperty( BaseObject* object, Property::Index propertyInde } case Toolkit::ToggleButton::Property::TOOLTIPS: { - Property::Array* tipArray = value.GetArray(); + const Property::Array* tipArray = value.GetArray(); if( tipArray ) { std::vector tips; @@ -267,10 +270,10 @@ void ToggleButton::SetToggleStates( const Property::Array& states ) DALI_LOG_INFO( gLogButtonFilter, Debug::General, "ToggleButton::Began to register visual.\n" ); - PrepareVisual( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex] ); - PrepareVisual( Toolkit::DevelButton::Property::SELECTED_VISUAL, mToggleSelectedVisuals[mCurrentToggleIndex] ); - PrepareVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL, mToggleDisabledVisuals[mCurrentToggleIndex] ); - PrepareVisual( Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL, mToggleDisabledSelectedVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::SELECTED_VISUAL, mToggleSelectedVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, mToggleDisabledVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, mToggleDisabledSelectedVisuals[mCurrentToggleIndex] ); RelayoutRequest(); } @@ -305,8 +308,17 @@ const std::vector& ToggleButton::GetToggleTooltips() const void ToggleButton::PrepareVisual(Property::Index index, Toolkit::Visual::Base& visual) { - DevelControl::RegisterVisual( *this, index, visual, true ); - DevelControl::EnableVisual( *this, index, false ); + bool enabled = false; // Disabled by default + + // Unregister the visual with the given index if registered previously + if( DevelControl::GetVisual( *this, index ) ) + { + // Check whether it was enabled to ensure we do the same with the new visual we're registering + enabled = DevelControl::IsVisualEnabled( *this, index ); + DevelControl::UnregisterVisual( *this, index ); + } + + DevelControl::RegisterVisual( *this, index, visual, enabled ); } void ToggleButton::RelayoutVisual( Property::Index index, const Vector2& size ) @@ -338,10 +350,10 @@ void ToggleButton::OnRelayout( const Vector2& size, RelayoutContainer& container { DALI_LOG_INFO( gLogButtonFilter, Debug::General, "ToggleButton::OnRelayout targetSize(%f,%f) ptr(%p)\n", size.width, size.height, this ); - RelayoutVisual( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, size ); - RelayoutVisual( Toolkit::DevelButton::Property::SELECTED_VISUAL, size ); - RelayoutVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL, size ); - RelayoutVisual( Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL, size ); + RelayoutVisual( Toolkit::Button::Property::UNSELECTED_VISUAL, size ); + RelayoutVisual( Toolkit::Button::Property::SELECTED_VISUAL, size ); + RelayoutVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, size ); + RelayoutVisual( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, size ); } void ToggleButton::OnPressed() @@ -351,10 +363,10 @@ void ToggleButton::OnPressed() mCurrentToggleIndex = ( mCurrentToggleIndex + 1 ) % mToggleVisuals.size(); // Both create SelectedVisual and UnselectedVisual - PrepareVisual( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex] ); - PrepareVisual( Toolkit::DevelButton::Property::SELECTED_VISUAL, mToggleSelectedVisuals[mCurrentToggleIndex] ); - PrepareVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL, mToggleDisabledVisuals[mCurrentToggleIndex] ); - PrepareVisual( Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL, mToggleDisabledSelectedVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::SELECTED_VISUAL, mToggleSelectedVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, mToggleDisabledVisuals[mCurrentToggleIndex] ); + PrepareVisual( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, mToggleDisabledSelectedVisuals[mCurrentToggleIndex] ); //Need to check mCurrentToggleIndex, it must less than the size of mToggleTooltips. if ( !mToggleTooltips.empty() && ( mCurrentToggleIndex < mToggleTooltips.size() ) ) @@ -365,6 +377,45 @@ void ToggleButton::OnPressed() RelayoutRequest(); } +Dali::Accessibility::States ToggleButton::AccessibleImpl::CalculateStates() +{ + auto states = Button::AccessibleImpl::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() +{ + 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() +{ + 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