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 // Check whether the actor is in the stage and is keyboard focusable.
148 if( actor && actor.IsKeyboardFocusable() )
150 if( mIsFocusIndicatorEnabled )
152 actor.Add( GetFocusIndicatorActor() );
154 // Send notification for the change of focus actor
155 Actor currentFocusedActor = GetCurrentFocusActor();
157 if( !mFocusChangedSignal.Empty() )
159 mFocusChangedSignal.Emit(currentFocusedActor, actor);
162 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
163 if( currentlyFocusedControl )
165 // Do we need it to remember if it was previously DISABLED?
166 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
167 currentlyFocusedControl.ClearKeyInputFocus();
170 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
172 // Save the current focused actor
173 mCurrentFocusActor = actor.GetId();
175 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
176 if( newlyFocusedControl )
178 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
179 newlyFocusedControl.SetKeyInputFocus();
182 // Push Current Focused Actor to FocusHistory
183 mFocusHistory.PushBack( &actor.GetBaseObject() );
185 // Delete first element before add new element when Stack is full.
186 if( mFocusHistory.Count() > MAX_HISTORY_AMOUNT )
188 FocusStackIterator beginPos = mFocusHistory.Begin();
189 mFocusHistory.Erase( beginPos );
192 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
197 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
203 Actor KeyboardFocusManager::GetCurrentFocusActor()
205 Actor rootActor = Stage::GetCurrent().GetRootLayer();
206 return rootActor.FindChildById(mCurrentFocusActor);
209 Actor KeyboardFocusManager::GetCurrentFocusGroup()
211 return GetFocusGroup(GetCurrentFocusActor());
214 void KeyboardFocusManager::MoveFocusBackward()
216 // Find Pre Focused Actor when the list size is more than 1
217 if( mFocusHistory.Count() > 1 )
219 // Delete current focused actor in history
220 FocusStackIterator endPos = mFocusHistory.End();
221 endPos = mFocusHistory.Erase( --endPos );
223 // If pre-focused actors are not on stage, remove them in stack
224 while( !Dali::Actor::DownCast(BaseHandle(mFocusHistory[ mFocusHistory.Count() - 1 ])).OnStage() )
226 endPos = mFocusHistory.Erase( --endPos );
229 // Get pre focused actor
230 BaseObject* object = mFocusHistory[ mFocusHistory.Count() - 1 ];
231 BaseHandle handle( object );
232 Actor preFocusedActor = Dali::Actor::DownCast( handle );
234 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
235 mFocusHistory.Erase( --endPos );
237 SetCurrentFocusActor( preFocusedActor );
241 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
243 Toolkit::Control control = Toolkit::Control::DownCast(actor);
244 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
247 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
249 // Get the actor's parent layout control that supports two dimensional keyboard navigation
250 Actor rootActor = Stage::GetCurrent().GetRootLayer();
254 parent = actor.GetParent();
257 while( parent && !IsLayoutControl(parent) && parent != rootActor )
259 parent = parent.GetParent();
262 return Toolkit::Control::DownCast(parent);
265 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
267 Actor currentFocusActor = GetCurrentFocusActor();
269 bool succeed = false;
271 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
272 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
273 while( parentLayoutControl && !succeed )
275 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
276 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
281 Actor nextFocusableActor;
283 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
285 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
286 if( currentFocusControl )
289 Property::Index index = Property::INVALID_INDEX;
290 Property::Value value;
292 // Find property index based upon focus direction
295 case Toolkit::Control::KeyboardFocus::LEFT:
297 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
300 case Toolkit::Control::KeyboardFocus::RIGHT:
302 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
305 case Toolkit::Control::KeyboardFocus::UP:
307 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
310 case Toolkit::Control::KeyboardFocus::DOWN:
312 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
319 // If the focusable property is set then determine next focusable actor
320 if( index != Property::INVALID_INDEX)
322 value = currentFocusActor.GetProperty( index );
323 actorId = value.Get<int>();
325 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
328 if( currentFocusActor.GetParent() )
330 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
333 if( !nextFocusableActor )
335 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
341 if( !nextFocusableActor )
343 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
344 if( mCustomAlgorithmInterface )
346 mIsWaitingKeyboardFocusChangeCommit = true;
347 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
348 mIsWaitingKeyboardFocusChangeCommit = false;
350 else if( !mPreFocusChangeSignal.Empty() )
352 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
353 mIsWaitingKeyboardFocusChangeCommit = true;
354 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
355 mIsWaitingKeyboardFocusChangeCommit = false;
359 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
361 // Whether the next focusable actor is a layout control
362 if( IsLayoutControl( nextFocusableActor ) )
364 // If so, move the focus inside it.
365 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
366 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
370 // Otherwise, just set focus to the next focusable actor
371 succeed = SetCurrentFocusActor( nextFocusableActor );
379 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
381 // Ask the control for the next actor to focus
382 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
383 if(nextFocusableActor)
385 if(!nextFocusableActor.IsKeyboardFocusable())
387 // If the actor is not focusable, ask the same layout control for the next actor to focus
388 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
392 Actor currentFocusActor = GetCurrentFocusActor();
393 Actor committedFocusActor = nextFocusableActor;
395 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
396 // Signal handler can check the proposed actor and return a different actor if it wishes.
397 if( !mPreFocusChangeSignal.Empty() )
399 mIsWaitingKeyboardFocusChangeCommit = true;
400 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
401 mIsWaitingKeyboardFocusChangeCommit = false;
404 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
406 // Whether the commited focusable actor is a layout control
407 if(IsLayoutControl(committedFocusActor))
409 // If so, move the focus inside it.
410 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
411 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
415 // Otherwise, just set focus to the next focusable actor
416 if(committedFocusActor == nextFocusableActor)
418 // If the application hasn't changed our proposed actor, we informs the layout control we will
419 // move the focus to what the control returns. The control might wish to perform some actions
420 // before the focus is actually moved.
421 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
424 return SetCurrentFocusActor(committedFocusActor);
435 // No more actor can be focused in the given direction within the same layout control.
440 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
442 bool succeed = false;
444 // Get the parent layout control of the current focus group
445 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
447 while(parentLayoutControl && !succeed)
449 // If the current focus group has a parent layout control, we can probably automatically
450 // move the focus to the next focus group in the forward or backward direction.
451 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
452 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
453 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
456 if(!mFocusGroupChangedSignal.Empty())
458 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
459 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
465 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
469 Toolkit::Control control = Toolkit::Control::DownCast( actor );
472 // Notify the control that enter has been pressed on it.
473 GetImplementation( control ).KeyboardEnter();
476 // Send a notification for the actor.
477 if( !mFocusedActorEnterKeySignal.Empty() )
479 mFocusedActorEnterKeySignal.Emit( actor );
484 void KeyboardFocusManager::ClearFocus()
486 Actor actor = GetCurrentFocusActor();
489 if( mFocusIndicatorActor )
491 actor.Remove( mFocusIndicatorActor );
494 // Send notification for the change of focus actor
495 if( !mFocusChangedSignal.Empty() )
497 mFocusChangedSignal.Emit( actor, Actor() );
500 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
501 if( currentlyFocusedControl )
503 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
504 currentlyFocusedControl.ClearKeyInputFocus();
508 mCurrentFocusActor = 0;
509 mIsFocusIndicatorEnabled = false;
512 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
514 mFocusGroupLoopEnabled = enabled;
517 bool KeyboardFocusManager::GetFocusGroupLoop() const
519 return mFocusGroupLoopEnabled;
522 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
526 // Create/Set focus group property.
527 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
531 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
533 // Check whether the actor is a focus group
534 bool isFocusGroup = false;
538 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
539 if(propertyIsFocusGroup != Property::INVALID_INDEX)
541 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
548 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
550 // Go through the actor's hierarchy to check which focus group the actor belongs to
551 while (actor && !IsFocusGroup(actor))
553 actor = actor.GetParent();
559 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
561 if(mFocusIndicatorActor != indicator)
563 Actor currentFocusActor = GetCurrentFocusActor();
564 if(currentFocusActor)
566 // The new focus indicator should be added to the current focused actor immediately
567 if(mFocusIndicatorActor)
569 currentFocusActor.Remove(mFocusIndicatorActor);
574 currentFocusActor.Add(indicator);
578 mFocusIndicatorActor = indicator;
582 Actor KeyboardFocusManager::GetFocusIndicatorActor()
584 if( ! mFocusIndicatorActor )
586 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
587 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
589 // Apply size constraint to the focus indicator
590 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
593 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
594 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
595 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
597 return mFocusIndicatorActor;
600 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
602 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
603 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
605 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
607 std::string keyName = event.keyPressedName;
609 bool isFocusStartableKey = false;
611 if(event.state == KeyEvent::Down)
613 if (keyName == "Left")
615 if(!isAccessibilityEnabled)
617 if(!mIsFocusIndicatorEnabled)
619 // Show focus indicator
620 mIsFocusIndicatorEnabled = true;
624 // Move the focus towards left
625 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
628 isFocusStartableKey = true;
632 // Move the accessibility focus backward
633 accessibilityManager.MoveFocusBackward();
636 else if (keyName == "Right")
638 if(!isAccessibilityEnabled)
640 if(!mIsFocusIndicatorEnabled)
642 // Show focus indicator
643 mIsFocusIndicatorEnabled = true;
647 // Move the focus towards right
648 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
653 // Move the accessibility focus forward
654 accessibilityManager.MoveFocusForward();
657 isFocusStartableKey = true;
659 else if (keyName == "Up" && !isAccessibilityEnabled)
661 if(!mIsFocusIndicatorEnabled)
663 // Show focus indicator
664 mIsFocusIndicatorEnabled = true;
668 // Move the focus towards up
669 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
672 isFocusStartableKey = true;
674 else if (keyName == "Down" && !isAccessibilityEnabled)
676 if(!mIsFocusIndicatorEnabled)
678 // Show focus indicator
679 mIsFocusIndicatorEnabled = true;
683 // Move the focus towards down
684 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
687 isFocusStartableKey = true;
689 else if (keyName == "Prior" && !isAccessibilityEnabled)
691 if(!mIsFocusIndicatorEnabled)
693 // Show focus indicator
694 mIsFocusIndicatorEnabled = true;
698 // Move the focus towards the previous page
699 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
702 isFocusStartableKey = true;
704 else if (keyName == "Next" && !isAccessibilityEnabled)
706 if(!mIsFocusIndicatorEnabled)
708 // Show focus indicator
709 mIsFocusIndicatorEnabled = true;
713 // Move the focus towards the next page
714 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
717 isFocusStartableKey = true;
719 else if (keyName == "Tab" && !isAccessibilityEnabled)
721 if(!mIsFocusIndicatorEnabled)
723 // Show focus indicator
724 mIsFocusIndicatorEnabled = true;
728 // "Tab" key changes the focus group in the forward direction and
729 // "Shift-Tab" key changes it in the backward direction.
730 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
733 isFocusStartableKey = true;
735 else if (keyName == "space" && !isAccessibilityEnabled)
737 if(!mIsFocusIndicatorEnabled)
739 // Show focus indicator
740 mIsFocusIndicatorEnabled = true;
743 isFocusStartableKey = true;
745 else if (keyName == "" && !isAccessibilityEnabled)
747 // Check the fake key event for evas-plugin case
748 if(!mIsFocusIndicatorEnabled)
750 // Show focus indicator
751 mIsFocusIndicatorEnabled = true;
754 isFocusStartableKey = true;
756 else if (keyName == "Backspace" && !isAccessibilityEnabled)
758 // Emit signal to go back to the previous view???
760 else if (keyName == "Escape" && !isAccessibilityEnabled)
764 else if(event.state == KeyEvent::Up)
766 if (keyName == "Return")
768 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
770 // Show focus indicator
771 mIsFocusIndicatorEnabled = true;
775 // The focused actor has enter pressed on it
777 if( !isAccessibilityEnabled )
779 actor = GetCurrentFocusActor();
783 actor = accessibilityManager.GetCurrentFocusActor();
788 DoKeyboardEnter( actor );
792 isFocusStartableKey = true;
796 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
798 Actor actor = GetCurrentFocusActor();
801 // Make sure the focused actor is highlighted
802 actor.Add( GetFocusIndicatorActor() );
806 // No actor is focused but keyboard focus is activated by the key press
807 // Let's try to move the initial focus
808 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
813 void KeyboardFocusManager::OnTouch(const TouchData& touch)
815 // Clear the focus when user touch the screen.
816 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
817 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
823 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
825 return mPreFocusChangeSignal;
828 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
830 return mFocusChangedSignal;
833 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
835 return mFocusGroupChangedSignal;
838 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
840 return mFocusedActorEnterKeySignal;
843 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
845 Dali::BaseHandle handle( object );
847 bool connected( true );
848 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
850 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
852 manager->PreFocusChangeSignal().Connect( tracker, functor );
854 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
856 manager->FocusChangedSignal().Connect( tracker, functor );
858 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
860 manager->FocusGroupChangedSignal().Connect( tracker, functor );
862 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
864 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
868 // signalName does not match any signal
875 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
877 mCustomAlgorithmInterface = &interface;
880 } // namespace Internal
882 } // namespace Toolkit