1 #ifndef DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H
2 #define DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali-toolkit/public-api/controls/control.h>
28 namespace Internal DALI_INTERNAL
30 class KeyboardFocusManager;
33 * @addtogroup dali_toolkit_managers
38 * @brief Provides the functionality of handling keyboard navigation
39 * and maintaining the two dimensional keyboard focus chain.
41 * It provides functionality of setting the focus and moving the focus
42 * in four directions (i.e. Left, Right, Up and Down). It also draws a
43 * highlight for the focused actor and emits a signal when the focus
47 * | %Signal Name | Method |
48 * |------------------------------|------------------------------------|
49 * | keyboardPreFocusChange | @ref PreFocusChangeSignal() |
50 * | keyboardFocusChanged | @ref FocusChangedSignal() |
51 * | keyboardFocusGroupChanged | @ref FocusGroupChangedSignal() |
52 * | keyboardFocusedActorEnterKey | @ref FocusedActorEnterKeySignal() |
55 class DALI_TOOLKIT_API KeyboardFocusManager : public BaseHandle
58 /// @brief Pre focus change signal
59 typedef Signal<Actor(Actor, Actor, Control::KeyboardFocus::Direction)> PreFocusChangeSignalType;
61 /// @brief Focus changed signal
62 typedef Signal<void(Actor, Actor)> FocusChangedSignalType;
64 /// @brief Focus group changed signal
65 typedef Signal<void(Actor, bool)> FocusGroupChangedSignalType;
67 /// @brief Focused actor has the enter key pressed signal
68 typedef Signal<void(Actor)> FocusedActorEnterKeySignalType;
71 * @brief Creates a KeyboardFocusManager handle; this can be initialized with KeyboardFocusManager::New().
73 * Calling member functions with an uninitialized handle is not allowed.
76 KeyboardFocusManager();
81 * This is non-virtual since derived Handle types must not contain data or virtual methods.
84 ~KeyboardFocusManager();
87 * @brief Gets the singleton of KeyboardFocusManager object.
90 * @return A handle to the KeyboardFocusManager control
92 static KeyboardFocusManager Get();
95 * @brief Moves the keyboard focus to the given actor.
97 * Only one actor can be focused at the same time. The actor must
98 * be in the stage already and keyboard focusable.
101 * @param actor The actor to be focused
102 * @return Whether the focus is successful or not
103 * @pre The KeyboardFocusManager has been initialized.
104 * @pre The Actor has been initialized.
106 bool SetCurrentFocusActor(Actor actor);
109 * @brief Gets the current focused actor.
112 * @return A handle to the current focused actor or an empty handle if no actor is focused
113 * @pre The KeyboardFocusManager has been initialized.
115 Actor GetCurrentFocusActor();
118 * @brief Moves the focus to the next focusable actor in the focus
119 * chain in the given direction (according to the focus traversal
123 * @param direction The direction of focus movement
124 * @return true if the movement was successful
125 * @pre The KeyboardFocusManager has been initialized.
127 bool MoveFocus(Control::KeyboardFocus::Direction direction);
130 * @brief Clears the focus from the current focused actor if any, so
131 * that no actor is focused in the focus chain.
133 * It will emit focus changed signal without current focused actor.
135 * @pre The KeyboardFocusManager has been initialized.
140 * @brief Sets whether the focus movement should be looped within the same focus group.
142 * The focus movement is not looped by default.
144 * @param enabled Whether the focus movement should be looped
145 * @pre The KeyboardFocusManager has been initialized.
147 void SetFocusGroupLoop(bool enabled);
150 * @brief Gets whether the focus movement should be looped within the same focus group.
153 * @return Whether the focus movement should be looped
154 * @pre The KeyboardFocusManager has been initialized.
156 bool GetFocusGroupLoop() const;
159 * @brief Sets whether an actor is a focus group that can limit the
160 * scope of focus movement to its child actors in the focus chain.
162 * Layout controls set themselves as focus groups by default.
165 * @param actor The actor to be set as a focus group
166 * @param isFocusGroup Whether to set the actor as a focus group or not
167 * @pre The KeyboardFocusManager has been initialized.
168 * @pre The Actor has been initialized.
170 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
173 * @brief Checks whether the actor is set as a focus group or not.
176 * @param actor The actor to be checked
177 * @return Whether the actor is set as a focus group
178 * @pre The KeyboardFocusManager has been initialized.
179 * @pre The Actor has been initialized.
181 bool IsFocusGroup(Actor actor) const;
184 * @brief Returns the closest ancestor of the given actor that is a focus group.
187 * @param actor The actor to be checked for its focus group
188 * @return The focus group the given actor belongs to or an empty handle if the given actor
189 * doesn't belong to any focus group
191 Actor GetFocusGroup(Actor actor);
194 * @brief Sets the focus indicator actor.
196 * This will replace the default focus indicator actor in
197 * KeyboardFocusManager and will be added to the focused actor as a
201 * @param indicator The indicator actor to be added
202 * @pre The KeyboardFocusManager has been initialized.
203 * @pre The indicator actor has been initialized.
205 void SetFocusIndicatorActor(Actor indicator);
208 * @brief Gets the focus indicator actor.
211 * @return A handle to the focus indicator actor
212 * @pre The KeyboardFocusManager has been initialized.
214 Actor GetFocusIndicatorActor();
217 * @brief Move the focus to prev focused actor
221 void MoveFocusBackward();
225 * @brief This signal is emitted before the focus is going to be changed.
227 * KeyboardFocusManager makes the best guess for which actor to
228 * focus towards the given direction, but applications might want to
229 * change that. By connecting with this signal, they can check the
230 * proposed actor to focus and return a different actor if they
231 * wish. This signal is only emitted when the navigation key is
232 * pressed and KeyboardFocusManager tries to move the focus
233 * automatically. It won't be emitted for focus movement by calling
234 * SetCurrentFocusActor directly.
236 * A callback of the following type may be connected:
238 * Actor YourCallbackName(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction);
241 * @return The signal to connect to
242 * @pre The Object has been initialized.
244 PreFocusChangeSignalType& PreFocusChangeSignal();
247 * @brief This signal is emitted after the current focused actor has been changed.
249 * A callback of the following type may be connected:
251 * void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
254 * @return The signal to connect to
255 * @pre The Object has been initialized.
257 FocusChangedSignalType& FocusChangedSignal();
260 * @brief This signal is emitted when the focus group has been changed.
262 * If the current focus group has a parent layout control,
263 * KeyboardFocusManager will make the best guess for the next focus
264 * group to move the focus to in the given direction (forward or
265 * backward). If not, the application has to set the new focus.
267 * A callback of the following type may be connected:
269 * void YourCallbackName(Actor currentFocusedActor, bool forward);
272 * @return The signal to connect to
273 * @pre The Object has been initialized.
275 FocusGroupChangedSignalType& FocusGroupChangedSignal();
278 * @brief This signal is emitted when the current focused actor has the enter key pressed on it.
280 * A callback of the following type may be connected:
282 * void YourCallbackName(Actor enterPressedActor);
285 * @return The signal to connect to
286 * @pre The Object has been initialized.
288 FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
290 // Not intended for application developers
294 * @brief Creates a new handle from the implementation.
297 * @param[in] impl A pointer to the object
299 explicit DALI_INTERNAL KeyboardFocusManager(Internal::KeyboardFocusManager* impl);
302 }; // class KeyboardFocusManager
307 } // namespace Toolkit
311 #endif // DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H