2 * Copyright (c) 2021 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/devel-api/actors/actor-devel.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/wheel-event-integ.h>
27 #include <dali-toolkit-test-suite-utils.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
30 #include <dali-toolkit/devel-api/controls/control-devel.h>
31 #include <dali-toolkit/devel-api/controls/table-view/table-view.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;
50 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
52 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
53 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
56 CustomAlgorithm(bool& interfaceVerified)
57 : mInterfaceVerified(interfaceVerified),
58 mCurrentFocusedActor(),
59 mProposedActorToFocus(),
60 mDirection(Control::KeyboardFocus::LEFT)
64 Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
66 tet_infoline("Verifying CustomAlgorithm()");
68 mInterfaceVerified = true;
70 mCurrentFocusedActor = currentFocusedActor;
71 mProposedActorToFocus = proposedActorToFocus;
72 mDirection = direction;
74 return mProposedActorToFocus;
79 mInterfaceVerified = false;
80 mCurrentFocusedActor = Actor();
81 mProposedActorToFocus = Actor();
82 mDirection = Control::KeyboardFocus::LEFT;
85 bool& mInterfaceVerified;
86 Actor mCurrentFocusedActor;
87 Actor mProposedActorToFocus;
88 Control::KeyboardFocus::Direction mDirection;
91 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
92 class PreFocusChangeCallback : public Dali::ConnectionTracker
95 PreFocusChangeCallback(bool& signalReceived)
96 : mSignalVerified(signalReceived),
97 mCurrentFocusedActor(),
98 mProposedActorToFocus(),
99 mDirection(Control::KeyboardFocus::LEFT)
103 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
105 tet_infoline("Verifying PreFocusChangeCallback()");
107 mSignalVerified = true;
109 mCurrentFocusedActor = currentFocusedActor;
110 mProposedActorToFocus = proposedActorToFocus;
111 mDirection = direction;
113 return mProposedActorToFocus;
118 mSignalVerified = false;
119 mCurrentFocusedActor = Actor();
120 mProposedActorToFocus = Actor();
121 mDirection = Control::KeyboardFocus::LEFT;
124 bool& mSignalVerified;
125 Actor mCurrentFocusedActor;
126 Actor mProposedActorToFocus;
127 Control::KeyboardFocus::Direction mDirection;
130 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
131 class FocusChangedCallback : public Dali::ConnectionTracker
134 FocusChangedCallback(bool& signalReceived)
135 : mSignalVerified(signalReceived),
136 mOriginalFocusedActor(),
137 mCurrentFocusedActor()
141 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
143 tet_infoline("Verifying FocusChangedCallback()");
145 if(originalFocusedActor == mCurrentFocusedActor)
147 mSignalVerified = true;
150 mOriginalFocusedActor = originalFocusedActor;
151 mCurrentFocusedActor = currentFocusedActor;
156 mSignalVerified = false;
159 bool& mSignalVerified;
160 Actor mOriginalFocusedActor;
161 Actor mCurrentFocusedActor;
164 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
165 class FocusGroupChangedCallback : public Dali::ConnectionTracker
168 FocusGroupChangedCallback(bool& signalReceived)
169 : mSignalVerified(signalReceived),
170 mCurrentFocusedActor(),
175 void Callback(Actor currentFocusedActor, bool forward)
177 tet_infoline("Verifying FocusGroupChangedCallback()");
179 mSignalVerified = true;
181 mCurrentFocusedActor = currentFocusedActor;
187 mSignalVerified = false;
190 bool& mSignalVerified;
191 Actor mCurrentFocusedActor;
195 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
196 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
199 FocusedActorActivatedCallback(bool& signalReceived)
200 : mSignalVerified(signalReceived),
205 void Callback(Actor activatedActor)
207 tet_infoline("Verifying FocusedActorActivatedCallback()");
209 mSignalVerified = true;
211 mActivatedActor = activatedActor;
216 mSignalVerified = false;
219 bool& mSignalVerified;
220 Actor mActivatedActor;
223 class KeyEventCallback : public Dali::ConnectionTracker
228 * @param[in] returnValue Set return value of KeyEvent callback.
230 KeyEventCallback( bool consumed )
231 : mConsumed( consumed ),
236 bool Callback( Control control, const KeyEvent& keyEvent )
242 void Callback( const KeyEvent& keyEvent )
251 class WheelEventCallback : public Dali::ConnectionTracker
256 * @param[in] returnValue Set return value of WheelEvent callback.
258 WheelEventCallback( bool consumed )
259 : mConsumed( consumed ),
264 bool Callback( Actor actor, const WheelEvent& wheelEvent )
270 void Callback( const WheelEvent& wheelEvent )
279 // Used to connect to signals via the ConnectSignal Handle method
280 struct CallbackFunctor
293 int UtcDaliKeyboardFocusManagerGet(void)
295 ToolkitTestApplication application;
297 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
301 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
302 DALI_TEST_CHECK( type );
303 BaseHandle handle = type.CreateInstance();
304 DALI_TEST_CHECK( handle );
306 KeyboardFocusManager manager;
308 manager = KeyboardFocusManager::Get();
309 DALI_TEST_CHECK(manager);
311 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
312 DALI_TEST_CHECK(newManager);
314 // Check that focus manager is a singleton
315 DALI_TEST_CHECK(manager == newManager);
319 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
321 ToolkitTestApplication application;
323 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
325 KeyboardFocusManager manager = KeyboardFocusManager::Get();
326 DALI_TEST_CHECK(manager);
328 // Create the first actor and add it to the stage
329 Actor first = Actor::New();
330 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
331 application.GetScene().Add(first);
333 // Create the second actor and add it to the stage
334 Actor second = Actor::New();
335 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
336 application.GetScene().Add(second);
338 // Create the third actor but don't add it to the stage
339 Actor third = Actor::New();
341 // Check that no actor is being focused yet.
342 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
344 // Check that it will fail to set focus on an invalid actor
345 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
347 // Check that the focus is set on the first actor
348 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
349 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
351 // Check that the focus is set on the second actor
352 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
353 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
355 // Check that it will fail to set focus on the third actor as it's not in the stage
356 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
357 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
359 // Add the third actor to the stage
360 application.GetScene().Add(third);
362 // Check that it will fail to set focus on the third actor as it's not focusable
363 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
364 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
366 // Make the third actor focusable
367 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
369 // Check that the focus is successfully moved to the third actor
370 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
371 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
375 int UtcDaliKeyboardFocusManagerMoveFocus(void)
377 ToolkitTestApplication application;
379 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
383 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
384 DALI_TEST_CHECK( type );
385 BaseHandle handle = type.CreateInstance();
386 DALI_TEST_CHECK( handle );
388 KeyboardFocusManager manager = KeyboardFocusManager::Get();
389 DALI_TEST_CHECK(manager);
391 bool preFocusChangeSignalVerified = false;
392 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
393 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
395 bool focusChangedSignalVerified = false;
396 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
397 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
399 // Create the first actor and add it to the stage
400 Actor first = Actor::New();
401 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
402 application.GetScene().Add(first);
404 // Create the second actor and add it to the stage
405 Actor second = Actor::New();
406 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
407 application.GetScene().Add(second);
409 // Move the focus to the right
410 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
412 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
413 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
414 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
415 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
416 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
417 preFocusChangeCallback.Reset();
419 // Check that the focus is set on the first actor
420 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
421 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
422 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
423 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
424 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
425 focusChangedCallback.Reset();
427 // Move the focus towards right
428 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
430 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
431 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
432 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
433 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
434 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
435 preFocusChangeCallback.Reset();
437 // Check that the focus is set on the second actor
438 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
439 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
440 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
441 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
442 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
443 focusChangedCallback.Reset();
445 // Move the focus towards up
446 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
448 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
449 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
450 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
451 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
452 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
453 preFocusChangeCallback.Reset();
454 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
456 // Create a 2x2 table view and try to move focus inside it
457 TableView tableView = TableView::New( 2, 2 );
458 application.GetScene().Add(tableView);
460 // Create the third actor
461 Actor third = Actor::New();
462 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
464 // Create the fourth actor
465 Actor fourth = Actor::New();
466 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
468 // Add the four children to table view
469 tableView.AddChild(first, TableView::CellPosition(0, 0));
470 tableView.AddChild(second, TableView::CellPosition(0, 1));
471 tableView.AddChild(third, TableView::CellPosition(1, 0));
472 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
474 // Set the focus to the first actor
475 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
476 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
477 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
478 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
479 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
480 focusChangedCallback.Reset();
482 // Move the focus towards right
483 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
484 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
485 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
486 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
487 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
488 focusChangedCallback.Reset();
490 // Move the focus towards down
491 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
492 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
493 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
494 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
495 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
496 focusChangedCallback.Reset();
498 // Move the focus towards left
499 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
500 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
501 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
502 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
503 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
504 focusChangedCallback.Reset();
506 // Move the focus towards up
507 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
508 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
509 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
510 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
511 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
512 focusChangedCallback.Reset();
514 // Move the focus towards left. The focus move will fail as no way to move it upwards
515 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
516 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
517 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
518 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
519 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
520 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
521 preFocusChangeCallback.Reset();
522 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
525 manager.SetFocusGroupLoop(true);
526 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
528 // Move the focus towards left again. The focus should move to the fourth actor.
529 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
530 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
531 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
532 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
533 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
534 focusChangedCallback.Reset();
538 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
540 ToolkitTestApplication application;
542 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
546 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
547 DALI_TEST_CHECK( type );
548 BaseHandle handle = type.CreateInstance();
549 DALI_TEST_CHECK( handle );
551 KeyboardFocusManager manager = KeyboardFocusManager::Get();
552 DALI_TEST_CHECK(manager);
554 bool preFocusChangeSignalVerified = false;
555 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
556 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
558 bool focusChangedSignalVerified = false;
559 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
560 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
562 // Create the first actor and add it to the stage
563 Actor first = Actor::New();
564 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
565 application.GetScene().Add(first);
567 // Create the second actor and add it to the stage
568 Actor second = Actor::New();
569 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
570 application.GetScene().Add(second);
572 // Move the focus to the right
573 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
575 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
576 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
577 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
578 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
579 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
580 preFocusChangeCallback.Reset();
582 bool customAlgorithmInterfaceVerified = false;
583 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
584 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
586 // Move the focus towards right
587 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
589 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
590 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
591 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
592 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
593 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
594 customAlgorithm.Reset();
596 // Check that the focus is set on the first actor
597 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
598 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
599 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
600 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
601 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
602 focusChangedCallback.Reset();
604 // Move the focus towards right
605 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
607 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
608 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
609 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
610 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
611 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
612 customAlgorithm.Reset();
614 // Check that the focus is set on the second actor
615 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
616 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
617 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
618 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
619 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
620 focusChangedCallback.Reset();
622 // Move the focus towards up
623 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
625 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
626 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
627 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
628 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
629 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
630 customAlgorithm.Reset();
631 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
635 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
637 ToolkitTestApplication application;
639 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
643 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
644 DALI_TEST_CHECK( type );
645 BaseHandle handle = type.CreateInstance();
646 DALI_TEST_CHECK( handle );
648 KeyboardFocusManager manager = KeyboardFocusManager::Get();
649 DALI_TEST_CHECK(manager);
651 bool focusChangedSignalVerified = false;
652 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
653 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
655 PushButton button1 = PushButton::New();
656 PushButton button2 = PushButton::New();
657 button1.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
658 button2.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
659 application.GetScene().Add(button1);
660 application.GetScene().Add(button2);
662 // Set the focus to the button1
663 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
664 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
665 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
666 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
667 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
668 focusChangedCallback.Reset();
670 // set the navigation properties of button1
671 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
672 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
673 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
674 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
676 // set the navigation properties of button2
677 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
678 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
679 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
680 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
682 // Move the focus towards left
683 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
685 // Confirm whether focus is moved to button2
686 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
687 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
688 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
689 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
690 focusChangedCallback.Reset();
692 // Move the focus towards right
693 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
695 // Confirm whether focus is moved to button1
696 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
697 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
698 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
699 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
700 focusChangedCallback.Reset();
702 // Move the focus towards up
703 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
705 // Confirm whether focus is moved to button2
706 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
707 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
708 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
709 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
710 focusChangedCallback.Reset();
712 // Move the focus towards down
713 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
715 // Confirm whether focus is moved to button1
716 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
717 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
718 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
719 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
720 focusChangedCallback.Reset();
722 // Create a 1x1 table view and try to move focus inside it
723 TableView tableView = TableView::New( 1, 1 );
724 application.GetScene().Add(tableView);
726 PushButton button = PushButton::New();
727 button.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
728 tableView.AddChild(button, TableView::CellPosition(0, 0));
730 // set the navigation properties of button3
731 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
733 // Set the focus to the button
734 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
735 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
736 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
737 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
738 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
739 focusChangedCallback.Reset();
741 // Move the focus towards left
742 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
744 // Confirm whether focus is moved to button1
745 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
746 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
747 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
748 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
749 focusChangedCallback.Reset();
754 int UtcDaliKeyboardFocusManagerClearFocus(void)
756 ToolkitTestApplication application;
758 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
760 KeyboardFocusManager manager = KeyboardFocusManager::Get();
761 DALI_TEST_CHECK(manager);
763 // Create the first actor and add it to the stage
764 Actor first = Actor::New();
765 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
766 application.GetScene().Add(first);
768 // Create the second actor and add it to the stage
769 Actor second = Actor::New();
770 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
771 application.GetScene().Add(second);
773 // Check that the focus is set on the first actor
774 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
775 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
777 // Check that the focus is set on the second actor
778 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
779 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
782 manager.ClearFocus();
784 // Check that no actor is being focused now.
785 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
789 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
791 ToolkitTestApplication application;
793 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
795 KeyboardFocusManager manager = KeyboardFocusManager::Get();
796 DALI_TEST_CHECK(manager);
798 // Check that the focus movement is not looped within the same focus group by default
799 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
802 manager.SetFocusGroupLoop(true);
803 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
807 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
809 ToolkitTestApplication application;
811 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
813 KeyboardFocusManager manager = KeyboardFocusManager::Get();
814 DALI_TEST_CHECK(manager);
816 // Create an actor and check that it is not a focus group by default
817 Actor actor = Actor::New();
818 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
820 // Set the actor as focus group
821 manager.SetAsFocusGroup(actor, true);
823 // flush the queue and render once
824 application.SendNotification();
825 application.Render();
827 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
829 // Set the actor not as focus group
830 manager.SetAsFocusGroup(actor, false);
832 // flush the queue and render once
833 application.SendNotification();
834 application.Render();
836 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
840 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
842 ToolkitTestApplication application;
844 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
846 KeyboardFocusManager manager = KeyboardFocusManager::Get();
847 DALI_TEST_CHECK(manager);
849 // Create an actor with two child actors and add it to the stage
850 Actor parent = Actor::New();
851 Actor child = Actor::New();
853 application.GetScene().Add(parent);
855 // Create three actors and add them as the children of the first child actor
856 Actor grandChild = Actor::New();
857 child.Add(grandChild);
859 // Set the parent and the first child actor as focus groups
860 manager.SetAsFocusGroup(parent, true);
862 // flush the queue and render once
863 application.SendNotification();
864 application.Render();
866 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
868 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
869 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
871 manager.SetAsFocusGroup(child, true);
873 // flush the queue and render once
874 application.SendNotification();
875 application.Render();
877 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
879 // The focus group should be the child, As it is the immediate parent which is also a focus group.
880 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
882 manager.SetAsFocusGroup(grandChild, true);
884 // flush the queue and render once
885 application.SendNotification();
886 application.Render();
888 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
890 // The current focus group should be itself, As it is also a focus group.
891 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
895 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
897 ToolkitTestApplication application;
899 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
901 KeyboardFocusManager manager = KeyboardFocusManager::Get();
902 DALI_TEST_CHECK(manager);
904 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
905 DALI_TEST_CHECK(defaultFocusIndicatorActor);
907 Actor newFocusIndicatorActor = Actor::New();
908 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
909 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
914 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
916 ToolkitTestApplication application;
918 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
920 KeyboardFocusManager manager = KeyboardFocusManager::Get();
921 DALI_TEST_CHECK(manager);
923 bool focusedActorActivatedSignalVerified = false;
924 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
925 manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
927 Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
929 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
930 // It makes mIsFocusIndicatorEnabled true
931 application.ProcessEvent(returnEvent);
933 // Create the first button and add it to the stage
934 PushButton firstPushButton = PushButton::New();
935 firstPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
936 application.GetScene().Add(firstPushButton);
938 // Create the second button and add it to the stage
939 PushButton secondPushButton = PushButton::New();
940 secondPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
941 application.GetScene().Add(secondPushButton);
943 // Check that the focus is set on the first button
944 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
945 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
947 // Send the return event to activate the first button
948 application.ProcessEvent(returnEvent);
949 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
950 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
951 focusedActorActivatedCallback.Reset();
953 // Check that the focus is set on the second button
954 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
955 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
957 // Send the return event again to activate the second button
958 application.ProcessEvent(returnEvent);
959 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
960 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
961 focusedActorActivatedCallback.Reset();
965 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
967 ToolkitTestApplication application;
969 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
973 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
974 DALI_TEST_CHECK( type );
975 BaseHandle handle = type.CreateInstance();
976 DALI_TEST_CHECK( handle );
978 KeyboardFocusManager manager = KeyboardFocusManager::Get();
979 DALI_TEST_CHECK(manager);
981 bool focusGroupChangedSignalVerified = false;
982 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
983 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
985 Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
986 Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
988 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
989 // It makes mIsFocusIndicatorEnabled true
990 application.ProcessEvent(tabEvent);
992 // Send the tab event to change focus group in the forward direction
993 application.ProcessEvent(tabEvent);
994 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
995 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
996 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
997 focusGroupChangedCallback.Reset();
999 // Send the shift tab event to change focus group in the backward direction
1000 application.ProcessEvent(shiftTabEvent);
1001 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
1002 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
1003 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
1004 focusGroupChangedCallback.Reset();
1008 int UtcDaliKeyboardFocusManagerSignals(void)
1010 ToolkitTestApplication application;
1012 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1013 DALI_TEST_CHECK( manager );
1015 ConnectionTracker* testTracker = new ConnectionTracker();
1016 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
1017 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
1018 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
1019 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
1024 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
1026 ToolkitTestApplication application;
1028 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1030 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1031 DALI_TEST_CHECK(manager);
1033 // Create the first actor and add it to the stage
1034 Actor first = Actor::New();
1035 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1036 application.GetScene().Add(first);
1038 // Create the second actor and add it to the stage
1039 Actor second = Actor::New();
1040 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1041 application.GetScene().Add(second);
1043 // Create the third actor and add it to the stage
1044 Actor third = Actor::New();
1045 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1046 application.GetScene().Add(third);
1048 // Create the fourth actor and add it to the stage
1049 Actor fourth = Actor::New();
1050 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1051 application.GetScene().Add(fourth);
1053 // Check that the focus is set on the second actor
1054 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1055 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1057 // Check that the focus is set on the second actor
1058 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1059 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1061 // Check that the focus is set on the third actor
1062 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1063 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1065 // Check that the focus is set on the third actor
1066 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1067 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1069 // Move the focus backward
1070 manager.MoveFocusBackward();
1072 // Check that it current focused actor is third actor
1073 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1075 // Remove the second actor on stage
1078 // Reset the first actor
1082 // Move the focus backward
1083 manager.MoveFocusBackward();
1085 // Check that it current focused actor is third actor
1086 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1088 // Make history stack full
1089 for(int i = 0 ; i < 31 ; i ++)
1091 Actor actor = Actor::New();
1092 actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1093 application.GetScene().Add(actor);
1094 manager.SetCurrentFocusActor(actor);
1097 for(int i = 0 ; i < 31 ; i ++)
1099 manager.MoveFocusBackward();
1102 // Check that it current focused actor is not second actor
1103 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1108 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1110 ToolkitTestApplication application;
1112 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1114 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1115 DALI_TEST_CHECK(manager);
1117 bool preFocusChangeSignalVerified = false;
1118 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1119 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1121 bool focusChangedSignalVerified = false;
1122 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1123 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1125 Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1126 Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1127 Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1128 Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1129 Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1130 Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1132 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1133 // It makes mIsFocusIndicatorEnabled true
1134 application.ProcessEvent(leftEvent);
1136 // Create a 2x2 table view and try to move focus inside it
1137 TableView tableView = TableView::New( 2, 2 );
1138 application.GetScene().Add(tableView);
1140 // Create the first actor
1141 Actor first = Actor::New();
1142 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1144 // Create the second actor
1145 Actor second = Actor::New();
1146 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1148 // Create the third actor
1149 Actor third = Actor::New();
1150 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1152 // Create the fourth actor
1153 Actor fourth = Actor::New();
1154 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1156 // Add the four children to table view
1157 tableView.AddChild(first, TableView::CellPosition(0, 0));
1158 tableView.AddChild(second, TableView::CellPosition(0, 1));
1159 tableView.AddChild(third, TableView::CellPosition(1, 0));
1160 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1162 // Set the focus to the first actor
1163 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1164 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1165 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1166 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1167 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1168 focusChangedCallback.Reset();
1170 // Send the right key event to move the focus towards right
1171 application.ProcessEvent(rightEvent);
1172 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1173 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1174 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1175 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1176 focusChangedCallback.Reset();
1178 // Send the down key event to move the focus towards down
1179 application.ProcessEvent(downEvent);
1180 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1181 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1182 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1183 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1184 focusChangedCallback.Reset();
1186 // Send the down event to move the focus towards left
1187 application.ProcessEvent(leftEvent);
1188 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1189 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1190 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1191 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1192 focusChangedCallback.Reset();
1194 // Send the up event to move the focus towards up
1195 application.ProcessEvent(upEvent);
1196 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1197 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1198 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1199 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1200 focusChangedCallback.Reset();
1202 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1203 application.ProcessEvent(pageUpEvent);
1204 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1205 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1206 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1207 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1208 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1209 preFocusChangeCallback.Reset();
1211 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1212 application.ProcessEvent(pageDownEvent);
1213 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1214 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1215 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1216 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1217 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1218 preFocusChangeCallback.Reset();
1221 manager.ClearFocus();
1223 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1224 preFocusChangeCallback.Reset();
1225 application.ProcessEvent(pageUpEvent);
1226 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1227 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1228 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1229 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1230 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1232 // Clear the focus again
1233 manager.ClearFocus();
1235 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1236 preFocusChangeCallback.Reset();
1237 application.ProcessEvent(pageDownEvent);
1238 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1239 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1240 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1241 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1242 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1244 // Clear the focus again
1245 manager.ClearFocus();
1247 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1248 preFocusChangeCallback.Reset();
1249 application.ProcessEvent(upEvent);
1250 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1251 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1252 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1253 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1255 // Clear the focus again
1256 manager.ClearFocus();
1258 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1259 preFocusChangeCallback.Reset();
1260 application.ProcessEvent(downEvent);
1261 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1262 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1263 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1264 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1269 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1271 ToolkitTestApplication application;
1273 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1275 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1276 DALI_TEST_CHECK(manager);
1278 bool preFocusChangeSignalVerified = false;
1279 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1280 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1282 Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1284 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1285 // It makes mIsFocusIndicatorEnabled true
1286 application.ProcessEvent(spaceEvent);
1288 // Send the space event
1289 application.ProcessEvent(spaceEvent);
1290 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1291 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1293 // Clear the focus again
1294 manager.ClearFocus();
1296 // Send the space event again for line coverage
1297 preFocusChangeCallback.Reset();
1298 application.ProcessEvent(spaceEvent);
1299 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1300 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1301 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1302 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1309 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1311 ToolkitTestApplication application;
1313 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1317 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1318 DALI_TEST_CHECK( type );
1319 BaseHandle handle = type.CreateInstance();
1320 DALI_TEST_CHECK( handle );
1322 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1323 DALI_TEST_CHECK(manager);
1325 bool preFocusChangeSignalVerified = false;
1326 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1327 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1329 bool focusChangedSignalVerified = false;
1330 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1331 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1333 // Create the first actor and add it to the stage
1334 Control first = Control::New();
1335 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1336 application.GetScene().Add(first);
1338 // Create the second actor and add it to the stage
1339 Control second = Control::New();
1340 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1341 application.GetScene().Add(second);
1343 // Move the focus to the right
1344 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1346 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1347 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1348 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1349 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1350 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1351 preFocusChangeCallback.Reset();
1353 // Check that the focus is set on the first actor
1354 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1355 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1356 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1357 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1358 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1359 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1360 focusChangedCallback.Reset();
1362 // Move the focus towards right
1363 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1365 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1366 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1367 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1368 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1369 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1370 preFocusChangeCallback.Reset();
1372 // Check that the focus is set on the second actor
1373 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1374 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1375 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1376 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1377 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1378 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1379 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1380 focusChangedCallback.Reset();
1382 // Move the focus towards up
1383 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1385 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1386 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1387 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1388 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1389 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1390 preFocusChangeCallback.Reset();
1391 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1393 // Create a 2x2 table view and try to move focus inside it
1394 TableView tableView = TableView::New( 2, 2 );
1395 application.GetScene().Add(tableView);
1397 // Create the third actor
1398 Control third = Control::New();
1399 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1401 // Create the fourth actor
1402 Control fourth = Control::New();
1403 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1405 // Add the four children to table view
1406 tableView.AddChild(first, TableView::CellPosition(0, 0));
1407 tableView.AddChild(second, TableView::CellPosition(0, 1));
1408 tableView.AddChild(third, TableView::CellPosition(1, 0));
1409 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1411 // Set the focus to the first actor
1412 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1413 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1414 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1415 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1416 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1418 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1419 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1421 focusChangedCallback.Reset();
1423 // Move the focus towards right
1424 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1425 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1426 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1427 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1428 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1429 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1430 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1432 focusChangedCallback.Reset();
1434 // Move the focus towards down
1435 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1436 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1437 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1438 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1439 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1441 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1442 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1443 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1444 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1446 focusChangedCallback.Reset();
1448 // Move the focus towards left
1449 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1450 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1451 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1452 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1453 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1455 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1456 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1457 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1458 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1460 focusChangedCallback.Reset();
1462 // Move the focus towards up
1463 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1464 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1465 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1466 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1467 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1468 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, 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::NORMAL, TEST_LOCATION );
1472 focusChangedCallback.Reset();
1474 // Move the focus towards left. The focus move will fail as no way to move it upwards
1475 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1476 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1477 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1478 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1479 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1480 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1481 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1482 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1483 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1484 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1486 preFocusChangeCallback.Reset();
1487 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1490 manager.SetFocusGroupLoop(true);
1491 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1493 // Move the focus towards left again. The focus should move to the fourth actor.
1494 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1495 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1496 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1497 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1498 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1500 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1501 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1502 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1503 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1505 focusChangedCallback.Reset();
1508 manager.ClearFocus();
1509 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1510 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1511 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1512 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1518 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1520 ToolkitTestApplication application;
1522 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" );
1524 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1525 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1527 Actor actor = Actor::New();
1528 actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1530 tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1531 manager.SetCurrentFocusActor( actor );
1532 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1534 tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1535 application.GetScene().Add( actor );
1536 manager.SetCurrentFocusActor( actor );
1537 DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1539 tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1541 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1546 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1548 ToolkitTestApplication application;
1550 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" );
1552 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1553 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1555 Actor actor = Actor::New();
1556 actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1557 application.GetScene().Add( actor );
1558 manager.SetCurrentFocusActor( actor );
1560 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1561 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1562 Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1563 application.ProcessEvent(rightEvent);
1565 Actor indicatorActor = manager.GetFocusIndicatorActor();
1567 tet_infoline( "Indicator is added to focused actor" );
1568 DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1570 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1571 DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1573 tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1574 DALI_TEST_CHECK( !indicatorActor.GetParent() );
1579 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1581 ToolkitTestApplication application;
1583 tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
1584 Dali::Integration::Scene scene = application.GetScene();
1586 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1587 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1589 // Create the first actor and add it to the stage
1590 Control control = Control::New();
1591 control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1594 KeyEventCallback controlCallback( true );
1595 control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
1597 KeyEventCallback sceneCallback( false );
1598 scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
1600 manager.SetCurrentFocusActor( control );
1602 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1603 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1604 Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1605 application.ProcessEvent(event1);
1607 DALI_TEST_CHECK( controlCallback.mIsCalled );
1608 DALI_TEST_CHECK( !sceneCallback.mIsCalled );
1613 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1615 ToolkitTestApplication application;
1617 tet_infoline( "Ensure Memory focus actors for each window ");
1618 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1619 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1621 Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false);
1622 DALI_TEST_CHECK( firstWindow );
1623 Control first = Control::New();
1624 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1625 firstWindow.Add(first);
1627 Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false);
1628 DALI_TEST_CHECK( secondWindow );
1629 Control second = Control::New();
1630 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1631 secondWindow.Add( second );
1633 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1634 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1636 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1637 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1638 firstWindow.Raise();
1639 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1641 secondWindow.Remove( second );
1642 secondWindow.Raise();
1643 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1645 secondWindow.Reset();
1649 int UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus(void)
1651 ToolkitTestApplication application;
1653 tet_infoline(" UtcDaliKeyboardFocusManagerWithoutFocusablePropertiesMoveFocus");
1657 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1658 DALI_TEST_CHECK( type );
1659 BaseHandle handle = type.CreateInstance();
1660 DALI_TEST_CHECK( handle );
1662 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1663 DALI_TEST_CHECK(manager);
1665 bool focusChangedSignalVerified = false;
1666 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1667 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1669 PushButton button1 = PushButton::New();
1670 PushButton button2 = PushButton::New();
1671 PushButton button3 = PushButton::New();
1672 PushButton button4 = PushButton::New();
1673 PushButton button5 = PushButton::New();
1675 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1676 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1677 button3.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1678 button4.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1679 button5.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1681 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1682 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1683 button3.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1684 button4.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1685 button5.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1687 application.GetScene().Add(button1);
1688 application.GetScene().Add(button2);
1689 application.GetScene().Add(button3);
1690 button5.Add(button4);
1691 application.GetScene().Add(button5);
1694 // button1 -- button2
1697 // button3 -- button4
1698 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1699 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1700 button3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
1701 button4.SetProperty(Actor::Property::POSITION, Vector2(40.0f, 40.0f));
1702 button5.SetProperty(Actor::Property::POSITION, Vector2(60.0f, 60.0f));
1704 // flush the queue and render once
1705 application.SendNotification();
1706 application.Render();
1708 // Set the focus to the button1
1709 // [button1] -- button2
1712 // button3 -- button4
1713 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1714 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1715 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1716 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1717 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1718 focusChangedCallback.Reset();
1720 // without set the navigation properties, but we can focus move
1721 // enable the default algorithm
1722 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1723 DALI_TEST_CHECK( Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
1725 // Move the focus towards right
1726 // button1 -- [button2]
1729 // button3 -- button4
1730 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1732 // Confirm whether focus is moved to button2
1733 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1734 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1735 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1736 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1737 focusChangedCallback.Reset();
1739 // Move the focus towards down
1740 // button1 -- button2
1743 // button3 -- button4
1744 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1746 // Confirm whether focus is moved to button5
1747 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1748 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1749 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
1750 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1751 focusChangedCallback.Reset();
1753 // Move the focus towards right
1754 // button1 -- button2
1757 // button3 -- [button4]
1758 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1760 // Confirm whether focus is moved to button4
1761 DALI_TEST_EQUALS(button4.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1762 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1763 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1764 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button4);
1765 focusChangedCallback.Reset();
1767 // Move the focus towards left
1768 // button1 -- button2
1771 // button3 -- button4
1772 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1774 // Confirm whether focus is moved to button5
1775 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1776 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1777 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button4);
1778 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1779 focusChangedCallback.Reset();
1781 // Move the focus towards left
1782 // button1 -- button2
1785 //[button3] -- button4
1786 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1788 // Confirm whether focus is moved to button3
1789 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1790 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1791 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1792 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1793 focusChangedCallback.Reset();
1795 // Move the focus towards right
1796 // button1 -- button2
1799 // button3 -- button4
1800 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1802 // Confirm whether focus is moved to button5
1803 DALI_TEST_EQUALS(button5.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1804 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1805 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1806 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button5);
1807 focusChangedCallback.Reset();
1809 // Move the focus towards left
1810 // button1 -- button2
1813 //[button3] -- button4
1814 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1816 // Confirm whether focus is moved to button3
1817 DALI_TEST_EQUALS(button3.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1818 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1819 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button5);
1820 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button3);
1821 focusChangedCallback.Reset();
1823 // Move the focus towards up
1824 //[button1]-- button2
1827 // button3 -- button4
1828 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1830 // Confirm whether focus is moved to button1
1831 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1832 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1833 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button3);
1834 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1835 focusChangedCallback.Reset();
1838 // Move the focus towards left. The focus move will fail as no way to move it upwards
1839 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1841 // Move the focus toward page up/down. The focus move will fail as invalid direction.
1842 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_UP) == false);
1843 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::PAGE_DOWN) == false);
1844 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);
1887 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
1888 Dali::Integration::Point pointDown1;
1889 pointDown1.SetState( PointState::DOWN );
1890 pointDown1.SetDeviceId(1);
1891 // touch first actor
1892 pointDown1.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1893 event1.AddPoint(pointDown1);
1894 application.ProcessEvent( event1 );
1896 // flush the queue and render once
1897 application.SendNotification();
1898 application.Render();
1900 // Check that the focus is successfully to the first actor
1901 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1903 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
1904 Dali::Integration::Point pointDown2;
1905 pointDown2.SetState( PointState::DOWN );
1906 pointDown2.SetDeviceId(1);
1907 // touch second actor
1908 pointDown2.SetScreenPosition( Vector2( 110.0f, 10.0f ) );
1909 event2.AddPoint(pointDown2);
1910 application.ProcessEvent( event2 );
1912 // flush the queue and render once
1913 application.SendNotification();
1914 application.Render();
1916 // Check that the focus is successfully to clear
1917 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1919 // Make the second actor focusableInTouchMode
1920 second.SetProperty( DevelActor::Property::TOUCH_FOCUSABLE,true);
1922 // touch second actor
1923 application.ProcessEvent( event2 );
1925 // flush the queue and render once
1926 application.SendNotification();
1927 application.Render();
1929 // Check that the focus is successfully to the second actor
1930 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1935 int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
1937 ToolkitTestApplication application;
1939 tet_infoline(" UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm");
1943 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1944 DALI_TEST_CHECK( type );
1945 BaseHandle handle = type.CreateInstance();
1946 DALI_TEST_CHECK( handle );
1948 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1949 DALI_TEST_CHECK(manager);
1951 bool focusChangedSignalVerified = false;
1952 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1953 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1955 PushButton button1 = PushButton::New();
1956 PushButton button2 = PushButton::New();
1958 button1.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1959 button2.SetProperty(Actor::Property::SIZE, Vector2(50, 50));
1961 button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1962 button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE,true);
1964 application.GetScene().Add(button1);
1965 application.GetScene().Add(button2);
1968 // button1 -- button2
1969 button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1970 button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
1972 // flush the queue and render once
1973 application.SendNotification();
1974 application.Render();
1976 // Set the focus to the button1
1977 // [button1] -- button2
1978 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
1979 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
1980 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1981 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1982 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
1983 focusChangedCallback.Reset();
1985 // without set the navigation properties, but we can focus move
1986 // enable the default algorithm
1987 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1988 DALI_TEST_CHECK( Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
1990 // Move the focus towards right
1991 // button1 -- [button2]
1992 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1994 // Confirm whether focus is moved to button2
1995 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
1996 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1997 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
1998 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
1999 focusChangedCallback.Reset();
2001 // disable the default algorithm
2002 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, false);
2003 DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
2005 // Move the focus towards left, The focus move will fail because the default algorithm is disabled.
2006 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
2008 // enable the default algorithm
2009 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
2010 DALI_TEST_CHECK( Dali::Toolkit::DevelKeyboardFocusManager::IsDefaultAlgorithmEnabled(manager) );
2012 // Move the focus towards left, The focus move will success because the default algorithm is enabled.
2013 // [button1] -- button2
2014 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
2015 // Confirm whether focus is moved to button2
2016 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
2017 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
2018 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
2019 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
2020 focusChangedCallback.Reset();
2027 int UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren(void)
2029 ToolkitTestApplication application;
2031 tet_infoline(" UtcDaliKeyboardFocusManagerWithKeyboardFocusableChildren");
2033 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2034 DALI_TEST_CHECK(manager);
2036 // Create the first actor and add it to the stage
2037 Actor first = Actor::New();
2038 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true);
2039 application.GetScene().Add(first);
2041 // Create the second actor and add it to the first actor.
2042 Actor second = Actor::New();
2043 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true);
2046 // Check that no actor is being focused yet.
2047 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
2049 // Check that the focus is set on the first actor
2050 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
2051 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2053 // Set KeyboardFocusableChildren false.
2054 first.SetProperty( DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, false);
2056 // Check that it will fail to set focus on the second actor as it's not focusable
2057 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false);
2058 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
2060 // Set KeyboardFocusableChildren true.
2061 first.SetProperty( DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN, true);
2063 // Check that the focus is set on the second actor
2064 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
2065 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
2070 int UtcDaliKeyboardFocusManagerCheckWheelEvent(void)
2072 ToolkitTestApplication application;
2074 tet_infoline( "UtcDaliKeyboardFocusManagerCheckWheelEvent" );
2075 Dali::Integration::Scene scene = application.GetScene();
2077 KeyboardFocusManager manager = KeyboardFocusManager::Get();
2078 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
2080 // Create the first actor and add it to the stage
2081 Actor parent = Actor::New();
2082 parent.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2084 Actor child = Actor::New();
2085 child.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
2090 WheelEventCallback childCallback( false );
2091 child.WheelEventSignal().Connect( &childCallback, &WheelEventCallback::Callback );
2093 WheelEventCallback parentCallback( true );
2094 parent.WheelEventSignal().Connect( &parentCallback, &WheelEventCallback::Callback );
2096 WheelEventCallback sceneCallback( false );
2097 scene.WheelEventSignal().Connect( &sceneCallback, &WheelEventCallback::Callback );
2099 manager.SetCurrentFocusActor( child );
2101 // Emit custom wheel event is comming to KeyboardFocusManager
2102 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2103 application.ProcessEvent(event);
2105 DALI_TEST_CHECK( childCallback.mIsCalled );
2106 DALI_TEST_CHECK( parentCallback.mIsCalled );
2107 DALI_TEST_CHECK( !sceneCallback.mIsCalled );