2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
31 using namespace Dali::Toolkit;
33 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
40 test_return_value = TET_PASS;
47 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
49 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
50 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
53 CustomAlgorithm(bool& interfaceVerified)
54 : mInterfaceVerified(interfaceVerified),
55 mCurrentFocusedActor(),
56 mProposedActorToFocus(),
57 mDirection(Control::KeyboardFocus::LEFT)
61 Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
63 tet_infoline("Verifying CustomAlgorithm()");
65 mInterfaceVerified = true;
67 mCurrentFocusedActor = currentFocusedActor;
68 mProposedActorToFocus = proposedActorToFocus;
69 mDirection = direction;
71 return mProposedActorToFocus;
76 mInterfaceVerified = false;
77 mCurrentFocusedActor = Actor();
78 mProposedActorToFocus = Actor();
79 mDirection = Control::KeyboardFocus::LEFT;
82 bool& mInterfaceVerified;
83 Actor mCurrentFocusedActor;
84 Actor mProposedActorToFocus;
85 Control::KeyboardFocus::Direction mDirection;
88 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
89 class PreFocusChangeCallback : public Dali::ConnectionTracker
92 PreFocusChangeCallback(bool& signalReceived)
93 : mSignalVerified(signalReceived),
94 mCurrentFocusedActor(),
95 mProposedActorToFocus(),
96 mDirection(Control::KeyboardFocus::LEFT)
100 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
102 tet_infoline("Verifying PreFocusChangeCallback()");
104 mSignalVerified = true;
106 mCurrentFocusedActor = currentFocusedActor;
107 mProposedActorToFocus = proposedActorToFocus;
108 mDirection = direction;
110 return mProposedActorToFocus;
115 mSignalVerified = false;
116 mCurrentFocusedActor = Actor();
117 mProposedActorToFocus = Actor();
118 mDirection = Control::KeyboardFocus::LEFT;
121 bool& mSignalVerified;
122 Actor mCurrentFocusedActor;
123 Actor mProposedActorToFocus;
124 Control::KeyboardFocus::Direction mDirection;
127 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
128 class FocusChangedCallback : public Dali::ConnectionTracker
131 FocusChangedCallback(bool& signalReceived)
132 : mSignalVerified(signalReceived),
133 mOriginalFocusedActor(),
134 mCurrentFocusedActor()
138 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
140 tet_infoline("Verifying FocusChangedCallback()");
142 if(originalFocusedActor == mCurrentFocusedActor)
144 mSignalVerified = true;
147 mOriginalFocusedActor = originalFocusedActor;
148 mCurrentFocusedActor = currentFocusedActor;
153 mSignalVerified = false;
156 bool& mSignalVerified;
157 Actor mOriginalFocusedActor;
158 Actor mCurrentFocusedActor;
161 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
162 class FocusGroupChangedCallback : public Dali::ConnectionTracker
165 FocusGroupChangedCallback(bool& signalReceived)
166 : mSignalVerified(signalReceived),
167 mCurrentFocusedActor(),
172 void Callback(Actor currentFocusedActor, bool forward)
174 tet_infoline("Verifying FocusGroupChangedCallback()");
176 mSignalVerified = true;
178 mCurrentFocusedActor = currentFocusedActor;
184 mSignalVerified = false;
187 bool& mSignalVerified;
188 Actor mCurrentFocusedActor;
192 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
193 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
196 FocusedActorActivatedCallback(bool& signalReceived)
197 : mSignalVerified(signalReceived),
202 void Callback(Actor activatedActor)
204 tet_infoline("Verifying FocusedActorActivatedCallback()");
206 mSignalVerified = true;
208 mActivatedActor = activatedActor;
213 mSignalVerified = false;
216 bool& mSignalVerified;
217 Actor mActivatedActor;
220 class KeyEventCallback : public Dali::ConnectionTracker
225 * @param[in] returnValue Set return value of KeyEvent callback.
227 KeyEventCallback( bool consumed )
228 : mConsumed( consumed ),
233 bool Callback( Control control, const KeyEvent& keyEvent )
239 void Callback( const KeyEvent& keyEvent )
248 // Used to connect to signals via the ConnectSignal Handle method
249 struct CallbackFunctor
262 int UtcDaliKeyboardFocusManagerGet(void)
264 ToolkitTestApplication application;
266 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
270 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
271 DALI_TEST_CHECK( type );
272 BaseHandle handle = type.CreateInstance();
273 DALI_TEST_CHECK( handle );
275 KeyboardFocusManager manager;
277 manager = KeyboardFocusManager::Get();
278 DALI_TEST_CHECK(manager);
280 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
281 DALI_TEST_CHECK(newManager);
283 // Check that focus manager is a singleton
284 DALI_TEST_CHECK(manager == newManager);
288 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
290 ToolkitTestApplication application;
292 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
294 KeyboardFocusManager manager = KeyboardFocusManager::Get();
295 DALI_TEST_CHECK(manager);
297 // Create the first actor and add it to the stage
298 Actor first = Actor::New();
299 first.SetKeyboardFocusable(true);
300 Stage::GetCurrent().Add(first);
302 // Create the second actor and add it to the stage
303 Actor second = Actor::New();
304 second.SetKeyboardFocusable(true);
305 Stage::GetCurrent().Add(second);
307 // Create the third actor but don't add it to the stage
308 Actor third = Actor::New();
310 // Check that no actor is being focused yet.
311 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
313 // Check that it will fail to set focus on an invalid actor
314 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
316 // Check that the focus is set on the first actor
317 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
318 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
320 // Check that the focus is set on the second actor
321 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
322 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
324 // Check that it will fail to set focus on the third actor as it's not in the stage
325 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
326 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
328 // Add the third actor to the stage
329 Stage::GetCurrent().Add(third);
331 // Check that it will fail to set focus on the third actor as it's not focusable
332 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
333 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
335 // Make the third actor focusable
336 third.SetKeyboardFocusable(true);
338 // Check that the focus is successfully moved to the third actor
339 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
340 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
344 int UtcDaliKeyboardFocusManagerMoveFocus(void)
346 ToolkitTestApplication application;
348 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
352 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
353 DALI_TEST_CHECK( type );
354 BaseHandle handle = type.CreateInstance();
355 DALI_TEST_CHECK( handle );
357 KeyboardFocusManager manager = KeyboardFocusManager::Get();
358 DALI_TEST_CHECK(manager);
360 bool preFocusChangeSignalVerified = false;
361 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
362 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
364 bool focusChangedSignalVerified = false;
365 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
366 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
368 // Create the first actor and add it to the stage
369 Actor first = Actor::New();
370 first.SetKeyboardFocusable(true);
371 Stage::GetCurrent().Add(first);
373 // Create the second actor and add it to the stage
374 Actor second = Actor::New();
375 second.SetKeyboardFocusable(true);
376 Stage::GetCurrent().Add(second);
378 // Move the focus to the right
379 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
381 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
382 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
383 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
384 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
385 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
386 preFocusChangeCallback.Reset();
388 // Check that the focus is set on the first actor
389 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
390 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
391 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
392 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
393 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
394 focusChangedCallback.Reset();
396 // Move the focus towards right
397 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
399 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
400 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
401 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
402 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
403 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
404 preFocusChangeCallback.Reset();
406 // Check that the focus is set on the second actor
407 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
408 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
409 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
410 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
411 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
412 focusChangedCallback.Reset();
414 // Move the focus towards up
415 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
417 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
418 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
419 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
420 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
421 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
422 preFocusChangeCallback.Reset();
423 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
425 // Create a 2x2 table view and try to move focus inside it
426 TableView tableView = TableView::New( 2, 2 );
427 Stage::GetCurrent().Add(tableView);
429 // Create the third actor
430 Actor third = Actor::New();
431 third.SetKeyboardFocusable(true);
433 // Create the fourth actor
434 Actor fourth = Actor::New();
435 fourth.SetKeyboardFocusable(true);
437 // Add the four children to table view
438 tableView.AddChild(first, TableView::CellPosition(0, 0));
439 tableView.AddChild(second, TableView::CellPosition(0, 1));
440 tableView.AddChild(third, TableView::CellPosition(1, 0));
441 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
443 // Set the focus to the first actor
444 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
445 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
446 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
447 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
448 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
449 focusChangedCallback.Reset();
451 // Move the focus towards right
452 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
453 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
454 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
455 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
456 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
457 focusChangedCallback.Reset();
459 // Move the focus towards down
460 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
461 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
462 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
463 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
464 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
465 focusChangedCallback.Reset();
467 // Move the focus towards left
468 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
469 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
470 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
471 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
472 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
473 focusChangedCallback.Reset();
475 // Move the focus towards up
476 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
477 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
478 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
479 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
480 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
481 focusChangedCallback.Reset();
483 // Move the focus towards left. The focus move will fail as no way to move it upwards
484 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
485 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
486 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
487 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
488 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
489 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
490 preFocusChangeCallback.Reset();
491 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
494 manager.SetFocusGroupLoop(true);
495 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
497 // Move the focus towards left again. The focus should move to the fourth actor.
498 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
499 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
500 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
501 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
502 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
503 focusChangedCallback.Reset();
507 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
509 ToolkitTestApplication application;
511 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
515 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
516 DALI_TEST_CHECK( type );
517 BaseHandle handle = type.CreateInstance();
518 DALI_TEST_CHECK( handle );
520 KeyboardFocusManager manager = KeyboardFocusManager::Get();
521 DALI_TEST_CHECK(manager);
523 bool preFocusChangeSignalVerified = false;
524 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
525 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
527 bool focusChangedSignalVerified = false;
528 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
529 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
531 // Create the first actor and add it to the stage
532 Actor first = Actor::New();
533 first.SetKeyboardFocusable(true);
534 Stage::GetCurrent().Add(first);
536 // Create the second actor and add it to the stage
537 Actor second = Actor::New();
538 second.SetKeyboardFocusable(true);
539 Stage::GetCurrent().Add(second);
541 // Move the focus to the right
542 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
544 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
545 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
546 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
547 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
548 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
549 preFocusChangeCallback.Reset();
551 bool customAlgorithmInterfaceVerified = false;
552 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
553 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
555 // Move the focus towards right
556 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
558 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
559 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
560 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
561 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
562 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
563 customAlgorithm.Reset();
565 // Check that the focus is set on the first actor
566 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
567 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
568 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
569 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
570 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
571 focusChangedCallback.Reset();
573 // Move the focus towards right
574 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
576 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
577 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
578 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
579 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
580 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
581 customAlgorithm.Reset();
583 // Check that the focus is set on the second actor
584 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
585 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
586 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
587 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
588 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
589 focusChangedCallback.Reset();
591 // Move the focus towards up
592 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
594 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
595 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
596 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
597 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
598 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
599 customAlgorithm.Reset();
600 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
604 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
606 ToolkitTestApplication application;
608 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
612 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
613 DALI_TEST_CHECK( type );
614 BaseHandle handle = type.CreateInstance();
615 DALI_TEST_CHECK( handle );
617 KeyboardFocusManager manager = KeyboardFocusManager::Get();
618 DALI_TEST_CHECK(manager);
620 bool focusChangedSignalVerified = false;
621 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
622 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
624 PushButton button1 = PushButton::New();
625 PushButton button2 = PushButton::New();
626 button1.SetKeyboardFocusable(true);
627 button2.SetKeyboardFocusable(true);
628 Stage::GetCurrent().Add(button1);
629 Stage::GetCurrent().Add(button2);
631 // Set the focus to the button1
632 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
633 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
634 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
635 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
636 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
637 focusChangedCallback.Reset();
639 // set the navigation properties of button1
640 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
641 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
642 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
643 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
645 // set the navigation properties of button2
646 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
647 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
648 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
649 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
651 // Move the focus towards left
652 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
654 // Confirm whether focus is moved to button2
655 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
656 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
657 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
658 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
659 focusChangedCallback.Reset();
661 // Move the focus towards right
662 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
664 // Confirm whether focus is moved to button1
665 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
666 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
667 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
668 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
669 focusChangedCallback.Reset();
671 // Move the focus towards up
672 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
674 // Confirm whether focus is moved to button2
675 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
676 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
677 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
678 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
679 focusChangedCallback.Reset();
681 // Move the focus towards down
682 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
684 // Confirm whether focus is moved to button1
685 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
686 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
687 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
688 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
689 focusChangedCallback.Reset();
691 // Create a 1x1 table view and try to move focus inside it
692 TableView tableView = TableView::New( 1, 1 );
693 Stage::GetCurrent().Add(tableView);
695 PushButton button = PushButton::New();
696 button.SetKeyboardFocusable(true);
697 tableView.AddChild(button, TableView::CellPosition(0, 0));
699 // set the navigation properties of button3
700 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
702 // Set the focus to the button
703 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
704 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
705 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
706 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
707 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
708 focusChangedCallback.Reset();
710 // Move the focus towards left
711 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
713 // Confirm whether focus is moved to button1
714 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
715 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
716 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
717 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
718 focusChangedCallback.Reset();
723 int UtcDaliKeyboardFocusManagerClearFocus(void)
725 ToolkitTestApplication application;
727 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
729 KeyboardFocusManager manager = KeyboardFocusManager::Get();
730 DALI_TEST_CHECK(manager);
732 // Create the first actor and add it to the stage
733 Actor first = Actor::New();
734 first.SetKeyboardFocusable(true);
735 Stage::GetCurrent().Add(first);
737 // Create the second actor and add it to the stage
738 Actor second = Actor::New();
739 second.SetKeyboardFocusable(true);
740 Stage::GetCurrent().Add(second);
742 // Check that the focus is set on the first actor
743 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
744 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
746 // Check that the focus is set on the second actor
747 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
748 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
751 manager.ClearFocus();
753 // Check that no actor is being focused now.
754 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
758 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
760 ToolkitTestApplication application;
762 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
764 KeyboardFocusManager manager = KeyboardFocusManager::Get();
765 DALI_TEST_CHECK(manager);
767 // Check that the focus movement is not looped within the same focus group by default
768 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
771 manager.SetFocusGroupLoop(true);
772 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
776 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
778 ToolkitTestApplication application;
780 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
782 KeyboardFocusManager manager = KeyboardFocusManager::Get();
783 DALI_TEST_CHECK(manager);
785 // Create an actor and check that it is not a focus group by default
786 Actor actor = Actor::New();
787 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
789 // Set the actor as focus group
790 manager.SetAsFocusGroup(actor, true);
792 // flush the queue and render once
793 application.SendNotification();
794 application.Render();
796 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
798 // Set the actor not as focus group
799 manager.SetAsFocusGroup(actor, false);
801 // flush the queue and render once
802 application.SendNotification();
803 application.Render();
805 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
809 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
811 ToolkitTestApplication application;
813 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
815 KeyboardFocusManager manager = KeyboardFocusManager::Get();
816 DALI_TEST_CHECK(manager);
818 // Create an actor with two child actors and add it to the stage
819 Actor parent = Actor::New();
820 Actor child = Actor::New();
822 Stage::GetCurrent().Add(parent);
824 // Create three actors and add them as the children of the first child actor
825 Actor grandChild = Actor::New();
826 child.Add(grandChild);
828 // Set the parent and the first child actor as focus groups
829 manager.SetAsFocusGroup(parent, true);
831 // flush the queue and render once
832 application.SendNotification();
833 application.Render();
835 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
837 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
838 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
840 manager.SetAsFocusGroup(child, true);
842 // flush the queue and render once
843 application.SendNotification();
844 application.Render();
846 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
848 // The focus group should be the child, As it is the immediate parent which is also a focus group.
849 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
851 manager.SetAsFocusGroup(grandChild, true);
853 // flush the queue and render once
854 application.SendNotification();
855 application.Render();
857 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
859 // The current focus group should be itself, As it is also a focus group.
860 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
864 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
866 ToolkitTestApplication application;
868 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
870 KeyboardFocusManager manager = KeyboardFocusManager::Get();
871 DALI_TEST_CHECK(manager);
873 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
874 DALI_TEST_CHECK(defaultFocusIndicatorActor);
876 Actor newFocusIndicatorActor = Actor::New();
877 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
878 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
883 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
885 ToolkitTestApplication application;
887 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
889 KeyboardFocusManager manager = KeyboardFocusManager::Get();
890 DALI_TEST_CHECK(manager);
892 bool focusedActorActivatedSignalVerified = false;
893 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
894 manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
896 Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
898 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
899 // It makes mIsFocusIndicatorEnabled true
900 application.ProcessEvent(returnEvent);
902 // Create the first button and add it to the stage
903 PushButton firstPushButton = PushButton::New();
904 firstPushButton.SetKeyboardFocusable(true);
905 Stage::GetCurrent().Add(firstPushButton);
907 // Create the second button and add it to the stage
908 PushButton secondPushButton = PushButton::New();
909 secondPushButton.SetKeyboardFocusable(true);
910 Stage::GetCurrent().Add(secondPushButton);
912 // Check that the focus is set on the first button
913 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
914 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
916 // Send the return event to activate the first button
917 application.ProcessEvent(returnEvent);
918 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
919 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
920 focusedActorActivatedCallback.Reset();
922 // Check that the focus is set on the second button
923 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
924 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
926 // Send the return event again to activate the second button
927 application.ProcessEvent(returnEvent);
928 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
929 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
930 focusedActorActivatedCallback.Reset();
934 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
936 ToolkitTestApplication application;
938 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
942 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
943 DALI_TEST_CHECK( type );
944 BaseHandle handle = type.CreateInstance();
945 DALI_TEST_CHECK( handle );
947 KeyboardFocusManager manager = KeyboardFocusManager::Get();
948 DALI_TEST_CHECK(manager);
950 bool focusGroupChangedSignalVerified = false;
951 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
952 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
954 Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
955 Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
957 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
958 // It makes mIsFocusIndicatorEnabled true
959 application.ProcessEvent(tabEvent);
961 // Send the tab event to change focus group in the forward direction
962 application.ProcessEvent(tabEvent);
963 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
964 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
965 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
966 focusGroupChangedCallback.Reset();
968 // Send the shift tab event to change focus group in the backward direction
969 application.ProcessEvent(shiftTabEvent);
970 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
971 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
972 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
973 focusGroupChangedCallback.Reset();
977 int UtcDaliKeyboardFocusManagerSignals(void)
979 ToolkitTestApplication application;
981 KeyboardFocusManager manager = KeyboardFocusManager::Get();
982 DALI_TEST_CHECK( manager );
984 ConnectionTracker* testTracker = new ConnectionTracker();
985 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
986 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
987 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
988 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
993 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
995 ToolkitTestApplication application;
997 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
999 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1000 DALI_TEST_CHECK(manager);
1002 // Create the first actor and add it to the stage
1003 Actor first = Actor::New();
1004 first.SetKeyboardFocusable(true);
1005 Stage::GetCurrent().Add(first);
1007 // Create the second actor and add it to the stage
1008 Actor second = Actor::New();
1009 second.SetKeyboardFocusable(true);
1010 Stage::GetCurrent().Add(second);
1012 // Create the third actor and add it to the stage
1013 Actor third = Actor::New();
1014 third.SetKeyboardFocusable(true);
1015 Stage::GetCurrent().Add(third);
1017 // Create the fourth actor and add it to the stage
1018 Actor fourth = Actor::New();
1019 fourth.SetKeyboardFocusable(true);
1020 Stage::GetCurrent().Add(fourth);
1022 // Check that the focus is set on the second actor
1023 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1024 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1026 // Check that the focus is set on the second actor
1027 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1028 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1030 // Check that the focus is set on the third actor
1031 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1032 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1034 // Check that the focus is set on the third actor
1035 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1036 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1038 // Move the focus backward
1039 manager.MoveFocusBackward();
1041 // Check that it current focused actor is third actor
1042 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1044 // Remove the second actor on stage
1047 // Reset the first actor
1051 // Move the focus backward
1052 manager.MoveFocusBackward();
1054 // Check that it current focused actor is third actor
1055 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1057 // Make history stack full
1058 for(int i = 0 ; i < 31 ; i ++)
1060 Actor actor = Actor::New();
1061 actor.SetKeyboardFocusable(true);
1062 Stage::GetCurrent().Add(actor);
1063 manager.SetCurrentFocusActor(actor);
1066 for(int i = 0 ; i < 31 ; i ++)
1068 manager.MoveFocusBackward();
1071 // Check that it current focused actor is not second actor
1072 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1077 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1079 ToolkitTestApplication application;
1081 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1083 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1084 DALI_TEST_CHECK(manager);
1086 bool preFocusChangeSignalVerified = false;
1087 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1088 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1090 bool focusChangedSignalVerified = false;
1091 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1092 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1094 Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1095 Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1096 Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1097 Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1098 Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1099 Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1101 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1102 // It makes mIsFocusIndicatorEnabled true
1103 application.ProcessEvent(leftEvent);
1105 // Create a 2x2 table view and try to move focus inside it
1106 TableView tableView = TableView::New( 2, 2 );
1107 Stage::GetCurrent().Add(tableView);
1109 // Create the first actor
1110 Actor first = Actor::New();
1111 first.SetKeyboardFocusable(true);
1113 // Create the second actor
1114 Actor second = Actor::New();
1115 second.SetKeyboardFocusable(true);
1117 // Create the third actor
1118 Actor third = Actor::New();
1119 third.SetKeyboardFocusable(true);
1121 // Create the fourth actor
1122 Actor fourth = Actor::New();
1123 fourth.SetKeyboardFocusable(true);
1125 // Add the four children to table view
1126 tableView.AddChild(first, TableView::CellPosition(0, 0));
1127 tableView.AddChild(second, TableView::CellPosition(0, 1));
1128 tableView.AddChild(third, TableView::CellPosition(1, 0));
1129 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1131 // Set the focus to the first actor
1132 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1133 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1134 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1135 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1136 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1137 focusChangedCallback.Reset();
1139 // Send the right key event to move the focus towards right
1140 application.ProcessEvent(rightEvent);
1141 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1142 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1143 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1144 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1145 focusChangedCallback.Reset();
1147 // Send the down key event to move the focus towards down
1148 application.ProcessEvent(downEvent);
1149 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1150 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1151 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1152 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1153 focusChangedCallback.Reset();
1155 // Send the down event to move the focus towards left
1156 application.ProcessEvent(leftEvent);
1157 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1158 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1159 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1160 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1161 focusChangedCallback.Reset();
1163 // Send the up event to move the focus towards up
1164 application.ProcessEvent(upEvent);
1165 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1166 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1167 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1168 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1169 focusChangedCallback.Reset();
1171 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1172 application.ProcessEvent(pageUpEvent);
1173 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1174 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1175 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1176 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1177 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1178 preFocusChangeCallback.Reset();
1180 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1181 application.ProcessEvent(pageDownEvent);
1182 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1183 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1184 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1185 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1186 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1187 preFocusChangeCallback.Reset();
1190 manager.ClearFocus();
1192 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1193 preFocusChangeCallback.Reset();
1194 application.ProcessEvent(pageUpEvent);
1195 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1196 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1197 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1198 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1199 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1201 // Clear the focus again
1202 manager.ClearFocus();
1204 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1205 preFocusChangeCallback.Reset();
1206 application.ProcessEvent(pageDownEvent);
1207 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1208 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1209 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1210 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1211 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1213 // Clear the focus again
1214 manager.ClearFocus();
1216 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1217 preFocusChangeCallback.Reset();
1218 application.ProcessEvent(upEvent);
1219 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1220 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1221 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1222 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1224 // Clear the focus again
1225 manager.ClearFocus();
1227 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1228 preFocusChangeCallback.Reset();
1229 application.ProcessEvent(downEvent);
1230 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1231 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1232 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1233 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1238 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1240 ToolkitTestApplication application;
1242 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1244 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1245 DALI_TEST_CHECK(manager);
1247 bool preFocusChangeSignalVerified = false;
1248 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1249 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1251 Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1253 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1254 // It makes mIsFocusIndicatorEnabled true
1255 application.ProcessEvent(spaceEvent);
1257 // Send the space event
1258 application.ProcessEvent(spaceEvent);
1259 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1260 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1262 // Clear the focus again
1263 manager.ClearFocus();
1265 // Send the space event again for line coverage
1266 preFocusChangeCallback.Reset();
1267 application.ProcessEvent(spaceEvent);
1268 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1269 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1270 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1271 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1278 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1280 ToolkitTestApplication application;
1282 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1286 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1287 DALI_TEST_CHECK( type );
1288 BaseHandle handle = type.CreateInstance();
1289 DALI_TEST_CHECK( handle );
1291 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1292 DALI_TEST_CHECK(manager);
1294 bool preFocusChangeSignalVerified = false;
1295 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1296 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1298 bool focusChangedSignalVerified = false;
1299 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1300 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1302 // Create the first actor and add it to the stage
1303 Control first = Control::New();
1304 first.SetKeyboardFocusable(true);
1305 Stage::GetCurrent().Add(first);
1307 // Create the second actor and add it to the stage
1308 Control second = Control::New();
1309 second.SetKeyboardFocusable(true);
1310 Stage::GetCurrent().Add(second);
1312 // Move the focus to the right
1313 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1315 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1316 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1317 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1318 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1319 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1320 preFocusChangeCallback.Reset();
1322 // Check that the focus is set on the first actor
1323 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1324 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1325 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1326 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1327 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1328 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1329 focusChangedCallback.Reset();
1331 // Move the focus towards right
1332 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1334 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1335 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1336 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1337 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1338 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1339 preFocusChangeCallback.Reset();
1341 // Check that the focus is set on the second actor
1342 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1343 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1344 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1345 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1346 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1347 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1348 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1349 focusChangedCallback.Reset();
1351 // Move the focus towards up
1352 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1354 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1355 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1356 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1357 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1358 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1359 preFocusChangeCallback.Reset();
1360 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1362 // Create a 2x2 table view and try to move focus inside it
1363 TableView tableView = TableView::New( 2, 2 );
1364 Stage::GetCurrent().Add(tableView);
1366 // Create the third actor
1367 Control third = Control::New();
1368 third.SetKeyboardFocusable(true);
1370 // Create the fourth actor
1371 Control fourth = Control::New();
1372 fourth.SetKeyboardFocusable(true);
1374 // Add the four children to table view
1375 tableView.AddChild(first, TableView::CellPosition(0, 0));
1376 tableView.AddChild(second, TableView::CellPosition(0, 1));
1377 tableView.AddChild(third, TableView::CellPosition(1, 0));
1378 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1380 // Set the focus to the first actor
1381 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1382 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1383 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1384 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1385 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1387 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1388 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1390 focusChangedCallback.Reset();
1392 // Move the focus towards right
1393 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1394 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1395 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1396 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1397 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1398 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1399 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1401 focusChangedCallback.Reset();
1403 // Move the focus towards down
1404 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1405 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1406 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1407 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1408 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1410 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1411 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1412 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1413 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1415 focusChangedCallback.Reset();
1417 // Move the focus towards left
1418 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1419 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1420 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1421 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1422 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1424 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1425 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1426 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1427 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1429 focusChangedCallback.Reset();
1431 // Move the focus towards up
1432 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1433 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1434 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1435 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1436 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1437 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1438 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1439 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1440 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1441 focusChangedCallback.Reset();
1443 // Move the focus towards left. The focus move will fail as no way to move it upwards
1444 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1445 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1446 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1447 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1448 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1449 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1450 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1451 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1452 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1453 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1455 preFocusChangeCallback.Reset();
1456 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1459 manager.SetFocusGroupLoop(true);
1460 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1462 // Move the focus towards left again. The focus should move to the fourth actor.
1463 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1464 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1465 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1466 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1467 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1469 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1470 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1471 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1472 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1474 focusChangedCallback.Reset();
1477 manager.ClearFocus();
1478 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1479 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1480 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1481 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1487 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1489 ToolkitTestApplication application;
1491 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" );
1493 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1494 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1496 Actor actor = Actor::New();
1497 actor.SetKeyboardFocusable( true );
1499 tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1500 manager.SetCurrentFocusActor( actor );
1501 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1503 tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1504 Stage::GetCurrent().Add( actor );
1505 manager.SetCurrentFocusActor( actor );
1506 DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1508 tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1510 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1515 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1517 ToolkitTestApplication application;
1519 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" );
1521 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1522 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1524 Actor actor = Actor::New();
1525 actor.SetKeyboardFocusable( true );
1526 Stage::GetCurrent().Add( actor );
1527 manager.SetCurrentFocusActor( actor );
1529 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1530 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1531 Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1532 application.ProcessEvent(rightEvent);
1534 Actor indicatorActor = manager.GetFocusIndicatorActor();
1536 tet_infoline( "Indicator is added to focused actor" );
1537 DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1539 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1540 DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1542 tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1543 DALI_TEST_CHECK( !indicatorActor.GetParent() );
1548 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1550 ToolkitTestApplication application;
1552 tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
1553 Dali::Integration::Scene scene = application.GetScene();
1555 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1556 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1558 // Create the first actor and add it to the stage
1559 Control control = Control::New();
1560 control.SetKeyboardFocusable(true);
1563 KeyEventCallback controlCallback( true );
1564 control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
1566 KeyEventCallback sceneCallback( false );
1567 scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
1569 manager.SetCurrentFocusActor( control );
1571 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1572 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1573 Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1574 application.ProcessEvent(event1);
1576 DALI_TEST_CHECK( controlCallback.mIsCalled );
1577 DALI_TEST_CHECK( !sceneCallback.mIsCalled );
1582 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1584 ToolkitTestApplication application;
1586 tet_infoline( "Ensure Memory focus actors for each window ");
1587 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1588 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1590 Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false);
1591 DALI_TEST_CHECK( firstWindow );
1592 Control first = Control::New();
1593 first.SetKeyboardFocusable(true);
1594 firstWindow.Add(first);
1596 Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false);
1597 DALI_TEST_CHECK( secondWindow );
1598 Control second = Control::New();
1599 second.SetKeyboardFocusable(true);
1600 secondWindow.Add( second );
1602 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1603 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1605 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1606 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1607 firstWindow.Raise();
1608 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1610 secondWindow.Remove( second );
1611 secondWindow.Raise();
1612 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1614 secondWindow.Reset();