2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "keyboard-focus-manager-impl.h"
22 #include <cstring> // for strcmp
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
25 #include <dali/devel-api/adaptor-framework/singleton-service.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/common/stage.h>
28 #include <dali/public-api/events/key-event.h>
29 #include <dali/public-api/events/touch-data.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/public-api/object/property-map.h>
33 #include <dali/public-api/images/resource-image.h>
34 #include <dali/integration-api/debug.h>
37 #include <dali-toolkit/public-api/controls/control.h>
38 #include <dali-toolkit/public-api/controls/control-impl.h>
39 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
40 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
41 #include <dali-toolkit/devel-api/controls/control-devel.h>
42 #include <dali-toolkit/public-api/styling/style-manager.h>
43 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
54 namespace // Unnamed namespace
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
61 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
63 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
67 BaseHandle handle = KeyboardFocusManager::Get();
71 SingletonService singletonService( SingletonService::Get() );
72 if ( singletonService )
74 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
75 singletonService.Register( typeid( manager ), manager );
83 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
85 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
86 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
87 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
88 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
90 DALI_TYPE_REGISTRATION_END()
92 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
94 } // unnamed namespace
96 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
98 Toolkit::KeyboardFocusManager manager;
100 SingletonService singletonService( SingletonService::Get() );
101 if ( singletonService )
103 // Check whether the keyboard focus manager is already created
104 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
107 // If so, downcast the handle of singleton to keyboard focus manager
108 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
115 KeyboardFocusManager::KeyboardFocusManager()
116 : mPreFocusChangeSignal(),
117 mFocusChangedSignal(),
118 mFocusGroupChangedSignal(),
119 mFocusedActorEnterKeySignal(),
120 mCurrentFocusActor(),
121 mFocusIndicatorActor(),
122 mIsFocusIndicatorEnabled( -1 ),
123 mFocusGroupLoopEnabled( false ),
124 mIsWaitingKeyboardFocusChangeCommit( false ),
126 mSlotDelegate( this ),
127 mCustomAlgorithmInterface(NULL)
129 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
130 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
131 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
134 KeyboardFocusManager::~KeyboardFocusManager()
138 void KeyboardFocusManager::GetConfigurationFromStyleManger()
140 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
143 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
144 mIsFocusIndicatorEnabled = static_cast<int>(config["alwaysShowFocus"].Get<bool>());
148 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
150 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
152 if( mIsFocusIndicatorEnabled == -1 )
154 GetConfigurationFromStyleManger();
157 return DoSetCurrentFocusActor( actor );
160 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
162 bool success = false;
164 Actor currentFocusedActor = GetCurrentFocusActor();
166 // If developer set focus on same actor, doing nothing
167 if( actor == currentFocusedActor )
176 // Check whether the actor is in the stage and is keyboard focusable.
177 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
179 if( mIsFocusIndicatorEnabled )
181 actor.Add( GetFocusIndicatorActor() );
184 // Send notification for the change of focus actor
185 if( !mFocusChangedSignal.Empty() )
187 mFocusChangedSignal.Emit(currentFocusedActor, actor);
190 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
191 if( currentlyFocusedControl )
193 // Do we need it to remember if it was previously DISABLED?
194 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
195 currentlyFocusedControl.ClearKeyInputFocus();
198 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
200 // Save the current focused actor
201 mCurrentFocusActor = actor;
203 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
204 if( newlyFocusedControl )
206 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
207 newlyFocusedControl.SetKeyInputFocus();
210 // Push Current Focused Actor to FocusHistory
211 mFocusHistory.push_back( actor );
213 // Delete first element before add new element when Stack is full.
214 if( mFocusHistory.size() > MAX_HISTORY_AMOUNT )
216 FocusStackIterator beginPos = mFocusHistory.begin();
217 mFocusHistory.erase( beginPos );
220 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
225 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
231 Actor KeyboardFocusManager::GetCurrentFocusActor()
233 Actor actor = mCurrentFocusActor.GetHandle();
234 if( actor && ! actor.OnStage() )
236 // If the actor has been removed from the stage, then it should not be focused
239 mCurrentFocusActor.Reset();
244 Actor KeyboardFocusManager::GetCurrentFocusGroup()
246 return GetFocusGroup(GetCurrentFocusActor());
249 void KeyboardFocusManager::MoveFocusBackward()
251 // Find Pre Focused Actor when the list size is more than 1
252 if( mFocusHistory.size() > 1 )
254 // Delete current focused actor in history
255 mFocusHistory.pop_back();
257 // If pre-focused actors are not on stage or deleted, remove them in stack
258 while( mFocusHistory.size() > 0 )
260 // Get pre focused actor
261 Actor target = mFocusHistory[ mFocusHistory.size() -1 ].GetHandle();
263 // Impl of Actor is not null
264 if( target && target.OnStage() )
266 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
267 mFocusHistory.pop_back();
268 SetCurrentFocusActor( target );
273 // Target is empty handle or off stage. Erase from queue
274 mFocusHistory.pop_back();
278 // if there is no actor which can get focus, then push current focus actor in stack again
279 if( mFocusHistory.size() == 0 )
281 Actor currentFocusedActor = GetCurrentFocusActor();
282 mFocusHistory.push_back( currentFocusedActor );
287 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
289 Toolkit::Control control = Toolkit::Control::DownCast(actor);
290 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
293 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
295 // Get the actor's parent layout control that supports two dimensional keyboard navigation
296 Actor rootActor = Stage::GetCurrent().GetRootLayer();
300 parent = actor.GetParent();
303 while( parent && !IsLayoutControl(parent) && parent != rootActor )
305 parent = parent.GetParent();
308 return Toolkit::Control::DownCast(parent);
311 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
313 Actor currentFocusActor = GetCurrentFocusActor();
315 bool succeed = false;
317 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
318 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
319 while( parentLayoutControl && !succeed )
321 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
322 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
327 Actor nextFocusableActor;
329 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
331 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
332 if( currentFocusControl )
335 Property::Index index = Property::INVALID_INDEX;
336 Property::Value value;
338 // Find property index based upon focus direction
341 case Toolkit::Control::KeyboardFocus::LEFT:
343 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
346 case Toolkit::Control::KeyboardFocus::RIGHT:
348 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
351 case Toolkit::Control::KeyboardFocus::UP:
353 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
356 case Toolkit::Control::KeyboardFocus::DOWN:
358 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
365 // If the focusable property is set then determine next focusable actor
366 if( index != Property::INVALID_INDEX)
368 value = currentFocusActor.GetProperty( index );
369 actorId = value.Get<int>();
371 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
374 if( currentFocusActor.GetParent() )
376 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
379 if( !nextFocusableActor )
381 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
387 if( !nextFocusableActor )
389 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
390 if( mCustomAlgorithmInterface )
392 mIsWaitingKeyboardFocusChangeCommit = true;
393 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
394 mIsWaitingKeyboardFocusChangeCommit = false;
396 else if( !mPreFocusChangeSignal.Empty() )
398 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
399 mIsWaitingKeyboardFocusChangeCommit = true;
400 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
401 mIsWaitingKeyboardFocusChangeCommit = false;
405 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
407 // Whether the next focusable actor is a layout control
408 if( IsLayoutControl( nextFocusableActor ) )
410 // If so, move the focus inside it.
411 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
412 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
416 // Otherwise, just set focus to the next focusable actor
417 succeed = SetCurrentFocusActor( nextFocusableActor );
425 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
427 // Ask the control for the next actor to focus
428 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
429 if(nextFocusableActor)
431 if(!nextFocusableActor.IsKeyboardFocusable())
433 // If the actor is not focusable, ask the same layout control for the next actor to focus
434 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
438 Actor currentFocusActor = GetCurrentFocusActor();
439 Actor committedFocusActor = nextFocusableActor;
441 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
442 // Signal handler can check the proposed actor and return a different actor if it wishes.
443 if( !mPreFocusChangeSignal.Empty() )
445 mIsWaitingKeyboardFocusChangeCommit = true;
446 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
447 mIsWaitingKeyboardFocusChangeCommit = false;
450 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
452 // Whether the commited focusable actor is a layout control
453 if(IsLayoutControl(committedFocusActor))
455 // If so, move the focus inside it.
456 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
457 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
461 // Otherwise, just set focus to the next focusable actor
462 if(committedFocusActor == nextFocusableActor)
464 // If the application hasn't changed our proposed actor, we informs the layout control we will
465 // move the focus to what the control returns. The control might wish to perform some actions
466 // before the focus is actually moved.
467 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
470 return SetCurrentFocusActor(committedFocusActor);
481 // No more actor can be focused in the given direction within the same layout control.
486 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
488 bool succeed = false;
490 // Get the parent layout control of the current focus group
491 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
493 while(parentLayoutControl && !succeed)
495 // If the current focus group has a parent layout control, we can probably automatically
496 // move the focus to the next focus group in the forward or backward direction.
497 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
498 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
499 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
502 if(!mFocusGroupChangedSignal.Empty())
504 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
505 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
511 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
515 Toolkit::Control control = Toolkit::Control::DownCast( actor );
518 // Notify the control that enter has been pressed on it.
519 GetImplementation( control ).KeyboardEnter();
522 // Send a notification for the actor.
523 if( !mFocusedActorEnterKeySignal.Empty() )
525 mFocusedActorEnterKeySignal.Emit( actor );
530 void KeyboardFocusManager::ClearFocus()
532 Actor actor = GetCurrentFocusActor();
535 if( mFocusIndicatorActor )
537 actor.Remove( mFocusIndicatorActor );
540 // Send notification for the change of focus actor
541 if( !mFocusChangedSignal.Empty() )
543 mFocusChangedSignal.Emit( actor, Actor() );
546 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
547 if( currentlyFocusedControl )
549 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
550 currentlyFocusedControl.ClearKeyInputFocus();
554 mCurrentFocusActor.Reset();
555 mIsFocusIndicatorEnabled = 0;
558 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
560 mFocusGroupLoopEnabled = enabled;
563 bool KeyboardFocusManager::GetFocusGroupLoop() const
565 return mFocusGroupLoopEnabled;
568 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
572 // Create/Set focus group property.
573 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
577 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
579 // Check whether the actor is a focus group
580 bool isFocusGroup = false;
584 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
585 if(propertyIsFocusGroup != Property::INVALID_INDEX)
587 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
594 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
596 // Go through the actor's hierarchy to check which focus group the actor belongs to
597 while (actor && !IsFocusGroup(actor))
599 actor = actor.GetParent();
605 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
607 if(mFocusIndicatorActor != indicator)
609 Actor currentFocusActor = GetCurrentFocusActor();
610 if(currentFocusActor)
612 // The new focus indicator should be added to the current focused actor immediately
613 if(mFocusIndicatorActor)
615 currentFocusActor.Remove(mFocusIndicatorActor);
620 currentFocusActor.Add(indicator);
624 mFocusIndicatorActor = indicator;
628 Actor KeyboardFocusManager::GetFocusIndicatorActor()
630 if( ! mFocusIndicatorActor )
632 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
633 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
635 // Apply size constraint to the focus indicator
636 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
639 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
640 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
641 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
643 return mFocusIndicatorActor;
646 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
648 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
649 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
651 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
653 std::string keyName = event.keyPressedName;
655 if( mIsFocusIndicatorEnabled == -1 )
657 GetConfigurationFromStyleManger();
660 bool isFocusStartableKey = false;
662 if(event.state == KeyEvent::Down)
664 if (keyName == "Left")
666 if(!isAccessibilityEnabled)
668 if(!mIsFocusIndicatorEnabled)
670 // Show focus indicator
671 mIsFocusIndicatorEnabled = 1;
675 // Move the focus towards left
676 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
679 isFocusStartableKey = true;
683 // Move the accessibility focus backward
684 accessibilityManager.MoveFocusBackward();
687 else if (keyName == "Right")
689 if(!isAccessibilityEnabled)
691 if(!mIsFocusIndicatorEnabled)
693 // Show focus indicator
694 mIsFocusIndicatorEnabled = 1;
698 // Move the focus towards right
699 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
704 // Move the accessibility focus forward
705 accessibilityManager.MoveFocusForward();
708 isFocusStartableKey = true;
710 else if (keyName == "Up" && !isAccessibilityEnabled)
712 if(!mIsFocusIndicatorEnabled)
714 // Show focus indicator
715 mIsFocusIndicatorEnabled = 1;
719 // Move the focus towards up
720 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
723 isFocusStartableKey = true;
725 else if (keyName == "Down" && !isAccessibilityEnabled)
727 if(!mIsFocusIndicatorEnabled)
729 // Show focus indicator
730 mIsFocusIndicatorEnabled = 1;
734 // Move the focus towards down
735 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
738 isFocusStartableKey = true;
740 else if (keyName == "Prior" && !isAccessibilityEnabled)
742 if(!mIsFocusIndicatorEnabled)
744 // Show focus indicator
745 mIsFocusIndicatorEnabled = 1;
749 // Move the focus towards the previous page
750 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
753 isFocusStartableKey = true;
755 else if (keyName == "Next" && !isAccessibilityEnabled)
757 if(!mIsFocusIndicatorEnabled)
759 // Show focus indicator
760 mIsFocusIndicatorEnabled = 1;
764 // Move the focus towards the next page
765 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
768 isFocusStartableKey = true;
770 else if (keyName == "Tab" && !isAccessibilityEnabled)
772 if(!mIsFocusIndicatorEnabled)
774 // Show focus indicator
775 mIsFocusIndicatorEnabled = 1;
779 // "Tab" key changes the focus group in the forward direction and
780 // "Shift-Tab" key changes it in the backward direction.
781 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
784 isFocusStartableKey = true;
786 else if (keyName == "space" && !isAccessibilityEnabled)
788 if(!mIsFocusIndicatorEnabled)
790 // Show focus indicator
791 mIsFocusIndicatorEnabled = 1;
794 isFocusStartableKey = true;
796 else if (keyName == "" && !isAccessibilityEnabled)
798 // Check the fake key event for evas-plugin case
799 if(!mIsFocusIndicatorEnabled)
801 // Show focus indicator
802 mIsFocusIndicatorEnabled = 1;
805 isFocusStartableKey = true;
807 else if (keyName == "Backspace" && !isAccessibilityEnabled)
809 // Emit signal to go back to the previous view???
811 else if (keyName == "Escape" && !isAccessibilityEnabled)
815 else if(event.state == KeyEvent::Up)
817 if (keyName == "Return")
819 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
821 // Show focus indicator
822 mIsFocusIndicatorEnabled = 1;
826 // The focused actor has enter pressed on it
828 if( !isAccessibilityEnabled )
830 actor = GetCurrentFocusActor();
834 actor = accessibilityManager.GetCurrentFocusActor();
839 DoKeyboardEnter( actor );
843 isFocusStartableKey = true;
847 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
849 Actor actor = GetCurrentFocusActor();
852 // Make sure the focused actor is highlighted
853 actor.Add( GetFocusIndicatorActor() );
857 // No actor is focused but keyboard focus is activated by the key press
858 // Let's try to move the initial focus
859 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
864 void KeyboardFocusManager::OnTouch(const TouchData& touch)
866 // Clear the focus when user touch the screen.
867 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
868 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
874 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
876 return mPreFocusChangeSignal;
879 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
881 return mFocusChangedSignal;
884 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
886 return mFocusGroupChangedSignal;
889 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
891 return mFocusedActorEnterKeySignal;
894 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
896 Dali::BaseHandle handle( object );
898 bool connected( true );
899 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
901 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
903 manager->PreFocusChangeSignal().Connect( tracker, functor );
905 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
907 manager->FocusChangedSignal().Connect( tracker, functor );
909 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
911 manager->FocusGroupChangedSignal().Connect( tracker, functor );
913 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
915 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
919 // signalName does not match any signal
926 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
928 mCustomAlgorithmInterface = &interface;
931 } // namespace Internal
933 } // namespace Toolkit