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 Integration::SceneHolder window = Integration::SceneHolder::Get( actor );
334 rootActor = window.GetRootLayer();
337 parent = actor.GetParent();
340 while( parent && !IsLayoutControl(parent) && parent != rootActor )
342 parent = parent.GetParent();
345 return Toolkit::Control::DownCast(parent);
348 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
350 Actor currentFocusActor = GetCurrentFocusActor();
352 bool succeed = false;
354 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
355 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
356 while( parentLayoutControl && !succeed )
358 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
359 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
364 Actor nextFocusableActor;
366 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
368 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
369 if( currentFocusControl )
372 Property::Index index = Property::INVALID_INDEX;
373 Property::Value value;
375 // Find property index based upon focus direction
378 case Toolkit::Control::KeyboardFocus::LEFT:
380 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
383 case Toolkit::Control::KeyboardFocus::RIGHT:
385 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
388 case Toolkit::Control::KeyboardFocus::UP:
390 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
393 case Toolkit::Control::KeyboardFocus::DOWN:
395 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
402 // If the focusable property is set then determine next focusable actor
403 if( index != Property::INVALID_INDEX)
405 value = currentFocusActor.GetProperty( index );
406 actorId = value.Get<int>();
408 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
411 if( currentFocusActor.GetParent() )
413 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
416 if( !nextFocusableActor )
418 Integration::SceneHolder window = Integration::SceneHolder::Get( currentFocusActor );
421 nextFocusableActor = window.GetRootLayer().FindChildById( actorId );
428 if( !nextFocusableActor )
430 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
431 if( mCustomAlgorithmInterface )
433 mIsWaitingKeyboardFocusChangeCommit = true;
434 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
435 mIsWaitingKeyboardFocusChangeCommit = false;
437 else if( !mPreFocusChangeSignal.Empty() )
439 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
440 mIsWaitingKeyboardFocusChangeCommit = true;
441 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
442 mIsWaitingKeyboardFocusChangeCommit = false;
446 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
448 // Whether the next focusable actor is a layout control
449 if( IsLayoutControl( nextFocusableActor ) )
451 // If so, move the focus inside it.
452 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
453 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
457 // Otherwise, just set focus to the next focusable actor
458 succeed = SetCurrentFocusActor( nextFocusableActor );
466 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
468 // Ask the control for the next actor to focus
469 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
470 if(nextFocusableActor)
472 if(!nextFocusableActor.IsKeyboardFocusable())
474 // If the actor is not focusable, ask the same layout control for the next actor to focus
475 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
479 Actor currentFocusActor = GetCurrentFocusActor();
480 Actor committedFocusActor = nextFocusableActor;
482 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
483 // Signal handler can check the proposed actor and return a different actor if it wishes.
484 if( !mPreFocusChangeSignal.Empty() )
486 mIsWaitingKeyboardFocusChangeCommit = true;
487 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
488 mIsWaitingKeyboardFocusChangeCommit = false;
491 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
493 // Whether the commited focusable actor is a layout control
494 if(IsLayoutControl(committedFocusActor))
496 // If so, move the focus inside it.
497 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
498 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
502 // Otherwise, just set focus to the next focusable actor
503 if(committedFocusActor == nextFocusableActor)
505 // If the application hasn't changed our proposed actor, we informs the layout control we will
506 // move the focus to what the control returns. The control might wish to perform some actions
507 // before the focus is actually moved.
508 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
511 return SetCurrentFocusActor(committedFocusActor);
522 // No more actor can be focused in the given direction within the same layout control.
527 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
529 bool succeed = false;
531 // Get the parent layout control of the current focus group
532 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
534 while(parentLayoutControl && !succeed)
536 // If the current focus group has a parent layout control, we can probably automatically
537 // move the focus to the next focus group in the forward or backward direction.
538 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
539 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
540 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
543 if(!mFocusGroupChangedSignal.Empty())
545 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
546 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
552 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
556 Toolkit::Control control = Toolkit::Control::DownCast( actor );
559 // Notify the control that enter has been pressed on it.
560 GetImplementation( control ).KeyboardEnter();
563 // Send a notification for the actor.
564 if( !mFocusedActorEnterKeySignal.Empty() )
566 mFocusedActorEnterKeySignal.Emit( actor );
571 void KeyboardFocusManager::ClearFocus()
573 Actor actor = GetCurrentFocusActor();
576 if( mFocusIndicatorActor )
578 actor.Remove( mFocusIndicatorActor );
581 // Send notification for the change of focus actor
582 if( !mFocusChangedSignal.Empty() )
584 mFocusChangedSignal.Emit( actor, Actor() );
587 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
588 if( currentlyFocusedControl )
590 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
591 currentlyFocusedControl.ClearKeyInputFocus();
595 mCurrentFocusActor.Reset();
596 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
599 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
601 mFocusGroupLoopEnabled = enabled;
604 bool KeyboardFocusManager::GetFocusGroupLoop() const
606 return mFocusGroupLoopEnabled;
609 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
613 // Create/Set focus group property.
614 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
618 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
620 // Check whether the actor is a focus group
621 bool isFocusGroup = false;
625 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
626 if(propertyIsFocusGroup != Property::INVALID_INDEX)
628 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
635 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
637 // Go through the actor's hierarchy to check which focus group the actor belongs to
638 while (actor && !IsFocusGroup(actor))
640 actor = actor.GetParent();
646 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
648 if(mFocusIndicatorActor != indicator)
650 Actor currentFocusActor = GetCurrentFocusActor();
651 if(currentFocusActor)
653 // The new focus indicator should be added to the current focused actor immediately
654 if(mFocusIndicatorActor)
656 currentFocusActor.Remove(mFocusIndicatorActor);
661 currentFocusActor.Add(indicator);
665 mFocusIndicatorActor = indicator;
669 Actor KeyboardFocusManager::GetFocusIndicatorActor()
671 if( ! mFocusIndicatorActor )
673 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
674 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
676 // Apply size constraint to the focus indicator
677 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
680 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
681 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
682 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
684 return mFocusIndicatorActor;
687 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
689 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
690 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
692 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
694 std::string keyName = event.keyPressedName;
696 if( mIsFocusIndicatorShown == -1 )
698 GetConfigurationFromStyleManger();
701 bool isFocusStartableKey = false;
703 if(event.state == KeyEvent::Down)
705 if (keyName == "Left")
707 if(!isAccessibilityEnabled)
709 if(!mIsFocusIndicatorShown)
711 // Show focus indicator
712 mIsFocusIndicatorShown = 1;
716 // Move the focus towards left
717 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
720 isFocusStartableKey = true;
724 // Move the accessibility focus backward
725 accessibilityManager.MoveFocusBackward();
728 else if (keyName == "Right")
730 if(!isAccessibilityEnabled)
732 if(!mIsFocusIndicatorShown)
734 // Show focus indicator
735 mIsFocusIndicatorShown = 1;
739 // Move the focus towards right
740 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
745 // Move the accessibility focus forward
746 accessibilityManager.MoveFocusForward();
749 isFocusStartableKey = true;
751 else if (keyName == "Up" && !isAccessibilityEnabled)
753 if(!mIsFocusIndicatorShown)
755 // Show focus indicator
756 mIsFocusIndicatorShown = 1;
760 // Move the focus towards up
761 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
764 isFocusStartableKey = true;
766 else if (keyName == "Down" && !isAccessibilityEnabled)
768 if(!mIsFocusIndicatorShown)
770 // Show focus indicator
771 mIsFocusIndicatorShown = 1;
775 // Move the focus towards down
776 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
779 isFocusStartableKey = true;
781 else if (keyName == "Prior" && !isAccessibilityEnabled)
783 if(!mIsFocusIndicatorShown)
785 // Show focus indicator
786 mIsFocusIndicatorShown = 1;
790 // Move the focus towards the previous page
791 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
794 isFocusStartableKey = true;
796 else if (keyName == "Next" && !isAccessibilityEnabled)
798 if(!mIsFocusIndicatorShown)
800 // Show focus indicator
801 mIsFocusIndicatorShown = 1;
805 // Move the focus towards the next page
806 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
809 isFocusStartableKey = true;
811 else if (keyName == "Tab" && !isAccessibilityEnabled)
813 if(!mIsFocusIndicatorShown)
815 // Show focus indicator
816 mIsFocusIndicatorShown = 1;
820 // "Tab" key changes the focus group in the forward direction and
821 // "Shift-Tab" key changes it in the backward direction.
822 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
825 isFocusStartableKey = true;
827 else if (keyName == "space" && !isAccessibilityEnabled)
829 if(!mIsFocusIndicatorShown)
831 // Show focus indicator
832 mIsFocusIndicatorShown = 1;
835 isFocusStartableKey = true;
837 else if (keyName == "" && !isAccessibilityEnabled)
839 // Check the fake key event for evas-plugin case
840 if(!mIsFocusIndicatorShown)
842 // Show focus indicator
843 mIsFocusIndicatorShown = 1;
846 isFocusStartableKey = true;
848 else if (keyName == "Backspace" && !isAccessibilityEnabled)
850 // Emit signal to go back to the previous view???
852 else if (keyName == "Escape" && !isAccessibilityEnabled)
856 else if(event.state == KeyEvent::Up)
858 if (keyName == "Return")
860 if(!mIsFocusIndicatorShown && !isAccessibilityEnabled)
862 // Show focus indicator
863 mIsFocusIndicatorShown = 1;
867 // The focused actor has enter pressed on it
869 if( !isAccessibilityEnabled )
871 actor = GetCurrentFocusActor();
875 actor = accessibilityManager.GetCurrentFocusActor();
880 DoKeyboardEnter( actor );
884 isFocusStartableKey = true;
888 if(isFocusStartableKey && mIsFocusIndicatorShown && !isAccessibilityEnabled)
890 Actor actor = GetCurrentFocusActor();
893 if( mEnableFocusIndicator )
895 // Make sure the focused actor is highlighted
896 actor.Add( GetFocusIndicatorActor() );
901 // No actor is focused but keyboard focus is activated by the key press
902 // Let's try to move the initial focus
903 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
908 void KeyboardFocusManager::OnTouch(const TouchData& touch)
910 // if mIsFocusIndicatorShown is -1, it means Configuration is not loaded.
911 // Try to load configuration.
912 if( mIsFocusIndicatorShown == -1 )
914 GetConfigurationFromStyleManger();
917 // Clear the focus when user touch the screen.
918 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
919 // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
920 if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
926 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
928 return mPreFocusChangeSignal;
931 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
933 return mFocusChangedSignal;
936 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
938 return mFocusGroupChangedSignal;
941 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
943 return mFocusedActorEnterKeySignal;
946 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
948 Dali::BaseHandle handle( object );
950 bool connected( true );
951 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
953 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
955 manager->PreFocusChangeSignal().Connect( tracker, functor );
957 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
959 manager->FocusChangedSignal().Connect( tracker, functor );
961 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
963 manager->FocusGroupChangedSignal().Connect( tracker, functor );
965 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
967 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
971 // signalName does not match any signal
978 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
980 mCustomAlgorithmInterface = &interface;
983 void KeyboardFocusManager::EnableFocusIndicator(bool enable)
985 if( !enable && mFocusIndicatorActor )
987 mFocusIndicatorActor.Unparent();
990 mEnableFocusIndicator = enable;
993 bool KeyboardFocusManager::IsFocusIndicatorEnabled() const
995 return mEnableFocusIndicator;
998 } // namespace Internal
1000 } // namespace Toolkit