For custom wheel events, event propagation starts from the focused actor.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-KeyboardFocusManager.cpp
1 /*
2  * Copyright (c) 2021 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 #include <iostream>
19 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali/devel-api/actors/actor-devel.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/wheel-event-integ.h>
27 #include <dali-toolkit-test-suite-utils.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
30 #include <dali-toolkit/devel-api/controls/control-devel.h>
31 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
32
33 using namespace Dali;
34 using namespace Dali::Toolkit;
35
36 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46
47 namespace
48 {
49
50 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
51
52 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
53 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
54 {
55 public:
56   CustomAlgorithm(bool& interfaceVerified)
57   : mInterfaceVerified(interfaceVerified),
58     mCurrentFocusedActor(),
59     mProposedActorToFocus(),
60     mDirection(Control::KeyboardFocus::LEFT)
61   {
62   }
63
64   Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
65   {
66     tet_infoline("Verifying CustomAlgorithm()");
67
68     mInterfaceVerified = true;
69
70     mCurrentFocusedActor = currentFocusedActor;
71     mProposedActorToFocus = proposedActorToFocus;
72     mDirection = direction;
73
74     return mProposedActorToFocus;
75   }
76
77   void Reset()
78   {
79     mInterfaceVerified = false;
80     mCurrentFocusedActor = Actor();
81     mProposedActorToFocus = Actor();
82     mDirection = Control::KeyboardFocus::LEFT;
83   }
84
85   bool& mInterfaceVerified;
86   Actor mCurrentFocusedActor;
87   Actor mProposedActorToFocus;
88   Control::KeyboardFocus::Direction mDirection;
89 };
90
91 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
92 class PreFocusChangeCallback : public Dali::ConnectionTracker
93 {
94 public:
95   PreFocusChangeCallback(bool& signalReceived)
96   : mSignalVerified(signalReceived),
97     mCurrentFocusedActor(),
98     mProposedActorToFocus(),
99     mDirection(Control::KeyboardFocus::LEFT)
100   {
101   }
102
103   Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
104   {
105     tet_infoline("Verifying PreFocusChangeCallback()");
106
107     mSignalVerified = true;
108
109     mCurrentFocusedActor = currentFocusedActor;
110     mProposedActorToFocus = proposedActorToFocus;
111     mDirection = direction;
112
113     return mProposedActorToFocus;
114   }
115
116   void Reset()
117   {
118     mSignalVerified = false;
119     mCurrentFocusedActor = Actor();
120     mProposedActorToFocus = Actor();
121     mDirection = Control::KeyboardFocus::LEFT;
122   }
123
124   bool& mSignalVerified;
125   Actor mCurrentFocusedActor;
126   Actor mProposedActorToFocus;
127   Control::KeyboardFocus::Direction mDirection;
128 };
129
130 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
131 class FocusChangedCallback : public Dali::ConnectionTracker
132 {
133 public:
134   FocusChangedCallback(bool& signalReceived)
135   : mSignalVerified(signalReceived),
136     mOriginalFocusedActor(),
137     mCurrentFocusedActor()
138   {
139   }
140
141   void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
142   {
143     tet_infoline("Verifying FocusChangedCallback()");
144
145     if(originalFocusedActor == mCurrentFocusedActor)
146     {
147       mSignalVerified = true;
148     }
149
150     mOriginalFocusedActor = originalFocusedActor;
151     mCurrentFocusedActor = currentFocusedActor;
152   }
153
154   void Reset()
155   {
156     mSignalVerified = false;
157   }
158
159   bool& mSignalVerified;
160   Actor mOriginalFocusedActor;
161   Actor mCurrentFocusedActor;
162 };
163
164 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
165 class FocusGroupChangedCallback : public Dali::ConnectionTracker
166 {
167 public:
168   FocusGroupChangedCallback(bool& signalReceived)
169   : mSignalVerified(signalReceived),
170     mCurrentFocusedActor(),
171     mForward(true)
172   {
173   }
174
175   void Callback(Actor currentFocusedActor, bool forward)
176   {
177     tet_infoline("Verifying FocusGroupChangedCallback()");
178
179     mSignalVerified = true;
180
181     mCurrentFocusedActor = currentFocusedActor;
182     mForward = forward;
183   }
184
185   void Reset()
186   {
187     mSignalVerified = false;
188   }
189
190   bool& mSignalVerified;
191   Actor mCurrentFocusedActor;
192   bool mForward;
193 };
194
195 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
196 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
197 {
198 public:
199   FocusedActorActivatedCallback(bool& signalReceived)
200   : mSignalVerified(signalReceived),
201     mActivatedActor()
202   {
203   }
204
205   void Callback(Actor activatedActor)
206   {
207     tet_infoline("Verifying FocusedActorActivatedCallback()");
208
209     mSignalVerified = true;
210
211     mActivatedActor = activatedActor;
212   }
213
214   void Reset()
215   {
216     mSignalVerified = false;
217   }
218
219   bool& mSignalVerified;
220   Actor mActivatedActor;
221 };
222
223 class KeyEventCallback : public Dali::ConnectionTracker
224 {
225 public:
226   /**
227    * Constructor
228    * @param[in]  returnValue  Set return value of KeyEvent callback.
229    * */
230   KeyEventCallback( bool consumed )
231   : mConsumed( consumed ),
232     mIsCalled( false )
233   {
234   }
235
236   bool Callback( Control control, const KeyEvent& keyEvent )
237   {
238     mIsCalled = true;
239     return mConsumed;
240   }
241
242   void Callback( const KeyEvent& keyEvent )
243   {
244     mIsCalled = true;
245   }
246
247   bool mConsumed;
248   bool mIsCalled;
249 };
250
251 class WheelEventCallback : public Dali::ConnectionTracker
252 {
253 public:
254   /**
255    * Constructor
256    * @param[in]  returnValue  Set return value of WheelEvent callback.
257    * */
258   WheelEventCallback( bool consumed )
259   : mConsumed( consumed ),
260     mIsCalled( false )
261   {
262   }
263
264   bool Callback( Actor actor, const WheelEvent& wheelEvent )
265   {
266     mIsCalled = true;
267     return mConsumed;
268   }
269
270   void Callback( const WheelEvent& wheelEvent )
271   {
272     mIsCalled = true;
273   }
274
275   bool mConsumed;
276   bool mIsCalled;
277 };
278
279 // Used to connect to signals via the ConnectSignal Handle method
280 struct CallbackFunctor
281 {
282   CallbackFunctor()
283   {
284   }
285
286   void operator()()
287   {
288   }
289 };
290
291 } // namespace
292
293 int UtcDaliKeyboardFocusManagerGet(void)
294 {
295   ToolkitTestApplication application;
296
297   tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
298
299   // Register Type
300   TypeInfo type;
301   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
302   DALI_TEST_CHECK( type );
303   BaseHandle handle = type.CreateInstance();
304   DALI_TEST_CHECK( handle );
305
306   KeyboardFocusManager manager;
307
308   manager = KeyboardFocusManager::Get();
309   DALI_TEST_CHECK(manager);
310
311   KeyboardFocusManager newManager = KeyboardFocusManager::Get();
312   DALI_TEST_CHECK(newManager);
313
314   // Check that focus manager is a singleton
315   DALI_TEST_CHECK(manager == newManager);
316   END_TEST;
317 }
318
319 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
320 {
321   ToolkitTestApplication application;
322
323   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
324
325   KeyboardFocusManager manager = KeyboardFocusManager::Get();
326   DALI_TEST_CHECK(manager);
327
328   // Create the first actor and add it to the stage
329   Actor first = Actor::New();
330   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
331   application.GetScene().Add(first);
332
333   // Create the second actor and add it to the stage
334   Actor second = Actor::New();
335   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
336   application.GetScene().Add(second);
337
338   // Create the third actor but don't add it to the stage
339   Actor third = Actor::New();
340
341   // Check that no actor is being focused yet.
342   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
343
344   // Check that it will fail to set focus on an invalid actor
345   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
346
347   // Check that the focus is set on the first actor
348   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
349   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
350
351   // Check that the focus is set on the second actor
352   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
353   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
354
355   // Check that it will fail to set focus on the third actor as it's not in the stage
356   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
357   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
358
359   // Add the third actor to the stage
360   application.GetScene().Add(third);
361
362   // Check that it will fail to set focus on the third actor as it's not focusable
363   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
364   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
365
366   // Make the third actor focusable
367   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
368
369   // Check that the focus is successfully moved to the third actor
370   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
371   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
372   END_TEST;
373 }
374
375 int UtcDaliKeyboardFocusManagerMoveFocus(void)
376 {
377   ToolkitTestApplication application;
378
379   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
380
381   // Register Type
382   TypeInfo type;
383   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
384   DALI_TEST_CHECK( type );
385   BaseHandle handle = type.CreateInstance();
386   DALI_TEST_CHECK( handle );
387
388   KeyboardFocusManager manager = KeyboardFocusManager::Get();
389   DALI_TEST_CHECK(manager);
390
391   bool preFocusChangeSignalVerified = false;
392   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
393   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
394
395   bool focusChangedSignalVerified = false;
396   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
397   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
398
399   // Create the first actor and add it to the stage
400   Actor first = Actor::New();
401   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
402   application.GetScene().Add(first);
403
404   // Create the second actor and add it to the stage
405   Actor second = Actor::New();
406   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
407   application.GetScene().Add(second);
408
409   // Move the focus to the right
410   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
411
412   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
413   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
414   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
415   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
416   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
417   preFocusChangeCallback.Reset();
418
419   // Check that the focus is set on the first actor
420   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
421   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
422   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
423   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
424   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
425   focusChangedCallback.Reset();
426
427   // Move the focus towards right
428   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
429
430   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
431   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
432   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
433   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
434   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
435   preFocusChangeCallback.Reset();
436
437   // Check that the focus is set on the second actor
438   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
439   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
440   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
441   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
442   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
443   focusChangedCallback.Reset();
444
445   // Move the focus towards up
446   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
447
448   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
449   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
450   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
451   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
452   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
453   preFocusChangeCallback.Reset();
454   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
455
456   // Create a 2x2 table view and try to move focus inside it
457   TableView tableView = TableView::New( 2, 2 );
458   application.GetScene().Add(tableView);
459
460   // Create the third actor
461   Actor third = Actor::New();
462   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
463
464   // Create the fourth actor
465   Actor fourth = Actor::New();
466   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
467
468   // Add the four children to table view
469   tableView.AddChild(first, TableView::CellPosition(0, 0));
470   tableView.AddChild(second, TableView::CellPosition(0, 1));
471   tableView.AddChild(third, TableView::CellPosition(1, 0));
472   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
473
474   // Set the focus to the first actor
475   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
476   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
477   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
478   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
479   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
480   focusChangedCallback.Reset();
481
482   // Move the focus towards right
483   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
484   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
485   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
486   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
487   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
488   focusChangedCallback.Reset();
489
490   // Move the focus towards down
491   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
492   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
493   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
494   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
495   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
496   focusChangedCallback.Reset();
497
498   // Move the focus towards left
499   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
500   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
501   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
502   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
503   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
504   focusChangedCallback.Reset();
505
506   // Move the focus towards up
507   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
508   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
509   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
510   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
511   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
512   focusChangedCallback.Reset();
513
514   // Move the focus towards left. The focus move will fail as no way to move it upwards
515   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
516   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
517   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
518   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
519   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
520   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
521   preFocusChangeCallback.Reset();
522   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
523
524   // Enable the loop
525   manager.SetFocusGroupLoop(true);
526   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
527
528   // Move the focus towards left again. The focus should move to the fourth actor.
529   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
530   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
531   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
532   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
533   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
534   focusChangedCallback.Reset();
535   END_TEST;
536 }
537
538 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
539 {
540   ToolkitTestApplication application;
541
542   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
543
544   // Register Type
545   TypeInfo type;
546   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
547   DALI_TEST_CHECK( type );
548   BaseHandle handle = type.CreateInstance();
549   DALI_TEST_CHECK( handle );
550
551   KeyboardFocusManager manager = KeyboardFocusManager::Get();
552   DALI_TEST_CHECK(manager);
553
554   bool preFocusChangeSignalVerified = false;
555   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
556   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
557
558   bool focusChangedSignalVerified = false;
559   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
560   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
561
562   // Create the first actor and add it to the stage
563   Actor first = Actor::New();
564   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
565   application.GetScene().Add(first);
566
567   // Create the second actor and add it to the stage
568   Actor second = Actor::New();
569   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
570   application.GetScene().Add(second);
571
572   // Move the focus to the right
573   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
574
575   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
576   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
577   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
578   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
579   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
580   preFocusChangeCallback.Reset();
581
582   bool customAlgorithmInterfaceVerified = false;
583   CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
584   Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
585
586   // Move the focus towards right
587   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
588
589   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
590   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
591   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
592   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
593   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
594   customAlgorithm.Reset();
595
596   // Check that the focus is set on the first actor
597   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
598   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
599   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
600   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
601   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
602   focusChangedCallback.Reset();
603
604   // Move the focus towards right
605   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
606
607   // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
608   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
609   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
610   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
611   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
612   customAlgorithm.Reset();
613
614   // Check that the focus is set on the second actor
615   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
616   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
617   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
618   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
619   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
620   focusChangedCallback.Reset();
621
622   // Move the focus towards up
623   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
624
625   // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
626   DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
627   DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
628   DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
629   DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
630   customAlgorithm.Reset();
631   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
632
633   END_TEST;
634 }
635 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
636 {
637   ToolkitTestApplication application;
638
639   tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
640
641   // Register Type
642   TypeInfo type;
643   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
644   DALI_TEST_CHECK( type );
645   BaseHandle handle = type.CreateInstance();
646   DALI_TEST_CHECK( handle );
647
648   KeyboardFocusManager manager = KeyboardFocusManager::Get();
649   DALI_TEST_CHECK(manager);
650
651   bool focusChangedSignalVerified = false;
652   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
653   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
654
655   PushButton button1 = PushButton::New();
656   PushButton button2 = PushButton::New();
657   button1.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
658   button2.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
659   application.GetScene().Add(button1);
660   application.GetScene().Add(button2);
661
662   // Set the focus to the button1
663   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
664   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
665   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
666   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
667   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
668   focusChangedCallback.Reset();
669
670   // set the navigation properties of button1
671   button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
672   button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
673   button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
674   button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
675
676   // set the navigation properties of button2
677   button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
678   button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
679   button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
680   button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
681
682   // Move the focus towards left
683   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
684
685   // Confirm whether focus is moved to button2
686   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
687   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
688   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
689   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
690   focusChangedCallback.Reset();
691
692   // Move the focus towards right
693   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
694
695   // Confirm whether focus is moved to button1
696   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
697   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
698   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
699   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
700   focusChangedCallback.Reset();
701
702   // Move the focus towards up
703   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
704
705   // Confirm whether focus is moved to button2
706   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
707   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
708   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
709   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
710   focusChangedCallback.Reset();
711
712   // Move the focus towards down
713   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
714
715   // Confirm whether focus is moved to button1
716   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
717   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
718   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
719   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
720   focusChangedCallback.Reset();
721
722   // Create a 1x1 table view and try to move focus inside it
723   TableView tableView = TableView::New( 1, 1 );
724   application.GetScene().Add(tableView);
725
726   PushButton button = PushButton::New();
727   button.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
728   tableView.AddChild(button, TableView::CellPosition(0, 0));
729
730   // set the navigation properties of button3
731   button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
732
733   // Set the focus to the button
734   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
735   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
736   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
737   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
738   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
739   focusChangedCallback.Reset();
740
741   // Move the focus towards left
742   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
743
744   // Confirm whether focus is moved to button1
745   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
746   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
747   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
748   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
749   focusChangedCallback.Reset();
750
751   END_TEST;
752 }
753
754 int UtcDaliKeyboardFocusManagerClearFocus(void)
755 {
756   ToolkitTestApplication application;
757
758   tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
759
760   KeyboardFocusManager manager = KeyboardFocusManager::Get();
761   DALI_TEST_CHECK(manager);
762
763   // Create the first actor and add it to the stage
764   Actor first = Actor::New();
765   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
766   application.GetScene().Add(first);
767
768   // Create the second actor and add it to the stage
769   Actor second = Actor::New();
770   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
771   application.GetScene().Add(second);
772
773   // Check that the focus is set on the first actor
774   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
775   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
776
777   // Check that the focus is set on the second actor
778   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
779   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
780
781   // Clear the focus
782   manager.ClearFocus();
783
784   // Check that no actor is being focused now.
785   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
786   END_TEST;
787 }
788
789 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
790 {
791   ToolkitTestApplication application;
792
793   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
794
795   KeyboardFocusManager manager = KeyboardFocusManager::Get();
796   DALI_TEST_CHECK(manager);
797
798   // Check that the focus movement is not looped within the same focus group by default
799   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
800
801   // Enable the loop
802   manager.SetFocusGroupLoop(true);
803   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
804   END_TEST;
805 }
806
807 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
808 {
809   ToolkitTestApplication application;
810
811   tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
812
813   KeyboardFocusManager manager = KeyboardFocusManager::Get();
814   DALI_TEST_CHECK(manager);
815
816   // Create an actor and check that it is not a focus group by default
817   Actor actor = Actor::New();
818   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
819
820   // Set the actor as focus group
821   manager.SetAsFocusGroup(actor, true);
822
823   // flush the queue and render once
824   application.SendNotification();
825   application.Render();
826
827   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
828
829   // Set the actor not as focus group
830   manager.SetAsFocusGroup(actor, false);
831
832   // flush the queue and render once
833   application.SendNotification();
834   application.Render();
835
836   DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
837   END_TEST;
838 }
839
840 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
841 {
842   ToolkitTestApplication application;
843
844   tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
845
846   KeyboardFocusManager manager = KeyboardFocusManager::Get();
847   DALI_TEST_CHECK(manager);
848
849   // Create an actor with two child actors and add it to the stage
850   Actor parent = Actor::New();
851   Actor child = Actor::New();
852   parent.Add(child);
853   application.GetScene().Add(parent);
854
855   // Create three actors and add them as the children of the first child actor
856   Actor grandChild = Actor::New();
857   child.Add(grandChild);
858
859   // Set the parent and the first child actor as focus groups
860   manager.SetAsFocusGroup(parent, true);
861
862   // flush the queue and render once
863   application.SendNotification();
864   application.Render();
865
866   DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
867
868   // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
869   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
870
871   manager.SetAsFocusGroup(child, true);
872
873   // flush the queue and render once
874   application.SendNotification();
875   application.Render();
876
877   DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
878
879   // The focus group should be the child, As it is the immediate parent which is also a focus group.
880   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
881
882   manager.SetAsFocusGroup(grandChild, true);
883
884   // flush the queue and render once
885   application.SendNotification();
886   application.Render();
887
888   DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
889
890   // The current focus group should be itself, As it is also a focus group.
891   DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
892   END_TEST;
893 }
894
895 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
896 {
897   ToolkitTestApplication application;
898
899   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
900
901   KeyboardFocusManager manager = KeyboardFocusManager::Get();
902   DALI_TEST_CHECK(manager);
903
904   Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
905   DALI_TEST_CHECK(defaultFocusIndicatorActor);
906
907   Actor newFocusIndicatorActor = Actor::New();
908   manager.SetFocusIndicatorActor(newFocusIndicatorActor);
909   DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
910   END_TEST;
911 }
912
913
914 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
915 {
916   ToolkitTestApplication application;
917
918   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
919
920   KeyboardFocusManager manager = KeyboardFocusManager::Get();
921   DALI_TEST_CHECK(manager);
922
923   bool focusedActorActivatedSignalVerified = false;
924   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
925   manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
926
927   Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
928
929   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
930   // It makes mIsFocusIndicatorEnabled true
931   application.ProcessEvent(returnEvent);
932
933   // Create the first button and add it to the stage
934   PushButton firstPushButton = PushButton::New();
935   firstPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
936   application.GetScene().Add(firstPushButton);
937
938   // Create the second button and add it to the stage
939   PushButton secondPushButton = PushButton::New();
940   secondPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
941   application.GetScene().Add(secondPushButton);
942
943   // Check that the focus is set on the first button
944   DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
945   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
946
947   // Send the return event to activate the first button
948   application.ProcessEvent(returnEvent);
949   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
950   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
951   focusedActorActivatedCallback.Reset();
952
953   // Check that the focus is set on the second button
954   DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
955   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
956
957   // Send the return event again to activate the second button
958   application.ProcessEvent(returnEvent);
959   DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
960   DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
961   focusedActorActivatedCallback.Reset();
962   END_TEST;
963 }
964
965 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
966 {
967   ToolkitTestApplication application;
968
969   tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
970
971   // Register Type
972   TypeInfo type;
973   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
974   DALI_TEST_CHECK( type );
975   BaseHandle handle = type.CreateInstance();
976   DALI_TEST_CHECK( handle );
977
978   KeyboardFocusManager manager = KeyboardFocusManager::Get();
979   DALI_TEST_CHECK(manager);
980
981   bool focusGroupChangedSignalVerified = false;
982   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
983   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
984
985   Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
986   Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
987
988   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
989   // It makes mIsFocusIndicatorEnabled true
990   application.ProcessEvent(tabEvent);
991
992   // Send the tab event to change focus group in the forward direction
993   application.ProcessEvent(tabEvent);
994   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
995   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
996   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
997   focusGroupChangedCallback.Reset();
998
999   // Send the shift tab event to change focus group in the backward direction
1000   application.ProcessEvent(shiftTabEvent);
1001   DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1002   DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1003   DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1004   focusGroupChangedCallback.Reset();
1005   END_TEST;
1006 }
1007
1008 int UtcDaliKeyboardFocusManagerSignals(void)
1009 {
1010   ToolkitTestApplication application;
1011
1012   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1013   DALI_TEST_CHECK( manager );
1014
1015   ConnectionTracker* testTracker = new ConnectionTracker();
1016   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
1017   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
1018   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
1019   DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
1020
1021   END_TEST;
1022 }
1023
1024 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1025 {
1026   ToolkitTestApplication application;
1027
1028   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1029
1030   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1031   DALI_TEST_CHECK(manager);
1032
1033   // Create the first actor and add it to the stage
1034   Actor first = Actor::New();
1035   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1036   application.GetScene().Add(first);
1037
1038   // Create the second actor and add it to the stage
1039   Actor second = Actor::New();
1040   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1041   application.GetScene().Add(second);
1042
1043   // Create the third actor and add it to the stage
1044   Actor third = Actor::New();
1045   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1046   application.GetScene().Add(third);
1047
1048   // Create the fourth actor and add it to the stage
1049   Actor fourth = Actor::New();
1050   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1051   application.GetScene().Add(fourth);
1052
1053   // Check that the focus is set on the second actor
1054   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1055   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1056
1057   // Check that the focus is set on the second actor
1058   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1059   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1060
1061   // Check that the focus is set on the third  actor
1062   DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1063   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1064
1065   // Check that the focus is set on the third  actor
1066   DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1067   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1068
1069   // Move the focus backward
1070   manager.MoveFocusBackward();
1071
1072   // Check that it current focused actor is third actor
1073   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1074
1075   // Remove the second actor on stage
1076   second.Unparent();
1077
1078   // Reset the first actor
1079   first.Unparent();
1080   first.Reset();
1081
1082   // Move the focus backward
1083   manager.MoveFocusBackward();
1084
1085   // Check that it current focused actor is third actor
1086   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1087
1088   // Make history stack full
1089   for(int i = 0 ; i < 31 ; i ++)
1090   {
1091     Actor actor = Actor::New();
1092     actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1093     application.GetScene().Add(actor);
1094     manager.SetCurrentFocusActor(actor);
1095   }
1096
1097   for(int i = 0 ; i < 31 ; i ++)
1098   {
1099     manager.MoveFocusBackward();
1100   }
1101
1102   // Check that it current focused actor is not second actor
1103   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1104
1105   END_TEST;
1106 }
1107
1108 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1109 {
1110   ToolkitTestApplication application;
1111
1112   tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1113
1114   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1115   DALI_TEST_CHECK(manager);
1116
1117   bool preFocusChangeSignalVerified = false;
1118   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1119   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1120
1121   bool focusChangedSignalVerified = false;
1122   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1123   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1124
1125   Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1126   Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1127   Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1128   Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1129   Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1130   Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1131
1132   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1133   // It makes mIsFocusIndicatorEnabled true
1134   application.ProcessEvent(leftEvent);
1135
1136   // Create a 2x2 table view and try to move focus inside it
1137   TableView tableView = TableView::New( 2, 2 );
1138   application.GetScene().Add(tableView);
1139
1140   // Create the first actor
1141   Actor first = Actor::New();
1142   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1143
1144   // Create the second actor
1145   Actor second = Actor::New();
1146   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1147
1148   // Create the third actor
1149   Actor third = Actor::New();
1150   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1151
1152   // Create the fourth actor
1153   Actor fourth = Actor::New();
1154   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1155
1156   // Add the four children to table view
1157   tableView.AddChild(first, TableView::CellPosition(0, 0));
1158   tableView.AddChild(second, TableView::CellPosition(0, 1));
1159   tableView.AddChild(third, TableView::CellPosition(1, 0));
1160   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1161
1162   // Set the focus to the first actor
1163   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1164   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1165   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1166   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1167   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1168   focusChangedCallback.Reset();
1169
1170   // Send the right key event to move the focus towards right
1171   application.ProcessEvent(rightEvent);
1172   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1173   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1174   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1175   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1176   focusChangedCallback.Reset();
1177
1178   // Send the down key event to move the focus towards down
1179   application.ProcessEvent(downEvent);
1180   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1181   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1182   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1183   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1184   focusChangedCallback.Reset();
1185
1186   // Send the down event to move the focus towards left
1187   application.ProcessEvent(leftEvent);
1188   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1189   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1190   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1191   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1192   focusChangedCallback.Reset();
1193
1194   // Send the up event to move the focus towards up
1195   application.ProcessEvent(upEvent);
1196   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1197   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1198   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1199   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1200   focusChangedCallback.Reset();
1201
1202   // Send the pape up event, but focus should not be moved because page up is not supported by table view
1203   application.ProcessEvent(pageUpEvent);
1204   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1205   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1206   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1207   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1208   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1209   preFocusChangeCallback.Reset();
1210
1211   // Send the pape down event, but focus should not be moved because page down is not supported by table view
1212   application.ProcessEvent(pageDownEvent);
1213   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1214   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1215   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1216   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1217   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1218   preFocusChangeCallback.Reset();
1219
1220   // Clear the focus
1221   manager.ClearFocus();
1222
1223   // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1224   preFocusChangeCallback.Reset();
1225   application.ProcessEvent(pageUpEvent);
1226   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1227   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1228   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1229   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1230   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1231
1232   // Clear the focus again
1233   manager.ClearFocus();
1234
1235   // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1236   preFocusChangeCallback.Reset();
1237   application.ProcessEvent(pageDownEvent);
1238   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1239   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1240   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1241   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1242   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1243
1244   // Clear the focus again
1245   manager.ClearFocus();
1246
1247   // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1248   preFocusChangeCallback.Reset();
1249   application.ProcessEvent(upEvent);
1250   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1251   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1252   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1253   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1254
1255   // Clear the focus again
1256   manager.ClearFocus();
1257
1258   // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1259   preFocusChangeCallback.Reset();
1260   application.ProcessEvent(downEvent);
1261   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1262   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1263   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1264   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1265
1266   END_TEST;
1267 }
1268
1269 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1270 {
1271   ToolkitTestApplication application;
1272
1273   tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1274
1275   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1276   DALI_TEST_CHECK(manager);
1277
1278   bool preFocusChangeSignalVerified = false;
1279   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1280   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1281
1282   Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1283
1284   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1285   // It makes mIsFocusIndicatorEnabled true
1286   application.ProcessEvent(spaceEvent);
1287
1288   // Send the space event
1289   application.ProcessEvent(spaceEvent);
1290   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1291   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1292
1293   // Clear the focus again
1294   manager.ClearFocus();
1295
1296   // Send the space event again for line coverage
1297   preFocusChangeCallback.Reset();
1298   application.ProcessEvent(spaceEvent);
1299   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1300   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1301   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1302   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1303
1304   END_TEST;
1305 }
1306
1307
1308
1309 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1310 {
1311   ToolkitTestApplication application;
1312
1313   tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1314
1315   // Register Type
1316   TypeInfo type;
1317   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1318   DALI_TEST_CHECK( type );
1319   BaseHandle handle = type.CreateInstance();
1320   DALI_TEST_CHECK( handle );
1321
1322   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1323   DALI_TEST_CHECK(manager);
1324
1325   bool preFocusChangeSignalVerified = false;
1326   PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1327   manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1328
1329   bool focusChangedSignalVerified = false;
1330   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1331   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1332
1333   // Create the first actor and add it to the stage
1334   Control first = Control::New();
1335   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1336   application.GetScene().Add(first);
1337
1338   // Create the second actor and add it to the stage
1339   Control second = Control::New();
1340   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1341   application.GetScene().Add(second);
1342
1343   // Move the focus to the right
1344   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1345
1346   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1347   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1348   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1349   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1350   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1351   preFocusChangeCallback.Reset();
1352
1353   // Check that the focus is set on the first actor
1354   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1355   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1356   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1357   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1358   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1359   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1360   focusChangedCallback.Reset();
1361
1362   // Move the focus towards right
1363   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1364
1365   // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1366   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1367   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1368   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1369   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1370   preFocusChangeCallback.Reset();
1371
1372   // Check that the focus is set on the second actor
1373   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1374   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1375   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1376   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1377   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1378   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1379   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1380   focusChangedCallback.Reset();
1381
1382   // Move the focus towards up
1383   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1384
1385   // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1386   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1387   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1388   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1389   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1390   preFocusChangeCallback.Reset();
1391   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1392
1393   // Create a 2x2 table view and try to move focus inside it
1394   TableView tableView = TableView::New( 2, 2 );
1395   application.GetScene().Add(tableView);
1396
1397   // Create the third actor
1398   Control third = Control::New();
1399   third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1400
1401   // Create the fourth actor
1402   Control fourth = Control::New();
1403   fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1404
1405   // Add the four children to table view
1406   tableView.AddChild(first, TableView::CellPosition(0, 0));
1407   tableView.AddChild(second, TableView::CellPosition(0, 1));
1408   tableView.AddChild(third, TableView::CellPosition(1, 0));
1409   tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1410
1411   // Set the focus to the first actor
1412   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1413   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1414   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1415   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1416   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1417
1418   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1419   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1420
1421   focusChangedCallback.Reset();
1422
1423   // Move the focus towards right
1424   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1425   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1426   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1427   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1428   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1429   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1430   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1431
1432   focusChangedCallback.Reset();
1433
1434   // Move the focus towards down
1435   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1436   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1437   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1438   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1439   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1440
1441   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1442   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1443   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1444   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1445
1446   focusChangedCallback.Reset();
1447
1448   // Move the focus towards left
1449   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1450   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1451   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1452   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1453   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1454
1455   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1456   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1457   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1458   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1459
1460   focusChangedCallback.Reset();
1461
1462   // Move the focus towards up
1463   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1464   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1465   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1466   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1467   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1468   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1469   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1470   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1471   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1472   focusChangedCallback.Reset();
1473
1474   // Move the focus towards left. The focus move will fail as no way to move it upwards
1475   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1476   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1477   DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1478   DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1479   DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1480   DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1481   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1482   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1483   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1484   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1485
1486   preFocusChangeCallback.Reset();
1487   DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1488
1489   // Enable the loop
1490   manager.SetFocusGroupLoop(true);
1491   DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1492
1493   // Move the focus towards left again. The focus should move to the fourth actor.
1494   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1495   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1496   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1497   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1498   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1499
1500   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1501   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1502   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1503   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1504
1505   focusChangedCallback.Reset();
1506
1507   // Clear the focus
1508   manager.ClearFocus();
1509   DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1510   DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1511   DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1512   DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1513
1514
1515   END_TEST;
1516 }
1517
1518 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1519 {
1520   ToolkitTestApplication application;
1521
1522   tet_infoline( "Ensure we cannot set an actor to be focused if it is not staged and that we do not retrieve an actor if it has been unstaged" );
1523
1524   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1525   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1526
1527   Actor actor = Actor::New();
1528   actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1529
1530   tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1531   manager.SetCurrentFocusActor( actor );
1532   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1533
1534   tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1535   application.GetScene().Add( actor );
1536   manager.SetCurrentFocusActor( actor );
1537   DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1538
1539   tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1540   actor.Unparent();
1541   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1542
1543   END_TEST;
1544 }
1545
1546 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1547 {
1548   ToolkitTestApplication application;
1549
1550   tet_infoline( "Ensure we cannot set an actor to be focused if it is not staged and that we do not retrieve an actor if it has been unstaged" );
1551
1552   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1553   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1554
1555   Actor actor = Actor::New();
1556   actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1557   application.GetScene().Add( actor );
1558   manager.SetCurrentFocusActor( actor );
1559
1560   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1561   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1562   Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1563   application.ProcessEvent(rightEvent);
1564
1565   Actor indicatorActor = manager.GetFocusIndicatorActor();
1566
1567   tet_infoline( "Indicator is added to focused actor" );
1568   DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1569
1570   Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1571   DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1572
1573   tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1574   DALI_TEST_CHECK( !indicatorActor.GetParent() );
1575
1576   END_TEST;
1577 }
1578
1579 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1580 {
1581   ToolkitTestApplication application;
1582
1583   tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
1584   Dali::Integration::Scene scene = application.GetScene();
1585
1586   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1587   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1588
1589   // Create the first actor and add it to the stage
1590   Control control = Control::New();
1591   control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1592   scene.Add(control);
1593
1594   KeyEventCallback controlCallback( true );
1595   control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
1596
1597   KeyEventCallback sceneCallback( false );
1598   scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
1599
1600   manager.SetCurrentFocusActor( control );
1601
1602   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1603   // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1604   Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1605   application.ProcessEvent(event1);
1606
1607   DALI_TEST_CHECK( controlCallback.mIsCalled );
1608   DALI_TEST_CHECK( !sceneCallback.mIsCalled );
1609
1610   END_TEST;
1611 }
1612
1613 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1614 {
1615   ToolkitTestApplication application;
1616
1617   tet_infoline( "Ensure Memory focus actors for each window ");
1618   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1619   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1620
1621   Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false);
1622   DALI_TEST_CHECK( firstWindow );
1623   Control first = Control::New();
1624   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1625   firstWindow.Add(first);
1626
1627   Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false);
1628   DALI_TEST_CHECK( secondWindow );
1629   Control second = Control::New();
1630   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1631   secondWindow.Add( second );
1632
1633   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1634   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1635
1636   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1637   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1638   firstWindow.Raise();
1639   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1640
1641   secondWindow.Remove( second );
1642   secondWindow.Raise();
1643   DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1644
1645   secondWindow.Reset();
1646   END_TEST;
1647 }
1648
1649 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1650 {
1651   ToolkitTestApplication application;
1652
1653   tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1654
1655   // Register Type
1656   TypeInfo type;
1657   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1658   DALI_TEST_CHECK( type );
1659   BaseHandle handle = type.CreateInstance();
1660   DALI_TEST_CHECK( handle );
1661
1662   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1663   DALI_TEST_CHECK(manager);
1664
1665   bool focusChangedSignalVerified = false;
1666   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1667   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1668
1669   PushButton button1 = PushButton::New();
1670   PushButton button2 = PushButton::New();
1671   PushButton button3 = PushButton::New();
1672   PushButton button4 = PushButton::New();
1673   PushButton button5 = PushButton::New();
1674
1675   button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1676   button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1677   button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1678   button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1679   button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1680
1681   button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1682   button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1683   button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1684   button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1685   button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1686
1687   application.GetScene().Add(button1);
1688   application.GetScene().Add(button2);
1689   application.GetScene().Add(button3);
1690   button5.Add(button4);
1691   application.GetScene().Add(button5);
1692
1693   // set position
1694   // button1 -- button2
1695   //   |           |
1696   //   |    button5|
1697   // button3 -- button4
1698   button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1699   button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1700   button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1701   button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1702   button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1703
1704   // flush the queue and render once
1705   application.SendNotification();
1706   application.Render();
1707
1708   // Set the focus to the button1
1709   // [button1] -- button2
1710   //   |           |
1711   //   |    button5|
1712   // button3 -- button4
1713   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1714   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1715   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1716   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1717   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1718   focusChangedCallback.Reset();
1719
1720   // without set the navigation properties, but we can focus move
1721   // enable the default algorithm
1722   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1723   DALI_TEST_CHECK( Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
1724
1725   // Move the focus towards right
1726   // button1 -- [button2]
1727   //   |           |
1728   //   |    button5|
1729   // button3 -- button4
1730   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1731
1732   // Confirm whether focus is moved to button2
1733   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1734   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1735   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1736   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1737   focusChangedCallback.Reset();
1738
1739   // Move the focus towards down
1740   // button1 -- button2
1741   //   |           |
1742   //   |  [button5]|
1743   // button3 -- button4
1744   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1745
1746   // Confirm whether focus is moved to button5
1747   DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1748   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1749   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1750   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1751   focusChangedCallback.Reset();
1752
1753   // Move the focus towards right
1754   // button1 -- button2
1755   //   |           |
1756   //   |    button5|
1757   // button3 -- [button4]
1758   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1759
1760   // Confirm whether focus is moved to button4
1761   DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1762   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1763   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1764   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1765   focusChangedCallback.Reset();
1766
1767   // Move the focus towards left
1768   // button1 -- button2
1769   //   |           |
1770   //   |  [button5]|
1771   // button3 -- button4
1772   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1773
1774   // Confirm whether focus is moved to button5
1775   DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1776   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1777   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1778   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1779   focusChangedCallback.Reset();
1780
1781   // Move the focus towards left
1782   // button1 -- button2
1783   //   |           |
1784   //   |    button5|
1785   //[button3] -- button4
1786   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1787
1788   // Confirm whether focus is moved to button3
1789   DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1790   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1791   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1792   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1793   focusChangedCallback.Reset();
1794
1795   // Move the focus towards right
1796   // button1 -- button2
1797   //   |           |
1798   //   |  [button5]|
1799   // button3 -- button4
1800   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1801
1802   // Confirm whether focus is moved to button5
1803   DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1804   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1805   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1806   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1807   focusChangedCallback.Reset();
1808
1809   // Move the focus towards left
1810   // button1 -- button2
1811   //   |           |
1812   //   |    button5|
1813   //[button3] -- button4
1814   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1815
1816   // Confirm whether focus is moved to button3
1817   DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1818   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1819   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1820   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1821   focusChangedCallback.Reset();
1822
1823   // Move the focus towards up
1824   //[button1]-- button2
1825   //   |           |
1826   //   |    button5|
1827   // button3 -- button4
1828   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1829
1830   // Confirm whether focus is moved to button1
1831   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1832   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1833   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1834   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1835   focusChangedCallback.Reset();
1836
1837
1838   // Move the focus towards left. The focus move will fail as no way to move it upwards
1839   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1840
1841   // Move the focus toward page up/down. The focus move will fail as invalid direction.
1842   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1843   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1844   focusChangedCallback.Reset();
1845
1846   END_TEST;
1847 }
1848
1849
1850 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode(void)
1851 {
1852   ToolkitTestApplication application;
1853
1854   tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode");
1855
1856   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1857   DALI_TEST_CHECK(manager);
1858
1859   // Create the first actor and add it to the stage
1860   Actor first = Actor::New();
1861   first.SetProperty(Actor::Property::SIZE, Vector2( 50, 50 ));
1862   first.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1863   first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1864   first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1865   first.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE,true);
1866   application.GetScene().Add(first);
1867
1868   // Create the second actor and add it to the stage
1869   Actor second = Actor::New();
1870   second.SetProperty(Actor::Property::SIZE, Vector2( 50, 50 ));
1871   second.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1872   second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1873   second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1874   application.GetScene().Add(second);
1875
1876   // flush the queue and render once
1877   application.SendNotification();
1878   application.Render();
1879
1880   // Check that no actor is being focused yet.
1881   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1882
1883   // Check that it will fail to set focus on an invalid actor
1884   DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
1885
1886
1887   Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1888   Dali::Integration::Point pointDown1;
1889   pointDown1.SetState( PointState::DOWN );
1890   pointDown1.SetDeviceId(1);
1891   // touch first actor
1892   pointDown1.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1893   event1.AddPoint(pointDown1);
1894   application.ProcessEvent( event1 );
1895
1896   // flush the queue and render once
1897   application.SendNotification();
1898   application.Render();
1899
1900   // Check that the focus is successfully to the first actor
1901   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1902
1903   Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1904   Dali::Integration::Point pointDown2;
1905   pointDown2.SetState( PointState::DOWN );
1906   pointDown2.SetDeviceId(1);
1907   // touch second actor
1908   pointDown2.SetScreenPosition( Vector2( 110.0f, 10.0f ) );
1909   event2.AddPoint(pointDown2);
1910   application.ProcessEvent( event2 );
1911
1912   // flush the queue and render once
1913   application.SendNotification();
1914   application.Render();
1915
1916   // Check that the focus is successfully to clear
1917   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1918
1919   // Make the second actor focusableInTouchMode
1920   second.SetProperty( DevelActor::Property::TOUCH_FOCUSABLE,true);
1921
1922   // touch second actor
1923   application.ProcessEvent( event2 );
1924
1925   // flush the queue and render once
1926   application.SendNotification();
1927   application.Render();
1928
1929   // Check that the focus is successfully to the second actor
1930   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1931
1932   END_TEST;
1933 }
1934
1935 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1936 {
1937   ToolkitTestApplication application;
1938
1939   tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1940
1941   // Register Type
1942   TypeInfo type;
1943   type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1944   DALI_TEST_CHECK( type );
1945   BaseHandle handle = type.CreateInstance();
1946   DALI_TEST_CHECK( handle );
1947
1948   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1949   DALI_TEST_CHECK(manager);
1950
1951   bool focusChangedSignalVerified = false;
1952   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1953   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1954
1955   PushButton button1 = PushButton::New();
1956   PushButton button2 = PushButton::New();
1957
1958   button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1959   button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1960
1961   button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1962   button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1963
1964   application.GetScene().Add(button1);
1965   application.GetScene().Add(button2);
1966
1967   // set position
1968   // button1 -- button2
1969   button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1970   button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1971
1972   // flush the queue and render once
1973   application.SendNotification();
1974   application.Render();
1975
1976   // Set the focus to the button1
1977   // [button1] -- button2
1978   DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1979   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1980   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1981   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1982   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1983   focusChangedCallback.Reset();
1984
1985   // without set the navigation properties, but we can focus move
1986   // enable the default algorithm
1987   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1988   DALI_TEST_CHECK( Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
1989
1990   // Move the focus towards right
1991   // button1 -- [button2]
1992   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1993
1994   // Confirm whether focus is moved to button2
1995   DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1996   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1997   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1998   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1999   focusChangedCallback.Reset();
2000
2001   // disable the default algorithm
2002   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
2003   DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
2004
2005   // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
2006   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
2007
2008   // enable the default algorithm
2009   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2010   DALI_TEST_CHECK( Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
2011
2012   // Move the focus towards left, The focus move will success because the default algorithm is enabled.
2013   // [button1] -- button2
2014   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2015   // Confirm whether focus is moved to button2
2016   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2017   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2018   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2019   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2020   focusChangedCallback.Reset();
2021
2022
2023   END_TEST;
2024 }
2025
2026
2027 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2028 {
2029   ToolkitTestApplication application;
2030
2031   tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2032
2033   KeyboardFocusManager manager = KeyboardFocusManager::Get();
2034   DALI_TEST_CHECK(manager);
2035
2036   // Create the first actor and add it to the stage
2037   Actor first = Actor::New();
2038   first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true);
2039   application.GetScene().Add(first);
2040
2041   // Create the second actor and add it to the first actor.
2042   Actor second = Actor::New();
2043   second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true);
2044   first.Add(second);
2045
2046   // Check that no actor is being focused yet.
2047   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2048
2049   // Check that the focus is set on the first actor
2050   DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2051   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2052
2053   // Set KeyboardFocusableChildren false.
2054   first.SetProperty( DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2055
2056   // Check that it will fail to set focus on the second actor as it's not focusable
2057   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2058   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2059
2060   // Set KeyboardFocusableChildren true.
2061   first.SetProperty( DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2062
2063   // Check that the focus is set on the second actor
2064   DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2065   DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2066
2067   END_TEST;
2068 }
2069
2070 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2071 {
2072   ToolkitTestApplication application;
2073
2074   tet_infoline( "UtcDaliKeyboardFocusManagerCheckWheelEvent" );
2075   Dali::Integration::Scene scene = application.GetScene();
2076
2077   KeyboardFocusManager manager = KeyboardFocusManager::Get();
2078   DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
2079
2080   // Create the first actor and add it to the stage
2081   Actor parent = Actor::New();
2082   parent.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2083
2084   Actor child = Actor::New();
2085   child.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2086
2087   parent.Add(child);
2088   scene.Add(parent);
2089
2090   WheelEventCallback childCallback( false );
2091   child.WheelEventSignal().Connect( &childCallback, &WheelEventCallback::Callback );
2092
2093   WheelEventCallback parentCallback( true );
2094   parent.WheelEventSignal().Connect( &parentCallback, &WheelEventCallback::Callback );
2095
2096   WheelEventCallback sceneCallback( false );
2097   scene.WheelEventSignal().Connect( &sceneCallback, &WheelEventCallback::Callback );
2098
2099   manager.SetCurrentFocusActor( child );
2100
2101   // Emit custom wheel event is comming to KeyboardFocusManager
2102   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2103   application.ProcessEvent(event);
2104
2105   DALI_TEST_CHECK( childCallback.mIsCalled );
2106   DALI_TEST_CHECK( parentCallback.mIsCalled );
2107   DALI_TEST_CHECK( !sceneCallback.mIsCalled );
2108
2109   END_TEST;
2110 }