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 ),
127 mSlotDelegate( this ),
128 mCustomAlgorithmInterface(NULL)
130 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
131 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
132 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
135 KeyboardFocusManager::~KeyboardFocusManager()
139 void KeyboardFocusManager::GetConfigurationFromStyleManger()
141 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
144 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
145 mIsFocusIndicatorEnabled = static_cast<int>(config["alwaysShowFocus"].Get<bool>());
146 mClearFocusOnTouch = mIsFocusIndicatorEnabled ? false : true;
150 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
152 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
154 if( mIsFocusIndicatorEnabled == -1 )
156 GetConfigurationFromStyleManger();
159 return DoSetCurrentFocusActor( actor );
162 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
164 bool success = false;
166 Actor currentFocusedActor = GetCurrentFocusActor();
168 // If developer set focus on same actor, doing nothing
169 if( actor == currentFocusedActor )
178 // Check whether the actor is in the stage and is keyboard focusable.
179 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
181 if( mIsFocusIndicatorEnabled )
183 actor.Add( GetFocusIndicatorActor() );
186 // Send notification for the change of focus actor
187 if( !mFocusChangedSignal.Empty() )
189 mFocusChangedSignal.Emit(currentFocusedActor, actor);
192 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
193 if( currentlyFocusedControl )
195 // Do we need it to remember if it was previously DISABLED?
196 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
197 currentlyFocusedControl.ClearKeyInputFocus();
200 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
202 // Save the current focused actor
203 mCurrentFocusActor = actor;
205 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
206 if( newlyFocusedControl )
208 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
209 newlyFocusedControl.SetKeyInputFocus();
212 // Push Current Focused Actor to FocusHistory
213 mFocusHistory.push_back( actor );
215 // Delete first element before add new element when Stack is full.
216 if( mFocusHistory.size() > MAX_HISTORY_AMOUNT )
218 FocusStackIterator beginPos = mFocusHistory.begin();
219 mFocusHistory.erase( beginPos );
222 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
227 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
233 Actor KeyboardFocusManager::GetCurrentFocusActor()
235 Actor actor = mCurrentFocusActor.GetHandle();
236 if( actor && ! actor.OnStage() )
238 // If the actor has been removed from the stage, then it should not be focused
241 mCurrentFocusActor.Reset();
246 Actor KeyboardFocusManager::GetCurrentFocusGroup()
248 return GetFocusGroup(GetCurrentFocusActor());
251 void KeyboardFocusManager::MoveFocusBackward()
253 // Find Pre Focused Actor when the list size is more than 1
254 if( mFocusHistory.size() > 1 )
256 // Delete current focused actor in history
257 mFocusHistory.pop_back();
259 // If pre-focused actors are not on stage or deleted, remove them in stack
260 while( mFocusHistory.size() > 0 )
262 // Get pre focused actor
263 Actor target = mFocusHistory[ mFocusHistory.size() -1 ].GetHandle();
265 // Impl of Actor is not null
266 if( target && target.OnStage() )
268 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
269 mFocusHistory.pop_back();
270 SetCurrentFocusActor( target );
275 // Target is empty handle or off stage. Erase from queue
276 mFocusHistory.pop_back();
280 // if there is no actor which can get focus, then push current focus actor in stack again
281 if( mFocusHistory.size() == 0 )
283 Actor currentFocusedActor = GetCurrentFocusActor();
284 mFocusHistory.push_back( currentFocusedActor );
289 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
291 Toolkit::Control control = Toolkit::Control::DownCast(actor);
292 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
295 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
297 // Get the actor's parent layout control that supports two dimensional keyboard navigation
298 Actor rootActor = Stage::GetCurrent().GetRootLayer();
302 parent = actor.GetParent();
305 while( parent && !IsLayoutControl(parent) && parent != rootActor )
307 parent = parent.GetParent();
310 return Toolkit::Control::DownCast(parent);
313 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
315 Actor currentFocusActor = GetCurrentFocusActor();
317 bool succeed = false;
319 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
320 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
321 while( parentLayoutControl && !succeed )
323 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
324 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
329 Actor nextFocusableActor;
331 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
333 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
334 if( currentFocusControl )
337 Property::Index index = Property::INVALID_INDEX;
338 Property::Value value;
340 // Find property index based upon focus direction
343 case Toolkit::Control::KeyboardFocus::LEFT:
345 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
348 case Toolkit::Control::KeyboardFocus::RIGHT:
350 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
353 case Toolkit::Control::KeyboardFocus::UP:
355 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
358 case Toolkit::Control::KeyboardFocus::DOWN:
360 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
367 // If the focusable property is set then determine next focusable actor
368 if( index != Property::INVALID_INDEX)
370 value = currentFocusActor.GetProperty( index );
371 actorId = value.Get<int>();
373 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
376 if( currentFocusActor.GetParent() )
378 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
381 if( !nextFocusableActor )
383 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
389 if( !nextFocusableActor )
391 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
392 if( mCustomAlgorithmInterface )
394 mIsWaitingKeyboardFocusChangeCommit = true;
395 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
396 mIsWaitingKeyboardFocusChangeCommit = false;
398 else if( !mPreFocusChangeSignal.Empty() )
400 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
401 mIsWaitingKeyboardFocusChangeCommit = true;
402 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
403 mIsWaitingKeyboardFocusChangeCommit = false;
407 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
409 // Whether the next focusable actor is a layout control
410 if( IsLayoutControl( nextFocusableActor ) )
412 // If so, move the focus inside it.
413 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
414 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
418 // Otherwise, just set focus to the next focusable actor
419 succeed = SetCurrentFocusActor( nextFocusableActor );
427 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
429 // Ask the control for the next actor to focus
430 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
431 if(nextFocusableActor)
433 if(!nextFocusableActor.IsKeyboardFocusable())
435 // If the actor is not focusable, ask the same layout control for the next actor to focus
436 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
440 Actor currentFocusActor = GetCurrentFocusActor();
441 Actor committedFocusActor = nextFocusableActor;
443 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
444 // Signal handler can check the proposed actor and return a different actor if it wishes.
445 if( !mPreFocusChangeSignal.Empty() )
447 mIsWaitingKeyboardFocusChangeCommit = true;
448 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
449 mIsWaitingKeyboardFocusChangeCommit = false;
452 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
454 // Whether the commited focusable actor is a layout control
455 if(IsLayoutControl(committedFocusActor))
457 // If so, move the focus inside it.
458 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
459 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
463 // Otherwise, just set focus to the next focusable actor
464 if(committedFocusActor == nextFocusableActor)
466 // If the application hasn't changed our proposed actor, we informs the layout control we will
467 // move the focus to what the control returns. The control might wish to perform some actions
468 // before the focus is actually moved.
469 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
472 return SetCurrentFocusActor(committedFocusActor);
483 // No more actor can be focused in the given direction within the same layout control.
488 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
490 bool succeed = false;
492 // Get the parent layout control of the current focus group
493 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
495 while(parentLayoutControl && !succeed)
497 // If the current focus group has a parent layout control, we can probably automatically
498 // move the focus to the next focus group in the forward or backward direction.
499 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
500 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
501 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
504 if(!mFocusGroupChangedSignal.Empty())
506 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
507 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
513 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
517 Toolkit::Control control = Toolkit::Control::DownCast( actor );
520 // Notify the control that enter has been pressed on it.
521 GetImplementation( control ).KeyboardEnter();
524 // Send a notification for the actor.
525 if( !mFocusedActorEnterKeySignal.Empty() )
527 mFocusedActorEnterKeySignal.Emit( actor );
532 void KeyboardFocusManager::ClearFocus()
534 Actor actor = GetCurrentFocusActor();
537 if( mFocusIndicatorActor )
539 actor.Remove( mFocusIndicatorActor );
542 // Send notification for the change of focus actor
543 if( !mFocusChangedSignal.Empty() )
545 mFocusChangedSignal.Emit( actor, Actor() );
548 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
549 if( currentlyFocusedControl )
551 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
552 currentlyFocusedControl.ClearKeyInputFocus();
556 mCurrentFocusActor.Reset();
557 mIsFocusIndicatorEnabled = 0;
560 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
562 mFocusGroupLoopEnabled = enabled;
565 bool KeyboardFocusManager::GetFocusGroupLoop() const
567 return mFocusGroupLoopEnabled;
570 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
574 // Create/Set focus group property.
575 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
579 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
581 // Check whether the actor is a focus group
582 bool isFocusGroup = false;
586 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
587 if(propertyIsFocusGroup != Property::INVALID_INDEX)
589 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
596 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
598 // Go through the actor's hierarchy to check which focus group the actor belongs to
599 while (actor && !IsFocusGroup(actor))
601 actor = actor.GetParent();
607 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
609 if(mFocusIndicatorActor != indicator)
611 Actor currentFocusActor = GetCurrentFocusActor();
612 if(currentFocusActor)
614 // The new focus indicator should be added to the current focused actor immediately
615 if(mFocusIndicatorActor)
617 currentFocusActor.Remove(mFocusIndicatorActor);
622 currentFocusActor.Add(indicator);
626 mFocusIndicatorActor = indicator;
630 Actor KeyboardFocusManager::GetFocusIndicatorActor()
632 if( ! mFocusIndicatorActor )
634 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
635 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
637 // Apply size constraint to the focus indicator
638 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
641 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
642 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
643 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
645 return mFocusIndicatorActor;
648 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
650 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
651 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
653 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
655 std::string keyName = event.keyPressedName;
657 if( mIsFocusIndicatorEnabled == -1 )
659 GetConfigurationFromStyleManger();
662 bool isFocusStartableKey = false;
664 if(event.state == KeyEvent::Down)
666 if (keyName == "Left")
668 if(!isAccessibilityEnabled)
670 if(!mIsFocusIndicatorEnabled)
672 // Show focus indicator
673 mIsFocusIndicatorEnabled = 1;
677 // Move the focus towards left
678 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
681 isFocusStartableKey = true;
685 // Move the accessibility focus backward
686 accessibilityManager.MoveFocusBackward();
689 else if (keyName == "Right")
691 if(!isAccessibilityEnabled)
693 if(!mIsFocusIndicatorEnabled)
695 // Show focus indicator
696 mIsFocusIndicatorEnabled = 1;
700 // Move the focus towards right
701 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
706 // Move the accessibility focus forward
707 accessibilityManager.MoveFocusForward();
710 isFocusStartableKey = true;
712 else if (keyName == "Up" && !isAccessibilityEnabled)
714 if(!mIsFocusIndicatorEnabled)
716 // Show focus indicator
717 mIsFocusIndicatorEnabled = 1;
721 // Move the focus towards up
722 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
725 isFocusStartableKey = true;
727 else if (keyName == "Down" && !isAccessibilityEnabled)
729 if(!mIsFocusIndicatorEnabled)
731 // Show focus indicator
732 mIsFocusIndicatorEnabled = 1;
736 // Move the focus towards down
737 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
740 isFocusStartableKey = true;
742 else if (keyName == "Prior" && !isAccessibilityEnabled)
744 if(!mIsFocusIndicatorEnabled)
746 // Show focus indicator
747 mIsFocusIndicatorEnabled = 1;
751 // Move the focus towards the previous page
752 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
755 isFocusStartableKey = true;
757 else if (keyName == "Next" && !isAccessibilityEnabled)
759 if(!mIsFocusIndicatorEnabled)
761 // Show focus indicator
762 mIsFocusIndicatorEnabled = 1;
766 // Move the focus towards the next page
767 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
770 isFocusStartableKey = true;
772 else if (keyName == "Tab" && !isAccessibilityEnabled)
774 if(!mIsFocusIndicatorEnabled)
776 // Show focus indicator
777 mIsFocusIndicatorEnabled = 1;
781 // "Tab" key changes the focus group in the forward direction and
782 // "Shift-Tab" key changes it in the backward direction.
783 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
786 isFocusStartableKey = true;
788 else if (keyName == "space" && !isAccessibilityEnabled)
790 if(!mIsFocusIndicatorEnabled)
792 // Show focus indicator
793 mIsFocusIndicatorEnabled = 1;
796 isFocusStartableKey = true;
798 else if (keyName == "" && !isAccessibilityEnabled)
800 // Check the fake key event for evas-plugin case
801 if(!mIsFocusIndicatorEnabled)
803 // Show focus indicator
804 mIsFocusIndicatorEnabled = 1;
807 isFocusStartableKey = true;
809 else if (keyName == "Backspace" && !isAccessibilityEnabled)
811 // Emit signal to go back to the previous view???
813 else if (keyName == "Escape" && !isAccessibilityEnabled)
817 else if(event.state == KeyEvent::Up)
819 if (keyName == "Return")
821 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
823 // Show focus indicator
824 mIsFocusIndicatorEnabled = 1;
828 // The focused actor has enter pressed on it
830 if( !isAccessibilityEnabled )
832 actor = GetCurrentFocusActor();
836 actor = accessibilityManager.GetCurrentFocusActor();
841 DoKeyboardEnter( actor );
845 isFocusStartableKey = true;
849 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
851 Actor actor = GetCurrentFocusActor();
854 // Make sure the focused actor is highlighted
855 actor.Add( GetFocusIndicatorActor() );
859 // No actor is focused but keyboard focus is activated by the key press
860 // Let's try to move the initial focus
861 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
866 void KeyboardFocusManager::OnTouch(const TouchData& touch)
868 // if mIsFocusIndicatorEnabled is -1, it means Configuration is not loaded.
869 // Try to load configuration.
870 if( mIsFocusIndicatorEnabled == -1 )
872 GetConfigurationFromStyleManger();
875 // Clear the focus when user touch the screen.
876 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
877 // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
878 if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
884 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
886 return mPreFocusChangeSignal;
889 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
891 return mFocusChangedSignal;
894 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
896 return mFocusGroupChangedSignal;
899 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
901 return mFocusedActorEnterKeySignal;
904 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
906 Dali::BaseHandle handle( object );
908 bool connected( true );
909 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
911 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
913 manager->PreFocusChangeSignal().Connect( tracker, functor );
915 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
917 manager->FocusChangedSignal().Connect( tracker, functor );
919 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
921 manager->FocusGroupChangedSignal().Connect( tracker, functor );
923 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
925 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
929 // signalName does not match any signal
936 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
938 mCustomAlgorithmInterface = &interface;
941 } // namespace Internal
943 } // namespace Toolkit