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/images/resource-image.h>
33 #include <dali/integration-api/debug.h>
36 #include <dali-toolkit/public-api/controls/control.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
39 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
40 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
41 #include <dali-toolkit/devel-api/controls/control-devel.h>
52 namespace // Unnamed namespace
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
59 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
61 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
65 BaseHandle handle = KeyboardFocusManager::Get();
69 SingletonService singletonService( SingletonService::Get() );
70 if ( singletonService )
72 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
73 singletonService.Register( typeid( manager ), manager );
81 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
83 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
84 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
85 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
86 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
88 DALI_TYPE_REGISTRATION_END()
90 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
92 } // unnamed namespace
94 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
96 Toolkit::KeyboardFocusManager manager;
98 SingletonService singletonService( SingletonService::Get() );
99 if ( singletonService )
101 // Check whether the keyboard focus manager is already created
102 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
105 // If so, downcast the handle of singleton to keyboard focus manager
106 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
113 KeyboardFocusManager::KeyboardFocusManager()
114 : mPreFocusChangeSignal(),
115 mFocusChangedSignal(),
116 mFocusGroupChangedSignal(),
117 mFocusedActorEnterKeySignal(),
118 mCurrentFocusActor( 0 ),
119 mFocusIndicatorActor(),
120 mFocusGroupLoopEnabled( false ),
121 mIsFocusIndicatorEnabled( true ),
122 mIsWaitingKeyboardFocusChangeCommit( false ),
124 mSlotDelegate( this ),
125 mCustomAlgorithmInterface(NULL)
127 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
128 Toolkit::KeyInputFocusManager::Get().UnhandledKeyEventSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
129 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
132 KeyboardFocusManager::~KeyboardFocusManager()
136 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
138 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
140 return DoSetCurrentFocusActor( actor );
143 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
145 bool success = false;
147 Actor currentFocusedActor = GetCurrentFocusActor();
149 // If developer set focus on same actor, doing nothing
150 if( actor == currentFocusedActor )
159 // Check whether the actor is in the stage and is keyboard focusable.
160 if( actor && actor.IsKeyboardFocusable() )
162 if( mIsFocusIndicatorEnabled )
164 actor.Add( GetFocusIndicatorActor() );
167 // Send notification for the change of focus actor
168 if( !mFocusChangedSignal.Empty() )
170 mFocusChangedSignal.Emit(currentFocusedActor, actor);
173 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
174 if( currentlyFocusedControl )
176 // Do we need it to remember if it was previously DISABLED?
177 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
178 currentlyFocusedControl.ClearKeyInputFocus();
181 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
183 // Save the current focused actor
184 mCurrentFocusActor = actor.GetId();
186 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
187 if( newlyFocusedControl )
189 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
190 newlyFocusedControl.SetKeyInputFocus();
193 // Push Current Focused Actor to FocusHistory
194 mFocusHistory.PushBack( &actor.GetBaseObject() );
196 // Delete first element before add new element when Stack is full.
197 if( mFocusHistory.Count() > MAX_HISTORY_AMOUNT )
199 FocusStackIterator beginPos = mFocusHistory.Begin();
200 mFocusHistory.Erase( beginPos );
203 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
208 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
214 Actor KeyboardFocusManager::GetCurrentFocusActor()
216 Actor rootActor = Stage::GetCurrent().GetRootLayer();
217 return rootActor.FindChildById(mCurrentFocusActor);
220 Actor KeyboardFocusManager::GetCurrentFocusGroup()
222 return GetFocusGroup(GetCurrentFocusActor());
225 void KeyboardFocusManager::MoveFocusBackward()
227 // Find Pre Focused Actor when the list size is more than 1
228 if( mFocusHistory.Count() > 1 )
230 // Delete current focused actor in history
231 FocusStackIterator endPos = mFocusHistory.End();
232 endPos = mFocusHistory.Erase( --endPos );
234 // If pre-focused actors are not on stage, remove them in stack
235 while( !Dali::Actor::DownCast(BaseHandle(mFocusHistory[ mFocusHistory.Count() - 1 ])).OnStage() )
237 endPos = mFocusHistory.Erase( --endPos );
240 // Get pre focused actor
241 BaseObject* object = mFocusHistory[ mFocusHistory.Count() - 1 ];
242 BaseHandle handle( object );
243 Actor preFocusedActor = Dali::Actor::DownCast( handle );
245 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
246 mFocusHistory.Erase( --endPos );
248 SetCurrentFocusActor( preFocusedActor );
252 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
254 Toolkit::Control control = Toolkit::Control::DownCast(actor);
255 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
258 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
260 // Get the actor's parent layout control that supports two dimensional keyboard navigation
261 Actor rootActor = Stage::GetCurrent().GetRootLayer();
265 parent = actor.GetParent();
268 while( parent && !IsLayoutControl(parent) && parent != rootActor )
270 parent = parent.GetParent();
273 return Toolkit::Control::DownCast(parent);
276 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
278 Actor currentFocusActor = GetCurrentFocusActor();
280 bool succeed = false;
282 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
283 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
284 while( parentLayoutControl && !succeed )
286 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
287 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
292 Actor nextFocusableActor;
294 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
296 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
297 if( currentFocusControl )
300 Property::Index index = Property::INVALID_INDEX;
301 Property::Value value;
303 // Find property index based upon focus direction
306 case Toolkit::Control::KeyboardFocus::LEFT:
308 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
311 case Toolkit::Control::KeyboardFocus::RIGHT:
313 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
316 case Toolkit::Control::KeyboardFocus::UP:
318 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
321 case Toolkit::Control::KeyboardFocus::DOWN:
323 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
330 // If the focusable property is set then determine next focusable actor
331 if( index != Property::INVALID_INDEX)
333 value = currentFocusActor.GetProperty( index );
334 actorId = value.Get<int>();
336 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
339 if( currentFocusActor.GetParent() )
341 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
344 if( !nextFocusableActor )
346 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
352 if( !nextFocusableActor )
354 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
355 if( mCustomAlgorithmInterface )
357 mIsWaitingKeyboardFocusChangeCommit = true;
358 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
359 mIsWaitingKeyboardFocusChangeCommit = false;
361 else if( !mPreFocusChangeSignal.Empty() )
363 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
364 mIsWaitingKeyboardFocusChangeCommit = true;
365 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
366 mIsWaitingKeyboardFocusChangeCommit = false;
370 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
372 // Whether the next focusable actor is a layout control
373 if( IsLayoutControl( nextFocusableActor ) )
375 // If so, move the focus inside it.
376 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
377 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
381 // Otherwise, just set focus to the next focusable actor
382 succeed = SetCurrentFocusActor( nextFocusableActor );
390 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
392 // Ask the control for the next actor to focus
393 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
394 if(nextFocusableActor)
396 if(!nextFocusableActor.IsKeyboardFocusable())
398 // If the actor is not focusable, ask the same layout control for the next actor to focus
399 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
403 Actor currentFocusActor = GetCurrentFocusActor();
404 Actor committedFocusActor = nextFocusableActor;
406 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
407 // Signal handler can check the proposed actor and return a different actor if it wishes.
408 if( !mPreFocusChangeSignal.Empty() )
410 mIsWaitingKeyboardFocusChangeCommit = true;
411 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
412 mIsWaitingKeyboardFocusChangeCommit = false;
415 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
417 // Whether the commited focusable actor is a layout control
418 if(IsLayoutControl(committedFocusActor))
420 // If so, move the focus inside it.
421 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
422 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
426 // Otherwise, just set focus to the next focusable actor
427 if(committedFocusActor == nextFocusableActor)
429 // If the application hasn't changed our proposed actor, we informs the layout control we will
430 // move the focus to what the control returns. The control might wish to perform some actions
431 // before the focus is actually moved.
432 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
435 return SetCurrentFocusActor(committedFocusActor);
446 // No more actor can be focused in the given direction within the same layout control.
451 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
453 bool succeed = false;
455 // Get the parent layout control of the current focus group
456 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
458 while(parentLayoutControl && !succeed)
460 // If the current focus group has a parent layout control, we can probably automatically
461 // move the focus to the next focus group in the forward or backward direction.
462 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
463 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
464 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
467 if(!mFocusGroupChangedSignal.Empty())
469 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
470 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
476 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
480 Toolkit::Control control = Toolkit::Control::DownCast( actor );
483 // Notify the control that enter has been pressed on it.
484 GetImplementation( control ).KeyboardEnter();
487 // Send a notification for the actor.
488 if( !mFocusedActorEnterKeySignal.Empty() )
490 mFocusedActorEnterKeySignal.Emit( actor );
495 void KeyboardFocusManager::ClearFocus()
497 Actor actor = GetCurrentFocusActor();
500 if( mFocusIndicatorActor )
502 actor.Remove( mFocusIndicatorActor );
505 // Send notification for the change of focus actor
506 if( !mFocusChangedSignal.Empty() )
508 mFocusChangedSignal.Emit( actor, Actor() );
511 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
512 if( currentlyFocusedControl )
514 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
515 currentlyFocusedControl.ClearKeyInputFocus();
519 mCurrentFocusActor = 0;
520 mIsFocusIndicatorEnabled = false;
523 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
525 mFocusGroupLoopEnabled = enabled;
528 bool KeyboardFocusManager::GetFocusGroupLoop() const
530 return mFocusGroupLoopEnabled;
533 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
537 // Create/Set focus group property.
538 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
542 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
544 // Check whether the actor is a focus group
545 bool isFocusGroup = false;
549 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
550 if(propertyIsFocusGroup != Property::INVALID_INDEX)
552 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
559 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
561 // Go through the actor's hierarchy to check which focus group the actor belongs to
562 while (actor && !IsFocusGroup(actor))
564 actor = actor.GetParent();
570 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
572 if(mFocusIndicatorActor != indicator)
574 Actor currentFocusActor = GetCurrentFocusActor();
575 if(currentFocusActor)
577 // The new focus indicator should be added to the current focused actor immediately
578 if(mFocusIndicatorActor)
580 currentFocusActor.Remove(mFocusIndicatorActor);
585 currentFocusActor.Add(indicator);
589 mFocusIndicatorActor = indicator;
593 Actor KeyboardFocusManager::GetFocusIndicatorActor()
595 if( ! mFocusIndicatorActor )
597 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
598 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
600 // Apply size constraint to the focus indicator
601 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
604 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
605 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
606 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
608 return mFocusIndicatorActor;
611 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
613 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
614 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
616 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
618 std::string keyName = event.keyPressedName;
620 bool isFocusStartableKey = false;
622 if(event.state == KeyEvent::Down)
624 if (keyName == "Left")
626 if(!isAccessibilityEnabled)
628 if(!mIsFocusIndicatorEnabled)
630 // Show focus indicator
631 mIsFocusIndicatorEnabled = true;
635 // Move the focus towards left
636 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
639 isFocusStartableKey = true;
643 // Move the accessibility focus backward
644 accessibilityManager.MoveFocusBackward();
647 else if (keyName == "Right")
649 if(!isAccessibilityEnabled)
651 if(!mIsFocusIndicatorEnabled)
653 // Show focus indicator
654 mIsFocusIndicatorEnabled = true;
658 // Move the focus towards right
659 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
664 // Move the accessibility focus forward
665 accessibilityManager.MoveFocusForward();
668 isFocusStartableKey = true;
670 else if (keyName == "Up" && !isAccessibilityEnabled)
672 if(!mIsFocusIndicatorEnabled)
674 // Show focus indicator
675 mIsFocusIndicatorEnabled = true;
679 // Move the focus towards up
680 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
683 isFocusStartableKey = true;
685 else if (keyName == "Down" && !isAccessibilityEnabled)
687 if(!mIsFocusIndicatorEnabled)
689 // Show focus indicator
690 mIsFocusIndicatorEnabled = true;
694 // Move the focus towards down
695 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
698 isFocusStartableKey = true;
700 else if (keyName == "Prior" && !isAccessibilityEnabled)
702 if(!mIsFocusIndicatorEnabled)
704 // Show focus indicator
705 mIsFocusIndicatorEnabled = true;
709 // Move the focus towards the previous page
710 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
713 isFocusStartableKey = true;
715 else if (keyName == "Next" && !isAccessibilityEnabled)
717 if(!mIsFocusIndicatorEnabled)
719 // Show focus indicator
720 mIsFocusIndicatorEnabled = true;
724 // Move the focus towards the next page
725 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
728 isFocusStartableKey = true;
730 else if (keyName == "Tab" && !isAccessibilityEnabled)
732 if(!mIsFocusIndicatorEnabled)
734 // Show focus indicator
735 mIsFocusIndicatorEnabled = true;
739 // "Tab" key changes the focus group in the forward direction and
740 // "Shift-Tab" key changes it in the backward direction.
741 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
744 isFocusStartableKey = true;
746 else if (keyName == "space" && !isAccessibilityEnabled)
748 if(!mIsFocusIndicatorEnabled)
750 // Show focus indicator
751 mIsFocusIndicatorEnabled = true;
754 isFocusStartableKey = true;
756 else if (keyName == "" && !isAccessibilityEnabled)
758 // Check the fake key event for evas-plugin case
759 if(!mIsFocusIndicatorEnabled)
761 // Show focus indicator
762 mIsFocusIndicatorEnabled = true;
765 isFocusStartableKey = true;
767 else if (keyName == "Backspace" && !isAccessibilityEnabled)
769 // Emit signal to go back to the previous view???
771 else if (keyName == "Escape" && !isAccessibilityEnabled)
775 else if(event.state == KeyEvent::Up)
777 if (keyName == "Return")
779 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
781 // Show focus indicator
782 mIsFocusIndicatorEnabled = true;
786 // The focused actor has enter pressed on it
788 if( !isAccessibilityEnabled )
790 actor = GetCurrentFocusActor();
794 actor = accessibilityManager.GetCurrentFocusActor();
799 DoKeyboardEnter( actor );
803 isFocusStartableKey = true;
807 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
809 Actor actor = GetCurrentFocusActor();
812 // Make sure the focused actor is highlighted
813 actor.Add( GetFocusIndicatorActor() );
817 // No actor is focused but keyboard focus is activated by the key press
818 // Let's try to move the initial focus
819 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
824 void KeyboardFocusManager::OnTouch(const TouchData& touch)
826 // Clear the focus when user touch the screen.
827 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
828 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
834 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
836 return mPreFocusChangeSignal;
839 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
841 return mFocusChangedSignal;
844 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
846 return mFocusGroupChangedSignal;
849 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
851 return mFocusedActorEnterKeySignal;
854 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
856 Dali::BaseHandle handle( object );
858 bool connected( true );
859 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
861 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
863 manager->PreFocusChangeSignal().Connect( tracker, functor );
865 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
867 manager->FocusChangedSignal().Connect( tracker, functor );
869 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
871 manager->FocusGroupChangedSignal().Connect( tracker, functor );
873 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
875 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
879 // signalName does not match any signal
886 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
888 mCustomAlgorithmInterface = &interface;
891 } // namespace Internal
893 } // namespace Toolkit