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/controls/control-devel.h>
51 namespace // Unnamed namespace
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
58 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
60 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
64 BaseHandle handle = KeyboardFocusManager::Get();
68 SingletonService singletonService( SingletonService::Get() );
69 if ( singletonService )
71 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
72 singletonService.Register( typeid( manager ), manager );
80 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
82 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
83 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
84 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
85 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
87 DALI_TYPE_REGISTRATION_END()
89 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
91 } // unnamed namespace
93 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
95 Toolkit::KeyboardFocusManager manager;
97 SingletonService singletonService( SingletonService::Get() );
98 if ( singletonService )
100 // Check whether the keyboard focus manager is already created
101 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
104 // If so, downcast the handle of singleton to keyboard focus manager
105 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
112 KeyboardFocusManager::KeyboardFocusManager()
113 : mPreFocusChangeSignal(),
114 mFocusChangedSignal(),
115 mFocusGroupChangedSignal(),
116 mFocusedActorEnterKeySignal(),
117 mCurrentFocusActor(),
118 mFocusIndicatorActor(),
119 mFocusGroupLoopEnabled( false ),
120 mIsFocusIndicatorEnabled( false ),
121 mIsWaitingKeyboardFocusChangeCommit( false ),
123 mSlotDelegate( this ),
124 mCustomAlgorithmInterface(NULL)
126 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
127 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
128 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
131 KeyboardFocusManager::~KeyboardFocusManager()
135 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
137 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
139 return DoSetCurrentFocusActor( actor );
142 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
144 bool success = false;
146 Actor currentFocusedActor = GetCurrentFocusActor();
148 // If developer set focus on same actor, doing nothing
149 if( actor == currentFocusedActor )
158 // Check whether the actor is in the stage and is keyboard focusable.
159 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
161 if( mIsFocusIndicatorEnabled )
163 actor.Add( GetFocusIndicatorActor() );
166 // Send notification for the change of focus actor
167 if( !mFocusChangedSignal.Empty() )
169 mFocusChangedSignal.Emit(currentFocusedActor, actor);
172 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
173 if( currentlyFocusedControl )
175 // Do we need it to remember if it was previously DISABLED?
176 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
177 currentlyFocusedControl.ClearKeyInputFocus();
180 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
182 // Save the current focused actor
183 mCurrentFocusActor = actor;
185 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
186 if( newlyFocusedControl )
188 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
189 newlyFocusedControl.SetKeyInputFocus();
192 // Push Current Focused Actor to FocusHistory
193 mFocusHistory.PushBack( &actor.GetBaseObject() );
195 // Delete first element before add new element when Stack is full.
196 if( mFocusHistory.Count() > MAX_HISTORY_AMOUNT )
198 FocusStackIterator beginPos = mFocusHistory.Begin();
199 mFocusHistory.Erase( beginPos );
202 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
207 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
213 Actor KeyboardFocusManager::GetCurrentFocusActor()
215 Actor actor = mCurrentFocusActor.GetHandle();
216 if( actor && ! actor.OnStage() )
218 // If the actor has been removed from the stage, then it should not be focused
221 mCurrentFocusActor.Reset();
226 Actor KeyboardFocusManager::GetCurrentFocusGroup()
228 return GetFocusGroup(GetCurrentFocusActor());
231 void KeyboardFocusManager::MoveFocusBackward()
233 // Find Pre Focused Actor when the list size is more than 1
234 if( mFocusHistory.Count() > 1 )
236 // Delete current focused actor in history
237 FocusStackIterator endPos = mFocusHistory.End();
238 endPos = mFocusHistory.Erase( --endPos );
240 // If pre-focused actors are not on stage, remove them in stack
241 while( !Dali::Actor::DownCast(BaseHandle(mFocusHistory[ mFocusHistory.Count() - 1 ])).OnStage() )
243 endPos = mFocusHistory.Erase( --endPos );
246 // Get pre focused actor
247 BaseObject* object = mFocusHistory[ mFocusHistory.Count() - 1 ];
248 BaseHandle handle( object );
249 Actor preFocusedActor = Dali::Actor::DownCast( handle );
251 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
252 mFocusHistory.Erase( --endPos );
254 SetCurrentFocusActor( preFocusedActor );
258 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
260 Toolkit::Control control = Toolkit::Control::DownCast(actor);
261 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
264 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
266 // Get the actor's parent layout control that supports two dimensional keyboard navigation
267 Actor rootActor = Stage::GetCurrent().GetRootLayer();
271 parent = actor.GetParent();
274 while( parent && !IsLayoutControl(parent) && parent != rootActor )
276 parent = parent.GetParent();
279 return Toolkit::Control::DownCast(parent);
282 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
284 Actor currentFocusActor = GetCurrentFocusActor();
286 bool succeed = false;
288 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
289 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
290 while( parentLayoutControl && !succeed )
292 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
293 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
298 Actor nextFocusableActor;
300 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
302 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
303 if( currentFocusControl )
306 Property::Index index = Property::INVALID_INDEX;
307 Property::Value value;
309 // Find property index based upon focus direction
312 case Toolkit::Control::KeyboardFocus::LEFT:
314 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
317 case Toolkit::Control::KeyboardFocus::RIGHT:
319 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
322 case Toolkit::Control::KeyboardFocus::UP:
324 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
327 case Toolkit::Control::KeyboardFocus::DOWN:
329 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
336 // If the focusable property is set then determine next focusable actor
337 if( index != Property::INVALID_INDEX)
339 value = currentFocusActor.GetProperty( index );
340 actorId = value.Get<int>();
342 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
345 if( currentFocusActor.GetParent() )
347 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
350 if( !nextFocusableActor )
352 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
358 if( !nextFocusableActor )
360 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
361 if( mCustomAlgorithmInterface )
363 mIsWaitingKeyboardFocusChangeCommit = true;
364 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
365 mIsWaitingKeyboardFocusChangeCommit = false;
367 else if( !mPreFocusChangeSignal.Empty() )
369 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
370 mIsWaitingKeyboardFocusChangeCommit = true;
371 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
372 mIsWaitingKeyboardFocusChangeCommit = false;
376 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
378 // Whether the next focusable actor is a layout control
379 if( IsLayoutControl( nextFocusableActor ) )
381 // If so, move the focus inside it.
382 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
383 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
387 // Otherwise, just set focus to the next focusable actor
388 succeed = SetCurrentFocusActor( nextFocusableActor );
396 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
398 // Ask the control for the next actor to focus
399 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
400 if(nextFocusableActor)
402 if(!nextFocusableActor.IsKeyboardFocusable())
404 // If the actor is not focusable, ask the same layout control for the next actor to focus
405 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
409 Actor currentFocusActor = GetCurrentFocusActor();
410 Actor committedFocusActor = nextFocusableActor;
412 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
413 // Signal handler can check the proposed actor and return a different actor if it wishes.
414 if( !mPreFocusChangeSignal.Empty() )
416 mIsWaitingKeyboardFocusChangeCommit = true;
417 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
418 mIsWaitingKeyboardFocusChangeCommit = false;
421 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
423 // Whether the commited focusable actor is a layout control
424 if(IsLayoutControl(committedFocusActor))
426 // If so, move the focus inside it.
427 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
428 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
432 // Otherwise, just set focus to the next focusable actor
433 if(committedFocusActor == nextFocusableActor)
435 // If the application hasn't changed our proposed actor, we informs the layout control we will
436 // move the focus to what the control returns. The control might wish to perform some actions
437 // before the focus is actually moved.
438 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
441 return SetCurrentFocusActor(committedFocusActor);
452 // No more actor can be focused in the given direction within the same layout control.
457 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
459 bool succeed = false;
461 // Get the parent layout control of the current focus group
462 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
464 while(parentLayoutControl && !succeed)
466 // If the current focus group has a parent layout control, we can probably automatically
467 // move the focus to the next focus group in the forward or backward direction.
468 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
469 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
470 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
473 if(!mFocusGroupChangedSignal.Empty())
475 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
476 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
482 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
486 Toolkit::Control control = Toolkit::Control::DownCast( actor );
489 // Notify the control that enter has been pressed on it.
490 GetImplementation( control ).KeyboardEnter();
493 // Send a notification for the actor.
494 if( !mFocusedActorEnterKeySignal.Empty() )
496 mFocusedActorEnterKeySignal.Emit( actor );
501 void KeyboardFocusManager::ClearFocus()
503 Actor actor = GetCurrentFocusActor();
506 if( mFocusIndicatorActor )
508 actor.Remove( mFocusIndicatorActor );
511 // Send notification for the change of focus actor
512 if( !mFocusChangedSignal.Empty() )
514 mFocusChangedSignal.Emit( actor, Actor() );
517 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
518 if( currentlyFocusedControl )
520 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
521 currentlyFocusedControl.ClearKeyInputFocus();
525 mCurrentFocusActor.Reset();
526 mIsFocusIndicatorEnabled = false;
529 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
531 mFocusGroupLoopEnabled = enabled;
534 bool KeyboardFocusManager::GetFocusGroupLoop() const
536 return mFocusGroupLoopEnabled;
539 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
543 // Create/Set focus group property.
544 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
548 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
550 // Check whether the actor is a focus group
551 bool isFocusGroup = false;
555 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
556 if(propertyIsFocusGroup != Property::INVALID_INDEX)
558 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
565 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
567 // Go through the actor's hierarchy to check which focus group the actor belongs to
568 while (actor && !IsFocusGroup(actor))
570 actor = actor.GetParent();
576 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
578 if(mFocusIndicatorActor != indicator)
580 Actor currentFocusActor = GetCurrentFocusActor();
581 if(currentFocusActor)
583 // The new focus indicator should be added to the current focused actor immediately
584 if(mFocusIndicatorActor)
586 currentFocusActor.Remove(mFocusIndicatorActor);
591 currentFocusActor.Add(indicator);
595 mFocusIndicatorActor = indicator;
599 Actor KeyboardFocusManager::GetFocusIndicatorActor()
601 if( ! mFocusIndicatorActor )
603 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
604 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
606 // Apply size constraint to the focus indicator
607 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
610 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
611 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
612 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
614 return mFocusIndicatorActor;
617 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
619 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
620 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
622 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
624 std::string keyName = event.keyPressedName;
626 bool isFocusStartableKey = false;
628 if(event.state == KeyEvent::Down)
630 if (keyName == "Left")
632 if(!isAccessibilityEnabled)
634 if(!mIsFocusIndicatorEnabled)
636 // Show focus indicator
637 mIsFocusIndicatorEnabled = true;
641 // Move the focus towards left
642 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
645 isFocusStartableKey = true;
649 // Move the accessibility focus backward
650 accessibilityManager.MoveFocusBackward();
653 else if (keyName == "Right")
655 if(!isAccessibilityEnabled)
657 if(!mIsFocusIndicatorEnabled)
659 // Show focus indicator
660 mIsFocusIndicatorEnabled = true;
664 // Move the focus towards right
665 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
670 // Move the accessibility focus forward
671 accessibilityManager.MoveFocusForward();
674 isFocusStartableKey = true;
676 else if (keyName == "Up" && !isAccessibilityEnabled)
678 if(!mIsFocusIndicatorEnabled)
680 // Show focus indicator
681 mIsFocusIndicatorEnabled = true;
685 // Move the focus towards up
686 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
689 isFocusStartableKey = true;
691 else if (keyName == "Down" && !isAccessibilityEnabled)
693 if(!mIsFocusIndicatorEnabled)
695 // Show focus indicator
696 mIsFocusIndicatorEnabled = true;
700 // Move the focus towards down
701 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
704 isFocusStartableKey = true;
706 else if (keyName == "Prior" && !isAccessibilityEnabled)
708 if(!mIsFocusIndicatorEnabled)
710 // Show focus indicator
711 mIsFocusIndicatorEnabled = true;
715 // Move the focus towards the previous page
716 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
719 isFocusStartableKey = true;
721 else if (keyName == "Next" && !isAccessibilityEnabled)
723 if(!mIsFocusIndicatorEnabled)
725 // Show focus indicator
726 mIsFocusIndicatorEnabled = true;
730 // Move the focus towards the next page
731 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
734 isFocusStartableKey = true;
736 else if (keyName == "Tab" && !isAccessibilityEnabled)
738 if(!mIsFocusIndicatorEnabled)
740 // Show focus indicator
741 mIsFocusIndicatorEnabled = true;
745 // "Tab" key changes the focus group in the forward direction and
746 // "Shift-Tab" key changes it in the backward direction.
747 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
750 isFocusStartableKey = true;
752 else if (keyName == "space" && !isAccessibilityEnabled)
754 if(!mIsFocusIndicatorEnabled)
756 // Show focus indicator
757 mIsFocusIndicatorEnabled = true;
760 isFocusStartableKey = true;
762 else if (keyName == "" && !isAccessibilityEnabled)
764 // Check the fake key event for evas-plugin case
765 if(!mIsFocusIndicatorEnabled)
767 // Show focus indicator
768 mIsFocusIndicatorEnabled = true;
771 isFocusStartableKey = true;
773 else if (keyName == "Backspace" && !isAccessibilityEnabled)
775 // Emit signal to go back to the previous view???
777 else if (keyName == "Escape" && !isAccessibilityEnabled)
781 else if(event.state == KeyEvent::Up)
783 if (keyName == "Return")
785 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
787 // Show focus indicator
788 mIsFocusIndicatorEnabled = true;
792 // The focused actor has enter pressed on it
794 if( !isAccessibilityEnabled )
796 actor = GetCurrentFocusActor();
800 actor = accessibilityManager.GetCurrentFocusActor();
805 DoKeyboardEnter( actor );
809 isFocusStartableKey = true;
813 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
815 Actor actor = GetCurrentFocusActor();
818 // Make sure the focused actor is highlighted
819 actor.Add( GetFocusIndicatorActor() );
823 // No actor is focused but keyboard focus is activated by the key press
824 // Let's try to move the initial focus
825 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
830 void KeyboardFocusManager::OnTouch(const TouchData& touch)
832 // Clear the focus when user touch the screen.
833 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
834 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
840 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
842 return mPreFocusChangeSignal;
845 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
847 return mFocusChangedSignal;
850 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
852 return mFocusGroupChangedSignal;
855 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
857 return mFocusedActorEnterKeySignal;
860 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
862 Dali::BaseHandle handle( object );
864 bool connected( true );
865 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
867 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
869 manager->PreFocusChangeSignal().Connect( tracker, functor );
871 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
873 manager->FocusChangedSignal().Connect( tracker, functor );
875 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
877 manager->FocusGroupChangedSignal().Connect( tracker, functor );
879 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
881 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
885 // signalName does not match any signal
892 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
894 mCustomAlgorithmInterface = &interface;
897 } // namespace Internal
899 } // namespace Toolkit