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)));
674 // set the navigation properties of button2
675 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
676 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
677 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
678 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
680 // Move the focus towards left
681 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
683 // Confirm whether focus is moved to button2
684 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
685 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
686 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
687 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
688 focusChangedCallback.Reset();
690 // Move the focus towards right
691 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
693 // Confirm whether focus is moved to button1
694 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
695 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
696 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
697 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
698 focusChangedCallback.Reset();
700 // Move the focus towards up
701 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
703 // Confirm whether focus is moved to button2
704 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
705 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
706 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
707 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
708 focusChangedCallback.Reset();
710 // Move the focus towards down
711 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == 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 == button2);
717 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
718 focusChangedCallback.Reset();
720 // Create a 1x1 table view and try to move focus inside it
721 TableView tableView = TableView::New(1, 1);
722 application.GetScene().Add(tableView);
724 PushButton button = PushButton::New();
725 button.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
726 tableView.AddChild(button, TableView::CellPosition(0, 0));
728 // set the navigation properties of button3
729 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
731 // Set the focus to the button
732 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
733 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
734 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
735 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
736 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
737 focusChangedCallback.Reset();
739 // Move the focus towards left
740 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
742 // Confirm whether focus is moved to button1
743 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
744 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
745 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
746 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
747 focusChangedCallback.Reset();
752 int UtcDaliKeyboardFocusManagerClearFocus(void)
754 ToolkitTestApplication application;
756 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
758 KeyboardFocusManager manager = KeyboardFocusManager::Get();
759 DALI_TEST_CHECK(manager);
761 // Create the first actor and add it to the stage
762 Actor first = Actor::New();
763 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
764 application.GetScene().Add(first);
766 // Create the second actor and add it to the stage
767 Actor second = Actor::New();
768 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
769 application.GetScene().Add(second);
771 // Check that the focus is set on the first actor
772 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
773 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
775 // Check that the focus is set on the second actor
776 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
777 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
780 manager.ClearFocus();
782 // Check that no actor is being focused now.
783 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
787 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
789 ToolkitTestApplication application;
791 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
793 KeyboardFocusManager manager = KeyboardFocusManager::Get();
794 DALI_TEST_CHECK(manager);
796 // Check that the focus movement is not looped within the same focus group by default
797 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
800 manager.SetFocusGroupLoop(true);
801 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
805 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
807 ToolkitTestApplication application;
809 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
811 KeyboardFocusManager manager = KeyboardFocusManager::Get();
812 DALI_TEST_CHECK(manager);
814 // Create an actor and check that it is not a focus group by default
815 Actor actor = Actor::New();
816 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
818 // Set the actor as focus group
819 manager.SetAsFocusGroup(actor, true);
821 // flush the queue and render once
822 application.SendNotification();
823 application.Render();
825 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
827 // Set the actor not as focus group
828 manager.SetAsFocusGroup(actor, false);
830 // flush the queue and render once
831 application.SendNotification();
832 application.Render();
834 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
838 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
840 ToolkitTestApplication application;
842 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
844 KeyboardFocusManager manager = KeyboardFocusManager::Get();
845 DALI_TEST_CHECK(manager);
847 // Create an actor with two child actors and add it to the stage
848 Actor parent = Actor::New();
849 Actor child = Actor::New();
851 application.GetScene().Add(parent);
853 // Create three actors and add them as the children of the first child actor
854 Actor grandChild = Actor::New();
855 child.Add(grandChild);
857 // Set the parent and the first child actor as focus groups
858 manager.SetAsFocusGroup(parent, true);
860 // flush the queue and render once
861 application.SendNotification();
862 application.Render();
864 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
866 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
867 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
869 manager.SetAsFocusGroup(child, true);
871 // flush the queue and render once
872 application.SendNotification();
873 application.Render();
875 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
877 // The focus group should be the child, As it is the immediate parent which is also a focus group.
878 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
880 manager.SetAsFocusGroup(grandChild, true);
882 // flush the queue and render once
883 application.SendNotification();
884 application.Render();
886 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
888 // The current focus group should be itself, As it is also a focus group.
889 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
893 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
895 ToolkitTestApplication application;
897 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
899 KeyboardFocusManager manager = KeyboardFocusManager::Get();
900 DALI_TEST_CHECK(manager);
902 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
903 DALI_TEST_CHECK(defaultFocusIndicatorActor);
905 Actor newFocusIndicatorActor = Actor::New();
906 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
907 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
911 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
913 ToolkitTestApplication application;
915 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
917 KeyboardFocusManager manager = KeyboardFocusManager::Get();
918 DALI_TEST_CHECK(manager);
920 bool focusedActorActivatedSignalVerified = false;
921 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
922 manager.FocusedActorEnterKeySignal().Connect(&focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback);
924 Integration::KeyEvent returnEvent("Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
926 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
927 // It makes mIsFocusIndicatorEnabled true
928 application.ProcessEvent(returnEvent);
930 // Create the first button and add it to the stage
931 PushButton firstPushButton = PushButton::New();
932 firstPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
933 application.GetScene().Add(firstPushButton);
935 // Create the second button and add it to the stage
936 PushButton secondPushButton = PushButton::New();
937 secondPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
938 application.GetScene().Add(secondPushButton);
940 // Check that the focus is set on the first button
941 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
942 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
944 // Send the return event to activate the first button
945 application.ProcessEvent(returnEvent);
946 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
947 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
948 focusedActorActivatedCallback.Reset();
950 // Check that the focus is set on the second button
951 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
952 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
954 // Send the return event again to activate the second button
955 application.ProcessEvent(returnEvent);
956 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
957 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
958 focusedActorActivatedCallback.Reset();
962 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
964 ToolkitTestApplication application;
966 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
970 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
971 DALI_TEST_CHECK(type);
972 BaseHandle handle = type.CreateInstance();
973 DALI_TEST_CHECK(handle);
975 KeyboardFocusManager manager = KeyboardFocusManager::Get();
976 DALI_TEST_CHECK(manager);
978 bool focusGroupChangedSignalVerified = false;
979 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
980 manager.FocusGroupChangedSignal().Connect(&focusGroupChangedCallback, &FocusGroupChangedCallback::Callback);
982 Integration::KeyEvent tabEvent("Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
983 Integration::KeyEvent shiftTabEvent("Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
985 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
986 // It makes mIsFocusIndicatorEnabled true
987 application.ProcessEvent(tabEvent);
989 // Send the tab event to change focus group in the forward direction
990 application.ProcessEvent(tabEvent);
991 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
992 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
993 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
994 focusGroupChangedCallback.Reset();
996 // Send the shift tab event to change focus group in the backward direction
997 application.ProcessEvent(shiftTabEvent);
998 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
999 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1000 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1001 focusGroupChangedCallback.Reset();
1005 int UtcDaliKeyboardFocusManagerSignals(void)
1007 ToolkitTestApplication application;
1009 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1010 DALI_TEST_CHECK(manager);
1012 ConnectionTracker* testTracker = new ConnectionTracker();
1013 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardPreFocusChange", CallbackFunctor()), TEST_LOCATION);
1014 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusChanged", CallbackFunctor()), TEST_LOCATION);
1015 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusGroupChanged", CallbackFunctor()), TEST_LOCATION);
1016 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor()), TEST_LOCATION);
1021 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1023 ToolkitTestApplication application;
1025 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1027 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1028 DALI_TEST_CHECK(manager);
1030 // Create the first actor and add it to the stage
1031 Actor first = Actor::New();
1032 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1033 application.GetScene().Add(first);
1035 // Create the second actor and add it to the stage
1036 Actor second = Actor::New();
1037 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1038 application.GetScene().Add(second);
1040 // Create the third actor and add it to the stage
1041 Actor third = Actor::New();
1042 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1043 application.GetScene().Add(third);
1045 // Create the fourth actor and add it to the stage
1046 Actor fourth = Actor::New();
1047 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1048 application.GetScene().Add(fourth);
1050 // Check that the focus is set on the second actor
1051 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1052 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1054 // Check that the focus is set on the second actor
1055 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1056 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1058 // Check that the focus is set on the third actor
1059 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1060 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1062 // Check that the focus is set on the third actor
1063 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1064 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1066 // Move the focus backward
1067 manager.MoveFocusBackward();
1069 // Check that it current focused actor is third actor
1070 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1072 // Remove the second actor on stage
1075 // Reset the first actor
1079 // Move the focus backward
1080 manager.MoveFocusBackward();
1082 // Check that it current focused actor is third actor
1083 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1085 // Make history stack full
1086 for(int i = 0; i < 31; i++)
1088 Actor actor = Actor::New();
1089 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1090 application.GetScene().Add(actor);
1091 manager.SetCurrentFocusActor(actor);
1094 for(int i = 0; i < 31; i++)
1096 manager.MoveFocusBackward();
1099 // Check that it current focused actor is not second actor
1100 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1105 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1107 ToolkitTestApplication application;
1109 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1111 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1112 DALI_TEST_CHECK(manager);
1114 bool preFocusChangeSignalVerified = false;
1115 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1116 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1118 bool focusChangedSignalVerified = false;
1119 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1120 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1122 Integration::KeyEvent leftEvent("Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1123 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1124 Integration::KeyEvent upEvent("Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1125 Integration::KeyEvent downEvent("Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1126 Integration::KeyEvent pageUpEvent("Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1127 Integration::KeyEvent pageDownEvent("Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1129 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1130 // It makes mIsFocusIndicatorEnabled true
1131 application.ProcessEvent(leftEvent);
1133 // Create a 2x2 table view and try to move focus inside it
1134 TableView tableView = TableView::New(2, 2);
1135 application.GetScene().Add(tableView);
1137 // Create the first actor
1138 Actor first = Actor::New();
1139 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1141 // Create the second actor
1142 Actor second = Actor::New();
1143 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1145 // Create the third actor
1146 Actor third = Actor::New();
1147 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1149 // Create the fourth actor
1150 Actor fourth = Actor::New();
1151 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1153 // Add the four children to table view
1154 tableView.AddChild(first, TableView::CellPosition(0, 0));
1155 tableView.AddChild(second, TableView::CellPosition(0, 1));
1156 tableView.AddChild(third, TableView::CellPosition(1, 0));
1157 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1159 // Set the focus to the first actor
1160 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1161 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1162 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1163 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1164 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1165 focusChangedCallback.Reset();
1167 // Send the right key event to move the focus towards right
1168 application.ProcessEvent(rightEvent);
1169 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1170 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1171 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1172 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1173 focusChangedCallback.Reset();
1175 // Send the down key event to move the focus towards down
1176 application.ProcessEvent(downEvent);
1177 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1178 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1179 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1180 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1181 focusChangedCallback.Reset();
1183 // Send the down event to move the focus towards left
1184 application.ProcessEvent(leftEvent);
1185 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1186 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1187 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1188 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1189 focusChangedCallback.Reset();
1191 // Send the up event to move the focus towards up
1192 application.ProcessEvent(upEvent);
1193 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1194 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1195 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1196 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1197 focusChangedCallback.Reset();
1199 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1200 application.ProcessEvent(pageUpEvent);
1201 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1202 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1203 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1204 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1205 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1206 preFocusChangeCallback.Reset();
1208 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1209 application.ProcessEvent(pageDownEvent);
1210 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1211 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1212 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1213 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1214 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1215 preFocusChangeCallback.Reset();
1218 manager.ClearFocus();
1220 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1221 preFocusChangeCallback.Reset();
1222 application.ProcessEvent(pageUpEvent);
1223 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1224 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1225 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1226 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1227 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1229 // Clear the focus again
1230 manager.ClearFocus();
1232 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1233 preFocusChangeCallback.Reset();
1234 application.ProcessEvent(pageDownEvent);
1235 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1236 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1237 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1238 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1239 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1241 // Clear the focus again
1242 manager.ClearFocus();
1244 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1245 preFocusChangeCallback.Reset();
1246 application.ProcessEvent(upEvent);
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());
1252 // Clear the focus again
1253 manager.ClearFocus();
1255 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1256 preFocusChangeCallback.Reset();
1257 application.ProcessEvent(downEvent);
1258 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1259 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1260 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1261 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1266 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1268 ToolkitTestApplication application;
1270 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1272 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1273 DALI_TEST_CHECK(manager);
1275 bool preFocusChangeSignalVerified = false;
1276 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1277 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1279 Integration::KeyEvent spaceEvent("space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1281 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1282 // It makes mIsFocusIndicatorEnabled true
1283 application.ProcessEvent(spaceEvent);
1285 // Send the space event
1286 application.ProcessEvent(spaceEvent);
1287 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1288 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1290 // Clear the focus again
1291 manager.ClearFocus();
1293 // Send the space event again for line coverage
1294 preFocusChangeCallback.Reset();
1295 application.ProcessEvent(spaceEvent);
1296 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1297 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1298 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1299 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1304 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1306 ToolkitTestApplication application;
1308 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1312 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1313 DALI_TEST_CHECK(type);
1314 BaseHandle handle = type.CreateInstance();
1315 DALI_TEST_CHECK(handle);
1317 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1318 DALI_TEST_CHECK(manager);
1320 bool preFocusChangeSignalVerified = false;
1321 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1322 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1324 bool focusChangedSignalVerified = false;
1325 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1326 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1328 // Create the first actor and add it to the stage
1329 Control first = Control::New();
1330 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1331 application.GetScene().Add(first);
1333 // Create the second actor and add it to the stage
1334 Control second = Control::New();
1335 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1336 application.GetScene().Add(second);
1338 // Move the focus to the right
1339 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1341 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1342 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1343 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1344 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1345 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1346 preFocusChangeCallback.Reset();
1348 // Check that the focus is set on the first actor
1349 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1350 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1351 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1352 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1353 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1354 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1355 focusChangedCallback.Reset();
1357 // Move the focus towards right
1358 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1360 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1361 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1362 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1363 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1364 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1365 preFocusChangeCallback.Reset();
1367 // Check that the focus is set on the second actor
1368 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1369 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1370 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1371 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1372 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1373 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1374 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1375 focusChangedCallback.Reset();
1377 // Move the focus towards up
1378 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1380 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1381 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1382 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1383 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1384 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1385 preFocusChangeCallback.Reset();
1386 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1388 // Create a 2x2 table view and try to move focus inside it
1389 TableView tableView = TableView::New(2, 2);
1390 application.GetScene().Add(tableView);
1392 // Create the third actor
1393 Control third = Control::New();
1394 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1396 // Create the fourth actor
1397 Control fourth = Control::New();
1398 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1400 // Add the four children to table view
1401 tableView.AddChild(first, TableView::CellPosition(0, 0));
1402 tableView.AddChild(second, TableView::CellPosition(0, 1));
1403 tableView.AddChild(third, TableView::CellPosition(1, 0));
1404 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1406 // Set the focus to the first actor
1407 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1408 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1409 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1410 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1411 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1413 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1414 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1416 focusChangedCallback.Reset();
1418 // Move the focus towards right
1419 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1420 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1421 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1422 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1423 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
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::FOCUSED, TEST_LOCATION);
1427 focusChangedCallback.Reset();
1429 // Move the focus towards down
1430 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1431 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1432 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1433 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1434 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1436 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1437 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1438 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1439 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1441 focusChangedCallback.Reset();
1443 // Move the focus towards left
1444 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1445 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1446 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1447 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1448 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1450 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, 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::FOCUSED, TEST_LOCATION);
1453 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1455 focusChangedCallback.Reset();
1457 // Move the focus towards up
1458 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1459 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1460 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1461 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1462 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1463 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1464 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1465 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1466 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1467 focusChangedCallback.Reset();
1469 // Move the focus towards left. The focus move will fail as no way to move it upwards
1470 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1471 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1472 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1473 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1474 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1475 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1476 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1477 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1478 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1479 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1481 preFocusChangeCallback.Reset();
1482 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1485 manager.SetFocusGroupLoop(true);
1486 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1488 // Move the focus towards left again. The focus should move to the fourth actor.
1489 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1490 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1491 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1492 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1493 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1495 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1496 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1497 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1498 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1500 focusChangedCallback.Reset();
1503 manager.ClearFocus();
1504 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1505 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1506 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1507 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1512 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1514 ToolkitTestApplication application;
1516 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");
1518 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1519 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1521 Actor actor = Actor::New();
1522 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1524 tet_infoline("Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager");
1525 manager.SetCurrentFocusActor(actor);
1526 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1528 tet_infoline("Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager");
1529 application.GetScene().Add(actor);
1530 manager.SetCurrentFocusActor(actor);
1531 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == actor);
1533 tet_infoline("Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager");
1535 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1540 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1542 ToolkitTestApplication application;
1544 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");
1546 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1547 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1549 Actor actor = Actor::New();
1550 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1551 application.GetScene().Add(actor);
1552 manager.SetCurrentFocusActor(actor);
1554 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1555 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1556 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1557 application.ProcessEvent(rightEvent);
1559 Actor indicatorActor = manager.GetFocusIndicatorActor();
1561 tet_infoline("Indicator is added to focused actor");
1562 DALI_TEST_CHECK(actor == indicatorActor.GetParent());
1564 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1565 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager));
1567 tet_infoline("Indicator is removed from focused actor because mUseFocusIndicator is false");
1568 DALI_TEST_CHECK(!indicatorActor.GetParent());
1573 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1575 ToolkitTestApplication application;
1577 tet_infoline("Ensure Window can't receive KeyEvent when Control already consumed it");
1578 Dali::Integration::Scene scene = application.GetScene();
1580 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1581 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1583 // Create the first actor and add it to the stage
1584 Control control = Control::New();
1585 control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1588 KeyEventCallback controlCallback(true);
1589 control.KeyEventSignal().Connect(&controlCallback, &KeyEventCallback::Callback);
1591 KeyEventCallback sceneCallback(false);
1592 scene.KeyEventSignal().Connect(&sceneCallback, &KeyEventCallback::Callback);
1594 manager.SetCurrentFocusActor(control);
1596 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1597 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1598 Integration::KeyEvent event1("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1599 application.ProcessEvent(event1);
1601 DALI_TEST_CHECK(controlCallback.mIsCalled);
1602 DALI_TEST_CHECK(!sceneCallback.mIsCalled);
1607 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1609 ToolkitTestApplication application;
1611 tet_infoline("Ensure Memory focus actors for each window ");
1612 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1613 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1615 Window firstWindow = Window::New(PositionSize(0, 0, 300, 500), "", false);
1616 DALI_TEST_CHECK(firstWindow);
1617 Control first = Control::New();
1618 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1619 firstWindow.Add(first);
1621 Window secondWindow = Window::New(PositionSize(0, 0, 400, 600), "", false);
1622 DALI_TEST_CHECK(secondWindow);
1623 Control second = Control::New();
1624 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1625 secondWindow.Add(second);
1627 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1628 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1630 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1631 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1632 firstWindow.Raise();
1633 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1635 secondWindow.Remove(second);
1636 secondWindow.Raise();
1637 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1639 secondWindow.Reset();
1643 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1645 ToolkitTestApplication application;
1647 tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1651 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1652 DALI_TEST_CHECK(type);
1653 BaseHandle handle = type.CreateInstance();
1654 DALI_TEST_CHECK(handle);
1656 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1657 DALI_TEST_CHECK(manager);
1659 bool focusChangedSignalVerified = false;
1660 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1661 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1663 PushButton button1 = PushButton::New();
1664 PushButton button2 = PushButton::New();
1665 PushButton button3 = PushButton::New();
1666 PushButton button4 = PushButton::New();
1667 PushButton button5 = PushButton::New();
1669 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1670 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1671 button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1672 button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1673 button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1675 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1676 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1677 button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1678 button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1679 button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1681 application.GetScene().Add(button1);
1682 application.GetScene().Add(button2);
1683 application.GetScene().Add(button3);
1684 button5.Add(button4);
1685 application.GetScene().Add(button5);
1688 // button1 -- button2
1691 // button3 -- button4
1692 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1693 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1694 button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1695 button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1696 button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1698 // flush the queue and render once
1699 application.SendNotification();
1700 application.Render();
1702 // Set the focus to the button1
1703 // [button1] -- button2
1706 // button3 -- button4
1707 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1708 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1709 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1710 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1711 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1712 focusChangedCallback.Reset();
1714 // without set the navigation properties, but we can focus move
1715 // enable the default algorithm
1716 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1717 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1719 // Move the focus towards right
1720 // button1 -- [button2]
1723 // button3 -- button4
1724 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1726 // Confirm whether focus is moved to button2
1727 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1728 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1729 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1730 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1731 focusChangedCallback.Reset();
1733 // Move the focus towards down
1734 // button1 -- button2
1737 // button3 -- button4
1738 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1740 // Confirm whether focus is moved to button5
1741 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1742 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1743 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1744 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1745 focusChangedCallback.Reset();
1747 // Move the focus towards right
1748 // button1 -- button2
1751 // button3 -- [button4]
1752 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1754 // Confirm whether focus is moved to button4
1755 DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1756 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1757 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1758 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1759 focusChangedCallback.Reset();
1761 // Move the focus towards left
1762 // button1 -- button2
1765 // button3 -- button4
1766 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1768 // Confirm whether focus is moved to button5
1769 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1770 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1771 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1772 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1773 focusChangedCallback.Reset();
1775 // Move the focus towards left
1776 // button1 -- button2
1779 //[button3] -- button4
1780 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1782 // Confirm whether focus is moved to button3
1783 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1784 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1785 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1786 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1787 focusChangedCallback.Reset();
1789 // Move the focus towards right
1790 // button1 -- button2
1793 // button3 -- button4
1794 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1796 // Confirm whether focus is moved to button5
1797 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1798 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1799 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1800 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1801 focusChangedCallback.Reset();
1803 // Move the focus towards left
1804 // button1 -- button2
1807 //[button3] -- button4
1808 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1810 // Confirm whether focus is moved to button3
1811 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1812 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1813 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1814 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1815 focusChangedCallback.Reset();
1817 // Move the focus towards up
1818 //[button1]-- button2
1821 // button3 -- button4
1822 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1824 // Confirm whether focus is moved to button1
1825 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1826 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1827 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1828 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1829 focusChangedCallback.Reset();
1831 // Move the focus towards left. The focus move will fail as no way to move it upwards
1832 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1834 // Move the focus toward page up/down. The focus move will fail as invalid direction.
1835 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1836 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1837 focusChangedCallback.Reset();
1842 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode(void)
1844 ToolkitTestApplication application;
1846 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode");
1848 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1849 DALI_TEST_CHECK(manager);
1851 // Create the first actor and add it to the stage
1852 Actor first = Actor::New();
1853 first.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1854 first.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1855 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1856 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1857 first.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1858 application.GetScene().Add(first);
1860 // Create the second actor and add it to the stage
1861 Actor second = Actor::New();
1862 second.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1863 second.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1864 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1865 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1866 application.GetScene().Add(second);
1868 // flush the queue and render once
1869 application.SendNotification();
1870 application.Render();
1872 // Check that no actor is being focused yet.
1873 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1875 // Check that it will fail to set focus on an invalid actor
1876 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
1878 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1879 Dali::Integration::Point pointDown1;
1880 pointDown1.SetState(PointState::DOWN);
1881 pointDown1.SetDeviceId(1);
1882 // touch first actor
1883 pointDown1.SetScreenPosition(Vector2(10.0f, 10.0f));
1884 event1.AddPoint(pointDown1);
1885 application.ProcessEvent(event1);
1887 // flush the queue and render once
1888 application.SendNotification();
1889 application.Render();
1891 // Check that the focus is successfully to the first actor
1892 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1894 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1895 Dali::Integration::Point pointDown2;
1896 pointDown2.SetState(PointState::DOWN);
1897 pointDown2.SetDeviceId(1);
1898 // touch second actor
1899 pointDown2.SetScreenPosition(Vector2(110.0f, 10.0f));
1900 event2.AddPoint(pointDown2);
1901 application.ProcessEvent(event2);
1903 // flush the queue and render once
1904 application.SendNotification();
1905 application.Render();
1907 // Check that the focus is successfully to clear
1908 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1910 // Make the second actor focusableInTouchMode
1911 second.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1913 // touch second actor
1914 application.ProcessEvent(event2);
1916 // flush the queue and render once
1917 application.SendNotification();
1918 application.Render();
1920 // Check that the focus is successfully to the second actor
1921 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1926 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1928 ToolkitTestApplication application;
1930 tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1934 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1935 DALI_TEST_CHECK(type);
1936 BaseHandle handle = type.CreateInstance();
1937 DALI_TEST_CHECK(handle);
1939 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1940 DALI_TEST_CHECK(manager);
1942 bool focusChangedSignalVerified = false;
1943 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1944 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1946 PushButton button1 = PushButton::New();
1947 PushButton button2 = PushButton::New();
1949 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1950 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1952 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1953 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1955 application.GetScene().Add(button1);
1956 application.GetScene().Add(button2);
1959 // button1 -- button2
1960 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1961 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1962 button1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1963 button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1965 // flush the queue and render once
1966 application.SendNotification();
1967 application.Render();
1969 // Set the focus to the button1
1970 // [button1] -- button2
1971 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1972 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1973 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1974 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1975 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1976 focusChangedCallback.Reset();
1978 // without set the navigation properties, but we can focus move
1979 // enable the default algorithm
1980 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1981 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1983 // Move the focus towards right
1984 // button1 -- [button2]
1985 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1987 // Confirm whether focus is moved to button2
1988 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1989 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1990 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1991 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1992 focusChangedCallback.Reset();
1994 // disable the default algorithm
1995 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
1996 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1998 // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
1999 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
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 left, The focus move will success because the default algorithm is enabled.
2006 // [button1] -- button2
2007 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2008 // Confirm whether focus is moved to button1
2009 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2010 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2011 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2012 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2013 focusChangedCallback.Reset();
2016 manager.ClearFocus();
2017 // There is no actor focused.
2018 // button1 -- button2
2019 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2021 // Move the focus towards right, The focus is on the actor closest to the top left of the window.
2022 // [button1] -- button2
2023 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2025 // Confirm whether focus is moved to button1
2026 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2027 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2028 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2029 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2030 focusChangedCallback.Reset();
2036 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2038 ToolkitTestApplication application;
2040 tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2042 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2043 DALI_TEST_CHECK(manager);
2045 // Create the first actor and add it to the stage
2046 Actor first = Actor::New();
2047 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2048 application.GetScene().Add(first);
2050 // Create the second actor and add it to the first actor.
2051 Actor second = Actor::New();
2052 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2055 // Check that no actor is being focused yet.
2056 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2058 // Check that the focus is set on the first actor
2059 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2060 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2062 // Set KeyboardFocusableChildren false.
2063 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2065 // Check that it will fail to set focus on the second actor as it's not focusable
2066 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2067 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2069 // Set KeyboardFocusableChildren true.
2070 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2072 // Check that the focus is set on the second actor
2073 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2074 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2079 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2081 ToolkitTestApplication application;
2083 tet_infoline("UtcDaliKeyboardFocusManagerCheckWheelEvent");
2084 Dali::Integration::Scene scene = application.GetScene();
2086 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2087 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
2089 // Create the first actor and add it to the stage
2090 Actor parent = Actor::New();
2091 parent.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2093 Actor child = Actor::New();
2094 child.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2099 WheelEventCallback childCallback(false);
2100 child.WheelEventSignal().Connect(&childCallback, &WheelEventCallback::Callback);
2102 WheelEventCallback parentCallback(true);
2103 parent.WheelEventSignal().Connect(&parentCallback, &WheelEventCallback::Callback);
2105 WheelEventCallback sceneCallback(false);
2106 scene.WheelEventSignal().Connect(&sceneCallback, &WheelEventCallback::Callback);
2108 manager.SetCurrentFocusActor(child);
2110 // Emit custom wheel event is comming to KeyboardFocusManager
2111 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2112 application.ProcessEvent(event);
2114 DALI_TEST_CHECK(childCallback.mIsCalled);
2115 DALI_TEST_CHECK(parentCallback.mIsCalled);
2116 DALI_TEST_CHECK(!sceneCallback.mIsCalled);