X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Faccessibility-manager%2Faccessibility-manager-impl.cpp;h=e336eeeabf00beb49043c8495a8a6d50c000f37d;hb=81b6946e6eae9989ba04ba164adf9347e85efdfe;hp=935e09fa61af1715770aa933fef7564e0f867d65;hpb=4b9580f45559ab748c5eb33cbe4a771de88770cf;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp b/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp index 935e09f..e336eee 100644 --- a/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp +++ b/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 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. @@ -25,12 +25,14 @@ #include #include #include -#include +#include #include // INTERNAL INCLUDES +#include #include #include +#include namespace Dali { @@ -46,22 +48,21 @@ namespace // unnamed namespace // Signals -const char* const SIGNAL_FOCUS_CHANGED = "focus-changed"; -const char* const SIGNAL_FOCUS_OVERSHOT = "focus-overshot"; -const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED = "focused-actor-activated"; +const char* const SIGNAL_FOCUS_CHANGED = "focusChanged"; +const char* const SIGNAL_FOCUS_OVERSHOT = "focusOvershot"; +const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED = "focusedActorActivated"; #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FOCUS_MANAGER"); #endif const char* const ACTOR_FOCUSABLE("focusable"); -const char* const IS_FOCUS_GROUP("is-focus-group"); +const char* const IS_FOCUS_GROUP("isFocusGroup"); -const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "B16-8_TTS_focus.png"; -const Vector4 FOCUS_BORDER_IMAGE_BORDER = Vector4(7.0f, 7.0f, 7.0f, 7.0f); +const char* FOCUS_BORDER_IMAGE_FILE_NAME = "B16-8_TTS_focus.9.png"; -const char* FOCUS_SOUND_FILE = DALI_SOUND_DIR "Focus.ogg"; -const char* FOCUS_CHAIN_END_SOUND_FILE = DALI_SOUND_DIR "End_of_List.ogg"; +const char* FOCUS_SOUND_FILE_NAME = "Focus.ogg"; +const char* FOCUS_CHAIN_END_SOUND_FILE_NAME = "End_of_List.ogg"; /** * The function to be used in the hit-test algorithm to check whether the actor is hittable. @@ -75,8 +76,8 @@ bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType case Dali::HitTestAlgorithm::CHECK_ACTOR: { // Check whether the actor is visible and not fully transparent. - if( actor.IsVisible() - && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT + if( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) + && actor.GetCurrentProperty< Vector4 >( Actor::Property::WORLD_COLOR ).a > 0.01f) // not FULLY_TRANSPARENT { // Check whether the actor is focusable Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE); @@ -89,7 +90,7 @@ bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType } case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE: { - if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible. + if( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) // Actor is visible, if not visible then none of its children are visible. { hittable = true; } @@ -108,8 +109,12 @@ bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType AccessibilityManager::AccessibilityManager() : mCurrentFocusActor(FocusIDPair(0, 0)), - mFocusIndicatorActor(Actor()), + mCurrentGesturedActor(), + mFocusIndicatorActor(), + mPreviousPosition( 0.0f, 0.0f ), mRecursiveFocusMoveCounter(0), + mFocusSoundFilePath(), + mFocusChainEndSoundFilePath(), mIsWrapped(false), mIsFocusWithinGroup(false), mIsEndcapFeedbackEnabled(false), @@ -117,7 +122,9 @@ AccessibilityManager::AccessibilityManager() mIsAccessibilityTtsEnabled(false), mTtsCreated(false), mIsFocusIndicatorEnabled(false), - mContinuousPlayMode(false) + mContinuousPlayMode(false), + mIsFocusSoundFilePathSet(false), + mIsFocusChainEndSoundFilePathSet(false) { } @@ -127,8 +134,6 @@ AccessibilityManager::~AccessibilityManager() void AccessibilityManager::Initialise() { - CreateDefaultFocusIndicatorActor(); - AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get(); adaptor.SetActionHandler(*this); adaptor.SetGestureHandler(*this); @@ -160,7 +165,7 @@ void AccessibilityManager::SetAccessibilityAttribute(Actor actor, Toolkit::Acces { if(actor) { - unsigned int actorID = actor.GetId(); + unsigned int actorID = actor.GetProperty< int >( Actor::Property::ID ); ActorAdditionalInfo info = GetActorAdditionalInfo(actorID); info.mAccessibilityAttributes[type] = text; @@ -176,7 +181,7 @@ std::string AccessibilityManager::GetAccessibilityAttribute(Actor actor, Toolkit if(actor) { - ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId()); + ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetProperty< int >( Actor::Property::ID )); text = data.mAccessibilityAttributes[type]; } @@ -191,12 +196,8 @@ void AccessibilityManager::SetFocusOrder(Actor actor, const unsigned int order) // Firstly delete the actor from the focus chain if it's already there with a different focus order. mFocusIDContainer.erase(GetFocusOrder(actor)); - // Create actor focusable property if not already created. - Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE); - if(propertyActorFocusable == Property::INVALID_INDEX) - { - propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE ); - } + // Create/retrieve actor focusable property + Property::Index propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE ); if(order == 0) { @@ -242,11 +243,11 @@ void AccessibilityManager::SetFocusOrder(Actor actor, const unsigned int order) actor.SetProperty(propertyActorFocusable, true); // Now we insert the actor into the focus chain with the specified focus order - mFocusIDContainer.insert(FocusIDPair(order, actor.GetId())); + mFocusIDContainer.insert(FocusIDPair(order, actor.GetProperty< int >( Actor::Property::ID ))); } // Update the actor's focus order in its additional data - SynchronizeActorAdditionalInfo(actor.GetId(), order); + SynchronizeActorAdditionalInfo(actor.GetProperty< int >( Actor::Property::ID ), order); } } @@ -256,7 +257,7 @@ unsigned int AccessibilityManager::GetFocusOrder(Actor actor) const if(actor) { - ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId()); + ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetProperty< int >( Actor::Property::ID )); focusOrder = data.mFocusOrder; } @@ -294,7 +295,7 @@ bool AccessibilityManager::SetCurrentFocusActor(Actor actor) { if(actor) { - return DoSetCurrentFocusActor(actor.GetId()); + return DoSetCurrentFocusActor(actor.GetProperty< int >( Actor::Property::ID )); } return false; @@ -330,24 +331,24 @@ bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID) } // Go through the actor's hierarchy to check whether the actor is visible - bool actorVisible = actor.IsVisible(); + bool actorVisible = actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ); Actor parent = actor.GetParent(); while (actorVisible && parent && parent != rootActor) { - actorVisible = parent.IsVisible(); + actorVisible = parent.GetCurrentProperty< bool >( Actor::Property::VISIBLE ); parent = parent.GetParent(); } // Check whether the actor is fully transparent - bool actorOpaque = actor.GetCurrentWorldColor().a > 0.01f; + bool actorOpaque = actor.GetCurrentProperty< Vector4 >( Actor::Property::WORLD_COLOR ).a > 0.01f; // Set the focus only when the actor is focusable and visible and not fully transparent if(actorVisible && actorFocusable && actorOpaque) { // Draw the focus indicator upon the focused actor - if(mIsFocusIndicatorEnabled && mFocusIndicatorActor) + if( mIsFocusIndicatorEnabled ) { - actor.Add(mFocusIndicatorActor); + actor.Add( GetFocusIndicatorActor() ); } // Send notification for the change of focus actor @@ -361,7 +362,13 @@ bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID) Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get(); if(soundPlayer) { - soundPlayer.PlaySound(FOCUS_SOUND_FILE); + if (!mIsFocusSoundFilePathSet) + { + const std::string soundDirPath = AssetManager::GetDaliSoundPath(); + mFocusSoundFilePath = soundDirPath + FOCUS_SOUND_FILE_NAME; + mIsFocusSoundFilePathSet = true; + } + soundPlayer.PlaySound(mFocusSoundFilePath); } // Play the accessibility attributes with the TTS player. @@ -483,9 +490,9 @@ void AccessibilityManager::DoActivate(Actor actor) void AccessibilityManager::ClearFocus() { Actor actor = GetCurrentFocusActor(); - if(actor) + if( actor && mFocusIndicatorActor ) { - actor.Remove(mFocusIndicatorActor); + actor.Remove( mFocusIndicatorActor ); } mCurrentFocusActor = FocusIDPair(0, 0); @@ -512,16 +519,8 @@ void AccessibilityManager::SetFocusGroup(Actor actor, bool isFocusGroup) { if(actor) { - // Create focus group property if not already created. - Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP); - if(propertyIsFocusGroup == Property::INVALID_INDEX) - { - actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE ); - } - else - { - actor.SetProperty(propertyIsFocusGroup, isFocusGroup); - } + // Create/Set focus group property. + actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE ); } } @@ -581,11 +580,43 @@ bool AccessibilityManager::GetWrapMode() const void AccessibilityManager::SetFocusIndicatorActor(Actor indicator) { - mFocusIndicatorActor = indicator; + if( mFocusIndicatorActor != indicator ) + { + Actor currentFocusActor = GetCurrentFocusActor(); + if( currentFocusActor ) + { + // The new focus indicator should be added to the current focused actor immediately + if( mFocusIndicatorActor ) + { + currentFocusActor.Remove( mFocusIndicatorActor ); + } + + if( indicator ) + { + currentFocusActor.Add( indicator ); + } + } + + mFocusIndicatorActor = indicator; + } } Actor AccessibilityManager::GetFocusIndicatorActor() { + if( ! mFocusIndicatorActor ) + { + // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors + const std::string imageDirPath = AssetManager::GetDaliImagePath(); + const std::string focusBorderImagePath = imageDirPath + FOCUS_BORDER_IMAGE_FILE_NAME; + + mFocusIndicatorActor = Toolkit::ImageView::New(focusBorderImagePath); + mFocusIndicatorActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mFocusIndicatorActor.SetProperty( Actor::Property::POSITION_Z, 1.0f ); + + // Apply size constraint to the focus indicator + mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + } + return mFocusIndicatorActor; } @@ -605,7 +636,13 @@ bool AccessibilityManager::DoMoveFocus(FocusIDIter focusIDIter, bool forward, bo Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get(); if(soundPlayer) { - soundPlayer.PlaySound(FOCUS_CHAIN_END_SOUND_FILE); + if (!mIsFocusChainEndSoundFilePathSet) + { + const std::string soundDirPath = AssetManager::GetDaliSoundPath(); + mFocusChainEndSoundFilePath = soundDirPath + FOCUS_CHAIN_END_SOUND_FILE_NAME; + mIsFocusChainEndSoundFilePathSet = true; + } + soundPlayer.PlaySound(mFocusChainEndSoundFilePath); } mIsEndcapFeedbackPlayed = true; @@ -667,36 +704,11 @@ void AccessibilityManager::SetFocusable(Actor actor, bool focusable) { if(actor) { - // Create actor focusable property if not already created. - Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE); - if(propertyActorFocusable == Property::INVALID_INDEX) - { - actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE ); - } - else - { - actor.SetProperty(propertyActorFocusable, focusable); - } + // Create/Set actor focusable property. + actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE ); } } -void AccessibilityManager::CreateDefaultFocusIndicatorActor() -{ - // Create a focus indicator actor shared by all the focusable actors - Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH); - - ImageActor focusIndicator = ImageActor::New(borderImage); - focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION ); - focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH ); - focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER); - focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f)); - - // Apply size constraint to the focus indicator - focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - SetFocusIndicatorActor(focusIndicator); -} - bool AccessibilityManager::ChangeAccessibilityStatus() { AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get(); @@ -709,10 +721,7 @@ bool AccessibilityManager::ChangeAccessibilityStatus() Actor actor = GetCurrentFocusActor(); if(actor) { - if(mFocusIndicatorActor) - { - actor.Add(mFocusIndicatorActor); - } + actor.Add( GetFocusIndicatorActor() ); } mIsFocusIndicatorEnabled = true; @@ -725,9 +734,9 @@ bool AccessibilityManager::ChangeAccessibilityStatus() { // Hide indicator when tts turned off Actor actor = GetCurrentFocusActor(); - if(actor) + if( actor && mFocusIndicatorActor ) { - actor.Remove(mFocusIndicatorActor); + actor.Remove( mFocusIndicatorActor ); } mIsFocusIndicatorEnabled = false; @@ -955,12 +964,12 @@ bool AccessibilityManager::ClearAccessibilityFocus() } } -bool AccessibilityManager::AccessibilityActionScroll( Dali::TouchEvent& touchEvent ) +bool AccessibilityManager::AccessibilityActionScroll( Dali::TouchEvent& touch ) { Dali::Toolkit::AccessibilityManager handle( this ); if( !mActionScrollSignal.Empty() ) { - mActionScrollSignal.Emit( handle, touchEvent ); + mActionScrollSignal.Emit( handle, touch ); } return true; @@ -1251,19 +1260,6 @@ bool AccessibilityManager::AccessibilityActionZoom() return ret; } -bool AccessibilityManager::AccessibilityActionReadIndicatorInformation() -{ - Dali::Toolkit::AccessibilityManager handle( this ); - if( !mActionReadIndicatorInformationSignal.Empty() ) - { - mActionReadIndicatorInformationSignal.Emit( handle ); - } - - // TODO: Read the information in the indicator - - return mIsAccessibilityTtsEnabled; -} - bool AccessibilityManager::AccessibilityActionReadPauseResume() { Dali::Toolkit::AccessibilityManager handle( this ); @@ -1307,26 +1303,11 @@ bool AccessibilityManager::AccessibilityActionStartStop() return mIsAccessibilityTtsEnabled; } -bool AccessibilityManager::AccessibilityActionTouch(const TouchEvent& touchEvent) +bool AccessibilityManager::HandlePanGesture(const AccessibilityGestureEvent& panEvent) { bool handled = false; - // TODO: Need to convert the touchevent for the focused actor? - - Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(GetCurrentFocusActor()); - if(control) - { - handled = GetImplementation( control ).OnAccessibilityTouch(touchEvent); - } - - return handled; -} - -bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& panEvent) -{ - bool handled = false; - - if( panEvent.state == Gesture::Started ) + if( panEvent.state == AccessibilityGestureEvent::STARTED ) { // Find the focusable actor at the event position Dali::HitTestAlgorithm::Results results; @@ -1337,27 +1318,26 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& if(!mCurrentGesturedActor) { - DALI_LOG_ERROR("Gesture detected, but no hit actor"); + DALI_LOG_ERROR("Gesture detected, but no hit actor\n"); } } - // Gesture::Finished (Up) events are delivered with previous (Motion) event position + // GestureState::FINISHED (Up) events are delivered with previous (Motion) event position // Use the real previous position; otherwise we may incorrectly get a ZERO velocity - if ( Gesture::Finished != panEvent.state ) + if ( AccessibilityGestureEvent::FINISHED != panEvent.state ) { - // Store the previous position for next Gesture::Finished iteration. + // Store the previous position for next GestureState::FINISHED iteration. mPreviousPosition = panEvent.previousPosition; } Actor rootActor = Stage::GetCurrent().GetRootLayer(); - Dali::PanGesture pan(panEvent.state); - pan.time = panEvent.time; - pan.numberOfTouches = panEvent.numberOfTouches; - pan.screenPosition = panEvent.currentPosition; - pan.screenDisplacement = mPreviousPosition - panEvent.currentPosition; - pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta; - pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta; + Dali::PanGesture pan = DevelPanGesture::New( static_cast(panEvent.state) ); + DevelPanGesture::SetTime( pan, panEvent.time ); + DevelPanGesture::SetNumberOfTouches( pan, panEvent.numberOfTouches ); + DevelPanGesture::SetScreenPosition( pan, panEvent.currentPosition ); + DevelPanGesture::SetScreenDisplacement( pan, mPreviousPosition - panEvent.currentPosition ); + DevelPanGesture::SetScreenVelocity( pan, Vector2( pan.GetScreenDisplacement().x / panEvent.timeDelta, pan.GetScreenDisplacement().y / panEvent.timeDelta ) ); // Only handle the pan gesture when the current focused actor is scrollable or within a scrollable actor while(mCurrentGesturedActor && mCurrentGesturedActor != rootActor && !handled) @@ -1367,14 +1347,13 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& { Vector2 localCurrent; control.ScreenToLocal( localCurrent.x, localCurrent.y, panEvent.currentPosition.x, panEvent.currentPosition.y ); - pan.position = localCurrent; + DevelPanGesture::SetPosition( pan, localCurrent ); Vector2 localPrevious; control.ScreenToLocal( localPrevious.x, localPrevious.y, mPreviousPosition.x, mPreviousPosition.y ); - pan.displacement = localCurrent - localPrevious; - pan.velocity.x = pan.displacement.x / panEvent.timeDelta; - pan.velocity.y = pan.displacement.y / panEvent.timeDelta; + DevelPanGesture::SetDisplacement( pan, localCurrent - localPrevious ); + DevelPanGesture::SetVelocity( pan, Vector2( pan.GetDisplacement().x / panEvent.timeDelta, pan.GetDisplacement().y / panEvent.timeDelta )); handled = GetImplementation( control ).OnAccessibilityPan(pan); } @@ -1386,7 +1365,7 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& if(!mCurrentGesturedActor) { - DALI_LOG_ERROR("no more gestured actor"); + DALI_LOG_ERROR("no more gestured actor\n"); } } else @@ -1414,34 +1393,6 @@ Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& AccessibilityMan return mFocusedActorActivatedSignal; } -bool AccessibilityManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) -{ - Dali::BaseHandle handle( object ); - - bool connected( true ); - AccessibilityManager* manager = dynamic_cast( object ); - - if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) ) - { - manager->FocusChangedSignal().Connect( tracker, functor ); - } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_OVERSHOT ) ) - { - manager->FocusOvershotSignal().Connect( tracker, functor ); - } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ACTIVATED ) ) - { - manager->FocusedActorActivatedSignal().Connect( tracker, functor ); - } - else - { - // signalName does not match any signal - connected = false; - } - - return connected; -} - } // namespace Internal } // namespace Toolkit