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),
63 Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction, const std::string& deviceName)
65 tet_infoline("Verifying CustomAlgorithm()");
67 mInterfaceVerified = true;
69 mCurrentFocusedActor = currentFocusedActor;
70 mProposedActorToFocus = proposedActorToFocus;
71 mDirection = direction;
72 mDeviceName = deviceName;
74 return mProposedActorToFocus;
79 mInterfaceVerified = false;
80 mCurrentFocusedActor = Actor();
81 mProposedActorToFocus = Actor();
82 mDirection = Control::KeyboardFocus::LEFT;
86 bool& mInterfaceVerified;
87 Actor mCurrentFocusedActor;
88 Actor mProposedActorToFocus;
89 Control::KeyboardFocus::Direction mDirection;
90 std::string mDeviceName;
93 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
94 class PreFocusChangeCallback : public Dali::ConnectionTracker
97 PreFocusChangeCallback(bool& signalReceived)
98 : mSignalVerified(signalReceived),
99 mCurrentFocusedActor(),
100 mProposedActorToFocus(),
101 mDirection(Control::KeyboardFocus::LEFT)
105 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
107 tet_infoline("Verifying PreFocusChangeCallback()");
109 mSignalVerified = true;
111 mCurrentFocusedActor = currentFocusedActor;
112 mProposedActorToFocus = proposedActorToFocus;
113 mDirection = direction;
115 return mProposedActorToFocus;
120 mSignalVerified = false;
121 mCurrentFocusedActor = Actor();
122 mProposedActorToFocus = Actor();
123 mDirection = Control::KeyboardFocus::LEFT;
126 bool& mSignalVerified;
127 Actor mCurrentFocusedActor;
128 Actor mProposedActorToFocus;
129 Control::KeyboardFocus::Direction mDirection;
132 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
133 class FocusChangedCallback : public Dali::ConnectionTracker
136 FocusChangedCallback(bool& signalReceived)
137 : mSignalVerified(signalReceived),
138 mOriginalFocusedActor(),
139 mCurrentFocusedActor()
143 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
145 tet_infoline("Verifying FocusChangedCallback()");
147 if(originalFocusedActor == mCurrentFocusedActor)
149 mSignalVerified = true;
152 mOriginalFocusedActor = originalFocusedActor;
153 mCurrentFocusedActor = currentFocusedActor;
158 mSignalVerified = false;
161 bool& mSignalVerified;
162 Actor mOriginalFocusedActor;
163 Actor mCurrentFocusedActor;
166 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
167 class FocusGroupChangedCallback : public Dali::ConnectionTracker
170 FocusGroupChangedCallback(bool& signalReceived)
171 : mSignalVerified(signalReceived),
172 mCurrentFocusedActor(),
177 void Callback(Actor currentFocusedActor, bool forward)
179 tet_infoline("Verifying FocusGroupChangedCallback()");
181 mSignalVerified = true;
183 mCurrentFocusedActor = currentFocusedActor;
189 mSignalVerified = false;
192 bool& mSignalVerified;
193 Actor mCurrentFocusedActor;
197 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
198 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
201 FocusedActorActivatedCallback(bool& signalReceived)
202 : mSignalVerified(signalReceived),
207 void Callback(Actor activatedActor)
209 tet_infoline("Verifying FocusedActorActivatedCallback()");
211 mSignalVerified = true;
213 mActivatedActor = activatedActor;
218 mSignalVerified = false;
221 bool& mSignalVerified;
222 Actor mActivatedActor;
225 class KeyEventCallback : public Dali::ConnectionTracker
230 * @param[in] returnValue Set return value of KeyEvent callback.
232 KeyEventCallback(bool consumed)
233 : mConsumed(consumed),
238 bool Callback(Control control, const KeyEvent& keyEvent)
244 void Callback(const KeyEvent& keyEvent)
253 class WheelEventCallback : public Dali::ConnectionTracker
258 * @param[in] returnValue Set return value of WheelEvent callback.
260 WheelEventCallback(bool consumed)
261 : mConsumed(consumed),
266 bool Callback(Actor actor, const WheelEvent& wheelEvent)
272 void Callback(const WheelEvent& wheelEvent)
281 // Used to connect to signals via the ConnectSignal Handle method
282 struct CallbackFunctor
295 int UtcDaliKeyboardFocusManagerGet(void)
297 ToolkitTestApplication application;
299 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
303 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
304 DALI_TEST_CHECK(type);
305 BaseHandle handle = type.CreateInstance();
306 DALI_TEST_CHECK(handle);
308 KeyboardFocusManager manager;
310 manager = KeyboardFocusManager::Get();
311 DALI_TEST_CHECK(manager);
313 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
314 DALI_TEST_CHECK(newManager);
316 // Check that focus manager is a singleton
317 DALI_TEST_CHECK(manager == newManager);
321 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
323 ToolkitTestApplication application;
325 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
327 KeyboardFocusManager manager = KeyboardFocusManager::Get();
328 DALI_TEST_CHECK(manager);
330 // Create the first actor and add it to the stage
331 Actor first = Actor::New();
332 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
333 application.GetScene().Add(first);
335 // Create the second actor and add it to the stage
336 Actor second = Actor::New();
337 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
338 application.GetScene().Add(second);
340 // Create the third actor but don't add it to the stage
341 Actor third = Actor::New();
343 // Check that no actor is being focused yet.
344 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
346 // Check that it will fail to set focus on an invalid actor
347 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
349 // Check that the focus is set on the first actor
350 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
351 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
353 // Check that the focus is set on the second actor
354 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
355 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
357 // Check that it will fail to set focus on the third actor as it's not in the stage
358 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
359 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
361 // Add the third actor to the stage
362 application.GetScene().Add(third);
364 // Check that it will fail to set focus on the third actor as it's not focusable
365 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
366 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
368 // Make the third actor focusable
369 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
371 // Check that the focus is successfully moved to the third actor
372 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
373 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
377 int UtcDaliKeyboardFocusManagerMoveFocus(void)
379 ToolkitTestApplication application;
381 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
385 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
386 DALI_TEST_CHECK(type);
387 BaseHandle handle = type.CreateInstance();
388 DALI_TEST_CHECK(handle);
390 KeyboardFocusManager manager = KeyboardFocusManager::Get();
391 DALI_TEST_CHECK(manager);
393 bool preFocusChangeSignalVerified = false;
394 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
395 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
397 bool focusChangedSignalVerified = false;
398 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
399 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
401 // Create the first actor and add it to the stage
402 Actor first = Actor::New();
403 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
404 application.GetScene().Add(first);
406 // Create the second actor and add it to the stage
407 Actor second = Actor::New();
408 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
409 application.GetScene().Add(second);
411 // Move the focus to the right
412 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
414 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
415 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
416 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
417 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
418 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
419 preFocusChangeCallback.Reset();
421 // Check that the focus is set on the first actor
422 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
423 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
424 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
425 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
426 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
427 focusChangedCallback.Reset();
429 // Move the focus towards right
430 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
432 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
433 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
434 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
435 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
436 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
437 preFocusChangeCallback.Reset();
439 // Check that the focus is set on the second actor
440 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
441 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
442 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
443 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
444 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
445 focusChangedCallback.Reset();
447 // Move the focus towards up
448 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
450 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
451 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
452 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
453 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
454 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
455 preFocusChangeCallback.Reset();
456 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
458 // Create a 2x2 table view and try to move focus inside it
459 TableView tableView = TableView::New(2, 2);
460 application.GetScene().Add(tableView);
462 // Create the third actor
463 Actor third = Actor::New();
464 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
466 // Create the fourth actor
467 Actor fourth = Actor::New();
468 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
470 // Add the four children to table view
471 tableView.AddChild(first, TableView::CellPosition(0, 0));
472 tableView.AddChild(second, TableView::CellPosition(0, 1));
473 tableView.AddChild(third, TableView::CellPosition(1, 0));
474 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
476 // Set the focus to the first actor
477 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
478 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
479 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
480 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
481 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
482 focusChangedCallback.Reset();
484 // Move the focus towards right
485 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
486 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
487 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
488 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
489 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
490 focusChangedCallback.Reset();
492 // Move the focus towards down
493 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
494 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
495 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
496 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
497 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
498 focusChangedCallback.Reset();
500 // Move the focus towards left
501 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
502 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
503 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
504 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
505 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
506 focusChangedCallback.Reset();
508 // Move the focus towards up
509 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
510 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
511 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
512 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
513 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
514 focusChangedCallback.Reset();
516 // Move the focus towards left. The focus move will fail as no way to move it upwards
517 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
518 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
519 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
520 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
521 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
522 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
523 preFocusChangeCallback.Reset();
524 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
527 manager.SetFocusGroupLoop(true);
528 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
530 // Move the focus towards left again. The focus should move to the fourth actor.
531 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
532 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
533 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
534 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
535 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
536 focusChangedCallback.Reset();
540 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
542 ToolkitTestApplication application;
544 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
548 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
549 DALI_TEST_CHECK(type);
550 BaseHandle handle = type.CreateInstance();
551 DALI_TEST_CHECK(handle);
553 KeyboardFocusManager manager = KeyboardFocusManager::Get();
554 DALI_TEST_CHECK(manager);
556 bool preFocusChangeSignalVerified = false;
557 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
558 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
560 bool focusChangedSignalVerified = false;
561 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
562 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
564 // Create the first actor and add it to the stage
565 Actor first = Actor::New();
566 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
567 application.GetScene().Add(first);
569 // Create the second actor and add it to the stage
570 Actor second = Actor::New();
571 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
572 application.GetScene().Add(second);
574 // Move the focus to the right
575 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
577 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
578 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
579 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
580 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
581 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
582 preFocusChangeCallback.Reset();
584 bool customAlgorithmInterfaceVerified = false;
585 std::string deviceName = "deviceName";
586 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
587 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
589 // Move the focus towards right
590 DALI_TEST_CHECK(Toolkit::DevelKeyboardFocusManager::MoveFocus(manager, Control::KeyboardFocus::RIGHT, deviceName) == false);
592 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
593 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
594 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
595 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
596 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
597 DALI_TEST_EQUALS(customAlgorithm.mDeviceName, deviceName, TEST_LOCATION );
598 customAlgorithm.Reset();
600 // Check that the focus is set on the first actor
601 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
602 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
603 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
604 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
605 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
606 focusChangedCallback.Reset();
608 // Move the focus towards right
609 DALI_TEST_CHECK(Toolkit::DevelKeyboardFocusManager::MoveFocus(manager, Control::KeyboardFocus::RIGHT, deviceName) == false);
611 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
612 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
613 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
614 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
615 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
616 DALI_TEST_EQUALS(customAlgorithm.mDeviceName, deviceName, TEST_LOCATION );
617 customAlgorithm.Reset();
619 // Check that the focus is set on the second actor
620 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
621 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
622 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
623 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
624 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
625 focusChangedCallback.Reset();
627 // Move the focus towards up
628 DALI_TEST_CHECK(Toolkit::DevelKeyboardFocusManager::MoveFocus(manager, Control::KeyboardFocus::UP, deviceName) == false);
630 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
631 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
632 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
633 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
634 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
635 DALI_TEST_EQUALS(customAlgorithm.mDeviceName, deviceName, TEST_LOCATION );
636 customAlgorithm.Reset();
637 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
641 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
643 ToolkitTestApplication application;
645 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
649 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
650 DALI_TEST_CHECK(type);
651 BaseHandle handle = type.CreateInstance();
652 DALI_TEST_CHECK(handle);
654 KeyboardFocusManager manager = KeyboardFocusManager::Get();
655 DALI_TEST_CHECK(manager);
657 bool focusChangedSignalVerified = false;
658 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
659 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
661 PushButton button1 = PushButton::New();
662 PushButton button2 = PushButton::New();
663 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
664 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
665 application.GetScene().Add(button1);
666 application.GetScene().Add(button2);
668 // Set the focus to the button1
669 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
670 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
671 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
672 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
673 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
674 focusChangedCallback.Reset();
676 // set the navigation properties of button1
677 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
678 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
679 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
680 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
681 button1.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID)));
682 button1.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID)));
684 // set the navigation properties of button2
685 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
686 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
687 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
688 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
689 button2.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID)));
690 button2.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID)));
692 // Move the focus towards left
693 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
695 // Confirm whether focus is moved to button2
696 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
697 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
698 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
699 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
700 focusChangedCallback.Reset();
702 // Move the focus towards right
703 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
705 // Confirm whether focus is moved to button1
706 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
707 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
708 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
709 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
710 focusChangedCallback.Reset();
712 // Move the focus towards up
713 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
715 // Confirm whether focus is moved to button2
716 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
717 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
718 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
719 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
720 focusChangedCallback.Reset();
722 // Move the focus towards down
723 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
725 // Confirm whether focus is moved to button1
726 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
727 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
728 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
729 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
730 focusChangedCallback.Reset();
732 // Move the focus towards clockwise
733 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::CLOCKWISE) == true);
735 // Confirm whether focus is moved to button2
736 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
737 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
738 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
739 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
740 focusChangedCallback.Reset();
742 // Move the focus towards clockwise
743 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::COUNTER_CLOCKWISE) == true);
745 // Confirm whether focus is moved to button1
746 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
747 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
748 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
749 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
750 focusChangedCallback.Reset();
752 // Create a 1x1 table view and try to move focus inside it
753 TableView tableView = TableView::New(1, 1);
754 application.GetScene().Add(tableView);
756 PushButton button = PushButton::New();
757 button.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
758 tableView.AddChild(button, TableView::CellPosition(0, 0));
760 // set the navigation properties of button3
761 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
763 // Set the focus to the button
764 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
765 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
766 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
767 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
768 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
769 focusChangedCallback.Reset();
771 // Move the focus towards left
772 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
774 // Confirm whether focus is moved to button1
775 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
776 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
777 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
778 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
779 focusChangedCallback.Reset();
784 int UtcDaliKeyboardFocusManagerClearFocus(void)
786 ToolkitTestApplication application;
788 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
790 KeyboardFocusManager manager = KeyboardFocusManager::Get();
791 DALI_TEST_CHECK(manager);
793 // Create the first actor and add it to the stage
794 Actor first = Actor::New();
795 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
796 application.GetScene().Add(first);
798 // Create the second actor and add it to the stage
799 Actor second = Actor::New();
800 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
801 application.GetScene().Add(second);
803 // Check that the focus is set on the first actor
804 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
805 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
807 // Check that the focus is set on the second actor
808 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
809 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
812 manager.ClearFocus();
814 // Check that no actor is being focused now.
815 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
819 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
821 ToolkitTestApplication application;
823 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
825 KeyboardFocusManager manager = KeyboardFocusManager::Get();
826 DALI_TEST_CHECK(manager);
828 // Check that the focus movement is not looped within the same focus group by default
829 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
832 manager.SetFocusGroupLoop(true);
833 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
837 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
839 ToolkitTestApplication application;
841 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
843 KeyboardFocusManager manager = KeyboardFocusManager::Get();
844 DALI_TEST_CHECK(manager);
846 // Create an actor and check that it is not a focus group by default
847 Actor actor = Actor::New();
848 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
850 // Set the actor as focus group
851 manager.SetAsFocusGroup(actor, true);
853 // flush the queue and render once
854 application.SendNotification();
855 application.Render();
857 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
859 // Set the actor not as focus group
860 manager.SetAsFocusGroup(actor, false);
862 // flush the queue and render once
863 application.SendNotification();
864 application.Render();
866 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
870 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
872 ToolkitTestApplication application;
874 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
876 KeyboardFocusManager manager = KeyboardFocusManager::Get();
877 DALI_TEST_CHECK(manager);
879 // Create an actor with two child actors and add it to the stage
880 Actor parent = Actor::New();
881 Actor child = Actor::New();
883 application.GetScene().Add(parent);
885 // Create three actors and add them as the children of the first child actor
886 Actor grandChild = Actor::New();
887 child.Add(grandChild);
889 // Set the parent and the first child actor as focus groups
890 manager.SetAsFocusGroup(parent, true);
892 // flush the queue and render once
893 application.SendNotification();
894 application.Render();
896 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
898 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
899 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
901 manager.SetAsFocusGroup(child, true);
903 // flush the queue and render once
904 application.SendNotification();
905 application.Render();
907 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
909 // The focus group should be the child, As it is the immediate parent which is also a focus group.
910 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
912 manager.SetAsFocusGroup(grandChild, true);
914 // flush the queue and render once
915 application.SendNotification();
916 application.Render();
918 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
920 // The current focus group should be itself, As it is also a focus group.
921 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
925 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
927 ToolkitTestApplication application;
929 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
931 KeyboardFocusManager manager = KeyboardFocusManager::Get();
932 DALI_TEST_CHECK(manager);
934 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
935 DALI_TEST_CHECK(defaultFocusIndicatorActor);
937 Actor newFocusIndicatorActor = Actor::New();
938 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
939 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
943 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
945 ToolkitTestApplication application;
947 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
949 KeyboardFocusManager manager = KeyboardFocusManager::Get();
950 DALI_TEST_CHECK(manager);
952 bool focusedActorActivatedSignalVerified = false;
953 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
954 manager.FocusedActorEnterKeySignal().Connect(&focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback);
956 Integration::KeyEvent returnEvent("Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
958 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
959 // It makes mIsFocusIndicatorEnabled true
960 application.ProcessEvent(returnEvent);
962 // Create the first button and add it to the stage
963 PushButton firstPushButton = PushButton::New();
964 firstPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
965 application.GetScene().Add(firstPushButton);
967 // Create the second button and add it to the stage
968 PushButton secondPushButton = PushButton::New();
969 secondPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
970 application.GetScene().Add(secondPushButton);
972 // Check that the focus is set on the first button
973 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
974 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
976 // Send the return event to activate the first button
977 application.ProcessEvent(returnEvent);
978 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
979 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
980 focusedActorActivatedCallback.Reset();
982 // Check that the focus is set on the second button
983 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
984 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
986 // Send the return event again to activate the second button
987 application.ProcessEvent(returnEvent);
988 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
989 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
990 focusedActorActivatedCallback.Reset();
994 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
996 ToolkitTestApplication application;
998 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
1002 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1003 DALI_TEST_CHECK(type);
1004 BaseHandle handle = type.CreateInstance();
1005 DALI_TEST_CHECK(handle);
1007 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1008 DALI_TEST_CHECK(manager);
1010 bool focusGroupChangedSignalVerified = false;
1011 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
1012 manager.FocusGroupChangedSignal().Connect(&focusGroupChangedCallback, &FocusGroupChangedCallback::Callback);
1014 Integration::KeyEvent tabEvent("Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1015 Integration::KeyEvent shiftTabEvent("Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1017 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1018 // It makes mIsFocusIndicatorEnabled true
1019 application.ProcessEvent(tabEvent);
1021 // Send the tab event to change focus group in the forward direction
1022 application.ProcessEvent(tabEvent);
1023 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1024 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1025 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
1026 focusGroupChangedCallback.Reset();
1028 // Send the shift tab event to change focus group in the backward direction
1029 application.ProcessEvent(shiftTabEvent);
1030 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1031 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1032 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1033 focusGroupChangedCallback.Reset();
1037 int UtcDaliKeyboardFocusManagerSignals(void)
1039 ToolkitTestApplication application;
1041 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1042 DALI_TEST_CHECK(manager);
1044 ConnectionTracker* testTracker = new ConnectionTracker();
1045 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardPreFocusChange", CallbackFunctor()), TEST_LOCATION);
1046 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusChanged", CallbackFunctor()), TEST_LOCATION);
1047 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusGroupChanged", CallbackFunctor()), TEST_LOCATION);
1048 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor()), TEST_LOCATION);
1053 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1055 ToolkitTestApplication application;
1057 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1059 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1060 DALI_TEST_CHECK(manager);
1062 // Create the first actor and add it to the stage
1063 Actor first = Actor::New();
1064 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1065 application.GetScene().Add(first);
1067 // Create the second actor and add it to the stage
1068 Actor second = Actor::New();
1069 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1070 application.GetScene().Add(second);
1072 // Create the third actor and add it to the stage
1073 Actor third = Actor::New();
1074 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1075 application.GetScene().Add(third);
1077 // Create the fourth actor and add it to the stage
1078 Actor fourth = Actor::New();
1079 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1080 application.GetScene().Add(fourth);
1082 // Check that the focus is set on the second actor
1083 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1084 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1086 // Check that the focus is set on the second actor
1087 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1088 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1090 // Check that the focus is set on the third actor
1091 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1092 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1094 // Check that the focus is set on the third actor
1095 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1096 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1098 // Move the focus backward
1099 manager.MoveFocusBackward();
1101 // Check that it current focused actor is third actor
1102 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1104 // Remove the second actor on stage
1107 // Reset the first actor
1111 // Move the focus backward
1112 manager.MoveFocusBackward();
1114 // Check that it current focused actor is third actor
1115 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1117 // Make history stack full
1118 for(int i = 0; i < 31; i++)
1120 Actor actor = Actor::New();
1121 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1122 application.GetScene().Add(actor);
1123 manager.SetCurrentFocusActor(actor);
1126 for(int i = 0; i < 31; i++)
1128 manager.MoveFocusBackward();
1131 // Check that it current focused actor is not second actor
1132 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1137 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1139 ToolkitTestApplication application;
1141 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1143 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1144 DALI_TEST_CHECK(manager);
1146 bool preFocusChangeSignalVerified = false;
1147 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1148 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1150 bool focusChangedSignalVerified = false;
1151 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1152 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1154 Integration::KeyEvent leftEvent("Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1155 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1156 Integration::KeyEvent upEvent("Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1157 Integration::KeyEvent downEvent("Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1158 Integration::KeyEvent pageUpEvent("Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1159 Integration::KeyEvent pageDownEvent("Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1161 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1162 // It makes mIsFocusIndicatorEnabled true
1163 application.ProcessEvent(leftEvent);
1165 // Create a 2x2 table view and try to move focus inside it
1166 TableView tableView = TableView::New(2, 2);
1167 application.GetScene().Add(tableView);
1169 // Create the first actor
1170 Actor first = Actor::New();
1171 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1173 // Create the second actor
1174 Actor second = Actor::New();
1175 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1177 // Create the third actor
1178 Actor third = Actor::New();
1179 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1181 // Create the fourth actor
1182 Actor fourth = Actor::New();
1183 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1185 // Add the four children to table view
1186 tableView.AddChild(first, TableView::CellPosition(0, 0));
1187 tableView.AddChild(second, TableView::CellPosition(0, 1));
1188 tableView.AddChild(third, TableView::CellPosition(1, 0));
1189 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1191 // Set the focus to the first actor
1192 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1193 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1194 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1195 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1196 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1197 focusChangedCallback.Reset();
1199 // Send the right key event to move the focus towards right
1200 application.ProcessEvent(rightEvent);
1201 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1202 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1203 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1204 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1205 focusChangedCallback.Reset();
1207 // Send the down key event to move the focus towards down
1208 application.ProcessEvent(downEvent);
1209 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1210 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1211 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1212 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1213 focusChangedCallback.Reset();
1215 // Send the down event to move the focus towards left
1216 application.ProcessEvent(leftEvent);
1217 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1218 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1219 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1220 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1221 focusChangedCallback.Reset();
1223 // Send the up event to move the focus towards up
1224 application.ProcessEvent(upEvent);
1225 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1226 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1227 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1228 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1229 focusChangedCallback.Reset();
1231 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1232 application.ProcessEvent(pageUpEvent);
1233 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1234 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1235 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1236 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1237 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1238 preFocusChangeCallback.Reset();
1240 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1241 application.ProcessEvent(pageDownEvent);
1242 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1243 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1244 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1245 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1246 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1247 preFocusChangeCallback.Reset();
1250 manager.ClearFocus();
1252 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1253 preFocusChangeCallback.Reset();
1254 application.ProcessEvent(pageUpEvent);
1255 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1256 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1257 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1258 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1259 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1261 // Clear the focus again
1262 manager.ClearFocus();
1264 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1265 preFocusChangeCallback.Reset();
1266 application.ProcessEvent(pageDownEvent);
1267 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1268 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1269 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1270 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1271 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1273 // Clear the focus again
1274 manager.ClearFocus();
1276 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1277 preFocusChangeCallback.Reset();
1278 application.ProcessEvent(upEvent);
1279 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1280 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1281 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1282 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1284 // Clear the focus again
1285 manager.ClearFocus();
1287 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1288 preFocusChangeCallback.Reset();
1289 application.ProcessEvent(downEvent);
1290 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1291 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1292 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1293 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1298 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1300 ToolkitTestApplication application;
1302 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1304 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1305 DALI_TEST_CHECK(manager);
1307 bool preFocusChangeSignalVerified = false;
1308 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1309 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1311 Integration::KeyEvent spaceEvent("space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1313 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1314 // It makes mIsFocusIndicatorEnabled true
1315 application.ProcessEvent(spaceEvent);
1317 // Send the space event
1318 application.ProcessEvent(spaceEvent);
1319 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1320 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1322 // Clear the focus again
1323 manager.ClearFocus();
1325 // Send the space event again for line coverage
1326 preFocusChangeCallback.Reset();
1327 application.ProcessEvent(spaceEvent);
1328 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1329 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1330 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1331 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1336 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1338 ToolkitTestApplication application;
1340 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1344 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1345 DALI_TEST_CHECK(type);
1346 BaseHandle handle = type.CreateInstance();
1347 DALI_TEST_CHECK(handle);
1349 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1350 DALI_TEST_CHECK(manager);
1352 bool preFocusChangeSignalVerified = false;
1353 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1354 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1356 bool focusChangedSignalVerified = false;
1357 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1358 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1360 // Create the first actor and add it to the stage
1361 Control first = Control::New();
1362 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1363 application.GetScene().Add(first);
1365 // Create the second actor and add it to the stage
1366 Control second = Control::New();
1367 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1368 application.GetScene().Add(second);
1370 // Move the focus to the right
1371 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1373 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1374 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1375 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1376 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1377 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1378 preFocusChangeCallback.Reset();
1380 // Check that the focus is set on the first actor
1381 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1382 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1383 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1384 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1385 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1386 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1387 focusChangedCallback.Reset();
1389 // Move the focus towards right
1390 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1392 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1393 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1394 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1395 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1396 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1397 preFocusChangeCallback.Reset();
1399 // Check that the focus is set on the second actor
1400 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1401 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1402 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1403 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1404 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1405 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1406 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1407 focusChangedCallback.Reset();
1409 // Move the focus towards up
1410 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1412 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1413 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1414 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1415 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1416 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1417 preFocusChangeCallback.Reset();
1418 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1420 // Create a 2x2 table view and try to move focus inside it
1421 TableView tableView = TableView::New(2, 2);
1422 application.GetScene().Add(tableView);
1424 // Create the third actor
1425 Control third = Control::New();
1426 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1428 // Create the fourth actor
1429 Control fourth = Control::New();
1430 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1432 // Add the four children to table view
1433 tableView.AddChild(first, TableView::CellPosition(0, 0));
1434 tableView.AddChild(second, TableView::CellPosition(0, 1));
1435 tableView.AddChild(third, TableView::CellPosition(1, 0));
1436 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1438 // Set the focus to the first actor
1439 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1440 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1441 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1442 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1443 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1445 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1446 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1448 focusChangedCallback.Reset();
1450 // Move the focus towards right
1451 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1452 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1453 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1454 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1455 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1456 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1457 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1459 focusChangedCallback.Reset();
1461 // Move the focus towards down
1462 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1463 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1464 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1465 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1466 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1468 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1469 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1470 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1471 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1473 focusChangedCallback.Reset();
1475 // Move the focus towards left
1476 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1477 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1478 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1479 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1480 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1482 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1483 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1484 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1485 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1487 focusChangedCallback.Reset();
1489 // Move the focus towards up
1490 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1491 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1492 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1493 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1494 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1495 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, 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::NORMAL, TEST_LOCATION);
1499 focusChangedCallback.Reset();
1501 // Move the focus towards left. The focus move will fail as no way to move it upwards
1502 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1503 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1504 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1505 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1506 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1507 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1508 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1509 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1510 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1511 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1513 preFocusChangeCallback.Reset();
1514 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1517 manager.SetFocusGroupLoop(true);
1518 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1520 // Move the focus towards left again. The focus should move to the fourth actor.
1521 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1522 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1523 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1524 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1525 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1527 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1528 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1529 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1530 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1532 focusChangedCallback.Reset();
1535 manager.ClearFocus();
1536 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1537 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1538 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1539 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1544 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1546 ToolkitTestApplication application;
1548 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");
1550 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1551 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1553 Actor actor = Actor::New();
1554 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1556 tet_infoline("Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager");
1557 manager.SetCurrentFocusActor(actor);
1558 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1560 tet_infoline("Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager");
1561 application.GetScene().Add(actor);
1562 manager.SetCurrentFocusActor(actor);
1563 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == actor);
1565 tet_infoline("Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager");
1567 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1572 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1574 ToolkitTestApplication application;
1576 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");
1578 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1579 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1581 Actor actor = Actor::New();
1582 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1583 application.GetScene().Add(actor);
1584 manager.SetCurrentFocusActor(actor);
1586 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1587 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1588 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1589 application.ProcessEvent(rightEvent);
1591 Actor indicatorActor = manager.GetFocusIndicatorActor();
1593 tet_infoline("Indicator is added to focused actor");
1594 DALI_TEST_CHECK(actor == indicatorActor.GetParent());
1596 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1597 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager));
1599 tet_infoline("Indicator is removed from focused actor because mUseFocusIndicator is false");
1600 DALI_TEST_CHECK(!indicatorActor.GetParent());
1605 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1607 ToolkitTestApplication application;
1609 tet_infoline("Ensure Window can't receive KeyEvent when Control already consumed it");
1610 Dali::Integration::Scene scene = application.GetScene();
1612 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1613 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1615 // Create the first actor and add it to the stage
1616 Control control = Control::New();
1617 control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1620 KeyEventCallback controlCallback(true);
1621 control.KeyEventSignal().Connect(&controlCallback, &KeyEventCallback::Callback);
1623 KeyEventCallback sceneCallback(false);
1624 scene.KeyEventSignal().Connect(&sceneCallback, &KeyEventCallback::Callback);
1626 manager.SetCurrentFocusActor(control);
1628 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1629 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1630 Integration::KeyEvent event1("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1631 application.ProcessEvent(event1);
1633 DALI_TEST_CHECK(controlCallback.mIsCalled);
1634 DALI_TEST_CHECK(!sceneCallback.mIsCalled);
1639 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1641 ToolkitTestApplication application;
1643 tet_infoline("Ensure Memory focus actors for each window ");
1644 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1645 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1647 Window firstWindow = Window::New(PositionSize(0, 0, 300, 500), "", false);
1648 DALI_TEST_CHECK(firstWindow);
1649 Control first = Control::New();
1650 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1651 firstWindow.Add(first);
1653 Window secondWindow = Window::New(PositionSize(0, 0, 400, 600), "", false);
1654 DALI_TEST_CHECK(secondWindow);
1655 Control second = Control::New();
1656 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1657 secondWindow.Add(second);
1659 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1660 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1662 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1663 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1664 firstWindow.Raise();
1665 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1667 secondWindow.Remove(second);
1668 secondWindow.Raise();
1669 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1671 secondWindow.Reset();
1675 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1677 ToolkitTestApplication application;
1679 tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1683 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1684 DALI_TEST_CHECK(type);
1685 BaseHandle handle = type.CreateInstance();
1686 DALI_TEST_CHECK(handle);
1688 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1689 DALI_TEST_CHECK(manager);
1691 bool focusChangedSignalVerified = false;
1692 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1693 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1695 PushButton button1 = PushButton::New();
1696 PushButton button2 = PushButton::New();
1697 PushButton button3 = PushButton::New();
1698 PushButton button4 = PushButton::New();
1699 PushButton button5 = PushButton::New();
1701 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1702 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1703 button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1704 button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1705 button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1707 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1708 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1709 button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1710 button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1711 button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1713 application.GetScene().Add(button1);
1714 application.GetScene().Add(button2);
1715 application.GetScene().Add(button3);
1716 button5.Add(button4);
1717 application.GetScene().Add(button5);
1720 // button1 -- button2
1723 // button3 -- button4
1724 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1725 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1726 button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1727 button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1728 button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1730 // flush the queue and render once
1731 application.SendNotification();
1732 application.Render();
1734 // Set the focus to the button1
1735 // [button1] -- button2
1738 // button3 -- button4
1739 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1740 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1741 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1742 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1743 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1744 focusChangedCallback.Reset();
1746 // without set the navigation properties, but we can focus move
1747 // enable the default algorithm
1748 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1749 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1751 // Move the focus towards right
1752 // button1 -- [button2]
1755 // button3 -- button4
1756 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1758 // Confirm whether focus is moved to button2
1759 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1760 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1761 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1762 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1763 focusChangedCallback.Reset();
1765 // Move the focus towards down
1766 // button1 -- button2
1769 // button3 -- button4
1770 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1772 // Confirm whether focus is moved to button5
1773 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1774 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1775 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1776 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1777 focusChangedCallback.Reset();
1779 // Move the focus towards right
1780 // button1 -- button2
1783 // button3 -- [button4]
1784 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1786 // Confirm whether focus is moved to button4
1787 DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1788 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1789 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1790 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1791 focusChangedCallback.Reset();
1793 // Move the focus towards left
1794 // button1 -- button2
1797 // button3 -- button4
1798 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1800 // Confirm whether focus is moved to button5
1801 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1802 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1803 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1804 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1805 focusChangedCallback.Reset();
1807 // Move the focus towards left
1808 // button1 -- button2
1811 //[button3] -- button4
1812 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1814 // Confirm whether focus is moved to button3
1815 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1816 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1817 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1818 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1819 focusChangedCallback.Reset();
1821 // Move the focus towards right
1822 // button1 -- button2
1825 // button3 -- button4
1826 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1828 // Confirm whether focus is moved to button5
1829 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1830 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1831 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1832 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1833 focusChangedCallback.Reset();
1835 // Move the focus towards left
1836 // button1 -- button2
1839 //[button3] -- button4
1840 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1842 // Confirm whether focus is moved to button3
1843 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1844 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1845 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1846 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1847 focusChangedCallback.Reset();
1849 // Move the focus towards up
1850 //[button1]-- button2
1853 // button3 -- button4
1854 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1856 // Confirm whether focus is moved to button1
1857 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1858 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1859 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1860 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1861 focusChangedCallback.Reset();
1863 // Move the focus towards left. The focus move will fail as no way to move it upwards
1864 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1866 // Move the focus toward page up/down. The focus move will fail as invalid direction.
1867 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1868 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1869 focusChangedCallback.Reset();
1874 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode(void)
1876 ToolkitTestApplication application;
1878 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode");
1880 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1881 DALI_TEST_CHECK(manager);
1883 // Create the first actor and add it to the stage
1884 Actor first = Actor::New();
1885 first.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1886 first.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1887 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1888 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1889 first.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1890 application.GetScene().Add(first);
1892 // Create the second actor and add it to the stage
1893 Actor second = Actor::New();
1894 second.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1895 second.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1896 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1897 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1898 application.GetScene().Add(second);
1900 // flush the queue and render once
1901 application.SendNotification();
1902 application.Render();
1904 // Check that no actor is being focused yet.
1905 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1907 // Check that it will fail to set focus on an invalid actor
1908 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
1910 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1911 Dali::Integration::Point pointDown1;
1912 pointDown1.SetState(PointState::DOWN);
1913 pointDown1.SetDeviceId(1);
1914 // touch first actor
1915 pointDown1.SetScreenPosition(Vector2(10.0f, 10.0f));
1916 event1.AddPoint(pointDown1);
1917 application.ProcessEvent(event1);
1919 // flush the queue and render once
1920 application.SendNotification();
1921 application.Render();
1923 // Check that the focus is successfully to the first actor
1924 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1926 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1927 Dali::Integration::Point pointDown2;
1928 pointDown2.SetState(PointState::DOWN);
1929 pointDown2.SetDeviceId(1);
1930 // touch second actor
1931 pointDown2.SetScreenPosition(Vector2(110.0f, 10.0f));
1932 event2.AddPoint(pointDown2);
1933 application.ProcessEvent(event2);
1935 // flush the queue and render once
1936 application.SendNotification();
1937 application.Render();
1939 // Since no focus has been moved, the current focus actor is the same.
1940 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1942 // Make the second actor focusableInTouchMode
1943 second.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1945 // touch second actor
1946 application.ProcessEvent(event2);
1948 // flush the queue and render once
1949 application.SendNotification();
1950 application.Render();
1952 // Check that the focus is successfully to the second actor
1953 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1958 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1960 ToolkitTestApplication application;
1962 tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1966 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1967 DALI_TEST_CHECK(type);
1968 BaseHandle handle = type.CreateInstance();
1969 DALI_TEST_CHECK(handle);
1971 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1972 DALI_TEST_CHECK(manager);
1974 bool focusChangedSignalVerified = false;
1975 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1976 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1978 PushButton button1 = PushButton::New();
1979 PushButton button2 = PushButton::New();
1981 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1982 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1984 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1985 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1987 application.GetScene().Add(button1);
1988 application.GetScene().Add(button2);
1991 // button1 -- button2
1992 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1993 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1994 button1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1995 button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1997 // flush the queue and render once
1998 application.SendNotification();
1999 application.Render();
2001 // Set the focus to the button1
2002 // [button1] -- button2
2003 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
2004 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
2005 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2006 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2007 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2008 focusChangedCallback.Reset();
2010 // without set the navigation properties, but we can focus move
2011 // enable the default algorithm
2012 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2013 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2015 // Move the focus towards right
2016 // button1 -- [button2]
2017 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2019 // Confirm whether focus is moved to button2
2020 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2021 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2022 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
2023 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
2024 focusChangedCallback.Reset();
2026 // disable the default algorithm
2027 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
2028 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2030 // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
2031 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
2033 // enable the default algorithm
2034 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2035 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2037 // Move the focus towards left, The focus move will success because the default algorithm is enabled.
2038 // [button1] -- button2
2039 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2040 // Confirm whether focus is moved to button1
2041 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2042 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2043 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2044 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2045 focusChangedCallback.Reset();
2048 manager.ClearFocus();
2049 // There is no actor focused.
2050 // button1 -- button2
2051 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2053 // Move the focus towards right, The focus is on the actor closest to the top left of the window.
2054 // [button1] -- button2
2055 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2057 // Confirm whether focus is moved to button1
2058 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2059 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2060 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2061 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2062 focusChangedCallback.Reset();
2068 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2070 ToolkitTestApplication application;
2072 tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2074 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2075 DALI_TEST_CHECK(manager);
2077 // Create the first actor and add it to the stage
2078 Actor first = Actor::New();
2079 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2080 application.GetScene().Add(first);
2082 // Create the second actor and add it to the first actor.
2083 Actor second = Actor::New();
2084 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2087 // Check that no actor is being focused yet.
2088 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2090 // Check that the focus is set on the first actor
2091 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2092 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2094 // Set KeyboardFocusableChildren false.
2095 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2097 // Check that it will fail to set focus on the second actor as it's not focusable
2098 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2099 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2101 // Set KeyboardFocusableChildren true.
2102 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2104 // Check that the focus is set on the second actor
2105 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2106 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2111 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2113 ToolkitTestApplication application;
2115 tet_infoline("UtcDaliKeyboardFocusManagerCheckWheelEvent");
2116 Dali::Integration::Scene scene = application.GetScene();
2118 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2119 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
2121 // Create the first actor and add it to the stage
2122 Actor parent = Actor::New();
2123 parent.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2125 Actor child = Actor::New();
2126 child.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2131 WheelEventCallback childCallback(false);
2132 child.WheelEventSignal().Connect(&childCallback, &WheelEventCallback::Callback);
2134 WheelEventCallback parentCallback(true);
2135 parent.WheelEventSignal().Connect(&parentCallback, &WheelEventCallback::Callback);
2137 WheelEventCallback sceneCallback(false);
2138 scene.WheelEventSignal().Connect(&sceneCallback, &WheelEventCallback::Callback);
2140 manager.SetCurrentFocusActor(child);
2142 // Emit custom wheel event is comming to KeyboardFocusManager
2143 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2144 application.ProcessEvent(event);
2146 DALI_TEST_CHECK(childCallback.mIsCalled);
2147 DALI_TEST_CHECK(parentCallback.mIsCalled);
2148 DALI_TEST_CHECK(!sceneCallback.mIsCalled);
2153 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByCustomWheelEvent(void)
2155 ToolkitTestApplication application;
2157 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByCustomWheelEvent");
2158 Dali::Integration::Scene scene = application.GetScene();
2160 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2161 DALI_TEST_CHECK(manager);
2163 bool focusChangedSignalVerified = false;
2164 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
2165 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
2167 Integration::WheelEvent clockwiseEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2168 Integration::WheelEvent counterClockwiseEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1100u);
2170 // Create the first button
2171 PushButton first = PushButton::New();
2172 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2175 // Create the second button
2176 PushButton second = PushButton::New();
2177 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2180 // set the navigation properties
2181 first.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)second.GetProperty< int >( Actor::Property::ID )));
2182 second.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)first.GetProperty< int >( Actor::Property::ID )));
2184 // Set the focus to the first actor
2185 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2186 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2187 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2188 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2189 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
2190 focusChangedCallback.Reset();
2192 // Send the clockwise wheel event to move the focus towards clockwise
2193 application.ProcessEvent(clockwiseEvent);
2194 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2195 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2196 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
2197 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
2198 focusChangedCallback.Reset();
2200 // Send the counter clockwise wheel event to move the focus towards count clockwise
2201 application.ProcessEvent(counterClockwiseEvent);
2202 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2203 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2204 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
2205 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
2206 focusChangedCallback.Reset();
2209 manager.ClearFocus();
2214 int UtcDaliKeyboardFocusManagerWithUserInteractionEnabled(void)
2216 ToolkitTestApplication application;
2218 tet_infoline(" UtcDaliKeyboardFocusManagerWithUserInteractionEnabled");
2220 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2221 DALI_TEST_CHECK(manager);
2223 // Create the first control and add it to the stage
2224 Control first = Control::New();
2225 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2226 application.GetScene().Add(first);
2228 // Create the second control and add it to the first control.
2229 Control second = Control::New();
2230 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2233 // Check that no actor is being focused yet.
2234 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2236 // Check that the focus is set on the first actor
2237 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2238 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2240 // Set USER_INTERACTION_ENABLED false.
2241 second.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
2243 // Check that it will fail to set focus on the second actor as it's not userInteractionEnabled
2244 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2245 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2247 // Set KeyboardFocusableChildren true.
2248 second.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, true);
2250 // Check that the focus is set on the second actor
2251 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2252 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2254 // If the currently focused actor becomes USER_INTERACTION_ENABLED false, it loses focus.
2255 second.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
2257 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2264 int UtcDaliKeyboardFocusManagerWithHide(void)
2266 ToolkitTestApplication application;
2268 tet_infoline(" UtcDaliKeyboardFocusManagerWithHide");
2270 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2271 DALI_TEST_CHECK(manager);
2273 // Create the first control and add it to the stage
2274 Control first = Control::New();
2275 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2276 application.GetScene().Add(first);
2278 // Create the second control and add it to the first control.
2279 Control second = Control::New();
2280 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2284 // flush the queue and render once
2285 application.SendNotification();
2286 application.Render();
2288 // Check that no actor is being focused yet.
2289 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2291 // Check that the focus is set on the actor
2292 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2293 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2295 // If the currently focused actor becomes VISIBLE false, it loses focus.
2296 first.SetProperty(Actor::Property::VISIBLE, false);
2297 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2299 first.SetProperty(Actor::Property::VISIBLE, true);
2300 // Check that the focus is set on the actor
2301 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2302 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2304 // If the currently focused actor becomes VISIBLE false, When the parent is hidden, the child also loses focus.
2305 first.SetProperty(Actor::Property::VISIBLE, false);
2306 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2312 int UtcDaliKeyboardFocusManagerWithVisible(void)
2314 ToolkitTestApplication application;
2316 tet_infoline(" UtcDaliKeyboardFocusManagerWithVisible");
2318 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2319 DALI_TEST_CHECK(manager);
2321 // Create the first actor and add it to the stage
2322 Actor first = Actor::New();
2323 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2324 application.GetScene().Add(first);
2326 // Create the second actor and add it to the first actor.
2327 Actor second = Actor::New();
2328 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2331 // Check that no actor is being focused yet.
2332 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2334 // Check that the focus is set on the first actor
2335 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2336 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2338 // Set visible false.
2339 first.SetProperty(Actor::Property::VISIBLE, false);
2341 // Check that it will fail to set focus on the second actor as it's not focusable
2342 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2343 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2345 // Set visible true.
2346 first.SetProperty(Actor::Property::VISIBLE, true);
2348 // Check that the focus is set on the second actor
2349 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2350 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2355 int UtcDaliKeyboardFocusManagerFocusFinderRootActor(void)
2357 ToolkitTestApplication application;
2359 tet_infoline(" UtcDaliKeyboardFocusManagerFocusFinderRootActor");
2363 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
2364 DALI_TEST_CHECK(type);
2365 BaseHandle handle = type.CreateInstance();
2366 DALI_TEST_CHECK(handle);
2368 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2369 DALI_TEST_CHECK(manager);
2371 bool focusChangedSignalVerified = false;
2372 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
2373 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
2375 PushButton button1 = PushButton::New();
2376 PushButton button2 = PushButton::New();
2378 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
2379 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
2381 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2382 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2384 application.GetScene().Add(button1);
2385 application.GetScene().Add(button2);
2387 Actor actor = Actor::New();
2388 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2389 application.GetScene().Add(actor);
2391 PushButton buttonA = PushButton::New();
2392 PushButton buttonB = PushButton::New();
2394 buttonA.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
2395 buttonB.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
2397 buttonA.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2398 buttonB.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2404 // button1 -- button2
2405 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
2406 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
2407 button1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2408 button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2410 // buttonA -- buttonB
2411 buttonA.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 50.0f));
2412 buttonB.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 50.0f));
2413 buttonA.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2414 buttonB.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2416 // flush the queue and render once
2417 application.SendNotification();
2418 application.Render();
2420 // Set the focus to the button1
2421 // [button1] -- button2
2422 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
2423 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
2424 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2425 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2426 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2427 focusChangedCallback.Reset();
2429 // without set the navigation properties, but we can focus move
2430 // enable the default algorithm
2431 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2432 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2434 // Move the focus towards right
2435 // button1 -- [button2]
2436 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2438 // Confirm whether focus is moved to button2
2439 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2440 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2441 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
2442 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
2443 focusChangedCallback.Reset();
2446 manager.ClearFocus();
2448 // There is no actor focused.
2449 // button1 -- button2
2450 // buttonA -- buttonB
2451 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2453 // Sets the actor to root.
2454 Dali::Toolkit::DevelKeyboardFocusManager::SetFocusFinderRootActor(manager, actor);
2456 // Move the focus towards right
2457 // [buttonA] -- buttonB
2458 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2460 // Confirm whether focus is moved to buttonA
2461 // Because the root is an actor, the focus is moved to buttonA, a child of the actor.
2462 DALI_TEST_EQUALS(buttonA.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2463 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2464 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2465 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == buttonA);
2466 focusChangedCallback.Reset();
2469 // Move the focus towards right, The focus move will success.
2470 // buttonA -- [buttonB]
2471 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2472 // Confirm whether focus is moved to buttonB
2473 DALI_TEST_EQUALS(buttonB.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2474 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2475 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == buttonA);
2476 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == buttonB);
2477 focusChangedCallback.Reset();
2480 Dali::Toolkit::DevelKeyboardFocusManager::ResetFocusFinderRootActor(manager);