2 * Copyright (c) 2017 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>
31 using namespace Dali::Toolkit;
33 void utc_dali_toolkit_keyboard_focus_manager_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_keyboard_focus_manager_cleanup(void)
40 test_return_value = TET_PASS;
47 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 // Used to connect to signals via the ConnectSignal Handle method
222 struct CallbackFunctor
235 int UtcDaliKeyboardFocusManagerGet(void)
237 ToolkitTestApplication application;
239 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
243 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
244 DALI_TEST_CHECK( type );
245 BaseHandle handle = type.CreateInstance();
246 DALI_TEST_CHECK( handle );
248 KeyboardFocusManager manager;
250 manager = KeyboardFocusManager::Get();
251 DALI_TEST_CHECK(manager);
253 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
254 DALI_TEST_CHECK(newManager);
256 // Check that focus manager is a singleton
257 DALI_TEST_CHECK(manager == newManager);
261 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
263 ToolkitTestApplication application;
265 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
267 KeyboardFocusManager manager = KeyboardFocusManager::Get();
268 DALI_TEST_CHECK(manager);
270 // Create the first actor and add it to the stage
271 Actor first = Actor::New();
272 first.SetKeyboardFocusable(true);
273 Stage::GetCurrent().Add(first);
275 // Create the second actor and add it to the stage
276 Actor second = Actor::New();
277 second.SetKeyboardFocusable(true);
278 Stage::GetCurrent().Add(second);
280 // Create the third actor but don't add it to the stage
281 Actor third = Actor::New();
283 // Check that no actor is being focused yet.
284 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
286 // Check that it will fail to set focus on an invalid actor
287 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
289 // Check that the focus is set on the first actor
290 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
291 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
293 // Check that the focus is set on the second actor
294 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
295 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
297 // Check that it will fail to set focus on the third actor as it's not in the stage
298 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
299 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
301 // Add the third actor to the stage
302 Stage::GetCurrent().Add(third);
304 // Check that it will fail to set focus on the third actor as it's not focusable
305 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
306 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
308 // Make the third actor focusable
309 third.SetKeyboardFocusable(true);
311 // Check that the focus is successfully moved to the third actor
312 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
313 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
317 int UtcDaliKeyboardFocusManagerMoveFocus(void)
319 ToolkitTestApplication application;
321 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
325 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
326 DALI_TEST_CHECK( type );
327 BaseHandle handle = type.CreateInstance();
328 DALI_TEST_CHECK( handle );
330 KeyboardFocusManager manager = KeyboardFocusManager::Get();
331 DALI_TEST_CHECK(manager);
333 bool preFocusChangeSignalVerified = false;
334 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
335 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
337 bool focusChangedSignalVerified = false;
338 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
339 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
341 // Create the first actor and add it to the stage
342 Actor first = Actor::New();
343 first.SetKeyboardFocusable(true);
344 Stage::GetCurrent().Add(first);
346 // Create the second actor and add it to the stage
347 Actor second = Actor::New();
348 second.SetKeyboardFocusable(true);
349 Stage::GetCurrent().Add(second);
351 // Move the focus to the right
352 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
354 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
355 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
356 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
357 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
358 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
359 preFocusChangeCallback.Reset();
361 // Check that the focus is set on the first actor
362 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
363 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
364 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
365 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
366 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
367 focusChangedCallback.Reset();
369 // Move the focus towards right
370 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
372 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
373 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
374 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
375 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
376 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
377 preFocusChangeCallback.Reset();
379 // Check that the focus is set on the second actor
380 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
381 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
382 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
383 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
384 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
385 focusChangedCallback.Reset();
387 // Move the focus towards up
388 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
390 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
391 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
392 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
393 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
394 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
395 preFocusChangeCallback.Reset();
396 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
398 // Create a 2x2 table view and try to move focus inside it
399 TableView tableView = TableView::New( 2, 2 );
400 Stage::GetCurrent().Add(tableView);
402 // Create the third actor
403 Actor third = Actor::New();
404 third.SetKeyboardFocusable(true);
406 // Create the fourth actor
407 Actor fourth = Actor::New();
408 fourth.SetKeyboardFocusable(true);
410 // Add the four children to table view
411 tableView.AddChild(first, TableView::CellPosition(0, 0));
412 tableView.AddChild(second, TableView::CellPosition(0, 1));
413 tableView.AddChild(third, TableView::CellPosition(1, 0));
414 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
416 // Set the focus to the first actor
417 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
418 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
419 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
420 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
421 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
422 focusChangedCallback.Reset();
424 // Move the focus towards right
425 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
426 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
427 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
428 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
429 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
430 focusChangedCallback.Reset();
432 // Move the focus towards down
433 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
434 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
435 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
436 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
437 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
438 focusChangedCallback.Reset();
440 // Move the focus towards left
441 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
442 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
443 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
444 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
445 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
446 focusChangedCallback.Reset();
448 // Move the focus towards up
449 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
450 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
451 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
452 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
453 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
454 focusChangedCallback.Reset();
456 // Move the focus towards left. The focus move will fail as no way to move it upwards
457 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
458 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
459 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
460 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
461 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
462 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
463 preFocusChangeCallback.Reset();
464 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
467 manager.SetFocusGroupLoop(true);
468 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
470 // Move the focus towards left again. The focus should move to the fourth actor.
471 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
472 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
473 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
474 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
475 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
476 focusChangedCallback.Reset();
480 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
482 ToolkitTestApplication application;
484 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
488 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
489 DALI_TEST_CHECK( type );
490 BaseHandle handle = type.CreateInstance();
491 DALI_TEST_CHECK( handle );
493 KeyboardFocusManager manager = KeyboardFocusManager::Get();
494 DALI_TEST_CHECK(manager);
496 bool preFocusChangeSignalVerified = false;
497 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
498 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
500 bool focusChangedSignalVerified = false;
501 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
502 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
504 // Create the first actor and add it to the stage
505 Actor first = Actor::New();
506 first.SetKeyboardFocusable(true);
507 Stage::GetCurrent().Add(first);
509 // Create the second actor and add it to the stage
510 Actor second = Actor::New();
511 second.SetKeyboardFocusable(true);
512 Stage::GetCurrent().Add(second);
514 // Move the focus to the right
515 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
517 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
518 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
519 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
520 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
521 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
522 preFocusChangeCallback.Reset();
524 bool customAlgorithmInterfaceVerified = false;
525 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
526 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
528 // Move the focus towards right
529 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
531 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
532 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
533 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
534 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
535 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
536 customAlgorithm.Reset();
538 // Check that the focus is set on the first actor
539 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
540 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
541 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
542 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
543 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
544 focusChangedCallback.Reset();
546 // Move the focus towards right
547 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
549 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
550 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
551 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
552 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
553 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
554 customAlgorithm.Reset();
556 // Check that the focus is set on the second actor
557 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
558 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
559 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
560 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
561 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
562 focusChangedCallback.Reset();
564 // Move the focus towards up
565 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
567 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
568 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
569 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
570 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
571 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
572 customAlgorithm.Reset();
573 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
577 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
579 ToolkitTestApplication application;
581 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
585 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
586 DALI_TEST_CHECK( type );
587 BaseHandle handle = type.CreateInstance();
588 DALI_TEST_CHECK( handle );
590 KeyboardFocusManager manager = KeyboardFocusManager::Get();
591 DALI_TEST_CHECK(manager);
593 bool focusChangedSignalVerified = false;
594 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
595 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
597 PushButton button1 = PushButton::New();
598 PushButton button2 = PushButton::New();
599 button1.SetKeyboardFocusable(true);
600 button2.SetKeyboardFocusable(true);
601 Stage::GetCurrent().Add(button1);
602 Stage::GetCurrent().Add(button2);
604 // Set the focus to the button1
605 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
606 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
607 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
608 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
609 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
610 focusChangedCallback.Reset();
612 // set the navigation properties of button1
613 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
614 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
615 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
616 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
618 // set the navigation properties of button2
619 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
620 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
621 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
622 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
624 // Move the focus towards left
625 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
627 // Confirm whether focus is moved to button2
628 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
629 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
630 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
631 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
632 focusChangedCallback.Reset();
634 // Move the focus towards right
635 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
637 // Confirm whether focus is moved to button1
638 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
639 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
640 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
641 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
642 focusChangedCallback.Reset();
644 // Move the focus towards up
645 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
647 // Confirm whether focus is moved to button2
648 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
649 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
650 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
651 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
652 focusChangedCallback.Reset();
654 // Move the focus towards down
655 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
657 // Confirm whether focus is moved to button1
658 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
659 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
660 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
661 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
662 focusChangedCallback.Reset();
664 // Create a 1x1 table view and try to move focus inside it
665 TableView tableView = TableView::New( 1, 1 );
666 Stage::GetCurrent().Add(tableView);
668 PushButton button = PushButton::New();
669 button.SetKeyboardFocusable(true);
670 tableView.AddChild(button, TableView::CellPosition(0, 0));
672 // set the navigation properties of button3
673 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
675 // Set the focus to the button
676 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
677 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
678 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
679 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
680 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
681 focusChangedCallback.Reset();
683 // Move the focus towards left
684 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
686 // Confirm whether focus is moved to button1
687 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
688 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
689 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
690 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
691 focusChangedCallback.Reset();
696 int UtcDaliKeyboardFocusManagerClearFocus(void)
698 ToolkitTestApplication application;
700 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
702 KeyboardFocusManager manager = KeyboardFocusManager::Get();
703 DALI_TEST_CHECK(manager);
705 // Create the first actor and add it to the stage
706 Actor first = Actor::New();
707 first.SetKeyboardFocusable(true);
708 Stage::GetCurrent().Add(first);
710 // Create the second actor and add it to the stage
711 Actor second = Actor::New();
712 second.SetKeyboardFocusable(true);
713 Stage::GetCurrent().Add(second);
715 // Check that the focus is set on the first actor
716 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
717 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
719 // Check that the focus is set on the second actor
720 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
721 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
724 manager.ClearFocus();
726 // Check that no actor is being focused now.
727 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
731 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
733 ToolkitTestApplication application;
735 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
737 KeyboardFocusManager manager = KeyboardFocusManager::Get();
738 DALI_TEST_CHECK(manager);
740 // Check that the focus movement is not looped within the same focus group by default
741 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
744 manager.SetFocusGroupLoop(true);
745 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
749 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
751 ToolkitTestApplication application;
753 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
755 KeyboardFocusManager manager = KeyboardFocusManager::Get();
756 DALI_TEST_CHECK(manager);
758 // Create an actor and check that it is not a focus group by default
759 Actor actor = Actor::New();
760 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
762 // Set the actor as focus group
763 manager.SetAsFocusGroup(actor, true);
765 // flush the queue and render once
766 application.SendNotification();
767 application.Render();
769 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
771 // Set the actor not as focus group
772 manager.SetAsFocusGroup(actor, false);
774 // flush the queue and render once
775 application.SendNotification();
776 application.Render();
778 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
782 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
784 ToolkitTestApplication application;
786 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
788 KeyboardFocusManager manager = KeyboardFocusManager::Get();
789 DALI_TEST_CHECK(manager);
791 // Create an actor with two child actors and add it to the stage
792 Actor parent = Actor::New();
793 Actor child = Actor::New();
795 Stage::GetCurrent().Add(parent);
797 // Create three actors and add them as the children of the first child actor
798 Actor grandChild = Actor::New();
799 child.Add(grandChild);
801 // Set the parent and the first child actor as focus groups
802 manager.SetAsFocusGroup(parent, true);
804 // flush the queue and render once
805 application.SendNotification();
806 application.Render();
808 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
810 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
811 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
813 manager.SetAsFocusGroup(child, true);
815 // flush the queue and render once
816 application.SendNotification();
817 application.Render();
819 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
821 // The focus group should be the child, As it is the immediate parent which is also a focus group.
822 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
824 manager.SetAsFocusGroup(grandChild, true);
826 // flush the queue and render once
827 application.SendNotification();
828 application.Render();
830 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
832 // The current focus group should be itself, As it is also a focus group.
833 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
837 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
839 ToolkitTestApplication application;
841 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
843 KeyboardFocusManager manager = KeyboardFocusManager::Get();
844 DALI_TEST_CHECK(manager);
846 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
847 DALI_TEST_CHECK(defaultFocusIndicatorActor);
849 Actor newFocusIndicatorActor = Actor::New();
850 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
851 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
856 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
858 ToolkitTestApplication application;
860 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
862 KeyboardFocusManager manager = KeyboardFocusManager::Get();
863 DALI_TEST_CHECK(manager);
865 bool focusedActorActivatedSignalVerified = false;
866 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
867 manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
869 Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME );
871 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
872 // It makes mIsFocusIndicatorEnabled true
873 application.ProcessEvent(returnEvent);
875 // Create the first button and add it to the stage
876 PushButton firstPushButton = PushButton::New();
877 firstPushButton.SetKeyboardFocusable(true);
878 Stage::GetCurrent().Add(firstPushButton);
880 // Create the second button and add it to the stage
881 PushButton secondPushButton = PushButton::New();
882 secondPushButton.SetKeyboardFocusable(true);
883 Stage::GetCurrent().Add(secondPushButton);
885 // Check that the focus is set on the first button
886 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
887 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
889 // Send the return event to activate the first button
890 application.ProcessEvent(returnEvent);
891 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
892 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
893 focusedActorActivatedCallback.Reset();
895 // Check that the focus is set on the second button
896 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
897 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
899 // Send the return event again to activate the second button
900 application.ProcessEvent(returnEvent);
901 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
902 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
903 focusedActorActivatedCallback.Reset();
907 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
909 ToolkitTestApplication application;
911 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
915 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
916 DALI_TEST_CHECK( type );
917 BaseHandle handle = type.CreateInstance();
918 DALI_TEST_CHECK( handle );
920 KeyboardFocusManager manager = KeyboardFocusManager::Get();
921 DALI_TEST_CHECK(manager);
923 bool focusGroupChangedSignalVerified = false;
924 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
925 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
927 Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
928 Integration::KeyEvent shiftTabEvent("Tab", "", 0, 1, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME);
930 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
931 // It makes mIsFocusIndicatorEnabled true
932 application.ProcessEvent(tabEvent);
934 // Send the tab event to change focus group in the forward direction
935 application.ProcessEvent(tabEvent);
936 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
937 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
938 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
939 focusGroupChangedCallback.Reset();
941 // Send the shift tab event to change focus group in the backward direction
942 application.ProcessEvent(shiftTabEvent);
943 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
944 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
945 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
946 focusGroupChangedCallback.Reset();
950 int UtcDaliKeyboardFocusManagerSignals(void)
952 ToolkitTestApplication application;
954 KeyboardFocusManager manager = KeyboardFocusManager::Get();
955 DALI_TEST_CHECK( manager );
957 ConnectionTracker* testTracker = new ConnectionTracker();
958 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
959 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
960 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
961 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
966 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
968 ToolkitTestApplication application;
970 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
972 KeyboardFocusManager manager = KeyboardFocusManager::Get();
973 DALI_TEST_CHECK(manager);
975 // Make history stack full
976 for(int i = 0 ; i < 31 ; i ++)
978 Actor actor = Actor::New();
979 actor.SetKeyboardFocusable(true);
980 Stage::GetCurrent().Add(actor);
981 manager.SetCurrentFocusActor(actor);
984 // Create the first actor and add it to the stage
985 Actor first = Actor::New();
986 first.SetKeyboardFocusable(true);
987 Stage::GetCurrent().Add(first);
989 // Create the second actor and add it to the stage
990 Actor second = Actor::New();
991 second.SetKeyboardFocusable(true);
992 Stage::GetCurrent().Add(second);
994 // Create the second actor and add it to the stage
995 Actor third = Actor::New();
996 third.SetKeyboardFocusable(true);
997 Stage::GetCurrent().Add(third);
999 // Check that the focus is set on the second actor
1000 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1001 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1003 // Check that the focus is set on the second actor
1004 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1005 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1007 // Check that the focus is set on the third actor
1008 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1009 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1011 // Move the focus backward
1012 manager.MoveFocusBackward();
1014 // Check that it current focused actor is second actor
1015 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1017 // Check that the focus is set on the third actor
1018 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1019 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1021 // Remove the second actor on stage
1024 // Move the focus backward
1025 manager.MoveFocusBackward();
1027 // Check that it current focused actor is first actor
1028 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1033 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1035 ToolkitTestApplication application;
1037 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1039 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1040 DALI_TEST_CHECK(manager);
1042 bool preFocusChangeSignalVerified = false;
1043 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1044 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1046 bool focusChangedSignalVerified = false;
1047 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1048 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1050 Integration::KeyEvent leftEvent("Left", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME);
1051 Integration::KeyEvent rightEvent("Right", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
1052 Integration::KeyEvent upEvent("Up", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
1053 Integration::KeyEvent downEvent("Down", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
1054 Integration::KeyEvent pageUpEvent("Prior", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
1055 Integration::KeyEvent pageDownEvent("Next", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
1057 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1058 // It makes mIsFocusIndicatorEnabled true
1059 application.ProcessEvent(leftEvent);
1061 // Create a 2x2 table view and try to move focus inside it
1062 TableView tableView = TableView::New( 2, 2 );
1063 Stage::GetCurrent().Add(tableView);
1065 // Create the first actor
1066 Actor first = Actor::New();
1067 first.SetKeyboardFocusable(true);
1069 // Create the second actor
1070 Actor second = Actor::New();
1071 second.SetKeyboardFocusable(true);
1073 // Create the third actor
1074 Actor third = Actor::New();
1075 third.SetKeyboardFocusable(true);
1077 // Create the fourth actor
1078 Actor fourth = Actor::New();
1079 fourth.SetKeyboardFocusable(true);
1081 // Add the four children to table view
1082 tableView.AddChild(first, TableView::CellPosition(0, 0));
1083 tableView.AddChild(second, TableView::CellPosition(0, 1));
1084 tableView.AddChild(third, TableView::CellPosition(1, 0));
1085 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1087 // Set the focus to the first actor
1088 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1089 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1090 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1091 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1092 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1093 focusChangedCallback.Reset();
1095 // Send the right key event to move the focus towards right
1096 application.ProcessEvent(rightEvent);
1097 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1098 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1099 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1100 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1101 focusChangedCallback.Reset();
1103 // Send the down key event to move the focus towards down
1104 application.ProcessEvent(downEvent);
1105 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1106 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1107 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1108 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1109 focusChangedCallback.Reset();
1111 // Send the down event to move the focus towards left
1112 application.ProcessEvent(leftEvent);
1113 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1114 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1115 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1116 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1117 focusChangedCallback.Reset();
1119 // Send the up event to move the focus towards up
1120 application.ProcessEvent(upEvent);
1121 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1122 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1123 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1124 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1125 focusChangedCallback.Reset();
1127 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1128 application.ProcessEvent(pageUpEvent);
1129 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1130 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1131 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1132 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1133 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1134 preFocusChangeCallback.Reset();
1136 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1137 application.ProcessEvent(pageDownEvent);
1138 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1139 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1140 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1141 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1142 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1143 preFocusChangeCallback.Reset();
1146 manager.ClearFocus();
1148 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1149 preFocusChangeCallback.Reset();
1150 application.ProcessEvent(pageUpEvent);
1151 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1152 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1153 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1154 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1155 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1157 // Clear the focus again
1158 manager.ClearFocus();
1160 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1161 preFocusChangeCallback.Reset();
1162 application.ProcessEvent(pageDownEvent);
1163 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1164 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1165 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1166 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1167 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1176 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1178 ToolkitTestApplication application;
1180 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1184 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1185 DALI_TEST_CHECK( type );
1186 BaseHandle handle = type.CreateInstance();
1187 DALI_TEST_CHECK( handle );
1189 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1190 DALI_TEST_CHECK(manager);
1192 bool preFocusChangeSignalVerified = false;
1193 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1194 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1196 bool focusChangedSignalVerified = false;
1197 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1198 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1200 // Create the first actor and add it to the stage
1201 Control first = Control::New();
1202 first.SetKeyboardFocusable(true);
1203 Stage::GetCurrent().Add(first);
1205 // Create the second actor and add it to the stage
1206 Control second = Control::New();
1207 second.SetKeyboardFocusable(true);
1208 Stage::GetCurrent().Add(second);
1210 // Move the focus to the right
1211 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1213 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1214 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1215 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1216 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1217 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1218 preFocusChangeCallback.Reset();
1220 // Check that the focus is set on the first actor
1221 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1222 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1223 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1224 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1225 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1226 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1227 focusChangedCallback.Reset();
1229 // Move the focus towards right
1230 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1232 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1233 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1234 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1235 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1236 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1237 preFocusChangeCallback.Reset();
1239 // Check that the focus is set on the second actor
1240 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1241 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1242 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1243 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1244 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1245 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1246 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1247 focusChangedCallback.Reset();
1249 // Move the focus towards up
1250 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1252 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1253 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1254 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1255 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1256 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1257 preFocusChangeCallback.Reset();
1258 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1260 // Create a 2x2 table view and try to move focus inside it
1261 TableView tableView = TableView::New( 2, 2 );
1262 Stage::GetCurrent().Add(tableView);
1264 // Create the third actor
1265 Control third = Control::New();
1266 third.SetKeyboardFocusable(true);
1268 // Create the fourth actor
1269 Control fourth = Control::New();
1270 fourth.SetKeyboardFocusable(true);
1272 // Add the four children to table view
1273 tableView.AddChild(first, TableView::CellPosition(0, 0));
1274 tableView.AddChild(second, TableView::CellPosition(0, 1));
1275 tableView.AddChild(third, TableView::CellPosition(1, 0));
1276 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1278 // Set the focus to the first actor
1279 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1280 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1281 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1282 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1283 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1285 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1286 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1288 focusChangedCallback.Reset();
1290 // Move the focus towards right
1291 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1292 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1293 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1294 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1295 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1296 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1297 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1299 focusChangedCallback.Reset();
1301 // Move the focus towards down
1302 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1303 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1304 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1305 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1306 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1308 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1309 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1310 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1311 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1313 focusChangedCallback.Reset();
1315 // Move the focus towards left
1316 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1317 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1318 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1319 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1320 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1322 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1323 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1324 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1325 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1327 focusChangedCallback.Reset();
1329 // Move the focus towards up
1330 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1331 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1332 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1333 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1334 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1335 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1336 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1337 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1338 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1339 focusChangedCallback.Reset();
1341 // Move the focus towards left. The focus move will fail as no way to move it upwards
1342 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1343 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1344 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1345 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1346 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1347 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1348 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1349 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1350 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1351 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1353 preFocusChangeCallback.Reset();
1354 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1357 manager.SetFocusGroupLoop(true);
1358 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1360 // Move the focus towards left again. The focus should move to the fourth actor.
1361 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1362 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1363 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1364 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1365 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1367 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1368 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1369 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1370 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1372 focusChangedCallback.Reset();
1375 manager.ClearFocus();
1376 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1377 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1378 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1379 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );