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=103992f1a7995640cc269c7123ddb66c0127b638;hp=0da7949571a7f01d61f6488c357444868ae222e1;hb=f546dd5d83a968e573f8f053a01ce43df32c71a0;hpb=2ec164cd618f93ccafe17b1d0b8ff16401ed4aef 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 0da7949..103992f 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) 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. @@ -19,9 +19,19 @@ #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 { @@ -34,13 +44,6 @@ namespace Internal namespace { -const float FOREGROUND_DEPTH( 0.5f ); -const float BACKGROUND_DEPTH( 0.25f ); - -const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time - -const Vector3 DISTANCE_BETWEEN_IMAGE_AND_LABEL(5.0f, 0.0f, 0.0f); - BaseHandle Create() { return Toolkit::CheckBoxButton::New(); @@ -48,6 +51,8 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); + + } Dali::Toolkit::CheckBoxButton CheckBoxButton::New() @@ -66,402 +71,45 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New() } CheckBoxButton::CheckBoxButton() -: Button(), - mPaintState( UnselectedState ) +: Button() { SetTogglableButton( true ); - - SetAnimationTime( ANIMATION_TIME ); } CheckBoxButton::~CheckBoxButton() { - if( mCheckInAnimation ) - { - mCheckInAnimation.Clear(); - } -} - -void CheckBoxButton::OnButtonInitialize() -{ - // Wrap around all children - Self().SetResizePolicy( FIT_TO_CHILDREN, ALL_DIMENSIONS ); -} - -void CheckBoxButton::SetSelectedImage( Actor image ) -{ - Actor& selectedImage = GetSelectedImage(); - - switch( mPaintState ) - { - case SelectedState: - { - if( selectedImage && selectedImage.GetParent() ) - { - Self().Remove( selectedImage ); - } - - selectedImage = image; - Self().Add( selectedImage ); - break; - } - case UnselectedSelectedTransition: - { - StopCheckInAnimation(); - Self().Remove( selectedImage ); - - selectedImage = image; - Self().Add( selectedImage ); - - mPaintState = SelectedState; - break; - } - default: - { - selectedImage = image; - break; - } - } - - selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - selectedImage.SetZ( FOREGROUND_DEPTH ); -} - -void CheckBoxButton::SetBackgroundImage( Actor image ) -{ - Actor& backgroundImage = GetBackgroundImage(); - - switch( mPaintState ) - { - case UnselectedState: // FALLTHROUGH - case SelectedState: - case UnselectedSelectedTransition: - { - if( backgroundImage && backgroundImage.GetParent() ) - { - Self().Remove( backgroundImage ); - - Actor& label = GetLabel(); - - if( label ) - { - backgroundImage.Remove( label ); - image.Add( label ); - } - } - - backgroundImage = image; - Self().Add( backgroundImage ); - break; - } - default: - { - backgroundImage = image; - break; - } - } - - backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - backgroundImage.SetZ( BACKGROUND_DEPTH ); } -void CheckBoxButton::SetDisabledSelectedImage( Actor image ) +void CheckBoxButton::OnInitialize() { - Actor& disabledSelectedImage = GetDisabledSelectedImage(); + Button::OnInitialize(); - switch( mPaintState ) - { - case DisabledSelectedState: - { - if( disabledSelectedImage && disabledSelectedImage.GetParent() ) - { - Self().Remove( disabledSelectedImage ); - } - - disabledSelectedImage = image; - Self().Add( disabledSelectedImage ); - break; - } - default: - { - disabledSelectedImage = image; - break; - } - } - - disabledSelectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - disabledSelectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - disabledSelectedImage.SetZ( FOREGROUND_DEPTH ); + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new AccessibleImpl( actor, Dali::Accessibility::Role::CHECK_BOX ) ); + } ); } -void CheckBoxButton::SetDisabledBackgroundImage( Actor image ) +Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates() { - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - - switch( mPaintState ) - { - case DisabledSelectedState: - case DisabledUnselectedState: - { - if( disabledBackgroundImage && disabledBackgroundImage.GetParent() ) - { - Self().Remove( disabledBackgroundImage ); - - Actor& label = GetLabel(); - - if( label ) - { - disabledBackgroundImage.Remove( label ); - image.Add( label ); - } - } - - disabledBackgroundImage = image; - Self().Add( disabledBackgroundImage ); - break; - } - default: - { - disabledBackgroundImage = image; - break; - } - } - - disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - disabledBackgroundImage.SetZ( BACKGROUND_DEPTH ); + auto tmp = Button::AccessibleImpl::CalculateStates(); + auto slf = Toolkit::Button::DownCast( self ); + if( slf.GetProperty( Toolkit::Button::Property::SELECTED ) ) + tmp[Dali::Accessibility::State::CHECKED] = true; + return tmp; } -void CheckBoxButton::OnLabelSet() +void CheckBoxButton::OnStateChange( State newState ) { - Actor& label = GetLabel(); - - if( label ) + // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used + if (Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE)) { - label.SetParentOrigin( ParentOrigin::CENTER_RIGHT ); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - label.TranslateBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - - if( IsDisabled() && GetDisabledBackgroundImage() ) - { - GetDisabledBackgroundImage().Add( label ); - } - else if ( GetBackgroundImage() ) - { - GetBackgroundImage().Add( label ); - } - else - { - Self().Add( label ); - } + Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged( + Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0 + ); } } -void CheckBoxButton::OnSelected( bool selected ) -{ - Actor& selectedImage = GetSelectedImage(); - - switch( mPaintState ) - { - case UnselectedState: - { - AddChild( selectedImage ); - StartCheckInAnimation( selectedImage ); // Animate in the check actor - - mPaintState = UnselectedSelectedTransition; - break; - } - case SelectedState: - { - RemoveChild( selectedImage ); - - mPaintState = UnselectedState; - break; - } - case UnselectedSelectedTransition: - { - StopCheckInAnimation(); - RemoveChild( selectedImage ); - - mPaintState = UnselectedState; - break; - } - default: - break; - } -} - -void CheckBoxButton::OnDisabled( bool disabled ) -{ - Actor& backgroundImage = GetBackgroundImage(); - Actor& selectedImage = GetSelectedImage(); - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - Actor& disabledSelectedImage = GetDisabledSelectedImage(); - - switch( mPaintState ) - { - case UnselectedState: - { - if( disabled ) - { - RemoveChild( backgroundImage ); - AddChild( disabledBackgroundImage ); - mPaintState = DisabledUnselectedState; - } - break; - } - case SelectedState: - { - if( disabled ) - { - RemoveChild( backgroundImage ); - RemoveChild( selectedImage ); - AddChild( disabledBackgroundImage ); - AddChild( disabledSelectedImage ); - - mPaintState = DisabledSelectedState; - } - break; - } - case DisabledUnselectedState: - { - if( !disabled ) - { - RemoveChild( disabledBackgroundImage ); - AddChild( backgroundImage ); - - mPaintState = UnselectedState; - } - break; - } - case DisabledSelectedState: - { - if( !disabled ) - { - RemoveChild( disabledBackgroundImage ); - RemoveChild( disabledSelectedImage ); - AddChild( backgroundImage ); - AddChild( selectedImage ); - - mPaintState = SelectedState; - } - break; - } - case UnselectedSelectedTransition: - { - if( disabled ) - { - StopCheckInAnimation(); - - RemoveChild( backgroundImage ); - RemoveChild( selectedImage ); - AddChild( disabledBackgroundImage ); - AddChild( disabledSelectedImage ); - - mPaintState = DisabledSelectedState; - } - break; - } - default: - break; - } - - Actor& label = GetLabel(); - - if( label ) - { - if( label.GetParent() ) - { - label.GetParent().Remove( label ); - } - - if( disabled && disabledBackgroundImage) - { - disabledBackgroundImage.Add( label ); - } - else if( backgroundImage ) - { - backgroundImage.Add( label ); - } - } -} - -void CheckBoxButton::AddChild( Actor& actor ) -{ - if( actor ) - { - Self().Add( actor); - } -} - -void CheckBoxButton::RemoveChild( Actor& actor ) -{ - if( actor ) - { - Self().Remove( actor ); - } -} - -void CheckBoxButton::StartCheckInAnimation( Actor& actor ) -{ - if( actor ) - { - if( !mTickUVEffect ) - { - ImageActor imageActor = ImageActor::DownCast( actor ); - mTickUVEffect = ImageRegionEffect::New(); - imageActor.SetShaderEffect( mTickUVEffect ); - } - - actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); - - mTickUVEffect.SetBottomRight( Vector2( 0.0f, 1.0f ) ); - - if( !mCheckInAnimation ) - { - mCheckInAnimation = Dali::Animation::New( GetAnimationTime() ); - } - - // UV anim - mCheckInAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) ); - - // Actor size anim - mCheckInAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); - - mCheckInAnimation.FinishedSignal().Connect( this, &CheckBoxButton::CheckInAnimationFinished ); - mCheckInAnimation.Play(); - } -} - -void CheckBoxButton::StopCheckInAnimation() -{ - if( mCheckInAnimation ) - { - mCheckInAnimation.Clear(); - mCheckInAnimation.Reset(); - } -} - -void CheckBoxButton::CheckInAnimationFinished( Dali::Animation& source ) -{ - switch( mPaintState ) - { - case UnselectedSelectedTransition: - { - mPaintState = SelectedState; - break; - } - default: - { - break; - } - } - - StopCheckInAnimation(); -} - } // namespace Internal } // namespace Toolkit