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 ),
125 mClearFocusOnTouch( true ),
126 mEnableFocusIndicator( true ),
128 mSlotDelegate( this ),
129 mCustomAlgorithmInterface(NULL)
131 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
132 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
133 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
136 KeyboardFocusManager::~KeyboardFocusManager()
140 void KeyboardFocusManager::GetConfigurationFromStyleManger()
142 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
145 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
146 mIsFocusIndicatorEnabled = static_cast<int>(config["alwaysShowFocus"].Get<bool>());
147 mClearFocusOnTouch = mIsFocusIndicatorEnabled ? false : true;
151 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
153 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
155 if( mIsFocusIndicatorEnabled == -1 )
157 GetConfigurationFromStyleManger();
160 return DoSetCurrentFocusActor( actor );
163 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
165 bool success = false;
167 Actor currentFocusedActor = GetCurrentFocusActor();
169 // If developer set focus on same actor, doing nothing
170 if( actor == currentFocusedActor )
179 // Check whether the actor is in the stage and is keyboard focusable.
180 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
182 if( mIsFocusIndicatorEnabled && mEnableFocusIndicator )
184 actor.Add( GetFocusIndicatorActor() );
187 // Send notification for the change of focus actor
188 if( !mFocusChangedSignal.Empty() )
190 mFocusChangedSignal.Emit(currentFocusedActor, actor);
193 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
194 if( currentlyFocusedControl )
196 // Do we need it to remember if it was previously DISABLED?
197 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
198 currentlyFocusedControl.ClearKeyInputFocus();
201 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
203 // Save the current focused actor
204 mCurrentFocusActor = actor;
206 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
207 if( newlyFocusedControl )
209 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
210 newlyFocusedControl.SetKeyInputFocus();
213 // Push Current Focused Actor to FocusHistory
214 mFocusHistory.push_back( actor );
216 // Delete first element before add new element when Stack is full.
217 if( mFocusHistory.size() > MAX_HISTORY_AMOUNT )
219 FocusStackIterator beginPos = mFocusHistory.begin();
220 mFocusHistory.erase( beginPos );
223 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
228 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
234 Actor KeyboardFocusManager::GetCurrentFocusActor()
236 Actor actor = mCurrentFocusActor.GetHandle();
237 if( actor && ! actor.OnStage() )
239 // If the actor has been removed from the stage, then it should not be focused
242 mCurrentFocusActor.Reset();
247 Actor KeyboardFocusManager::GetCurrentFocusGroup()
249 return GetFocusGroup(GetCurrentFocusActor());
252 void KeyboardFocusManager::MoveFocusBackward()
254 // Find Pre Focused Actor when the list size is more than 1
255 if( mFocusHistory.size() > 1 )
257 // Delete current focused actor in history
258 mFocusHistory.pop_back();
260 // If pre-focused actors are not on stage or deleted, remove them in stack
261 while( mFocusHistory.size() > 0 )
263 // Get pre focused actor
264 Actor target = mFocusHistory[ mFocusHistory.size() -1 ].GetHandle();
266 // Impl of Actor is not null
267 if( target && target.OnStage() )
269 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
270 mFocusHistory.pop_back();
271 SetCurrentFocusActor( target );
276 // Target is empty handle or off stage. Erase from queue
277 mFocusHistory.pop_back();
281 // if there is no actor which can get focus, then push current focus actor in stack again
282 if( mFocusHistory.size() == 0 )
284 Actor currentFocusedActor = GetCurrentFocusActor();
285 mFocusHistory.push_back( currentFocusedActor );
290 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
292 Toolkit::Control control = Toolkit::Control::DownCast(actor);
293 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
296 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
298 // Get the actor's parent layout control that supports two dimensional keyboard navigation
299 Actor rootActor = Stage::GetCurrent().GetRootLayer();
303 parent = actor.GetParent();
306 while( parent && !IsLayoutControl(parent) && parent != rootActor )
308 parent = parent.GetParent();
311 return Toolkit::Control::DownCast(parent);
314 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
316 Actor currentFocusActor = GetCurrentFocusActor();
318 bool succeed = false;
320 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
321 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
322 while( parentLayoutControl && !succeed )
324 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
325 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
330 Actor nextFocusableActor;
332 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
334 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
335 if( currentFocusControl )
338 Property::Index index = Property::INVALID_INDEX;
339 Property::Value value;
341 // Find property index based upon focus direction
344 case Toolkit::Control::KeyboardFocus::LEFT:
346 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
349 case Toolkit::Control::KeyboardFocus::RIGHT:
351 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
354 case Toolkit::Control::KeyboardFocus::UP:
356 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
359 case Toolkit::Control::KeyboardFocus::DOWN:
361 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
368 // If the focusable property is set then determine next focusable actor
369 if( index != Property::INVALID_INDEX)
371 value = currentFocusActor.GetProperty( index );
372 actorId = value.Get<int>();
374 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
377 if( currentFocusActor.GetParent() )
379 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
382 if( !nextFocusableActor )
384 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
390 if( !nextFocusableActor )
392 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
393 if( mCustomAlgorithmInterface )
395 mIsWaitingKeyboardFocusChangeCommit = true;
396 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
397 mIsWaitingKeyboardFocusChangeCommit = false;
399 else if( !mPreFocusChangeSignal.Empty() )
401 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
402 mIsWaitingKeyboardFocusChangeCommit = true;
403 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
404 mIsWaitingKeyboardFocusChangeCommit = false;
408 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
410 // Whether the next focusable actor is a layout control
411 if( IsLayoutControl( nextFocusableActor ) )
413 // If so, move the focus inside it.
414 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
415 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
419 // Otherwise, just set focus to the next focusable actor
420 succeed = SetCurrentFocusActor( nextFocusableActor );
428 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
430 // Ask the control for the next actor to focus
431 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
432 if(nextFocusableActor)
434 if(!nextFocusableActor.IsKeyboardFocusable())
436 // If the actor is not focusable, ask the same layout control for the next actor to focus
437 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
441 Actor currentFocusActor = GetCurrentFocusActor();
442 Actor committedFocusActor = nextFocusableActor;
444 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
445 // Signal handler can check the proposed actor and return a different actor if it wishes.
446 if( !mPreFocusChangeSignal.Empty() )
448 mIsWaitingKeyboardFocusChangeCommit = true;
449 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
450 mIsWaitingKeyboardFocusChangeCommit = false;
453 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
455 // Whether the commited focusable actor is a layout control
456 if(IsLayoutControl(committedFocusActor))
458 // If so, move the focus inside it.
459 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
460 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
464 // Otherwise, just set focus to the next focusable actor
465 if(committedFocusActor == nextFocusableActor)
467 // If the application hasn't changed our proposed actor, we informs the layout control we will
468 // move the focus to what the control returns. The control might wish to perform some actions
469 // before the focus is actually moved.
470 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
473 return SetCurrentFocusActor(committedFocusActor);
484 // No more actor can be focused in the given direction within the same layout control.
489 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
491 bool succeed = false;
493 // Get the parent layout control of the current focus group
494 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
496 while(parentLayoutControl && !succeed)
498 // If the current focus group has a parent layout control, we can probably automatically
499 // move the focus to the next focus group in the forward or backward direction.
500 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
501 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
502 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
505 if(!mFocusGroupChangedSignal.Empty())
507 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
508 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
514 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
518 Toolkit::Control control = Toolkit::Control::DownCast( actor );
521 // Notify the control that enter has been pressed on it.
522 GetImplementation( control ).KeyboardEnter();
525 // Send a notification for the actor.
526 if( !mFocusedActorEnterKeySignal.Empty() )
528 mFocusedActorEnterKeySignal.Emit( actor );
533 void KeyboardFocusManager::ClearFocus()
535 Actor actor = GetCurrentFocusActor();
538 if( mFocusIndicatorActor )
540 actor.Remove( mFocusIndicatorActor );
543 // Send notification for the change of focus actor
544 if( !mFocusChangedSignal.Empty() )
546 mFocusChangedSignal.Emit( actor, Actor() );
549 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
550 if( currentlyFocusedControl )
552 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
553 currentlyFocusedControl.ClearKeyInputFocus();
557 mCurrentFocusActor.Reset();
558 mIsFocusIndicatorEnabled = 0;
561 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
563 mFocusGroupLoopEnabled = enabled;
566 bool KeyboardFocusManager::GetFocusGroupLoop() const
568 return mFocusGroupLoopEnabled;
571 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
575 // Create/Set focus group property.
576 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
580 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
582 // Check whether the actor is a focus group
583 bool isFocusGroup = false;
587 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
588 if(propertyIsFocusGroup != Property::INVALID_INDEX)
590 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
597 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
599 // Go through the actor's hierarchy to check which focus group the actor belongs to
600 while (actor && !IsFocusGroup(actor))
602 actor = actor.GetParent();
608 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
610 if(mFocusIndicatorActor != indicator)
612 Actor currentFocusActor = GetCurrentFocusActor();
613 if(currentFocusActor)
615 // The new focus indicator should be added to the current focused actor immediately
616 if(mFocusIndicatorActor)
618 currentFocusActor.Remove(mFocusIndicatorActor);
623 currentFocusActor.Add(indicator);
627 mFocusIndicatorActor = indicator;
631 Actor KeyboardFocusManager::GetFocusIndicatorActor()
633 if( ! mFocusIndicatorActor )
635 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
636 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
638 // Apply size constraint to the focus indicator
639 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
642 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
643 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
644 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
646 return mFocusIndicatorActor;
649 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
651 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
652 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
654 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
656 std::string keyName = event.keyPressedName;
658 if( mIsFocusIndicatorEnabled == -1 )
660 GetConfigurationFromStyleManger();
663 bool isFocusStartableKey = false;
665 if(event.state == KeyEvent::Down)
667 if (keyName == "Left")
669 if(!isAccessibilityEnabled)
671 if(!mIsFocusIndicatorEnabled)
673 // Show focus indicator
674 mIsFocusIndicatorEnabled = 1;
677 // Move the focus towards left
678 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;
697 // Move the focus towards right
698 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
702 // Move the accessibility focus forward
703 accessibilityManager.MoveFocusForward();
706 isFocusStartableKey = true;
708 else if (keyName == "Up" && !isAccessibilityEnabled)
710 if(!mIsFocusIndicatorEnabled)
712 // Show focus indicator
713 mIsFocusIndicatorEnabled = 1;
716 // Move the focus towards up
717 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
718 isFocusStartableKey = true;
720 else if (keyName == "Down" && !isAccessibilityEnabled)
722 if(!mIsFocusIndicatorEnabled)
724 // Show focus indicator
725 mIsFocusIndicatorEnabled = 1;
728 // Move the focus towards down
729 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
730 isFocusStartableKey = true;
732 else if (keyName == "Prior" && !isAccessibilityEnabled)
734 if(!mIsFocusIndicatorEnabled)
736 // Show focus indicator
737 mIsFocusIndicatorEnabled = 1;
740 // Move the focus towards the previous page
741 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
743 isFocusStartableKey = true;
745 else if (keyName == "Next" && !isAccessibilityEnabled)
747 if(!mIsFocusIndicatorEnabled)
749 // Show focus indicator
750 mIsFocusIndicatorEnabled = 1;
753 // Move the focus towards the next page
754 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
756 isFocusStartableKey = true;
758 else if (keyName == "Tab" && !isAccessibilityEnabled)
760 if(!mIsFocusIndicatorEnabled)
762 // Show focus indicator
763 mIsFocusIndicatorEnabled = 1;
767 // "Tab" key changes the focus group in the forward direction and
768 // "Shift-Tab" key changes it in the backward direction.
769 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
772 isFocusStartableKey = true;
774 else if (keyName == "space" && !isAccessibilityEnabled)
776 if(!mIsFocusIndicatorEnabled)
778 // Show focus indicator
779 mIsFocusIndicatorEnabled = 1;
782 isFocusStartableKey = true;
784 else if (keyName == "" && !isAccessibilityEnabled)
786 // Check the fake key event for evas-plugin case
787 if(!mIsFocusIndicatorEnabled)
789 // Show focus indicator
790 mIsFocusIndicatorEnabled = 1;
793 isFocusStartableKey = true;
795 else if (keyName == "Backspace" && !isAccessibilityEnabled)
797 // Emit signal to go back to the previous view???
799 else if (keyName == "Escape" && !isAccessibilityEnabled)
803 else if(event.state == KeyEvent::Up)
805 if (keyName == "Return")
807 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
809 // Show focus indicator
810 mIsFocusIndicatorEnabled = 1;
814 // The focused actor has enter pressed on it
816 if( !isAccessibilityEnabled )
818 actor = GetCurrentFocusActor();
822 actor = accessibilityManager.GetCurrentFocusActor();
827 DoKeyboardEnter( actor );
831 isFocusStartableKey = true;
835 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
837 Actor actor = GetCurrentFocusActor();
840 if( mEnableFocusIndicator )
842 // Make sure the focused actor is highlighted
843 actor.Add( GetFocusIndicatorActor() );
848 // No actor is focused but keyboard focus is activated by the key press
849 // Let's try to move the initial focus
850 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
855 void KeyboardFocusManager::OnTouch(const TouchData& touch)
857 // if mIsFocusIndicatorEnabled is -1, it means Configuration is not loaded.
858 // Try to load configuration.
859 if( mIsFocusIndicatorEnabled == -1 )
861 GetConfigurationFromStyleManger();
864 // Clear the focus when user touch the screen.
865 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
866 // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
867 if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
873 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
875 return mPreFocusChangeSignal;
878 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
880 return mFocusChangedSignal;
883 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
885 return mFocusGroupChangedSignal;
888 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
890 return mFocusedActorEnterKeySignal;
893 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
895 Dali::BaseHandle handle( object );
897 bool connected( true );
898 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
900 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
902 manager->PreFocusChangeSignal().Connect( tracker, functor );
904 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
906 manager->FocusChangedSignal().Connect( tracker, functor );
908 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
910 manager->FocusGroupChangedSignal().Connect( tracker, functor );
912 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
914 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
918 // signalName does not match any signal
925 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
927 mCustomAlgorithmInterface = &interface;
930 void KeyboardFocusManager::EnableFocusIndicator(bool enable)
932 if( !enable && mFocusIndicatorActor )
934 mFocusIndicatorActor.Unparent();
937 mEnableFocusIndicator = enable;
940 bool KeyboardFocusManager::IsFocusIndicatorEnabled() const
942 return mEnableFocusIndicator;
945 } // namespace Internal
947 } // namespace Toolkit