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 = "focus-changed";
50 const char* const SIGNAL_FOCUS_OVERSHOT = "focus-overshot";
51 const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED = "focused-actor-activated";
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("is-focus-group");
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 actor focusable property if not already created.
195 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
196 if(propertyActorFocusable == Property::INVALID_INDEX)
198 propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE );
203 // The actor is not focusable without a defined focus order.
204 actor.SetProperty(propertyActorFocusable, false);
206 // If the actor is currently being focused, it should clear the focus
207 if(actor == GetCurrentFocusActor())
212 else // Insert the actor to the focus chain
214 // Check whether there is another actor in the focus chain with the same focus order already.
215 FocusIDIter focusIDIter = mFocusIDContainer.find(order);
216 if(focusIDIter != mFocusIDContainer.end())
218 // We need to increase the focus order of that actor and all the actors followed it
219 // in the focus chain.
220 FocusIDIter lastIter = mFocusIDContainer.end();
221 --lastIter;//We want forward iterator to the last element here
222 mFocusIDContainer.insert(FocusIDPair((*lastIter).first + 1, (*lastIter).second));
224 // Update the actor's focus order in its additional data
225 SynchronizeActorAdditionalInfo((*lastIter).second, (*lastIter).first + 1);
227 for(FocusIDIter iter = lastIter; iter != focusIDIter; iter--)
229 FocusIDIter previousIter = iter;
230 --previousIter;//We want forward iterator to the previous element here
231 unsigned int actorID = (*previousIter).second;
232 (*iter).second = actorID;
234 // Update the actor's focus order in its additional data
235 SynchronizeActorAdditionalInfo(actorID, (*iter).first);
238 mFocusIDContainer.erase(order);
241 // The actor is focusable
242 actor.SetProperty(propertyActorFocusable, true);
244 // Now we insert the actor into the focus chain with the specified focus order
245 mFocusIDContainer.insert(FocusIDPair(order, actor.GetId()));
248 // Update the actor's focus order in its additional data
249 SynchronizeActorAdditionalInfo(actor.GetId(), order);
253 unsigned int AccessibilityManager::GetFocusOrder(Actor actor) const
255 unsigned int focusOrder = 0;
259 ActorAdditionalInfo data = GetActorAdditionalInfo(actor.GetId());
260 focusOrder = data.mFocusOrder;
266 unsigned int AccessibilityManager::GenerateNewFocusOrder() const
268 unsigned int order = 1;
269 FocusIDContainer::const_reverse_iterator iter = mFocusIDContainer.rbegin();
271 if(iter != mFocusIDContainer.rend())
273 order = (*iter).first + 1;
279 Actor AccessibilityManager::GetActorByFocusOrder(const unsigned int order)
281 Actor actor = Actor();
283 FocusIDIter focusIDIter = mFocusIDContainer.find(order);
284 if(focusIDIter != mFocusIDContainer.end())
286 Actor rootActor = Stage::GetCurrent().GetRootLayer();
287 actor = rootActor.FindChildById(mFocusIDContainer[order]);
293 bool AccessibilityManager::SetCurrentFocusActor(Actor actor)
297 return DoSetCurrentFocusActor(actor.GetId());
303 bool AccessibilityManager::DoSetCurrentFocusActor(const unsigned int actorID)
305 Actor rootActor = Stage::GetCurrent().GetRootLayer();
307 // If the group mode is enabled, check which focus group the current focused actor belongs to
309 if(mIsFocusWithinGroup)
311 focusGroup = GetFocusGroup(GetCurrentFocusActor());
316 focusGroup = rootActor;
319 Actor actor = focusGroup.FindChildById(actorID);
321 // Check whether the actor is in the stage
324 // Check whether the actor is focusable
325 bool actorFocusable = false;
326 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
327 if(propertyActorFocusable != Property::INVALID_INDEX)
329 actorFocusable = actor.GetProperty<bool>(propertyActorFocusable);
332 // Go through the actor's hierarchy to check whether the actor is visible
333 bool actorVisible = actor.IsVisible();
334 Actor parent = actor.GetParent();
335 while (actorVisible && parent && parent != rootActor)
337 actorVisible = parent.IsVisible();
338 parent = parent.GetParent();
341 // Check whether the actor is fully transparent
342 bool actorOpaque = actor.GetCurrentWorldColor().a > 0.01f;
344 // Set the focus only when the actor is focusable and visible and not fully transparent
345 if(actorVisible && actorFocusable && actorOpaque)
347 // Draw the focus indicator upon the focused actor
348 if(mIsFocusIndicatorEnabled && mFocusIndicatorActor)
350 actor.Add(mFocusIndicatorActor);
353 // Send notification for the change of focus actor
354 mFocusChangedSignal.Emit( GetCurrentFocusActor(), actor );
356 // Save the current focused actor
357 mCurrentFocusActor = FocusIDPair(GetFocusOrder(actor), actorID);
359 if(mIsAccessibilityTtsEnabled)
361 Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get();
364 soundPlayer.PlaySound(FOCUS_SOUND_FILE);
367 // Play the accessibility attributes with the TTS player.
368 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
370 // Combine attribute texts to one text
371 std::string informationText;
372 for(int i = 0; i < Toolkit::AccessibilityManager::ACCESSIBILITY_ATTRIBUTE_NUM; i++)
374 if(!GetActorAdditionalInfo(actorID).mAccessibilityAttributes[i].empty())
378 informationText += ", "; // for space time between each information
380 informationText += GetActorAdditionalInfo(actorID).mAccessibilityAttributes[i];
383 player.Play(informationText);
390 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
394 Actor AccessibilityManager::GetCurrentFocusActor()
396 Actor rootActor = Stage::GetCurrent().GetRootLayer();
397 return rootActor.FindChildById(mCurrentFocusActor.second);
400 Actor AccessibilityManager::GetCurrentFocusGroup()
402 return GetFocusGroup(GetCurrentFocusActor());
405 unsigned int AccessibilityManager::GetCurrentFocusOrder()
407 return mCurrentFocusActor.first;
410 bool AccessibilityManager::MoveFocusForward()
413 mRecursiveFocusMoveCounter = 0;
415 FocusIDIter focusIDIter = mFocusIDContainer.find(mCurrentFocusActor.first);
416 if(focusIDIter != mFocusIDContainer.end())
418 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
419 ret = DoMoveFocus(focusIDIter, true, mIsWrapped);
423 // TODO: if there is not focused actor, move first actor
424 if(!mFocusIDContainer.empty())
426 //if there is not focused actor, move 1st actor
427 focusIDIter = mFocusIDContainer.begin(); // TODO: I'm not sure it was sorted.
428 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
429 ret = DoSetCurrentFocusActor((*focusIDIter).second);
433 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s] %s\n", __FUNCTION__, ret?"SUCCEED!!!":"FAILED!!!");
438 bool AccessibilityManager::MoveFocusBackward()
441 mRecursiveFocusMoveCounter = 0;
443 FocusIDIter focusIDIter = mFocusIDContainer.find(mCurrentFocusActor.first);
444 if(focusIDIter != mFocusIDContainer.end())
446 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
447 ret = DoMoveFocus(focusIDIter, false, mIsWrapped);
451 // TODO: if there is not focused actor, move last actor
452 if(!mFocusIDContainer.empty())
454 //if there is not focused actor, move last actor
455 focusIDIter = mFocusIDContainer.end();
456 --focusIDIter;//We want forward iterator to the last element here
457 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
458 ret = DoSetCurrentFocusActor((*focusIDIter).second);
462 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s] %s\n", __FUNCTION__, ret?"SUCCEED!!!":"FAILED!!!");
467 void AccessibilityManager::DoActivate(Actor actor)
471 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
474 // Notify the control that it is activated
475 GetImplementation( control ).AccessibilityActivate();
478 // Send notification for the activation of focused actor
479 mFocusedActorActivatedSignal.Emit(actor);
483 void AccessibilityManager::ClearFocus()
485 Actor actor = GetCurrentFocusActor();
488 actor.Remove(mFocusIndicatorActor);
491 mCurrentFocusActor = FocusIDPair(0, 0);
493 // Send notification for the change of focus actor
494 mFocusChangedSignal.Emit(actor, Actor());
496 if(mIsAccessibilityTtsEnabled)
498 // Stop the TTS playing if any
499 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
504 void AccessibilityManager::Reset()
507 mFocusIDContainer.clear();
508 mIDAdditionalInfoContainer.clear();
511 void AccessibilityManager::SetFocusGroup(Actor actor, bool isFocusGroup)
515 // Create focus group property if not already created.
516 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP);
517 if(propertyIsFocusGroup == Property::INVALID_INDEX)
519 actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE );
523 actor.SetProperty(propertyIsFocusGroup, isFocusGroup);
528 bool AccessibilityManager::IsFocusGroup(Actor actor) const
530 // Check whether the actor is a focus group
531 bool isFocusGroup = false;
535 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP);
536 if(propertyIsFocusGroup != Property::INVALID_INDEX)
538 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
545 Actor AccessibilityManager::GetFocusGroup(Actor actor)
547 // Go through the actor's hierarchy to check which focus group the actor belongs to
548 while (actor && !IsFocusGroup(actor))
550 actor = actor.GetParent();
556 void AccessibilityManager::SetGroupMode(bool enabled)
558 mIsFocusWithinGroup = enabled;
561 bool AccessibilityManager::GetGroupMode() const
563 return mIsFocusWithinGroup;
566 void AccessibilityManager::SetWrapMode(bool wrapped)
568 mIsWrapped = wrapped;
571 bool AccessibilityManager::GetWrapMode() const
576 void AccessibilityManager::SetFocusIndicatorActor(Actor indicator)
578 mFocusIndicatorActor = indicator;
581 Actor AccessibilityManager::GetFocusIndicatorActor()
583 return mFocusIndicatorActor;
586 bool AccessibilityManager::DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped)
588 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] %d focusable actors\n", __FUNCTION__, __LINE__, mFocusIDContainer.size());
589 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] focus order : %d\n", __FUNCTION__, __LINE__, (*focusIDIter).first);
591 if( (forward && ++focusIDIter == mFocusIDContainer.end())
592 || (!forward && focusIDIter-- == mFocusIDContainer.begin()) )
594 if(mIsEndcapFeedbackEnabled)
596 if(mIsEndcapFeedbackPlayed == false)
598 // play sound & skip moving once
599 Dali::SoundPlayer soundPlayer = Dali::SoundPlayer::Get();
602 soundPlayer.PlaySound(FOCUS_CHAIN_END_SOUND_FILE);
605 mIsEndcapFeedbackPlayed = true;
608 mIsEndcapFeedbackPlayed = false;
615 focusIDIter = mFocusIDContainer.begin();
619 focusIDIter = mFocusIDContainer.end();
620 --focusIDIter;//We want forward iterator to the last element here
625 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Overshot\n", __FUNCTION__, __LINE__);
626 // Send notification for handling overshooted situation
627 mFocusOvershotSignal.Emit(GetCurrentFocusActor(), forward ? Toolkit::AccessibilityManager::OVERSHOT_NEXT : Toolkit::AccessibilityManager::OVERSHOT_PREVIOUS);
629 return false; // Try to move the focus out of the scope
634 if( focusIDIter == mFocusIDContainer.end() )
639 // Note: This function performs the focus change.
640 if( !DoSetCurrentFocusActor( (*focusIDIter).second ) )
642 mRecursiveFocusMoveCounter++;
643 if(mRecursiveFocusMoveCounter > mFocusIDContainer.size())
645 // We've attempted to focus all the actors in the whole focus chain and no actor
646 // can be focused successfully.
647 DALI_LOG_WARNING("[%s] There is no more focusable actor in %d focus chains\n", __FUNCTION__, mRecursiveFocusMoveCounter);
653 return DoMoveFocus(focusIDIter, forward, wrapped);
660 void AccessibilityManager::SetFocusable(Actor actor, bool focusable)
664 // Create actor focusable property if not already created.
665 Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE);
666 if(propertyActorFocusable == Property::INVALID_INDEX)
668 actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE );
672 actor.SetProperty(propertyActorFocusable, focusable);
677 void AccessibilityManager::CreateDefaultFocusIndicatorActor()
679 // Create a focus indicator actor shared by all the focusable actors
680 Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH);
682 ImageActor focusIndicator = ImageActor::New(borderImage);
683 focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
684 focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
685 focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER);
686 focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
688 // Apply size constraint to the focus indicator
689 focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
691 SetFocusIndicatorActor(focusIndicator);
694 bool AccessibilityManager::ChangeAccessibilityStatus()
696 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
697 mIsAccessibilityTtsEnabled = adaptor.IsEnabled();
698 Dali::Toolkit::AccessibilityManager handle( this );
700 if(mIsAccessibilityTtsEnabled)
702 // Show indicator when tts turned on if there is focused actor.
703 Actor actor = GetCurrentFocusActor();
706 if(mFocusIndicatorActor)
708 actor.Add(mFocusIndicatorActor);
711 mIsFocusIndicatorEnabled = true;
713 // Connect a signal to the TTS player to implement continuous reading mode.
714 Dali::TtsPlayer player = Dali::TtsPlayer::Get( Dali::TtsPlayer::SCREEN_READER );
715 player.StateChangedSignal().Connect( this, &AccessibilityManager::TtsStateChanged );
720 // Hide indicator when tts turned off
721 Actor actor = GetCurrentFocusActor();
724 actor.Remove(mFocusIndicatorActor);
726 mIsFocusIndicatorEnabled = false;
730 // Disconnect the TTS state change signal.
731 Dali::TtsPlayer player = Dali::TtsPlayer::Get( Dali::TtsPlayer::SCREEN_READER );
732 player.StateChangedSignal().Disconnect( this, &AccessibilityManager::TtsStateChanged );
737 mStatusChangedSignal.Emit( handle );
742 bool AccessibilityManager::AccessibilityActionNext(bool allowEndFeedback)
744 Dali::Toolkit::AccessibilityManager handle( this );
745 if( !mActionNextSignal.Empty() )
747 mActionNextSignal.Emit( handle );
750 if(mIsAccessibilityTtsEnabled)
752 mIsEndcapFeedbackEnabled = allowEndFeedback;
753 return MoveFocusForward();
761 bool AccessibilityManager::AccessibilityActionPrevious(bool allowEndFeedback)
763 Dali::Toolkit::AccessibilityManager handle( this );
764 if( !mActionPreviousSignal.Empty() )
766 mActionPreviousSignal.Emit( handle );
769 if(mIsAccessibilityTtsEnabled)
771 mIsEndcapFeedbackEnabled = allowEndFeedback;
772 return MoveFocusBackward();
780 bool AccessibilityManager::AccessibilityActionActivate()
782 Dali::Toolkit::AccessibilityManager handle( this );
783 if( !mActionActivateSignal.Empty() )
785 mActionActivateSignal.Emit( handle );
790 Actor actor = GetCurrentFocusActor();
800 bool AccessibilityManager::AccessibilityActionRead(bool allowReadAgain)
802 Dali::Toolkit::AccessibilityManager handle( this );
806 if ( !mActionReadSignal.Empty() )
808 mActionReadSignal.Emit( handle );
813 if ( !mActionOverSignal.Empty() )
815 mActionOverSignal.Emit( handle );
821 if(mIsAccessibilityTtsEnabled)
823 // Find the focusable actor at the read position
824 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
825 Dali::HitTestAlgorithm::Results results;
826 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), adaptor.GetReadPosition(), results, IsActorFocusableFunction );
828 FocusIDIter focusIDIter = mFocusIDContainer.find(GetFocusOrder(results.actor));
829 if(focusIDIter != mFocusIDContainer.end())
831 if( allowReadAgain || (results.actor != GetCurrentFocusActor()) )
833 // Move the focus to the actor
834 ret = SetCurrentFocusActor(results.actor);
835 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SetCurrentFocusActor returns %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
843 bool AccessibilityManager::AccessibilityActionReadNext(bool allowEndFeedback)
845 Dali::Toolkit::AccessibilityManager handle( this );
846 if( !mActionReadNextSignal.Empty() )
848 mActionReadNextSignal.Emit( handle );
851 if(mIsAccessibilityTtsEnabled)
853 return MoveFocusForward();
861 bool AccessibilityManager::AccessibilityActionReadPrevious(bool allowEndFeedback)
863 Dali::Toolkit::AccessibilityManager handle( this );
864 if( !mActionReadPreviousSignal.Empty() )
866 mActionReadPreviousSignal.Emit( handle );
869 if(mIsAccessibilityTtsEnabled)
871 return MoveFocusBackward();
879 bool AccessibilityManager::AccessibilityActionUp()
881 Dali::Toolkit::AccessibilityManager handle( this );
882 if( !mActionUpSignal.Empty() )
884 mActionUpSignal.Emit( handle );
889 if(mIsAccessibilityTtsEnabled)
891 Actor actor = GetCurrentFocusActor();
894 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
897 // Notify the control that it is activated
898 ret = GetImplementation( control ).OnAccessibilityValueChange(true);
906 bool AccessibilityManager::AccessibilityActionDown()
908 Dali::Toolkit::AccessibilityManager handle( this );
909 if( !mActionDownSignal.Empty() )
911 mActionDownSignal.Emit( handle );
916 if(mIsAccessibilityTtsEnabled)
918 Actor actor = GetCurrentFocusActor();
921 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
924 // Notify the control that it is activated
925 ret = GetImplementation( control ).OnAccessibilityValueChange(false);
933 bool AccessibilityManager::ClearAccessibilityFocus()
935 Dali::Toolkit::AccessibilityManager handle( this );
936 if( !mActionClearFocusSignal.Empty() )
938 mActionClearFocusSignal.Emit( handle );
941 if(mIsAccessibilityTtsEnabled)
952 bool AccessibilityManager::AccessibilityActionScroll( Dali::TouchEvent& touchEvent )
954 Dali::Toolkit::AccessibilityManager handle( this );
955 if( !mActionScrollSignal.Empty() )
957 mActionScrollSignal.Emit( handle, touchEvent );
963 bool AccessibilityManager::AccessibilityActionBack()
965 Dali::Toolkit::AccessibilityManager handle( this );
966 if( !mActionBackSignal.Empty() )
968 mActionBackSignal.Emit( handle );
971 // TODO: Back to previous view
973 return mIsAccessibilityTtsEnabled;
976 bool AccessibilityManager::AccessibilityActionScrollUp()
978 Dali::Toolkit::AccessibilityManager handle( this );
979 if( !mActionScrollUpSignal.Empty() )
981 mActionScrollUpSignal.Emit( handle );
986 if(mIsAccessibilityTtsEnabled)
988 Actor actor = GetCurrentFocusActor();
991 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
994 // TODO: Notify the control to scroll up. Should control handle this?
995 // ret = GetImplementation( control ).OnAccessibilityScroll(Direction::UP);
1003 bool AccessibilityManager::AccessibilityActionScrollDown()
1005 Dali::Toolkit::AccessibilityManager handle( this );
1006 if( !mActionScrollDownSignal.Empty() )
1008 mActionScrollDownSignal.Emit( handle );
1013 if(mIsAccessibilityTtsEnabled)
1015 Actor actor = GetCurrentFocusActor();
1018 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1021 // TODO: Notify the control to scroll down. Should control handle this?
1022 // ret = GetImplementation( control ).OnAccessibilityScrollDown(Direction::DOWN);
1030 bool AccessibilityManager::AccessibilityActionPageLeft()
1032 Dali::Toolkit::AccessibilityManager handle( this );
1033 if( !mActionPageLeftSignal.Empty() )
1035 mActionPageLeftSignal.Emit( handle );
1040 if(mIsAccessibilityTtsEnabled)
1042 Actor actor = GetCurrentFocusActor();
1045 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1048 // TODO: Notify the control to scroll left to the previous page. Should control handle this?
1049 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::LEFT);
1057 bool AccessibilityManager::AccessibilityActionPageRight()
1059 Dali::Toolkit::AccessibilityManager handle( this );
1060 if( !mActionPageRightSignal.Empty() )
1062 mActionPageRightSignal.Emit( handle );
1067 if(mIsAccessibilityTtsEnabled)
1069 Actor actor = GetCurrentFocusActor();
1072 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1075 // TODO: Notify the control to scroll right to the next page. Should control handle this?
1076 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::RIGHT);
1084 bool AccessibilityManager::AccessibilityActionPageUp()
1086 Dali::Toolkit::AccessibilityManager handle( this );
1087 if( !mActionPageUpSignal.Empty() )
1089 mActionPageUpSignal.Emit( handle );
1094 if(mIsAccessibilityTtsEnabled)
1096 Actor actor = GetCurrentFocusActor();
1099 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1102 // TODO: Notify the control to scroll up to the previous page. Should control handle this?
1103 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::UP);
1111 bool AccessibilityManager::AccessibilityActionPageDown()
1113 Dali::Toolkit::AccessibilityManager handle( this );
1114 if( !mActionPageDownSignal.Empty() )
1116 mActionPageDownSignal.Emit( handle );
1121 if(mIsAccessibilityTtsEnabled)
1123 Actor actor = GetCurrentFocusActor();
1126 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1129 // TODO: Notify the control to scroll down to the next page. Should control handle this?
1130 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::DOWN);
1138 bool AccessibilityManager::AccessibilityActionMoveToFirst()
1140 Dali::Toolkit::AccessibilityManager handle( this );
1141 if( !mActionMoveToFirstSignal.Empty() )
1143 mActionMoveToFirstSignal.Emit( handle );
1146 // TODO: Move to the first item on screen
1148 return mIsAccessibilityTtsEnabled;
1151 bool AccessibilityManager::AccessibilityActionMoveToLast()
1153 Dali::Toolkit::AccessibilityManager handle( this );
1154 if( !mActionMoveToLastSignal.Empty() )
1156 mActionMoveToLastSignal.Emit( handle );
1159 // TODO: Move to the last item on screen
1161 return mIsAccessibilityTtsEnabled;
1164 bool AccessibilityManager::AccessibilityActionReadFromTop()
1166 Dali::Toolkit::AccessibilityManager handle( this );
1167 if( !mActionReadFromTopSignal.Empty() )
1169 mActionReadFromTopSignal.Emit( handle );
1172 // TODO: Move to the top item on screen and read from the item continuously
1174 return mIsAccessibilityTtsEnabled;
1177 bool AccessibilityManager::AccessibilityActionReadFromNext()
1179 Dali::Toolkit::AccessibilityManager handle( this );
1181 if( !mActionReadFromNextSignal.Empty() )
1183 mActionReadFromNextSignal.Emit( handle );
1186 if( mIsAccessibilityTtsEnabled )
1188 // Mark that we are in continuous play mode, so TTS signals can move focus.
1189 mContinuousPlayMode = true;
1191 // Attempt to move to the next item and read from the item continuously.
1195 return mIsAccessibilityTtsEnabled;
1198 void AccessibilityManager::TtsStateChanged( const Dali::TtsPlayer::State previousState, const Dali::TtsPlayer::State currentState )
1200 if( mContinuousPlayMode )
1202 // If we were playing and now we have stopped, attempt to play the next item.
1203 if( ( previousState == Dali::TtsPlayer::PLAYING ) && ( currentState == Dali::TtsPlayer::READY ) )
1205 // Attempt to move the focus forward and play.
1206 // If we can't cancel continuous play mode.
1207 if( !MoveFocusForward() )
1209 // We are done, exit continuous play mode.
1210 mContinuousPlayMode = false;
1215 // Unexpected play state change, exit continuous play mode.
1216 mContinuousPlayMode = false;
1221 bool AccessibilityManager::AccessibilityActionZoom()
1223 Dali::Toolkit::AccessibilityManager handle( this );
1224 if( !mActionZoomSignal.Empty() )
1226 mActionZoomSignal.Emit( handle );
1231 if(mIsAccessibilityTtsEnabled)
1233 Actor actor = GetCurrentFocusActor();
1236 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1239 // Notify the control to zoom
1240 ret = GetImplementation( control ).OnAccessibilityZoom();
1248 bool AccessibilityManager::AccessibilityActionReadIndicatorInformation()
1250 Dali::Toolkit::AccessibilityManager handle( this );
1251 if( !mActionReadIndicatorInformationSignal.Empty() )
1253 mActionReadIndicatorInformationSignal.Emit( handle );
1256 // TODO: Read the information in the indicator
1258 return mIsAccessibilityTtsEnabled;
1261 bool AccessibilityManager::AccessibilityActionReadPauseResume()
1263 Dali::Toolkit::AccessibilityManager handle( this );
1264 if( !mActionReadPauseResumeSignal.Empty() )
1266 mActionReadPauseResumeSignal.Emit( handle );
1271 if(mIsAccessibilityTtsEnabled)
1273 // Pause or resume the TTS player
1274 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
1275 Dali::TtsPlayer::State state = player.GetState();
1276 if(state == Dali::TtsPlayer::PLAYING)
1281 else if(state == Dali::TtsPlayer::PAUSED)
1291 bool AccessibilityManager::AccessibilityActionStartStop()
1293 Dali::Toolkit::AccessibilityManager handle( this );
1294 if( !mActionStartStopSignal.Empty() )
1296 mActionStartStopSignal.Emit( handle );
1299 // TODO: Start/stop the current action
1301 return mIsAccessibilityTtsEnabled;
1304 bool AccessibilityManager::AccessibilityActionTouch(const TouchEvent& touchEvent)
1306 bool handled = false;
1308 // TODO: Need to convert the touchevent for the focused actor?
1310 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(GetCurrentFocusActor());
1313 handled = GetImplementation( control ).OnAccessibilityTouch(touchEvent);
1319 bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& panEvent)
1321 bool handled = false;
1323 if( panEvent.state == Gesture::Started )
1325 // Find the focusable actor at the event position
1326 Dali::HitTestAlgorithm::Results results;
1327 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
1329 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), panEvent.currentPosition, results, IsActorFocusableFunction );
1330 mCurrentGesturedActor = results.actor;
1332 if(!mCurrentGesturedActor)
1334 DALI_LOG_ERROR("Gesture detected, but no hit actor");
1338 // Gesture::Finished (Up) events are delivered with previous (Motion) event position
1339 // Use the real previous position; otherwise we may incorrectly get a ZERO velocity
1340 if ( Gesture::Finished != panEvent.state )
1342 // Store the previous position for next Gesture::Finished iteration.
1343 mPreviousPosition = panEvent.previousPosition;
1346 Actor rootActor = Stage::GetCurrent().GetRootLayer();
1348 Dali::PanGesture pan(panEvent.state);
1349 pan.time = panEvent.time;
1350 pan.numberOfTouches = panEvent.numberOfTouches;
1351 pan.screenPosition = panEvent.currentPosition;
1352 pan.screenDisplacement = mPreviousPosition - panEvent.currentPosition;
1353 pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
1354 pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
1356 // Only handle the pan gesture when the current focused actor is scrollable or within a scrollable actor
1357 while(mCurrentGesturedActor && mCurrentGesturedActor != rootActor && !handled)
1359 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(mCurrentGesturedActor);
1362 Vector2 localCurrent;
1363 control.ScreenToLocal( localCurrent.x, localCurrent.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
1364 pan.position = localCurrent;
1366 Vector2 localPrevious;
1367 control.ScreenToLocal( localPrevious.x, localPrevious.y, mPreviousPosition.x, mPreviousPosition.y );
1369 pan.displacement = localCurrent - localPrevious;
1370 pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
1371 pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
1373 handled = GetImplementation( control ).OnAccessibilityPan(pan);
1376 // If the gesture is not handled by the control, check its parent
1379 mCurrentGesturedActor = mCurrentGesturedActor.GetParent();
1381 if(!mCurrentGesturedActor)
1383 DALI_LOG_ERROR("no more gestured actor");
1388 // If handled, then update the pan gesture properties
1389 PanGestureDetector::SetPanGestureProperties( pan );
1396 Toolkit::AccessibilityManager::FocusChangedSignalType& AccessibilityManager::FocusChangedSignal()
1398 return mFocusChangedSignal;
1401 Toolkit::AccessibilityManager::FocusOvershotSignalType& AccessibilityManager::FocusOvershotSignal()
1403 return mFocusOvershotSignal;
1406 Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& AccessibilityManager::FocusedActorActivatedSignal()
1408 return mFocusedActorActivatedSignal;
1411 bool AccessibilityManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1413 Dali::BaseHandle handle( object );
1415 bool connected( true );
1416 AccessibilityManager* manager = dynamic_cast<AccessibilityManager*>( object );
1418 if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
1420 manager->FocusChangedSignal().Connect( tracker, functor );
1422 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_OVERSHOT ) )
1424 manager->FocusOvershotSignal().Connect( tracker, functor );
1426 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ACTIVATED ) )
1428 manager->FocusedActorActivatedSignal().Connect( tracker, functor );
1432 // signalName does not match any signal
1439 } // namespace Internal
1441 } // namespace Toolkit