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/images/resource-image.h>
33 #include <dali/integration-api/debug.h>
36 #include <dali-toolkit/public-api/controls/control.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
39 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
40 #include <dali-toolkit/devel-api/controls/control-devel.h>
51 namespace // Unnamed namespace
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
58 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
60 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
64 BaseHandle handle = KeyboardFocusManager::Get();
68 SingletonService singletonService( SingletonService::Get() );
69 if ( singletonService )
71 Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
72 singletonService.Register( typeid( manager ), manager );
80 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
82 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange", SIGNAL_PRE_FOCUS_CHANGE )
83 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged", SIGNAL_FOCUS_CHANGED )
84 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged", SIGNAL_FOCUS_GROUP_CHANGED )
85 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey", SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
87 DALI_TYPE_REGISTRATION_END()
89 const unsigned int MAX_HISTORY_AMOUNT = 30; ///< Max length of focus history stack
91 } // unnamed namespace
93 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
95 Toolkit::KeyboardFocusManager manager;
97 SingletonService singletonService( SingletonService::Get() );
98 if ( singletonService )
100 // Check whether the keyboard focus manager is already created
101 Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
104 // If so, downcast the handle of singleton to keyboard focus manager
105 manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
112 KeyboardFocusManager::KeyboardFocusManager()
113 : mPreFocusChangeSignal(),
114 mFocusChangedSignal(),
115 mFocusGroupChangedSignal(),
116 mFocusedActorEnterKeySignal(),
117 mCurrentFocusActor( 0 ),
118 mFocusIndicatorActor(),
119 mFocusGroupLoopEnabled( false ),
120 mIsFocusIndicatorEnabled( false ),
121 mIsWaitingKeyboardFocusChangeCommit( false ),
123 mSlotDelegate( this ),
124 mCustomAlgorithmInterface(NULL)
126 // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorEnabled.
127 Stage::GetCurrent().KeyEventSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
128 Stage::GetCurrent().TouchSignal().Connect( mSlotDelegate, &KeyboardFocusManager::OnTouch );
131 KeyboardFocusManager::~KeyboardFocusManager()
135 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
137 DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
139 return DoSetCurrentFocusActor( actor );
142 bool KeyboardFocusManager::DoSetCurrentFocusActor( Actor actor )
144 bool success = false;
146 // Check whether the actor is in the stage and is keyboard focusable.
147 if( actor && actor.IsKeyboardFocusable() )
149 if( mIsFocusIndicatorEnabled )
151 actor.Add( GetFocusIndicatorActor() );
153 // Send notification for the change of focus actor
154 Actor currentFocusedActor = GetCurrentFocusActor();
156 if( !mFocusChangedSignal.Empty() )
158 mFocusChangedSignal.Emit(currentFocusedActor, actor);
161 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor);
162 if( currentlyFocusedControl )
164 // Do we need it to remember if it was previously DISABLED?
165 currentlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL );
166 currentlyFocusedControl.ClearKeyInputFocus();
169 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
171 // Save the current focused actor
172 mCurrentFocusActor = actor.GetId();
174 Toolkit::Control newlyFocusedControl = Toolkit::Control::DownCast(actor);
175 if( newlyFocusedControl )
177 newlyFocusedControl.SetProperty(DevelControl::Property::STATE, DevelControl::FOCUSED );
178 newlyFocusedControl.SetKeyInputFocus();
181 // Push Current Focused Actor to FocusHistory
182 mFocusHistory.PushBack( &actor.GetBaseObject() );
184 // Delete first element before add new element when Stack is full.
185 if( mFocusHistory.Count() > MAX_HISTORY_AMOUNT )
187 FocusStackIterator beginPos = mFocusHistory.Begin();
188 mFocusHistory.Erase( beginPos );
191 DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
196 DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
202 Actor KeyboardFocusManager::GetCurrentFocusActor()
204 Actor rootActor = Stage::GetCurrent().GetRootLayer();
205 return rootActor.FindChildById(mCurrentFocusActor);
208 Actor KeyboardFocusManager::GetCurrentFocusGroup()
210 return GetFocusGroup(GetCurrentFocusActor());
213 void KeyboardFocusManager::MoveFocusBackward()
215 // Find Pre Focused Actor when the list size is more than 1
216 if( mFocusHistory.Count() > 1 )
218 // Delete current focused actor in history
219 FocusStackIterator endPos = mFocusHistory.End();
220 endPos = mFocusHistory.Erase( --endPos );
222 // If pre-focused actors are not on stage, remove them in stack
223 while( !Dali::Actor::DownCast(BaseHandle(mFocusHistory[ mFocusHistory.Count() - 1 ])).OnStage() )
225 endPos = mFocusHistory.Erase( --endPos );
228 // Get pre focused actor
229 BaseObject* object = mFocusHistory[ mFocusHistory.Count() - 1 ];
230 BaseHandle handle( object );
231 Actor preFocusedActor = Dali::Actor::DownCast( handle );
233 // Delete pre focused actor in history because it will pushed again by SetCurrentFocusActor()
234 mFocusHistory.Erase( --endPos );
236 SetCurrentFocusActor( preFocusedActor );
240 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
242 Toolkit::Control control = Toolkit::Control::DownCast(actor);
243 return control && GetImplementation( control ).IsKeyboardNavigationSupported();
246 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
248 // Get the actor's parent layout control that supports two dimensional keyboard navigation
249 Actor rootActor = Stage::GetCurrent().GetRootLayer();
253 parent = actor.GetParent();
256 while( parent && !IsLayoutControl(parent) && parent != rootActor )
258 parent = parent.GetParent();
261 return Toolkit::Control::DownCast(parent);
264 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
266 Actor currentFocusActor = GetCurrentFocusActor();
268 bool succeed = false;
270 // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
271 Toolkit::Control parentLayoutControl = GetParentLayoutControl( currentFocusActor );
272 while( parentLayoutControl && !succeed )
274 succeed = DoMoveFocusWithinLayoutControl( parentLayoutControl, currentFocusActor, direction );
275 parentLayoutControl = GetParentLayoutControl( parentLayoutControl );
280 Actor nextFocusableActor;
282 Toolkit::Control currentFocusControl = Toolkit::Control::DownCast(currentFocusActor);
284 // If the current focused actor is a control, then find the next focusable actor via the focusable properties.
285 if( currentFocusControl )
288 Property::Index index = Property::INVALID_INDEX;
289 Property::Value value;
291 // Find property index based upon focus direction
294 case Toolkit::Control::KeyboardFocus::LEFT:
296 index = Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
299 case Toolkit::Control::KeyboardFocus::RIGHT:
301 index = Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
304 case Toolkit::Control::KeyboardFocus::UP:
306 index = Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
309 case Toolkit::Control::KeyboardFocus::DOWN:
311 index = Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
318 // If the focusable property is set then determine next focusable actor
319 if( index != Property::INVALID_INDEX)
321 value = currentFocusActor.GetProperty( index );
322 actorId = value.Get<int>();
324 // If actor's id is valid then find actor form actor's id. The actor should be on the stage.
327 if( currentFocusActor.GetParent() )
329 nextFocusableActor = currentFocusActor.GetParent().FindChildById( actorId );
332 if( !nextFocusableActor )
334 nextFocusableActor = Stage::GetCurrent().GetRootLayer().FindChildById( actorId );
340 if( !nextFocusableActor )
342 // If the implementation of CustomAlgorithmInterface is provided then the PreFocusChangeSignal is no longer emitted.
343 if( mCustomAlgorithmInterface )
345 mIsWaitingKeyboardFocusChangeCommit = true;
346 nextFocusableActor = mCustomAlgorithmInterface->GetNextFocusableActor( currentFocusActor, Actor(), direction );
347 mIsWaitingKeyboardFocusChangeCommit = false;
349 else if( !mPreFocusChangeSignal.Empty() )
351 // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
352 mIsWaitingKeyboardFocusChangeCommit = true;
353 nextFocusableActor = mPreFocusChangeSignal.Emit( currentFocusActor, Actor(), direction );
354 mIsWaitingKeyboardFocusChangeCommit = false;
358 if( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
360 // Whether the next focusable actor is a layout control
361 if( IsLayoutControl( nextFocusableActor ) )
363 // If so, move the focus inside it.
364 Toolkit::Control layoutControl = Toolkit::Control::DownCast( nextFocusableActor) ;
365 succeed = DoMoveFocusWithinLayoutControl( layoutControl, currentFocusActor, direction );
369 // Otherwise, just set focus to the next focusable actor
370 succeed = SetCurrentFocusActor( nextFocusableActor );
378 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
380 // Ask the control for the next actor to focus
381 Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
382 if(nextFocusableActor)
384 if(!nextFocusableActor.IsKeyboardFocusable())
386 // If the actor is not focusable, ask the same layout control for the next actor to focus
387 return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
391 Actor currentFocusActor = GetCurrentFocusActor();
392 Actor committedFocusActor = nextFocusableActor;
394 // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
395 // Signal handler can check the proposed actor and return a different actor if it wishes.
396 if( !mPreFocusChangeSignal.Empty() )
398 mIsWaitingKeyboardFocusChangeCommit = true;
399 committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
400 mIsWaitingKeyboardFocusChangeCommit = false;
403 if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
405 // Whether the commited focusable actor is a layout control
406 if(IsLayoutControl(committedFocusActor))
408 // If so, move the focus inside it.
409 Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
410 return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
414 // Otherwise, just set focus to the next focusable actor
415 if(committedFocusActor == nextFocusableActor)
417 // If the application hasn't changed our proposed actor, we informs the layout control we will
418 // move the focus to what the control returns. The control might wish to perform some actions
419 // before the focus is actually moved.
420 GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
423 return SetCurrentFocusActor(committedFocusActor);
434 // No more actor can be focused in the given direction within the same layout control.
439 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
441 bool succeed = false;
443 // Get the parent layout control of the current focus group
444 Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
446 while(parentLayoutControl && !succeed)
448 // If the current focus group has a parent layout control, we can probably automatically
449 // move the focus to the next focus group in the forward or backward direction.
450 Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
451 succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
452 parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
455 if(!mFocusGroupChangedSignal.Empty())
457 // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
458 mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
464 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
468 Toolkit::Control control = Toolkit::Control::DownCast( actor );
471 // Notify the control that enter has been pressed on it.
472 GetImplementation( control ).KeyboardEnter();
475 // Send a notification for the actor.
476 if( !mFocusedActorEnterKeySignal.Empty() )
478 mFocusedActorEnterKeySignal.Emit( actor );
483 void KeyboardFocusManager::ClearFocus()
485 Actor actor = GetCurrentFocusActor();
488 if( mFocusIndicatorActor )
490 actor.Remove( mFocusIndicatorActor );
493 // Send notification for the change of focus actor
494 if( !mFocusChangedSignal.Empty() )
496 mFocusChangedSignal.Emit( actor, Actor() );
499 Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast( actor );
500 if( currentlyFocusedControl )
502 currentlyFocusedControl.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
503 currentlyFocusedControl.ClearKeyInputFocus();
507 mCurrentFocusActor = 0;
508 mIsFocusIndicatorEnabled = false;
511 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
513 mFocusGroupLoopEnabled = enabled;
516 bool KeyboardFocusManager::GetFocusGroupLoop() const
518 return mFocusGroupLoopEnabled;
521 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
525 // Create/Set focus group property.
526 actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
530 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
532 // Check whether the actor is a focus group
533 bool isFocusGroup = false;
537 Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
538 if(propertyIsFocusGroup != Property::INVALID_INDEX)
540 isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
547 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
549 // Go through the actor's hierarchy to check which focus group the actor belongs to
550 while (actor && !IsFocusGroup(actor))
552 actor = actor.GetParent();
558 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
560 if(mFocusIndicatorActor != indicator)
562 Actor currentFocusActor = GetCurrentFocusActor();
563 if(currentFocusActor)
565 // The new focus indicator should be added to the current focused actor immediately
566 if(mFocusIndicatorActor)
568 currentFocusActor.Remove(mFocusIndicatorActor);
573 currentFocusActor.Add(indicator);
577 mFocusIndicatorActor = indicator;
581 Actor KeyboardFocusManager::GetFocusIndicatorActor()
583 if( ! mFocusIndicatorActor )
585 // Create the default if it hasn't been set and one that's shared by all the keyboard focusable actors
586 mFocusIndicatorActor = Toolkit::ImageView::New( FOCUS_BORDER_IMAGE_PATH );
588 // Apply size constraint to the focus indicator
589 mFocusIndicatorActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
592 mFocusIndicatorActor.SetParentOrigin( ParentOrigin::CENTER );
593 mFocusIndicatorActor.SetAnchorPoint( AnchorPoint::CENTER );
594 mFocusIndicatorActor.SetPosition(0.0f, 0.0f);
596 return mFocusIndicatorActor;
599 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
601 AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
602 bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
604 Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
606 std::string keyName = event.keyPressedName;
608 bool isFocusStartableKey = false;
610 if(event.state == KeyEvent::Down)
612 if (keyName == "Left")
614 if(!isAccessibilityEnabled)
616 if(!mIsFocusIndicatorEnabled)
618 // Show focus indicator
619 mIsFocusIndicatorEnabled = true;
623 // Move the focus towards left
624 MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
627 isFocusStartableKey = true;
631 // Move the accessibility focus backward
632 accessibilityManager.MoveFocusBackward();
635 else if (keyName == "Right")
637 if(!isAccessibilityEnabled)
639 if(!mIsFocusIndicatorEnabled)
641 // Show focus indicator
642 mIsFocusIndicatorEnabled = true;
646 // Move the focus towards right
647 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
652 // Move the accessibility focus forward
653 accessibilityManager.MoveFocusForward();
656 isFocusStartableKey = true;
658 else if (keyName == "Up" && !isAccessibilityEnabled)
660 if(!mIsFocusIndicatorEnabled)
662 // Show focus indicator
663 mIsFocusIndicatorEnabled = true;
667 // Move the focus towards up
668 MoveFocus(Toolkit::Control::KeyboardFocus::UP);
671 isFocusStartableKey = true;
673 else if (keyName == "Down" && !isAccessibilityEnabled)
675 if(!mIsFocusIndicatorEnabled)
677 // Show focus indicator
678 mIsFocusIndicatorEnabled = true;
682 // Move the focus towards down
683 MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
686 isFocusStartableKey = true;
688 else if (keyName == "Prior" && !isAccessibilityEnabled)
690 if(!mIsFocusIndicatorEnabled)
692 // Show focus indicator
693 mIsFocusIndicatorEnabled = true;
697 // Move the focus towards the previous page
698 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_UP);
701 isFocusStartableKey = true;
703 else if (keyName == "Next" && !isAccessibilityEnabled)
705 if(!mIsFocusIndicatorEnabled)
707 // Show focus indicator
708 mIsFocusIndicatorEnabled = true;
712 // Move the focus towards the next page
713 MoveFocus(Toolkit::Control::KeyboardFocus::PAGE_DOWN);
716 isFocusStartableKey = true;
718 else if (keyName == "Tab" && !isAccessibilityEnabled)
720 if(!mIsFocusIndicatorEnabled)
722 // Show focus indicator
723 mIsFocusIndicatorEnabled = true;
727 // "Tab" key changes the focus group in the forward direction and
728 // "Shift-Tab" key changes it in the backward direction.
729 DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
732 isFocusStartableKey = true;
734 else if (keyName == "space" && !isAccessibilityEnabled)
736 if(!mIsFocusIndicatorEnabled)
738 // Show focus indicator
739 mIsFocusIndicatorEnabled = true;
742 isFocusStartableKey = true;
744 else if (keyName == "" && !isAccessibilityEnabled)
746 // Check the fake key event for evas-plugin case
747 if(!mIsFocusIndicatorEnabled)
749 // Show focus indicator
750 mIsFocusIndicatorEnabled = true;
753 isFocusStartableKey = true;
755 else if (keyName == "Backspace" && !isAccessibilityEnabled)
757 // Emit signal to go back to the previous view???
759 else if (keyName == "Escape" && !isAccessibilityEnabled)
763 else if(event.state == KeyEvent::Up)
765 if (keyName == "Return")
767 if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
769 // Show focus indicator
770 mIsFocusIndicatorEnabled = true;
774 // The focused actor has enter pressed on it
776 if( !isAccessibilityEnabled )
778 actor = GetCurrentFocusActor();
782 actor = accessibilityManager.GetCurrentFocusActor();
787 DoKeyboardEnter( actor );
791 isFocusStartableKey = true;
795 if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
797 Actor actor = GetCurrentFocusActor();
800 // Make sure the focused actor is highlighted
801 actor.Add( GetFocusIndicatorActor() );
805 // No actor is focused but keyboard focus is activated by the key press
806 // Let's try to move the initial focus
807 MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
812 void KeyboardFocusManager::OnTouch(const TouchData& touch)
814 // Clear the focus when user touch the screen.
815 // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
816 if( ( touch.GetPointCount() < 1 ) || ( touch.GetState( 0 ) == PointState::DOWN ) )
822 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
824 return mPreFocusChangeSignal;
827 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
829 return mFocusChangedSignal;
832 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
834 return mFocusGroupChangedSignal;
837 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
839 return mFocusedActorEnterKeySignal;
842 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
844 Dali::BaseHandle handle( object );
846 bool connected( true );
847 KeyboardFocusManager* manager = static_cast< KeyboardFocusManager* >( object ); // TypeRegistry guarantees that this is the correct type.
849 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
851 manager->PreFocusChangeSignal().Connect( tracker, functor );
853 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
855 manager->FocusChangedSignal().Connect( tracker, functor );
857 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
859 manager->FocusGroupChangedSignal().Connect( tracker, functor );
861 else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
863 manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
867 // signalName does not match any signal
874 void KeyboardFocusManager::SetCustomAlgorithm(CustomAlgorithmInterface& interface)
876 mCustomAlgorithmInterface = &interface;
879 } // namespace Internal
881 } // namespace Toolkit