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 mIsFocusIndicatorShown( -1 ),
123 mFocusGroupLoopEnabled( false ),
124 mIsWaitingKeyboardFocusChangeCommit( false ),
125 mClearFocusOnTouch( true ),
126 mEnableFocusIndicator( true ),
127 mAlwaysShowIndicator( true ),
129 mSlotDelegate( this ),
130 mCustomAlgorithmInterface(NULL)
132 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorShown.
133 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
134 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
137 KeyboardFocusManager::~KeyboardFocusManager()
141 void KeyboardFocusManager::GetConfigurationFromStyleManger()
143 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
146 Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
147 mAlwaysShowIndicator = config["alwaysShowFocus"].Get<bool>();
148 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
149 mClearFocusOnTouch = mIsFocusIndicatorShown ? false : true;
153 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
155 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
157 if( mIsFocusIndicatorShown == -1 )
159 GetConfigurationFromStyleManger();
162 return DoSetCurrentFocusActor( actor );
165 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
167 bool success = false;
169 Actor currentFocusedActor = GetCurrentFocusActor();
171 // If developer set focus on same actor, doing nothing
172 if( actor == currentFocusedActor )
181 // Check whether the actor is in the stage and is keyboard focusable.
182 if( actor && actor.IsKeyboardFocusable() && actor.OnStage() )
184 if( mIsFocusIndicatorShown && mEnableFocusIndicator )
186 actor.Add( GetFocusIndicatorActor() );
189 // Send notification for the change of focus actor
190 if( !mFocusChangedSignal.Empty() )
192 mFocusChangedSignal.Emit(currentFocusedActor, actor);
195 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
196 if( currentlyFocusedControl )
198 // Do we need it to remember if it was previously DISABLED?
199 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
200 currentlyFocusedControl.ClearKeyInputFocus();
203 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
205 // Save the current focused actor
206 mCurrentFocusActor = actor;
208 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
209 if( newlyFocusedControl )
211 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
212 newlyFocusedControl.SetKeyInputFocus();
215 // Push Current Focused Actor to FocusHistory
216 mFocusHistory.push_back( actor );
218 // Delete first element before add new element when Stack is full.
219 if( mFocusHistory.size() > MAX_HISTORY_AMOUNT )
221 FocusStackIterator beginPos = mFocusHistory.begin();
222 mFocusHistory.erase( beginPos );
225 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
230 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
236 Actor KeyboardFocusManager::GetCurrentFocusActor()
238 Actor actor = mCurrentFocusActor.GetHandle();
239 if( actor && ! actor.OnStage() )
241 // If the actor has been removed from the stage, then it should not be focused
244 mCurrentFocusActor.Reset();
249 Actor KeyboardFocusManager::GetCurrentFocusGroup()
251 return GetFocusGroup(GetCurrentFocusActor());
254 void KeyboardFocusManager::MoveFocusBackward()
256 // Find Pre Focused Actor when the list size is more than 1
257 if( mFocusHistory.size() > 1 )
259 // Delete current focused actor in history
260 mFocusHistory.pop_back();
262 // If pre-focused actors are not on stage or deleted, remove them in stack
263 while( mFocusHistory.size() > 0 )
265 // Get pre focused actor
266 Actor target = mFocusHistory[ mFocusHistory.size() -1 ].GetHandle();
268 // Impl of Actor is not null
269 if( target && target.OnStage() )
271 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
272 mFocusHistory.pop_back();
273 SetCurrentFocusActor( target );
278 // Target is empty handle or off stage. Erase from queue
279 mFocusHistory.pop_back();
283 // if there is no actor which can get focus, then push current focus actor in stack again
284 if( mFocusHistory.size() == 0 )
286 Actor currentFocusedActor = GetCurrentFocusActor();
287 mFocusHistory.push_back( currentFocusedActor );
292 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
294 Toolkit::Control control = Toolkit::Control::DownCast(actor);
295 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
298 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
300 // Get the actor's parent layout control that supports two dimensional keyboard navigation
301 Actor rootActor = Stage::GetCurrent().GetRootLayer();
305 parent = actor.GetParent();
308 while( parent && !IsLayoutControl(parent) && parent != rootActor )
310 parent = parent.GetParent();
313 return Toolkit::Control::DownCast(parent);
316 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
318 Actor currentFocusActor = GetCurrentFocusActor();
320 bool succeed = false;
322 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
323 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
324 while( parentLayoutControl && !succeed )
326 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
327 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
332 Actor nextFocusableActor;
334 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
336 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
337 if( currentFocusControl )
340 Property::Index index = Property::INVALID_INDEX;
341 Property::Value value;
343 // Find property index based upon focus direction
346 case Toolkit::Control::KeyboardFocus::LEFT:
348 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
351 case Toolkit::Control::KeyboardFocus::RIGHT:
353 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
356 case Toolkit::Control::KeyboardFocus::UP:
358 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
361 case Toolkit::Control::KeyboardFocus::DOWN:
363 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
370 // If the focusable property is set then determine next focusable actor
371 if( index != Property::INVALID_INDEX)
373 value = currentFocusActor.GetProperty( index );
374 actorId = value.Get<int>();
376 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
379 if( currentFocusActor.GetParent() )
381 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
384 if( !nextFocusableActor )
386 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
392 if( !nextFocusableActor )
394 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
395 if( mCustomAlgorithmInterface )
397 mIsWaitingKeyboardFocusChangeCommit = true;
398 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
399 mIsWaitingKeyboardFocusChangeCommit = false;
401 else if( !mPreFocusChangeSignal.Empty() )
403 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
404 mIsWaitingKeyboardFocusChangeCommit = true;
405 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
406 mIsWaitingKeyboardFocusChangeCommit = false;
410 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
412 // Whether the next focusable actor is a layout control
413 if( IsLayoutControl( nextFocusableActor ) )
415 // If so, move the focus inside it.
416 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
417 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
421 // Otherwise, just set focus to the next focusable actor
422 succeed = SetCurrentFocusActor( nextFocusableActor );
430 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
432 // Ask the control for the next actor to focus
433 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
434 if(nextFocusableActor)
436 if(!nextFocusableActor.IsKeyboardFocusable())
438 // If the actor is not focusable, ask the same layout control for the next actor to focus
439 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
443 Actor currentFocusActor = GetCurrentFocusActor();
444 Actor committedFocusActor = nextFocusableActor;
446 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
447 // Signal handler can check the proposed actor and return a different actor if it wishes.
448 if( !mPreFocusChangeSignal.Empty() )
450 mIsWaitingKeyboardFocusChangeCommit = true;
451 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
452 mIsWaitingKeyboardFocusChangeCommit = false;
455 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
457 // Whether the commited focusable actor is a layout control
458 if(IsLayoutControl(committedFocusActor))
460 // If so, move the focus inside it.
461 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
462 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
466 // Otherwise, just set focus to the next focusable actor
467 if(committedFocusActor == nextFocusableActor)
469 // If the application hasn't changed our proposed actor, we informs the layout control we will
470 // move the focus to what the control returns. The control might wish to perform some actions
471 // before the focus is actually moved.
472 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
475 return SetCurrentFocusActor(committedFocusActor);
486 // No more actor can be focused in the given direction within the same layout control.
491 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
493 bool succeed = false;
495 // Get the parent layout control of the current focus group
496 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
498 while(parentLayoutControl && !succeed)
500 // If the current focus group has a parent layout control, we can probably automatically
501 // move the focus to the next focus group in the forward or backward direction.
502 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
503 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
504 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
507 if(!mFocusGroupChangedSignal.Empty())
509 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
510 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
516 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
520 Toolkit::Control control = Toolkit::Control::DownCast( actor );
523 // Notify the control that enter has been pressed on it.
524 GetImplementation( control ).KeyboardEnter();
527 // Send a notification for the actor.
528 if( !mFocusedActorEnterKeySignal.Empty() )
530 mFocusedActorEnterKeySignal.Emit( actor );
535 void KeyboardFocusManager::ClearFocus()
537 Actor actor = GetCurrentFocusActor();
540 if( mFocusIndicatorActor )
542 actor.Remove( mFocusIndicatorActor );
545 // Send notification for the change of focus actor
546 if( !mFocusChangedSignal.Empty() )
548 mFocusChangedSignal.Emit( actor, Actor() );
551 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
552 if( currentlyFocusedControl )
554 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
555 currentlyFocusedControl.ClearKeyInputFocus();
559 mCurrentFocusActor.Reset();
560 mIsFocusIndicatorShown = static_cast<int>(mAlwaysShowIndicator);
563 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
565 mFocusGroupLoopEnabled = enabled;
568 bool KeyboardFocusManager::GetFocusGroupLoop() const
570 return mFocusGroupLoopEnabled;
573 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
577 // Create/Set focus group property.
578 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
582 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
584 // Check whether the actor is a focus group
585 bool isFocusGroup = false;
589 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
590 if(propertyIsFocusGroup != Property::INVALID_INDEX)
592 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
599 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
601 // Go through the actor's hierarchy to check which focus group the actor belongs to
602 while (actor && !IsFocusGroup(actor))
604 actor = actor.GetParent();
610 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
612 if(mFocusIndicatorActor != indicator)
614 Actor currentFocusActor = GetCurrentFocusActor();
615 if(currentFocusActor)
617 // The new focus indicator should be added to the current focused actor immediately
618 if(mFocusIndicatorActor)
620 currentFocusActor.Remove(mFocusIndicatorActor);
625 currentFocusActor.Add(indicator);
629 mFocusIndicatorActor = indicator;
633 Actor KeyboardFocusManager::GetFocusIndicatorActor()
635 if( ! mFocusIndicatorActor )
637 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
638 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
640 // Apply size constraint to the focus indicator
641 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
644 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
645 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
646 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
648 return mFocusIndicatorActor;
651 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
653 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
654 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
656 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
658 std::string keyName = event.keyPressedName;
660 if( mIsFocusIndicatorShown == -1 )
662 GetConfigurationFromStyleManger();
665 bool isFocusStartableKey = false;
667 if(event.state == KeyEvent::Down)
669 if (keyName == "Left")
671 if(!isAccessibilityEnabled)
673 if(!mIsFocusIndicatorShown)
675 // Show focus indicator
676 mIsFocusIndicatorShown = 1;
680 // Move the focus towards left
681 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
684 isFocusStartableKey = true;
688 // Move the accessibility focus backward
689 accessibilityManager.MoveFocusBackward();
692 else if (keyName == "Right")
694 if(!isAccessibilityEnabled)
696 if(!mIsFocusIndicatorShown)
698 // Show focus indicator
699 mIsFocusIndicatorShown = 1;
703 // Move the focus towards right
704 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
709 // Move the accessibility focus forward
710 accessibilityManager.MoveFocusForward();
713 isFocusStartableKey = true;
715 else if (keyName == "Up" && !isAccessibilityEnabled)
717 if(!mIsFocusIndicatorShown)
719 // Show focus indicator
720 mIsFocusIndicatorShown = 1;
724 // Move the focus towards up
725 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
728 isFocusStartableKey = true;
730 else if (keyName == "Down" && !isAccessibilityEnabled)
732 if(!mIsFocusIndicatorShown)
734 // Show focus indicator
735 mIsFocusIndicatorShown = 1;
739 // Move the focus towards down
740 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
743 isFocusStartableKey = true;
745 else if (keyName == "Prior" && !isAccessibilityEnabled)
747 if(!mIsFocusIndicatorShown)
749 // Show focus indicator
750 mIsFocusIndicatorShown = 1;
754 // Move the focus towards the previous page
755 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
758 isFocusStartableKey = true;
760 else if (keyName == "Next" && !isAccessibilityEnabled)
762 if(!mIsFocusIndicatorShown)
764 // Show focus indicator
765 mIsFocusIndicatorShown = 1;
769 // Move the focus towards the next page
770 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
773 isFocusStartableKey = true;
775 else if (keyName == "Tab" && !isAccessibilityEnabled)
777 if(!mIsFocusIndicatorShown)
779 // Show focus indicator
780 mIsFocusIndicatorShown = 1;
784 // "Tab" key changes the focus group in the forward direction and
785 // "Shift-Tab" key changes it in the backward direction.
786 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
789 isFocusStartableKey = true;
791 else if (keyName == "space" && !isAccessibilityEnabled)
793 if(!mIsFocusIndicatorShown)
795 // Show focus indicator
796 mIsFocusIndicatorShown = 1;
799 isFocusStartableKey = true;
801 else if (keyName == "" && !isAccessibilityEnabled)
803 // Check the fake key event for evas-plugin case
804 if(!mIsFocusIndicatorShown)
806 // Show focus indicator
807 mIsFocusIndicatorShown = 1;
810 isFocusStartableKey = true;
812 else if (keyName == "Backspace" && !isAccessibilityEnabled)
814 // Emit signal to go back to the previous view???
816 else if (keyName == "Escape" && !isAccessibilityEnabled)
820 else if(event.state == KeyEvent::Up)
822 if (keyName == "Return")
824 if(!mIsFocusIndicatorShown && !isAccessibilityEnabled)
826 // Show focus indicator
827 mIsFocusIndicatorShown = 1;
831 // The focused actor has enter pressed on it
833 if( !isAccessibilityEnabled )
835 actor = GetCurrentFocusActor();
839 actor = accessibilityManager.GetCurrentFocusActor();
844 DoKeyboardEnter( actor );
848 isFocusStartableKey = true;
852 if(isFocusStartableKey && mIsFocusIndicatorShown && !isAccessibilityEnabled)
854 Actor actor = GetCurrentFocusActor();
857 if( mEnableFocusIndicator )
859 // Make sure the focused actor is highlighted
860 actor.Add( GetFocusIndicatorActor() );
865 // No actor is focused but keyboard focus is activated by the key press
866 // Let's try to move the initial focus
867 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
872 void KeyboardFocusManager::OnTouch(const TouchData& touch)
874 // if mIsFocusIndicatorShown is -1, it means Configuration is not loaded.
875 // Try to load configuration.
876 if( mIsFocusIndicatorShown == -1 )
878 GetConfigurationFromStyleManger();
881 // Clear the focus when user touch the screen.
882 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
883 // If mClearFocusOnTouch is false, do not clear the focus even if user touch the screen.
884 if( (( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN )) && mClearFocusOnTouch )
890 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
892 return mPreFocusChangeSignal;
895 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
897 return mFocusChangedSignal;
900 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
902 return mFocusGroupChangedSignal;
905 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
907 return mFocusedActorEnterKeySignal;
910 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
912 Dali::BaseHandle handle( object );
914 bool connected( true );
915 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
917 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
919 manager->PreFocusChangeSignal().Connect( tracker, functor );
921 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
923 manager->FocusChangedSignal().Connect( tracker, functor );
925 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
927 manager->FocusGroupChangedSignal().Connect( tracker, functor );
929 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
931 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
935 // signalName does not match any signal
942 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
944 mCustomAlgorithmInterface = &interface;
947 void KeyboardFocusManager::EnableFocusIndicator(bool enable)
949 if( !enable && mFocusIndicatorActor )
951 mFocusIndicatorActor.Unparent();
954 mEnableFocusIndicator = enable;
957 bool KeyboardFocusManager::IsFocusIndicatorEnabled() const
959 return mEnableFocusIndicator;
962 } // namespace Internal
964 } // namespace Toolkit