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 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
48 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
51 CustomAlgorithm(bool& interfaceVerified)
52 : mInterfaceVerified(interfaceVerified),
53 mCurrentFocusedActor(),
54 mProposedActorToFocus(),
55 mDirection(Control::KeyboardFocus::LEFT)
59 Actor GetNextFocusableActor(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
61 tet_infoline("Verifying CustomAlgorithm()");
63 mInterfaceVerified = true;
65 mCurrentFocusedActor = currentFocusedActor;
66 mProposedActorToFocus = proposedActorToFocus;
67 mDirection = direction;
69 return mProposedActorToFocus;
74 mInterfaceVerified = false;
75 mCurrentFocusedActor = Actor();
76 mProposedActorToFocus = Actor();
77 mDirection = Control::KeyboardFocus::LEFT;
80 bool& mInterfaceVerified;
81 Actor mCurrentFocusedActor;
82 Actor mProposedActorToFocus;
83 Control::KeyboardFocus::Direction mDirection;
86 // Functors to test whether PreFocusChange signal is emitted when the keyboard focus is about to change
87 class PreFocusChangeCallback : public Dali::ConnectionTracker
90 PreFocusChangeCallback(bool& signalReceived)
91 : mSignalVerified(signalReceived),
92 mCurrentFocusedActor(),
93 mProposedActorToFocus(),
94 mDirection(Control::KeyboardFocus::LEFT)
98 Actor Callback(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction)
100 tet_infoline("Verifying PreFocusChangeCallback()");
102 mSignalVerified = true;
104 mCurrentFocusedActor = currentFocusedActor;
105 mProposedActorToFocus = proposedActorToFocus;
106 mDirection = direction;
108 return mProposedActorToFocus;
113 mSignalVerified = false;
114 mCurrentFocusedActor = Actor();
115 mProposedActorToFocus = Actor();
116 mDirection = Control::KeyboardFocus::LEFT;
119 bool& mSignalVerified;
120 Actor mCurrentFocusedActor;
121 Actor mProposedActorToFocus;
122 Control::KeyboardFocus::Direction mDirection;
125 // Functors to test whether focus changed signal is emitted when the keyboard focus is changed
126 class FocusChangedCallback : public Dali::ConnectionTracker
129 FocusChangedCallback(bool& signalReceived)
130 : mSignalVerified(signalReceived),
131 mOriginalFocusedActor(),
132 mCurrentFocusedActor()
136 void Callback(Actor originalFocusedActor, Actor currentFocusedActor)
138 tet_infoline("Verifying FocusChangedCallback()");
140 if(originalFocusedActor == mCurrentFocusedActor)
142 mSignalVerified = true;
145 mOriginalFocusedActor = originalFocusedActor;
146 mCurrentFocusedActor = currentFocusedActor;
151 mSignalVerified = false;
154 bool& mSignalVerified;
155 Actor mOriginalFocusedActor;
156 Actor mCurrentFocusedActor;
159 // Functors to test whether focus group changed signal is emitted when the keyboard focus group is changed
160 class FocusGroupChangedCallback : public Dali::ConnectionTracker
163 FocusGroupChangedCallback(bool& signalReceived)
164 : mSignalVerified(signalReceived),
165 mCurrentFocusedActor(),
170 void Callback(Actor currentFocusedActor, bool forward)
172 tet_infoline("Verifying FocusGroupChangedCallback()");
174 mSignalVerified = true;
176 mCurrentFocusedActor = currentFocusedActor;
182 mSignalVerified = false;
185 bool& mSignalVerified;
186 Actor mCurrentFocusedActor;
190 // Functors to test whether focused actor activated signal is emitted when the focused actor is activated
191 class FocusedActorActivatedCallback : public Dali::ConnectionTracker
194 FocusedActorActivatedCallback(bool& signalReceived)
195 : mSignalVerified(signalReceived),
200 void Callback(Actor activatedActor)
202 tet_infoline("Verifying FocusedActorActivatedCallback()");
204 mSignalVerified = true;
206 mActivatedActor = activatedActor;
211 mSignalVerified = false;
214 bool& mSignalVerified;
215 Actor mActivatedActor;
218 // Used to connect to signals via the ConnectSignal Handle method
219 struct CallbackFunctor
232 int UtcDaliKeyboardFocusManagerGet(void)
234 ToolkitTestApplication application;
236 tet_infoline(" UtcDaliKeyboardKeyboardFocusManagerGet");
240 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
241 DALI_TEST_CHECK( type );
242 BaseHandle handle = type.CreateInstance();
243 DALI_TEST_CHECK( handle );
245 KeyboardFocusManager manager;
247 manager = KeyboardFocusManager::Get();
248 DALI_TEST_CHECK(manager);
250 KeyboardFocusManager newManager = KeyboardFocusManager::Get();
251 DALI_TEST_CHECK(newManager);
253 // Check that focus manager is a singleton
254 DALI_TEST_CHECK(manager == newManager);
258 int UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor(void)
260 ToolkitTestApplication application;
262 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetCurrentFocusActor");
264 KeyboardFocusManager manager = KeyboardFocusManager::Get();
265 DALI_TEST_CHECK(manager);
267 // Create the first actor and add it to the stage
268 Actor first = Actor::New();
269 first.SetKeyboardFocusable(true);
270 Stage::GetCurrent().Add(first);
272 // Create the second actor and add it to the stage
273 Actor second = Actor::New();
274 second.SetKeyboardFocusable(true);
275 Stage::GetCurrent().Add(second);
277 // Create the third actor but don't add it to the stage
278 Actor third = Actor::New();
280 // Check that no actor is being focused yet.
281 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
283 // Check that it will fail to set focus on an invalid actor
284 DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false);
286 // Check that the focus is set on the first actor
287 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
288 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
290 // Check that the focus is set on the second actor
291 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
292 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
294 // Check that it will fail to set focus on the third actor as it's not in the stage
295 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
296 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
298 // Add the third actor to the stage
299 Stage::GetCurrent().Add(third);
301 // Check that it will fail to set focus on the third actor as it's not focusable
302 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false);
303 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
305 // Make the third actor focusable
306 third.SetKeyboardFocusable(true);
308 // Check that the focus is successfully moved to the third actor
309 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
310 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
314 int UtcDaliKeyboardFocusManagerMoveFocus(void)
316 ToolkitTestApplication application;
318 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocus");
322 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
323 DALI_TEST_CHECK( type );
324 BaseHandle handle = type.CreateInstance();
325 DALI_TEST_CHECK( handle );
327 KeyboardFocusManager manager = KeyboardFocusManager::Get();
328 DALI_TEST_CHECK(manager);
330 bool preFocusChangeSignalVerified = false;
331 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
332 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
334 bool focusChangedSignalVerified = false;
335 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
336 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
338 // Create the first actor and add it to the stage
339 Actor first = Actor::New();
340 first.SetKeyboardFocusable(true);
341 Stage::GetCurrent().Add(first);
343 // Create the second actor and add it to the stage
344 Actor second = Actor::New();
345 second.SetKeyboardFocusable(true);
346 Stage::GetCurrent().Add(second);
348 // Move the focus to the right
349 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
351 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
352 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
353 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
354 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
355 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
356 preFocusChangeCallback.Reset();
358 // Check that the focus is set on the first actor
359 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
360 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
361 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
362 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
363 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
364 focusChangedCallback.Reset();
366 // Move the focus towards right
367 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
369 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
370 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
371 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
372 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
373 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
374 preFocusChangeCallback.Reset();
376 // Check that the focus is set on the second actor
377 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
378 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
379 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
380 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
381 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
382 focusChangedCallback.Reset();
384 // Move the focus towards up
385 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
387 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
388 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
389 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
390 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
391 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
392 preFocusChangeCallback.Reset();
393 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
395 // Create a 2x2 table view and try to move focus inside it
396 TableView tableView = TableView::New( 2, 2 );
397 Stage::GetCurrent().Add(tableView);
399 // Create the third actor
400 Actor third = Actor::New();
401 third.SetKeyboardFocusable(true);
403 // Create the fourth actor
404 Actor fourth = Actor::New();
405 fourth.SetKeyboardFocusable(true);
407 // Add the four children to table view
408 tableView.AddChild(first, TableView::CellPosition(0, 0));
409 tableView.AddChild(second, TableView::CellPosition(0, 1));
410 tableView.AddChild(third, TableView::CellPosition(1, 0));
411 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
413 // Set the focus to the first actor
414 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
415 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
416 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
417 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
418 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
419 focusChangedCallback.Reset();
421 // Move the focus towards right
422 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
423 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
424 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
425 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
426 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
427 focusChangedCallback.Reset();
429 // Move the focus towards down
430 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
431 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
432 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
433 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
434 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
435 focusChangedCallback.Reset();
437 // Move the focus towards left
438 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
439 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
440 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
441 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
442 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
443 focusChangedCallback.Reset();
445 // Move the focus towards up
446 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
447 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
448 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
449 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
450 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
451 focusChangedCallback.Reset();
453 // Move the focus towards left. The focus move will fail as no way to move it upwards
454 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
455 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
456 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
457 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
458 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
459 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
460 preFocusChangeCallback.Reset();
461 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
464 manager.SetFocusGroupLoop(true);
465 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
467 // Move the focus towards left again. The focus should move to the fourth actor.
468 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
469 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
470 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
471 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
472 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
473 focusChangedCallback.Reset();
477 int UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus(void)
479 ToolkitTestApplication application;
481 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
485 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
486 DALI_TEST_CHECK( type );
487 BaseHandle handle = type.CreateInstance();
488 DALI_TEST_CHECK( handle );
490 KeyboardFocusManager manager = KeyboardFocusManager::Get();
491 DALI_TEST_CHECK(manager);
493 bool preFocusChangeSignalVerified = false;
494 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
495 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
497 bool focusChangedSignalVerified = false;
498 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
499 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
501 // Create the first actor and add it to the stage
502 Actor first = Actor::New();
503 first.SetKeyboardFocusable(true);
504 Stage::GetCurrent().Add(first);
506 // Create the second actor and add it to the stage
507 Actor second = Actor::New();
508 second.SetKeyboardFocusable(true);
509 Stage::GetCurrent().Add(second);
511 // Move the focus to the right
512 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
514 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
515 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
516 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
517 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
518 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
519 preFocusChangeCallback.Reset();
521 bool customAlgorithmInterfaceVerified = false;
522 CustomAlgorithm customAlgorithm(customAlgorithmInterfaceVerified);
523 Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm(manager, customAlgorithm);
525 // Move the focus towards right
526 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
528 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
529 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
530 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == Actor());
531 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
532 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
533 customAlgorithm.Reset();
535 // Check that the focus is set on the first actor
536 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
537 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
538 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
539 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
540 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
541 focusChangedCallback.Reset();
543 // Move the focus towards right
544 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
546 // Because no layout control in the stage and the first actor is focused, it should invoke CustomAlgorithm
547 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
548 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == first);
549 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
550 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::RIGHT);
551 customAlgorithm.Reset();
553 // Check that the focus is set on the second actor
554 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
555 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
556 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
557 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
558 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
559 focusChangedCallback.Reset();
561 // Move the focus towards up
562 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
564 // Because no layout control in the stage and no actor is focused, it should invoke CustomAlgorithm
565 DALI_TEST_CHECK(customAlgorithm.mInterfaceVerified);
566 DALI_TEST_CHECK(customAlgorithm.mCurrentFocusedActor == second);
567 DALI_TEST_CHECK(customAlgorithm.mProposedActorToFocus == Actor());
568 DALI_TEST_CHECK(customAlgorithm.mDirection == Control::KeyboardFocus::UP);
569 customAlgorithm.Reset();
570 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
574 int UtcDaliKeyboardFocusManagerFocusablePropertiesMoveFocus(void)
576 ToolkitTestApplication application;
578 tet_infoline(" UtcDaliKeyboardFocusManagerCustomAlgorithmMoveFocus");
582 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
583 DALI_TEST_CHECK( type );
584 BaseHandle handle = type.CreateInstance();
585 DALI_TEST_CHECK( handle );
587 KeyboardFocusManager manager = KeyboardFocusManager::Get();
588 DALI_TEST_CHECK(manager);
590 bool focusChangedSignalVerified = false;
591 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
592 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
594 PushButton button1 = PushButton::New();
595 PushButton button2 = PushButton::New();
596 button1.SetKeyboardFocusable(true);
597 button2.SetKeyboardFocusable(true);
598 Stage::GetCurrent().Add(button1);
599 Stage::GetCurrent().Add(button2);
601 // Set the focus to the button1
602 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true);
603 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1);
604 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
605 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
606 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
607 focusChangedCallback.Reset();
609 // set the navigation properties of button1
610 button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
611 button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
612 button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
613 button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetId()));
615 // set the navigation properties of button2
616 button2.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
617 button2.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
618 button2.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
619 button2.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
621 // Move the focus towards left
622 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
624 // Confirm whether focus is moved to button2
625 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
626 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
627 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
628 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
629 focusChangedCallback.Reset();
631 // Move the focus towards right
632 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
634 // Confirm whether focus is moved to button1
635 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
636 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
637 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
638 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
639 focusChangedCallback.Reset();
641 // Move the focus towards up
642 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
644 // Confirm whether focus is moved to button2
645 DALI_TEST_EQUALS(button2.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
646 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
647 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
648 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button2);
649 focusChangedCallback.Reset();
651 // Move the focus towards down
652 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
654 // Confirm whether focus is moved to button1
655 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
656 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
657 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
658 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
659 focusChangedCallback.Reset();
661 // Create a 1x1 table view and try to move focus inside it
662 TableView tableView = TableView::New( 1, 1 );
663 Stage::GetCurrent().Add(tableView);
665 PushButton button = PushButton::New();
666 button.SetKeyboardFocusable(true);
667 tableView.AddChild(button, TableView::CellPosition(0, 0));
669 // set the navigation properties of button3
670 button.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button1.GetId()));
672 // Set the focus to the button
673 DALI_TEST_CHECK(manager.SetCurrentFocusActor(button) == true);
674 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button);
675 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
676 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button1);
677 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button);
678 focusChangedCallback.Reset();
680 // Move the focus towards left
681 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
683 // Confirm whether focus is moved to button1
684 DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
685 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
686 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button);
687 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
688 focusChangedCallback.Reset();
693 int UtcDaliKeyboardFocusManagerClearFocus(void)
695 ToolkitTestApplication application;
697 tet_infoline(" UtcDaliKeyboardFocusManagerClearFocus");
699 KeyboardFocusManager manager = KeyboardFocusManager::Get();
700 DALI_TEST_CHECK(manager);
702 // Create the first actor and add it to the stage
703 Actor first = Actor::New();
704 first.SetKeyboardFocusable(true);
705 Stage::GetCurrent().Add(first);
707 // Create the second actor and add it to the stage
708 Actor second = Actor::New();
709 second.SetKeyboardFocusable(true);
710 Stage::GetCurrent().Add(second);
712 // Check that the focus is set on the first actor
713 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
714 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
716 // Check that the focus is set on the second actor
717 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
718 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
721 manager.ClearFocus();
723 // Check that no actor is being focused now.
724 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
728 int UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop(void)
730 ToolkitTestApplication application;
732 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusGroupLoop");
734 KeyboardFocusManager manager = KeyboardFocusManager::Get();
735 DALI_TEST_CHECK(manager);
737 // Check that the focus movement is not looped within the same focus group by default
738 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == false);
741 manager.SetFocusGroupLoop(true);
742 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
746 int UtcDaliKeyboardFocusManagerSetAsFocusGroup(void)
748 ToolkitTestApplication application;
750 tet_infoline(" UtcDaliKeyboardFocusManagerSetAsFocusGroup");
752 KeyboardFocusManager manager = KeyboardFocusManager::Get();
753 DALI_TEST_CHECK(manager);
755 // Create an actor and check that it is not a focus group by default
756 Actor actor = Actor::New();
757 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
759 // Set the actor as focus group
760 manager.SetAsFocusGroup(actor, true);
762 // flush the queue and render once
763 application.SendNotification();
764 application.Render();
766 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == true);
768 // Set the actor not as focus group
769 manager.SetAsFocusGroup(actor, false);
771 // flush the queue and render once
772 application.SendNotification();
773 application.Render();
775 DALI_TEST_CHECK(manager.IsFocusGroup(actor) == false);
779 int UtcDaliKeyboardFocusManagerGetFocusGroup(void)
781 ToolkitTestApplication application;
783 tet_infoline(" UtcDaliKeyboardFocusManagerGetFocusGroup");
785 KeyboardFocusManager manager = KeyboardFocusManager::Get();
786 DALI_TEST_CHECK(manager);
788 // Create an actor with two child actors and add it to the stage
789 Actor parent = Actor::New();
790 Actor child = Actor::New();
792 Stage::GetCurrent().Add(parent);
794 // Create three actors and add them as the children of the first child actor
795 Actor grandChild = Actor::New();
796 child.Add(grandChild);
798 // Set the parent and the first child actor as focus groups
799 manager.SetAsFocusGroup(parent, true);
801 // flush the queue and render once
802 application.SendNotification();
803 application.Render();
805 DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true);
807 // The current focus group should be the parent, As it is the immediate parent which is also a focus group.
808 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == parent);
810 manager.SetAsFocusGroup(child, true);
812 // flush the queue and render once
813 application.SendNotification();
814 application.Render();
816 DALI_TEST_CHECK(manager.IsFocusGroup(child) == true);
818 // The focus group should be the child, As it is the immediate parent which is also a focus group.
819 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == child);
821 manager.SetAsFocusGroup(grandChild, true);
823 // flush the queue and render once
824 application.SendNotification();
825 application.Render();
827 DALI_TEST_CHECK(manager.IsFocusGroup(grandChild) == true);
829 // The current focus group should be itself, As it is also a focus group.
830 DALI_TEST_CHECK(manager.GetFocusGroup(grandChild) == grandChild);
834 int UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator(void)
836 ToolkitTestApplication application;
838 tet_infoline(" UtcDaliKeyboardFocusManagerSetAndGetFocusIndicator");
840 KeyboardFocusManager manager = KeyboardFocusManager::Get();
841 DALI_TEST_CHECK(manager);
843 Actor defaultFocusIndicatorActor = manager.GetFocusIndicatorActor();
844 DALI_TEST_CHECK(defaultFocusIndicatorActor);
846 Actor newFocusIndicatorActor = Actor::New();
847 manager.SetFocusIndicatorActor(newFocusIndicatorActor);
848 DALI_TEST_CHECK(manager.GetFocusIndicatorActor() == newFocusIndicatorActor);
853 int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
855 ToolkitTestApplication application;
857 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusedActorActivated");
859 KeyboardFocusManager manager = KeyboardFocusManager::Get();
860 DALI_TEST_CHECK(manager);
862 bool focusedActorActivatedSignalVerified = false;
863 FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
864 manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
866 Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up);
868 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
869 // It makes mIsFocusIndicatorEnabled true
870 application.ProcessEvent(returnEvent);
872 // Create the first button and add it to the stage
873 PushButton firstPushButton = PushButton::New();
874 firstPushButton.SetKeyboardFocusable(true);
875 Stage::GetCurrent().Add(firstPushButton);
877 // Create the second button and add it to the stage
878 PushButton secondPushButton = PushButton::New();
879 secondPushButton.SetKeyboardFocusable(true);
880 Stage::GetCurrent().Add(secondPushButton);
882 // Check that the focus is set on the first button
883 DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstPushButton) == true);
884 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstPushButton);
886 // Send the return event to activate the first button
887 application.ProcessEvent(returnEvent);
888 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
889 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == firstPushButton);
890 focusedActorActivatedCallback.Reset();
892 // Check that the focus is set on the second button
893 DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondPushButton) == true);
894 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondPushButton);
896 // Send the return event again to activate the second button
897 application.ProcessEvent(returnEvent);
898 DALI_TEST_CHECK(focusedActorActivatedCallback.mSignalVerified);
899 DALI_TEST_CHECK(focusedActorActivatedCallback.mActivatedActor == secondPushButton);
900 focusedActorActivatedCallback.Reset();
904 int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
906 ToolkitTestApplication application;
908 tet_infoline(" UtcDaliKeyboardFocusManagerSignalFocusGroupChanged");
912 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
913 DALI_TEST_CHECK( type );
914 BaseHandle handle = type.CreateInstance();
915 DALI_TEST_CHECK( handle );
917 KeyboardFocusManager manager = KeyboardFocusManager::Get();
918 DALI_TEST_CHECK(manager);
920 bool focusGroupChangedSignalVerified = false;
921 FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
922 manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
924 Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down);
925 Integration::KeyEvent shiftTabEvent("Tab", "", 0, 1, 0, Integration::KeyEvent::Down);
927 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
928 // It makes mIsFocusIndicatorEnabled true
929 application.ProcessEvent(tabEvent);
931 // Send the tab event to change focus group in the forward direction
932 application.ProcessEvent(tabEvent);
933 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
934 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
935 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == true);
936 focusGroupChangedCallback.Reset();
938 // Send the shift tab event to change focus group in the backward direction
939 application.ProcessEvent(shiftTabEvent);
940 DALI_TEST_CHECK(focusGroupChangedCallback.mSignalVerified);
941 DALI_TEST_CHECK(focusGroupChangedCallback.mCurrentFocusedActor == Actor());
942 DALI_TEST_CHECK(focusGroupChangedCallback.mForward == false);
943 focusGroupChangedCallback.Reset();
947 int UtcDaliKeyboardFocusManagerSignals(void)
949 ToolkitTestApplication application;
951 KeyboardFocusManager manager = KeyboardFocusManager::Get();
952 DALI_TEST_CHECK( manager );
954 ConnectionTracker* testTracker = new ConnectionTracker();
955 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardPreFocusChange", CallbackFunctor() ), TEST_LOCATION );
956 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusChanged", CallbackFunctor() ), TEST_LOCATION );
957 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusGroupChanged", CallbackFunctor() ), TEST_LOCATION );
958 DALI_TEST_EQUALS( true, manager.ConnectSignal( testTracker, "keyboardFocusedActorEnterKey", CallbackFunctor() ), TEST_LOCATION );
963 int UtcDaliKeyboardFocusManagerMoveFocusBackward(void)
965 ToolkitTestApplication application;
967 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusBackward");
969 KeyboardFocusManager manager = KeyboardFocusManager::Get();
970 DALI_TEST_CHECK(manager);
972 // Make history stack full
973 for(int i = 0 ; i < 31 ; i ++)
975 Actor actor = Actor::New();
976 actor.SetKeyboardFocusable(true);
977 Stage::GetCurrent().Add(actor);
978 manager.SetCurrentFocusActor(actor);
981 // Create the first actor and add it to the stage
982 Actor first = Actor::New();
983 first.SetKeyboardFocusable(true);
984 Stage::GetCurrent().Add(first);
986 // Create the second actor and add it to the stage
987 Actor second = Actor::New();
988 second.SetKeyboardFocusable(true);
989 Stage::GetCurrent().Add(second);
991 // Create the second actor and add it to the stage
992 Actor third = Actor::New();
993 third.SetKeyboardFocusable(true);
994 Stage::GetCurrent().Add(third);
996 // Check that the focus is set on the second actor
997 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
998 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1000 // Check that the focus is set on the second actor
1001 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1002 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1004 // Check that the focus is set on the third actor
1005 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1006 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1008 // Move the focus backward
1009 manager.MoveFocusBackward();
1011 // Check that it current focused actor is second actor
1012 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1014 // Check that the focus is set on the third actor
1015 DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true);
1016 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1018 // Remove the second actor on stage
1021 // Move the focus backward
1022 manager.MoveFocusBackward();
1024 // Check that it current focused actor is first actor
1025 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1030 int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
1032 ToolkitTestApplication application;
1034 tet_infoline(" UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents");
1036 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1037 DALI_TEST_CHECK(manager);
1039 bool preFocusChangeSignalVerified = false;
1040 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1041 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1043 bool focusChangedSignalVerified = false;
1044 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1045 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1047 Integration::KeyEvent leftEvent("Left", "", 0, 0, 0, Integration::KeyEvent::Down);
1048 Integration::KeyEvent rightEvent("Right", "", 0, 0, 0, Integration::KeyEvent::Down);
1049 Integration::KeyEvent upEvent("Up", "", 0, 0, 0, Integration::KeyEvent::Down);
1050 Integration::KeyEvent downEvent("Down", "", 0, 0, 0, Integration::KeyEvent::Down);
1051 Integration::KeyEvent pageUpEvent("Prior", "", 0, 0, 0, Integration::KeyEvent::Down);
1052 Integration::KeyEvent pageDownEvent("Next", "", 0, 0, 0, Integration::KeyEvent::Down);
1054 // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
1055 // It makes mIsFocusIndicatorEnabled true
1056 application.ProcessEvent(leftEvent);
1058 // Create a 2x2 table view and try to move focus inside it
1059 TableView tableView = TableView::New( 2, 2 );
1060 Stage::GetCurrent().Add(tableView);
1062 // Create the first actor
1063 Actor first = Actor::New();
1064 first.SetKeyboardFocusable(true);
1066 // Create the second actor
1067 Actor second = Actor::New();
1068 second.SetKeyboardFocusable(true);
1070 // Create the third actor
1071 Actor third = Actor::New();
1072 third.SetKeyboardFocusable(true);
1074 // Create the fourth actor
1075 Actor fourth = Actor::New();
1076 fourth.SetKeyboardFocusable(true);
1078 // Add the four children to table view
1079 tableView.AddChild(first, TableView::CellPosition(0, 0));
1080 tableView.AddChild(second, TableView::CellPosition(0, 1));
1081 tableView.AddChild(third, TableView::CellPosition(1, 0));
1082 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1084 // Set the focus to the first actor
1085 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1086 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1087 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1088 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1089 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1090 focusChangedCallback.Reset();
1092 // Send the right key event to move the focus towards right
1093 application.ProcessEvent(rightEvent);
1094 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1095 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1096 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1097 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1098 focusChangedCallback.Reset();
1100 // Send the down key event to move the focus towards down
1101 application.ProcessEvent(downEvent);
1102 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1103 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1104 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1105 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1106 focusChangedCallback.Reset();
1108 // Send the down event to move the focus towards left
1109 application.ProcessEvent(leftEvent);
1110 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1111 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1112 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1113 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1114 focusChangedCallback.Reset();
1116 // Send the up event to move the focus towards up
1117 application.ProcessEvent(upEvent);
1118 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1119 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1120 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1121 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1122 focusChangedCallback.Reset();
1124 // Send the pape up event, but focus should not be moved because page up is not supported by table view
1125 application.ProcessEvent(pageUpEvent);
1126 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1127 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1128 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1129 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1130 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_UP);
1131 preFocusChangeCallback.Reset();
1133 // Send the pape down event, but focus should not be moved because page down is not supported by table view
1134 application.ProcessEvent(pageDownEvent);
1135 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1136 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1137 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1138 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == first);
1139 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::PAGE_DOWN);
1140 preFocusChangeCallback.Reset();
1143 manager.ClearFocus();
1145 // Send the pape up event, but nothing was focued so focus manager will try the initial focus
1146 preFocusChangeCallback.Reset();
1147 application.ProcessEvent(pageUpEvent);
1148 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1149 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1150 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1151 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1152 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1154 // Clear the focus again
1155 manager.ClearFocus();
1157 // Send the pape down event, but nothing was focued so focus manager will try the initial focus
1158 preFocusChangeCallback.Reset();
1159 application.ProcessEvent(pageDownEvent);
1160 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
1161 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1162 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1163 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1164 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1173 int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
1175 ToolkitTestApplication application;
1177 tet_infoline(" UtcDaliKeyboardFocusManagerMoveFocusTestStateChange");
1181 type = TypeRegistry::Get().GetTypeInfo( "KeyboardFocusManager" );
1182 DALI_TEST_CHECK( type );
1183 BaseHandle handle = type.CreateInstance();
1184 DALI_TEST_CHECK( handle );
1186 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1187 DALI_TEST_CHECK(manager);
1189 bool preFocusChangeSignalVerified = false;
1190 PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified);
1191 manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback );
1193 bool focusChangedSignalVerified = false;
1194 FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
1195 manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
1197 // Create the first actor and add it to the stage
1198 Control first = Control::New();
1199 first.SetKeyboardFocusable(true);
1200 Stage::GetCurrent().Add(first);
1202 // Create the second actor and add it to the stage
1203 Control second = Control::New();
1204 second.SetKeyboardFocusable(true);
1205 Stage::GetCurrent().Add(second);
1207 // Move the focus to the right
1208 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1210 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1211 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1212 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor());
1213 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1214 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1215 preFocusChangeCallback.Reset();
1217 // Check that the focus is set on the first actor
1218 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1219 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1220 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1221 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
1222 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1223 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1224 focusChangedCallback.Reset();
1226 // Move the focus towards right
1227 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1229 // Because no layout control in the stage and the first actor is focused, it should emit the PreFocusChange signal
1230 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1231 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1232 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1233 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT);
1234 preFocusChangeCallback.Reset();
1236 // Check that the focus is set on the second actor
1237 DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true);
1238 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1239 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1240 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1241 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1242 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1243 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1244 focusChangedCallback.Reset();
1246 // Move the focus towards up
1247 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == false);
1249 // Because no layout control in the stage and no actor is focused, it should emit the PreFocusChange signal
1250 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1251 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == second);
1252 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1253 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::UP);
1254 preFocusChangeCallback.Reset();
1255 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1257 // Create a 2x2 table view and try to move focus inside it
1258 TableView tableView = TableView::New( 2, 2 );
1259 Stage::GetCurrent().Add(tableView);
1261 // Create the third actor
1262 Control third = Control::New();
1263 third.SetKeyboardFocusable(true);
1265 // Create the fourth actor
1266 Control fourth = Control::New();
1267 fourth.SetKeyboardFocusable(true);
1269 // Add the four children to table view
1270 tableView.AddChild(first, TableView::CellPosition(0, 0));
1271 tableView.AddChild(second, TableView::CellPosition(0, 1));
1272 tableView.AddChild(third, TableView::CellPosition(1, 0));
1273 tableView.AddChild(fourth, TableView::CellPosition(1, 1));
1275 // Set the focus to the first actor
1276 DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true);
1277 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1278 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1279 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1280 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1282 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1283 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1285 focusChangedCallback.Reset();
1287 // Move the focus towards right
1288 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1289 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second);
1290 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1291 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1292 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second);
1293 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1294 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1296 focusChangedCallback.Reset();
1298 // Move the focus towards down
1299 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::DOWN) == true);
1300 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1301 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1302 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second);
1303 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1305 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1306 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1307 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1308 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1310 focusChangedCallback.Reset();
1312 // Move the focus towards left
1313 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1314 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third);
1315 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1316 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth);
1317 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third);
1319 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1320 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1321 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1322 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1324 focusChangedCallback.Reset();
1326 // Move the focus towards up
1327 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::UP) == true);
1328 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1329 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1330 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third);
1331 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first);
1332 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1333 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1334 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1335 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1336 focusChangedCallback.Reset();
1338 // Move the focus towards left. The focus move will fail as no way to move it upwards
1339 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == false);
1340 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first);
1341 DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified);
1342 DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first);
1343 DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor());
1344 DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT);
1345 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1346 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1347 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1348 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1350 preFocusChangeCallback.Reset();
1351 DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified);
1354 manager.SetFocusGroupLoop(true);
1355 DALI_TEST_CHECK(manager.GetFocusGroupLoop() == true);
1357 // Move the focus towards left again. The focus should move to the fourth actor.
1358 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
1359 DALI_TEST_CHECK(manager.GetCurrentFocusActor() == fourth);
1360 DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
1361 DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first);
1362 DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth);
1364 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1365 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1366 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1367 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION );
1369 focusChangedCallback.Reset();
1372 manager.ClearFocus();
1373 DALI_TEST_EQUALS(first.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1374 DALI_TEST_EQUALS(second.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1375 DALI_TEST_EQUALS(third.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );
1376 DALI_TEST_EQUALS(fourth.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION );