Support mouse & wheel events in web view.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / check-box-button-impl.cpp
index c15c15e..3f4188b 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 <algorithm>
-#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 "check-box-button-default-painter-impl.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
 {
-
 BaseHandle Create()
 {
   return Toolkit::CheckBoxButton::New();
 }
 
-TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create );
-
-TypeAction a1(mType, Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK, &CheckBoxButton::DoAction);
+TypeRegistration mType(typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create);
 
-}
-
-namespace
-{
-  // Helper function used to cast a ButtonPainterPtr to CheckBoxButtonDefaultPainterPtr
-  CheckBoxButtonDefaultPainterPtr GetCheckBoxButtonPainter( ButtonPainterPtr painter )
-  {
-    return static_cast<CheckBoxButtonDefaultPainter*>( painter.Get() );
-  }
 } // 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...
@@ -73,195 +63,45 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
   return checkBoxButton;
 }
 
-void CheckBoxButton::SetChecked( bool checked )
-{
-  if( !mDisabled && ( checked != mChecked ) )
-  {
-    // Stores the state.
-    mChecked = checked;
-
-    Toolkit::CheckBoxButton handle( GetOwner() );
-
-    // Notifies the painter the checkbox has been checked.
-    GetCheckBoxButtonPainter( mPainter )->Checked( handle );
-
-    // Raise state changed signal
-    mStateChangedSignal.Emit( handle, mChecked );
-  }
-}
-
-bool CheckBoxButton::IsChecked() const
-{
-  return mChecked;
-}
-
-void CheckBoxButton::SetBackgroundImage( Image image )
-{
-  SetBackgroundImage( ImageActor::New( image ) );
-}
-
-void CheckBoxButton::SetBackgroundImage( Actor image )
-{
-  Toolkit::CheckBoxButton handle( GetOwner() );
-  GetCheckBoxButtonPainter( mPainter )->SetBackgroundImage( handle, image );
-}
-
-Actor& CheckBoxButton::GetBackgroundImage()
-{
-  return mBackgroundImage;
-}
-
-Actor CheckBoxButton::GetBackgroundImage() const
-{
-  return mBackgroundImage;
-}
-
-void CheckBoxButton::SetCheckedImage( Image image )
-{
-  SetCheckedImage( ImageActor::New( image ) );
-}
-
-void CheckBoxButton::SetCheckedImage( Actor image )
-{
-  Toolkit::CheckBoxButton handle( GetOwner() );
-  GetCheckBoxButtonPainter( mPainter )->SetCheckedImage( handle, image );
-}
-
-Actor& CheckBoxButton::GetCheckedImage()
-{
-  return mCheckedImage;
-}
-
-Actor CheckBoxButton::GetCheckedImage() const
-{
-  return mCheckedImage;
-}
-
-void CheckBoxButton::SetDisabledBackgroundImage( Image image )
-{
-  SetDisabledBackgroundImage( ImageActor::New( image ) );
-}
-
-void CheckBoxButton::SetDisabledBackgroundImage( Actor image )
-{
-  Toolkit::CheckBoxButton handle( GetOwner() );
-  GetCheckBoxButtonPainter( mPainter )->SetDisabledBackgroundImage( handle, image );
-}
-
-Actor& CheckBoxButton::GetDisabledBackgroundImage()
-{
-  return mDisabledBackgroundImage;
-}
-
-Actor CheckBoxButton::GetDisabledBackgroundImage() const
-{
-  return mDisabledBackgroundImage;
-}
-
-void CheckBoxButton::SetDisabledCheckedImage( Image image )
-{
-  SetDisabledCheckedImage( ImageActor::New( image ) );
-}
-
-void CheckBoxButton::SetDisabledCheckedImage( Actor image )
-{
-  Toolkit::CheckBoxButton handle( GetOwner() );
-  GetCheckBoxButtonPainter( mPainter )->SetDisabledCheckedImage( handle, image );
-}
-
-Actor& CheckBoxButton::GetDisabledCheckedImage()
-{
-  return mDisabledCheckedImage;
-}
-
-Actor CheckBoxButton::GetDisabledCheckedImage() const
-{
-  return mDisabledCheckedImage;
-}
-
-Actor& CheckBoxButton::GetFadeOutBackgroundImage()
-{
-  return mFadeOutBackgroundImage;
-}
-
-Actor& CheckBoxButton::GetFadeOutCheckedImage()
-{
-  return mFadeOutCheckedImage;
-}
-
-void CheckBoxButton::OnButtonInitialize()
+CheckBoxButton::CheckBoxButton()
+: Button()
 {
+  SetTogglableButton(true);
 }
 
-void CheckBoxButton::OnButtonUp()
+CheckBoxButton::~CheckBoxButton()
 {
-  if( ButtonDown == mState )
-  {
-    // Stores the state, notifies the painter and emits a signal.
-    SetChecked( !mChecked );
-  }
 }
 
-void CheckBoxButton::OnAnimationTimeSet( float animationTime )
+void CheckBoxButton::OnInitialize()
 {
-  GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime );
-}
+  Button::OnInitialize();
 
-float CheckBoxButton::OnAnimationTimeRequested() const
-{
-  return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime();
+  DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
+    return std::unique_ptr<Dali::Accessibility::Accessible>(
+      new AccessibleImpl(actor, Dali::Accessibility::Role::CHECK_BOX));
+  });
 }
 
-void CheckBoxButton::OnActivated()
+Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates()
 {
-  // When the button is activated, it performs the click action
-  PropertyValueContainer attributes;
-  DoClickAction(attributes);
+  auto tmp = Button::AccessibleImpl::CalculateStates();
+  auto slf = Toolkit::Button::DownCast(self);
+  if(slf.GetProperty<bool>(Toolkit::Button::Property::SELECTED))
+    tmp[Dali::Accessibility::State::CHECKED] = true;
+  return tmp;
 }
 
-void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes)
+void CheckBoxButton::OnStateChange(State newState)
 {
-  // Prevents the button signals from doing a recursive loop by sending an action
-  // and re-emitting the signals.
-  if(!mClickActionPerforming)
+  // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
+  if(Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
   {
-    mClickActionPerforming = true;
-    SetChecked( !mChecked );
-    mClickActionPerforming = false;
+    Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
+      Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0);
   }
 }
 
-bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
-{
-  bool ret = false;
-
-  Dali::BaseHandle handle(object);
-
-  Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle);
-
-  if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName)
-  {
-    GetImplementation(button).DoClickAction(attributes);
-    ret = true;
-  }
-
-  return ret;
-}
-
-CheckBoxButton::CheckBoxButton()
-: Button(),
-  mChecked( false ),
-  mClickActionPerforming(false)
-{
-  // Creates specific painter.
-  mPainter = new CheckBoxButtonDefaultPainter();
-}
-
-CheckBoxButton::~CheckBoxButton()
-{
-  mPainter = NULL;
-}
-
 } // namespace Internal
 
 } // namespace Toolkit