X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscroll-bar%2Fscroll-bar-impl.cpp;h=4701d6c809b4dc79c8adc3b5f35d690f3b378f3f;hp=7612185049596fd714a250d277d3ec2c0409f430;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=2f705dd3525531584ee46d9a7fc9f23331909c10 diff --git a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp old mode 100755 new mode 100644 index 7612185..4701d6c --- a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp +++ b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -19,16 +19,18 @@ #include // EXTERNAL INCLUDES -#include // for strcmp +#include +#include +#include #include #include -#include -#include #include #include -#include +#include +#include // for strcmp // INTERNAL INCLUDES +#include #include #include @@ -36,8 +38,7 @@ using namespace Dali; namespace { - -const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.9.png"; +const char* DEFAULT_INDICATOR_IMAGE_FILE_NAME = "popup_scroll.9.png"; const float DEFAULT_SLIDER_DEPTH(1.0f); const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f); const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f); @@ -46,6 +47,7 @@ const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f); const float DEFAULT_INDICATOR_MINIMUM_HEIGHT(0.0f); const float DEFAULT_INDICATOR_START_PADDING(0.0f); const float DEFAULT_INDICATOR_END_PADDING(0.0f); +const float DEFAULT_INDICATOR_TRANSIENT_DURATION(1.0f); /** * Indicator size constraint @@ -57,9 +59,9 @@ struct IndicatorSizeConstraint * @param[in] minimumHeight The minimum height for the indicator * @param[in] padding The sum of the padding at the start & end of the indicator */ - IndicatorSizeConstraint( float minimumHeight, float padding ) - : mMinimumHeight( minimumHeight ), - mPadding( padding ) + IndicatorSizeConstraint(float minimumHeight, float padding) + : mMinimumHeight(minimumHeight), + mPadding(padding) { } @@ -69,19 +71,17 @@ struct IndicatorSizeConstraint * @param[in] parentSizeProperty The parent size of scroll indicator. * @return The new scroll indicator size. */ - void operator()( Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { - const Vector3& parentSize = inputs[0]->GetVector3(); - const float contentSize = inputs[1]->GetFloat(); + const Vector3& parentSize = inputs[0]->GetVector3(); + const float contentSize = inputs[1]->GetFloat(); // Take into account padding that may exist at the beginning and end of the indicator. const float parentHeightMinusPadding = parentSize.height - mPadding; - float height = contentSize > parentHeightMinusPadding ? - parentHeightMinusPadding * ( parentHeightMinusPadding / contentSize ) : - parentHeightMinusPadding * ( ( parentHeightMinusPadding - contentSize * 0.5f ) / parentHeightMinusPadding ); + float height = contentSize > parentHeightMinusPadding ? parentHeightMinusPadding * (parentHeightMinusPadding / contentSize) : parentHeightMinusPadding * ((parentHeightMinusPadding - contentSize * 0.5f) / parentHeightMinusPadding); - current.y = std::max( mMinimumHeight, height ); + current.y = std::max(mMinimumHeight, height); } float mMinimumHeight; @@ -98,9 +98,9 @@ struct IndicatorPositionConstraint * @param[in] startPadding The padding at the start of the indicator * @param[in] endPadding The padding at the end of the indicator */ - IndicatorPositionConstraint( float startPadding, float endPadding ) - : mStartPadding( startPadding ), - mEndPadding( endPadding ) + IndicatorPositionConstraint(float startPadding, float endPadding) + : mStartPadding(startPadding), + mEndPadding(endPadding) { } @@ -110,20 +110,20 @@ struct IndicatorPositionConstraint * @param[in] inputs Contains the size of indicator, the size of indicator's parent, and the scroll position of the scrollable container (from 0.0 -> 1.0 in each axis) * @return The new indicator position is returned. */ - void operator()( Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { - const Vector3& indicatorSize = inputs[0]->GetVector3(); - const Vector3& parentSize = inputs[1]->GetVector3(); - const float scrollPosition = -inputs[2]->GetFloat(); - const float minimumScrollPosition = inputs[3]->GetFloat(); - const float maximumScrollPosition = inputs[4]->GetFloat(); + const Vector3& indicatorSize = inputs[0]->GetVector3(); + const Vector3& parentSize = inputs[1]->GetVector3(); + const float scrollPosition = -inputs[2]->GetFloat(); + const float minimumScrollPosition = inputs[3]->GetFloat(); + const float maximumScrollPosition = inputs[4]->GetFloat(); // Take into account padding that may exist at the beginning and end of the indicator. - const float parentHeightMinusPadding = parentSize.height - ( mStartPadding + mEndPadding ); + const float parentHeightMinusPadding = parentSize.height - (mStartPadding + mEndPadding); - float relativePosition = std::max( 0.0f, std::min( 1.0f, ( scrollPosition - minimumScrollPosition ) / ( maximumScrollPosition - minimumScrollPosition ) ) ); - current.y = mStartPadding + ( parentHeightMinusPadding - indicatorSize.height ) * relativePosition; - current.z = DEFAULT_SLIDER_DEPTH; + float relativePosition = std::max(0.0f, std::min(1.0f, (scrollPosition - minimumScrollPosition) / (maximumScrollPosition - minimumScrollPosition))); + current.y = mStartPadding + (parentHeightMinusPadding - indicatorSize.height) * relativePosition; + current.z = DEFAULT_SLIDER_DEPTH; } float mStartPadding; @@ -134,16 +134,12 @@ struct IndicatorPositionConstraint namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - using namespace Dali; BaseHandle Create() @@ -151,43 +147,52 @@ BaseHandle Create() return Toolkit::ScrollBar::New(); } +// clang-format off // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create ); -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollDirection", STRING, SCROLL_DIRECTION ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy", STRING, INDICATOR_HEIGHT_POLICY ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight", FLOAT, INDICATOR_FIXED_HEIGHT ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration", FLOAT, INDICATOR_SHOW_DURATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration", FLOAT, INDICATOR_HIDE_DURATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals", ARRAY, SCROLL_POSITION_INTERVALS ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight", FLOAT, INDICATOR_MINIMUM_HEIGHT ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding", FLOAT, INDICATOR_START_PADDING ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding", FLOAT, INDICATOR_END_PADDING ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "scrollDirection", STRING, SCROLL_DIRECTION ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorHeightPolicy", STRING, INDICATOR_HEIGHT_POLICY ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorFixedHeight", FLOAT, INDICATOR_FIXED_HEIGHT ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorShowDuration", FLOAT, INDICATOR_SHOW_DURATION ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorHideDuration", FLOAT, INDICATOR_HIDE_DURATION ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "scrollPositionIntervals", ARRAY, SCROLL_POSITION_INTERVALS ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorMinimumHeight", FLOAT, INDICATOR_MINIMUM_HEIGHT ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorStartPadding", FLOAT, INDICATOR_START_PADDING ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorEndPadding", FLOAT, INDICATOR_END_PADDING ) +DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorTransientDuration", FLOAT, INDICATOR_TRANSIENT_DURATION) + +DALI_SIGNAL_REGISTRATION(Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL) -DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL ) -DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) +DALI_ACTION_REGISTRATION(Toolkit, ScrollBar, "ShowIndicator", ACTION_SHOW_INDICATOR ) +DALI_ACTION_REGISTRATION(Toolkit, ScrollBar, "HideIndicator", ACTION_HIDE_INDICATOR ) +DALI_ACTION_REGISTRATION(Toolkit, ScrollBar, "ShowTransientIndicator", ACTION_SHOW_TRANSIENT_INDICATOR) DALI_TYPE_REGISTRATION_END() +// clang-format on -const char* SCROLL_DIRECTION_NAME[] = {"Vertical", "Horizontal"}; -const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"}; +const char* SCROLL_DIRECTION_NAME[] = {"VERTICAL", "HORIZONTAL"}; +const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"VARIABLE", "FIXED"}; -} +} // namespace ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction) -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mIndicatorShowAlpha(1.0f), mDirection(direction), - mScrollableObject(WeakHandleBase()), + mScrollableObject(WeakHandle()), mPropertyScrollPosition(Property::INVALID_INDEX), mPropertyMinScrollPosition(Property::INVALID_INDEX), mPropertyMaxScrollPosition(Property::INVALID_INDEX), mPropertyScrollContentSize(Property::INVALID_INDEX), mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION), mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION), + mTransientIndicatorDuration(DEFAULT_INDICATOR_TRANSIENT_DURATION), mScrollStart(0.0f), + mGestureDisplacement(Vector2::ZERO), mCurrentScrollPosition(0.0f), - mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable), + mIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE), mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT), mIndicatorMinimumHeight(DEFAULT_INDICATOR_MINIMUM_HEIGHT), mIndicatorStartPadding(DEFAULT_INDICATOR_START_PADDING), @@ -204,19 +209,20 @@ ScrollBar::~ScrollBar() void ScrollBar::OnInitialize() { CreateDefaultIndicatorActor(); - Self().SetDrawMode(DrawMode::OVERLAY_2D); + Self().SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + + DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) { + return std::unique_ptr( + new AccessibleImpl(actor, Dali::Accessibility::Role::SCROLL_BAR)); + }); } -void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize ) +void ScrollBar::SetScrollPropertySource(Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize) { - if( handle - && propertyScrollPosition != Property::INVALID_INDEX - && propertyMinScrollPosition != Property::INVALID_INDEX - && propertyMaxScrollPosition != Property::INVALID_INDEX - && propertyScrollContentSize != Property::INVALID_INDEX ) + if(handle && propertyScrollPosition != Property::INVALID_INDEX && propertyMinScrollPosition != Property::INVALID_INDEX && propertyMaxScrollPosition != Property::INVALID_INDEX && propertyScrollContentSize != Property::INVALID_INDEX) { - mScrollableObject = WeakHandleBase(handle); - mPropertyScrollPosition = propertyScrollPosition; + mScrollableObject = WeakHandle(handle); + mPropertyScrollPosition = propertyScrollPosition; mPropertyMinScrollPosition = propertyMinScrollPosition; mPropertyMaxScrollPosition = propertyMaxScrollPosition; mPropertyScrollContentSize = propertyScrollContentSize; @@ -231,42 +237,43 @@ void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index property void ScrollBar::CreateDefaultIndicatorActor() { - Toolkit::ImageView indicator = Toolkit::ImageView::New( DEFAULT_INDICATOR_IMAGE_PATH ); - indicator.SetParentOrigin( ParentOrigin::TOP_LEFT ); - indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - indicator.SetStyleName( "ScrollBarIndicator" ); - indicator.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); + const std::string imageDirPath = AssetManager::GetDaliImagePath(); + Toolkit::ImageView indicator = Toolkit::ImageView::New(imageDirPath + DEFAULT_INDICATOR_IMAGE_FILE_NAME); + indicator.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + indicator.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + indicator.SetStyleName("ScrollBarIndicator"); + indicator.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR); SetScrollIndicator(indicator); } -void ScrollBar::SetScrollIndicator( Actor indicator ) +void ScrollBar::SetScrollIndicator(Actor indicator) { // Don't allow empty handle - if( indicator ) + if(indicator) { // Remove current Indicator - if( mIndicator ) + if(mIndicator) { - Self().Remove( mIndicator ); + Self().Remove(mIndicator); } mIndicator = indicator; mIndicatorFirstShow = true; - Self().Add( mIndicator ); + Self().Add(mIndicator); - EnableGestureDetection( Gesture::Type( Gesture::Pan ) ); + EnableGestureDetection(GestureType::Value(GestureType::PAN)); - PanGestureDetector detector( GetPanGestureDetector() ); + PanGestureDetector detector(GetPanGestureDetector()); detector.DetachAll(); - detector.Attach( mIndicator ); + detector.Attach(mIndicator); unsigned int childCount = mIndicator.GetChildCount(); - for ( unsigned int index = 0; index < childCount; index++ ) + for(unsigned int index = 0; index < childCount; index++) { - Actor child = mIndicator.GetChildAt( index ); - if ( child ) + Actor child = mIndicator.GetChildAt(index); + if(child) { - detector.Attach( child ); + detector.Attach(child); } } } @@ -283,9 +290,9 @@ Actor ScrollBar::GetScrollIndicator() void ScrollBar::ApplyConstraints() { - Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + Handle scrollableHandle = mScrollableObject.GetHandle(); - if( scrollableHandle ) + if(scrollableHandle) { if(mIndicatorSizeConstraint) { @@ -293,16 +300,15 @@ void ScrollBar::ApplyConstraints() } // Set indicator height according to the indicator's height policy - if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED) { - mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + mIndicator.SetProperty(Actor::Property::SIZE, Vector2(Self().GetCurrentProperty(Actor::Property::SIZE).width, mIndicatorFixedHeight)); } else { - mIndicatorSizeConstraint = Constraint::New( mIndicator, Actor::Property::SIZE, - IndicatorSizeConstraint( mIndicatorMinimumHeight, mIndicatorStartPadding + mIndicatorEndPadding ) ); - mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) ); - mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) ); + mIndicatorSizeConstraint = Constraint::New(mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint(mIndicatorMinimumHeight, mIndicatorStartPadding + mIndicatorEndPadding)); + mIndicatorSizeConstraint.AddSource(ParentSource(Actor::Property::SIZE)); + mIndicatorSizeConstraint.AddSource(Source(scrollableHandle, mPropertyScrollContentSize)); mIndicatorSizeConstraint.Apply(); } @@ -311,32 +317,31 @@ void ScrollBar::ApplyConstraints() mIndicatorPositionConstraint.Remove(); } - mIndicatorPositionConstraint = Constraint::New( mIndicator, Actor::Property::POSITION, - IndicatorPositionConstraint( mIndicatorStartPadding, mIndicatorEndPadding ) ); - mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) ); - mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) ); - mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) ); - mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) ); - mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) ); + mIndicatorPositionConstraint = Constraint::New(mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint(mIndicatorStartPadding, mIndicatorEndPadding)); + mIndicatorPositionConstraint.AddSource(LocalSource(Actor::Property::SIZE)); + mIndicatorPositionConstraint.AddSource(ParentSource(Actor::Property::SIZE)); + mIndicatorPositionConstraint.AddSource(Source(scrollableHandle, mPropertyScrollPosition)); + mIndicatorPositionConstraint.AddSource(Source(scrollableHandle, mPropertyMinScrollPosition)); + mIndicatorPositionConstraint.AddSource(Source(scrollableHandle, mPropertyMaxScrollPosition)); mIndicatorPositionConstraint.Apply(); } } -void ScrollBar::SetScrollPositionIntervals( const Dali::Vector& positions ) +void ScrollBar::SetScrollPositionIntervals(const Dali::Vector& positions) { mScrollPositionIntervals = positions; - Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + Handle scrollableHandle = mScrollableObject.GetHandle(); - if( scrollableHandle ) + if(scrollableHandle) { - if( mPositionNotification ) + if(mPositionNotification) { scrollableHandle.RemovePropertyNotification(mPositionNotification); } - mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) ); - mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached ); + mPositionNotification = scrollableHandle.AddPropertyNotification(mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals)); + mPositionNotification.NotifySignal().Connect(this, &ScrollBar::OnScrollPositionIntervalReached); } } @@ -348,10 +353,14 @@ Dali::Vector ScrollBar::GetScrollPositionIntervals() const void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source) { // Emit the signal to notify the scroll position crossing - Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + Handle scrollableHandle = mScrollableObject.GetHandle(); if(scrollableHandle) { - mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty(mPropertyScrollPosition)); + mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetCurrentProperty(mPropertyScrollPosition)); + if(Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor()) + { + Control::Impl::GetAccessibilityObject(Self())->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::VALUE); + } } } @@ -364,22 +373,22 @@ void ScrollBar::ShowIndicator() mAnimation.Reset(); } - if( mIndicatorFirstShow ) + if(mIndicatorFirstShow) { // Preserve the alpha value from the stylesheet - mIndicatorShowAlpha = Self().GetCurrentColor().a; + mIndicatorShowAlpha = Self().GetCurrentProperty(Actor::Property::COLOR).a; mIndicatorFirstShow = false; } if(mIndicatorShowDuration > 0.0f) { - mAnimation = Animation::New( mIndicatorShowDuration ); - mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), mIndicatorShowAlpha, AlphaFunction::EASE_IN ); + mAnimation = Animation::New(mIndicatorShowDuration); + mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA), mIndicatorShowAlpha, AlphaFunction::EASE_IN); mAnimation.Play(); } else { - mIndicator.SetOpacity(mIndicatorShowAlpha); + mIndicator.SetProperty(Actor::Property::OPACITY, mIndicatorShowAlpha); } } @@ -394,21 +403,49 @@ void ScrollBar::HideIndicator() if(mIndicatorHideDuration > 0.0f) { - mAnimation = Animation::New( mIndicatorHideDuration ); - mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN ); + mAnimation = Animation::New(mIndicatorHideDuration); + mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN); mAnimation.Play(); } else { - mIndicator.SetOpacity(0.0f); + mIndicator.SetProperty(Actor::Property::OPACITY, 0.0f); + } +} + +void ScrollBar::ShowTransientIndicator() +{ + // Cancel any animation + if(mAnimation) + { + mAnimation.Clear(); + mAnimation.Reset(); + } + + mAnimation = Animation::New(mIndicatorShowDuration + mTransientIndicatorDuration + mIndicatorHideDuration); + if(mIndicatorShowDuration > 0.0f) + { + mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA), + mIndicatorShowAlpha, + AlphaFunction::EASE_IN, + TimePeriod(0, mIndicatorShowDuration)); + } + else + { + mIndicator.SetProperty(Actor::Property::OPACITY, mIndicatorShowAlpha); } + mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA), + 0.0f, + AlphaFunction::EASE_IN, + TimePeriod((mIndicatorShowDuration + mTransientIndicatorDuration), mIndicatorHideDuration)); + mAnimation.Play(); } bool ScrollBar::OnPanGestureProcessTick() { // Update the scroll position property. - Handle scrollableHandle = mScrollableObject.GetBaseHandle(); - if( scrollableHandle ) + Handle scrollableHandle = mScrollableObject.GetHandle(); + if(scrollableHandle) { scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition); } @@ -416,47 +453,46 @@ bool ScrollBar::OnPanGestureProcessTick() return true; } -void ScrollBar::OnPan( const PanGesture& gesture ) +void ScrollBar::OnPan(const PanGesture& gesture) { - Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + Handle scrollableHandle = mScrollableObject.GetHandle(); if(scrollableHandle) { Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle); - switch(gesture.state) + switch(gesture.GetState()) { - case Gesture::Started: + case Dali::GestureState::STARTED: { - if( !mPanProcessTimer ) + if(!mPanProcessTimer) { // Make sure the pan gesture is only being processed once per frame. - mPanProcessTimer = Timer::New( DEFAULT_PAN_GESTURE_PROCESS_TIME ); - mPanProcessTimer.TickSignal().Connect( this, &ScrollBar::OnPanGestureProcessTick ); + mPanProcessTimer = Timer::New(DEFAULT_PAN_GESTURE_PROCESS_TIME); + mPanProcessTimer.TickSignal().Connect(this, &ScrollBar::OnPanGestureProcessTick); mPanProcessTimer.Start(); } ShowIndicator(); - mScrollStart = scrollableHandle.GetProperty(mPropertyScrollPosition); - mGestureDisplacement = Vector3::ZERO; - mIsPanning = true; + mScrollStart = scrollableHandle.GetCurrentProperty(mPropertyScrollPosition); + mGestureDisplacement = Vector2::ZERO; + mIsPanning = true; break; } - case Gesture::Continuing: + case Dali::GestureState::CONTINUING: { - mGestureDisplacement.x += gesture.displacement.x; - mGestureDisplacement.y += gesture.displacement.y; + mGestureDisplacement += gesture.GetDisplacement(); - float minScrollPosition = scrollableHandle.GetProperty( mPropertyMinScrollPosition ); - float maxScrollPosition = scrollableHandle.GetProperty( mPropertyMaxScrollPosition ); + float minScrollPosition = scrollableHandle.GetCurrentProperty(mPropertyMinScrollPosition); + float maxScrollPosition = scrollableHandle.GetCurrentProperty(mPropertyMaxScrollPosition); // The domain size is the internal range - float domainSize = maxScrollPosition - minScrollPosition; - float logicalSize = Self().GetCurrentSize().y - ( mIndicator.GetCurrentSize().y + mIndicatorStartPadding + mIndicatorEndPadding ); + float domainSize = maxScrollPosition - minScrollPosition; + float logicalSize = Self().GetCurrentProperty(Actor::Property::SIZE).y - (mIndicator.GetCurrentProperty(Actor::Property::SIZE).y + mIndicatorStartPadding + mIndicatorEndPadding); - mCurrentScrollPosition = mScrollStart - ( ( mGestureDisplacement.y * domainSize ) / logicalSize ); - mCurrentScrollPosition = -std::min( maxScrollPosition, std::max( -mCurrentScrollPosition, minScrollPosition ) ); + mCurrentScrollPosition = mScrollStart - ((mGestureDisplacement.y * domainSize) / logicalSize); + mCurrentScrollPosition = -std::min(maxScrollPosition, std::max(-mCurrentScrollPosition, minScrollPosition)); break; } @@ -464,11 +500,11 @@ void ScrollBar::OnPan( const PanGesture& gesture ) { mIsPanning = false; - if( mPanProcessTimer ) + if(mPanProcessTimer) { // Destroy the timer when pan gesture is finished. mPanProcessTimer.Stop(); - mPanProcessTimer.TickSignal().Disconnect( this, &ScrollBar::OnPanGestureProcessTick ); + mPanProcessTimer.TickSignal().Disconnect(this, &ScrollBar::OnPanGestureProcessTick); mPanProcessTimer.Reset(); } @@ -492,17 +528,17 @@ void ScrollBar::OnPan( const PanGesture& gesture ) } } -void ScrollBar::OnSizeSet( const Vector3& size ) +void ScrollBar::OnSizeSet(const Vector3& size) { - if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED) { - mIndicator.SetSize(size.width, mIndicatorFixedHeight); + mIndicator.SetProperty(Actor::Property::SIZE, Vector2(size.width, mIndicatorFixedHeight)); } - Control::OnSizeSet( size ); + Control::OnSizeSet(size); } -void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction ) +void ScrollBar::SetScrollDirection(Toolkit::ScrollBar::Direction direction) { mDirection = direction; } @@ -512,9 +548,9 @@ Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const return mDirection; } -void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy ) +void ScrollBar::SetIndicatorHeightPolicy(Toolkit::ScrollBar::IndicatorHeightPolicy policy) { - if( policy != mIndicatorHeightPolicy ) + if(policy != mIndicatorHeightPolicy) { mIndicatorHeightPolicy = policy; ApplyConstraints(); @@ -526,13 +562,13 @@ Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() return mIndicatorHeightPolicy; } -void ScrollBar::SetIndicatorFixedHeight( float height ) +void ScrollBar::SetIndicatorFixedHeight(float height) { mIndicatorFixedHeight = height; - if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED) { - mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + mIndicator.SetProperty(Actor::Property::SIZE, Vector2(Self().GetCurrentProperty(Actor::Property::SIZE).width, mIndicatorFixedHeight)); } } @@ -541,7 +577,7 @@ float ScrollBar::GetIndicatorFixedHeight() const return mIndicatorFixedHeight; } -void ScrollBar::SetIndicatorShowDuration( float durationSeconds ) +void ScrollBar::SetIndicatorShowDuration(float durationSeconds) { mIndicatorShowDuration = durationSeconds; } @@ -551,7 +587,7 @@ float ScrollBar::GetIndicatorShowDuration() const return mIndicatorShowDuration; } -void ScrollBar::SetIndicatorHideDuration( float durationSeconds ) +void ScrollBar::SetIndicatorHideDuration(float durationSeconds) { mIndicatorHideDuration = durationSeconds; } @@ -561,54 +597,54 @@ float ScrollBar::GetIndicatorHideDuration() const return mIndicatorHideDuration; } -void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue ) +void ScrollBar::OnScrollDirectionPropertySet(Property::Value propertyValue) { - std::string directionName( propertyValue.Get() ); - if(directionName == "Vertical") + std::string directionName(propertyValue.Get()); + if(directionName == "VERTICAL") { - SetScrollDirection(Toolkit::ScrollBar::Vertical); + SetScrollDirection(Toolkit::ScrollBar::VERTICAL); } - else if(directionName == "Horizontal") + else if(directionName == "HORIZONTAL") { - SetScrollDirection(Toolkit::ScrollBar::Horizontal); + SetScrollDirection(Toolkit::ScrollBar::HORIZONTAL); } else { - DALI_ASSERT_ALWAYS( !"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value." ); + DALI_ASSERT_ALWAYS(!"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value."); } } -void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue ) +void ScrollBar::OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue) { - std::string policyName( propertyValue.Get() ); - if(policyName == "Variable") + std::string policyName(propertyValue.Get()); + if(policyName == "VARIABLE") { - SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable); + SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE); } - else if(policyName == "Fixed") + else if(policyName == "FIXED") { - SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed); + SetIndicatorHeightPolicy(Toolkit::ScrollBar::FIXED); } else { - DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." ); + DALI_ASSERT_ALWAYS(!"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value."); } } -bool ScrollBar::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) +bool ScrollBar::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor) { - Dali::BaseHandle handle( object ); + Dali::BaseHandle handle(object); - bool connected( true ); - Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle ); + bool connected(true); + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(handle); - if( 0 == strcmp( signalName.c_str(), PAN_FINISHED_SIGNAL ) ) + if(0 == strcmp(signalName.c_str(), PAN_FINISHED_SIGNAL)) { - scrollBar.PanFinishedSignal().Connect( tracker, functor ); + scrollBar.PanFinishedSignal().Connect(tracker, functor); } - else if( 0 == strcmp( signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) ) + else if(0 == strcmp(signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL)) { - scrollBar.ScrollPositionIntervalReachedSignal().Connect( tracker, functor ); + scrollBar.ScrollPositionIntervalReachedSignal().Connect(tracker, functor); } else { @@ -619,23 +655,23 @@ bool ScrollBar::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* return connected; } -void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void ScrollBar::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) ); + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(Dali::BaseHandle(object)); - if( scrollBar ) + if(scrollBar) { - ScrollBar& scrollBarImpl( GetImpl( scrollBar ) ); - switch( index ) + ScrollBar& scrollBarImpl(GetImpl(scrollBar)); + switch(index) { case Toolkit::ScrollBar::Property::SCROLL_DIRECTION: { - scrollBarImpl.OnScrollDirectionPropertySet( value ); + scrollBarImpl.OnScrollDirectionPropertySet(value); break; } case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY: { - scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value ); + scrollBarImpl.OnIndicatorHeightPolicyPropertySet(value); break; } case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT: @@ -655,15 +691,15 @@ void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS: { - Property::Array* array = value.GetArray(); - if( array ) + const Property::Array* array = value.GetArray(); + if(array) { Dali::Vector positions; - size_t positionCount = array->Count(); - positions.Resize( positionCount ); - for( size_t i = 0; i != positionCount; ++i ) + size_t positionCount = array->Count(); + positions.Resize(positionCount); + for(size_t i = 0; i != positionCount; ++i) { - array->GetElementAt( i ).Get( positions[i] ); + array->GetElementAt(i).Get(positions[i]); } scrollBarImpl.SetScrollPositionIntervals(positions); @@ -688,29 +724,34 @@ void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Pr scrollBarImpl.ApplyConstraints(); break; } + case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION: + { + scrollBarImpl.mTransientIndicatorDuration = value.Get(); + break; + } } } } -Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index ) +Property::Value ScrollBar::GetProperty(BaseObject* object, Property::Index index) { Property::Value value; - Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) ); + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(Dali::BaseHandle(object)); - if( scrollBar ) + if(scrollBar) { - ScrollBar& scrollBarImpl( GetImpl( scrollBar ) ); - switch( index ) + ScrollBar& scrollBarImpl(GetImpl(scrollBar)); + switch(index) { case Toolkit::ScrollBar::Property::SCROLL_DIRECTION: { - value = SCROLL_DIRECTION_NAME[ scrollBarImpl.GetScrollDirection() ]; + value = SCROLL_DIRECTION_NAME[scrollBarImpl.GetScrollDirection()]; break; } case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY: { - value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ]; + value = INDICATOR_HEIGHT_POLICY_NAME[scrollBarImpl.GetIndicatorHeightPolicy()]; break; } case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT: @@ -730,17 +771,20 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde } case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS: { - Property::Value value( Property::ARRAY ); - Property::Array* array = value.GetArray(); + Property::Value tempValue(Property::ARRAY); + Property::Array* array = tempValue.GetArray(); - if( array ) + if(array) { Dali::Vector positions = scrollBarImpl.GetScrollPositionIntervals(); - size_t positionCount( array->Count() ); - for( size_t i( 0 ); i != positionCount; ++i ) + size_t positionCount(positions.Count()); + + for(size_t i(0); i != positionCount; ++i) { - array->PushBack( positions[i] ); + array->PushBack(positions[i]); } + + value = tempValue; } break; } @@ -759,18 +803,55 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde value = scrollBarImpl.mIndicatorEndPadding; break; } + case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION: + { + value = scrollBarImpl.mTransientIndicatorDuration; + break; + } } } return value; } +bool ScrollBar::DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes) +{ + bool ret = false; + + Dali::BaseHandle handle(object); + + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(handle); + + DALI_ASSERT_DEBUG(scrollBar); + + if(scrollBar) + { + if(0 == strcmp(actionName.c_str(), ACTION_SHOW_INDICATOR)) + { + GetImpl(scrollBar).ShowIndicator(); + ret = true; + } + else if(0 == strcmp(actionName.c_str(), ACTION_HIDE_INDICATOR)) + { + GetImpl(scrollBar).HideIndicator(); + ret = true; + } + else if(0 == strcmp(actionName.c_str(), ACTION_SHOW_TRANSIENT_INDICATOR)) + { + GetImpl(scrollBar).ShowTransientIndicator(); + ret = true; + } + } + + return ret; +} + Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction) { // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr< ScrollBar > impl = new ScrollBar(direction); + IntrusivePtr impl = new ScrollBar(direction); // Pass ownership to CustomActor handle - Toolkit::ScrollBar handle( *impl ); + Toolkit::ScrollBar handle(*impl); // Second-phase init of the implementation // This can only be done after the CustomActor connection has been made... @@ -779,6 +860,53 @@ Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction) return handle; } +double ScrollBar::AccessibleImpl::GetMinimum() +{ + auto p = Toolkit::ScrollBar::DownCast(self); + Handle scrollableHandle = GetImpl(p).mScrollableObject.GetHandle(); + return scrollableHandle ? scrollableHandle.GetCurrentProperty(GetImpl(p).mPropertyMinScrollPosition) : 0.0f; +} + +double ScrollBar::AccessibleImpl::GetCurrent() +{ + auto p = Toolkit::ScrollBar::DownCast(self); + Handle scrollableHandle = GetImpl(p).mScrollableObject.GetHandle(); + return scrollableHandle ? scrollableHandle.GetCurrentProperty(GetImpl(p).mPropertyScrollPosition) : 0.0f; +} + +double ScrollBar::AccessibleImpl::GetMaximum() +{ + auto p = Toolkit::ScrollBar::DownCast(self); + Handle scrollableHandle = GetImpl(p).mScrollableObject.GetHandle(); + return scrollableHandle ? scrollableHandle.GetCurrentProperty(GetImpl(p).mPropertyMaxScrollPosition) : 1.0f; +} + +bool ScrollBar::AccessibleImpl::SetCurrent(double current) +{ + if(current < GetMinimum() || current > GetMaximum()) + return false; + + auto value_before = GetCurrent(); + + auto p = Toolkit::ScrollBar::DownCast(self); + Handle scrollableHandle = GetImpl(p).mScrollableObject.GetHandle(); + if(!scrollableHandle) + return false; + scrollableHandle.SetProperty(GetImpl(p).mPropertyScrollPosition, static_cast(current)); + + auto value_after = GetCurrent(); + + if((current != value_before) && (value_before == value_after)) + return false; + + return true; +} + +double ScrollBar::AccessibleImpl::GetMinimumIncrement() +{ + return 1.0; +} + } // namespace Internal } // namespace Toolkit