X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fcheck-box-button-impl.cpp;h=98733ea455dce629be2daabcee049ae7f3e6b075;hp=6607c5cda33109dd8e5aa64c41be72591206947c;hb=646440beeb663fc5efcccadeba73dd46016ed1b3;hpb=b98287f646f84cd33e9ffc725f43a562946d13c9 diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index 6607c5c..98733ea 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -19,49 +19,42 @@ #include "check-box-button-impl.h" // EXTERNAL INCLUDES +#include #include -#include //INTERNAL INCLUDES -#include #include #include +#include + +#if defined(DEBUG_ENABLED) +extern Debug::Filter* gLogButtonFilter; +#endif namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - -const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); -const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time - BaseHandle Create() { return Toolkit::CheckBoxButton::New(); } -TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); +TypeRegistration mType(typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create); -const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected.png"; -const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected.png"; -const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected-disabled.png"; -const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected-diabled.png"; -} +} // namespace Dali::Toolkit::CheckBoxButton CheckBoxButton::New() { // Create the implementation, temporarily owned on stack - IntrusivePtr< CheckBoxButton > internalCheckBoxButton = new CheckBoxButton(); + IntrusivePtr internalCheckBoxButton = new CheckBoxButton(); // Pass ownership to CustomActor - Dali::Toolkit::CheckBoxButton checkBoxButton( *internalCheckBoxButton ); + Dali::Toolkit::CheckBoxButton checkBoxButton(*internalCheckBoxButton); // Second-phase init of the implementation // This can only be done after the CustomActor connection has been made... @@ -73,167 +66,41 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New() CheckBoxButton::CheckBoxButton() : Button() { - SetTogglableButton( true ); - - SetAnimationTime( ANIMATION_TIME ); + SetTogglableButton(true); } CheckBoxButton::~CheckBoxButton() { } -void CheckBoxButton::SetTickUVEffect() -{ - Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( mSelectedImage ); - if( imageView ) - { - imageView.RegisterProperty( "uTextureRect", Vector4(0.f, 0.f, 1.f, 1.f ) ); - imageView.RegisterProperty( "uTopLeft", Vector2::ZERO ); - - Property::Map shaderMap = CreateImageRegionEffect(); - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderMap ); - - GetImpl( imageView ).SetDepthIndex( DepthIndex::DECORATION ); - } -} - void CheckBoxButton::OnInitialize() { Button::OnInitialize(); - // Wrap around all children - Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - - SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); - SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); - SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); - SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); - - mSelectedImage = GetSelectedImage(); - SetTickUVEffect(); -} - -void CheckBoxButton::OnLabelSet( bool noPadding ) -{ - Actor& label = GetLabelActor(); - - if( label ) - { - label.SetParentOrigin( ParentOrigin::CENTER_LEFT ); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - - if( IsDisabled() && GetDisabledBackgroundImage() ) - { - label.SetX( GetDisabledBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if ( GetBackgroundImage() ) - { - label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( IsSelected() && GetSelectedImage()) - { - label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( GetUnselectedImage() ) - { - label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else - { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - } -} - -void CheckBoxButton::OnDisabled() -{ - Actor& backgroundImage = GetBackgroundImage(); - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - - Actor& label = GetLabelActor(); - if( label ) - { - if( IsDisabled() && disabledBackgroundImage ) - { - label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( backgroundImage ) - { - label.SetX( backgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( IsSelected() && GetSelectedImage()) - { - label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( GetUnselectedImage() ) - { - label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else - { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - } -} - -void CheckBoxButton::PrepareForTranstionIn( Actor actor ) -{ - Actor& selectedImage = GetSelectedImage(); - if( actor == selectedImage ) - { - actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); - actor.RegisterProperty( "uBottomRight", Vector2( 0.0f, 1.0f ) ); - - if( mSelectedImage != selectedImage ) - { - mSelectedImage = selectedImage; - SetTickUVEffect(); - } - } + DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) { + return std::unique_ptr( + new AccessibleImpl(actor, Dali::Accessibility::Role::CHECK_BOX)); + }); } -void CheckBoxButton::PrepareForTranstionOut( Actor actor ) +Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates() { - Actor& selectedImage = GetSelectedImage(); - if( actor == selectedImage ) + auto state = Button::AccessibleImpl::CalculateStates(); + auto self = Toolkit::Button::DownCast(Self()); + if(self.GetProperty(Toolkit::Button::Property::SELECTED)) { - actor.SetScale( Vector3::ONE ); - actor.RegisterProperty( "uBottomRight", Vector2::ONE ); - - if( mSelectedImage != selectedImage ) - { - mSelectedImage = selectedImage; - SetTickUVEffect(); - } + state[Dali::Accessibility::State::CHECKED] = true; } + return state; } -void CheckBoxButton::OnTransitionIn( Actor actor ) +void CheckBoxButton::OnStateChange(State newState) { - Actor& selectedImage = GetSelectedImage(); - if( actor && actor == selectedImage ) + // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used + if(Dali::Accessibility::IsUp() && (Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor() == Self()) + && (newState == SELECTED_STATE || newState == UNSELECTED_STATE)) { - if( GetPaintState() == UnselectedState ) - { - Dali::Animation transitionAnimation = GetTransitionAnimation(); - if( transitionAnimation ) - { - // UV anim - transitionAnimation.AnimateTo( Property( actor, "uBottomRight" ), Vector2::ONE ); - - // Actor size anim - transitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); - } - } - else - { - //explicitly end the swipe animation - actor.SetScale( Vector3::ONE ); - if( mSelectedImage == selectedImage ) - { - actor.RegisterProperty( "uBottomRight", Vector2::ONE ); - } - } + Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0); } }