2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "accessibility-manager-impl.h"
22 #include <cstring> // for strcmp
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
25 #include <dali/devel-api/adaptor-framework/sound-player.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/devel-api/events/hit-test-algorithm.h>
28 #include <dali/public-api/images/resource-image.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/controls/control.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
44 namespace // unnamed namespace
49 const char* const SIGNAL_FOCUS_CHANGED = "focusChanged";
50 const char* const SIGNAL_FOCUS_OVERSHOT = "focusOvershot";
51 const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED = "focusedActorActivated";
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FOCUS_MANAGER");
57 const char* const ACTOR_FOCUSABLE("focusable");
58 const char* const IS_FOCUS_GROUP("isFocusGroup");
60 const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "B16-8_TTS_focus.png";
61 const Vector4 FOCUS_BORDER_IMAGE_BORDER = Vector4(7.0f, 7.0f, 7.0f, 7.0f);
63 const char* FOCUS_SOUND_FILE = DALI_SOUND_DIR "Focus.ogg";
64 const char* FOCUS_CHAIN_END_SOUND_FILE = DALI_SOUND_DIR "End_of_List.ogg";
67 * The function to be used in the hit-test algorithm to check whether the actor is hittable.
69 bool IsActorFocusableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
71 bool hittable = false;
75 case Dali::HitTestAlgorithm::CHECK_ACTOR:
77 // Check whether the actor is visible and not fully transparent.
79 && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
81 // Check whether the actor is focusable
82 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
83 if(propertyActorFocusable != Property::INVALID_INDEX)
85 hittable = actor.GetProperty<bool>(propertyActorFocusable);
90 case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
92 if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
109 AccessibilityManager::AccessibilityManager()
110 : mCurrentFocusActor(FocusIDPair(0, 0)),
111 mFocusIndicatorActor(Actor()),
112 mRecursiveFocusMoveCounter(0),
114 mIsFocusWithinGroup(false),
115 mIsEndcapFeedbackEnabled(false),
116 mIsEndcapFeedbackPlayed(false),
117 mIsAccessibilityTtsEnabled(false),
119 mIsFocusIndicatorEnabled(false),
120 mContinuousPlayMode(false)
124 AccessibilityManager::~AccessibilityManager()
128 void AccessibilityManager::Initialise()
130 CreateDefaultFocusIndicatorActor();
132 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
133 adaptor.SetActionHandler(*this);
134 adaptor.SetGestureHandler(*this);
136 ChangeAccessibilityStatus();
139 AccessibilityManager::ActorAdditionalInfo AccessibilityManager::GetActorAdditionalInfo(const unsigned int actorID) const
141 ActorAdditionalInfo data;
142 IDAdditionalInfoConstIter iter = mIDAdditionalInfoContainer.find(actorID);
143 if(iter != mIDAdditionalInfoContainer.end())
145 data = (*iter).second;
151 void AccessibilityManager::SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order)
153 ActorAdditionalInfo actorInfo = GetActorAdditionalInfo(actorID);
154 actorInfo.mFocusOrder = order;
155 mIDAdditionalInfoContainer.erase(actorID);
156 mIDAdditionalInfoContainer.insert(IDAdditionalInfoPair(actorID, actorInfo));
159 void AccessibilityManager::SetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type, const std::string& text)
163 unsigned int actorID = actor.GetId();
165 ActorAdditionalInfo info = GetActorAdditionalInfo(actorID);
166 info.mAccessibilityAttributes[type] = text;
168 mIDAdditionalInfoContainer.erase(actorID);
169 mIDAdditionalInfoContainer.insert(IDAdditionalInfoPair(actorID, info));
173 std::string AccessibilityManager::GetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type) const
179 ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId());
180 text = data.mAccessibilityAttributes[type];
186 void AccessibilityManager::SetFocusOrder(Actor actor, const unsigned int order)
188 // Do nothing if the focus order of the actor is not changed.
189 if(actor && GetFocusOrder(actor) != order)
191 // Firstly delete the actor from the focus chain if it's already there with a different focus order.
192 mFocusIDContainer.erase(GetFocusOrder(actor));
194 // Create/retrieve actor focusable property
195 Property::Index propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE );
199 // The actor is not focusable without a defined focus order.
200 actor.SetProperty(propertyActorFocusable, false);
202 // If the actor is currently being focused, it should clear the focus
203 if(actor == GetCurrentFocusActor())
208 else // Insert the actor to the focus chain
210 // Check whether there is another actor in the focus chain with the same focus order already.
211 FocusIDIter focusIDIter = mFocusIDContainer.find(order);
212 if(focusIDIter != mFocusIDContainer.end())
214 // We need to increase the focus order of that actor and all the actors followed it
215 // in the focus chain.
216 FocusIDIter lastIter = mFocusIDContainer.end();
217 --lastIter;//We want forward iterator to the last element here
218 mFocusIDContainer.insert(FocusIDPair((*lastIter).first + 1, (*lastIter).second));
220 // Update the actor's focus order in its additional data
221 SynchronizeActorAdditionalInfo((*lastIter).second, (*lastIter).first + 1);
223 for(FocusIDIter iter = lastIter; iter != focusIDIter; iter--)
225 FocusIDIter previousIter = iter;
226 --previousIter;//We want forward iterator to the previous element here
227 unsigned int actorID = (*previousIter).second;
228 (*iter).second = actorID;
230 // Update the actor's focus order in its additional data
231 SynchronizeActorAdditionalInfo(actorID, (*iter).first);
234 mFocusIDContainer.erase(order);
237 // The actor is focusable
238 actor.SetProperty(propertyActorFocusable, true);
240 // Now we insert the actor into the focus chain with the specified focus order
241 mFocusIDContainer.insert(FocusIDPair(order, actor.GetId()));
244 // Update the actor's focus order in its additional data
245 SynchronizeActorAdditionalInfo(actor.GetId(), order);
249 unsigned int AccessibilityManager::GetFocusOrder(Actor actor) const
251 unsigned int focusOrder = 0;
255 ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId());
256 focusOrder = data.mFocusOrder;
262 unsigned int AccessibilityManager::GenerateNewFocusOrder() const
264 unsigned int order = 1;
265 FocusIDContainer::const_reverse_iterator iter = mFocusIDContainer.rbegin();
267 if(iter != mFocusIDContainer.rend())
269 order = (*iter).first + 1;
275 Actor AccessibilityManager::GetActorByFocusOrder(const unsigned int order)
277 Actor actor = Actor();
279 FocusIDIter focusIDIter = mFocusIDContainer.find(order);
280 if(focusIDIter != mFocusIDContainer.end())
282 Actor rootActor = Stage::GetCurrent().GetRootLayer();
283 actor = rootActor.FindChildById(mFocusIDContainer[order]);
289 bool AccessibilityManager::SetCurrentFocusActor(Actor actor)
293 return DoSetCurrentFocusActor(actor.GetId());
299 bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID)
301 Actor rootActor = Stage::GetCurrent().GetRootLayer();
303 // If the group mode is enabled, check which focus group the current focused actor belongs to
305 if(mIsFocusWithinGroup)
307 focusGroup = GetFocusGroup(GetCurrentFocusActor());
312 focusGroup = rootActor;
315 Actor actor = focusGroup.FindChildById(actorID);
317 // Check whether the actor is in the stage
320 // Check whether the actor is focusable
321 bool actorFocusable = false;
322 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
323 if(propertyActorFocusable != Property::INVALID_INDEX)
325 actorFocusable = actor.GetProperty<bool>(propertyActorFocusable);
328 // Go through the actor's hierarchy to check whether the actor is visible
329 bool actorVisible = actor.IsVisible();
330 Actor parent = actor.GetParent();
331 while (actorVisible && parent && parent != rootActor)
333 actorVisible = parent.IsVisible();
334 parent = parent.GetParent();
337 // Check whether the actor is fully transparent
338 bool actorOpaque = actor.GetCurrentWorldColor().a > 0.01f;
340 // Set the focus only when the actor is focusable and visible and not fully transparent
341 if(actorVisible && actorFocusable && actorOpaque)
343 // Draw the focus indicator upon the focused actor
344 if(mIsFocusIndicatorEnabled && mFocusIndicatorActor)
346 actor.Add(mFocusIndicatorActor);
349 // Send notification for the change of focus actor
350 mFocusChangedSignal.Emit( GetCurrentFocusActor(), actor );
352 // Save the current focused actor
353 mCurrentFocusActor = FocusIDPair(GetFocusOrder(actor), actorID);
355 if(mIsAccessibilityTtsEnabled)
357 Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get();
360 soundPlayer.PlaySound(FOCUS_SOUND_FILE);
363 // Play the accessibility attributes with the TTS player.
364 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
366 // Combine attribute texts to one text
367 std::string informationText;
368 for(int i = 0; i < Toolkit::AccessibilityManager::ACCESSIBILITY_ATTRIBUTE_NUM; i++)
370 if(!GetActorAdditionalInfo(actorID).mAccessibilityAttributes[i].empty())
374 informationText += ", "; // for space time between each information
376 informationText += GetActorAdditionalInfo(actorID).mAccessibilityAttributes[i];
379 player.Play(informationText);
386 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
390 Actor AccessibilityManager::GetCurrentFocusActor()
392 Actor rootActor = Stage::GetCurrent().GetRootLayer();
393 return rootActor.FindChildById(mCurrentFocusActor.second);
396 Actor AccessibilityManager::GetCurrentFocusGroup()
398 return GetFocusGroup(GetCurrentFocusActor());
401 unsigned int AccessibilityManager::GetCurrentFocusOrder()
403 return mCurrentFocusActor.first;
406 bool AccessibilityManager::MoveFocusForward()
409 mRecursiveFocusMoveCounter = 0;
411 FocusIDIter focusIDIter = mFocusIDContainer.find(mCurrentFocusActor.first);
412 if(focusIDIter != mFocusIDContainer.end())
414 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
415 ret = DoMoveFocus(focusIDIter, true, mIsWrapped);
419 // TODO: if there is not focused actor, move first actor
420 if(!mFocusIDContainer.empty())
422 //if there is not focused actor, move 1st actor
423 focusIDIter = mFocusIDContainer.begin(); // TODO: I'm not sure it was sorted.
424 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
425 ret = DoSetCurrentFocusActor((*focusIDIter).second);
429 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s] %s\n", __FUNCTION__, ret?"SUCCEED!!!":"FAILED!!!");
434 bool AccessibilityManager::MoveFocusBackward()
437 mRecursiveFocusMoveCounter = 0;
439 FocusIDIter focusIDIter = mFocusIDContainer.find(mCurrentFocusActor.first);
440 if(focusIDIter != mFocusIDContainer.end())
442 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
443 ret = DoMoveFocus(focusIDIter, false, mIsWrapped);
447 // TODO: if there is not focused actor, move last actor
448 if(!mFocusIDContainer.empty())
450 //if there is not focused actor, move last actor
451 focusIDIter = mFocusIDContainer.end();
452 --focusIDIter;//We want forward iterator to the last element here
453 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
454 ret = DoSetCurrentFocusActor((*focusIDIter).second);
458 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s] %s\n", __FUNCTION__, ret?"SUCCEED!!!":"FAILED!!!");
463 void AccessibilityManager::DoActivate(Actor actor)
467 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
470 // Notify the control that it is activated
471 GetImplementation( control ).AccessibilityActivate();
474 // Send notification for the activation of focused actor
475 mFocusedActorActivatedSignal.Emit(actor);
479 void AccessibilityManager::ClearFocus()
481 Actor actor = GetCurrentFocusActor();
484 actor.Remove(mFocusIndicatorActor);
487 mCurrentFocusActor = FocusIDPair(0, 0);
489 // Send notification for the change of focus actor
490 mFocusChangedSignal.Emit(actor, Actor());
492 if(mIsAccessibilityTtsEnabled)
494 // Stop the TTS playing if any
495 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
500 void AccessibilityManager::Reset()
503 mFocusIDContainer.clear();
504 mIDAdditionalInfoContainer.clear();
507 void AccessibilityManager::SetFocusGroup(Actor actor, bool isFocusGroup)
511 // Create/Set focus group property.
512 actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE );
516 bool AccessibilityManager::IsFocusGroup(Actor actor) const
518 // Check whether the actor is a focus group
519 bool isFocusGroup = false;
523 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP);
524 if(propertyIsFocusGroup != Property::INVALID_INDEX)
526 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
533 Actor AccessibilityManager::GetFocusGroup(Actor actor)
535 // Go through the actor's hierarchy to check which focus group the actor belongs to
536 while (actor && !IsFocusGroup(actor))
538 actor = actor.GetParent();
544 Vector2 AccessibilityManager::GetReadPosition() const
546 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
547 return adaptor.GetReadPosition();
550 void AccessibilityManager::SetGroupMode(bool enabled)
552 mIsFocusWithinGroup = enabled;
555 bool AccessibilityManager::GetGroupMode() const
557 return mIsFocusWithinGroup;
560 void AccessibilityManager::SetWrapMode(bool wrapped)
562 mIsWrapped = wrapped;
565 bool AccessibilityManager::GetWrapMode() const
570 void AccessibilityManager::SetFocusIndicatorActor(Actor indicator)
572 mFocusIndicatorActor = indicator;
575 Actor AccessibilityManager::GetFocusIndicatorActor()
577 return mFocusIndicatorActor;
580 bool AccessibilityManager::DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped)
582 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] %d focusable actors\n", __FUNCTION__, __LINE__, mFocusIDContainer.size());
583 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
585 if( (forward && ++focusIDIter == mFocusIDContainer.end())
586 || (!forward && focusIDIter-- == mFocusIDContainer.begin()) )
588 if(mIsEndcapFeedbackEnabled)
590 if(mIsEndcapFeedbackPlayed == false)
592 // play sound & skip moving once
593 Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get();
596 soundPlayer.PlaySound(FOCUS_CHAIN_END_SOUND_FILE);
599 mIsEndcapFeedbackPlayed = true;
602 mIsEndcapFeedbackPlayed = false;
609 focusIDIter = mFocusIDContainer.begin();
613 focusIDIter = mFocusIDContainer.end();
614 --focusIDIter;//We want forward iterator to the last element here
619 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Overshot\n", __FUNCTION__, __LINE__);
620 // Send notification for handling overshooted situation
621 mFocusOvershotSignal.Emit(GetCurrentFocusActor(), forward ? Toolkit::AccessibilityManager::OVERSHOT_NEXT : Toolkit::AccessibilityManager::OVERSHOT_PREVIOUS);
623 return false; // Try to move the focus out of the scope
628 if( focusIDIter == mFocusIDContainer.end() )
633 // Note: This function performs the focus change.
634 if( !DoSetCurrentFocusActor( (*focusIDIter).second ) )
636 mRecursiveFocusMoveCounter++;
637 if(mRecursiveFocusMoveCounter > mFocusIDContainer.size())
639 // We've attempted to focus all the actors in the whole focus chain and no actor
640 // can be focused successfully.
641 DALI_LOG_WARNING("[%s] There is no more focusable actor in %d focus chains\n", __FUNCTION__, mRecursiveFocusMoveCounter);
647 return DoMoveFocus(focusIDIter, forward, wrapped);
654 void AccessibilityManager::SetFocusable(Actor actor, bool focusable)
658 // Create/Set actor focusable property.
659 actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE );
663 void AccessibilityManager::CreateDefaultFocusIndicatorActor()
665 // Create a focus indicator actor shared by all the focusable actors
666 Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH);
668 ImageActor focusIndicator = ImageActor::New(borderImage);
669 focusIndicator.SetParentOrigin( ParentOrigin::CENTER );
670 focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
671 focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER);
672 focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
674 // Apply size constraint to the focus indicator
675 focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
677 SetFocusIndicatorActor(focusIndicator);
680 bool AccessibilityManager::ChangeAccessibilityStatus()
682 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
683 mIsAccessibilityTtsEnabled = adaptor.IsEnabled();
684 Dali::Toolkit::AccessibilityManager handle( this );
686 if(mIsAccessibilityTtsEnabled)
688 // Show indicator when tts turned on if there is focused actor.
689 Actor actor = GetCurrentFocusActor();
692 if(mFocusIndicatorActor)
694 actor.Add(mFocusIndicatorActor);
697 mIsFocusIndicatorEnabled = true;
699 // Connect a signal to the TTS player to implement continuous reading mode.
700 Dali::TtsPlayer player = Dali::TtsPlayer::Get( Dali::TtsPlayer::SCREEN_READER );
701 player.StateChangedSignal().Connect( this, &AccessibilityManager::TtsStateChanged );
706 // Hide indicator when tts turned off
707 Actor actor = GetCurrentFocusActor();
710 actor.Remove(mFocusIndicatorActor);
712 mIsFocusIndicatorEnabled = false;
716 // Disconnect the TTS state change signal.
717 Dali::TtsPlayer player = Dali::TtsPlayer::Get( Dali::TtsPlayer::SCREEN_READER );
718 player.StateChangedSignal().Disconnect( this, &AccessibilityManager::TtsStateChanged );
723 mStatusChangedSignal.Emit( handle );
728 bool AccessibilityManager::AccessibilityActionNext(bool allowEndFeedback)
730 Dali::Toolkit::AccessibilityManager handle( this );
731 if( !mActionNextSignal.Empty() )
733 mActionNextSignal.Emit( handle );
736 if(mIsAccessibilityTtsEnabled)
738 mIsEndcapFeedbackEnabled = allowEndFeedback;
739 return MoveFocusForward();
747 bool AccessibilityManager::AccessibilityActionPrevious(bool allowEndFeedback)
749 Dali::Toolkit::AccessibilityManager handle( this );
750 if( !mActionPreviousSignal.Empty() )
752 mActionPreviousSignal.Emit( handle );
755 if(mIsAccessibilityTtsEnabled)
757 mIsEndcapFeedbackEnabled = allowEndFeedback;
758 return MoveFocusBackward();
766 bool AccessibilityManager::AccessibilityActionActivate()
768 Dali::Toolkit::AccessibilityManager handle( this );
769 if( !mActionActivateSignal.Empty() )
771 mActionActivateSignal.Emit( handle );
776 Actor actor = GetCurrentFocusActor();
786 bool AccessibilityManager::AccessibilityActionRead(bool allowReadAgain)
788 Dali::Toolkit::AccessibilityManager handle( this );
792 if ( !mActionReadSignal.Empty() )
794 mActionReadSignal.Emit( handle );
799 if ( !mActionOverSignal.Empty() )
801 mActionOverSignal.Emit( handle );
807 if(mIsAccessibilityTtsEnabled)
809 // Find the focusable actor at the read position
810 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
811 Dali::HitTestAlgorithm::Results results;
812 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), adaptor.GetReadPosition(), results, IsActorFocusableFunction );
814 FocusIDIter focusIDIter = mFocusIDContainer.find(GetFocusOrder(results.actor));
815 if(focusIDIter != mFocusIDContainer.end())
817 if( allowReadAgain || (results.actor != GetCurrentFocusActor()) )
819 // Move the focus to the actor
820 ret = SetCurrentFocusActor(results.actor);
821 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SetCurrentFocusActor returns %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
829 bool AccessibilityManager::AccessibilityActionReadNext(bool allowEndFeedback)
831 Dali::Toolkit::AccessibilityManager handle( this );
832 if( !mActionReadNextSignal.Empty() )
834 mActionReadNextSignal.Emit( handle );
837 if(mIsAccessibilityTtsEnabled)
839 return MoveFocusForward();
847 bool AccessibilityManager::AccessibilityActionReadPrevious(bool allowEndFeedback)
849 Dali::Toolkit::AccessibilityManager handle( this );
850 if( !mActionReadPreviousSignal.Empty() )
852 mActionReadPreviousSignal.Emit( handle );
855 if(mIsAccessibilityTtsEnabled)
857 return MoveFocusBackward();
865 bool AccessibilityManager::AccessibilityActionUp()
867 Dali::Toolkit::AccessibilityManager handle( this );
868 if( !mActionUpSignal.Empty() )
870 mActionUpSignal.Emit( handle );
875 if(mIsAccessibilityTtsEnabled)
877 Actor actor = GetCurrentFocusActor();
880 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
883 // Notify the control that it is activated
884 ret = GetImplementation( control ).OnAccessibilityValueChange(true);
892 bool AccessibilityManager::AccessibilityActionDown()
894 Dali::Toolkit::AccessibilityManager handle( this );
895 if( !mActionDownSignal.Empty() )
897 mActionDownSignal.Emit( handle );
902 if(mIsAccessibilityTtsEnabled)
904 Actor actor = GetCurrentFocusActor();
907 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
910 // Notify the control that it is activated
911 ret = GetImplementation( control ).OnAccessibilityValueChange(false);
919 bool AccessibilityManager::ClearAccessibilityFocus()
921 Dali::Toolkit::AccessibilityManager handle( this );
922 if( !mActionClearFocusSignal.Empty() )
924 mActionClearFocusSignal.Emit( handle );
927 if(mIsAccessibilityTtsEnabled)
938 bool AccessibilityManager::AccessibilityActionScroll( Dali::TouchEvent& touchEvent )
940 Dali::Toolkit::AccessibilityManager handle( this );
941 if( !mActionScrollSignal.Empty() )
943 mActionScrollSignal.Emit( handle, touchEvent );
949 bool AccessibilityManager::AccessibilityActionBack()
951 Dali::Toolkit::AccessibilityManager handle( this );
952 if( !mActionBackSignal.Empty() )
954 mActionBackSignal.Emit( handle );
957 // TODO: Back to previous view
959 return mIsAccessibilityTtsEnabled;
962 bool AccessibilityManager::AccessibilityActionScrollUp()
964 Dali::Toolkit::AccessibilityManager handle( this );
965 if( !mActionScrollUpSignal.Empty() )
967 mActionScrollUpSignal.Emit( handle );
972 if(mIsAccessibilityTtsEnabled)
974 Actor actor = GetCurrentFocusActor();
977 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
980 // TODO: Notify the control to scroll up. Should control handle this?
981 // ret = GetImplementation( control ).OnAccessibilityScroll(Direction::UP);
989 bool AccessibilityManager::AccessibilityActionScrollDown()
991 Dali::Toolkit::AccessibilityManager handle( this );
992 if( !mActionScrollDownSignal.Empty() )
994 mActionScrollDownSignal.Emit( handle );
999 if(mIsAccessibilityTtsEnabled)
1001 Actor actor = GetCurrentFocusActor();
1004 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1007 // TODO: Notify the control to scroll down. Should control handle this?
1008 // ret = GetImplementation( control ).OnAccessibilityScrollDown(Direction::DOWN);
1016 bool AccessibilityManager::AccessibilityActionPageLeft()
1018 Dali::Toolkit::AccessibilityManager handle( this );
1019 if( !mActionPageLeftSignal.Empty() )
1021 mActionPageLeftSignal.Emit( handle );
1026 if(mIsAccessibilityTtsEnabled)
1028 Actor actor = GetCurrentFocusActor();
1031 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1034 // TODO: Notify the control to scroll left to the previous page. Should control handle this?
1035 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::LEFT);
1043 bool AccessibilityManager::AccessibilityActionPageRight()
1045 Dali::Toolkit::AccessibilityManager handle( this );
1046 if( !mActionPageRightSignal.Empty() )
1048 mActionPageRightSignal.Emit( handle );
1053 if(mIsAccessibilityTtsEnabled)
1055 Actor actor = GetCurrentFocusActor();
1058 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1061 // TODO: Notify the control to scroll right to the next page. Should control handle this?
1062 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::RIGHT);
1070 bool AccessibilityManager::AccessibilityActionPageUp()
1072 Dali::Toolkit::AccessibilityManager handle( this );
1073 if( !mActionPageUpSignal.Empty() )
1075 mActionPageUpSignal.Emit( handle );
1080 if(mIsAccessibilityTtsEnabled)
1082 Actor actor = GetCurrentFocusActor();
1085 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1088 // TODO: Notify the control to scroll up to the previous page. Should control handle this?
1089 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::UP);
1097 bool AccessibilityManager::AccessibilityActionPageDown()
1099 Dali::Toolkit::AccessibilityManager handle( this );
1100 if( !mActionPageDownSignal.Empty() )
1102 mActionPageDownSignal.Emit( handle );
1107 if(mIsAccessibilityTtsEnabled)
1109 Actor actor = GetCurrentFocusActor();
1112 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1115 // TODO: Notify the control to scroll down to the next page. Should control handle this?
1116 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::DOWN);
1124 bool AccessibilityManager::AccessibilityActionMoveToFirst()
1126 Dali::Toolkit::AccessibilityManager handle( this );
1127 if( !mActionMoveToFirstSignal.Empty() )
1129 mActionMoveToFirstSignal.Emit( handle );
1132 // TODO: Move to the first item on screen
1134 return mIsAccessibilityTtsEnabled;
1137 bool AccessibilityManager::AccessibilityActionMoveToLast()
1139 Dali::Toolkit::AccessibilityManager handle( this );
1140 if( !mActionMoveToLastSignal.Empty() )
1142 mActionMoveToLastSignal.Emit( handle );
1145 // TODO: Move to the last item on screen
1147 return mIsAccessibilityTtsEnabled;
1150 bool AccessibilityManager::AccessibilityActionReadFromTop()
1152 Dali::Toolkit::AccessibilityManager handle( this );
1153 if( !mActionReadFromTopSignal.Empty() )
1155 mActionReadFromTopSignal.Emit( handle );
1158 // TODO: Move to the top item on screen and read from the item continuously
1160 return mIsAccessibilityTtsEnabled;
1163 bool AccessibilityManager::AccessibilityActionReadFromNext()
1165 Dali::Toolkit::AccessibilityManager handle( this );
1167 if( !mActionReadFromNextSignal.Empty() )
1169 mActionReadFromNextSignal.Emit( handle );
1172 if( mIsAccessibilityTtsEnabled )
1174 // Mark that we are in continuous play mode, so TTS signals can move focus.
1175 mContinuousPlayMode = true;
1177 // Attempt to move to the next item and read from the item continuously.
1181 return mIsAccessibilityTtsEnabled;
1184 void AccessibilityManager::TtsStateChanged( const Dali::TtsPlayer::State previousState, const Dali::TtsPlayer::State currentState )
1186 if( mContinuousPlayMode )
1188 // If we were playing and now we have stopped, attempt to play the next item.
1189 if( ( previousState == Dali::TtsPlayer::PLAYING ) && ( currentState == Dali::TtsPlayer::READY ) )
1191 // Attempt to move the focus forward and play.
1192 // If we can't cancel continuous play mode.
1193 if( !MoveFocusForward() )
1195 // We are done, exit continuous play mode.
1196 mContinuousPlayMode = false;
1201 // Unexpected play state change, exit continuous play mode.
1202 mContinuousPlayMode = false;
1207 bool AccessibilityManager::AccessibilityActionZoom()
1209 Dali::Toolkit::AccessibilityManager handle( this );
1210 if( !mActionZoomSignal.Empty() )
1212 mActionZoomSignal.Emit( handle );
1217 if(mIsAccessibilityTtsEnabled)
1219 Actor actor = GetCurrentFocusActor();
1222 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1225 // Notify the control to zoom
1226 ret = GetImplementation( control ).OnAccessibilityZoom();
1234 bool AccessibilityManager::AccessibilityActionReadIndicatorInformation()
1236 Dali::Toolkit::AccessibilityManager handle( this );
1237 if( !mActionReadIndicatorInformationSignal.Empty() )
1239 mActionReadIndicatorInformationSignal.Emit( handle );
1242 // TODO: Read the information in the indicator
1244 return mIsAccessibilityTtsEnabled;
1247 bool AccessibilityManager::AccessibilityActionReadPauseResume()
1249 Dali::Toolkit::AccessibilityManager handle( this );
1250 if( !mActionReadPauseResumeSignal.Empty() )
1252 mActionReadPauseResumeSignal.Emit( handle );
1257 if(mIsAccessibilityTtsEnabled)
1259 // Pause or resume the TTS player
1260 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
1261 Dali::TtsPlayer::State state = player.GetState();
1262 if(state == Dali::TtsPlayer::PLAYING)
1267 else if(state == Dali::TtsPlayer::PAUSED)
1277 bool AccessibilityManager::AccessibilityActionStartStop()
1279 Dali::Toolkit::AccessibilityManager handle( this );
1280 if( !mActionStartStopSignal.Empty() )
1282 mActionStartStopSignal.Emit( handle );
1285 // TODO: Start/stop the current action
1287 return mIsAccessibilityTtsEnabled;
1290 bool AccessibilityManager::AccessibilityActionTouch(const TouchEvent& touchEvent)
1292 bool handled = false;
1294 // TODO: Need to convert the touchevent for the focused actor?
1296 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(GetCurrentFocusActor());
1299 handled = GetImplementation( control ).OnAccessibilityTouch(touchEvent);
1305 bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& panEvent)
1307 bool handled = false;
1309 if( panEvent.state == Gesture::Started )
1311 // Find the focusable actor at the event position
1312 Dali::HitTestAlgorithm::Results results;
1313 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
1315 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), panEvent.currentPosition, results, IsActorFocusableFunction );
1316 mCurrentGesturedActor = results.actor;
1318 if(!mCurrentGesturedActor)
1320 DALI_LOG_ERROR("Gesture detected, but no hit actor");
1324 // Gesture::Finished (Up) events are delivered with previous (Motion) event position
1325 // Use the real previous position; otherwise we may incorrectly get a ZERO velocity
1326 if ( Gesture::Finished != panEvent.state )
1328 // Store the previous position for next Gesture::Finished iteration.
1329 mPreviousPosition = panEvent.previousPosition;
1332 Actor rootActor = Stage::GetCurrent().GetRootLayer();
1334 Dali::PanGesture pan(panEvent.state);
1335 pan.time = panEvent.time;
1336 pan.numberOfTouches = panEvent.numberOfTouches;
1337 pan.screenPosition = panEvent.currentPosition;
1338 pan.screenDisplacement = mPreviousPosition - panEvent.currentPosition;
1339 pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
1340 pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
1342 // Only handle the pan gesture when the current focused actor is scrollable or within a scrollable actor
1343 while(mCurrentGesturedActor && mCurrentGesturedActor != rootActor && !handled)
1345 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(mCurrentGesturedActor);
1348 Vector2 localCurrent;
1349 control.ScreenToLocal( localCurrent.x, localCurrent.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
1350 pan.position = localCurrent;
1352 Vector2 localPrevious;
1353 control.ScreenToLocal( localPrevious.x, localPrevious.y, mPreviousPosition.x, mPreviousPosition.y );
1355 pan.displacement = localCurrent - localPrevious;
1356 pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
1357 pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
1359 handled = GetImplementation( control ).OnAccessibilityPan(pan);
1362 // If the gesture is not handled by the control, check its parent
1365 mCurrentGesturedActor = mCurrentGesturedActor.GetParent();
1367 if(!mCurrentGesturedActor)
1369 DALI_LOG_ERROR("no more gestured actor");
1374 // If handled, then update the pan gesture properties
1375 PanGestureDetector::SetPanGestureProperties( pan );
1382 Toolkit::AccessibilityManager::FocusChangedSignalType& AccessibilityManager::FocusChangedSignal()
1384 return mFocusChangedSignal;
1387 Toolkit::AccessibilityManager::FocusOvershotSignalType& AccessibilityManager::FocusOvershotSignal()
1389 return mFocusOvershotSignal;
1392 Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& AccessibilityManager::FocusedActorActivatedSignal()
1394 return mFocusedActorActivatedSignal;
1397 bool AccessibilityManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1399 Dali::BaseHandle handle( object );
1401 bool connected( true );
1402 AccessibilityManager* manager = dynamic_cast<AccessibilityManager*>( object );
1404 if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
1406 manager->FocusChangedSignal().Connect( tracker, functor );
1408 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_OVERSHOT ) )
1410 manager->FocusOvershotSignal().Connect( tracker, functor );
1412 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ACTIVATED ) )
1414 manager->FocusedActorActivatedSignal().Connect( tracker, functor );
1418 // signalName does not match any signal
1425 } // namespace Internal
1427 } // namespace Toolkit