1 #ifndef __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_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.
23 #include <dali/dali.h>
24 #include <dali/public-api/common/map-wrapper.h>
27 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
41 * @copydoc Toolkit::FocusManager
43 class FocusManager : public Dali::BaseObject, Dali::AccessibilityActionHandler, Dali::AccessibilityGestureHandler
47 struct ActorAdditionalInfo
54 unsigned int mFocusOrder; ///< The focus order of the actor. It is undefined by default.
56 std::string mAccessibilityAttributes[Toolkit::FocusManager::ACCESSIBILITY_ATTRIBUTE_NUM]; ///< The array of attribute texts
59 typedef std::pair<unsigned int, unsigned int> FocusIDPair;
60 typedef std::map<unsigned int, unsigned int> FocusIDContainer;
61 typedef FocusIDContainer::iterator FocusIDIter;
62 typedef FocusIDContainer::const_iterator FocusIDConstIter;
64 typedef std::pair<unsigned int, ActorAdditionalInfo> IDAdditionalInfoPair;
65 typedef std::map<unsigned int, ActorAdditionalInfo> IDAdditionalInfoContainer;
66 typedef IDAdditionalInfoContainer::iterator IDAdditionalInfoIter;
67 typedef IDAdditionalInfoContainer::const_iterator IDAdditionalInfoConstIter;
70 * Construct a new FocusManager.
75 * @copydoc Toolkit::FocusManager::SetAccessibilityAttribute
77 void SetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type, const std::string& text);
80 * @copydoc Toolkit::FocusManager::GetAccessibilityAttribute
82 std::string GetAccessibilityAttribute(Actor actor, Toolkit::FocusManager::AccessibilityAttribute type) const;
85 * @copydoc Toolkit::FocusManager::SetFocusOrder
87 void SetFocusOrder(Actor actor, const unsigned int order);
90 * @copydoc Toolkit::FocusManager::GetFocusOrder
92 unsigned int GetFocusOrder(Actor actor) const;
95 * @copydoc Toolkit::FocusManager::GenerateNewFocusOrder
97 unsigned int GenerateNewFocusOrder() const;
100 * @copydoc Toolkit::FocusManager::GetActorByFocusOrder
102 Actor GetActorByFocusOrder(const unsigned int order);
105 * @copydoc Toolkit::FocusManager::SetCurrentFocusActor
107 bool SetCurrentFocusActor(Actor actor);
110 * @copydoc Toolkit::FocusManager::GetCurrentFocusActor
112 Actor GetCurrentFocusActor();
115 * @copydoc Toolkit::FocusManager::GetCurrentFocusGroup
117 Actor GetCurrentFocusGroup();
120 * @copydoc Toolkit::FocusManager::GetCurrentFocusOrder
122 unsigned int GetCurrentFocusOrder();
125 * @copydoc Toolkit::FocusManager::MoveFocusForward
127 bool MoveFocusForward();
130 * @copydoc Toolkit::FocusManager::MoveFocusBackward
132 bool MoveFocusBackward();
135 * @copydoc Toolkit::FocusManager::ClearFocus
140 * @copydoc Toolkit::FocusManager::Reset
145 * @copydoc Toolkit::FocusManager::SetFocusGroup
147 void SetFocusGroup(Actor actor, bool isFocusGroup);
150 * @copydoc Toolkit::FocusManager::IsFocusGroup
152 bool IsFocusGroup(Actor actor) const;
155 * @copydoc Toolkit::FocusManager::SetGroupMode
157 void SetGroupMode(bool enabled);
160 * @copydoc Toolkit::FocusManager::GetGroupMode
162 bool GetGroupMode() const;
165 * @copydoc Toolkit::FocusManager::SetWrapMode
167 void SetWrapMode(bool wrapped);
170 * @copydoc Toolkit::FocusManager::GetWrapMode
172 bool GetWrapMode() const;
175 * @copydoc Toolkit::FocusManager::SetFocusIndicatorActor
177 void SetFocusIndicatorActor(Actor indicator);
180 * @copydoc Toolkit::FocusManager::GetFocusIndicatorActor
182 Actor GetFocusIndicatorActor();
185 * @copydoc Toolkit::FocusManager::GetFocusGroup
187 Actor GetFocusGroup(Actor actor);
192 * @copydoc Toolkit::FocusManager::FocusChangedSignal()
194 Toolkit::FocusManager::FocusChangedSignalV2& FocusChangedSignal();
197 * @copydoc Toolkit::FocusManager::FocusOvershotSignal()
199 Toolkit::FocusManager::FocusOvershotSignalV2& FocusOvershotSignal();
202 * @copydoc Toolkit::FocusManager::FocusedActorActivatedSignal()
204 Toolkit::FocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
207 * Connects a callback function with the object's signals.
208 * @param[in] object The object providing the signal.
209 * @param[in] tracker Used to disconnect the signal.
210 * @param[in] signalName The signal to connect to.
211 * @param[in] functor A newly allocated FunctorDelegate.
212 * @return True if the signal was connected.
213 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
215 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
222 virtual ~FocusManager();
227 * Get the additional information (e.g. focus order and description) of the given actor.
228 * @param actorID The ID of the actor to be queried
229 * @return The additional information of the actor
231 ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
234 * Synchronize the actor's additional information to reflect its latest focus order
235 * @param actorID The ID of the actor
236 * @param order The focus order of the actor
237 * @return The additional information of the actor
239 void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
242 * Move the focus to the specified actor and send notification for the focus change.
243 * @param actorID The ID of the actor to be queried
244 * @return Whether the focus is successful or not
246 bool DoSetCurrentFocusActor(const unsigned int actorID);
249 * Move the focus to the next actor in the focus chain towards the specified direction.
250 * @param focusIDIter The iterator pointing to the current focused actor
251 * @param forward Whether the focus movement is forward or not. The focus movement will be backward if this is false.
252 * @param wrapped Whether the focus shoule be moved wrapped around or not
253 * @return Whether the focus is successful or not
255 bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
258 * Activate the actor. If the actor is control, call OnActivated virtual function.
259 * This function will emit FocusedActorActivatedSignal.
260 * @param actor The actor to activate
262 void DoActivate(Actor actor);
265 * Create the default indicator actor to highlight the focused actor.
267 void CreateDefaultFocusIndicatorActor();
270 * Set whether the actor is focusable or not. A focusable property will be registered for
271 * the actor if not yet.
272 * @param actor The actor to be focused
273 * @param focusable Whether the actor is focusable or not
275 void SetFocusable(Actor actor, bool focusable);
278 * Handle the accessibility pan gesture.
279 * @param[in] panEvent The pan event to be handled.
280 * @return whether the gesture is handled successfully or not.
282 virtual bool HandlePanGesture(const Integration::PanGestureEvent& panEvent);
285 * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
286 * @return whether the status is changed or not.
288 virtual bool ChangeAccessibilityStatus();
291 * Clear the accessibility focus from the current focused actor.
292 * @return whether the focus is cleared or not.
294 virtual bool ClearAccessibilityFocus();
297 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick up).
298 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
299 * @return whether the accessibility action is performed or not.
301 virtual bool AccessibilityActionPrevious(bool allowEndFeedback);
304 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
305 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
306 * @return whether the accessibility action is performed or not.
308 virtual bool AccessibilityActionNext(bool allowEndFeedback);
311 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
312 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
313 * @return whether the accessibility action is performed or not.
315 virtual bool AccessibilityActionReadPrevious(bool allowEndFeedback);
318 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
319 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
320 * @return whether the accessibility action is performed or not.
322 virtual bool AccessibilityActionReadNext(bool allowEndFeedback);
325 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
326 * @param allowReadAgain true if the action read again the same object (i.e. read action)
327 * false if the action just read when the focus object is changed (i.e. over action)
328 * @return whether the accessibility action is performed or not.
330 virtual bool AccessibilityActionRead(bool allowReadAgain);
333 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
334 * @return whether the accessibility action is performed or not.
336 virtual bool AccessibilityActionActivate();
339 * Perform the accessibility action to change the value when the current focused actor is a slider
340 * (by double finger down and move up and right).
341 * @return whether the accessibility action is performed or not.
343 virtual bool AccessibilityActionUp();
346 * Perform the accessibility action to change the value when the current focused actor is a slider
347 * (by double finger down and move down and left).
348 * @return whether the accessibility action is performed or not.
350 virtual bool AccessibilityActionDown();
353 * Perform the accessibility action to navigate back (by two fingers circle draw).
354 * @return whether the accessibility action is performed or not.
356 virtual bool AccessibilityActionBack();
359 * Perform the accessibility action to mouse move (by one finger tap & hold and move).
360 * @param touchEvent touch event structure
361 * @return whether the accessibility action is performed or not.
363 virtual bool AccessibilityActionTouch(const TouchEvent& touchEvent);
368 FocusManager(const FocusManager&);
370 FocusManager& operator=(const FocusManager& rhs);
374 Toolkit::FocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
375 Toolkit::FocusManager::FocusOvershotSignalV2 mFocusOvershotSignalV2; ///< The signal to notify the focus overshooted
376 Toolkit::FocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
378 bool mIsWrapped; ///< Whether the focus movement is wrapped around or not
379 bool mIsFocusWithinGroup; ///< Whether the focus movement is limited to the current focus group or not
381 bool mIsEndcapFeedbackEnabled; ///< Whether the endcap feedback need to be played when the focus leaves the end or vice versa
382 bool mIsEndcapFeedbackPlayed; ///< Whether the endcap feedback was played or not
384 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
385 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
387 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
388 Actor mCurrentGesturedActor; ///< The actor that will handle the gesture
390 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
392 Vector2 mPreviousPosition; ///< The previous pan position; useful for calculating velocity for Gesture::Finished events
394 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
396 bool mIsAccessibilityTtsEnabled; ///< Whether accessibility feature(screen-reader) turned on/off
398 bool mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
401 } // namespace Internal
403 inline Internal::FocusManager& GetImpl(Dali::Toolkit::FocusManager& obj)
405 DALI_ASSERT_ALWAYS(obj);
407 Dali::BaseObject& handle = obj.GetBaseObject();
409 return static_cast<Internal::FocusManager&>(handle);
412 inline const Internal::FocusManager& GetImpl(const Dali::Toolkit::FocusManager& obj)
414 DALI_ASSERT_ALWAYS(obj);
416 const Dali::BaseObject& handle = obj.GetBaseObject();
418 return static_cast<const Internal::FocusManager&>(handle);
421 } // namespace Toolkit
425 #endif // __DALI_TOOLKIT_INTERNAL_FOCUS_MANAGER_H__