2 * Copyright (c) 2022 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>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
27 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
31 #include <dali/integration-api/events/wheel-event-integ.h>
34 using namespace Dali::Toolkit;
36 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
38 test_return_value = TET_UNDEF;
41 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
43 test_return_value = TET_PASS;
48 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
50 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
51 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
54 CustomAlgorithm(bool& interfaceVerified)
55 : mInterfaceVerified(interfaceVerified),
56 mCurrentFocusedActor(),
57 mProposedActorToFocus(),
58 mDirection(Control::KeyboardFocus::LEFT)
62 Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
64 tet_infoline("Verifying CustomAlgorithm()");
66 mInterfaceVerified = true;
68 mCurrentFocusedActor = currentFocusedActor;
69 mProposedActorToFocus = proposedActorToFocus;
70 mDirection = direction;
72 return mProposedActorToFocus;
77 mInterfaceVerified = false;
78 mCurrentFocusedActor = Actor();
79 mProposedActorToFocus = Actor();
80 mDirection = Control::KeyboardFocus::LEFT;
83 bool& mInterfaceVerified;
84 Actor mCurrentFocusedActor;
85 Actor mProposedActorToFocus;
86 Control::KeyboardFocus::Direction mDirection;
89 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
90 class PreFocusChangeCallback : public Dali::ConnectionTracker
93 PreFocusChangeCallback(bool& signalReceived)
94 : mSignalVerified(signalReceived),
95 mCurrentFocusedActor(),
96 mProposedActorToFocus(),
97 mDirection(Control::KeyboardFocus::LEFT)
101 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
103 tet_infoline("Verifying PreFocusChangeCallback()");
105 mSignalVerified = true;
107 mCurrentFocusedActor = currentFocusedActor;
108 mProposedActorToFocus = proposedActorToFocus;
109 mDirection = direction;
111 return mProposedActorToFocus;
116 mSignalVerified = false;
117 mCurrentFocusedActor = Actor();
118 mProposedActorToFocus = Actor();
119 mDirection = Control::KeyboardFocus::LEFT;
122 bool& mSignalVerified;
123 Actor mCurrentFocusedActor;
124 Actor mProposedActorToFocus;
125 Control::KeyboardFocus::Direction mDirection;
128 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
129 class FocusChangedCallback : public Dali::ConnectionTracker
132 FocusChangedCallback(bool& signalReceived)
133 : mSignalVerified(signalReceived),
134 mOriginalFocusedActor(),
135 mCurrentFocusedActor()
139 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
141 tet_infoline("Verifying FocusChangedCallback()");
143 if(originalFocusedActor == mCurrentFocusedActor)
145 mSignalVerified = true;
148 mOriginalFocusedActor = originalFocusedActor;
149 mCurrentFocusedActor = currentFocusedActor;
154 mSignalVerified = false;
157 bool& mSignalVerified;
158 Actor mOriginalFocusedActor;
159 Actor mCurrentFocusedActor;
162 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
163 class FocusGroupChangedCallback : public Dali::ConnectionTracker
166 FocusGroupChangedCallback(bool& signalReceived)
167 : mSignalVerified(signalReceived),
168 mCurrentFocusedActor(),
173 void Callback(Actor currentFocusedActor, bool forward)
175 tet_infoline("Verifying FocusGroupChangedCallback()");
177 mSignalVerified = true;
179 mCurrentFocusedActor = currentFocusedActor;
185 mSignalVerified = false;
188 bool& mSignalVerified;
189 Actor mCurrentFocusedActor;
193 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
194 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
197 FocusedActorActivatedCallback(bool& signalReceived)
198 : mSignalVerified(signalReceived),
203 void Callback(Actor activatedActor)
205 tet_infoline("Verifying FocusedActorActivatedCallback()");
207 mSignalVerified = true;
209 mActivatedActor = activatedActor;
214 mSignalVerified = false;
217 bool& mSignalVerified;
218 Actor mActivatedActor;
221 class KeyEventCallback : public Dali::ConnectionTracker
226 * @param[in] returnValue Set return value of KeyEvent callback.
228 KeyEventCallback(bool consumed)
229 : mConsumed(consumed),
234 bool Callback(Control control, const KeyEvent& keyEvent)
240 void Callback(const KeyEvent& keyEvent)
249 class WheelEventCallback : public Dali::ConnectionTracker
254 * @param[in] returnValue Set return value of WheelEvent callback.
256 WheelEventCallback(bool consumed)
257 : mConsumed(consumed),
262 bool Callback(Actor actor, const WheelEvent& wheelEvent)
268 void Callback(const WheelEvent& wheelEvent)
277 // Used to connect to signals via the ConnectSignal Handle method
278 struct CallbackFunctor
291 int UtcDaliKeyboardFocusManagerGet(void)
293 ToolkitTestApplication application;
295 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
299 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
300 DALI_TEST_CHECK(type);
301 BaseHandle handle = type.CreateInstance();
302 DALI_TEST_CHECK(handle);
304 KeyboardFocusManager manager;
306 manager = KeyboardFocusManager::Get();
307 DALI_TEST_CHECK(manager);
309 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
310 DALI_TEST_CHECK(newManager);
312 // Check that focus manager is a singleton
313 DALI_TEST_CHECK(manager == newManager);
317 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
319 ToolkitTestApplication application;
321 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
323 KeyboardFocusManager manager = KeyboardFocusManager::Get();
324 DALI_TEST_CHECK(manager);
326 // Create the first actor and add it to the stage
327 Actor first = Actor::New();
328 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
329 application.GetScene().Add(first);
331 // Create the second actor and add it to the stage
332 Actor second = Actor::New();
333 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
334 application.GetScene().Add(second);
336 // Create the third actor but don't add it to the stage
337 Actor third = Actor::New();
339 // Check that no actor is being focused yet.
340 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
342 // Check that it will fail to set focus on an invalid actor
343 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
345 // Check that the focus is set on the first actor
346 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
347 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
349 // Check that the focus is set on the second actor
350 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
351 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
353 // Check that it will fail to set focus on the third actor as it's not in the stage
354 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
355 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
357 // Add the third actor to the stage
358 application.GetScene().Add(third);
360 // Check that it will fail to set focus on the third actor as it's not focusable
361 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
362 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
364 // Make the third actor focusable
365 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
367 // Check that the focus is successfully moved to the third actor
368 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
369 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
373 int UtcDaliKeyboardFocusManagerMoveFocus(void)
375 ToolkitTestApplication application;
377 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
381 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
382 DALI_TEST_CHECK(type);
383 BaseHandle handle = type.CreateInstance();
384 DALI_TEST_CHECK(handle);
386 KeyboardFocusManager manager = KeyboardFocusManager::Get();
387 DALI_TEST_CHECK(manager);
389 bool preFocusChangeSignalVerified = false;
390 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
391 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
393 bool focusChangedSignalVerified = false;
394 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
395 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
397 // Create the first actor and add it to the stage
398 Actor first = Actor::New();
399 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
400 application.GetScene().Add(first);
402 // Create the second actor and add it to the stage
403 Actor second = Actor::New();
404 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
405 application.GetScene().Add(second);
407 // Move the focus to the right
408 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
410 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
411 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
412 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
413 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
414 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
415 preFocusChangeCallback.Reset();
417 // Check that the focus is set on the first actor
418 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
419 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
420 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
421 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
422 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
423 focusChangedCallback.Reset();
425 // Move the focus towards right
426 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
428 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
429 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
430 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
431 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
432 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
433 preFocusChangeCallback.Reset();
435 // Check that the focus is set on the second actor
436 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
437 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
438 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
439 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
440 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
441 focusChangedCallback.Reset();
443 // Move the focus towards up
444 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
446 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
447 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
448 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
449 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
450 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
451 preFocusChangeCallback.Reset();
452 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
454 // Create a 2x2 table view and try to move focus inside it
455 TableView tableView = TableView::New(2, 2);
456 application.GetScene().Add(tableView);
458 // Create the third actor
459 Actor third = Actor::New();
460 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
462 // Create the fourth actor
463 Actor fourth = Actor::New();
464 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
466 // Add the four children to table view
467 tableView.AddChild(first, TableView::CellPosition(0, 0));
468 tableView.AddChild(second, TableView::CellPosition(0, 1));
469 tableView.AddChild(third, TableView::CellPosition(1, 0));
470 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
472 // Set the focus to the first actor
473 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
474 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
475 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
476 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
477 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
478 focusChangedCallback.Reset();
480 // Move the focus towards right
481 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
482 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
483 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
484 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
485 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
486 focusChangedCallback.Reset();
488 // Move the focus towards down
489 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
490 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
491 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
492 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
493 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
494 focusChangedCallback.Reset();
496 // Move the focus towards left
497 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
498 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
499 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
500 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
501 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
502 focusChangedCallback.Reset();
504 // Move the focus towards up
505 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
506 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
507 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
508 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
509 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
510 focusChangedCallback.Reset();
512 // Move the focus towards left. The focus move will fail as no way to move it upwards
513 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
514 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
515 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
516 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
517 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
518 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
519 preFocusChangeCallback.Reset();
520 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
523 manager.SetFocusGroupLoop(true);
524 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
526 // Move the focus towards left again. The focus should move to the fourth actor.
527 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
528 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
529 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
530 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
531 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
532 focusChangedCallback.Reset();
536 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
538 ToolkitTestApplication application;
540 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
544 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
545 DALI_TEST_CHECK(type);
546 BaseHandle handle = type.CreateInstance();
547 DALI_TEST_CHECK(handle);
549 KeyboardFocusManager manager = KeyboardFocusManager::Get();
550 DALI_TEST_CHECK(manager);
552 bool preFocusChangeSignalVerified = false;
553 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
554 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
556 bool focusChangedSignalVerified = false;
557 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
558 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
560 // Create the first actor and add it to the stage
561 Actor first = Actor::New();
562 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
563 application.GetScene().Add(first);
565 // Create the second actor and add it to the stage
566 Actor second = Actor::New();
567 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
568 application.GetScene().Add(second);
570 // Move the focus to the right
571 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
573 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
574 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
575 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
576 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
577 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
578 preFocusChangeCallback.Reset();
580 bool customAlgorithmInterfaceVerified = false;
581 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
582 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
584 // Move the focus towards right
585 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
587 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
588 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
589 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
590 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
591 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
592 customAlgorithm.Reset();
594 // Check that the focus is set on the first actor
595 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
596 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
597 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
598 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
599 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
600 focusChangedCallback.Reset();
602 // Move the focus towards right
603 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
605 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
606 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
607 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
608 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
609 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
610 customAlgorithm.Reset();
612 // Check that the focus is set on the second actor
613 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
614 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
615 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
616 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
617 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
618 focusChangedCallback.Reset();
620 // Move the focus towards up
621 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
623 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
624 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
625 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
626 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
627 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
628 customAlgorithm.Reset();
629 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
633 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
635 ToolkitTestApplication application;
637 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
641 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
642 DALI_TEST_CHECK(type);
643 BaseHandle handle = type.CreateInstance();
644 DALI_TEST_CHECK(handle);
646 KeyboardFocusManager manager = KeyboardFocusManager::Get();
647 DALI_TEST_CHECK(manager);
649 bool focusChangedSignalVerified = false;
650 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
651 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
653 PushButton button1 = PushButton::New();
654 PushButton button2 = PushButton::New();
655 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
656 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
657 application.GetScene().Add(button1);
658 application.GetScene().Add(button2);
660 // Set the focus to the button1
661 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
662 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
663 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
664 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
665 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
666 focusChangedCallback.Reset();
668 // set the navigation properties of button1
669 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
670 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
671 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
672 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
673 button1.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID)));
674 button1.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID)));
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 button2.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID)));
682 button2.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID)));
684 // Move the focus towards left
685 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
687 // Confirm whether focus is moved to button2
688 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
689 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
690 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
691 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
692 focusChangedCallback.Reset();
694 // Move the focus towards right
695 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
697 // Confirm whether focus is moved to button1
698 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
699 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
700 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
701 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
702 focusChangedCallback.Reset();
704 // Move the focus towards up
705 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
707 // Confirm whether focus is moved to button2
708 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
709 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
710 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
711 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
712 focusChangedCallback.Reset();
714 // Move the focus towards down
715 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
717 // Confirm whether focus is moved to button1
718 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
719 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
720 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
721 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
722 focusChangedCallback.Reset();
724 // Move the focus towards clockwise
725 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::CLOCKWISE) == true);
727 // Confirm whether focus is moved to button2
728 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
729 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
730 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
731 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
732 focusChangedCallback.Reset();
734 // Move the focus towards clockwise
735 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::COUNTER_CLOCKWISE) == true);
737 // Confirm whether focus is moved to button1
738 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
739 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
740 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
741 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
742 focusChangedCallback.Reset();
744 // Create a 1x1 table view and try to move focus inside it
745 TableView tableView = TableView::New(1, 1);
746 application.GetScene().Add(tableView);
748 PushButton button = PushButton::New();
749 button.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
750 tableView.AddChild(button, TableView::CellPosition(0, 0));
752 // set the navigation properties of button3
753 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
755 // Set the focus to the button
756 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
757 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
758 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
759 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
760 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
761 focusChangedCallback.Reset();
763 // Move the focus towards left
764 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
766 // Confirm whether focus is moved to button1
767 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
768 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
769 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
770 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
771 focusChangedCallback.Reset();
776 int UtcDaliKeyboardFocusManagerClearFocus(void)
778 ToolkitTestApplication application;
780 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
782 KeyboardFocusManager manager = KeyboardFocusManager::Get();
783 DALI_TEST_CHECK(manager);
785 // Create the first actor and add it to the stage
786 Actor first = Actor::New();
787 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
788 application.GetScene().Add(first);
790 // Create the second actor and add it to the stage
791 Actor second = Actor::New();
792 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
793 application.GetScene().Add(second);
795 // Check that the focus is set on the first actor
796 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
797 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
799 // Check that the focus is set on the second actor
800 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
801 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
804 manager.ClearFocus();
806 // Check that no actor is being focused now.
807 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
811 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
813 ToolkitTestApplication application;
815 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
817 KeyboardFocusManager manager = KeyboardFocusManager::Get();
818 DALI_TEST_CHECK(manager);
820 // Check that the focus movement is not looped within the same focus group by default
821 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
824 manager.SetFocusGroupLoop(true);
825 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
829 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
831 ToolkitTestApplication application;
833 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
835 KeyboardFocusManager manager = KeyboardFocusManager::Get();
836 DALI_TEST_CHECK(manager);
838 // Create an actor and check that it is not a focus group by default
839 Actor actor = Actor::New();
840 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
842 // Set the actor as focus group
843 manager.SetAsFocusGroup(actor, true);
845 // flush the queue and render once
846 application.SendNotification();
847 application.Render();
849 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
851 // Set the actor not as focus group
852 manager.SetAsFocusGroup(actor, false);
854 // flush the queue and render once
855 application.SendNotification();
856 application.Render();
858 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
862 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
864 ToolkitTestApplication application;
866 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
868 KeyboardFocusManager manager = KeyboardFocusManager::Get();
869 DALI_TEST_CHECK(manager);
871 // Create an actor with two child actors and add it to the stage
872 Actor parent = Actor::New();
873 Actor child = Actor::New();
875 application.GetScene().Add(parent);
877 // Create three actors and add them as the children of the first child actor
878 Actor grandChild = Actor::New();
879 child.Add(grandChild);
881 // Set the parent and the first child actor as focus groups
882 manager.SetAsFocusGroup(parent, true);
884 // flush the queue and render once
885 application.SendNotification();
886 application.Render();
888 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
890 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
891 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
893 manager.SetAsFocusGroup(child, true);
895 // flush the queue and render once
896 application.SendNotification();
897 application.Render();
899 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
901 // The focus group should be the child, As it is the immediate parent which is also a focus group.
902 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
904 manager.SetAsFocusGroup(grandChild, true);
906 // flush the queue and render once
907 application.SendNotification();
908 application.Render();
910 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
912 // The current focus group should be itself, As it is also a focus group.
913 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
917 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
919 ToolkitTestApplication application;
921 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
923 KeyboardFocusManager manager = KeyboardFocusManager::Get();
924 DALI_TEST_CHECK(manager);
926 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
927 DALI_TEST_CHECK(defaultFocusIndicatorActor);
929 Actor newFocusIndicatorActor = Actor::New();
930 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
931 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
935 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
937 ToolkitTestApplication application;
939 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
941 KeyboardFocusManager manager = KeyboardFocusManager::Get();
942 DALI_TEST_CHECK(manager);
944 bool focusedActorActivatedSignalVerified = false;
945 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
946 manager.FocusedActorEnterKeySignal().Connect(&focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback);
948 Integration::KeyEvent returnEvent("Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
950 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
951 // It makes mIsFocusIndicatorEnabled true
952 application.ProcessEvent(returnEvent);
954 // Create the first button and add it to the stage
955 PushButton firstPushButton = PushButton::New();
956 firstPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
957 application.GetScene().Add(firstPushButton);
959 // Create the second button and add it to the stage
960 PushButton secondPushButton = PushButton::New();
961 secondPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
962 application.GetScene().Add(secondPushButton);
964 // Check that the focus is set on the first button
965 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
966 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
968 // Send the return event to activate the first button
969 application.ProcessEvent(returnEvent);
970 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
971 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
972 focusedActorActivatedCallback.Reset();
974 // Check that the focus is set on the second button
975 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
976 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
978 // Send the return event again to activate the second button
979 application.ProcessEvent(returnEvent);
980 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
981 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
982 focusedActorActivatedCallback.Reset();
986 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
988 ToolkitTestApplication application;
990 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
994 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
995 DALI_TEST_CHECK(type);
996 BaseHandle handle = type.CreateInstance();
997 DALI_TEST_CHECK(handle);
999 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1000 DALI_TEST_CHECK(manager);
1002 bool focusGroupChangedSignalVerified = false;
1003 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
1004 manager.FocusGroupChangedSignal().Connect(&focusGroupChangedCallback, &FocusGroupChangedCallback::Callback);
1006 Integration::KeyEvent tabEvent("Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1007 Integration::KeyEvent shiftTabEvent("Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1009 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1010 // It makes mIsFocusIndicatorEnabled true
1011 application.ProcessEvent(tabEvent);
1013 // Send the tab event to change focus group in the forward direction
1014 application.ProcessEvent(tabEvent);
1015 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1016 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1017 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
1018 focusGroupChangedCallback.Reset();
1020 // Send the shift tab event to change focus group in the backward direction
1021 application.ProcessEvent(shiftTabEvent);
1022 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1023 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1024 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1025 focusGroupChangedCallback.Reset();
1029 int UtcDaliKeyboardFocusManagerSignals(void)
1031 ToolkitTestApplication application;
1033 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1034 DALI_TEST_CHECK(manager);
1036 ConnectionTracker* testTracker = new ConnectionTracker();
1037 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardPreFocusChange", CallbackFunctor()), TEST_LOCATION);
1038 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusChanged", CallbackFunctor()), TEST_LOCATION);
1039 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusGroupChanged", CallbackFunctor()), TEST_LOCATION);
1040 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor()), TEST_LOCATION);
1045 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1047 ToolkitTestApplication application;
1049 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1051 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1052 DALI_TEST_CHECK(manager);
1054 // Create the first actor and add it to the stage
1055 Actor first = Actor::New();
1056 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1057 application.GetScene().Add(first);
1059 // Create the second actor and add it to the stage
1060 Actor second = Actor::New();
1061 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1062 application.GetScene().Add(second);
1064 // Create the third actor and add it to the stage
1065 Actor third = Actor::New();
1066 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1067 application.GetScene().Add(third);
1069 // Create the fourth actor and add it to the stage
1070 Actor fourth = Actor::New();
1071 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1072 application.GetScene().Add(fourth);
1074 // Check that the focus is set on the second actor
1075 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1076 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1078 // Check that the focus is set on the second actor
1079 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1080 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1082 // Check that the focus is set on the third actor
1083 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1084 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1086 // Check that the focus is set on the third actor
1087 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1088 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1090 // Move the focus backward
1091 manager.MoveFocusBackward();
1093 // Check that it current focused actor is third actor
1094 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1096 // Remove the second actor on stage
1099 // Reset the first actor
1103 // Move the focus backward
1104 manager.MoveFocusBackward();
1106 // Check that it current focused actor is third actor
1107 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1109 // Make history stack full
1110 for(int i = 0; i < 31; i++)
1112 Actor actor = Actor::New();
1113 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1114 application.GetScene().Add(actor);
1115 manager.SetCurrentFocusActor(actor);
1118 for(int i = 0; i < 31; i++)
1120 manager.MoveFocusBackward();
1123 // Check that it current focused actor is not second actor
1124 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1129 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1131 ToolkitTestApplication application;
1133 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1135 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1136 DALI_TEST_CHECK(manager);
1138 bool preFocusChangeSignalVerified = false;
1139 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1140 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1142 bool focusChangedSignalVerified = false;
1143 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1144 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1146 Integration::KeyEvent leftEvent("Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1147 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1148 Integration::KeyEvent upEvent("Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1149 Integration::KeyEvent downEvent("Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1150 Integration::KeyEvent pageUpEvent("Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1151 Integration::KeyEvent pageDownEvent("Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1153 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1154 // It makes mIsFocusIndicatorEnabled true
1155 application.ProcessEvent(leftEvent);
1157 // Create a 2x2 table view and try to move focus inside it
1158 TableView tableView = TableView::New(2, 2);
1159 application.GetScene().Add(tableView);
1161 // Create the first actor
1162 Actor first = Actor::New();
1163 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1165 // Create the second actor
1166 Actor second = Actor::New();
1167 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1169 // Create the third actor
1170 Actor third = Actor::New();
1171 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1173 // Create the fourth actor
1174 Actor fourth = Actor::New();
1175 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1177 // Add the four children to table view
1178 tableView.AddChild(first, TableView::CellPosition(0, 0));
1179 tableView.AddChild(second, TableView::CellPosition(0, 1));
1180 tableView.AddChild(third, TableView::CellPosition(1, 0));
1181 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1183 // Set the focus to the first actor
1184 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1185 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1186 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1187 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1188 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1189 focusChangedCallback.Reset();
1191 // Send the right key event to move the focus towards right
1192 application.ProcessEvent(rightEvent);
1193 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1194 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1195 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1196 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1197 focusChangedCallback.Reset();
1199 // Send the down key event to move the focus towards down
1200 application.ProcessEvent(downEvent);
1201 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1202 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1203 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1204 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1205 focusChangedCallback.Reset();
1207 // Send the down event to move the focus towards left
1208 application.ProcessEvent(leftEvent);
1209 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1210 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1211 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1212 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1213 focusChangedCallback.Reset();
1215 // Send the up event to move the focus towards up
1216 application.ProcessEvent(upEvent);
1217 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1218 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1219 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1220 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1221 focusChangedCallback.Reset();
1223 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1224 application.ProcessEvent(pageUpEvent);
1225 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1226 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1227 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1228 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1229 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1230 preFocusChangeCallback.Reset();
1232 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1233 application.ProcessEvent(pageDownEvent);
1234 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1235 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1236 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1237 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1238 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1239 preFocusChangeCallback.Reset();
1242 manager.ClearFocus();
1244 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1245 preFocusChangeCallback.Reset();
1246 application.ProcessEvent(pageUpEvent);
1247 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1248 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1249 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1250 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1251 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1253 // Clear the focus again
1254 manager.ClearFocus();
1256 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1257 preFocusChangeCallback.Reset();
1258 application.ProcessEvent(pageDownEvent);
1259 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1260 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1261 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1262 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1263 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1265 // Clear the focus again
1266 manager.ClearFocus();
1268 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1269 preFocusChangeCallback.Reset();
1270 application.ProcessEvent(upEvent);
1271 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1272 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1273 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1274 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1276 // Clear the focus again
1277 manager.ClearFocus();
1279 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1280 preFocusChangeCallback.Reset();
1281 application.ProcessEvent(downEvent);
1282 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1283 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1284 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1285 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1290 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1292 ToolkitTestApplication application;
1294 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1296 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1297 DALI_TEST_CHECK(manager);
1299 bool preFocusChangeSignalVerified = false;
1300 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1301 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1303 Integration::KeyEvent spaceEvent("space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1305 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1306 // It makes mIsFocusIndicatorEnabled true
1307 application.ProcessEvent(spaceEvent);
1309 // Send the space event
1310 application.ProcessEvent(spaceEvent);
1311 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1312 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1314 // Clear the focus again
1315 manager.ClearFocus();
1317 // Send the space event again for line coverage
1318 preFocusChangeCallback.Reset();
1319 application.ProcessEvent(spaceEvent);
1320 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1321 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1322 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1323 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1328 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1330 ToolkitTestApplication application;
1332 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1336 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1337 DALI_TEST_CHECK(type);
1338 BaseHandle handle = type.CreateInstance();
1339 DALI_TEST_CHECK(handle);
1341 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1342 DALI_TEST_CHECK(manager);
1344 bool preFocusChangeSignalVerified = false;
1345 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1346 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1348 bool focusChangedSignalVerified = false;
1349 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1350 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1352 // Create the first actor and add it to the stage
1353 Control first = Control::New();
1354 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1355 application.GetScene().Add(first);
1357 // Create the second actor and add it to the stage
1358 Control second = Control::New();
1359 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1360 application.GetScene().Add(second);
1362 // Move the focus to the right
1363 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1365 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1366 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1367 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1368 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1369 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1370 preFocusChangeCallback.Reset();
1372 // Check that the focus is set on the first actor
1373 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1374 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1375 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1376 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1377 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1378 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1379 focusChangedCallback.Reset();
1381 // Move the focus towards right
1382 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1384 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1385 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1386 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1387 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1388 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1389 preFocusChangeCallback.Reset();
1391 // Check that the focus is set on the second actor
1392 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1393 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1394 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1395 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1396 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1397 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1398 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1399 focusChangedCallback.Reset();
1401 // Move the focus towards up
1402 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1404 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1405 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1406 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1407 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1408 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1409 preFocusChangeCallback.Reset();
1410 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1412 // Create a 2x2 table view and try to move focus inside it
1413 TableView tableView = TableView::New(2, 2);
1414 application.GetScene().Add(tableView);
1416 // Create the third actor
1417 Control third = Control::New();
1418 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1420 // Create the fourth actor
1421 Control fourth = Control::New();
1422 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1424 // Add the four children to table view
1425 tableView.AddChild(first, TableView::CellPosition(0, 0));
1426 tableView.AddChild(second, TableView::CellPosition(0, 1));
1427 tableView.AddChild(third, TableView::CellPosition(1, 0));
1428 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1430 // Set the focus to the first actor
1431 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1432 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1433 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1434 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1435 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);
1440 focusChangedCallback.Reset();
1442 // Move the focus towards right
1443 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1444 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1445 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1446 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1447 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1448 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1449 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1451 focusChangedCallback.Reset();
1453 // Move the focus towards down
1454 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1455 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1456 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1457 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1458 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1460 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1461 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1462 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1463 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1465 focusChangedCallback.Reset();
1467 // Move the focus towards left
1468 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1469 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1470 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1471 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1472 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1474 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1475 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1476 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1477 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1479 focusChangedCallback.Reset();
1481 // Move the focus towards up
1482 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1483 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1484 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1485 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1486 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1487 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1488 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1489 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1490 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1491 focusChangedCallback.Reset();
1493 // Move the focus towards left. The focus move will fail as no way to move it upwards
1494 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1495 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1496 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1497 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1498 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1499 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1500 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, 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::NORMAL, TEST_LOCATION);
1505 preFocusChangeCallback.Reset();
1506 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1509 manager.SetFocusGroupLoop(true);
1510 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1512 // Move the focus towards left again. The focus should move to the fourth actor.
1513 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1514 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1515 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1516 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1517 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1519 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1520 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1521 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1522 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1524 focusChangedCallback.Reset();
1527 manager.ClearFocus();
1528 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1529 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1530 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1531 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1536 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1538 ToolkitTestApplication application;
1540 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");
1542 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1543 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1545 Actor actor = Actor::New();
1546 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1548 tet_infoline("Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager");
1549 manager.SetCurrentFocusActor(actor);
1550 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1552 tet_infoline("Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager");
1553 application.GetScene().Add(actor);
1554 manager.SetCurrentFocusActor(actor);
1555 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == actor);
1557 tet_infoline("Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager");
1559 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1564 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1566 ToolkitTestApplication application;
1568 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");
1570 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1571 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1573 Actor actor = Actor::New();
1574 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1575 application.GetScene().Add(actor);
1576 manager.SetCurrentFocusActor(actor);
1578 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1579 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1580 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1581 application.ProcessEvent(rightEvent);
1583 Actor indicatorActor = manager.GetFocusIndicatorActor();
1585 tet_infoline("Indicator is added to focused actor");
1586 DALI_TEST_CHECK(actor == indicatorActor.GetParent());
1588 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1589 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager));
1591 tet_infoline("Indicator is removed from focused actor because mUseFocusIndicator is false");
1592 DALI_TEST_CHECK(!indicatorActor.GetParent());
1597 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1599 ToolkitTestApplication application;
1601 tet_infoline("Ensure Window can't receive KeyEvent when Control already consumed it");
1602 Dali::Integration::Scene scene = application.GetScene();
1604 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1605 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1607 // Create the first actor and add it to the stage
1608 Control control = Control::New();
1609 control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1612 KeyEventCallback controlCallback(true);
1613 control.KeyEventSignal().Connect(&controlCallback, &KeyEventCallback::Callback);
1615 KeyEventCallback sceneCallback(false);
1616 scene.KeyEventSignal().Connect(&sceneCallback, &KeyEventCallback::Callback);
1618 manager.SetCurrentFocusActor(control);
1620 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1621 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1622 Integration::KeyEvent event1("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1623 application.ProcessEvent(event1);
1625 DALI_TEST_CHECK(controlCallback.mIsCalled);
1626 DALI_TEST_CHECK(!sceneCallback.mIsCalled);
1631 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1633 ToolkitTestApplication application;
1635 tet_infoline("Ensure Memory focus actors for each window ");
1636 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1637 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1639 Window firstWindow = Window::New(PositionSize(0, 0, 300, 500), "", false);
1640 DALI_TEST_CHECK(firstWindow);
1641 Control first = Control::New();
1642 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1643 firstWindow.Add(first);
1645 Window secondWindow = Window::New(PositionSize(0, 0, 400, 600), "", false);
1646 DALI_TEST_CHECK(secondWindow);
1647 Control second = Control::New();
1648 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1649 secondWindow.Add(second);
1651 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1652 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1654 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1655 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1656 firstWindow.Raise();
1657 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1659 secondWindow.Remove(second);
1660 secondWindow.Raise();
1661 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1663 secondWindow.Reset();
1667 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1669 ToolkitTestApplication application;
1671 tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1675 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1676 DALI_TEST_CHECK(type);
1677 BaseHandle handle = type.CreateInstance();
1678 DALI_TEST_CHECK(handle);
1680 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1681 DALI_TEST_CHECK(manager);
1683 bool focusChangedSignalVerified = false;
1684 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1685 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1687 PushButton button1 = PushButton::New();
1688 PushButton button2 = PushButton::New();
1689 PushButton button3 = PushButton::New();
1690 PushButton button4 = PushButton::New();
1691 PushButton button5 = PushButton::New();
1693 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1694 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1695 button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1696 button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1697 button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1699 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1700 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1701 button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1702 button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1703 button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1705 application.GetScene().Add(button1);
1706 application.GetScene().Add(button2);
1707 application.GetScene().Add(button3);
1708 button5.Add(button4);
1709 application.GetScene().Add(button5);
1712 // button1 -- button2
1715 // button3 -- button4
1716 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1717 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1718 button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1719 button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1720 button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1722 // flush the queue and render once
1723 application.SendNotification();
1724 application.Render();
1726 // Set the focus to the button1
1727 // [button1] -- button2
1730 // button3 -- button4
1731 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1732 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1733 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1734 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1735 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1736 focusChangedCallback.Reset();
1738 // without set the navigation properties, but we can focus move
1739 // enable the default algorithm
1740 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1741 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1743 // Move the focus towards right
1744 // button1 -- [button2]
1747 // button3 -- button4
1748 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1750 // Confirm whether focus is moved to button2
1751 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1752 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1753 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1754 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1755 focusChangedCallback.Reset();
1757 // Move the focus towards down
1758 // button1 -- button2
1761 // button3 -- button4
1762 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1764 // Confirm whether focus is moved to button5
1765 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1766 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1767 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1768 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1769 focusChangedCallback.Reset();
1771 // Move the focus towards right
1772 // button1 -- button2
1775 // button3 -- [button4]
1776 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1778 // Confirm whether focus is moved to button4
1779 DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1780 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1781 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1782 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1783 focusChangedCallback.Reset();
1785 // Move the focus towards left
1786 // button1 -- button2
1789 // button3 -- button4
1790 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1792 // Confirm whether focus is moved to button5
1793 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1794 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1795 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1796 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1797 focusChangedCallback.Reset();
1799 // Move the focus towards left
1800 // button1 -- button2
1803 //[button3] -- button4
1804 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1806 // Confirm whether focus is moved to button3
1807 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1808 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1809 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1810 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1811 focusChangedCallback.Reset();
1813 // Move the focus towards right
1814 // button1 -- button2
1817 // button3 -- button4
1818 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1820 // Confirm whether focus is moved to button5
1821 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1822 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1823 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1824 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1825 focusChangedCallback.Reset();
1827 // Move the focus towards left
1828 // button1 -- button2
1831 //[button3] -- button4
1832 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1834 // Confirm whether focus is moved to button3
1835 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1836 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1837 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1838 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1839 focusChangedCallback.Reset();
1841 // Move the focus towards up
1842 //[button1]-- button2
1845 // button3 -- button4
1846 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1848 // Confirm whether focus is moved to button1
1849 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1850 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1851 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1852 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1853 focusChangedCallback.Reset();
1855 // Move the focus towards left. The focus move will fail as no way to move it upwards
1856 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1858 // Move the focus toward page up/down. The focus move will fail as invalid direction.
1859 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1860 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1861 focusChangedCallback.Reset();
1866 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode(void)
1868 ToolkitTestApplication application;
1870 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode");
1872 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1873 DALI_TEST_CHECK(manager);
1875 // Create the first actor and add it to the stage
1876 Actor first = Actor::New();
1877 first.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1878 first.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1879 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1880 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1881 first.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1882 application.GetScene().Add(first);
1884 // Create the second actor and add it to the stage
1885 Actor second = Actor::New();
1886 second.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1887 second.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1888 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1889 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1890 application.GetScene().Add(second);
1892 // flush the queue and render once
1893 application.SendNotification();
1894 application.Render();
1896 // Check that no actor is being focused yet.
1897 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1899 // Check that it will fail to set focus on an invalid actor
1900 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
1902 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1903 Dali::Integration::Point pointDown1;
1904 pointDown1.SetState(PointState::DOWN);
1905 pointDown1.SetDeviceId(1);
1906 // touch first actor
1907 pointDown1.SetScreenPosition(Vector2(10.0f, 10.0f));
1908 event1.AddPoint(pointDown1);
1909 application.ProcessEvent(event1);
1911 // flush the queue and render once
1912 application.SendNotification();
1913 application.Render();
1915 // Check that the focus is successfully to the first actor
1916 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1918 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1919 Dali::Integration::Point pointDown2;
1920 pointDown2.SetState(PointState::DOWN);
1921 pointDown2.SetDeviceId(1);
1922 // touch second actor
1923 pointDown2.SetScreenPosition(Vector2(110.0f, 10.0f));
1924 event2.AddPoint(pointDown2);
1925 application.ProcessEvent(event2);
1927 // flush the queue and render once
1928 application.SendNotification();
1929 application.Render();
1931 // Check that the focus is successfully to clear
1932 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1934 // Make the second actor focusableInTouchMode
1935 second.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1937 // touch second actor
1938 application.ProcessEvent(event2);
1940 // flush the queue and render once
1941 application.SendNotification();
1942 application.Render();
1944 // Check that the focus is successfully to the second actor
1945 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1950 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1952 ToolkitTestApplication application;
1954 tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1958 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1959 DALI_TEST_CHECK(type);
1960 BaseHandle handle = type.CreateInstance();
1961 DALI_TEST_CHECK(handle);
1963 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1964 DALI_TEST_CHECK(manager);
1966 bool focusChangedSignalVerified = false;
1967 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1968 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1970 PushButton button1 = PushButton::New();
1971 PushButton button2 = PushButton::New();
1973 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1974 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1976 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1977 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1979 application.GetScene().Add(button1);
1980 application.GetScene().Add(button2);
1983 // button1 -- button2
1984 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1985 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1987 // flush the queue and render once
1988 application.SendNotification();
1989 application.Render();
1991 // Set the focus to the button1
1992 // [button1] -- button2
1993 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1994 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1995 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1996 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1997 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1998 focusChangedCallback.Reset();
2000 // without set the navigation properties, but we can focus move
2001 // enable the default algorithm
2002 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2003 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2005 // Move the focus towards right
2006 // button1 -- [button2]
2007 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2009 // Confirm whether focus is moved to button2
2010 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2011 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2012 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
2013 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
2014 focusChangedCallback.Reset();
2016 // disable the default algorithm
2017 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
2018 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2020 // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
2021 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
2023 // enable the default algorithm
2024 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2025 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2027 // Move the focus towards left, The focus move will success because the default algorithm is enabled.
2028 // [button1] -- button2
2029 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2030 // Confirm whether focus is moved to button2
2031 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2032 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2033 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2034 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2035 focusChangedCallback.Reset();
2040 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2042 ToolkitTestApplication application;
2044 tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2046 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2047 DALI_TEST_CHECK(manager);
2049 // Create the first actor and add it to the stage
2050 Actor first = Actor::New();
2051 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2052 application.GetScene().Add(first);
2054 // Create the second actor and add it to the first actor.
2055 Actor second = Actor::New();
2056 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2059 // Check that no actor is being focused yet.
2060 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2062 // Check that the focus is set on the first actor
2063 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2064 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2066 // Set KeyboardFocusableChildren false.
2067 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2069 // Check that it will fail to set focus on the second actor as it's not focusable
2070 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2071 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2073 // Set KeyboardFocusableChildren true.
2074 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2076 // Check that the focus is set on the second actor
2077 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2078 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2083 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2085 ToolkitTestApplication application;
2087 tet_infoline("UtcDaliKeyboardFocusManagerCheckWheelEvent");
2088 Dali::Integration::Scene scene = application.GetScene();
2090 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2091 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
2093 // Create the first actor and add it to the stage
2094 Actor parent = Actor::New();
2095 parent.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2097 Actor child = Actor::New();
2098 child.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2103 WheelEventCallback childCallback(false);
2104 child.WheelEventSignal().Connect(&childCallback, &WheelEventCallback::Callback);
2106 WheelEventCallback parentCallback(true);
2107 parent.WheelEventSignal().Connect(&parentCallback, &WheelEventCallback::Callback);
2109 WheelEventCallback sceneCallback(false);
2110 scene.WheelEventSignal().Connect(&sceneCallback, &WheelEventCallback::Callback);
2112 manager.SetCurrentFocusActor(child);
2114 // Emit custom wheel event is comming to KeyboardFocusManager
2115 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2116 application.ProcessEvent(event);
2118 DALI_TEST_CHECK(childCallback.mIsCalled);
2119 DALI_TEST_CHECK(parentCallback.mIsCalled);
2120 DALI_TEST_CHECK(!sceneCallback.mIsCalled);
2125 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByCustomWheelEvent(void)
2127 ToolkitTestApplication application;
2129 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByCustomWheelEvent");
2130 Dali::Integration::Scene scene = application.GetScene();
2132 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2133 DALI_TEST_CHECK(manager);
2135 bool focusChangedSignalVerified = false;
2136 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
2137 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
2139 Integration::WheelEvent clockwiseEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2140 Integration::WheelEvent counterClockwiseEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1100u);
2142 // Create the first button
2143 PushButton first = PushButton::New();
2144 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2147 // Create the second button
2148 PushButton second = PushButton::New();
2149 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2152 // set the navigation properties
2153 first.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)second.GetProperty< int >( Actor::Property::ID )));
2154 second.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)first.GetProperty< int >( Actor::Property::ID )));
2156 // Set the focus to the first actor
2157 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2158 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2159 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2160 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2161 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
2162 focusChangedCallback.Reset();
2164 // Send the clockwise wheel event to move the focus towards clockwise
2165 application.ProcessEvent(clockwiseEvent);
2166 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2167 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2168 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
2169 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
2170 focusChangedCallback.Reset();
2172 // Send the counter clockwise wheel event to move the focus towards count clockwise
2173 application.ProcessEvent(counterClockwiseEvent);
2174 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2175 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2176 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
2177 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
2178 focusChangedCallback.Reset();
2181 manager.ClearFocus();