/*
- * 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.
#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>
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 ) );
+
+ // Set the Slider to be highlightable in Screen Reader mode
+ self.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true );
// 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 )
Control::OnRelayout( size, container );
}
-bool Slider::OnTouch(Actor actor, const TouchData& touch)
+bool Slider::OnTouch(Actor actor, const TouchEvent& touch)
{
if( mState != DISABLED )
{
}
}
- return true;
+ return false;
}
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 );
}
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
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;
}
Toolkit::ImageView Slider::CreateTrack()
{
Toolkit::ImageView track = Toolkit::ImageView::New();
- track.SetName("SliderTrack");
- 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;
}
mTrackRegion = size;
if( mTrack )
{
- mTrack.SetSize( mTrackRegion );
+ mTrack.SetProperty( Actor::Property::SIZE, mTrackRegion );
}
ResizeProgressRegion( Vector2( 0.0f, mTrackRegion.y ) );
Toolkit::ImageView Slider::CreateProgress()
{
Toolkit::ImageView progress = Toolkit::ImageView::New();
- progress.SetName("SliderProgress");
- 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;
}
{
if( mProgress )
{
- mProgress.SetSize( region );
+ mProgress.SetProperty( Actor::Property::SIZE, region );
}
}
Toolkit::ImageView Slider::CreateHandle()
{
Toolkit::ImageView handle = Toolkit::ImageView::New();
- handle.SetName("SliderHandle");
- 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;
}
{
Toolkit::ImageView arrow = Toolkit::ImageView::New();
arrow.SetStyleName("SliderPopupArrow");
- arrow.SetName("SliderPopupArrow");
- arrow.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
- arrow.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+ 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;
}
Toolkit::TextLabel Slider::CreatePopupText()
{
Toolkit::TextLabel textLabel = Toolkit::TextLabel::New();
- textLabel.SetName( "SliderPopupTextLabel" );
+ textLabel.SetProperty( Dali::Actor::Property::NAME, "SliderPopupTextLabel" );
textLabel.SetStyleName( "SliderPopupTextLabel" );
- textLabel.SetParentOrigin( ParentOrigin::CENTER );
- textLabel.SetAnchorPoint( AnchorPoint::CENTER );
+ 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 ) );
+ textLabel.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
return textLabel;
}
Toolkit::ImageView Slider::CreatePopup()
{
Toolkit::ImageView popup = Toolkit::ImageView::New();
- popup.SetName( "SliderPopup" );
- 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();
{
if( mHandle )
{
- mHandle.SetSize( size );
+ mHandle.SetProperty( Actor::Property::SIZE, size );
}
}
if( mHandle && !mHandleValueTextLabel )
{
mHandleValueTextLabel = Toolkit::TextLabel::New();
- mHandleValueTextLabel.SetName("SliderHandleTextLabel");
+ mHandleValueTextLabel.SetProperty( Dali::Actor::Property::NAME,"SliderHandleTextLabel");
mHandleValueTextLabel.SetStyleName("SliderHandleTextLabel");
- mHandleValueTextLabel.SetParentOrigin( ParentOrigin::CENTER );
- mHandleValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
+ 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" );
+ mHandleValueTextLabel.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
mHandle.Add( mHandleValueTextLabel );
}
}
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;
{
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:
if( mHitArea )
{
- mHitArea.SetSize( mHitRegion );
+ mHitArea.SetProperty( Actor::Property::SIZE, mHitRegion );
}
}
if( !mValueDisplay )
{
mValueDisplay = CreateValueDisplay();
- mValueDisplay.SetVisible( false );
+ mValueDisplay.SetProperty( Actor::Property::VISIBLE, false );
mHandle.Add( mValueDisplay );
CreatePopupImage( GetPopupVisual() );
{
const float MARK_TOLERANCE = GetMarkTolerance();
- float mark;
- for( MarkList::SizeType i = 0; i < mMarks.Count(); ++i)
- {
- const Property::Value& propertyValue = mMarks[i];
- propertyValue.Get( mark );
- mark = MapValuePercentage( mark );
-
- // If close to a mark, return the mark
- if( fabsf( mark - value ) < MARK_TOLERANCE )
- {
- return mark;
- }
- }
+ float mark = SnapToMark(value);
+ if (fabsf(mark - value) < MARK_TOLERANCE)
+ return mark;
return value;
}
{
if( mValueDisplay )
{
- mValueDisplay.SetVisible( false );
+ mValueDisplay.SetProperty( Actor::Property::VISIBLE, false );
}
return false;
{
mValue = value;
DisplayValue( mValue, true );
+ if (Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
+ {
+ Control::Impl::GetAccessibilityObject(Self())->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::VALUE);
+ }
}
float Slider::GetValue() const
if( mTrack )
{
- mTrack.SetSize( mTrackRegion );
+ mTrack.SetProperty( Actor::Property::SIZE, mTrackRegion );
}
ResizeProgressRegion( Vector2( 0.0f, mTrackRegion.y ) );
if( mValueDisplay )
{
- mValueDisplay.SetVisible( true );
+ mValueDisplay.SetProperty( Actor::Property::VISIBLE, true );
mValueTimer.SetInterval( VALUE_VIEW_SHOW_DURATION );
}
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 );
+ auto &impl = Toolkit::GetImpl(p);
+
+ const float prev = p.GetProperty<float>(Toolkit::Slider::Property::VALUE);
+ float next = static_cast<float>(current);
+
+ if (fabsf(next - prev) < Math::MACHINE_EPSILON_0)
+ {
+ // do nothing
+ }
+ else if (p.GetProperty<bool>(Toolkit::Slider::Property::SNAP_TO_MARKS))
+ {
+ auto marks = p.GetProperty<Property::Array>(Toolkit::Slider::Property::MARKS);
+
+ int prevIdx;
+ if (impl.MarkReached(impl.MapValuePercentage(prev), prevIdx))
+ {
+ int nextIdx = prevIdx;
+ nextIdx += (next > prev) ? 1 : -1;
+
+ if (nextIdx < 0 || nextIdx >= static_cast<int>(marks.Count()))
+ return false;
+
+ next = marks[nextIdx].Get<float>();
+ }
+ else
+ {
+ next = impl.MapBounds(impl.SnapToMark(impl.MapValuePercentage(next)), impl.GetLowerBound(), impl.GetUpperBound());
+ }
+ }
+ else
+ {
+ next = impl.MapBounds(impl.MarkFilter(impl.MapValuePercentage(next)), impl.GetLowerBound(), impl.GetUpperBound());
+ }
+
+ impl.SetValue(next);
+ impl.DisplayPopup(next);
+
+ return true;
+}
+
+double Slider::AccessibleImpl::GetMinimumIncrement()
+{
+ auto p = Toolkit::Slider::DownCast( self );
+
+ bool hasMarks = !p.GetProperty<Property::Array>(Toolkit::Slider::Property::MARKS).Empty();
+ float tolerance = p.GetProperty<float>(Toolkit::Slider::Property::MARK_TOLERANCE);
+
+ if (!hasMarks || fabsf(tolerance) < 0.01)
+ return 0.0; // let screen-reader choose the increment
+
+ return Math::MACHINE_EPSILON_10000 + tolerance * (GetMaximum() - GetMinimum());
+}
+
} // namespace Internal
} // namespace Toolkit