Merge "Updated test cases for increased coverage" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyboard-focus-manager-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "keyboard-focus-manager-impl.h"
20
21 // EXTERNAL INCLUDES
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/object/type-registry.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/public-api/images/resource-image.h>
32 #include <dali/integration-api/debug.h>
33
34 // INTERNAL INCLUDES
35 #include <dali-toolkit/public-api/controls/control.h>
36 #include <dali-toolkit/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
38 #include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
39 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
40
41 namespace Dali
42 {
43
44 namespace Toolkit
45 {
46
47 namespace Internal
48 {
49
50 namespace // Unnamed namespace
51 {
52
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_KEYBOARD_FOCUS_MANAGER");
55 #endif
56
57 const char* const IS_FOCUS_GROUP_PROPERTY_NAME = "isKeyboardFocusGroup"; // This property will be replaced by a flag in Control.
58
59 const char* const FOCUS_BORDER_IMAGE_PATH = DALI_IMAGE_DIR "keyboard_focus.9.png";
60
61 BaseHandle Create()
62 {
63   BaseHandle handle = KeyboardFocusManager::Get();
64
65   if ( !handle )
66   {
67     SingletonService singletonService( SingletonService::Get() );
68     if ( singletonService )
69     {
70       Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
71       singletonService.Register( typeid( manager ), manager );
72       handle = manager;
73     }
74   }
75
76   return handle;
77 }
78
79 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::KeyboardFocusManager, Dali::BaseHandle, Create, true )
80
81 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardPreFocusChange",           SIGNAL_PRE_FOCUS_CHANGE )
82 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusChanged",             SIGNAL_FOCUS_CHANGED )
83 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusGroupChanged",        SIGNAL_FOCUS_GROUP_CHANGED )
84 DALI_SIGNAL_REGISTRATION( Toolkit, KeyboardFocusManager, "keyboardFocusedActorEnterKey",     SIGNAL_FOCUSED_ACTOR_ENTER_KEY )
85
86 DALI_TYPE_REGISTRATION_END()
87
88 } // unnamed namespace
89
90 Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
91 {
92   Toolkit::KeyboardFocusManager manager;
93
94   SingletonService singletonService( SingletonService::Get() );
95   if ( singletonService )
96   {
97     // Check whether the keyboard focus manager is already created
98     Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
99     if(handle)
100     {
101       // If so, downcast the handle of singleton to keyboard focus manager
102       manager = Toolkit::KeyboardFocusManager( dynamic_cast< KeyboardFocusManager* >( handle.GetObjectPtr() ) );
103     }
104   }
105
106   return manager;
107 }
108
109 KeyboardFocusManager::KeyboardFocusManager()
110 : mCurrentFocusActor(0),
111   mFocusIndicatorActor(Actor()),
112   mFocusGroupLoopEnabled(false),
113   mIsKeyboardFocusEnabled(false),
114   mIsFocusIndicatorEnabled(false),
115   mIsWaitingKeyboardFocusChangeCommit(false),
116   mSlotDelegate(this)
117 {
118   CreateDefaultFocusIndicatorActor();
119
120   OnPhysicalKeyboardStatusChanged(PhysicalKeyboard::Get());
121
122   Toolkit::KeyInputFocusManager::Get().UnhandledKeyEventSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnKeyEvent);
123   Stage::GetCurrent().TouchedSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnTouched);
124   PhysicalKeyboard::Get().StatusChangedSignal().Connect(mSlotDelegate, &KeyboardFocusManager::OnPhysicalKeyboardStatusChanged);
125 }
126
127 KeyboardFocusManager::~KeyboardFocusManager()
128 {
129 }
130
131 bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor )
132 {
133   DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" );
134
135   if( actor )
136   {
137     return DoSetCurrentFocusActor( actor.GetId() );
138   }
139
140   return false;
141 }
142
143 bool KeyboardFocusManager::DoSetCurrentFocusActor( const unsigned int actorID )
144 {
145   Actor rootActor = Stage::GetCurrent().GetRootLayer();
146   Actor actor = rootActor.FindChildById( actorID );
147   bool success = false;
148
149   // Check whether the actor is in the stage and is keyboard focusable.
150   if( actor && actor.IsKeyboardFocusable() )
151   {
152     mIsFocusIndicatorEnabled = true;
153     // Draw the focus indicator upon the focused actor
154     if( mFocusIndicatorActor )
155     {
156       actor.Add( mFocusIndicatorActor );
157     }
158
159     // Send notification for the change of focus actor
160     if( !mFocusChangedSignal.Empty() )
161     {
162       mFocusChangedSignal.Emit(GetCurrentFocusActor(), actor);
163     }
164
165     DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] Focus Changed\n", __FUNCTION__, __LINE__);
166
167     // Save the current focused actor
168     mCurrentFocusActor = actorID;
169
170     DALI_LOG_INFO( gLogFilter, Debug::General, "[%s:%d] SUCCEED\n", __FUNCTION__, __LINE__);
171     success = true;
172   }
173   else
174   {
175     DALI_LOG_WARNING("[%s:%d] FAILED\n", __FUNCTION__, __LINE__);
176   }
177
178   return success;
179 }
180
181 Actor KeyboardFocusManager::GetCurrentFocusActor()
182 {
183   Actor rootActor = Stage::GetCurrent().GetRootLayer();
184   return rootActor.FindChildById(mCurrentFocusActor);
185 }
186
187 Actor KeyboardFocusManager::GetCurrentFocusGroup()
188 {
189   return GetFocusGroup(GetCurrentFocusActor());
190 }
191
192 bool KeyboardFocusManager::IsLayoutControl(Actor actor) const
193 {
194   Toolkit::Control control = Toolkit::Control::DownCast(actor);
195   return control && GetImplementation( control ).IsKeyboardNavigationSupported();
196 }
197
198 Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
199 {
200   // Get the actor's parent layout control that supports two dimensional keyboard navigation
201   Actor rootActor = Stage::GetCurrent().GetRootLayer();
202   Actor parent;
203   if(actor)
204   {
205     parent = actor.GetParent();
206   }
207
208   while( parent && !IsLayoutControl(parent) && parent != rootActor )
209   {
210     parent = parent.GetParent();
211   }
212
213   return Toolkit::Control::DownCast(parent);
214 }
215
216 bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction)
217 {
218   Actor currentFocusActor = GetCurrentFocusActor();
219
220   bool succeed = false;
221
222   // Go through the actor's hierarchy until we find a layout control that knows how to move the focus
223   Toolkit::Control parentLayoutControl = GetParentLayoutControl(currentFocusActor);
224   while(parentLayoutControl && !succeed)
225   {
226     succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, currentFocusActor, direction);
227     parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
228   }
229
230   if(!succeed && !mPreFocusChangeSignal.Empty())
231   {
232     // Don't know how to move the focus further. The application needs to tell us which actor to move the focus to
233     mIsWaitingKeyboardFocusChangeCommit = true;
234     Actor nextFocusableActor = mPreFocusChangeSignal.Emit(currentFocusActor, Actor(), direction);
235     mIsWaitingKeyboardFocusChangeCommit = false;
236
237     if ( nextFocusableActor && nextFocusableActor.IsKeyboardFocusable() )
238     {
239       // Whether the next focusable actor is a layout control
240       if(IsLayoutControl(nextFocusableActor))
241       {
242         // If so, move the focus inside it.
243         Toolkit::Control layoutControl = Toolkit::Control::DownCast(nextFocusableActor);
244         succeed = DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
245       }
246       else
247       {
248         // Otherwise, just set focus to the next focusable actor
249         succeed = SetCurrentFocusActor(nextFocusableActor);
250       }
251     }
252   }
253
254   return succeed;
255 }
256
257 bool KeyboardFocusManager::DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction)
258 {
259   // Ask the control for the next actor to focus
260   Actor nextFocusableActor = GetImplementation( control ).GetNextKeyboardFocusableActor(actor, direction, mFocusGroupLoopEnabled);
261   if(nextFocusableActor)
262   {
263     if(!nextFocusableActor.IsKeyboardFocusable())
264     {
265       // If the actor is not focusable, ask the same layout control for the next actor to focus
266       return DoMoveFocusWithinLayoutControl(control, nextFocusableActor, direction);
267     }
268     else
269     {
270       Actor currentFocusActor = GetCurrentFocusActor();
271       Actor committedFocusActor = nextFocusableActor;
272
273       // We will try to move the focus to the actor. Emit a signal to notify the proposed actor to focus
274       // Signal handler can check the proposed actor and return a different actor if it wishes.
275       if( !mPreFocusChangeSignal.Empty() )
276       {
277         mIsWaitingKeyboardFocusChangeCommit = true;
278         committedFocusActor = mPreFocusChangeSignal.Emit(currentFocusActor, nextFocusableActor, direction);
279         mIsWaitingKeyboardFocusChangeCommit = false;
280       }
281
282       if (committedFocusActor && committedFocusActor.IsKeyboardFocusable())
283       {
284         // Whether the commited focusable actor is a layout control
285         if(IsLayoutControl(committedFocusActor))
286         {
287           // If so, move the focus inside it.
288           Toolkit::Control layoutControl = Toolkit::Control::DownCast(committedFocusActor);
289           return DoMoveFocusWithinLayoutControl(layoutControl, currentFocusActor, direction);
290         }
291         else
292         {
293           // Otherwise, just set focus to the next focusable actor
294           if(committedFocusActor == nextFocusableActor)
295           {
296             // If the application hasn't changed our proposed actor, we informs the layout control we will
297             // move the focus to what the control returns. The control might wish to perform some actions
298             // before the focus is actually moved.
299             GetImplementation( control ).OnKeyboardFocusChangeCommitted( committedFocusActor );
300           }
301
302           return SetCurrentFocusActor(committedFocusActor);
303         }
304       }
305       else
306       {
307         return false;
308       }
309     }
310   }
311   else
312   {
313     // No more actor can be focused in the given direction within the same layout control.
314     return false;
315   }
316 }
317
318 bool KeyboardFocusManager::DoMoveFocusToNextFocusGroup(bool forward)
319 {
320   bool succeed = false;
321
322   // Get the parent layout control of the current focus group
323   Toolkit::Control parentLayoutControl = GetParentLayoutControl(GetCurrentFocusGroup());
324
325   while(parentLayoutControl && !succeed)
326   {
327     // If the current focus group has a parent layout control, we can probably automatically
328     // move the focus to the next focus group in the forward or backward direction.
329     Toolkit::Control::KeyboardFocus::Direction direction = forward ? Toolkit::Control::KeyboardFocus::RIGHT : Toolkit::Control::KeyboardFocus::LEFT;
330     succeed = DoMoveFocusWithinLayoutControl(parentLayoutControl, GetCurrentFocusActor(), direction);
331     parentLayoutControl = GetParentLayoutControl(parentLayoutControl);
332   }
333
334   if(!mFocusGroupChangedSignal.Empty())
335   {
336     // Emit a focus group changed signal. The applicaton can move the focus to a new focus group
337     mFocusGroupChangedSignal.Emit(GetCurrentFocusActor(), forward);
338   }
339
340   return succeed;
341 }
342
343 void KeyboardFocusManager::DoKeyboardEnter(Actor actor)
344 {
345   if( actor )
346   {
347     Toolkit::Control control = Toolkit::Control::DownCast( actor );
348     if( control )
349     {
350       // Notify the control that enter has been pressed on it.
351       GetImplementation( control ).KeyboardEnter();
352     }
353
354     // Send a notification for the actor.
355     if( !mFocusedActorEnterKeySignal.Empty() )
356     {
357       mFocusedActorEnterKeySignal.Emit( actor );
358     }
359   }
360 }
361
362 void KeyboardFocusManager::ClearFocus()
363 {
364   Actor actor = GetCurrentFocusActor();
365   if(actor)
366   {
367     if(mFocusIndicatorActor)
368     {
369       actor.Remove(mFocusIndicatorActor);
370     }
371
372     // Send notification for the change of focus actor
373     if( !mFocusChangedSignal.Empty() )
374     {
375       mFocusChangedSignal.Emit(actor, Actor());
376     }
377   }
378
379   mCurrentFocusActor = 0;
380   mIsFocusIndicatorEnabled = false;
381 }
382
383 void KeyboardFocusManager::SetFocusGroupLoop(bool enabled)
384 {
385   mFocusGroupLoopEnabled = enabled;
386 }
387
388 bool KeyboardFocusManager::GetFocusGroupLoop() const
389 {
390   return mFocusGroupLoopEnabled;
391 }
392
393 void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup)
394 {
395   if(actor)
396   {
397     // Create/Set focus group property.
398     actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE );
399   }
400 }
401
402 bool KeyboardFocusManager::IsFocusGroup(Actor actor) const
403 {
404   // Check whether the actor is a focus group
405   bool isFocusGroup = false;
406
407   if(actor)
408   {
409     Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME);
410     if(propertyIsFocusGroup != Property::INVALID_INDEX)
411     {
412       isFocusGroup = actor.GetProperty<bool>(propertyIsFocusGroup);
413     }
414   }
415
416   return isFocusGroup;
417 }
418
419 Actor KeyboardFocusManager::GetFocusGroup(Actor actor)
420 {
421   // Go through the actor's hierarchy to check which focus group the actor belongs to
422   while (actor && !IsFocusGroup(actor))
423   {
424     actor = actor.GetParent();
425   }
426
427   return actor;
428 }
429
430 void KeyboardFocusManager::SetFocusIndicatorActor(Actor indicator)
431 {
432   if(mFocusIndicatorActor != indicator)
433   {
434     Actor currentFocusActor = GetCurrentFocusActor();
435     if(currentFocusActor)
436     {
437       // The new focus indicator should be added to the current focused actor immediately
438       if(mFocusIndicatorActor)
439       {
440         currentFocusActor.Remove(mFocusIndicatorActor);
441       }
442
443       if(indicator)
444       {
445         currentFocusActor.Add(indicator);
446       }
447     }
448
449     mFocusIndicatorActor = indicator;
450   }
451 }
452
453 Actor KeyboardFocusManager::GetFocusIndicatorActor()
454 {
455   return mFocusIndicatorActor;
456 }
457
458 void KeyboardFocusManager::CreateDefaultFocusIndicatorActor()
459 {
460   // Create a focus indicator actor shared by all the keyboard focusable actors
461   Toolkit::ImageView focusIndicator = Toolkit::ImageView::New(FOCUS_BORDER_IMAGE_PATH);
462   focusIndicator.SetParentOrigin( ParentOrigin::CENTER );
463
464   // Apply size constraint to the focus indicator
465   focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
466
467   SetFocusIndicatorActor(focusIndicator);
468 }
469
470 void KeyboardFocusManager::OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyboard)
471 {
472   mIsKeyboardFocusEnabled = keyboard.IsAttached();
473
474   if(mIsKeyboardFocusEnabled)
475   {
476     // Show indicator when keyboard focus turned on if there is focused actor.
477     Actor actor = GetCurrentFocusActor();
478     if(actor)
479     {
480       if(mFocusIndicatorActor)
481       {
482         actor.Add(mFocusIndicatorActor);
483       }
484     }
485     mIsFocusIndicatorEnabled = true;
486   }
487   else
488   {
489     // Hide indicator when keyboard focus turned off
490     Actor actor = GetCurrentFocusActor();
491     if(actor)
492     {
493       actor.Remove(mFocusIndicatorActor);
494     }
495     mIsFocusIndicatorEnabled = false;
496   }
497 }
498
499 void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event)
500 {
501   if(!mIsKeyboardFocusEnabled)
502   {
503     return;
504   }
505
506   AccessibilityAdaptor accessibilityAdaptor = AccessibilityAdaptor::Get();
507   bool isAccessibilityEnabled = accessibilityAdaptor.IsEnabled();
508
509   Toolkit::AccessibilityManager accessibilityManager = Toolkit::AccessibilityManager::Get();
510
511   std::string keyName = event.keyPressedName;
512
513   bool isFocusStartableKey = false;
514
515   if(event.state == KeyEvent::Down)
516   {
517     if (keyName == "Left")
518     {
519       if(!isAccessibilityEnabled)
520       {
521         if(!mIsFocusIndicatorEnabled)
522         {
523           // Show focus indicator
524           mIsFocusIndicatorEnabled = true;
525         }
526         else
527         {
528           // Move the focus towards left
529           MoveFocus(Toolkit::Control::KeyboardFocus::LEFT);
530         }
531
532         isFocusStartableKey = true;
533       }
534       else
535       {
536         // Move the accessibility focus backward
537         accessibilityManager.MoveFocusBackward();
538       }
539     }
540     else if (keyName == "Right")
541     {
542       if(!isAccessibilityEnabled)
543       {
544         if(!mIsFocusIndicatorEnabled)
545         {
546           // Show focus indicator
547           mIsFocusIndicatorEnabled = true;
548         }
549         else
550         {
551           // Move the focus towards right
552           MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
553         }
554       }
555       else
556       {
557         // Move the accessibility focus forward
558         accessibilityManager.MoveFocusForward();
559       }
560
561       isFocusStartableKey = true;
562     }
563     else if (keyName == "Up" && !isAccessibilityEnabled)
564     {
565       if(!mIsFocusIndicatorEnabled)
566       {
567         // Show focus indicator
568         mIsFocusIndicatorEnabled = true;
569       }
570       else
571       {
572         // Move the focus towards up
573         MoveFocus(Toolkit::Control::KeyboardFocus::UP);
574       }
575
576       isFocusStartableKey = true;
577     }
578     else if (keyName == "Down" && !isAccessibilityEnabled)
579     {
580       if(!mIsFocusIndicatorEnabled)
581       {
582         // Show focus indicator
583         mIsFocusIndicatorEnabled = true;
584       }
585       else
586       {
587         // Move the focus towards down
588         MoveFocus(Toolkit::Control::KeyboardFocus::DOWN);
589       }
590
591       isFocusStartableKey = true;
592     }
593     else if (keyName == "Tab" && !isAccessibilityEnabled)
594     {
595       if(!mIsFocusIndicatorEnabled)
596       {
597         // Show focus indicator
598         mIsFocusIndicatorEnabled = true;
599       }
600       else
601       {
602         // "Tab" key changes the focus group in the forward direction and
603         // "Shift-Tab" key changes it in the backward direction.
604         DoMoveFocusToNextFocusGroup(!event.IsShiftModifier());
605       }
606
607       isFocusStartableKey = true;
608     }
609     else if (keyName == "space" && !isAccessibilityEnabled)
610     {
611       if(!mIsFocusIndicatorEnabled)
612       {
613         // Show focus indicator
614         mIsFocusIndicatorEnabled = true;
615       }
616
617       isFocusStartableKey = true;
618     }
619     else if (keyName == "" && !isAccessibilityEnabled)
620     {
621       // Check the fake key event for evas-plugin case
622       if(!mIsFocusIndicatorEnabled)
623       {
624         // Show focus indicator
625         mIsFocusIndicatorEnabled = true;
626       }
627
628       isFocusStartableKey = true;
629     }
630     else if (keyName == "Backspace" && !isAccessibilityEnabled)
631     {
632       // Emit signal to go back to the previous view???
633     }
634   }
635   else if(event.state == KeyEvent::Up)
636   {
637     if (keyName == "Return")
638     {
639       if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
640       {
641         // Show focus indicator
642         mIsFocusIndicatorEnabled = true;
643       }
644       else
645       {
646         // The focused actor has enter pressed on it
647         Actor actor;
648         if( !isAccessibilityEnabled )
649         {
650           actor = GetCurrentFocusActor();
651         }
652         else
653         {
654           actor = accessibilityManager.GetCurrentFocusActor();
655         }
656
657         if( actor )
658         {
659           DoKeyboardEnter( actor );
660         }
661       }
662
663       isFocusStartableKey = true;
664     }
665   }
666
667   if(isFocusStartableKey && mIsFocusIndicatorEnabled && !isAccessibilityEnabled)
668   {
669     Actor actor = GetCurrentFocusActor();
670     if( !actor )
671     {
672       // No actor is focused but keyboard focus is activated by the key press
673       // Let's try to move the initial focus
674       MoveFocus(Toolkit::Control::KeyboardFocus::RIGHT);
675     }
676     else if(mFocusIndicatorActor)
677     {
678       // Make sure the focused actor is highlighted
679       actor.Add(mFocusIndicatorActor);
680     }
681   }
682 }
683
684 void KeyboardFocusManager::OnTouched(const TouchEvent& touchEvent)
685 {
686   // Clear the focus when user touch the screen.
687   // We only do this on a Down event, otherwise the clear action may override a manually focused actor.
688   if( ( touchEvent.GetPointCount() < 1 ) || ( touchEvent.GetPoint( 0 ).state == TouchPoint::Down ) )
689   {
690     ClearFocus();
691   }
692 }
693
694 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& KeyboardFocusManager::PreFocusChangeSignal()
695 {
696   return mPreFocusChangeSignal;
697 }
698
699 Toolkit::KeyboardFocusManager::FocusChangedSignalType& KeyboardFocusManager::FocusChangedSignal()
700 {
701   return mFocusChangedSignal;
702 }
703
704 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& KeyboardFocusManager::FocusGroupChangedSignal()
705 {
706   return mFocusGroupChangedSignal;
707 }
708
709 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& KeyboardFocusManager::FocusedActorEnterKeySignal()
710 {
711   return mFocusedActorEnterKeySignal;
712 }
713
714 bool KeyboardFocusManager::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
715 {
716   Dali::BaseHandle handle( object );
717
718   bool connected( true );
719   KeyboardFocusManager* manager = dynamic_cast<KeyboardFocusManager*>( object );
720
721   if( 0 == strcmp( signalName.c_str(), SIGNAL_PRE_FOCUS_CHANGE ) )
722   {
723     manager->PreFocusChangeSignal().Connect( tracker, functor );
724   }
725   if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_CHANGED ) )
726   {
727     manager->FocusChangedSignal().Connect( tracker, functor );
728   }
729   if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUS_GROUP_CHANGED ) )
730   {
731     manager->FocusGroupChangedSignal().Connect( tracker, functor );
732   }
733   else if( 0 == strcmp( signalName.c_str(), SIGNAL_FOCUSED_ACTOR_ENTER_KEY ) )
734   {
735     manager->FocusedActorEnterKeySignal().Connect( tracker, functor );
736   }
737   else
738   {
739     // signalName does not match any signal
740     connected = false;
741   }
742
743   return connected;
744 }
745
746 } // namespace Internal
747
748 } // namespace Toolkit
749
750 } // namespace Dali