[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 915db02..c347676
@@ -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.
 #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>
-#include <dali/public-api/images/resource-image.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
 
@@ -87,11 +88,11 @@ const float DEFAULT_HIT_HEIGHT = 72.0f;
 const float DEFAULT_HANDLE_HEIGHT = DEFAULT_HIT_HEIGHT;
 const float POPUP_TEXT_PADDING = 10.0f;
 
-const char* SKINNED_TRACK_VISUAL = DALI_IMAGE_DIR "slider-skin.9.png";
-const char* SKINNED_HANDLE_VISUAL = DALI_IMAGE_DIR "slider-skin-handle.png";
-const char* SKINNED_PROGRESS_VISUAL = DALI_IMAGE_DIR "slider-skin-progress.9.png";
-const char* SKINNED_POPUP_VISUAL = DALI_IMAGE_DIR "slider-popup.9.png";
-const char* SKINNED_POPUP_ARROW_VISUAL = DALI_IMAGE_DIR "slider-popup-arrow.png";
+const char* SKINNED_TRACK_VISUAL_FILE_NAME = "slider-skin.9.png";
+const char* SKINNED_HANDLE_VISUAL_FILE_NAME = "slider-skin-handle.png";
+const char* SKINNED_PROGRESS_VISUAL_FILE_NAME = "slider-skin-progress.9.png";
+const char* SKINNED_POPUP_VISUAL_FILE_NAME = "slider-popup.9.png";
+const char* SKINNED_POPUP_ARROW_VISUAL_FILE_NAME = "slider-popup-arrow.png";
 
 const Vector2 DEFAULT_HIT_REGION( DEFAULT_WIDTH, DEFAULT_HIT_HEIGHT );
 const Vector2 DEFAULT_TRACK_REGION( DEFAULT_WIDTH, DEFAULT_HEIGHT );
@@ -102,7 +103,6 @@ const Vector4 DEFAULT_DISABLED_COLOR( 0.5f, 0.5f, 0.5f, 1.0f );
 const float VALUE_POPUP_MARGIN = 10.0f;
 const float VALUE_POPUP_HEIGHT = 81.0f;
 const float VALUE_POPUP_MIN_WIDTH = 54.0f;
-const Vector2 VALUE_POPUP_ARROW_SIZE( 18.0f, 18.0f );
 
 const float DEFAULT_LOWER_BOUND = 0.0f;
 const float DEFAULT_UPPER_BOUND = 1.0f;
@@ -135,7 +135,7 @@ Dali::Toolkit::Slider Slider::New()
 }
 
 Slider::Slider()
-: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mState( NORMAL ),
   mPopupVisual(""),
   mPopupArrowVisual(""),
@@ -177,11 +177,12 @@ void Slider::OnInitialize()
   SetTrackRegion(   DEFAULT_TRACK_REGION   );
   SetHandleSize(    DEFAULT_HANDLE_SIZE    );
 
-  SetTrackVisual(            SKINNED_TRACK_VISUAL             );
-  SetHandleVisual(           SKINNED_HANDLE_VISUAL            );
-  SetProgressVisual(         SKINNED_PROGRESS_VISUAL          );
-  SetPopupVisual(            SKINNED_POPUP_VISUAL             );
-  SetPopupArrowVisual(       SKINNED_POPUP_ARROW_VISUAL       );
+  const std::string imageDirPath = AssetManager::GetDaliImagePath();
+  SetTrackVisual(            imageDirPath + SKINNED_TRACK_VISUAL_FILE_NAME             );
+  SetHandleVisual(           imageDirPath + SKINNED_HANDLE_VISUAL_FILE_NAME            );
+  SetProgressVisual(         imageDirPath + SKINNED_PROGRESS_VISUAL_FILE_NAME          );
+  SetPopupVisual(            imageDirPath + SKINNED_POPUP_VISUAL_FILE_NAME             );
+  SetPopupArrowVisual(       imageDirPath + SKINNED_POPUP_ARROW_VISUAL_FILE_NAME       );
 
   SetShowPopup( DEFAULT_SHOW_POPUP );
   SetShowValue( DEFAULT_SHOW_VALUE );
@@ -200,20 +201,26 @@ 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::OnSizeSet( const Vector3& size )
+void Slider::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
-  // Factor in handle overshoot into size of track
   SetHitRegion( Vector2( size.x, GetHitRegion().y ) );
+  // Factor in handle overshoot into size of backing
   SetTrackRegion( Vector2( size.x - GetHandleSize().x, GetTrackRegion().y ) );
+  Control::OnRelayout( size, container );
 }
 
-bool Slider::OnTouch(Actor actor, const TouchData& touch)
+bool Slider::OnTouch(Actor actor, const TouchEvent& touch)
 {
   if( mState != DISABLED )
   {
@@ -238,7 +245,7 @@ bool Slider::OnTouch(Actor actor, const TouchData& touch)
     }
   }
 
-  return true;
+  return false;
 }
 
 void Slider::OnPan( Actor actor, const PanGesture& gesture )
@@ -246,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 );
           }
