2 * Copyright (c) 2019 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/devel-api/adaptor-framework/lifecycle-controller.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/common/stage.h>
29 #include <dali/public-api/events/key-event.h>
30 #include <dali/public-api/events/touch-data.h>
31 #include <dali/public-api/object/type-registry.h>
32 #include <dali/public-api/object/type-registry-helper.h>
33 #include <dali/public-api/object/property-map.h>
34 #include <dali/public-api/images/resource-image.h>
35 #include <dali/integration-api/adaptors/adaptor.h>
36 #include <dali/integration-api/adaptors/scene-holder.h>
37 #include <dali/integration-api/debug.h>
40 #include <dali-toolkit/public-api/controls/control.h>
41 #include <dali-toolkit/public-api/controls/control-impl.h>
42 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
43 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/public-api/styling/style-manager.h>
46 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
57 namespace // Unnamed namespace
60 #if defined(DEBUG_ENABLED)
61 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
64 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
66 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
70 BaseHandle handle = KeyboardFocusManager::Get();
74 SingletonService singletonService( SingletonService::Get() );
75 if ( singletonService )
77 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
78 singletonService.Register( typeid( manager ), manager );
86 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
88 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
89 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
90 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
91 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
93 DALI_TYPE_REGISTRATION_END()
95 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
97 } // unnamed namespace
99 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
101 Toolkit::KeyboardFocusManager manager;
103 SingletonService singletonService( SingletonService::Get() );
104 if ( singletonService )
106 // Check whether the keyboard focus manager is already created
107 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
110 // If so, downcast the handle of singleton to keyboard focus manager
111 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
118 KeyboardFocusManager::KeyboardFocusManager()
119 : mPreFocusChangeSignal(),
120 mFocusChangedSignal(),
121 mFocusGroupChangedSignal(),
122 mFocusedActorEnterKeySignal(),
123 mCurrentFocusActor(),
124 mFocusIndicatorActor(),
125 mIsFocusIndicatorShown( -1 ),
126 mFocusGroupLoopEnabled( false ),
127 mIsWaitingKeyboardFocusChangeCommit( false ),
128 mClearFocusOnTouch( true ),
129 mEnableFocusIndicator( true ),
130 mAlwaysShowIndicator( true ),
132 mSlotDelegate( this ),
133 mCustomAlgorithmInterface(NULL)
135 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorShown.
137 LifecycleController::Get().InitSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnAdaptorInit );
140 void KeyboardFocusManager::OnAdaptorInit()
142 if( Adaptor::IsAvailable() )
144 // Retrieve all the existing scene holders
145 Dali::SceneHolderList sceneHolders = Adaptor::Get().GetSceneHolders();
146 for( auto iter = sceneHolders.begin(); iter != sceneHolders.end(); ++iter )
148 ( *iter ).KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent );
149 ( *iter ).TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
152 // Get notified when any new scene holder is created afterwards
153 Adaptor::Get().WindowCreatedSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnSceneHolderCreated );
157 void KeyboardFocusManager::OnSceneHolderCreated( Dali::Integration::SceneHolder& sceneHolder )
159 sceneHolder.KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent );
160 sceneHolder.TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
163 KeyboardFocusManager::~KeyboardFocusManager()
167 void KeyboardFocusManager::GetConfigurationFromStyleManger()
169 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
172 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
173 mAlwaysShowIndicator = config["alwaysShowFocus"].Get<bool>();
174 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
175 mClearFocusOnTouch = mIsFocusIndicatorShown ? false : true;
179 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
181 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
183 if( mIsFocusIndicatorShown == -1 )
185 GetConfigurationFromStyleManger();
188 return DoSetCurrentFocusActor( actor );
191 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
193 bool success = false;
195 Actor currentFocusedActor = GetCurrentFocusActor();
197 // If developer set focus on same actor, doing nothing
198 if( actor == currentFocusedActor )
207 // Check whether the actor is in the stage and is keyboard focusable.
208 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
210 if( mIsFocusIndicatorShown && mEnableFocusIndicator )
212 actor.Add( GetFocusIndicatorActor() );
215 // Send notification for the change of focus actor
216 if( !mFocusChangedSignal.Empty() )
218 mFocusChangedSignal.Emit(currentFocusedActor, actor);
221 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
222 if( currentlyFocusedControl )
224 // Do we need it to remember if it was previously DISABLED?
225 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
226 currentlyFocusedControl.ClearKeyInputFocus();
229 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
231 // Save the current focused actor
232 mCurrentFocusActor = actor;
234 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
235 if( newlyFocusedControl )
237 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
238 newlyFocusedControl.SetKeyInputFocus();
241 // Push Current Focused Actor to FocusHistory
242 mFocusHistory.push_back( actor );
244 // Delete first element before add new element when Stack is full.
245 if( mFocusHistory.size() > MAX_HISTORY_AMOUNT )
247 FocusStackIterator beginPos = mFocusHistory.begin();
248 mFocusHistory.erase( beginPos );
251 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
256 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
262 Actor KeyboardFocusManager::GetCurrentFocusActor()
264 Actor actor = mCurrentFocusActor.GetHandle();
265 if( actor && ! actor.OnStage() )
267 // If the actor has been removed from the stage, then it should not be focused
270 mCurrentFocusActor.Reset();
275 Actor KeyboardFocusManager::GetCurrentFocusGroup()
277 return GetFocusGroup(GetCurrentFocusActor());
280 void KeyboardFocusManager::MoveFocusBackward()
282 // Find Pre Focused Actor when the list size is more than 1
283 if( mFocusHistory.size() > 1 )
285 // Delete current focused actor in history
286 mFocusHistory.pop_back();
288 // If pre-focused actors are not on stage or deleted, remove them in stack
289 while( mFocusHistory.size() > 0 )
291 // Get pre focused actor
292 Actor target = mFocusHistory[ mFocusHistory.size() -1 ].GetHandle();
294 // Impl of Actor is not null
295 if( target && target.OnStage() )
297 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
298 mFocusHistory.pop_back();
299 SetCurrentFocusActor( target );
304 // Target is empty handle or off stage. Erase from queue
305 mFocusHistory.pop_back();
309 // if there is no actor which can get focus, then push current focus actor in stack again
310 if( mFocusHistory.size() == 0 )
312 Actor currentFocusedActor = GetCurrentFocusActor();
313 mFocusHistory.push_back( currentFocusedActor );
318 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
320 Toolkit::Control control = Toolkit::Control::DownCast(actor);
321 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
324 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
326 // Get the actor's parent layout control that supports two dimensional keyboard navigation
331 rootActor = Integration::SceneHolder::Get( actor ).GetRootLayer();
332 parent = actor.GetParent();
335 while( parent && !IsLayoutControl(parent) && parent != rootActor )
337 parent = parent.GetParent();
340 return Toolkit::Control::DownCast(parent);
343 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
345 Actor currentFocusActor = GetCurrentFocusActor();
347 bool succeed = false;
349 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
350 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
351 while( parentLayoutControl && !succeed )
353 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
354 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
359 Actor nextFocusableActor;
361 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
363 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
364 if( currentFocusControl )
367 Property::Index index = Property::INVALID_INDEX;
368 Property::Value value;
370 // Find property index based upon focus direction
373 case Toolkit::Control::KeyboardFocus::LEFT:
375 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
378 case Toolkit::Control::KeyboardFocus::RIGHT:
380 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
383 case Toolkit::Control::KeyboardFocus::UP:
385 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
388 case Toolkit::Control::KeyboardFocus::DOWN:
390 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
397 // If the focusable property is set then determine next focusable actor
398 if( index != Property::INVALID_INDEX)
400 value = currentFocusActor.GetProperty( index );
401 actorId = value.Get<int>();
403 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
406 if( currentFocusActor.GetParent() )
408 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
411 if( !nextFocusableActor )
413 nextFocusableActor = Integration::SceneHolder::Get( currentFocusActor ).GetRootLayer().FindChildById( actorId );
419 if( !nextFocusableActor )
421 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
422 if( mCustomAlgorithmInterface )
424 mIsWaitingKeyboardFocusChangeCommit = true;
425 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
426 mIsWaitingKeyboardFocusChangeCommit = false;
428 else if( !mPreFocusChangeSignal.Empty() )
430 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
431 mIsWaitingKeyboardFocusChangeCommit = true;
432 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
433 mIsWaitingKeyboardFocusChangeCommit = false;
437 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
439 // Whether the next focusable actor is a layout control
440 if( IsLayoutControl( nextFocusableActor ) )
442 // If so, move the focus inside it.
443 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
444 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
448 // Otherwise, just set focus to the next focusable actor
449 succeed = SetCurrentFocusActor( nextFocusableActor );
457 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
459 // Ask the control for the next actor to focus
460 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
461 if(nextFocusableActor)
463 if(!nextFocusableActor.IsKeyboardFocusable())
465 // If the actor is not focusable, ask the same layout control for the next actor to focus
466 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
470 Actor currentFocusActor = GetCurrentFocusActor();
471 Actor committedFocusActor = nextFocusableActor;
473 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
474 // Signal handler can check the proposed actor and return a different actor if it wishes.
475 if( !mPreFocusChangeSignal.Empty() )
477 mIsWaitingKeyboardFocusChangeCommit = true;
478 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
479 mIsWaitingKeyboardFocusChangeCommit = false;
482 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
484 // Whether the commited focusable actor is a layout control
485 if(IsLayoutControl(committedFocusActor))
487 // If so, move the focus inside it.
488 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
489 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
493 // Otherwise, just set focus to the next focusable actor
494 if(committedFocusActor == nextFocusableActor)
496 // If the application hasn't changed our proposed actor, we informs the layout control we will
497 // move the focus to what the control returns. The control might wish to perform some actions
498 // before the focus is actually moved.
499 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
502 return SetCurrentFocusActor(committedFocusActor);
513 // No more actor can be focused in the given direction within the same layout control.
518 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
520 bool succeed = false;
522 // Get the parent layout control of the current focus group
523 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
525 while(parentLayoutControl && !succeed)
527 // If the current focus group has a parent layout control, we can probably automatically
528 // move the focus to the next focus group in the forward or backward direction.
529 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
530 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
531 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
534 if(!mFocusGroupChangedSignal.Empty())
536 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
537 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
543 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
547 Toolkit::Control control = Toolkit::Control::DownCast( actor );
550 // Notify the control that enter has been pressed on it.
551 GetImplementation( control ).KeyboardEnter();
554 // Send a notification for the actor.
555 if( !mFocusedActorEnterKeySignal.Empty() )
557 mFocusedActorEnterKeySignal.Emit( actor );
562 void KeyboardFocusManager::ClearFocus()
564 Actor actor = GetCurrentFocusActor();
567 if( mFocusIndicatorActor )
569 actor.Remove( mFocusIndicatorActor );
572 // Send notification for the change of focus actor
573 if( !mFocusChangedSignal.Empty() )
575 mFocusChangedSignal.Emit( actor, Actor() );
578 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
579 if( currentlyFocusedControl )
581 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
582 currentlyFocusedControl.ClearKeyInputFocus();
586 mCurrentFocusActor.Reset();
587 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
590 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
592 mFocusGroupLoopEnabled = enabled;
595 bool KeyboardFocusManager::GetFocusGroupLoop() const
597 return mFocusGroupLoopEnabled;
600 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
604 // Create/Set focus group property.
605 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
609 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
611 // Check whether the actor is a focus group
612 bool isFocusGroup = false;
616 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
617 if(propertyIsFocusGroup != Property::INVALID_INDEX)
619 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
626 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
628 // Go through the actor's hierarchy to check which focus group the actor belongs to
629 while (actor && !IsFocusGroup(actor))
631 actor = actor.GetParent();
637 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
639 if(mFocusIndicatorActor != indicator)
641 Actor currentFocusActor = GetCurrentFocusActor();
642 if(currentFocusActor)
644 // The new focus indicator should be added to the current focused actor immediately
645 if(mFocusIndicatorActor)
647 currentFocusActor.Remove(mFocusIndicatorActor);
652 currentFocusActor.Add(indicator);
656 mFocusIndicatorActor = indicator;
660 Actor KeyboardFocusManager::GetFocusIndicatorActor()
662 if( ! mFocusIndicatorActor )
664 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
665 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
667 // Apply size constraint to the focus indicator
668 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
671 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
672 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
673 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
675 return mFocusIndicatorActor;
678 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
680 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
681 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
683 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
685 std::string keyName = event.keyPressedName;
687 if( mIsFocusIndicatorShown == -1 )
689 GetConfigurationFromStyleManger();
692 bool isFocusStartableKey = false;
694 if(event.state == KeyEvent::Down)
696 if (keyName == "Left")
698 if(!isAccessibilityEnabled)
700 if(!mIsFocusIndicatorShown)
702 // Show focus indicator
703 mIsFocusIndicatorShown = 1;
707 // Move the focus towards left
708 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
711 isFocusStartableKey = true;
715 // Move the accessibility focus backward
716 accessibilityManager.MoveFocusBackward();
719 else if (keyName == "Right")
721 if(!isAccessibilityEnabled)
723 if(!mIsFocusIndicatorShown)
725 // Show focus indicator
726 mIsFocusIndicatorShown = 1;
730 // Move the focus towards right
731 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
736 // Move the accessibility focus forward
737 accessibilityManager.MoveFocusForward();
740 isFocusStartableKey = true;
742 else if (keyName == "Up" && !isAccessibilityEnabled)
744 if(!mIsFocusIndicatorShown)
746 // Show focus indicator
747 mIsFocusIndicatorShown = 1;
751 // Move the focus towards up
752 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
755 isFocusStartableKey = true;
757 else if (keyName == "Down" && !isAccessibilityEnabled)
759 if(!mIsFocusIndicatorShown)
761 // Show focus indicator
762 mIsFocusIndicatorShown = 1;
766 // Move the focus towards down
767 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
770 isFocusStartableKey = true;
772 else if (keyName == "Prior" && !isAccessibilityEnabled)
774 if(!mIsFocusIndicatorShown)
776 // Show focus indicator
777 mIsFocusIndicatorShown = 1;
781 // Move the focus towards the previous page
782 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
785 isFocusStartableKey = true;
787 else if (keyName == "Next" && !isAccessibilityEnabled)
789 if(!mIsFocusIndicatorShown)
791 // Show focus indicator
792 mIsFocusIndicatorShown = 1;
796 // Move the focus towards the next page
797 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
800 isFocusStartableKey = true;
802 else if (keyName == "Tab" && !isAccessibilityEnabled)
804 if(!mIsFocusIndicatorShown)
806 // Show focus indicator
807 mIsFocusIndicatorShown = 1;
811 // "Tab" key changes the focus group in the forward direction and
812 // "Shift-Tab" key changes it in the backward direction.
813 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
816 isFocusStartableKey = true;
818 else if (keyName == "space" && !isAccessibilityEnabled)
820 if(!mIsFocusIndicatorShown)
822 // Show focus indicator
823 mIsFocusIndicatorShown = 1;
826 isFocusStartableKey = true;
828 else if (keyName == "" && !isAccessibilityEnabled)
830 // Check the fake key event for evas-plugin case
831 if(!mIsFocusIndicatorShown)
833 // Show focus indicator
834 mIsFocusIndicatorShown = 1;
837 isFocusStartableKey = true;
839 else if (keyName == "Backspace" && !isAccessibilityEnabled)
841 // Emit signal to go back to the previous view???
843 else if (keyName == "Escape" && !isAccessibilityEnabled)
847 else if(event.state == KeyEvent::Up)
849 if (keyName == "Return")
851 if(!mIsFocusIndicatorShown && !isAccessibilityEnabled)
853 // Show focus indicator
854 mIsFocusIndicatorShown = 1;
858 // The focused actor has enter pressed on it
860 if( !isAccessibilityEnabled )
862 actor = GetCurrentFocusActor();
866 actor = accessibilityManager.GetCurrentFocusActor();
871 DoKeyboardEnter( actor );
875 isFocusStartableKey = true;
879 if(isFocusStartableKey && mIsFocusIndicatorShown && !isAccessibilityEnabled)
881 Actor actor = GetCurrentFocusActor();
884 if( mEnableFocusIndicator )
886 // Make sure the focused actor is highlighted
887 actor.Add( GetFocusIndicatorActor() );
892 // No actor is focused but keyboard focus is activated by the key press
893 // Let's try to move the initial focus
894 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
899 void KeyboardFocusManager::OnTouch(const TouchData& touch)
901 // if mIsFocusIndicatorShown is -1, it means Configuration is not loaded.
902 // Try to load configuration.
903 if( mIsFocusIndicatorShown == -1 )
905 GetConfigurationFromStyleManger();
908 // Clear the focus when user touch the screen.
909 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
910 // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
911 if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
917 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
919 return mPreFocusChangeSignal;
922 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
924 return mFocusChangedSignal;
927 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
929 return mFocusGroupChangedSignal;
932 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
934 return mFocusedActorEnterKeySignal;
937 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
939 Dali::BaseHandle handle( object );
941 bool connected( true );
942 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
944 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
946 manager->PreFocusChangeSignal().Connect( tracker, functor );
948 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
950 manager->FocusChangedSignal().Connect( tracker, functor );
952 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
954 manager->FocusGroupChangedSignal().Connect( tracker, functor );
956 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
958 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
962 // signalName does not match any signal
969 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
971 mCustomAlgorithmInterface = &interface;
974 void KeyboardFocusManager::EnableFocusIndicator(bool enable)
976 if( !enable && mFocusIndicatorActor )
978 mFocusIndicatorActor.Unparent();
981 mEnableFocusIndicator = enable;
984 bool KeyboardFocusManager::IsFocusIndicatorEnabled() const
986 return mEnableFocusIndicator;
989 } // namespace Internal
991 } // namespace Toolkit