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