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)));
682 // set the navigation properties of button2
683 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
684 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
685 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
686 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
688 // Move the focus towards left
689 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
691 // Confirm whether focus is moved to button2
692 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
693 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
694 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
695 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
696 focusChangedCallback.Reset();
698 // Move the focus towards right
699 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
701 // Confirm whether focus is moved to button1
702 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
703 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
704 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
705 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
706 focusChangedCallback.Reset();
708 // Move the focus towards up
709 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
711 // Confirm whether focus is moved to button2
712 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
713 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
714 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
715 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
716 focusChangedCallback.Reset();
718 // Move the focus towards down
719 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
721 // Confirm whether focus is moved to button1
722 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
723 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
724 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
725 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
726 focusChangedCallback.Reset();
728 // Create a 1x1 table view and try to move focus inside it
729 TableView tableView = TableView::New(1, 1);
730 application.GetScene().Add(tableView);
732 PushButton button = PushButton::New();
733 button.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
734 tableView.AddChild(button, TableView::CellPosition(0, 0));
736 // set the navigation properties of button3
737 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty<int>(Actor::Property::ID)));
739 // Set the focus to the button
740 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
741 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
742 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
743 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
744 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
745 focusChangedCallback.Reset();
747 // Move the focus towards left
748 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
750 // Confirm whether focus is moved to button1
751 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
752 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
753 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
754 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
755 focusChangedCallback.Reset();
760 int UtcDaliKeyboardFocusManagerClearFocus(void)
762 ToolkitTestApplication application;
764 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
766 KeyboardFocusManager manager = KeyboardFocusManager::Get();
767 DALI_TEST_CHECK(manager);
769 // Create the first actor and add it to the stage
770 Actor first = Actor::New();
771 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
772 application.GetScene().Add(first);
774 // Create the second actor and add it to the stage
775 Actor second = Actor::New();
776 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
777 application.GetScene().Add(second);
779 // Check that the focus is set on the first actor
780 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
781 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
783 // Check that the focus is set on the second actor
784 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
785 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
788 manager.ClearFocus();
790 // Check that no actor is being focused now.
791 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
795 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
797 ToolkitTestApplication application;
799 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
801 KeyboardFocusManager manager = KeyboardFocusManager::Get();
802 DALI_TEST_CHECK(manager);
804 // Check that the focus movement is not looped within the same focus group by default
805 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
808 manager.SetFocusGroupLoop(true);
809 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
813 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
815 ToolkitTestApplication application;
817 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
819 KeyboardFocusManager manager = KeyboardFocusManager::Get();
820 DALI_TEST_CHECK(manager);
822 // Create an actor and check that it is not a focus group by default
823 Actor actor = Actor::New();
824 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
826 // Set the actor as focus group
827 manager.SetAsFocusGroup(actor, true);
829 // flush the queue and render once
830 application.SendNotification();
831 application.Render();
833 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
835 // Set the actor not as focus group
836 manager.SetAsFocusGroup(actor, false);
838 // flush the queue and render once
839 application.SendNotification();
840 application.Render();
842 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
846 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
848 ToolkitTestApplication application;
850 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
852 KeyboardFocusManager manager = KeyboardFocusManager::Get();
853 DALI_TEST_CHECK(manager);
855 // Create an actor with two child actors and add it to the stage
856 Actor parent = Actor::New();
857 Actor child = Actor::New();
859 application.GetScene().Add(parent);
861 // Create three actors and add them as the children of the first child actor
862 Actor grandChild = Actor::New();
863 child.Add(grandChild);
865 // Set the parent and the first child actor as focus groups
866 manager.SetAsFocusGroup(parent, true);
868 // flush the queue and render once
869 application.SendNotification();
870 application.Render();
872 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
874 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
875 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
877 manager.SetAsFocusGroup(child, true);
879 // flush the queue and render once
880 application.SendNotification();
881 application.Render();
883 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
885 // The focus group should be the child, As it is the immediate parent which is also a focus group.
886 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
888 manager.SetAsFocusGroup(grandChild, true);
890 // flush the queue and render once
891 application.SendNotification();
892 application.Render();
894 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
896 // The current focus group should be itself, As it is also a focus group.
897 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
901 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
903 ToolkitTestApplication application;
905 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
907 KeyboardFocusManager manager = KeyboardFocusManager::Get();
908 DALI_TEST_CHECK(manager);
910 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
911 DALI_TEST_CHECK(defaultFocusIndicatorActor);
913 Actor newFocusIndicatorActor = Actor::New();
914 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
915 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
919 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
921 ToolkitTestApplication application;
923 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
925 KeyboardFocusManager manager = KeyboardFocusManager::Get();
926 DALI_TEST_CHECK(manager);
928 bool focusedActorActivatedSignalVerified = false;
929 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
930 manager.FocusedActorEnterKeySignal().Connect(&focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback);
932 Integration::KeyEvent returnEvent("Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
934 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
935 // It makes mIsFocusIndicatorEnabled true
936 application.ProcessEvent(returnEvent);
938 // Create the first button and add it to the stage
939 PushButton firstPushButton = PushButton::New();
940 firstPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
941 application.GetScene().Add(firstPushButton);
943 // Create the second button and add it to the stage
944 PushButton secondPushButton = PushButton::New();
945 secondPushButton.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
946 application.GetScene().Add(secondPushButton);
948 // Check that the focus is set on the first button
949 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
950 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
952 // Send the return event to activate the first button
953 application.ProcessEvent(returnEvent);
954 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
955 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
956 focusedActorActivatedCallback.Reset();
958 // Check that the focus is set on the second button
959 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
960 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
962 // Send the return event again to activate the second button
963 application.ProcessEvent(returnEvent);
964 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
965 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
966 focusedActorActivatedCallback.Reset();
970 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
972 ToolkitTestApplication application;
974 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
978 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
979 DALI_TEST_CHECK(type);
980 BaseHandle handle = type.CreateInstance();
981 DALI_TEST_CHECK(handle);
983 KeyboardFocusManager manager = KeyboardFocusManager::Get();
984 DALI_TEST_CHECK(manager);
986 bool focusGroupChangedSignalVerified = false;
987 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
988 manager.FocusGroupChangedSignal().Connect(&focusGroupChangedCallback, &FocusGroupChangedCallback::Callback);
990 Integration::KeyEvent tabEvent("Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
991 Integration::KeyEvent shiftTabEvent("Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
993 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
994 // It makes mIsFocusIndicatorEnabled true
995 application.ProcessEvent(tabEvent);
997 // Send the tab event to change focus group in the forward direction
998 application.ProcessEvent(tabEvent);
999 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1000 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1001 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
1002 focusGroupChangedCallback.Reset();
1004 // Send the shift tab event to change focus group in the backward direction
1005 application.ProcessEvent(shiftTabEvent);
1006 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1007 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1008 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1009 focusGroupChangedCallback.Reset();
1013 int UtcDaliKeyboardFocusManagerSignals(void)
1015 ToolkitTestApplication application;
1017 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1018 DALI_TEST_CHECK(manager);
1020 ConnectionTracker* testTracker = new ConnectionTracker();
1021 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardPreFocusChange", CallbackFunctor()), TEST_LOCATION);
1022 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusChanged", CallbackFunctor()), TEST_LOCATION);
1023 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusGroupChanged", CallbackFunctor()), TEST_LOCATION);
1024 DALI_TEST_EQUALS(true, manager.ConnectSignal(testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor()), TEST_LOCATION);
1029 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1031 ToolkitTestApplication application;
1033 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1035 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1036 DALI_TEST_CHECK(manager);
1038 // Create the first actor and add it to the stage
1039 Actor first = Actor::New();
1040 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1041 application.GetScene().Add(first);
1043 // Create the second actor and add it to the stage
1044 Actor second = Actor::New();
1045 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1046 application.GetScene().Add(second);
1048 // Create the third actor and add it to the stage
1049 Actor third = Actor::New();
1050 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1051 application.GetScene().Add(third);
1053 // Create the fourth actor and add it to the stage
1054 Actor fourth = Actor::New();
1055 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1056 application.GetScene().Add(fourth);
1058 // Check that the focus is set on the second actor
1059 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1060 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1062 // Check that the focus is set on the second actor
1063 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1064 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1066 // Check that the focus is set on the third actor
1067 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1068 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1070 // Check that the focus is set on the third actor
1071 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1072 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1074 // Move the focus backward
1075 manager.MoveFocusBackward();
1077 // Check that it current focused actor is third actor
1078 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1080 // Remove the second actor on stage
1083 // Reset the first actor
1087 // Move the focus backward
1088 manager.MoveFocusBackward();
1090 // Check that it current focused actor is third actor
1091 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1093 // Make history stack full
1094 for(int i = 0; i < 31; i++)
1096 Actor actor = Actor::New();
1097 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1098 application.GetScene().Add(actor);
1099 manager.SetCurrentFocusActor(actor);
1102 for(int i = 0; i < 31; i++)
1104 manager.MoveFocusBackward();
1107 // Check that it current focused actor is not second actor
1108 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1113 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1115 ToolkitTestApplication application;
1117 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1119 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1120 DALI_TEST_CHECK(manager);
1122 bool preFocusChangeSignalVerified = false;
1123 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1124 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1126 bool focusChangedSignalVerified = false;
1127 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1128 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1130 Integration::KeyEvent leftEvent("Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1131 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1132 Integration::KeyEvent upEvent("Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1133 Integration::KeyEvent downEvent("Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1134 Integration::KeyEvent pageUpEvent("Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1135 Integration::KeyEvent pageDownEvent("Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1137 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1138 // It makes mIsFocusIndicatorEnabled true
1139 application.ProcessEvent(leftEvent);
1141 // Create a 2x2 table view and try to move focus inside it
1142 TableView tableView = TableView::New(2, 2);
1143 application.GetScene().Add(tableView);
1145 // Create the first actor
1146 Actor first = Actor::New();
1147 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1149 // Create the second actor
1150 Actor second = Actor::New();
1151 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1153 // Create the third actor
1154 Actor third = Actor::New();
1155 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1157 // Create the fourth actor
1158 Actor fourth = Actor::New();
1159 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1161 // Add the four children to table view
1162 tableView.AddChild(first, TableView::CellPosition(0, 0));
1163 tableView.AddChild(second, TableView::CellPosition(0, 1));
1164 tableView.AddChild(third, TableView::CellPosition(1, 0));
1165 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1167 // Set the focus to the first actor
1168 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1169 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1170 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1171 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1172 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1173 focusChangedCallback.Reset();
1175 // Send the right key event to move the focus towards right
1176 application.ProcessEvent(rightEvent);
1177 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1178 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1179 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1180 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1181 focusChangedCallback.Reset();
1183 // Send the down key event to move the focus towards down
1184 application.ProcessEvent(downEvent);
1185 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1186 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1187 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1188 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1189 focusChangedCallback.Reset();
1191 // Send the down event to move the focus towards left
1192 application.ProcessEvent(leftEvent);
1193 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1194 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1195 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1196 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1197 focusChangedCallback.Reset();
1199 // Send the up event to move the focus towards up
1200 application.ProcessEvent(upEvent);
1201 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1202 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1203 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1204 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1205 focusChangedCallback.Reset();
1207 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1208 application.ProcessEvent(pageUpEvent);
1209 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1210 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1211 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1212 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1213 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1214 preFocusChangeCallback.Reset();
1216 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1217 application.ProcessEvent(pageDownEvent);
1218 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1219 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1220 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1221 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1222 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1223 preFocusChangeCallback.Reset();
1226 manager.ClearFocus();
1228 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1229 preFocusChangeCallback.Reset();
1230 application.ProcessEvent(pageUpEvent);
1231 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1232 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1233 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1234 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1235 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1237 // Clear the focus again
1238 manager.ClearFocus();
1240 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1241 preFocusChangeCallback.Reset();
1242 application.ProcessEvent(pageDownEvent);
1243 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1244 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1245 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1246 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1247 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1249 // Clear the focus again
1250 manager.ClearFocus();
1252 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1253 preFocusChangeCallback.Reset();
1254 application.ProcessEvent(upEvent);
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());
1260 // Clear the focus again
1261 manager.ClearFocus();
1263 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1264 preFocusChangeCallback.Reset();
1265 application.ProcessEvent(downEvent);
1266 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1267 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1268 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1269 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1274 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1276 ToolkitTestApplication application;
1278 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1280 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1281 DALI_TEST_CHECK(manager);
1283 bool preFocusChangeSignalVerified = false;
1284 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1285 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1287 Integration::KeyEvent spaceEvent("space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1289 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1290 // It makes mIsFocusIndicatorEnabled true
1291 application.ProcessEvent(spaceEvent);
1293 // Send the space event
1294 application.ProcessEvent(spaceEvent);
1295 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1296 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1298 // Clear the focus again
1299 manager.ClearFocus();
1301 // Send the space event again for line coverage
1302 preFocusChangeCallback.Reset();
1303 application.ProcessEvent(spaceEvent);
1304 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1305 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1306 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1307 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1312 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1314 ToolkitTestApplication application;
1316 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1320 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1321 DALI_TEST_CHECK(type);
1322 BaseHandle handle = type.CreateInstance();
1323 DALI_TEST_CHECK(handle);
1325 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1326 DALI_TEST_CHECK(manager);
1328 bool preFocusChangeSignalVerified = false;
1329 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1330 manager.PreFocusChangeSignal().Connect(&preFocusChangeCallback, &PreFocusChangeCallback::Callback);
1332 bool focusChangedSignalVerified = false;
1333 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1334 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1336 // Create the first actor and add it to the stage
1337 Control first = Control::New();
1338 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1339 application.GetScene().Add(first);
1341 // Create the second actor and add it to the stage
1342 Control second = Control::New();
1343 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1344 application.GetScene().Add(second);
1346 // Move the focus to the right
1347 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1349 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1350 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1351 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1352 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1353 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1354 preFocusChangeCallback.Reset();
1356 // Check that the focus is set on the first actor
1357 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1358 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1359 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1360 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1361 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1362 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1363 focusChangedCallback.Reset();
1365 // Move the focus towards right
1366 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1368 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1369 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1370 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1371 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1372 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1373 preFocusChangeCallback.Reset();
1375 // Check that the focus is set on the second actor
1376 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1377 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1378 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1379 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1380 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1381 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1382 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1383 focusChangedCallback.Reset();
1385 // Move the focus towards up
1386 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1388 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1389 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1390 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1391 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1392 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1393 preFocusChangeCallback.Reset();
1394 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1396 // Create a 2x2 table view and try to move focus inside it
1397 TableView tableView = TableView::New(2, 2);
1398 application.GetScene().Add(tableView);
1400 // Create the third actor
1401 Control third = Control::New();
1402 third.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1404 // Create the fourth actor
1405 Control fourth = Control::New();
1406 fourth.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1408 // Add the four children to table view
1409 tableView.AddChild(first, TableView::CellPosition(0, 0));
1410 tableView.AddChild(second, TableView::CellPosition(0, 1));
1411 tableView.AddChild(third, TableView::CellPosition(1, 0));
1412 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1414 // Set the focus to the first actor
1415 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1416 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1417 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1418 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1419 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1421 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1422 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1424 focusChangedCallback.Reset();
1426 // Move the focus towards right
1427 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1428 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1429 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1430 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1431 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1432 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1433 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1435 focusChangedCallback.Reset();
1437 // Move the focus towards down
1438 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1439 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1440 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1441 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1442 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1444 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1445 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1446 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1447 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1449 focusChangedCallback.Reset();
1451 // Move the focus towards left
1452 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1453 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1454 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1455 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1456 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1458 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1459 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1460 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1461 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1463 focusChangedCallback.Reset();
1465 // Move the focus towards up
1466 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1467 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1468 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1469 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1470 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1471 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1472 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1473 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1474 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1475 focusChangedCallback.Reset();
1477 // Move the focus towards left. The focus move will fail as no way to move it upwards
1478 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1479 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1480 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1481 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1482 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1483 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1484 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1485 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1486 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1487 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1489 preFocusChangeCallback.Reset();
1490 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1493 manager.SetFocusGroupLoop(true);
1494 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1496 // Move the focus towards left again. The focus should move to the fourth actor.
1497 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1498 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1499 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1500 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1501 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1503 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1504 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1505 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1506 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1508 focusChangedCallback.Reset();
1511 manager.ClearFocus();
1512 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1513 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1514 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1515 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION);
1520 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1522 ToolkitTestApplication application;
1524 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");
1526 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1527 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1529 Actor actor = Actor::New();
1530 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1532 tet_infoline("Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager");
1533 manager.SetCurrentFocusActor(actor);
1534 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1536 tet_infoline("Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager");
1537 application.GetScene().Add(actor);
1538 manager.SetCurrentFocusActor(actor);
1539 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == actor);
1541 tet_infoline("Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager");
1543 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1548 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1550 ToolkitTestApplication application;
1552 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");
1554 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1555 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1557 Actor actor = Actor::New();
1558 actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1559 application.GetScene().Add(actor);
1560 manager.SetCurrentFocusActor(actor);
1562 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1563 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1564 Integration::KeyEvent rightEvent("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1565 application.ProcessEvent(rightEvent);
1567 Actor indicatorActor = manager.GetFocusIndicatorActor();
1569 tet_infoline("Indicator is added to focused actor");
1570 DALI_TEST_CHECK(actor == indicatorActor.GetParent());
1572 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1573 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager));
1575 tet_infoline("Indicator is removed from focused actor because mUseFocusIndicator is false");
1576 DALI_TEST_CHECK(!indicatorActor.GetParent());
1581 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1583 ToolkitTestApplication application;
1585 tet_infoline("Ensure Window can't receive KeyEvent when Control already consumed it");
1586 Dali::Integration::Scene scene = application.GetScene();
1588 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1589 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1591 // Create the first actor and add it to the stage
1592 Control control = Control::New();
1593 control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1596 KeyEventCallback controlCallback(true);
1597 control.KeyEventSignal().Connect(&controlCallback, &KeyEventCallback::Callback);
1599 KeyEventCallback sceneCallback(false);
1600 scene.KeyEventSignal().Connect(&sceneCallback, &KeyEventCallback::Callback);
1602 manager.SetCurrentFocusActor(control);
1604 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1605 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1606 Integration::KeyEvent event1("Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
1607 application.ProcessEvent(event1);
1609 DALI_TEST_CHECK(controlCallback.mIsCalled);
1610 DALI_TEST_CHECK(!sceneCallback.mIsCalled);
1615 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1617 ToolkitTestApplication application;
1619 tet_infoline("Ensure Memory focus actors for each window ");
1620 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1621 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
1623 Window firstWindow = Window::New(PositionSize(0, 0, 300, 500), "", false);
1624 DALI_TEST_CHECK(firstWindow);
1625 Control first = Control::New();
1626 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1627 firstWindow.Add(first);
1629 Window secondWindow = Window::New(PositionSize(0, 0, 400, 600), "", false);
1630 DALI_TEST_CHECK(secondWindow);
1631 Control second = Control::New();
1632 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1633 secondWindow.Add(second);
1635 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1636 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1638 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1639 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1640 firstWindow.Raise();
1641 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1643 secondWindow.Remove(second);
1644 secondWindow.Raise();
1645 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1647 secondWindow.Reset();
1651 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1653 ToolkitTestApplication application;
1655 tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1659 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1660 DALI_TEST_CHECK(type);
1661 BaseHandle handle = type.CreateInstance();
1662 DALI_TEST_CHECK(handle);
1664 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1665 DALI_TEST_CHECK(manager);
1667 bool focusChangedSignalVerified = false;
1668 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1669 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1671 PushButton button1 = PushButton::New();
1672 PushButton button2 = PushButton::New();
1673 PushButton button3 = PushButton::New();
1674 PushButton button4 = PushButton::New();
1675 PushButton button5 = PushButton::New();
1677 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1678 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1679 button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1680 button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1681 button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1683 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1684 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1685 button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1686 button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1687 button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1689 application.GetScene().Add(button1);
1690 application.GetScene().Add(button2);
1691 application.GetScene().Add(button3);
1692 button5.Add(button4);
1693 application.GetScene().Add(button5);
1696 // button1 -- button2
1699 // button3 -- button4
1700 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1701 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1702 button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1703 button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1704 button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1706 // flush the queue and render once
1707 application.SendNotification();
1708 application.Render();
1710 // Set the focus to the button1
1711 // [button1] -- button2
1714 // button3 -- button4
1715 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1716 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1717 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1718 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1719 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1720 focusChangedCallback.Reset();
1722 // without set the navigation properties, but we can focus move
1723 // enable the default algorithm
1724 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1725 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1727 // Move the focus towards right
1728 // button1 -- [button2]
1731 // button3 -- button4
1732 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1734 // Confirm whether focus is moved to button2
1735 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1736 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1737 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1738 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1739 focusChangedCallback.Reset();
1741 // Move the focus towards down
1742 // button1 -- button2
1745 // button3 -- button4
1746 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1748 // Confirm whether focus is moved to button5
1749 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1750 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1751 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1752 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1753 focusChangedCallback.Reset();
1755 // Move the focus towards right
1756 // button1 -- button2
1759 // button3 -- [button4]
1760 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1762 // Confirm whether focus is moved to button4
1763 DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1764 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1765 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1766 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1767 focusChangedCallback.Reset();
1769 // Move the focus towards left
1770 // button1 -- button2
1773 // button3 -- button4
1774 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1776 // Confirm whether focus is moved to button5
1777 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1778 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1779 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1780 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1781 focusChangedCallback.Reset();
1783 // Move the focus towards left
1784 // button1 -- button2
1787 //[button3] -- button4
1788 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1790 // Confirm whether focus is moved to button3
1791 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1792 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1793 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1794 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1795 focusChangedCallback.Reset();
1797 // Move the focus towards right
1798 // button1 -- button2
1801 // button3 -- button4
1802 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1804 // Confirm whether focus is moved to button5
1805 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1806 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1807 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1808 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1809 focusChangedCallback.Reset();
1811 // Move the focus towards left
1812 // button1 -- button2
1815 //[button3] -- button4
1816 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1818 // Confirm whether focus is moved to button3
1819 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1820 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1821 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1822 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1823 focusChangedCallback.Reset();
1825 // Move the focus towards up
1826 //[button1]-- button2
1829 // button3 -- button4
1830 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1832 // Confirm whether focus is moved to button1
1833 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1834 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1835 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1836 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1837 focusChangedCallback.Reset();
1839 // Move the focus towards left. The focus move will fail as no way to move it upwards
1840 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1842 // Move the focus toward page up/down. The focus move will fail as invalid direction.
1843 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1844 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1845 focusChangedCallback.Reset();
1850 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode(void)
1852 ToolkitTestApplication application;
1854 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActorInTouchMode");
1856 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1857 DALI_TEST_CHECK(manager);
1859 // Create the first actor and add it to the stage
1860 Actor first = Actor::New();
1861 first.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1862 first.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1863 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1864 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1865 first.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1866 application.GetScene().Add(first);
1868 // Create the second actor and add it to the stage
1869 Actor second = Actor::New();
1870 second.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1871 second.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1872 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1873 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1874 application.GetScene().Add(second);
1876 // flush the queue and render once
1877 application.SendNotification();
1878 application.Render();
1880 // Check that no actor is being focused yet.
1881 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1883 // Check that it will fail to set focus on an invalid actor
1884 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
1886 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1887 Dali::Integration::Point pointDown1;
1888 pointDown1.SetState(PointState::DOWN);
1889 pointDown1.SetDeviceId(1);
1890 // touch first actor
1891 pointDown1.SetScreenPosition(Vector2(10.0f, 10.0f));
1892 event1.AddPoint(pointDown1);
1893 application.ProcessEvent(event1);
1895 // flush the queue and render once
1896 application.SendNotification();
1897 application.Render();
1899 // Check that the focus is successfully to the first actor
1900 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1902 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1903 Dali::Integration::Point pointDown2;
1904 pointDown2.SetState(PointState::DOWN);
1905 pointDown2.SetDeviceId(1);
1906 // touch second actor
1907 pointDown2.SetScreenPosition(Vector2(110.0f, 10.0f));
1908 event2.AddPoint(pointDown2);
1909 application.ProcessEvent(event2);
1911 // flush the queue and render once
1912 application.SendNotification();
1913 application.Render();
1915 // Check that the focus is successfully to clear
1916 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1918 // Make the second actor focusableInTouchMode
1919 second.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
1921 // touch second actor
1922 application.ProcessEvent(event2);
1924 // flush the queue and render once
1925 application.SendNotification();
1926 application.Render();
1928 // Check that the focus is successfully to the second actor
1929 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1934 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1936 ToolkitTestApplication application;
1938 tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1942 type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager");
1943 DALI_TEST_CHECK(type);
1944 BaseHandle handle = type.CreateInstance();
1945 DALI_TEST_CHECK(handle);
1947 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1948 DALI_TEST_CHECK(manager);
1950 bool focusChangedSignalVerified = false;
1951 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1952 manager.FocusChangedSignal().Connect(&focusChangedCallback, &FocusChangedCallback::Callback);
1954 PushButton button1 = PushButton::New();
1955 PushButton button2 = PushButton::New();
1957 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1958 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1960 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1961 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1963 application.GetScene().Add(button1);
1964 application.GetScene().Add(button2);
1967 // button1 -- button2
1968 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1969 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1970 button1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1971 button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1973 // flush the queue and render once
1974 application.SendNotification();
1975 application.Render();
1977 // Set the focus to the button1
1978 // [button1] -- button2
1979 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1980 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1981 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1982 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1983 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1984 focusChangedCallback.Reset();
1986 // without set the navigation properties, but we can focus move
1987 // enable the default algorithm
1988 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1989 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
1991 // Move the focus towards right
1992 // button1 -- [button2]
1993 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1995 // Confirm whether focus is moved to button2
1996 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1997 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1998 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1999 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
2000 focusChangedCallback.Reset();
2002 // disable the default algorithm
2003 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
2004 DALI_TEST_CHECK(!Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2006 // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
2007 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
2009 // enable the default algorithm
2010 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2011 DALI_TEST_CHECK(Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager));
2013 // Move the focus towards left, The focus move will success because the default algorithm is enabled.
2014 // [button1] -- button2
2015 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2016 // Confirm whether focus is moved to button1
2017 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2018 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2019 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2020 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2021 focusChangedCallback.Reset();
2024 manager.ClearFocus();
2025 // There is no actor focused.
2026 // button1 -- button2
2027 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2029 // Move the focus towards right, The focus is on the actor closest to the top left of the window.
2030 // [button1] -- button2
2031 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
2033 // Confirm whether focus is moved to button1
2034 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2035 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2036 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
2037 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2038 focusChangedCallback.Reset();
2044 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2046 ToolkitTestApplication application;
2048 tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2050 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2051 DALI_TEST_CHECK(manager);
2053 // Create the first actor and add it to the stage
2054 Actor first = Actor::New();
2055 first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2056 application.GetScene().Add(first);
2058 // Create the second actor and add it to the first actor.
2059 Actor second = Actor::New();
2060 second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2063 // Check that no actor is being focused yet.
2064 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2066 // Check that the focus is set on the first actor
2067 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2068 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2070 // Set KeyboardFocusableChildren false.
2071 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2073 // Check that it will fail to set focus on the second actor as it's not focusable
2074 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2075 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2077 // Set KeyboardFocusableChildren true.
2078 first.SetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2080 // Check that the focus is set on the second actor
2081 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2082 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2087 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2089 ToolkitTestApplication application;
2091 tet_infoline("UtcDaliKeyboardFocusManagerCheckWheelEvent");
2092 Dali::Integration::Scene scene = application.GetScene();
2094 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2095 DALI_TEST_CHECK(!manager.GetCurrentFocusActor());
2097 // Create the first actor and add it to the stage
2098 Actor parent = Actor::New();
2099 parent.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2101 Actor child = Actor::New();
2102 child.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
2107 WheelEventCallback childCallback(false);
2108 child.WheelEventSignal().Connect(&childCallback, &WheelEventCallback::Callback);
2110 WheelEventCallback parentCallback(true);
2111 parent.WheelEventSignal().Connect(&parentCallback, &WheelEventCallback::Callback);
2113 WheelEventCallback sceneCallback(false);
2114 scene.WheelEventSignal().Connect(&sceneCallback, &WheelEventCallback::Callback);
2116 manager.SetCurrentFocusActor(child);
2118 // Emit custom wheel event is comming to KeyboardFocusManager
2119 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2120 application.ProcessEvent(event);
2122 DALI_TEST_CHECK(childCallback.mIsCalled);
2123 DALI_TEST_CHECK(parentCallback.mIsCalled);
2124 DALI_TEST_CHECK(!sceneCallback.mIsCalled);