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 // Check whether the actor is in the stage and is keyboard focusable.
147 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
149 if( mIsFocusIndicatorEnabled )
151 actor.Add( GetFocusIndicatorActor() );
153 // Send notification for the change of focus actor
154 Actor currentFocusedActor = GetCurrentFocusActor();
156 if( !mFocusChangedSignal.Empty() )
158 mFocusChangedSignal.Emit(currentFocusedActor, actor);
161 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
162 if( currentlyFocusedControl )
164 // Do we need it to remember if it was previously DISABLED?
165 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
166 currentlyFocusedControl.ClearKeyInputFocus();
169 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
171 // Save the current focused actor
172 mCurrentFocusActor = actor;
174 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
175 if( newlyFocusedControl )
177 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
178 newlyFocusedControl.SetKeyInputFocus();
181 // Push Current Focused Actor to FocusHistory
182 mFocusHistory.PushBack( &actor.GetBaseObject() );
184 // Delete first element before add new element when Stack is full.
185 if( mFocusHistory.Count() > MAX_HISTORY_AMOUNT )
187 FocusStackIterator beginPos = mFocusHistory.Begin();
188 mFocusHistory.Erase( beginPos );
191 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
196 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
202 Actor KeyboardFocusManager::GetCurrentFocusActor()
204 Actor actor = mCurrentFocusActor.GetHandle();
205 if( actor && ! actor.OnStage() )
207 // If the actor has been removed from the stage, then it should not be focused
210 mCurrentFocusActor.Reset();
215 Actor KeyboardFocusManager::GetCurrentFocusGroup()
217 return GetFocusGroup(GetCurrentFocusActor());
220 void KeyboardFocusManager::MoveFocusBackward()
222 // Find Pre Focused Actor when the list size is more than 1
223 if( mFocusHistory.Count() > 1 )
225 // Delete current focused actor in history
226 FocusStackIterator endPos = mFocusHistory.End();
227 endPos = mFocusHistory.Erase( --endPos );
229 // If pre-focused actors are not on stage, remove them in stack
230 while( !Dali::Actor::DownCast(BaseHandle(mFocusHistory[ mFocusHistory.Count() - 1 ])).OnStage() )
232 endPos = mFocusHistory.Erase( --endPos );
235 // Get pre focused actor
236 BaseObject* object = mFocusHistory[ mFocusHistory.Count() - 1 ];
237 BaseHandle handle( object );
238 Actor preFocusedActor = Dali::Actor::DownCast( handle );
240 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
241 mFocusHistory.Erase( --endPos );
243 SetCurrentFocusActor( preFocusedActor );
247 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
249 Toolkit::Control control = Toolkit::Control::DownCast(actor);
250 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
253 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
255 // Get the actor's parent layout control that supports two dimensional keyboard navigation
256 Actor rootActor = Stage::GetCurrent().GetRootLayer();
260 parent = actor.GetParent();
263 while( parent && !IsLayoutControl(parent) && parent != rootActor )
265 parent = parent.GetParent();
268 return Toolkit::Control::DownCast(parent);
271 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
273 Actor currentFocusActor = GetCurrentFocusActor();
275 bool succeed = false;
277 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
278 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
279 while( parentLayoutControl && !succeed )
281 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
282 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
287 Actor nextFocusableActor;
289 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
291 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
292 if( currentFocusControl )
295 Property::Index index = Property::INVALID_INDEX;
296 Property::Value value;
298 // Find property index based upon focus direction
301 case Toolkit::Control::KeyboardFocus::LEFT:
303 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
306 case Toolkit::Control::KeyboardFocus::RIGHT:
308 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
311 case Toolkit::Control::KeyboardFocus::UP:
313 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
316 case Toolkit::Control::KeyboardFocus::DOWN:
318 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
325 // If the focusable property is set then determine next focusable actor
326 if( index != Property::INVALID_INDEX)
328 value = currentFocusActor.GetProperty( index );
329 actorId = value.Get<int>();
331 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
334 if( currentFocusActor.GetParent() )
336 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
339 if( !nextFocusableActor )
341 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
347 if( !nextFocusableActor )
349 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
350 if( mCustomAlgorithmInterface )
352 mIsWaitingKeyboardFocusChangeCommit = true;
353 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
354 mIsWaitingKeyboardFocusChangeCommit = false;
356 else if( !mPreFocusChangeSignal.Empty() )
358 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
359 mIsWaitingKeyboardFocusChangeCommit = true;
360 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
361 mIsWaitingKeyboardFocusChangeCommit = false;
365 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
367 // Whether the next focusable actor is a layout control
368 if( IsLayoutControl( nextFocusableActor ) )
370 // If so, move the focus inside it.
371 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
372 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
376 // Otherwise, just set focus to the next focusable actor
377 succeed = SetCurrentFocusActor( nextFocusableActor );
385 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
387 // Ask the control for the next actor to focus
388 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
389 if(nextFocusableActor)
391 if(!nextFocusableActor.IsKeyboardFocusable())
393 // If the actor is not focusable, ask the same layout control for the next actor to focus
394 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
398 Actor currentFocusActor = GetCurrentFocusActor();
399 Actor committedFocusActor = nextFocusableActor;
401 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
402 // Signal handler can check the proposed actor and return a different actor if it wishes.
403 if( !mPreFocusChangeSignal.Empty() )
405 mIsWaitingKeyboardFocusChangeCommit = true;
406 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
407 mIsWaitingKeyboardFocusChangeCommit = false;
410 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
412 // Whether the commited focusable actor is a layout control
413 if(IsLayoutControl(committedFocusActor))
415 // If so, move the focus inside it.
416 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
417 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
421 // Otherwise, just set focus to the next focusable actor
422 if(committedFocusActor == nextFocusableActor)
424 // If the application hasn't changed our proposed actor, we informs the layout control we will
425 // move the focus to what the control returns. The control might wish to perform some actions
426 // before the focus is actually moved.
427 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
430 return SetCurrentFocusActor(committedFocusActor);
441 // No more actor can be focused in the given direction within the same layout control.
446 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
448 bool succeed = false;
450 // Get the parent layout control of the current focus group
451 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
453 while(parentLayoutControl && !succeed)
455 // If the current focus group has a parent layout control, we can probably automatically
456 // move the focus to the next focus group in the forward or backward direction.
457 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
458 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
459 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
462 if(!mFocusGroupChangedSignal.Empty())
464 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
465 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
471 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
475 Toolkit::Control control = Toolkit::Control::DownCast( actor );
478 // Notify the control that enter has been pressed on it.
479 GetImplementation( control ).KeyboardEnter();
482 // Send a notification for the actor.
483 if( !mFocusedActorEnterKeySignal.Empty() )
485 mFocusedActorEnterKeySignal.Emit( actor );
490 void KeyboardFocusManager::ClearFocus()
492 Actor actor = GetCurrentFocusActor();
495 if( mFocusIndicatorActor )
497 actor.Remove( mFocusIndicatorActor );
500 // Send notification for the change of focus actor
501 if( !mFocusChangedSignal.Empty() )
503 mFocusChangedSignal.Emit( actor, Actor() );
506 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
507 if( currentlyFocusedControl )
509 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
510 currentlyFocusedControl.ClearKeyInputFocus();
514 mCurrentFocusActor.Reset();
515 mIsFocusIndicatorEnabled = false;
518 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
520 mFocusGroupLoopEnabled = enabled;
523 bool KeyboardFocusManager::GetFocusGroupLoop() const
525 return mFocusGroupLoopEnabled;
528 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
532 // Create/Set focus group property.
533 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
537 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
539 // Check whether the actor is a focus group
540 bool isFocusGroup = false;
544 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
545 if(propertyIsFocusGroup != Property::INVALID_INDEX)
547 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
554 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
556 // Go through the actor's hierarchy to check which focus group the actor belongs to
557 while (actor && !IsFocusGroup(actor))
559 actor = actor.GetParent();
565 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
567 if(mFocusIndicatorActor != indicator)
569 Actor currentFocusActor = GetCurrentFocusActor();
570 if(currentFocusActor)
572 // The new focus indicator should be added to the current focused actor immediately
573 if(mFocusIndicatorActor)
575 currentFocusActor.Remove(mFocusIndicatorActor);
580 currentFocusActor.Add(indicator);
584 mFocusIndicatorActor = indicator;
588 Actor KeyboardFocusManager::GetFocusIndicatorActor()
590 if( ! mFocusIndicatorActor )
592 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
593 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
595 // Apply size constraint to the focus indicator
596 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
599 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
600 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
601 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
603 return mFocusIndicatorActor;
606 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
608 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
609 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
611 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
613 std::string keyName = event.keyPressedName;
615 bool isFocusStartableKey = false;
617 if(event.state == KeyEvent::Down)
619 if (keyName == "Left")
621 if(!isAccessibilityEnabled)
623 if(!mIsFocusIndicatorEnabled)
625 // Show focus indicator
626 mIsFocusIndicatorEnabled = true;
630 // Move the focus towards left
631 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
634 isFocusStartableKey = true;
638 // Move the accessibility focus backward
639 accessibilityManager.MoveFocusBackward();
642 else if (keyName == "Right")
644 if(!isAccessibilityEnabled)
646 if(!mIsFocusIndicatorEnabled)
648 // Show focus indicator
649 mIsFocusIndicatorEnabled = true;
653 // Move the focus towards right
654 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
659 // Move the accessibility focus forward
660 accessibilityManager.MoveFocusForward();
663 isFocusStartableKey = true;
665 else if (keyName == "Up" && !isAccessibilityEnabled)
667 if(!mIsFocusIndicatorEnabled)
669 // Show focus indicator
670 mIsFocusIndicatorEnabled = true;
674 // Move the focus towards up
675 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
678 isFocusStartableKey = true;
680 else if (keyName == "Down" && !isAccessibilityEnabled)
682 if(!mIsFocusIndicatorEnabled)
684 // Show focus indicator
685 mIsFocusIndicatorEnabled = true;
689 // Move the focus towards down
690 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
693 isFocusStartableKey = true;
695 else if (keyName == "Prior" && !isAccessibilityEnabled)
697 if(!mIsFocusIndicatorEnabled)
699 // Show focus indicator
700 mIsFocusIndicatorEnabled = true;
704 // Move the focus towards the previous page
705 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
708 isFocusStartableKey = true;
710 else if (keyName == "Next" && !isAccessibilityEnabled)
712 if(!mIsFocusIndicatorEnabled)
714 // Show focus indicator
715 mIsFocusIndicatorEnabled = true;
719 // Move the focus towards the next page
720 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
723 isFocusStartableKey = true;
725 else if (keyName == "Tab" && !isAccessibilityEnabled)
727 if(!mIsFocusIndicatorEnabled)
729 // Show focus indicator
730 mIsFocusIndicatorEnabled = true;
734 // "Tab" key changes the focus group in the forward direction and
735 // "Shift-Tab" key changes it in the backward direction.
736 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
739 isFocusStartableKey = true;
741 else if (keyName == "space" && !isAccessibilityEnabled)
743 if(!mIsFocusIndicatorEnabled)
745 // Show focus indicator
746 mIsFocusIndicatorEnabled = true;
749 isFocusStartableKey = true;
751 else if (keyName == "" && !isAccessibilityEnabled)
753 // Check the fake key event for evas-plugin case
754 if(!mIsFocusIndicatorEnabled)
756 // Show focus indicator
757 mIsFocusIndicatorEnabled = true;
760 isFocusStartableKey = true;
762 else if (keyName == "Backspace" && !isAccessibilityEnabled)
764 // Emit signal to go back to the previous view???
766 else if (keyName == "Escape" && !isAccessibilityEnabled)
770 else if(event.state == KeyEvent::Up)
772 if (keyName == "Return")
774 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
776 // Show focus indicator
777 mIsFocusIndicatorEnabled = true;
781 // The focused actor has enter pressed on it
783 if( !isAccessibilityEnabled )
785 actor = GetCurrentFocusActor();
789 actor = accessibilityManager.GetCurrentFocusActor();
794 DoKeyboardEnter( actor );
798 isFocusStartableKey = true;
802 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
804 Actor actor = GetCurrentFocusActor();
807 // Make sure the focused actor is highlighted
808 actor.Add( GetFocusIndicatorActor() );
812 // No actor is focused but keyboard focus is activated by the key press
813 // Let's try to move the initial focus
814 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
819 void KeyboardFocusManager::OnTouch(const TouchData& touch)
821 // Clear the focus when user touch the screen.
822 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
823 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
829 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
831 return mPreFocusChangeSignal;
834 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
836 return mFocusChangedSignal;
839 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
841 return mFocusGroupChangedSignal;
844 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
846 return mFocusedActorEnterKeySignal;
849 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
851 Dali::BaseHandle handle( object );
853 bool connected( true );
854 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
856 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
858 manager->PreFocusChangeSignal().Connect( tracker, functor );
860 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
862 manager->FocusChangedSignal().Connect( tracker, functor );
864 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
866 manager->FocusGroupChangedSignal().Connect( tracker, functor );
868 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
870 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
874 // signalName does not match any signal
881 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
883 mCustomAlgorithmInterface = &interface;
886 } // namespace Internal
888 } // namespace Toolkit