[AT-SPI] Fix role setting
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / check-box-button-impl.cpp
index 4eb7831..103992f 100644 (file)
@@ -1,30 +1,36 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
-
 #include "check-box-button-impl.h"
 
 // EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/object/type-registry.h>
 
-#include <algorithm>
-
-// INTERNAL INCLUDES
+//INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
+#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/devel-api/shader-effects/image-region-effect.h>
 
-#include "check-box-button-default-painter-impl.h"
+#if defined(DEBUG_ENABLED)
+  extern Debug::Filter* gLogButtonFilter;
+#endif
 
 namespace Dali
 {
@@ -45,18 +51,9 @@ BaseHandle Create()
 
 TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create );
 
-TypeAction a1(mType, Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK, &CheckBoxButton::DoAction);
 
-}
 
-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()
 {
@@ -73,195 +70,44 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
   return checkBoxButton;
 }
 
-void CheckBoxButton::SetChecked( bool checked )
-{
-  if( !mDimmed && ( checked != mChecked ) )
-  {
-    // Stores the state.
-    mChecked = checked;
-
-    Toolkit::CheckBoxButton handle( GetOwner() );
-
-    // Notifies the painter the checkbox has been checked.
-    GetCheckBoxButtonPainter( mPainter )->Checked( handle );
-
-    // Emit signal.
-    mClickedSignalV2.Emit( handle );
-  }
-}
-
-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::SetDimmedBackgroundImage( Image image )
-{
-  SetDimmedBackgroundImage( ImageActor::New( image ) );
-}
-
-void CheckBoxButton::SetDimmedBackgroundImage( Actor image )
-{
-  Toolkit::CheckBoxButton handle( GetOwner() );
-  GetCheckBoxButtonPainter( mPainter )->SetDimmedBackgroundImage( handle, image );
-}
-
-Actor& CheckBoxButton::GetDimmedBackgroundImage()
-{
-  return mDimmedBackgroundImage;
-}
-
-Actor CheckBoxButton::GetDimmedBackgroundImage() const
-{
-  return mDimmedBackgroundImage;
-}
-
-void CheckBoxButton::SetDimmedCheckedImage( Image image )
-{
-  SetDimmedCheckedImage( ImageActor::New( image ) );
-}
-
-void CheckBoxButton::SetDimmedCheckedImage( Actor image )
-{
-  Toolkit::CheckBoxButton handle( GetOwner() );
-  GetCheckBoxButtonPainter( mPainter )->SetDimmedCheckedImage( handle, image );
-}
-
-Actor& CheckBoxButton::GetDimmedCheckedImage()
-{
-  return mDimmedCheckedImage;
-}
-
-Actor CheckBoxButton::GetDimmedCheckedImage() const
-{
-  return mDimmedCheckedImage;
-}
-
-Actor& CheckBoxButton::GetFadeOutBackgroundImage()
-{
-  return mFadeOutBackgroundImage;
-}
-
-Actor& CheckBoxButton::GetFadeOutCheckedImage()
-{
-  return mFadeOutCheckedImage;
-}
-
-void CheckBoxButton::OnButtonInitialize()
-{
-  mUseFadeAnimationProperty = Self().RegisterProperty( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME, false );
-  mUseCheckAnimationProperty = Self().RegisterProperty( Toolkit::CheckBoxButton::USE_CHECK_ANIMATION_PROPERTY_NAME, true );
-}
-
-void CheckBoxButton::OnButtonUp()
+CheckBoxButton::CheckBoxButton()
+: Button()
 {
-  if( ButtonDown == mState )
-  {
-    // Stores the state, notifies the painter and emits a signal.
-    SetChecked( !mChecked );
-  }
+  SetTogglableButton( true );
 }
 
-void CheckBoxButton::OnAnimationTimeSet( float animationTime )
+CheckBoxButton::~CheckBoxButton()
 {
-  GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime );
 }
 
-float CheckBoxButton::OnAnimationTimeRequested() const
+void CheckBoxButton::OnInitialize()
 {
-  return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime();
-}
+  Button::OnInitialize();
 
-void CheckBoxButton::OnActivated()
-{
-  // When the button is activated, it performs the click action
-  std::vector<Property::Value> attributes;
-  DoClickAction(attributes);
+  DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
+    return std::unique_ptr< Dali::Accessibility::Accessible >(
+      new AccessibleImpl( actor, Dali::Accessibility::Role::CHECK_BOX ) );
+  } );
 }
 
-void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes)
+Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates()
 {
-  // Prevents the button signals from doing a recursive loop by sending an action
-  // and re-emitting the signals.
-  if(!mClickActionPerforming)
-  {
-    mClickActionPerforming = true;
-    SetChecked( !mChecked );
-    mClickActionPerforming = false;
-  }
+  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;
 }
 
-bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
+void CheckBoxButton::OnStateChange( State newState )
 {
-  bool ret = false;
-
-  Dali::BaseHandle handle(object);
-
-  Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle);
-
-  if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName)
+  // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
+  if (Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
   {
-    GetImplementation(button).DoClickAction(attributes);
-    ret = true;
+    Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
+      Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0
+    );
   }
-
-  return ret;
-}
-
-CheckBoxButton::CheckBoxButton()
-: Button(),
-  mChecked( false ),
-  mClickActionPerforming(false)
-{
-  // Creates specific painter.
-  mPainter = new CheckBoxButtonDefaultPainter();
-}
-
-CheckBoxButton::~CheckBoxButton()
-{
-  mPainter = NULL;
 }
 
 } // namespace Internal