1 #ifndef __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__
5 * Copyright (c) 2015 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>
30 namespace Internal DALI_INTERNAL
32 class KeyboardFocusManager;
35 * @addtogroup dali_toolkit_focus_manager
40 * @brief Provides the functionality of handling keyboard navigation
41 * and maintaining the two dimensional keyboard focus chain.
43 * It provides functionality of setting the focus and moving the focus
44 * in four directions (i.e. Left, Right, Up and Down). It also draws a
45 * highlight for the focused actor and emits a signal when the focus
49 * | %Signal Name | Method |
50 * |----------------------------------|------------------------------------|
51 * | keyboard-pre-focus-change | @ref PreFocusChangeSignal() |
52 * | keyboard-focus-changed | @ref FocusChangedSignal() |
53 * | keyboard-focus-group-changed | @ref FocusGroupChangedSignal() |
54 * | keyboard-focused-actor-enter-key | @ref FocusedActorEnterKeySignal() |
56 class DALI_IMPORT_API KeyboardFocusManager : public BaseHandle
61 /// @brief Pre focus change signal
62 typedef Signal< Actor ( Actor, Actor, Control::KeyboardFocus::Direction ) > PreFocusChangeSignalType;
64 /// @brief Focus changed signal
65 typedef Signal< void ( Actor, Actor ) > FocusChangedSignalType;
67 /// @brief Focus group changed signal
68 typedef Signal< void ( Actor, bool ) > FocusGroupChangedSignalType;
70 /// @brief Focused actor has the enter key pressed signal
71 typedef Signal< void ( Actor ) > FocusedActorEnterKeySignalType;
74 * @brief Create a KeyboardFocusManager handle; this can be initialised with KeyboardFocusManager::New().
76 * Calling member functions with an uninitialised handle is not allowed.
78 KeyboardFocusManager();
83 * This is non-virtual since derived Handle types must not contain data or virtual methods.
85 ~KeyboardFocusManager();
88 * @brief Get the singleton of KeyboardFocusManager object.
90 * @return A handle to the KeyboardFocusManager control.
92 static KeyboardFocusManager Get();
95 * @brief Move 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.
100 * @pre The KeyboardFocusManager has been initialized.
101 * @pre The Actor has been initialized.
102 * @param actor The actor to be focused
103 * @return Whether the focus is successful or not
105 bool SetCurrentFocusActor(Actor actor);
108 * @brief Get the current focused actor.
110 * @pre The KeyboardFocusManager has been initialized.
111 * @return A handle to the current focused actor or an empty handle if no actor is focused.
113 Actor GetCurrentFocusActor();
116 * @brief Move the focus to the next focusable actor in the focus
117 * chain in the given direction (according to the focus traversal
120 * @pre The KeyboardFocusManager has been initialized.
121 * @param direction The direction of focus movement
122 * @return true if the movement was successful
124 bool MoveFocus(Control::KeyboardFocus::Direction direction);
127 * @brief Clear the focus from the current focused actor if any, so
128 * that no actor is focused in the focus chain.
130 * It will emit focus changed signal without current focused actor
131 * @pre The KeyboardFocusManager has been initialized.
136 * @brief Set whether the focus movement should be looped within the same focus group.
138 * The focus movement is not looped by default.
139 * @pre The KeyboardFocusManager has been initialized.
140 * @param enabled Whether the focus movement should be looped
142 void SetFocusGroupLoop(bool enabled);
145 * @brief Get whether the focus movement should be looped within the same focus group.
147 * @pre The KeyboardFocusManager has been initialized.
148 * @return Whether the focus movement should be looped
150 bool GetFocusGroupLoop() const;
153 * @brief Set whether an actor is a focus group that can limit the
154 * scope of focus movement to its child actors in the focus chain.
156 * Layout controls set themselves as focus groups by default.
158 * @pre The KeyboardFocusManager has been initialized.
159 * @pre The Actor has been initialized.
160 * @param actor The actor to be set as a focus group.
161 * @param isFocusGroup Whether to set the actor as a focus group or not.
163 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
166 * @brief Check whether the actor is set as a focus group or not.
168 * @pre The KeyboardFocusManager has been initialized.
169 * @pre The Actor has been initialized.
170 * @param actor The actor to be checked.
171 * @return Whether the actor is set as a focus group.
173 bool IsFocusGroup(Actor actor) const;
176 * @brief Returns the closest ancestor of the given actor that is a focus group.
178 * @param actor The actor to be checked for its focus group
179 * @return The focus group the given actor belongs to or an empty handle if the given actor
180 * doesn't belong to any focus group
182 Actor GetFocusGroup(Actor actor);
185 * @brief Set the focus indicator actor.
187 * This will replace the default focus indicator actor in
188 * KeyboardFocusManager and will be added to the focused actor as a
191 * @pre The KeyboardFocusManager has been initialized.
192 * @pre The indicator actor has been initialized.
193 * @param indicator The indicator actor to be added
195 void SetFocusIndicatorActor(Actor indicator);
198 * @brief Get the focus indicator actor.
200 * @pre The KeyboardFocusManager has been initialized.
201 * @return A handle to the focus indicator actor
203 Actor GetFocusIndicatorActor();
208 * @brief This signal is emitted before the focus is going to be changed.
210 * KeyboardFocusManager makes the best guess for which actor to
211 * focus towards the given direction, but applications might want to
212 * change that. By connecting with this signal, they can check the
213 * proposed actor to focus and return a different actor if they
214 * wish. This signal is only emitted when the navigation key is
215 * pressed and KeyboardFocusManager tries to move the focus
216 * automatically. It won't be emitted for focus movement by calling
217 * SetCurrentFocusActor directly.
219 * A callback of the following type may be connected:
221 * Actor YourCallbackName(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocus::Direction direction);
223 * @pre The Object has been initialized.
224 * @return The signal to connect to.
226 PreFocusChangeSignalType& PreFocusChangeSignal();
229 * @brief This signal is emitted after the current focused actor has been changed.
231 * A callback of the following type may be connected:
233 * void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
235 * @pre The Object has been initialized.
236 * @return The signal to connect to.
238 FocusChangedSignalType& FocusChangedSignal();
241 * @brief This signal is emitted when the focus group has been changed.
243 * If the current focus group has a parent layout control,
244 * KeyboardFocusManager will make the best guess for the next focus
245 * group to move the focus to in the given direction (forward or
246 * backward). If not, the application has to set the new focus.
248 * A callback of the following type may be connected:
250 * void YourCallbackName(Actor currentFocusedActor, bool forward);
252 * @pre The Object has been initialized.
253 * @return The signal to connect to.
255 FocusGroupChangedSignalType& FocusGroupChangedSignal();
258 * @brief This signal is emitted when the current focused actor has the enter key pressed on it.
260 * A callback of the following type may be connected:
262 * void YourCallbackName(Actor enterPressedActor);
264 * @pre The Object has been initialized.
265 * @return The signal to connect to.
267 FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
269 // Not intended for application developers
272 * @brief Creates a new handle from the implementation.
274 * @param[in] impl A pointer to the object.
276 explicit DALI_INTERNAL KeyboardFocusManager(Internal::KeyboardFocusManager *impl);
278 }; // class KeyboardFocusManager
283 } // namespace Toolkit
287 #endif // __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__