@@ -313,25 +320,25 @@ Slider::Domain Slider::CalcDomain( const Vector2& currentSize )
 
 void Slider::DisplayValue( float value, bool raiseSignals )
 {
-  float clampledValue = Clamp( value, GetLowerBound(), GetUpperBound() );
+  float clampedValue = Clamp( value, GetLowerBound(), GetUpperBound() );
 
-  float percent = MapValuePercentage( clampledValue );
+  float percent = MapValuePercentage( clampedValue );
 
   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
   if( raiseSignals )
   {
     Toolkit::Slider self = Toolkit::Slider::DownCast( Self() );
-    mValueChangedSignal.Emit( self, clampledValue );
+    mValueChangedSignal.Emit( self, clampedValue );
 
     int markIndex;
     if( MarkReached( percent, markIndex ) )
@@ -344,9 +351,13 @@ void Slider::DisplayValue( float value, bool raiseSignals )
   {
     std::stringstream ss;
     ss.precision( GetValuePrecision() );
-    ss << std::fixed << clampledValue;
+    ss << std::fixed << clampedValue;
 
-    mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
+    std::string label = mHandleValueTextLabel.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
+    if( label.compare(ss.str()) )
+    {
+      mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
+    }
   }
 }
 
@@ -373,9 +384,9 @@ bool Slider::GetSnapToMarks() const
 Actor Slider::CreateHitRegion()
 {
   Actor hitRegion = Actor::New();
-  hitRegion.SetParentOrigin( ParentOrigin::CENTER );
-  hitRegion.SetAnchorPoint( AnchorPoint::CENTER );
-  hitRegion.TouchSignal().Connect( this, &Slider::OnTouch );
+  hitRegion.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+  hitRegion.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+  hitRegion.TouchedSignal().Connect( this, &Slider::OnTouch );
 
   return hitRegion;
 }
@@ -383,9 +394,9 @@ Actor Slider::CreateHitRegion()
 Toolkit::ImageView Slider::CreateTrack()
 {
   Toolkit::ImageView track = Toolkit::ImageView::New();
-  track.SetParentOrigin( ParentOrigin::CENTER );
-  track.SetAnchorPoint( AnchorPoint::CENTER );
-
+  track.SetProperty( Dali::Actor::Property::NAME,"SliderTrack");
+  track.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+  track.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
   return track;
 }
 
@@ -424,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 ) );
@@ -445,8 +456,9 @@ std::string Slider::GetTrackVisual()
 Toolkit::ImageView Slider::CreateProgress()
 {
   Toolkit::ImageView progress = Toolkit::ImageView::New();
-  progress.SetParentOrigin( ParentOrigin::CENTER_LEFT );
-  progress.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+  progress.SetProperty( Dali::Actor::Property::NAME,"SliderProgress");
+  progress.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT );
+  progress.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
 
   return progress;
 }
@@ -515,8 +527,9 @@ void Slider::CreatePopupImage( const std::string& filename )
 {
   if( mPopup && ( filename.size() > 0 ) )
   {
-    Image image = ResourceImage::New( filename );
-    mPopup.SetImage( image );
+    Property::Map map;
+    map[Toolkit::ImageVisual::Property::URL] = filename;
+    mPopup.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
   }
 }
 
@@ -552,8 +565,9 @@ void Slider::CreatePopupArrowImage( const std::string& filename )
 {
   if( mPopupArrow && ( filename.size() > 0 ) )
   {
-    Image image = ResourceImage::New( filename );
-    mPopupArrow.SetImage( image );
+    Property::Map map;
+    map[Toolkit::ImageVisual::Property::URL] = filename;
+    mPopupArrow.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
   }
 }
 
@@ -561,15 +575,16 @@ void Slider::ResizeProgressRegion( const Vector2& region )
 {
   if( mProgress )
   {
-    mProgress.SetSize( region );
+    mProgress.SetProperty( Actor::Property::SIZE, region );
   }
 }
 
 Toolkit::ImageView Slider::CreateHandle()
 {
   Toolkit::ImageView handle = Toolkit::ImageView::New();
-  handle.SetParentOrigin( ParentOrigin::CENTER_LEFT );
-  handle.SetAnchorPoint( AnchorPoint::CENTER );
+  handle.SetProperty( Dali::Actor::Property::NAME,"SliderHandle");
+  handle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT );
+  handle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
 
   return handle;
 }
@@ -577,8 +592,10 @@ Toolkit::ImageView Slider::CreateHandle()
 Toolkit::ImageView Slider::CreatePopupArrow()
 {
   Toolkit::ImageView arrow = Toolkit::ImageView::New();
-  arrow.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-  arrow.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+  arrow.SetStyleName("SliderPopupArrow");
+  arrow.SetProperty( Dali::Actor::Property::NAME,"SliderPopupArrow");
+  arrow.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+  arrow.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
 
   return arrow;
 }
@@ -586,20 +603,23 @@ Toolkit::ImageView Slider::CreatePopupArrow()
 Toolkit::TextLabel Slider::CreatePopupText()
 {
   Toolkit::TextLabel textLabel = Toolkit::TextLabel::New();
-  textLabel.SetParentOrigin( ParentOrigin::CENTER );
-  textLabel.SetAnchorPoint( AnchorPoint::CENTER );
+  textLabel.SetProperty( Dali::Actor::Property::NAME, "SliderPopupTextLabel" );
+  textLabel.SetStyleName( "SliderPopupTextLabel" );
+  textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+  textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
   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;
 }
 
 Toolkit::ImageView Slider::CreatePopup()
 {
   Toolkit::ImageView popup = Toolkit::ImageView::New();
-  popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
-  popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+  popup.SetProperty( Dali::Actor::Property::NAME, "SliderPopup" );
+  popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+  popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
   popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
 
   mValueTextLabel = CreatePopupText();
@@ -659,7 +679,7 @@ void Slider::ResizeHandleSize( const Vector2& size )
 {
   if( mHandle )
   {
-    mHandle.SetSize( size );
+    mHandle.SetProperty( Actor::Property::SIZE, size );
   }
 }
 
@@ -668,8 +688,10 @@ void Slider::CreateHandleValueDisplay()
   if( mHandle && !mHandleValueTextLabel )
   {
     mHandleValueTextLabel = Toolkit::TextLabel::New();
-    mHandleValueTextLabel.SetParentOrigin( ParentOrigin::CENTER );
-    mHandleValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
+    mHandleValueTextLabel.SetProperty( Dali::Actor::Property::NAME,"SliderHandleTextLabel");
+    mHandleValueTextLabel.SetStyleName("SliderHandleTextLabel");
+    mHandleValueTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mHandleValueTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
     mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
     mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
     mHandle.Add( mHandleValueTextLabel );
@@ -684,14 +706,14 @@ void Slider::DestroyHandleValueDisplay()
 Actor Slider::CreateValueDisplay()
 {
   Actor popup = Actor::New();
-  popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
-  popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+  popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+  popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
 
   mPopupArrow = CreatePopupArrow();
   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;
@@ -718,17 +740,17 @@ void Slider::UpdateSkin()
   {
     case NORMAL:
     {
-      mTrack.SetColor( Color::WHITE );
-      mHandle.SetColor( Color::WHITE );
-      mProgress.SetColor( Color::WHITE );
+      mTrack.SetProperty( Actor::Property::COLOR, Color::WHITE );
+      mHandle.SetProperty( Actor::Property::COLOR, Color::WHITE );
+      mProgress.SetProperty( Actor::Property::COLOR, Color::WHITE );
       break;
     }
     case DISABLED:
     {
       Vector4 disabledColor = GetDisabledColor();
-      mTrack.SetColor( disabledColor );
-      mHandle.SetColor( disabledColor );
-      mProgress.SetColor( disabledColor );
+      mTrack.SetProperty( Actor::Property::COLOR, disabledColor );
+      mHandle.SetProperty( Actor::Property::COLOR, disabledColor );
+      mProgress.SetProperty( Actor::Property::COLOR, disabledColor );
       break;
     }
     case PRESSED:
@@ -772,7 +794,7 @@ void Slider::SetHitRegion( const Vector2& size )
 
   if( mHitArea )
   {
-    mHitArea.SetSize( mHitRegion );
+    mHitArea.SetProperty( Actor::Property::SIZE, mHitRegion );
   }
 }
 
@@ -786,7 +808,7 @@ void Slider::AddPopup()
   if( !mValueDisplay )
   {
     mValueDisplay = CreateValueDisplay();
-    mValueDisplay.SetVisible( false );
+    mValueDisplay.SetProperty( Actor::Property::VISIBLE, false );
     mHandle.Add( mValueDisplay );
 
     CreatePopupImage( GetPopupVisual() );
@@ -901,7 +923,7 @@ bool Slider::HideValueView()
 {
   if( mValueDisplay )
   {
-    mValueDisplay.SetVisible( false );
+    mValueDisplay.SetProperty( Actor::Property::VISIBLE, false );
   }
 
   return false;
@@ -946,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 ) );
@@ -1104,7 +1126,7 @@ void Slider::DisplayPopup( float value )
 
     if( mValueDisplay )
     {
-      mValueDisplay.SetVisible( true );
+      mValueDisplay.SetProperty( Actor::Property::VISIBLE, true );
 
       mValueTimer.SetInterval( VALUE_VIEW_SHOW_DURATION );
     }
@@ -1363,8 +1385,15 @@ Property::Value Slider::GetProperty( BaseObject* object, Property::Index propert
 
       case Toolkit::Slider::Property::MARKS:
       {
-        // TODO: Need to be able to return a PropertyArray
-        // value = sliderImpl.GetMarks();
+        Property::Value value1( Property::ARRAY );
+        Property::Array* markArray = value1.GetArray();
+
+        if( markArray )
+        {
+          *markArray = sliderImpl.GetMarks();
+        }
+
+        value = value1;
         break;
       }
 
@@ -1385,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