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/window-devel.h>
27 #include <dali/devel-api/adaptor-framework/lifecycle-controller.h>
28 #include <dali/public-api/animation/constraints.h>
29 #include <dali/public-api/common/stage.h>
30 #include <dali/public-api/events/key-event.h>
31 #include <dali/public-api/events/touch-data.h>
32 #include <dali/public-api/object/type-registry.h>
33 #include <dali/public-api/object/type-registry-helper.h>
34 #include <dali/public-api/object/property-map.h>
35 #include <dali/public-api/images/resource-image.h>
36 #include <dali/integration-api/adaptors/adaptor.h>
37 #include <dali/integration-api/adaptors/scene-holder.h>
38 #include <dali/integration-api/debug.h>
41 #include <dali-toolkit/public-api/controls/control.h>
42 #include <dali-toolkit/public-api/controls/control-impl.h>
43 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
44 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
45 #include <dali-toolkit/devel-api/controls/control-devel.h>
46 #include <dali-toolkit/public-api/styling/style-manager.h>
47 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
58 namespace // Unnamed namespace
61 #if defined(DEBUG_ENABLED)
62 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
65 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
67 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
71 BaseHandle handle = KeyboardFocusManager::Get();
75 SingletonService singletonService( SingletonService::Get() );
76 if ( singletonService )
78 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
79 singletonService.Register( typeid( manager ), manager );
87 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
89 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
90 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
91 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
92 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
94 DALI_TYPE_REGISTRATION_END()
96 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
98 } // unnamed namespace
100 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
102 Toolkit::KeyboardFocusManager manager;
104 SingletonService singletonService( SingletonService::Get() );
105 if ( singletonService )
107 // Check whether the keyboard focus manager is already created
108 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
111 // If so, downcast the handle of singleton to keyboard focus manager
112 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
119 KeyboardFocusManager::KeyboardFocusManager()
120 : mPreFocusChangeSignal(),
121 mFocusChangedSignal(),
122 mFocusGroupChangedSignal(),
123 mFocusedActorEnterKeySignal(),
124 mCurrentFocusActor(),
125 mFocusIndicatorActor(),
126 mIsFocusIndicatorShown( -1 ),
127 mFocusGroupLoopEnabled( false ),
128 mIsWaitingKeyboardFocusChangeCommit( false ),
129 mClearFocusOnTouch( true ),
130 mEnableFocusIndicator( true ),
131 mAlwaysShowIndicator( true ),
133 mSlotDelegate( this ),
134 mCustomAlgorithmInterface(NULL)
136 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorShown.
138 LifecycleController::Get().InitSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnAdaptorInit );
141 void KeyboardFocusManager::OnAdaptorInit()
143 if( Adaptor::IsAvailable() )
145 // Retrieve all the existing widnows
146 Dali::WindowContainer windows = Adaptor::Get().GetWindows();
147 for ( auto iter = windows.begin(); iter != windows.end(); ++iter )
149 DevelWindow::KeyEventSignal( *iter ).Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
150 DevelWindow::TouchSignal( *iter ).Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch);
153 // Get notified when any new window is created afterwards
154 Adaptor::Get().WindowCreatedSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnWindowCreated);
158 void KeyboardFocusManager::OnWindowCreated( Dali::Window& window )
160 DevelWindow::KeyEventSignal( window ).Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
161 DevelWindow::TouchSignal( window ).Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch);
164 KeyboardFocusManager::~KeyboardFocusManager()
168 void KeyboardFocusManager::GetConfigurationFromStyleManger()
170 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
173 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
174 mAlwaysShowIndicator = config["alwaysShowFocus"].Get<bool>();
175 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
176 mClearFocusOnTouch = mIsFocusIndicatorShown ? false : true;
180 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
182 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
184 if( mIsFocusIndicatorShown == -1 )
186 GetConfigurationFromStyleManger();
189 return DoSetCurrentFocusActor( actor );
192 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
194 bool success = false;
196 Actor currentFocusedActor = GetCurrentFocusActor();
198 // If developer set focus on same actor, doing nothing
199 if( actor == currentFocusedActor )
208 // Check whether the actor is in the stage and is keyboard focusable.
209 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
211 if( mIsFocusIndicatorShown && mEnableFocusIndicator )
213 actor.Add( GetFocusIndicatorActor() );
216 // Send notification for the change of focus actor
217 if( !mFocusChangedSignal.Empty() )
219 mFocusChangedSignal.Emit(currentFocusedActor, actor);
222 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
223 if( currentlyFocusedControl )
225 // Do we need it to remember if it was previously DISABLED?
226 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
227 currentlyFocusedControl.ClearKeyInputFocus();
230 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
232 // Save the current focused actor
233 mCurrentFocusActor = actor;
235 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
236 if( newlyFocusedControl )
238 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
239 newlyFocusedControl.SetKeyInputFocus();
242 // Push Current Focused Actor to FocusHistory
243 mFocusHistory.push_back( actor );
245 // Delete first element before add new element when Stack is full.
246 if( mFocusHistory.size() > MAX_HISTORY_AMOUNT )
248 FocusStackIterator beginPos = mFocusHistory.begin();
249 mFocusHistory.erase( beginPos );
252 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
257 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
263 Actor KeyboardFocusManager::GetCurrentFocusActor()
265 Actor actor = mCurrentFocusActor.GetHandle();
266 if( actor && ! actor.OnStage() )
268 // If the actor has been removed from the stage, then it should not be focused
271 mCurrentFocusActor.Reset();
276 Actor KeyboardFocusManager::GetCurrentFocusGroup()
278 return GetFocusGroup(GetCurrentFocusActor());
281 void KeyboardFocusManager::MoveFocusBackward()
283 // Find Pre Focused Actor when the list size is more than 1
284 if( mFocusHistory.size() > 1 )
286 // Delete current focused actor in history
287 mFocusHistory.pop_back();
289 // If pre-focused actors are not on stage or deleted, remove them in stack
290 while( mFocusHistory.size() > 0 )
292 // Get pre focused actor
293 Actor target = mFocusHistory[ mFocusHistory.size() -1 ].GetHandle();
295 // Impl of Actor is not null
296 if( target && target.OnStage() )
298 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
299 mFocusHistory.pop_back();
300 SetCurrentFocusActor( target );
305 // Target is empty handle or off stage. Erase from queue
306 mFocusHistory.pop_back();
310 // if there is no actor which can get focus, then push current focus actor in stack again
311 if( mFocusHistory.size() == 0 )
313 Actor currentFocusedActor = GetCurrentFocusActor();
314 mFocusHistory.push_back( currentFocusedActor );
319 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
321 Toolkit::Control control = Toolkit::Control::DownCast(actor);
322 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
325 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
327 // Get the actor's parent layout control that supports two dimensional keyboard navigation
332 rootActor = Integration::SceneHolder::Get( actor ).GetRootLayer();
333 parent = actor.GetParent();
336 while( parent && !IsLayoutControl(parent) && parent != rootActor )
338 parent = parent.GetParent();
341 return Toolkit::Control::DownCast(parent);
344 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
346 Actor currentFocusActor = GetCurrentFocusActor();
348 bool succeed = false;
350 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
351 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
352 while( parentLayoutControl && !succeed )
354 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
355 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
360 Actor nextFocusableActor;
362 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
364 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
365 if( currentFocusControl )
368 Property::Index index = Property::INVALID_INDEX;
369 Property::Value value;
371 // Find property index based upon focus direction
374 case Toolkit::Control::KeyboardFocus::LEFT:
376 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
379 case Toolkit::Control::KeyboardFocus::RIGHT:
381 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
384 case Toolkit::Control::KeyboardFocus::UP:
386 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
389 case Toolkit::Control::KeyboardFocus::DOWN:
391 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
398 // If the focusable property is set then determine next focusable actor
399 if( index != Property::INVALID_INDEX)
401 value = currentFocusActor.GetProperty( index );
402 actorId = value.Get<int>();
404 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
407 if( currentFocusActor.GetParent() )
409 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
412 if( !nextFocusableActor )
414 nextFocusableActor = Integration::SceneHolder::Get( currentFocusActor ).GetRootLayer().FindChildById( actorId );
420 if( !nextFocusableActor )
422 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
423 if( mCustomAlgorithmInterface )
425 mIsWaitingKeyboardFocusChangeCommit = true;
426 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
427 mIsWaitingKeyboardFocusChangeCommit = false;
429 else if( !mPreFocusChangeSignal.Empty() )
431 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
432 mIsWaitingKeyboardFocusChangeCommit = true;
433 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
434 mIsWaitingKeyboardFocusChangeCommit = false;
438 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
440 // Whether the next focusable actor is a layout control
441 if( IsLayoutControl( nextFocusableActor ) )
443 // If so, move the focus inside it.
444 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
445 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
449 // Otherwise, just set focus to the next focusable actor
450 succeed = SetCurrentFocusActor( nextFocusableActor );
458 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
460 // Ask the control for the next actor to focus
461 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
462 if(nextFocusableActor)
464 if(!nextFocusableActor.IsKeyboardFocusable())
466 // If the actor is not focusable, ask the same layout control for the next actor to focus
467 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
471 Actor currentFocusActor = GetCurrentFocusActor();
472 Actor committedFocusActor = nextFocusableActor;
474 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
475 // Signal handler can check the proposed actor and return a different actor if it wishes.
476 if( !mPreFocusChangeSignal.Empty() )
478 mIsWaitingKeyboardFocusChangeCommit = true;
479 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
480 mIsWaitingKeyboardFocusChangeCommit = false;
483 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
485 // Whether the commited focusable actor is a layout control
486 if(IsLayoutControl(committedFocusActor))
488 // If so, move the focus inside it.
489 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
490 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
494 // Otherwise, just set focus to the next focusable actor
495 if(committedFocusActor == nextFocusableActor)
497 // If the application hasn't changed our proposed actor, we informs the layout control we will
498 // move the focus to what the control returns. The control might wish to perform some actions
499 // before the focus is actually moved.
500 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
503 return SetCurrentFocusActor(committedFocusActor);
514 // No more actor can be focused in the given direction within the same layout control.
519 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
521 bool succeed = false;
523 // Get the parent layout control of the current focus group
524 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
526 while(parentLayoutControl && !succeed)
528 // If the current focus group has a parent layout control, we can probably automatically
529 // move the focus to the next focus group in the forward or backward direction.
530 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
531 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
532 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
535 if(!mFocusGroupChangedSignal.Empty())
537 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
538 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
544 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
548 Toolkit::Control control = Toolkit::Control::DownCast( actor );
551 // Notify the control that enter has been pressed on it.
552 GetImplementation( control ).KeyboardEnter();
555 // Send a notification for the actor.
556 if( !mFocusedActorEnterKeySignal.Empty() )
558 mFocusedActorEnterKeySignal.Emit( actor );
563 void KeyboardFocusManager::ClearFocus()
565 Actor actor = GetCurrentFocusActor();
568 if( mFocusIndicatorActor )
570 actor.Remove( mFocusIndicatorActor );
573 // Send notification for the change of focus actor
574 if( !mFocusChangedSignal.Empty() )
576 mFocusChangedSignal.Emit( actor, Actor() );
579 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
580 if( currentlyFocusedControl )
582 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
583 currentlyFocusedControl.ClearKeyInputFocus();
587 mCurrentFocusActor.Reset();
588 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
591 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
593 mFocusGroupLoopEnabled = enabled;
596 bool KeyboardFocusManager::GetFocusGroupLoop() const
598 return mFocusGroupLoopEnabled;
601 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
605 // Create/Set focus group property.
606 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
610 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
612 // Check whether the actor is a focus group
613 bool isFocusGroup = false;
617 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
618 if(propertyIsFocusGroup != Property::INVALID_INDEX)
620 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
627 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
629 // Go through the actor's hierarchy to check which focus group the actor belongs to
630 while (actor && !IsFocusGroup(actor))
632 actor = actor.GetParent();
638 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
640 if(mFocusIndicatorActor != indicator)
642 Actor currentFocusActor = GetCurrentFocusActor();
643 if(currentFocusActor)
645 // The new focus indicator should be added to the current focused actor immediately
646 if(mFocusIndicatorActor)
648 currentFocusActor.Remove(mFocusIndicatorActor);
653 currentFocusActor.Add(indicator);
657 mFocusIndicatorActor = indicator;
661 Actor KeyboardFocusManager::GetFocusIndicatorActor()
663 if( ! mFocusIndicatorActor )
665 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
666 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
668 // Apply size constraint to the focus indicator
669 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
672 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
673 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
674 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
676 return mFocusIndicatorActor;
679 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
681 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
682 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
684 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
686 std::string keyName = event.keyPressedName;
688 if( mIsFocusIndicatorShown == -1 )
690 GetConfigurationFromStyleManger();
693 bool isFocusStartableKey = false;
695 if(event.state == KeyEvent::Down)
697 if (keyName == "Left")
699 if(!isAccessibilityEnabled)
701 if(!mIsFocusIndicatorShown)
703 // Show focus indicator
704 mIsFocusIndicatorShown = 1;
708 // Move the focus towards left
709 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
712 isFocusStartableKey = true;
716 // Move the accessibility focus backward
717 accessibilityManager.MoveFocusBackward();
720 else if (keyName == "Right")
722 if(!isAccessibilityEnabled)
724 if(!mIsFocusIndicatorShown)
726 // Show focus indicator
727 mIsFocusIndicatorShown = 1;
731 // Move the focus towards right
732 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
737 // Move the accessibility focus forward
738 accessibilityManager.MoveFocusForward();
741 isFocusStartableKey = true;
743 else if (keyName == "Up" && !isAccessibilityEnabled)
745 if(!mIsFocusIndicatorShown)
747 // Show focus indicator
748 mIsFocusIndicatorShown = 1;
752 // Move the focus towards up
753 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
756 isFocusStartableKey = true;
758 else if (keyName == "Down" && !isAccessibilityEnabled)
760 if(!mIsFocusIndicatorShown)
762 // Show focus indicator
763 mIsFocusIndicatorShown = 1;
767 // Move the focus towards down
768 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
771 isFocusStartableKey = true;
773 else if (keyName == "Prior" && !isAccessibilityEnabled)
775 if(!mIsFocusIndicatorShown)
777 // Show focus indicator
778 mIsFocusIndicatorShown = 1;
782 // Move the focus towards the previous page
783 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
786 isFocusStartableKey = true;
788 else if (keyName == "Next" && !isAccessibilityEnabled)
790 if(!mIsFocusIndicatorShown)
792 // Show focus indicator
793 mIsFocusIndicatorShown = 1;
797 // Move the focus towards the next page
798 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
801 isFocusStartableKey = true;
803 else if (keyName == "Tab" && !isAccessibilityEnabled)
805 if(!mIsFocusIndicatorShown)
807 // Show focus indicator
808 mIsFocusIndicatorShown = 1;
812 // "Tab" key changes the focus group in the forward direction and
813 // "Shift-Tab" key changes it in the backward direction.
814 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
817 isFocusStartableKey = true;
819 else if (keyName == "space" && !isAccessibilityEnabled)
821 if(!mIsFocusIndicatorShown)
823 // Show focus indicator
824 mIsFocusIndicatorShown = 1;
827 isFocusStartableKey = true;
829 else if (keyName == "" && !isAccessibilityEnabled)
831 // Check the fake key event for evas-plugin case
832 if(!mIsFocusIndicatorShown)
834 // Show focus indicator
835 mIsFocusIndicatorShown = 1;
838 isFocusStartableKey = true;
840 else if (keyName == "Backspace" && !isAccessibilityEnabled)
842 // Emit signal to go back to the previous view???
844 else if (keyName == "Escape" && !isAccessibilityEnabled)
848 else if(event.state == KeyEvent::Up)
850 if (keyName == "Return")
852 if(!mIsFocusIndicatorShown && !isAccessibilityEnabled)
854 // Show focus indicator
855 mIsFocusIndicatorShown = 1;
859 // The focused actor has enter pressed on it
861 if( !isAccessibilityEnabled )
863 actor = GetCurrentFocusActor();
867 actor = accessibilityManager.GetCurrentFocusActor();
872 DoKeyboardEnter( actor );
876 isFocusStartableKey = true;
880 if(isFocusStartableKey && mIsFocusIndicatorShown && !isAccessibilityEnabled)
882 Actor actor = GetCurrentFocusActor();
885 if( mEnableFocusIndicator )
887 // Make sure the focused actor is highlighted
888 actor.Add( GetFocusIndicatorActor() );
893 // No actor is focused but keyboard focus is activated by the key press
894 // Let's try to move the initial focus
895 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
900 void KeyboardFocusManager::OnTouch(const TouchData& touch)
902 // if mIsFocusIndicatorShown is -1, it means Configuration is not loaded.
903 // Try to load configuration.
904 if( mIsFocusIndicatorShown == -1 )
906 GetConfigurationFromStyleManger();
909 // Clear the focus when user touch the screen.
910 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
911 // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
912 if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
918 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
920 return mPreFocusChangeSignal;
923 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
925 return mFocusChangedSignal;
928 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
930 return mFocusGroupChangedSignal;
933 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
935 return mFocusedActorEnterKeySignal;
938 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
940 Dali::BaseHandle handle( object );
942 bool connected( true );
943 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
945 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
947 manager->PreFocusChangeSignal().Connect( tracker, functor );
949 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
951 manager->FocusChangedSignal().Connect( tracker, functor );
953 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
955 manager->FocusGroupChangedSignal().Connect( tracker, functor );
957 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
959 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
963 // signalName does not match any signal
970 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
972 mCustomAlgorithmInterface = &interface;
975 void KeyboardFocusManager::EnableFocusIndicator(bool enable)
977 if( !enable && mFocusIndicatorActor )
979 mFocusIndicatorActor.Unparent();
982 mEnableFocusIndicator = enable;
985 bool KeyboardFocusManager::IsFocusIndicatorEnabled() const
987 return mEnableFocusIndicator;
990 } // namespace Internal
992 } // namespace Toolkit