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>
34 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
45 namespace // unnamed namespace
50 const char* const SIGNAL_FOCUS_CHANGED = "focusChanged";
51 const char* const SIGNAL_FOCUS_OVERSHOT = "focusOvershot";
52 const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED = "focusedActorActivated";
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FOCUS_MANAGER");
58 const char* const ACTOR_FOCUSABLE("focusable");
59 const char* const IS_FOCUS_GROUP("isFocusGroup");
61 const char* FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "B16-8_TTS_focus.9.png";
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 Toolkit::ImageView focusIndicator = Toolkit::ImageView::New(FOCUS_BORDER_IMAGE_PATH);
667 focusIndicator.SetParentOrigin( ParentOrigin::CENTER );
668 focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));
670 // Apply size constraint to the focus indicator
671 focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
673 SetFocusIndicatorActor(focusIndicator);
676 bool AccessibilityManager::ChangeAccessibilityStatus()
678 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
679 mIsAccessibilityTtsEnabled = adaptor.IsEnabled();
680 Dali::Toolkit::AccessibilityManager handle( this );
682 if(mIsAccessibilityTtsEnabled)
684 // Show indicator when tts turned on if there is focused actor.
685 Actor actor = GetCurrentFocusActor();
688 if(mFocusIndicatorActor)
690 actor.Add(mFocusIndicatorActor);
693 mIsFocusIndicatorEnabled = true;
695 // Connect a signal to the TTS player to implement continuous reading mode.
696 Dali::TtsPlayer player = Dali::TtsPlayer::Get( Dali::TtsPlayer::SCREEN_READER );
697 player.StateChangedSignal().Connect( this, &AccessibilityManager::TtsStateChanged );
702 // Hide indicator when tts turned off
703 Actor actor = GetCurrentFocusActor();
706 actor.Remove(mFocusIndicatorActor);
708 mIsFocusIndicatorEnabled = false;
712 // Disconnect the TTS state change signal.
713 Dali::TtsPlayer player = Dali::TtsPlayer::Get( Dali::TtsPlayer::SCREEN_READER );
714 player.StateChangedSignal().Disconnect( this, &AccessibilityManager::TtsStateChanged );
719 mStatusChangedSignal.Emit( handle );
724 bool AccessibilityManager::AccessibilityActionNext(bool allowEndFeedback)
726 Dali::Toolkit::AccessibilityManager handle( this );
727 if( !mActionNextSignal.Empty() )
729 mActionNextSignal.Emit( handle );
732 if(mIsAccessibilityTtsEnabled)
734 mIsEndcapFeedbackEnabled = allowEndFeedback;
735 return MoveFocusForward();
743 bool AccessibilityManager::AccessibilityActionPrevious(bool allowEndFeedback)
745 Dali::Toolkit::AccessibilityManager handle( this );
746 if( !mActionPreviousSignal.Empty() )
748 mActionPreviousSignal.Emit( handle );
751 if(mIsAccessibilityTtsEnabled)
753 mIsEndcapFeedbackEnabled = allowEndFeedback;
754 return MoveFocusBackward();
762 bool AccessibilityManager::AccessibilityActionActivate()
764 Dali::Toolkit::AccessibilityManager handle( this );
765 if( !mActionActivateSignal.Empty() )
767 mActionActivateSignal.Emit( handle );
772 Actor actor = GetCurrentFocusActor();
782 bool AccessibilityManager::AccessibilityActionRead(bool allowReadAgain)
784 Dali::Toolkit::AccessibilityManager handle( this );
788 if ( !mActionReadSignal.Empty() )
790 mActionReadSignal.Emit( handle );
795 if ( !mActionOverSignal.Empty() )
797 mActionOverSignal.Emit( handle );
803 if(mIsAccessibilityTtsEnabled)
805 // Find the focusable actor at the read position
806 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
807 Dali::HitTestAlgorithm::Results results;
808 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), adaptor.GetReadPosition(), results, IsActorFocusableFunction );
810 FocusIDIter focusIDIter = mFocusIDContainer.find(GetFocusOrder(results.actor));
811 if(focusIDIter != mFocusIDContainer.end())
813 if( allowReadAgain || (results.actor != GetCurrentFocusActor()) )
815 // Move the focus to the actor
816 ret = SetCurrentFocusActor(results.actor);
817 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SetCurrentFocusActor returns %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
825 bool AccessibilityManager::AccessibilityActionReadNext(bool allowEndFeedback)
827 Dali::Toolkit::AccessibilityManager handle( this );
828 if( !mActionReadNextSignal.Empty() )
830 mActionReadNextSignal.Emit( handle );
833 if(mIsAccessibilityTtsEnabled)
835 return MoveFocusForward();
843 bool AccessibilityManager::AccessibilityActionReadPrevious(bool allowEndFeedback)
845 Dali::Toolkit::AccessibilityManager handle( this );
846 if( !mActionReadPreviousSignal.Empty() )
848 mActionReadPreviousSignal.Emit( handle );
851 if(mIsAccessibilityTtsEnabled)
853 return MoveFocusBackward();
861 bool AccessibilityManager::AccessibilityActionUp()
863 Dali::Toolkit::AccessibilityManager handle( this );
864 if( !mActionUpSignal.Empty() )
866 mActionUpSignal.Emit( handle );
871 if(mIsAccessibilityTtsEnabled)
873 Actor actor = GetCurrentFocusActor();
876 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
879 // Notify the control that it is activated
880 ret = GetImplementation( control ).OnAccessibilityValueChange(true);
888 bool AccessibilityManager::AccessibilityActionDown()
890 Dali::Toolkit::AccessibilityManager handle( this );
891 if( !mActionDownSignal.Empty() )
893 mActionDownSignal.Emit( handle );
898 if(mIsAccessibilityTtsEnabled)
900 Actor actor = GetCurrentFocusActor();
903 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
906 // Notify the control that it is activated
907 ret = GetImplementation( control ).OnAccessibilityValueChange(false);
915 bool AccessibilityManager::ClearAccessibilityFocus()
917 Dali::Toolkit::AccessibilityManager handle( this );
918 if( !mActionClearFocusSignal.Empty() )
920 mActionClearFocusSignal.Emit( handle );
923 if(mIsAccessibilityTtsEnabled)
934 bool AccessibilityManager::AccessibilityActionScroll( Dali::TouchEvent& touchEvent )
936 Dali::Toolkit::AccessibilityManager handle( this );
937 if( !mActionScrollSignal.Empty() )
939 mActionScrollSignal.Emit( handle, touchEvent );
945 bool AccessibilityManager::AccessibilityActionBack()
947 Dali::Toolkit::AccessibilityManager handle( this );
948 if( !mActionBackSignal.Empty() )
950 mActionBackSignal.Emit( handle );
953 // TODO: Back to previous view
955 return mIsAccessibilityTtsEnabled;
958 bool AccessibilityManager::AccessibilityActionScrollUp()
960 Dali::Toolkit::AccessibilityManager handle( this );
961 if( !mActionScrollUpSignal.Empty() )
963 mActionScrollUpSignal.Emit( handle );
968 if(mIsAccessibilityTtsEnabled)
970 Actor actor = GetCurrentFocusActor();
973 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
976 // TODO: Notify the control to scroll up. Should control handle this?
977 // ret = GetImplementation( control ).OnAccessibilityScroll(Direction::UP);
985 bool AccessibilityManager::AccessibilityActionScrollDown()
987 Dali::Toolkit::AccessibilityManager handle( this );
988 if( !mActionScrollDownSignal.Empty() )
990 mActionScrollDownSignal.Emit( handle );
995 if(mIsAccessibilityTtsEnabled)
997 Actor actor = GetCurrentFocusActor();
1000 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1003 // TODO: Notify the control to scroll down. Should control handle this?
1004 // ret = GetImplementation( control ).OnAccessibilityScrollDown(Direction::DOWN);
1012 bool AccessibilityManager::AccessibilityActionPageLeft()
1014 Dali::Toolkit::AccessibilityManager handle( this );
1015 if( !mActionPageLeftSignal.Empty() )
1017 mActionPageLeftSignal.Emit( handle );
1022 if(mIsAccessibilityTtsEnabled)
1024 Actor actor = GetCurrentFocusActor();
1027 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1030 // TODO: Notify the control to scroll left to the previous page. Should control handle this?
1031 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::LEFT);
1039 bool AccessibilityManager::AccessibilityActionPageRight()
1041 Dali::Toolkit::AccessibilityManager handle( this );
1042 if( !mActionPageRightSignal.Empty() )
1044 mActionPageRightSignal.Emit( handle );
1049 if(mIsAccessibilityTtsEnabled)
1051 Actor actor = GetCurrentFocusActor();
1054 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1057 // TODO: Notify the control to scroll right to the next page. Should control handle this?
1058 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::RIGHT);
1066 bool AccessibilityManager::AccessibilityActionPageUp()
1068 Dali::Toolkit::AccessibilityManager handle( this );
1069 if( !mActionPageUpSignal.Empty() )
1071 mActionPageUpSignal.Emit( handle );
1076 if(mIsAccessibilityTtsEnabled)
1078 Actor actor = GetCurrentFocusActor();
1081 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1084 // TODO: Notify the control to scroll up to the previous page. Should control handle this?
1085 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::UP);
1093 bool AccessibilityManager::AccessibilityActionPageDown()
1095 Dali::Toolkit::AccessibilityManager handle( this );
1096 if( !mActionPageDownSignal.Empty() )
1098 mActionPageDownSignal.Emit( handle );
1103 if(mIsAccessibilityTtsEnabled)
1105 Actor actor = GetCurrentFocusActor();
1108 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1111 // TODO: Notify the control to scroll down to the next page. Should control handle this?
1112 // ret = GetImplementation( control ).OnAccessibilityScrollToPage(Direction::DOWN);
1120 bool AccessibilityManager::AccessibilityActionMoveToFirst()
1122 Dali::Toolkit::AccessibilityManager handle( this );
1123 if( !mActionMoveToFirstSignal.Empty() )
1125 mActionMoveToFirstSignal.Emit( handle );
1128 // TODO: Move to the first item on screen
1130 return mIsAccessibilityTtsEnabled;
1133 bool AccessibilityManager::AccessibilityActionMoveToLast()
1135 Dali::Toolkit::AccessibilityManager handle( this );
1136 if( !mActionMoveToLastSignal.Empty() )
1138 mActionMoveToLastSignal.Emit( handle );
1141 // TODO: Move to the last item on screen
1143 return mIsAccessibilityTtsEnabled;
1146 bool AccessibilityManager::AccessibilityActionReadFromTop()
1148 Dali::Toolkit::AccessibilityManager handle( this );
1149 if( !mActionReadFromTopSignal.Empty() )
1151 mActionReadFromTopSignal.Emit( handle );
1154 // TODO: Move to the top item on screen and read from the item continuously
1156 return mIsAccessibilityTtsEnabled;
1159 bool AccessibilityManager::AccessibilityActionReadFromNext()
1161 Dali::Toolkit::AccessibilityManager handle( this );
1163 if( !mActionReadFromNextSignal.Empty() )
1165 mActionReadFromNextSignal.Emit( handle );
1168 if( mIsAccessibilityTtsEnabled )
1170 // Mark that we are in continuous play mode, so TTS signals can move focus.
1171 mContinuousPlayMode = true;
1173 // Attempt to move to the next item and read from the item continuously.
1177 return mIsAccessibilityTtsEnabled;
1180 void AccessibilityManager::TtsStateChanged( const Dali::TtsPlayer::State previousState, const Dali::TtsPlayer::State currentState )
1182 if( mContinuousPlayMode )
1184 // If we were playing and now we have stopped, attempt to play the next item.
1185 if( ( previousState == Dali::TtsPlayer::PLAYING ) && ( currentState == Dali::TtsPlayer::READY ) )
1187 // Attempt to move the focus forward and play.
1188 // If we can't cancel continuous play mode.
1189 if( !MoveFocusForward() )
1191 // We are done, exit continuous play mode.
1192 mContinuousPlayMode = false;
1197 // Unexpected play state change, exit continuous play mode.
1198 mContinuousPlayMode = false;
1203 bool AccessibilityManager::AccessibilityActionZoom()
1205 Dali::Toolkit::AccessibilityManager handle( this );
1206 if( !mActionZoomSignal.Empty() )
1208 mActionZoomSignal.Emit( handle );
1213 if(mIsAccessibilityTtsEnabled)
1215 Actor actor = GetCurrentFocusActor();
1218 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(actor);
1221 // Notify the control to zoom
1222 ret = GetImplementation( control ).OnAccessibilityZoom();
1230 bool AccessibilityManager::AccessibilityActionReadIndicatorInformation()
1232 Dali::Toolkit::AccessibilityManager handle( this );
1233 if( !mActionReadIndicatorInformationSignal.Empty() )
1235 mActionReadIndicatorInformationSignal.Emit( handle );
1238 // TODO: Read the information in the indicator
1240 return mIsAccessibilityTtsEnabled;
1243 bool AccessibilityManager::AccessibilityActionReadPauseResume()
1245 Dali::Toolkit::AccessibilityManager handle( this );
1246 if( !mActionReadPauseResumeSignal.Empty() )
1248 mActionReadPauseResumeSignal.Emit( handle );
1253 if(mIsAccessibilityTtsEnabled)
1255 // Pause or resume the TTS player
1256 Dali::TtsPlayer player = Dali::TtsPlayer::Get(Dali::TtsPlayer::SCREEN_READER);
1257 Dali::TtsPlayer::State state = player.GetState();
1258 if(state == Dali::TtsPlayer::PLAYING)
1263 else if(state == Dali::TtsPlayer::PAUSED)
1273 bool AccessibilityManager::AccessibilityActionStartStop()
1275 Dali::Toolkit::AccessibilityManager handle( this );
1276 if( !mActionStartStopSignal.Empty() )
1278 mActionStartStopSignal.Emit( handle );
1281 // TODO: Start/stop the current action
1283 return mIsAccessibilityTtsEnabled;
1286 bool AccessibilityManager::AccessibilityActionTouch(const TouchEvent& touchEvent)
1288 bool handled = false;
1290 // TODO: Need to convert the touchevent for the focused actor?
1292 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(GetCurrentFocusActor());
1295 handled = GetImplementation( control ).OnAccessibilityTouch(touchEvent);
1301 bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& panEvent)
1303 bool handled = false;
1305 if( panEvent.state == Gesture::Started )
1307 // Find the focusable actor at the event position
1308 Dali::HitTestAlgorithm::Results results;
1309 AccessibilityAdaptor adaptor = AccessibilityAdaptor::Get();
1311 Dali::HitTestAlgorithm::HitTest( Stage::GetCurrent(), panEvent.currentPosition, results, IsActorFocusableFunction );
1312 mCurrentGesturedActor = results.actor;
1314 if(!mCurrentGesturedActor)
1316 DALI_LOG_ERROR("Gesture detected, but no hit actor");
1320 // Gesture::Finished (Up) events are delivered with previous (Motion) event position
1321 // Use the real previous position; otherwise we may incorrectly get a ZERO velocity
1322 if ( Gesture::Finished != panEvent.state )
1324 // Store the previous position for next Gesture::Finished iteration.
1325 mPreviousPosition = panEvent.previousPosition;
1328 Actor rootActor = Stage::GetCurrent().GetRootLayer();
1330 Dali::PanGesture pan(panEvent.state);
1331 pan.time = panEvent.time;
1332 pan.numberOfTouches = panEvent.numberOfTouches;
1333 pan.screenPosition = panEvent.currentPosition;
1334 pan.screenDisplacement = mPreviousPosition - panEvent.currentPosition;
1335 pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
1336 pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
1338 // Only handle the pan gesture when the current focused actor is scrollable or within a scrollable actor
1339 while(mCurrentGesturedActor && mCurrentGesturedActor != rootActor && !handled)
1341 Dali::Toolkit::Control control = Dali::Toolkit::Control::DownCast(mCurrentGesturedActor);
1344 Vector2 localCurrent;
1345 control.ScreenToLocal( localCurrent.x, localCurrent.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
1346 pan.position = localCurrent;
1348 Vector2 localPrevious;
1349 control.ScreenToLocal( localPrevious.x, localPrevious.y, mPreviousPosition.x, mPreviousPosition.y );
1351 pan.displacement = localCurrent - localPrevious;
1352 pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
1353 pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
1355 handled = GetImplementation( control ).OnAccessibilityPan(pan);
1358 // If the gesture is not handled by the control, check its parent
1361 mCurrentGesturedActor = mCurrentGesturedActor.GetParent();
1363 if(!mCurrentGesturedActor)
1365 DALI_LOG_ERROR("no more gestured actor");
1370 // If handled, then update the pan gesture properties
1371 PanGestureDetector::SetPanGestureProperties( pan );
1378 Toolkit::AccessibilityManager::FocusChangedSignalType& AccessibilityManager::FocusChangedSignal()
1380 return mFocusChangedSignal;
1383 Toolkit::AccessibilityManager::FocusOvershotSignalType& AccessibilityManager::FocusOvershotSignal()
1385 return mFocusOvershotSignal;
1388 Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& AccessibilityManager::FocusedActorActivatedSignal()
1390 return mFocusedActorActivatedSignal;
1393 bool AccessibilityManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1395 bool connected( true );
1396 AccessibilityManager* manager = dynamic_cast<AccessibilityManager*>( object );
1400 if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
1402 manager->FocusChangedSignal().Connect( tracker, functor );
1404 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_OVERSHOT ) )
1406 manager->FocusOvershotSignal().Connect( tracker, functor );
1408 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ACTIVATED ) )
1410 manager->FocusedActorActivatedSignal().Connect( tracker, functor );
1414 // signalName does not match any signal
1422 } // namespace Internal
1424 } // namespace Toolkit