1 #ifndef __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
24 #include <dali/dali.h>
25 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
37 * @copydoc Toolkit::KeyboardFocusManager
39 class KeyboardFocusManager : public Dali::BaseObject
44 * @copydoc Toolkit::KeyboardFocusManager::Get
46 static Toolkit::KeyboardFocusManager Get();
49 * Construct a new KeyboardFocusManager.
51 KeyboardFocusManager();
54 * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
56 bool SetCurrentFocusActor(Actor actor);
59 * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
61 Actor GetCurrentFocusActor();
64 * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
66 bool MoveFocus(Toolkit::Control::KeyboardFocusNavigationDirection direction);
69 * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
74 * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
76 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
79 * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
81 bool IsFocusGroup(Actor actor) const;
84 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
86 Actor GetFocusGroup(Actor actor);
89 * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
91 void SetFocusGroupLoop(bool enabled);
94 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
96 bool GetFocusGroupLoop() const;
99 * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
101 void SetFocusIndicatorActor(Actor indicator);
104 * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
106 Actor GetFocusIndicatorActor();
111 * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
113 Toolkit::KeyboardFocusManager::PreFocusChangeSignalV2& PreFocusChangeSignal();
116 * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
118 Toolkit::KeyboardFocusManager::FocusChangedSignalV2& FocusChangedSignal();
121 * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
123 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalV2& FocusGroupChangedSignal();
126 * @copydoc Toolkit::KeyboardFocusManager::FocusedActorActivatedSignal()
128 Toolkit::KeyboardFocusManager::FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
131 * Connects a callback function with the object's signals.
132 * @param[in] object The object providing the signal.
133 * @param[in] tracker Used to disconnect the signal.
134 * @param[in] signalName The signal to connect to.
135 * @param[in] functor A newly allocated FunctorDelegate.
136 * @return True if the signal was connected.
137 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
139 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
146 virtual ~KeyboardFocusManager();
151 * Get the focus group of current focused actor.
152 * @pre The FocusManager has been initialized.
153 * @return A handle to the parent of the current focused actor which is a focus group,
154 * or an empty handle if no actor is focused.
156 Actor GetCurrentFocusGroup();
159 * Move the focus to the specified actor and send notification for the focus change.
160 * @param actorID The ID of the actor to be queried
161 * @return Whether the focus is successful or not
163 bool DoSetCurrentFocusActor(const unsigned int actorID);
166 * Move the focus to the next actor towards the specified direction within the layout control
167 * @param control The layout control to move the focus in
168 * @param actor The current focused actor
169 * @param direction The direction of focus movement
170 * @return Whether the focus is successful or not
172 bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocusNavigationDirection direction);
175 * Move the focus to the first focusable actor in the next focus group in the forward
176 * or backward direction. The "Tab" key changes the focus group in the forward direction
177 * and the "Shift-Tab" key changes it in the backward direction.
178 * @param forward Whether the direction of focus group change is forward or backward
179 * @return Whether the focus group change is successful or not
181 bool DoMoveFocusToNextFocusGroup(bool forward);
184 * Activate the actor. If the actor is control, call OnActivated virtual function.
185 * This function will emit FocusedActorActivatedSignal.
186 * @param actor The actor to activate
188 void DoActivate(Actor actor);
191 * Create the default indicator actor to highlight the focused actor.
193 void CreateDefaultFocusIndicatorActor();
196 * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
197 * The layout control needs to internally set the focus order for the child actor and be able to
198 * tell KeyboardFocusmanager the next focusable actor in the given direction.
199 * @pre The KeyboardFocusManager has been initialized.
200 * @pre The Actor has been initialized.
201 * @param actor The actor to be checked.
202 * @return Whether the actor is a layout control or not.
204 bool IsLayoutControl(Actor actor) const;
207 * Returns the closest ancestor of the given actor that is a layout control.
208 * @param actor The actor to be checked for its parent layout control
209 * @return The parent layout control the given actor belongs to or an empty handle if the given actor doesn't belong to a layout control
211 Toolkit::Control GetParentLayoutControl(Actor actor) const;
214 * Callback for the key event when no actor in the stage has gained the key input focus
215 * @param[in] event The KeyEvent event.
217 void OnKeyEvent(const KeyEvent& event);
220 * Callback for the touch event when the screen is touched and when the touch ends
221 * (i.e. the down & up touch events only).
222 * @param[in] touchEvent The touch event
224 void OnTouched(const TouchEvent& touchEvent);
227 * Change the keyboard focus status when keyboard focus feature turned on or off.
228 * @return Whether the status is changed or not.
230 void OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyboard);
235 KeyboardFocusManager(const KeyboardFocusManager&);
237 KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
241 Toolkit::KeyboardFocusManager::PreFocusChangeSignalV2 mPreFocusChangeSignalV2; ///< The signal to notify the focus will be changed
242 Toolkit::KeyboardFocusManager::FocusChangedSignalV2 mFocusChangedSignalV2; ///< The signal to notify the focus change
243 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalV2 mFocusGroupChangedSignalV2; ///< The signal to notify the focus group change
244 Toolkit::KeyboardFocusManager::FocusedActorActivatedSignalV2 mFocusedActorActivatedSignalV2; ///< The signal to notify the activation of focused actor
246 unsigned int mCurrentFocusActor; ///< The actor ID of current focused actor
248 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
250 bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
252 bool mIsKeyboardFocusEnabled:1; ///< Whether keyboard focus feature turned on/off
254 bool mIsFocusIndicatorEnabled:1; ///< Whether indicator should be shown / hidden. It could be enabled when keyboard focus feature enabled and navigation keys or 'Tab' key pressed.
256 bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
258 SlotDelegate< KeyboardFocusManager > mSlotDelegate;
261 } // namespace Internal
263 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
265 DALI_ASSERT_ALWAYS(obj);
267 Dali::BaseObject& handle = obj.GetBaseObject();
269 return static_cast<Internal::KeyboardFocusManager&>(handle);
272 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
274 DALI_ASSERT_ALWAYS(obj);
276 const Dali::BaseObject& handle = obj.GetBaseObject();
278 return static_cast<const Internal::KeyboardFocusManager&>(handle);
281 } // namespace Toolkit
285 #endif // __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__