2 * Copyright (c) 2017 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 "keyboard-focus-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/singleton-service.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/common/stage.h>
28 #include <dali/public-api/events/key-event.h>
29 #include <dali/public-api/events/touch-data.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/public-api/object/property-map.h>
33 #include <dali/public-api/images/resource-image.h>
34 #include <dali/integration-api/debug.h>
37 #include <dali-toolkit/public-api/controls/control.h>
38 #include <dali-toolkit/public-api/controls/control-impl.h>
39 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
40 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
41 #include <dali-toolkit/devel-api/controls/control-devel.h>
42 #include <dali-toolkit/public-api/styling/style-manager.h>
43 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
54 namespace // Unnamed namespace
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
61 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
63 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
67 BaseHandle handle = KeyboardFocusManager::Get();
71 SingletonService singletonService( SingletonService::Get() );
72 if ( singletonService )
74 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
75 singletonService.Register( typeid( manager ), manager );
83 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
85 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
86 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
87 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
88 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
90 DALI_TYPE_REGISTRATION_END()
92 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
94 } // unnamed namespace
96 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
98 Toolkit::KeyboardFocusManager manager;
100 SingletonService singletonService( SingletonService::Get() );
101 if ( singletonService )
103 // Check whether the keyboard focus manager is already created
104 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
107 // If so, downcast the handle of singleton to keyboard focus manager
108 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
115 KeyboardFocusManager::KeyboardFocusManager()
116 : mPreFocusChangeSignal(),
117 mFocusChangedSignal(),
118 mFocusGroupChangedSignal(),
119 mFocusedActorEnterKeySignal(),
120 mCurrentFocusActor(),
121 mFocusIndicatorActor(),
122 mIsFocusIndicatorEnabled( -1 ),
123 mFocusGroupLoopEnabled( false ),
124 mIsWaitingKeyboardFocusChangeCommit( false ),
126 mSlotDelegate( this ),
127 mCustomAlgorithmInterface(NULL)
129 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
130 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
131 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
134 KeyboardFocusManager::~KeyboardFocusManager()
138 void KeyboardFocusManager::GetConfigurationFromStyleManger()
140 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
143 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
144 mIsFocusIndicatorEnabled = static_cast<int>(config["alwaysShowFocus"].Get<bool>());
148 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
150 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
152 if( mIsFocusIndicatorEnabled == -1 )
154 GetConfigurationFromStyleManger();
157 return DoSetCurrentFocusActor( actor );
160 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
162 bool success = false;
164 Actor currentFocusedActor = GetCurrentFocusActor();
166 // If developer set focus on same actor, doing nothing
167 if( actor == currentFocusedActor )
176 // Check whether the actor is in the stage and is keyboard focusable.
177 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
179 if( mIsFocusIndicatorEnabled )
181 actor.Add( GetFocusIndicatorActor() );
184 // Send notification for the change of focus actor
185 if( !mFocusChangedSignal.Empty() )
187 mFocusChangedSignal.Emit(currentFocusedActor, actor);
190 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
191 if( currentlyFocusedControl )
193 // Do we need it to remember if it was previously DISABLED?
194 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
195 currentlyFocusedControl.ClearKeyInputFocus();
198 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
200 // Save the current focused actor
201 mCurrentFocusActor = actor;
203 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
204 if( newlyFocusedControl )
206 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
207 newlyFocusedControl.SetKeyInputFocus();
210 // Push Current Focused Actor to FocusHistory
211 mFocusHistory.PushBack( &actor.GetBaseObject() );
213 // Delete first element before add new element when Stack is full.
214 if( mFocusHistory.Count() > MAX_HISTORY_AMOUNT )
216 FocusStackIterator beginPos = mFocusHistory.Begin();
217 mFocusHistory.Erase( beginPos );
220 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
225 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
231 Actor KeyboardFocusManager::GetCurrentFocusActor()
233 Actor actor = mCurrentFocusActor.GetHandle();
234 if( actor && ! actor.OnStage() )
236 // If the actor has been removed from the stage, then it should not be focused
239 mCurrentFocusActor.Reset();
244 Actor KeyboardFocusManager::GetCurrentFocusGroup()
246 return GetFocusGroup(GetCurrentFocusActor());
249 void KeyboardFocusManager::MoveFocusBackward()
251 // Find Pre Focused Actor when the list size is more than 1
252 if( mFocusHistory.Count() > 1 )
254 // Delete current focused actor in history
255 FocusStackIterator endPos = mFocusHistory.End();
256 endPos = mFocusHistory.Erase( --endPos );
258 // If pre-focused actors are not on stage, remove them in stack
259 while( !Dali::Actor::DownCast(BaseHandle(mFocusHistory[ mFocusHistory.Count() - 1 ])).OnStage() )
261 endPos = mFocusHistory.Erase( --endPos );
264 // Get pre focused actor
265 BaseObject* object = mFocusHistory[ mFocusHistory.Count() - 1 ];
266 BaseHandle handle( object );
267 Actor preFocusedActor = Dali::Actor::DownCast( handle );
269 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
270 mFocusHistory.Erase( --endPos );
272 SetCurrentFocusActor( preFocusedActor );
276 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
278 Toolkit::Control control = Toolkit::Control::DownCast(actor);
279 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
282 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
284 // Get the actor's parent layout control that supports two dimensional keyboard navigation
285 Actor rootActor = Stage::GetCurrent().GetRootLayer();
289 parent = actor.GetParent();
292 while( parent && !IsLayoutControl(parent) && parent != rootActor )
294 parent = parent.GetParent();
297 return Toolkit::Control::DownCast(parent);
300 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
302 Actor currentFocusActor = GetCurrentFocusActor();
304 bool succeed = false;
306 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
307 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
308 while( parentLayoutControl && !succeed )
310 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
311 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
316 Actor nextFocusableActor;
318 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
320 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
321 if( currentFocusControl )
324 Property::Index index = Property::INVALID_INDEX;
325 Property::Value value;
327 // Find property index based upon focus direction
330 case Toolkit::Control::KeyboardFocus::LEFT:
332 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
335 case Toolkit::Control::KeyboardFocus::RIGHT:
337 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
340 case Toolkit::Control::KeyboardFocus::UP:
342 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
345 case Toolkit::Control::KeyboardFocus::DOWN:
347 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
354 // If the focusable property is set then determine next focusable actor
355 if( index != Property::INVALID_INDEX)
357 value = currentFocusActor.GetProperty( index );
358 actorId = value.Get<int>();
360 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
363 if( currentFocusActor.GetParent() )
365 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
368 if( !nextFocusableActor )
370 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
376 if( !nextFocusableActor )
378 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
379 if( mCustomAlgorithmInterface )
381 mIsWaitingKeyboardFocusChangeCommit = true;
382 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
383 mIsWaitingKeyboardFocusChangeCommit = false;
385 else if( !mPreFocusChangeSignal.Empty() )
387 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
388 mIsWaitingKeyboardFocusChangeCommit = true;
389 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
390 mIsWaitingKeyboardFocusChangeCommit = false;
394 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
396 // Whether the next focusable actor is a layout control
397 if( IsLayoutControl( nextFocusableActor ) )
399 // If so, move the focus inside it.
400 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
401 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
405 // Otherwise, just set focus to the next focusable actor
406 succeed = SetCurrentFocusActor( nextFocusableActor );
414 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
416 // Ask the control for the next actor to focus
417 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
418 if(nextFocusableActor)
420 if(!nextFocusableActor.IsKeyboardFocusable())
422 // If the actor is not focusable, ask the same layout control for the next actor to focus
423 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
427 Actor currentFocusActor = GetCurrentFocusActor();
428 Actor committedFocusActor = nextFocusableActor;
430 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
431 // Signal handler can check the proposed actor and return a different actor if it wishes.
432 if( !mPreFocusChangeSignal.Empty() )
434 mIsWaitingKeyboardFocusChangeCommit = true;
435 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
436 mIsWaitingKeyboardFocusChangeCommit = false;
439 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
441 // Whether the commited focusable actor is a layout control
442 if(IsLayoutControl(committedFocusActor))
444 // If so, move the focus inside it.
445 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
446 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
450 // Otherwise, just set focus to the next focusable actor
451 if(committedFocusActor == nextFocusableActor)
453 // If the application hasn't changed our proposed actor, we informs the layout control we will
454 // move the focus to what the control returns. The control might wish to perform some actions
455 // before the focus is actually moved.
456 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
459 return SetCurrentFocusActor(committedFocusActor);
470 // No more actor can be focused in the given direction within the same layout control.
475 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
477 bool succeed = false;
479 // Get the parent layout control of the current focus group
480 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
482 while(parentLayoutControl && !succeed)
484 // If the current focus group has a parent layout control, we can probably automatically
485 // move the focus to the next focus group in the forward or backward direction.
486 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
487 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
488 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
491 if(!mFocusGroupChangedSignal.Empty())
493 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
494 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
500 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
504 Toolkit::Control control = Toolkit::Control::DownCast( actor );
507 // Notify the control that enter has been pressed on it.
508 GetImplementation( control ).KeyboardEnter();
511 // Send a notification for the actor.
512 if( !mFocusedActorEnterKeySignal.Empty() )
514 mFocusedActorEnterKeySignal.Emit( actor );
519 void KeyboardFocusManager::ClearFocus()
521 Actor actor = GetCurrentFocusActor();
524 if( mFocusIndicatorActor )
526 actor.Remove( mFocusIndicatorActor );
529 // Send notification for the change of focus actor
530 if( !mFocusChangedSignal.Empty() )
532 mFocusChangedSignal.Emit( actor, Actor() );
535 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
536 if( currentlyFocusedControl )
538 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
539 currentlyFocusedControl.ClearKeyInputFocus();
543 mCurrentFocusActor.Reset();
544 mIsFocusIndicatorEnabled = 0;
547 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
549 mFocusGroupLoopEnabled = enabled;
552 bool KeyboardFocusManager::GetFocusGroupLoop() const
554 return mFocusGroupLoopEnabled;
557 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
561 // Create/Set focus group property.
562 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
566 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
568 // Check whether the actor is a focus group
569 bool isFocusGroup = false;
573 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
574 if(propertyIsFocusGroup != Property::INVALID_INDEX)
576 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
583 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
585 // Go through the actor's hierarchy to check which focus group the actor belongs to
586 while (actor && !IsFocusGroup(actor))
588 actor = actor.GetParent();
594 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
596 if(mFocusIndicatorActor != indicator)
598 Actor currentFocusActor = GetCurrentFocusActor();
599 if(currentFocusActor)
601 // The new focus indicator should be added to the current focused actor immediately
602 if(mFocusIndicatorActor)
604 currentFocusActor.Remove(mFocusIndicatorActor);
609 currentFocusActor.Add(indicator);
613 mFocusIndicatorActor = indicator;
617 Actor KeyboardFocusManager::GetFocusIndicatorActor()
619 if( ! mFocusIndicatorActor )
621 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
622 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
624 // Apply size constraint to the focus indicator
625 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
628 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
629 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
630 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
632 return mFocusIndicatorActor;
635 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
637 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
638 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
640 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
642 std::string keyName = event.keyPressedName;
644 if( mIsFocusIndicatorEnabled == -1 )
646 GetConfigurationFromStyleManger();
649 bool isFocusStartableKey = false;
651 if(event.state == KeyEvent::Down)
653 if (keyName == "Left")
655 if(!isAccessibilityEnabled)
657 if(!mIsFocusIndicatorEnabled)
659 // Show focus indicator
660 mIsFocusIndicatorEnabled = 1;
664 // Move the focus towards left
665 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
668 isFocusStartableKey = true;
672 // Move the accessibility focus backward
673 accessibilityManager.MoveFocusBackward();
676 else if (keyName == "Right")
678 if(!isAccessibilityEnabled)
680 if(!mIsFocusIndicatorEnabled)
682 // Show focus indicator
683 mIsFocusIndicatorEnabled = 1;
687 // Move the focus towards right
688 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
693 // Move the accessibility focus forward
694 accessibilityManager.MoveFocusForward();
697 isFocusStartableKey = true;
699 else if (keyName == "Up" && !isAccessibilityEnabled)
701 if(!mIsFocusIndicatorEnabled)
703 // Show focus indicator
704 mIsFocusIndicatorEnabled = 1;
708 // Move the focus towards up
709 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
712 isFocusStartableKey = true;
714 else if (keyName == "Down" && !isAccessibilityEnabled)
716 if(!mIsFocusIndicatorEnabled)
718 // Show focus indicator
719 mIsFocusIndicatorEnabled = 1;
723 // Move the focus towards down
724 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
727 isFocusStartableKey = true;
729 else if (keyName == "Prior" && !isAccessibilityEnabled)
731 if(!mIsFocusIndicatorEnabled)
733 // Show focus indicator
734 mIsFocusIndicatorEnabled = 1;
738 // Move the focus towards the previous page
739 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
742 isFocusStartableKey = true;
744 else if (keyName == "Next" && !isAccessibilityEnabled)
746 if(!mIsFocusIndicatorEnabled)
748 // Show focus indicator
749 mIsFocusIndicatorEnabled = 1;
753 // Move the focus towards the next page
754 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
757 isFocusStartableKey = true;
759 else if (keyName == "Tab" && !isAccessibilityEnabled)
761 if(!mIsFocusIndicatorEnabled)
763 // Show focus indicator
764 mIsFocusIndicatorEnabled = 1;
768 // "Tab" key changes the focus group in the forward direction and
769 // "Shift-Tab" key changes it in the backward direction.
770 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
773 isFocusStartableKey = true;
775 else if (keyName == "space" && !isAccessibilityEnabled)
777 if(!mIsFocusIndicatorEnabled)
779 // Show focus indicator
780 mIsFocusIndicatorEnabled = 1;
783 isFocusStartableKey = true;
785 else if (keyName == "" && !isAccessibilityEnabled)
787 // Check the fake key event for evas-plugin case
788 if(!mIsFocusIndicatorEnabled)
790 // Show focus indicator
791 mIsFocusIndicatorEnabled = 1;
794 isFocusStartableKey = true;
796 else if (keyName == "Backspace" && !isAccessibilityEnabled)
798 // Emit signal to go back to the previous view???
800 else if (keyName == "Escape" && !isAccessibilityEnabled)
804 else if(event.state == KeyEvent::Up)
806 if (keyName == "Return")
808 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
810 // Show focus indicator
811 mIsFocusIndicatorEnabled = 1;
815 // The focused actor has enter pressed on it
817 if( !isAccessibilityEnabled )
819 actor = GetCurrentFocusActor();
823 actor = accessibilityManager.GetCurrentFocusActor();
828 DoKeyboardEnter( actor );
832 isFocusStartableKey = true;
836 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
838 Actor actor = GetCurrentFocusActor();
841 // Make sure the focused actor is highlighted
842 actor.Add( GetFocusIndicatorActor() );
846 // No actor is focused but keyboard focus is activated by the key press
847 // Let's try to move the initial focus
848 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
853 void KeyboardFocusManager::OnTouch(const TouchData& touch)
855 // Clear the focus when user touch the screen.
856 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
857 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
863 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
865 return mPreFocusChangeSignal;
868 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
870 return mFocusChangedSignal;
873 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
875 return mFocusGroupChangedSignal;
878 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
880 return mFocusedActorEnterKeySignal;
883 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
885 Dali::BaseHandle handle( object );
887 bool connected( true );
888 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
890 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
892 manager->PreFocusChangeSignal().Connect( tracker, functor );
894 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
896 manager->FocusChangedSignal().Connect( tracker, functor );
898 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
900 manager->FocusGroupChangedSignal().Connect( tracker, functor );
902 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
904 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
908 // signalName does not match any signal
915 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
917 mCustomAlgorithmInterface = &interface;
920 } // namespace Internal
922 } // namespace Toolkit