Merge "Add ApplyCustomFragmentPrefix" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / check-box-button-impl.cpp
index 88e5364..98733ea 100644 (file)
@@ -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.
 #include "check-box-button-impl.h"
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/actors/image-actor.h>
+#include <dali/integration-api/debug.h>
 #include <dali/public-api/object/type-registry.h>
 
+//INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
+#include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
+
+#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);
 
-}
+} // namespace
 
 Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
 {
   // Create the implementation, temporarily owned on stack
-  IntrusivePtr< CheckBoxButton > internalCheckBoxButton = new CheckBoxButton();
+  IntrusivePtr<CheckBoxButton> 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...
@@ -64,213 +66,42 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
 CheckBoxButton::CheckBoxButton()
 : Button()
 {
-  SetTogglableButton( true );
-
-  SetAnimationTime( ANIMATION_TIME );
+  SetTogglableButton(true);
 }
 
 CheckBoxButton::~CheckBoxButton()
 {
-  if( mTransitionAnimation )
-  {
-    mTransitionAnimation.Clear();
-  }
 }
 
-void CheckBoxButton::OnButtonInitialize()
+void CheckBoxButton::OnInitialize()
 {
-  // Wrap around all children
-  Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
-}
-
-void CheckBoxButton::OnLabelSet()
-{
-  Actor& label = GetLabel();
-
-  if( label )
-  {
-    label.SetParentOrigin( ParentOrigin::CENTER_LEFT );
-    label.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+  Button::OnInitialize();
 
-    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
-    {
-      label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
-    }
-  }
+  DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
+    return std::unique_ptr<Dali::Accessibility::Accessible>(
+      new AccessibleImpl(actor, Dali::Accessibility::Role::CHECK_BOX));
+  });
 }
 
-bool CheckBoxButton::OnSelected()
+Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates()
 {
-  Actor& selectedImage = GetSelectedImage();
-
-  PaintState paintState = GetPaintState();
-
-  switch( paintState )
+  auto state = Button::AccessibleImpl::CalculateStates();
+  auto self = Toolkit::Button::DownCast(Self());
+  if(self.GetProperty<bool>(Toolkit::Button::Property::SELECTED))
   {
-    case UnselectedState:
-    {
-      StartTransitionAnimation( selectedImage );
-      break;
-    }
-    case SelectedState:
-    {
-      RemoveChild( selectedImage );
-      break;
-    }
-    case UnselectedSelectedTransition:
-    {
-      StopTransitionAnimation( false );
-      RemoveChild( selectedImage );
-      break;
-    }
-    default:
-    {
-      break;
-    }
+    state[Dali::Accessibility::State::CHECKED] = true;
   }
-
-  if( mTransitionAnimation )
-  {
-    return true;
-  }
-
-  return false;
+  return state;
 }
 
-bool CheckBoxButton::OnDisabled()
+void CheckBoxButton::OnStateChange(State newState)
 {
-  Actor& backgroundImage = GetBackgroundImage();
-  Actor& selectedImage = GetSelectedImage();
-  Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
-  Actor& disabledSelectedImage = GetDisabledSelectedImage();
-
-  PaintState paintState = GetPaintState();
-
-  switch( paintState )
-  {
-    case UnselectedState:
-    {
-      RemoveChild( backgroundImage );
-      break;
-    }
-    case SelectedState:
-    {
-      RemoveChild( backgroundImage );
-      RemoveChild( selectedImage );
-      break;
-    }
-    case DisabledUnselectedState:
-    {
-      RemoveChild( disabledBackgroundImage );
-      break;
-    }
-    case DisabledSelectedState:
-    {
-      RemoveChild( disabledBackgroundImage );
-      RemoveChild( disabledSelectedImage );
-      break;
-    }
-    case UnselectedSelectedTransition:
-    {
-      StopTransitionAnimation();
-
-      RemoveChild( backgroundImage );
-      RemoveChild( selectedImage );
-      break;
-    }
-    default:
-    {
-      break;
-    }
-  }
-
-  Actor& label = GetLabel();
-
-  if( label )
+  // 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( 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
-    {
-      label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL );
-    }
+    Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0);
   }
-
-  if( mTransitionAnimation )
-  {
-    return true;
-  }
-
-  return false;
-}
-
-void CheckBoxButton::StopAllAnimations()
-{
-  StopTransitionAnimation();
-}
-
-void CheckBoxButton::StartTransitionAnimation( 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( !mTransitionAnimation )
-    {
-      mTransitionAnimation = Dali::Animation::New( GetAnimationTime()  );
-    }
-
-    // UV anim
-    mTransitionAnimation.AnimateTo( Property( mTickUVEffect, mTickUVEffect.GetBottomRightPropertyName() ), Vector2( 1.0f, 1.0f ) );
-
-    // Actor size anim
-    mTransitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f );
-
-    mTransitionAnimation.FinishedSignal().Connect( this, &CheckBoxButton::TransitionAnimationFinished );
-    mTransitionAnimation.Play();
-  }
-}
-
-void CheckBoxButton::StopTransitionAnimation( bool remove )
-{
-  if( mTransitionAnimation )
-  {
-    mTransitionAnimation.Clear();
-    mTransitionAnimation.Reset();
-  }
-
-  if( remove )
-  {
-    UpdatePaintTransitionState();
-  }
-}
-
-void CheckBoxButton::TransitionAnimationFinished( Dali::Animation& source )
-{
-  StopTransitionAnimation();
 }
 
 } // namespace Internal