2 * Copyright (c) 2020 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>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
32 using namespace Dali::Toolkit;
34 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
41 test_return_value = TET_PASS;
48 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
50 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
51 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
54 CustomAlgorithm(bool& interfaceVerified)
55 : mInterfaceVerified(interfaceVerified),
56 mCurrentFocusedActor(),
57 mProposedActorToFocus(),
58 mDirection(Control::KeyboardFocus::LEFT)
62 Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
64 tet_infoline("Verifying CustomAlgorithm()");
66 mInterfaceVerified = true;
68 mCurrentFocusedActor = currentFocusedActor;
69 mProposedActorToFocus = proposedActorToFocus;
70 mDirection = direction;
72 return mProposedActorToFocus;
77 mInterfaceVerified = false;
78 mCurrentFocusedActor = Actor();
79 mProposedActorToFocus = Actor();
80 mDirection = Control::KeyboardFocus::LEFT;
83 bool& mInterfaceVerified;
84 Actor mCurrentFocusedActor;
85 Actor mProposedActorToFocus;
86 Control::KeyboardFocus::Direction mDirection;
89 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
90 class PreFocusChangeCallback : public Dali::ConnectionTracker
93 PreFocusChangeCallback(bool& signalReceived)
94 : mSignalVerified(signalReceived),
95 mCurrentFocusedActor(),
96 mProposedActorToFocus(),
97 mDirection(Control::KeyboardFocus::LEFT)
101 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
103 tet_infoline("Verifying PreFocusChangeCallback()");
105 mSignalVerified = true;
107 mCurrentFocusedActor = currentFocusedActor;
108 mProposedActorToFocus = proposedActorToFocus;
109 mDirection = direction;
111 return mProposedActorToFocus;
116 mSignalVerified = false;
117 mCurrentFocusedActor = Actor();
118 mProposedActorToFocus = Actor();
119 mDirection = Control::KeyboardFocus::LEFT;
122 bool& mSignalVerified;
123 Actor mCurrentFocusedActor;
124 Actor mProposedActorToFocus;
125 Control::KeyboardFocus::Direction mDirection;
128 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
129 class FocusChangedCallback : public Dali::ConnectionTracker
132 FocusChangedCallback(bool& signalReceived)
133 : mSignalVerified(signalReceived),
134 mOriginalFocusedActor(),
135 mCurrentFocusedActor()
139 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
141 tet_infoline("Verifying FocusChangedCallback()");
143 if(originalFocusedActor == mCurrentFocusedActor)
145 mSignalVerified = true;
148 mOriginalFocusedActor = originalFocusedActor;
149 mCurrentFocusedActor = currentFocusedActor;
154 mSignalVerified = false;
157 bool& mSignalVerified;
158 Actor mOriginalFocusedActor;
159 Actor mCurrentFocusedActor;
162 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
163 class FocusGroupChangedCallback : public Dali::ConnectionTracker
166 FocusGroupChangedCallback(bool& signalReceived)
167 : mSignalVerified(signalReceived),
168 mCurrentFocusedActor(),
173 void Callback(Actor currentFocusedActor, bool forward)
175 tet_infoline("Verifying FocusGroupChangedCallback()");
177 mSignalVerified = true;
179 mCurrentFocusedActor = currentFocusedActor;
185 mSignalVerified = false;
188 bool& mSignalVerified;
189 Actor mCurrentFocusedActor;
193 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
194 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
197 FocusedActorActivatedCallback(bool& signalReceived)
198 : mSignalVerified(signalReceived),
203 void Callback(Actor activatedActor)
205 tet_infoline("Verifying FocusedActorActivatedCallback()");
207 mSignalVerified = true;
209 mActivatedActor = activatedActor;
214 mSignalVerified = false;
217 bool& mSignalVerified;
218 Actor mActivatedActor;
221 class KeyEventCallback : public Dali::ConnectionTracker
226 * @param[in] returnValue Set return value of KeyEvent callback.
228 KeyEventCallback( bool consumed )
229 : mConsumed( consumed ),
234 bool Callback( Control control, const KeyEvent& keyEvent )
240 void Callback( const KeyEvent& keyEvent )
249 // Used to connect to signals via the ConnectSignal Handle method
250 struct CallbackFunctor
263 int UtcDaliKeyboardFocusManagerGet(void)
265 ToolkitTestApplication application;
267 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
271 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
272 DALI_TEST_CHECK( type );
273 BaseHandle handle = type.CreateInstance();
274 DALI_TEST_CHECK( handle );
276 KeyboardFocusManager manager;
278 manager = KeyboardFocusManager::Get();
279 DALI_TEST_CHECK(manager);
281 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
282 DALI_TEST_CHECK(newManager);
284 // Check that focus manager is a singleton
285 DALI_TEST_CHECK(manager == newManager);
289 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
291 ToolkitTestApplication application;
293 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
295 KeyboardFocusManager manager = KeyboardFocusManager::Get();
296 DALI_TEST_CHECK(manager);
298 // Create the first actor and add it to the stage
299 Actor first = Actor::New();
300 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
301 application.GetScene().Add(first);
303 // Create the second actor and add it to the stage
304 Actor second = Actor::New();
305 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
306 application.GetScene().Add(second);
308 // Create the third actor but don't add it to the stage
309 Actor third = Actor::New();
311 // Check that no actor is being focused yet.
312 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
314 // Check that it will fail to set focus on an invalid actor
315 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
317 // Check that the focus is set on the first actor
318 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
319 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
321 // Check that the focus is set on the second actor
322 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
323 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
325 // Check that it will fail to set focus on the third actor as it's not in the stage
326 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
327 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
329 // Add the third actor to the stage
330 application.GetScene().Add(third);
332 // Check that it will fail to set focus on the third actor as it's not focusable
333 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
334 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
336 // Make the third actor focusable
337 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
339 // Check that the focus is successfully moved to the third actor
340 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
341 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
345 int UtcDaliKeyboardFocusManagerMoveFocus(void)
347 ToolkitTestApplication application;
349 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
353 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
354 DALI_TEST_CHECK( type );
355 BaseHandle handle = type.CreateInstance();
356 DALI_TEST_CHECK( handle );
358 KeyboardFocusManager manager = KeyboardFocusManager::Get();
359 DALI_TEST_CHECK(manager);
361 bool preFocusChangeSignalVerified = false;
362 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
363 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
365 bool focusChangedSignalVerified = false;
366 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
367 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
369 // Create the first actor and add it to the stage
370 Actor first = Actor::New();
371 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
372 application.GetScene().Add(first);
374 // Create the second actor and add it to the stage
375 Actor second = Actor::New();
376 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
377 application.GetScene().Add(second);
379 // Move the focus to the right
380 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
382 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
383 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
384 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
385 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
386 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
387 preFocusChangeCallback.Reset();
389 // Check that the focus is set on the first actor
390 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
391 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
392 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
393 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
394 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
395 focusChangedCallback.Reset();
397 // Move the focus towards right
398 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
400 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
401 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
402 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
403 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
404 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
405 preFocusChangeCallback.Reset();
407 // Check that the focus is set on the second actor
408 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
409 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
410 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
411 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
412 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
413 focusChangedCallback.Reset();
415 // Move the focus towards up
416 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
418 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
419 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
420 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
421 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
422 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
423 preFocusChangeCallback.Reset();
424 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
426 // Create a 2x2 table view and try to move focus inside it
427 TableView tableView = TableView::New( 2, 2 );
428 application.GetScene().Add(tableView);
430 // Create the third actor
431 Actor third = Actor::New();
432 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
434 // Create the fourth actor
435 Actor fourth = Actor::New();
436 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
438 // Add the four children to table view
439 tableView.AddChild(first, TableView::CellPosition(0, 0));
440 tableView.AddChild(second, TableView::CellPosition(0, 1));
441 tableView.AddChild(third, TableView::CellPosition(1, 0));
442 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
444 // Set the focus to the first actor
445 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
446 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
447 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
448 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
449 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
450 focusChangedCallback.Reset();
452 // Move the focus towards right
453 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
454 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
455 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
456 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
457 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
458 focusChangedCallback.Reset();
460 // Move the focus towards down
461 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
462 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
463 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
464 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
465 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
466 focusChangedCallback.Reset();
468 // Move the focus towards left
469 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
470 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
471 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
472 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
473 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
474 focusChangedCallback.Reset();
476 // Move the focus towards up
477 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
478 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
479 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
480 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
481 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
482 focusChangedCallback.Reset();
484 // Move the focus towards left. The focus move will fail as no way to move it upwards
485 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
486 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
487 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
488 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
489 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
490 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
491 preFocusChangeCallback.Reset();
492 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
495 manager.SetFocusGroupLoop(true);
496 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
498 // Move the focus towards left again. The focus should move to the fourth actor.
499 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
500 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
501 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
502 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
503 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
504 focusChangedCallback.Reset();
508 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
510 ToolkitTestApplication application;
512 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
516 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
517 DALI_TEST_CHECK( type );
518 BaseHandle handle = type.CreateInstance();
519 DALI_TEST_CHECK( handle );
521 KeyboardFocusManager manager = KeyboardFocusManager::Get();
522 DALI_TEST_CHECK(manager);
524 bool preFocusChangeSignalVerified = false;
525 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
526 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
528 bool focusChangedSignalVerified = false;
529 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
530 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
532 // Create the first actor and add it to the stage
533 Actor first = Actor::New();
534 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
535 application.GetScene().Add(first);
537 // Create the second actor and add it to the stage
538 Actor second = Actor::New();
539 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
540 application.GetScene().Add(second);
542 // Move the focus to the right
543 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
545 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
546 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
547 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
548 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
549 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
550 preFocusChangeCallback.Reset();
552 bool customAlgorithmInterfaceVerified = false;
553 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
554 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
556 // Move the focus towards right
557 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
559 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
560 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
561 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
562 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
563 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
564 customAlgorithm.Reset();
566 // Check that the focus is set on the first actor
567 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
568 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
569 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
570 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
571 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
572 focusChangedCallback.Reset();
574 // Move the focus towards right
575 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
577 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
578 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
579 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
580 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
581 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
582 customAlgorithm.Reset();
584 // Check that the focus is set on the second actor
585 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
586 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
587 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
588 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
589 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
590 focusChangedCallback.Reset();
592 // Move the focus towards up
593 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
595 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
596 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
597 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
598 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
599 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
600 customAlgorithm.Reset();
601 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
605 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
607 ToolkitTestApplication application;
609 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
613 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
614 DALI_TEST_CHECK( type );
615 BaseHandle handle = type.CreateInstance();
616 DALI_TEST_CHECK( handle );
618 KeyboardFocusManager manager = KeyboardFocusManager::Get();
619 DALI_TEST_CHECK(manager);
621 bool focusChangedSignalVerified = false;
622 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
623 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
625 PushButton button1 = PushButton::New();
626 PushButton button2 = PushButton::New();
627 button1.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
628 button2.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
629 application.GetScene().Add(button1);
630 application.GetScene().Add(button2);
632 // Set the focus to the button1
633 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
634 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
635 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
636 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
637 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
638 focusChangedCallback.Reset();
640 // set the navigation properties of button1
641 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
642 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
643 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
644 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID )));
646 // set the navigation properties of button2
647 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
648 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
649 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
650 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
652 // Move the focus towards left
653 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
655 // Confirm whether focus is moved to button2
656 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
657 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
658 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
659 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
660 focusChangedCallback.Reset();
662 // Move the focus towards right
663 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
665 // Confirm whether focus is moved to button1
666 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
667 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
668 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
669 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
670 focusChangedCallback.Reset();
672 // Move the focus towards up
673 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
675 // Confirm whether focus is moved to button2
676 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
677 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
678 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
679 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
680 focusChangedCallback.Reset();
682 // Move the focus towards down
683 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
685 // Confirm whether focus is moved to button1
686 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
687 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
688 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
689 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
690 focusChangedCallback.Reset();
692 // Create a 1x1 table view and try to move focus inside it
693 TableView tableView = TableView::New( 1, 1 );
694 application.GetScene().Add(tableView);
696 PushButton button = PushButton::New();
697 button.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
698 tableView.AddChild(button, TableView::CellPosition(0, 0));
700 // set the navigation properties of button3
701 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetProperty< int >( Actor::Property::ID )));
703 // Set the focus to the button
704 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
705 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
706 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
707 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
708 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
709 focusChangedCallback.Reset();
711 // Move the focus towards left
712 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
714 // Confirm whether focus is moved to button1
715 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
716 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
717 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
718 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
719 focusChangedCallback.Reset();
724 int UtcDaliKeyboardFocusManagerClearFocus(void)
726 ToolkitTestApplication application;
728 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
730 KeyboardFocusManager manager = KeyboardFocusManager::Get();
731 DALI_TEST_CHECK(manager);
733 // Create the first actor and add it to the stage
734 Actor first = Actor::New();
735 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
736 application.GetScene().Add(first);
738 // Create the second actor and add it to the stage
739 Actor second = Actor::New();
740 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
741 application.GetScene().Add(second);
743 // Check that the focus is set on the first actor
744 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
745 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
747 // Check that the focus is set on the second actor
748 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
749 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
752 manager.ClearFocus();
754 // Check that no actor is being focused now.
755 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
759 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
761 ToolkitTestApplication application;
763 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
765 KeyboardFocusManager manager = KeyboardFocusManager::Get();
766 DALI_TEST_CHECK(manager);
768 // Check that the focus movement is not looped within the same focus group by default
769 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
772 manager.SetFocusGroupLoop(true);
773 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
777 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
779 ToolkitTestApplication application;
781 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
783 KeyboardFocusManager manager = KeyboardFocusManager::Get();
784 DALI_TEST_CHECK(manager);
786 // Create an actor and check that it is not a focus group by default
787 Actor actor = Actor::New();
788 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
790 // Set the actor as focus group
791 manager.SetAsFocusGroup(actor, true);
793 // flush the queue and render once
794 application.SendNotification();
795 application.Render();
797 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
799 // Set the actor not as focus group
800 manager.SetAsFocusGroup(actor, false);
802 // flush the queue and render once
803 application.SendNotification();
804 application.Render();
806 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
810 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
812 ToolkitTestApplication application;
814 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
816 KeyboardFocusManager manager = KeyboardFocusManager::Get();
817 DALI_TEST_CHECK(manager);
819 // Create an actor with two child actors and add it to the stage
820 Actor parent = Actor::New();
821 Actor child = Actor::New();
823 application.GetScene().Add(parent);
825 // Create three actors and add them as the children of the first child actor
826 Actor grandChild = Actor::New();
827 child.Add(grandChild);
829 // Set the parent and the first child actor as focus groups
830 manager.SetAsFocusGroup(parent, true);
832 // flush the queue and render once
833 application.SendNotification();
834 application.Render();
836 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
838 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
839 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
841 manager.SetAsFocusGroup(child, true);
843 // flush the queue and render once
844 application.SendNotification();
845 application.Render();
847 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
849 // The focus group should be the child, As it is the immediate parent which is also a focus group.
850 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
852 manager.SetAsFocusGroup(grandChild, true);
854 // flush the queue and render once
855 application.SendNotification();
856 application.Render();
858 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
860 // The current focus group should be itself, As it is also a focus group.
861 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
865 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
867 ToolkitTestApplication application;
869 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
871 KeyboardFocusManager manager = KeyboardFocusManager::Get();
872 DALI_TEST_CHECK(manager);
874 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
875 DALI_TEST_CHECK(defaultFocusIndicatorActor);
877 Actor newFocusIndicatorActor = Actor::New();
878 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
879 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
884 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
886 ToolkitTestApplication application;
888 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
890 KeyboardFocusManager manager = KeyboardFocusManager::Get();
891 DALI_TEST_CHECK(manager);
893 bool focusedActorActivatedSignalVerified = false;
894 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
895 manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
897 Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
899 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
900 // It makes mIsFocusIndicatorEnabled true
901 application.ProcessEvent(returnEvent);
903 // Create the first button and add it to the stage
904 PushButton firstPushButton = PushButton::New();
905 firstPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
906 application.GetScene().Add(firstPushButton);
908 // Create the second button and add it to the stage
909 PushButton secondPushButton = PushButton::New();
910 secondPushButton.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
911 application.GetScene().Add(secondPushButton);
913 // Check that the focus is set on the first button
914 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
915 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
917 // Send the return event to activate the first button
918 application.ProcessEvent(returnEvent);
919 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
920 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
921 focusedActorActivatedCallback.Reset();
923 // Check that the focus is set on the second button
924 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
925 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
927 // Send the return event again to activate the second button
928 application.ProcessEvent(returnEvent);
929 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
930 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
931 focusedActorActivatedCallback.Reset();
935 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
937 ToolkitTestApplication application;
939 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
943 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
944 DALI_TEST_CHECK( type );
945 BaseHandle handle = type.CreateInstance();
946 DALI_TEST_CHECK( handle );
948 KeyboardFocusManager manager = KeyboardFocusManager::Get();
949 DALI_TEST_CHECK(manager);
951 bool focusGroupChangedSignalVerified = false;
952 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
953 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
955 Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
956 Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
958 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
959 // It makes mIsFocusIndicatorEnabled true
960 application.ProcessEvent(tabEvent);
962 // Send the tab event to change focus group in the forward direction
963 application.ProcessEvent(tabEvent);
964 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
965 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
966 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
967 focusGroupChangedCallback.Reset();
969 // Send the shift tab event to change focus group in the backward direction
970 application.ProcessEvent(shiftTabEvent);
971 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
972 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
973 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
974 focusGroupChangedCallback.Reset();
978 int UtcDaliKeyboardFocusManagerSignals(void)
980 ToolkitTestApplication application;
982 KeyboardFocusManager manager = KeyboardFocusManager::Get();
983 DALI_TEST_CHECK( manager );
985 ConnectionTracker* testTracker = new ConnectionTracker();
986 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
987 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
988 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
989 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
994 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
996 ToolkitTestApplication application;
998 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
1000 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1001 DALI_TEST_CHECK(manager);
1003 // Create the first actor and add it to the stage
1004 Actor first = Actor::New();
1005 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1006 application.GetScene().Add(first);
1008 // Create the second actor and add it to the stage
1009 Actor second = Actor::New();
1010 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1011 application.GetScene().Add(second);
1013 // Create the third actor and add it to the stage
1014 Actor third = Actor::New();
1015 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1016 application.GetScene().Add(third);
1018 // Create the fourth actor and add it to the stage
1019 Actor fourth = Actor::New();
1020 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1021 application.GetScene().Add(fourth);
1023 // Check that the focus is set on the second actor
1024 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1025 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1027 // Check that the focus is set on the second actor
1028 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1029 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1031 // Check that the focus is set on the third actor
1032 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1033 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1035 // Check that the focus is set on the third actor
1036 DALI_TEST_CHECK(manager.SetCurrentFocusActor(fourth) == true);
1037 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1039 // Move the focus backward
1040 manager.MoveFocusBackward();
1042 // Check that it current focused actor is third actor
1043 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1045 // Remove the second actor on stage
1048 // Reset the first actor
1052 // Move the focus backward
1053 manager.MoveFocusBackward();
1055 // Check that it current focused actor is third actor
1056 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1058 // Make history stack full
1059 for(int i = 0 ; i < 31 ; i ++)
1061 Actor actor = Actor::New();
1062 actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1063 application.GetScene().Add(actor);
1064 manager.SetCurrentFocusActor(actor);
1067 for(int i = 0 ; i < 31 ; i ++)
1069 manager.MoveFocusBackward();
1072 // Check that it current focused actor is not second actor
1073 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1078 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1080 ToolkitTestApplication application;
1082 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1084 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1085 DALI_TEST_CHECK(manager);
1087 bool preFocusChangeSignalVerified = false;
1088 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1089 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1091 bool focusChangedSignalVerified = false;
1092 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1093 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1095 Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1096 Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1097 Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1098 Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1099 Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1100 Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1102 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1103 // It makes mIsFocusIndicatorEnabled true
1104 application.ProcessEvent(leftEvent);
1106 // Create a 2x2 table view and try to move focus inside it
1107 TableView tableView = TableView::New( 2, 2 );
1108 application.GetScene().Add(tableView);
1110 // Create the first actor
1111 Actor first = Actor::New();
1112 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1114 // Create the second actor
1115 Actor second = Actor::New();
1116 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1118 // Create the third actor
1119 Actor third = Actor::New();
1120 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1122 // Create the fourth actor
1123 Actor fourth = Actor::New();
1124 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1126 // Add the four children to table view
1127 tableView.AddChild(first, TableView::CellPosition(0, 0));
1128 tableView.AddChild(second, TableView::CellPosition(0, 1));
1129 tableView.AddChild(third, TableView::CellPosition(1, 0));
1130 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1132 // Set the focus to the first actor
1133 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1134 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1135 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1136 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1137 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1138 focusChangedCallback.Reset();
1140 // Send the right key event to move the focus towards right
1141 application.ProcessEvent(rightEvent);
1142 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1143 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1144 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1145 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1146 focusChangedCallback.Reset();
1148 // Send the down key event to move the focus towards down
1149 application.ProcessEvent(downEvent);
1150 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1151 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1152 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1153 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1154 focusChangedCallback.Reset();
1156 // Send the down event to move the focus towards left
1157 application.ProcessEvent(leftEvent);
1158 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1159 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1160 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1161 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1162 focusChangedCallback.Reset();
1164 // Send the up event to move the focus towards up
1165 application.ProcessEvent(upEvent);
1166 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1167 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1168 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1169 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1170 focusChangedCallback.Reset();
1172 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1173 application.ProcessEvent(pageUpEvent);
1174 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1175 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1176 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1177 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1178 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1179 preFocusChangeCallback.Reset();
1181 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1182 application.ProcessEvent(pageDownEvent);
1183 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1184 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1185 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1186 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1187 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1188 preFocusChangeCallback.Reset();
1191 manager.ClearFocus();
1193 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1194 preFocusChangeCallback.Reset();
1195 application.ProcessEvent(pageUpEvent);
1196 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1197 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1198 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1199 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1200 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1202 // Clear the focus again
1203 manager.ClearFocus();
1205 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1206 preFocusChangeCallback.Reset();
1207 application.ProcessEvent(pageDownEvent);
1208 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1209 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1210 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1211 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1212 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1214 // Clear the focus again
1215 manager.ClearFocus();
1217 // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus
1218 preFocusChangeCallback.Reset();
1219 application.ProcessEvent(upEvent);
1220 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1221 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1222 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1223 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1225 // Clear the focus again
1226 manager.ClearFocus();
1228 // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus
1229 preFocusChangeCallback.Reset();
1230 application.ProcessEvent(downEvent);
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());
1239 int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void)
1241 ToolkitTestApplication application;
1243 tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent");
1245 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1246 DALI_TEST_CHECK(manager);
1248 bool preFocusChangeSignalVerified = false;
1249 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1250 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1252 Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1254 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1255 // It makes mIsFocusIndicatorEnabled true
1256 application.ProcessEvent(spaceEvent);
1258 // Send the space event
1259 application.ProcessEvent(spaceEvent);
1260 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1261 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1263 // Clear the focus again
1264 manager.ClearFocus();
1266 // Send the space event again for line coverage
1267 preFocusChangeCallback.Reset();
1268 application.ProcessEvent(spaceEvent);
1269 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1270 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1271 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1272 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1279 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1281 ToolkitTestApplication application;
1283 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1287 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1288 DALI_TEST_CHECK( type );
1289 BaseHandle handle = type.CreateInstance();
1290 DALI_TEST_CHECK( handle );
1292 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1293 DALI_TEST_CHECK(manager);
1295 bool preFocusChangeSignalVerified = false;
1296 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1297 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1299 bool focusChangedSignalVerified = false;
1300 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1301 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1303 // Create the first actor and add it to the stage
1304 Control first = Control::New();
1305 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1306 application.GetScene().Add(first);
1308 // Create the second actor and add it to the stage
1309 Control second = Control::New();
1310 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1311 application.GetScene().Add(second);
1313 // Move the focus to the right
1314 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1316 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1317 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1318 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1319 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1320 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1321 preFocusChangeCallback.Reset();
1323 // Check that the focus is set on the first actor
1324 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1325 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1326 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1327 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1328 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1329 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1330 focusChangedCallback.Reset();
1332 // Move the focus towards right
1333 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1335 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1336 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1337 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1338 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1339 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1340 preFocusChangeCallback.Reset();
1342 // Check that the focus is set on the second actor
1343 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1344 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1345 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1346 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1347 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1348 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1349 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1350 focusChangedCallback.Reset();
1352 // Move the focus towards up
1353 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1355 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1356 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1357 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1358 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1359 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1360 preFocusChangeCallback.Reset();
1361 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1363 // Create a 2x2 table view and try to move focus inside it
1364 TableView tableView = TableView::New( 2, 2 );
1365 application.GetScene().Add(tableView);
1367 // Create the third actor
1368 Control third = Control::New();
1369 third.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1371 // Create the fourth actor
1372 Control fourth = Control::New();
1373 fourth.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1375 // Add the four children to table view
1376 tableView.AddChild(first, TableView::CellPosition(0, 0));
1377 tableView.AddChild(second, TableView::CellPosition(0, 1));
1378 tableView.AddChild(third, TableView::CellPosition(1, 0));
1379 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1381 // Set the focus to the first actor
1382 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1383 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1384 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1385 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1386 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1388 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1389 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1391 focusChangedCallback.Reset();
1393 // Move the focus towards right
1394 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1395 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1396 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1397 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1398 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1399 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1400 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1402 focusChangedCallback.Reset();
1404 // Move the focus towards down
1405 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1406 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1407 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1408 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1409 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1411 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1412 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1413 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1414 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1416 focusChangedCallback.Reset();
1418 // Move the focus towards left
1419 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1420 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1421 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1422 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1423 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1425 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1426 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1427 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1428 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1430 focusChangedCallback.Reset();
1432 // Move the focus towards up
1433 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1434 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1435 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1436 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1437 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1438 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1439 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1440 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1441 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1442 focusChangedCallback.Reset();
1444 // Move the focus towards left. The focus move will fail as no way to move it upwards
1445 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1446 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1447 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1448 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1449 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1450 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1451 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1452 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1453 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1454 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1456 preFocusChangeCallback.Reset();
1457 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1460 manager.SetFocusGroupLoop(true);
1461 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1463 // Move the focus towards left again. The focus should move to the fourth actor.
1464 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1465 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1466 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1467 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1468 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1470 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1471 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1472 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1473 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1475 focusChangedCallback.Reset();
1478 manager.ClearFocus();
1479 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1480 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1481 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1482 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1488 int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
1490 ToolkitTestApplication application;
1492 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" );
1494 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1495 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1497 Actor actor = Actor::New();
1498 actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1500 tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
1501 manager.SetCurrentFocusActor( actor );
1502 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1504 tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
1505 application.GetScene().Add( actor );
1506 manager.SetCurrentFocusActor( actor );
1507 DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
1509 tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
1511 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1516 int UtcDaliKeyboardFocusManagerEnableFocusIndicator(void)
1518 ToolkitTestApplication application;
1520 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" );
1522 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1523 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1525 Actor actor = Actor::New();
1526 actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
1527 application.GetScene().Add( actor );
1528 manager.SetCurrentFocusActor( actor );
1530 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1531 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1532 Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1533 application.ProcessEvent(rightEvent);
1535 Actor indicatorActor = manager.GetFocusIndicatorActor();
1537 tet_infoline( "Indicator is added to focused actor" );
1538 DALI_TEST_CHECK( actor == indicatorActor.GetParent() );
1540 Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false);
1541 DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) );
1543 tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" );
1544 DALI_TEST_CHECK( !indicatorActor.GetParent() );
1549 int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void)
1551 ToolkitTestApplication application;
1553 tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" );
1554 Dali::Integration::Scene scene = application.GetScene();
1556 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1557 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1559 // Create the first actor and add it to the stage
1560 Control control = Control::New();
1561 control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1564 KeyEventCallback controlCallback( true );
1565 control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback );
1567 KeyEventCallback sceneCallback( false );
1568 scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback );
1570 manager.SetCurrentFocusActor( control );
1572 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1573 // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor.
1574 Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1575 application.ProcessEvent(event1);
1577 DALI_TEST_CHECK( controlCallback.mIsCalled );
1578 DALI_TEST_CHECK( !sceneCallback.mIsCalled );
1583 int UtcDaliKeyboardFocusManagerFocusPerWindow(void)
1585 ToolkitTestApplication application;
1587 tet_infoline( "Ensure Memory focus actors for each window ");
1588 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1589 DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
1591 Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false);
1592 DALI_TEST_CHECK( firstWindow );
1593 Control first = Control::New();
1594 first.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1595 firstWindow.Add(first);
1597 Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false);
1598 DALI_TEST_CHECK( secondWindow );
1599 Control second = Control::New();
1600 second.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
1601 secondWindow.Add( second );
1603 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1604 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1606 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1607 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1608 firstWindow.Raise();
1609 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1611 secondWindow.Remove( second );
1612 secondWindow.Raise();
1613 DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second);
1615 secondWindow.Reset();