1 #ifndef __DALI_TOOLKIT_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_FOCUS_MANAGER_H__
5 * Copyright (c) 2014 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/public-api/actors/actor.h>
23 #include <dali/public-api/actors/image-actor.h>
31 namespace Internal DALI_INTERNAL
37 * @brief Manages registration of actors in a focus chain and changing the focused
38 * actor within that chain.
40 * This class provides the functionality of registering the focus order and description
41 * of actors and maintaining the focus chain.
43 * It provides functionality of setting the
44 * focus and moving the focus forward and backward. It also draws a highlight for the
45 * focused actor and emits a signal when the focus is changed.
48 * | %Signal Name | Method |
49 * |-------------------------|------------------------------------|
50 * | focus-changed | @ref FocusChangedSignal() |
51 * | focus-overshot | @ref FocusOvershotSignal() |
52 * | focused-actor-activated | @ref FocusedActorActivatedSignal() |
54 class DALI_IMPORT_API FocusManager : public BaseHandle
59 * @brief Accessibility needs four information which will be read by screen-reader.
61 * Reading order : Label -> Trait -> Optional (Value and Hint)
63 enum AccessibilityAttribute
65 ACCESSIBILITY_LABEL = 0, ///< Simple text which contained in ui-control
66 ACCESSIBILITY_TRAIT, ///< Description of ui-control trait
67 ACCESSIBILITY_VALUE, ///< Current value of ui-control (Optional)
68 ACCESSIBILITY_HINT, ///< Hint for action (Optional)
69 ACCESSIBILITY_ATTRIBUTE_NUM ///< Number of attributes
73 * @brief Overshoot direction.
75 enum FocusOvershotDirection
77 OVERSHOT_PREVIOUS = -1, ///< Try to move previous of the first actor
78 OVERSHOT_NEXT = 1, ///< Try to move next of the last actor
83 /// @brief Focus changed signal
84 typedef Signal< void ( Actor, Actor ) > FocusChangedSignalType;
86 /// @brief Focus overshooted signal
87 typedef Signal< void ( Actor, FocusOvershotDirection ) > FocusOvershotSignalType;
89 /// @brief Focused actor activated signal
90 typedef Signal< void ( Actor ) > FocusedActorActivatedSignalType;
93 * @brief Create a FocusManager handle; this can be initialised with FocusManager::New().
95 * Calling member functions with an uninitialised handle is not allowed.
102 * This is non-virtual since derived Handle types must not contain data or virtual methods.
107 * @brief Get the singleton of FocusManager object.
109 * @return A handle to the FocusManager control.
111 static FocusManager Get();
114 * @brief Set the information of the specified actor's accessibility attribute.
116 * @pre The FocusManager has been initialized.
117 * @pre The Actor has been initialized.
118 * @param actor The actor the text to be set with
119 * @param type The attribute type the text to be set with
120 * @param text The text for the actor's accessibility information
122 void SetAccessibilityAttribute(Actor actor, AccessibilityAttribute type, const std::string& text);
125 * @brief Get the text of the specified actor's accessibility attribute.
127 * @pre The FocusManager has been initialized.
128 * @pre The Actor has been initialized.
129 * @param actor The actor to be queried
130 * @param type The attribute type to be queried
131 * @return The text of the actor's accessibility information
133 std::string GetAccessibilityAttribute(Actor actor, AccessibilityAttribute type) const;
136 * @brief Set the focus order of the actor.
138 * The focus order of each actor in the focus chain is unique. If
139 * there is another actor assigned with the same focus order
140 * already, the new actor will be inserted to the focus chain with
141 * that focus order, and the focus order of the original actor and
142 * all the actors followed in the focus chain will be increased
143 * accordingly. If the focus order assigned to the actor is 0, it
144 * means that actor's focus order is undefined (e.g. the actor has a
145 * description but with no focus order being set yet) and therefore
146 * that actor is not focusable.
148 * @pre The FocusManager has been initialized.
149 * @pre The Actor has been initialized.
150 * @param actor The actor the focus order to be set with
151 * @param order The focus order of the actor
153 void SetFocusOrder(Actor actor, const unsigned int order);
156 * @brief Get the focus order of the actor.
158 * When the focus order is 0, it means the focus order of the actor
161 * @pre The FocusManager has been initialized.
162 * @pre The Actor has been initialized.
163 * @param actor The actor to be queried
164 * @return The focus order of the actor
166 unsigned int GetFocusOrder(Actor actor) const;
169 * @brief Generates a new focus order number which can be used to
170 * assign to actors which need to be appended to the end of the
171 * current focus order chain.
173 * The new number will be an increment over the very last focus
174 * order number in the focus chain. If the focus chain is empty then
175 * the function returns 1, else the number returned will be FOLast +
176 * 1 where FOLast is the focus order of the very last control in the
179 * @pre The FocusManager has been initialized.
180 * @return The focus order of the actor
182 unsigned int GenerateNewFocusOrder() const;
185 * @brief Get the actor that has the specified focus order.
187 * It will return an empty handle if the actor is not in the stage
188 * or has a focus order of 0.
190 * @pre The FocusManager has been initialized.
191 * @param order The focus order of the actor
193 * @return The actor that has the specified focus order or an empty
194 * handle if no actor in the stage has the specified focus order.
196 Actor GetActorByFocusOrder(const unsigned int order);
199 * @brief Move the focus to the specified actor.
201 * Only one actor can be focused at the same time. The actor must
202 * have a defined focus order and must be focusable, visible and in
205 * @pre The FocusManager has been initialized.
206 * @pre The Actor has been initialized.
207 * @param actor The actor to be focused
208 * @return Whether the focus is successful or not
210 bool SetCurrentFocusActor(Actor actor);
213 * @brief Get the current focused actor.
215 * @pre The FocusManager has been initialized.
216 * @return A handle to the current focused actor or an empty handle if no actor is focused.
218 Actor GetCurrentFocusActor();
221 * @brief Get the focus group of current focused actor.
223 * @pre The FocusManager has been initialized.
225 * @return A handle to the immediate parent of the current focused
226 * actor which is also a focus group, or an empty handle if no actor
229 Actor GetCurrentFocusGroup();
232 * @brief Get the focus order of currently focused actor.
233 * @pre The FocusManager has been initialized.
235 * @return The focus order of the currently focused actor or 0 if no
238 unsigned int GetCurrentFocusOrder();
241 * @brief Move the focus to the next focusable actor in the focus
242 * chain (according to the focus traversal order).
244 * When the focus movement is wrapped around, the focus will be moved
245 * to the first focusable actor when it reaches the end of the focus chain.
247 * @pre The FocusManager has been initialized.
248 * @return true if the moving was successful
250 bool MoveFocusForward();
253 * @brief Move the focus to the previous focusable actor in the
254 * focus chain (according to the focus traversal order).
256 * When the focus movement is wrapped around, the focus will be
257 * moved to the last focusable actor when it reaches the beginning
258 * of the focus chain.
260 * @pre The FocusManager has been initialized.
261 * @return true if the moving was successful
263 bool MoveFocusBackward();
266 * @brief Clear the focus from the current focused actor if any, so
267 * that no actor is focused in the focus chain.
269 * It will emit focus changed signal without current focused actor
270 * @pre The FocusManager has been initialized.
275 * @brief Clear the every registered focusable actor from focus-manager.
276 * @pre The FocusManager has been initialized.
281 * @brief Set whether an actor is a focus group that can limit the
282 * scope of focus movement to its child actors in the focus chain.
284 * @pre The FocusManager has been initialized.
285 * @pre The Actor has been initialized.
286 * @param actor The actor to be set as a focus group.
287 * @param isFocusGroup Whether to set the actor to be a focus group or not.
289 void SetFocusGroup(Actor actor, bool isFocusGroup);
292 * @brief Check whether the actor is set as a focus group or not.
294 * @pre The FocusManager has been initialized.
295 * @pre The Actor has been initialized.
296 * @param actor The actor to be checked.
297 * @return Whether the actor is set as a focus group.
299 bool IsFocusGroup(Actor actor) const;
302 * @brief Set whether the group mode is enabled or not.
304 * When the group mode is enabled, the focus movement will be limited to the child actors
305 * of the current focus group including the current focus group itself. The current focus
306 * group is the closest ancestor of the current focused actor that set as a focus group.
307 * @pre The FocusManager has been initialized.
308 * @param enabled Whether the group mode is enabled or not
310 void SetGroupMode(bool enabled);
313 * @brief Get whether the group mode is enabled or not.
315 * @pre The FocusManager has been initialized.
316 * @return Whether the group mode is enabled or not.
318 bool GetGroupMode() const;
321 * @brief Set whether focus will be moved to the beginning of the
322 * focus chain when it reaches the end or vice versa.
324 * When both the wrap mode and the group mode are enabled, focus will be
325 * wrapped within the current focus group. Focus will not be wrapped in default.
326 * @pre The FocusManager has been initialized.
327 * @param wrapped Whether the focus movement is wrapped around or not
329 void SetWrapMode(bool wrapped);
332 * @brief Get whether the wrap mode is enabled or not.
334 * @pre The FocusManager has been initialized.
335 * @return Whether the wrap mode is enabled or not.
337 bool GetWrapMode() const;
340 * @brief Set the focus indicator actor.
342 * This will replace the default focus indicator actor in
343 * FocusManager and will be added to the focused actor as a
346 * @pre The FocusManager has been initialized.
347 * @pre The indicator actor has been initialized.
348 * @param indicator The indicator actor to be added
350 void SetFocusIndicatorActor(Actor indicator);
353 * @brief Get the focus indicator actor.
355 * @pre The FocusManager has been initialized.
356 * @return A handle to the focus indicator actor
358 Actor GetFocusIndicatorActor();
361 * @brief Returns the closest ancestor of the given actor that is a focus group.
363 * @param actor The actor to be checked for its focus group
364 * @return The focus group the given actor belongs to or an empty handle if the given actor doesn't belong to any focus group
366 Actor GetFocusGroup(Actor actor);
371 * @brief This signal is emitted when the current focused actor is changed.
373 * A callback of the following type may be connected:
375 * void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
377 * @pre The Object has been initialized.
378 * @return The signal to connect to.
380 FocusChangedSignalType& FocusChangedSignal();
383 * @brief This signal is emitted when there is no way to move focus further.
385 * A callback of the following type may be connected:
387 * void YourCallbackName(Actor currentFocusedActor, FocusOvershotDirection direction);
389 * @pre The Object has been initialized.
390 * @return The signal to connect to.
392 FocusOvershotSignalType& FocusOvershotSignal();
395 * @brief This signal is emitted when the current focused actor is activated.
397 * A callback of the following type may be connected:
399 * void YourCallbackName(Actor activatedActor);
401 * @pre The Object has been initialized.
402 * @return The signal to connect to.
404 FocusedActorActivatedSignalType& FocusedActorActivatedSignal();
408 explicit DALI_INTERNAL FocusManager(Internal::FocusManager *impl);
410 }; // class FocusManager
412 } // namespace Toolkit
416 #endif // __DALI_TOOLKIT_FOCUS_MANAGER_H__