Implement FocusFinder
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / focus-finder-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_FOCUS_FINDER_H\r
2 #define DALI_TOOLKIT_INTERNAL_FOCUS_FINDER_H\r
3 \r
4 /*\r
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  */\r
20 \r
21 // EXTERNAL INCLUDES\r
22 #include <dali/public-api/object/base-object.h>\r
23 \r
24 // INTERNAL INCLUDES\r
25 #include <dali-toolkit/devel-api/focus-manager/focus-finder.h>\r
26 \r
27 namespace Dali\r
28 {\r
29 namespace Integration\r
30 {\r
31 class SceneHolder;\r
32 \r
33 } // namespace Integration\r
34 \r
35 namespace Toolkit\r
36 {\r
37 namespace Internal\r
38 {\r
39 class FocusFinder;\r
40 \r
41 /**\r
42  * @copydoc Toolkit::FocusFinder\r
43  */\r
44 class FocusFinder : public Dali::BaseObject\r
45 {\r
46 public:\r
47   /**\r
48    * Construct a new FocusFinder.\r
49    */\r
50   FocusFinder();\r
51 \r
52   /**\r
53    * @copydoc Toolkit::GetNearestFocusableActor\r
54    */\r
55   Actor GetNearestFocusableActor(Actor& focusedActor, Toolkit::Control::KeyboardFocus::Direction direction);\r
56 \r
57 protected:\r
58   /**\r
59    * Destructor\r
60    */\r
61   virtual ~FocusFinder();\r
62 \r
63 private:\r
64   /**\r
65    * Find the next actor to take focus in root's descendants, starting from the actor.\r
66    * @param[in] actor The root actor.\r
67    * @param[in] focusedActor The current focused actor.\r
68    * @param[in] focusedRect The rect of current focused actor.\r
69    * @param[in] bestCandidateRect The current best candidate.\r
70    * @param[in] direction The direction.\r
71    * @return nearest Actor.\r
72    */\r
73   Actor FindNextFocus(Actor& actor, Actor& focusedActor, Rect<float>& focusedRect, Rect<float>& bestCandidateRect, Toolkit::Control::KeyboardFocus::Direction direction);\r
74 \r
75   /**\r
76    * Is rect1 a better candidate than rect2 for a focus search in a particular\r
77    * direction from a source rect?  This is the core routine that determines\r
78    * the order of focus searching.\r
79    * @param direction The direction (up, down, left, right)\r
80    * @param candidateRect The candidate rectangle\r
81    * @param bestCandidateRect The current best candidate.\r
82    * @return Whether the candidate is the new best.\r
83    */\r
84   bool IsBetterCandidate(Toolkit::Control::KeyboardFocus::Direction direction, Rect<float>& focusedRect, Rect<float>& candidateRect, Rect<float>& bestCandidateRect) const;\r
85 \r
86 private:\r
87   // Undefined\r
88   FocusFinder(const FocusFinder&);\r
89 \r
90   FocusFinder& operator=(const FocusFinder& rhs);\r
91 };\r
92 \r
93 } // namespace Internal\r
94 \r
95 inline Internal::FocusFinder& GetImpl(Dali::Toolkit::FocusFinder& obj)\r
96 {\r
97   DALI_ASSERT_ALWAYS(obj);\r
98 \r
99   Dali::BaseObject& handle = obj.GetBaseObject();\r
100 \r
101   return static_cast<Internal::FocusFinder&>(handle);\r
102 }\r
103 \r
104 inline const Internal::FocusFinder& GetImpl(const Dali::Toolkit::FocusFinder& obj)\r
105 {\r
106   DALI_ASSERT_ALWAYS(obj);\r
107 \r
108   const Dali::BaseObject& handle = obj.GetBaseObject();\r
109 \r
110   return static_cast<const Internal::FocusFinder&>(handle);\r
111 }\r
112 \r
113 } // namespace Toolkit\r
114 \r
115 } // namespace Dali\r
116 \r
117 #endif // DALI_TOOLKIT_INTERNAL_FOCUS_FINDER_H\r