X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fslider%2Fslider-impl.cpp;h=e2dc5e30a2e988d9c73f3408813903fff29a010b;hb=09502f5f09f1294ef5555e4efbf0e7e8115bfbc3;hp=7fa1551e203baa726f8d80f5167b97f84811af5b;hpb=9808ae4c46337178721866e7ec163eebe0d1c85a;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/slider/slider-impl.cpp b/dali-toolkit/internal/controls/slider/slider-impl.cpp index 7fa1551..e2dc5e3 100644 --- a/dali-toolkit/internal/controls/slider/slider-impl.cpp +++ b/dali-toolkit/internal/controls/slider/slider-impl.cpp @@ -22,7 +22,7 @@ #include // for strcmp #include #include -#include +#include #include #include @@ -203,8 +203,16 @@ void Slider::OnInitialize() // Size the Slider actor to a default 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 ) @@ -215,7 +223,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 ) { @@ -248,25 +256,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 ); } @@ -381,7 +389,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; } @@ -606,6 +614,7 @@ Toolkit::TextLabel Slider::CreatePopupText() textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); 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; } @@ -689,6 +698,7 @@ void Slider::CreateHandleValueDisplay() 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 ); } } @@ -837,19 +847,9 @@ float Slider::MarkFilter( float value ) { 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; } @@ -950,6 +950,10 @@ void Slider::SetValue( float value ) { mValue = value; DisplayValue( mValue, true ); + if (Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor()) + { + Control::Impl::GetAccessibilityObject(Self())->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::VALUE); + } } float Slider::GetValue() const @@ -1409,6 +1413,83 @@ 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 ); + auto &impl = Toolkit::GetImpl(p); + + const float prev = p.GetProperty(Toolkit::Slider::Property::VALUE); + float next = static_cast(current); + + if (fabsf(next - prev) < Math::MACHINE_EPSILON_0) + { + // do nothing + } + else if (p.GetProperty(Toolkit::Slider::Property::SNAP_TO_MARKS)) + { + auto marks = p.GetProperty(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(marks.Count())) + return false; + + next = marks[nextIdx].Get(); + } + 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(Toolkit::Slider::Property::MARKS).Empty(); + float tolerance = p.GetProperty(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