[dali_2.0.28] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / focus-manager / focus-finder.cpp
1 /*\r
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  *\r
16  */\r
17 \r
18 // CLASS HEADER\r
19 #include "focus-finder.h"\r
20 \r
21 // EXTERNAL INCLUDES\r
22 #include <dali/devel-api/common/singleton-service.h>\r
23 \r
24 // INTERNAL INCLUDES\r
25 #include <dali-toolkit/internal/focus-manager/focus-finder-impl.h>\r
26 \r
27 namespace Dali\r
28 {\r
29 namespace Toolkit\r
30 {\r
31 FocusFinder::FocusFinder()\r
32 {\r
33 }\r
34 \r
35 FocusFinder::~FocusFinder()\r
36 {\r
37 }\r
38 \r
39 FocusFinder FocusFinder::Get()\r
40 {\r
41   FocusFinder finder;\r
42 \r
43   // Check whether the focus finder is already created\r
44   SingletonService singletonService(SingletonService::Get());\r
45   if(singletonService)\r
46   {\r
47     Dali::BaseHandle handle = singletonService.GetSingleton(typeid(FocusFinder));\r
48     if(handle)\r
49     {\r
50       // If so, downcast the handle of singleton to focus finder\r
51       finder = FocusFinder(dynamic_cast<Internal::FocusFinder*>(handle.GetObjectPtr()));\r
52     }\r
53 \r
54     if(!finder)\r
55     {\r
56       // If not, create the focus finder and register it as a singleton\r
57       finder = FocusFinder(new Internal::FocusFinder());\r
58       singletonService.Register(typeid(finder), finder);\r
59     }\r
60   }\r
61 \r
62   return finder;\r
63 }\r
64 \r
65 FocusFinder::FocusFinder(Internal::FocusFinder* impl)\r
66 : BaseHandle(impl)\r
67 {\r
68 }\r
69 \r
70 Actor FocusFinder::GetNearestFocusableActor(Actor focusedActor, Toolkit::Control::KeyboardFocus::Direction direction)\r
71 {\r
72   return GetImpl(*this).GetNearestFocusableActor(focusedActor, direction);\r
73 }\r
74 \r
75 } // namespace Toolkit\r
76 \r
77 } // namespace Dali\r