[AT-SPI] Fix role setting
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / slider / slider-impl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 4fa4bf6..c347676
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 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.
@@ -22,7 +22,7 @@
 #include <cstring> // for strcmp
 #include <sstream>
 #include <limits>
-#include <dali/public-api/events/touch-data.h>
+#include <dali/public-api/events/touch-event.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
 
@@ -201,10 +201,15 @@ void Slider::OnInitialize()
   DisplayValue( mValue, false );       // Run this last to display the correct value
 
   // Size the Slider actor to a default
-  self.SetSize( DEFAULT_HIT_REGION.x, DEFAULT_HIT_REGION.y );
+  self.SetProperty( Actor::Property::SIZE, Vector2( DEFAULT_HIT_REGION.x, DEFAULT_HIT_REGION.y ) );
 
   // Connect to the touch signal
-  self.TouchSignal().Connect( this, &Slider::OnTouch );
+  self.TouchedSignal().Connect( this, &Slider::OnTouch );
+
+  DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) {
+    return std::unique_ptr< Dali::Accessibility::Accessible >(
+      new AccessibleImpl( actor, Dali::Accessibility::Role::SLIDER ) );
+  } );
 }
 
 void Slider::OnRelayout( const Vector2& size, RelayoutContainer& container )
@@ -215,7 +220,7 @@ void Slider::OnRelayout( const Vector2& size, RelayoutContainer& container )
   Control::OnRelayout( size, container );
 }
 
-bool Slider::OnTouch(Actor actor, const TouchData& touch)
+bool Slider::OnTouch(Actor actor, const TouchEvent& touch)
 {
   if( mState != DISABLED )
   {
@@ -240,7 +245,7 @@ bool Slider::OnTouch(Actor actor, const TouchData& touch)
     }
   }
 
-  return true;
+  return false;
 }
 
 void Slider::OnPan( Actor actor, const PanGesture& gesture )
@@ -248,25 +253,25 @@ void Slider::OnPan( Actor actor, const PanGesture& gesture )
   // gesture.position is in local actor coordinates
   if( mState != DISABLED )
   {
-    switch( gesture.state )
+    switch( gesture.GetState() )
     {
-      case Gesture::Continuing:
+      case GestureState::CONTINUING:
       {
         if( mState == PRESSED )
         {
-          float value = MapBounds( MarkFilter ( MapPercentage( gesture.position ) ), GetLowerBound(), GetUpperBound() );
+          float value = MapBounds( MarkFilter ( MapPercentage( gesture.GetPosition() ) ), GetLowerBound(), GetUpperBound() );
           SetValue( value );
           DisplayPopup( value );
         }
         break;
       }
-      case Gesture::Finished:
+      case GestureState::FINISHED:
       {
         if( mState == PRESSED  )
         {
           if( GetSnapToMarks() )
           {
-            float value = MapBounds( SnapToMark( MapPercentage( gesture.position ) ), GetLowerBound(), GetUpperBound() );
+            float value = MapBounds( SnapToMark( MapPercentage( gesture.GetPosition() ) ), GetLowerBound(), GetUpperBound() );
             SetValue( value );
             DisplayPopup( value );
           }
@@ -321,12 +326,12 @@ void Slider::DisplayValue( float value, bool raiseSignals )
 
   float x = mDomain.from.x + percent * ( mDomain.to.x - mDomain.from.x );
 
-  mHandle.SetX( x );
+  mHandle.SetProperty( Actor::Property::POSITION_X,  x );
 
   // Progress bar
   if( mProgress )
   {
-    mProgress.SetSize( x, GetTrackRegion().y );
+    mProgress.SetProperty( Actor::Property::SIZE, Vector2( x, GetTrackRegion().y ) );
   }
 
   // Signals
@@ -381,7 +386,7 @@ Actor Slider::CreateHitRegion()
   Actor hitRegion = Actor::New();
   hitRegion.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   hitRegion.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-  hitRegion.TouchSignal().Connect( this, &Slider::OnTouch );
+  hitRegion.TouchedSignal().Connect( this, &Slider::OnTouch );
 
   return hitRegion;
 }
@@ -430,7 +435,7 @@ void Slider::SetTrackVisual( Property::Map map )
       mTrackRegion = size;
       if( mTrack )
       {
-        mTrack.SetSize( mTrackRegion );
+        mTrack.SetProperty( Actor::Property::SIZE, mTrackRegion );
       }
 
     ResizeProgressRegion( Vector2( 0.0f, mTrackRegion.y ) );
@@ -570,7 +575,7 @@ void Slider::ResizeProgressRegion( const Vector2& region )
 {
   if( mProgress )
   {
-    mProgress.SetSize( region );
+    mProgress.SetProperty( Actor::Property::SIZE, region );
   }
 }
 
@@ -605,7 +610,7 @@ Toolkit::TextLabel Slider::CreatePopupText()
   textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
   textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
   textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
-  textLabel.SetPadding( Padding( POPUP_TEXT_PADDING, POPUP_TEXT_PADDING, 0.0f, 0.0f ) );
+  textLabel.SetProperty( Actor::Property::PADDING, Padding( POPUP_TEXT_PADDING, POPUP_TEXT_PADDING, 0.0f, 0.0f ) );
   return textLabel;
 }
 
@@ -674,7 +679,7 @@ void Slider::ResizeHandleSize( const Vector2& size )
 {
   if( mHandle )
   {
-    mHandle.SetSize( size );
+    mHandle.SetProperty( Actor::Property::SIZE, size );
   }
 }
 
@@ -708,7 +713,7 @@ Actor Slider::CreateValueDisplay()
   popup.Add( mPopupArrow );
 
   mPopup = CreatePopup();
-  mPopup.SetSize( 0.0f, VALUE_POPUP_HEIGHT );
+  mPopup.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, VALUE_POPUP_HEIGHT ) );
   mPopupArrow.Add( mPopup );
 
   return popup;
@@ -789,7 +794,7 @@ void Slider::SetHitRegion( const Vector2& size )
 
   if( mHitArea )
   {
-    mHitArea.SetSize( mHitRegion );
+    mHitArea.SetProperty( Actor::Property::SIZE, mHitRegion );
   }
 }
 
@@ -963,7 +968,7 @@ void Slider::SetTrackRegion( const Vector2& region )
 
   if( mTrack )
   {
-    mTrack.SetSize( mTrackRegion );
+    mTrack.SetProperty( Actor::Property::SIZE, mTrackRegion );
   }
 
   ResizeProgressRegion( Vector2( 0.0f, mTrackRegion.y ) );
@@ -1409,6 +1414,39 @@ Property::Value Slider::GetProperty( BaseObject* object, Property::Index propert
   return value;
 }
 
+double Slider::AccessibleImpl::GetMinimum()
+{
+  auto p = Toolkit::Slider::DownCast( self );
+  return p.GetProperty( Toolkit::Slider::Property::LOWER_BOUND ).Get< float >();
+}
+
+double Slider::AccessibleImpl::GetCurrent()
+{
+  auto p = Toolkit::Slider::DownCast( self );
+  return p.GetProperty( Toolkit::Slider::Property::VALUE ).Get< float >();
+}
+
+double Slider::AccessibleImpl::GetMaximum()
+{
+  auto p = Toolkit::Slider::DownCast( self );
+  return p.GetProperty( Toolkit::Slider::Property::UPPER_BOUND ).Get< float >();
+}
+
+bool Slider::AccessibleImpl::SetCurrent( double current )
+{
+  if( current < GetMinimum() || current > GetMaximum() )
+    return false;
+  auto p = Toolkit::Slider::DownCast( self );
+  p.SetProperty( Toolkit::Slider::Property::VALUE, static_cast< float >( current ) );
+  return true;
+}
+
+double Slider::AccessibleImpl::GetMinimumIncrement()
+{
+  auto p = Toolkit::Slider::DownCast( self );
+  return p.GetProperty( Toolkit::Slider::Property::MARK_TOLERANCE ).Get< float >();
+}
+
 } // namespace Internal
 
 } // namespace Toolkit