1 #ifndef __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
5 * Copyright (c) 2016 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/devel-api/adaptor-framework/physical-keyboard.h>
24 #include <dali/public-api/object/base-object.h>
27 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
39 * @copydoc Toolkit::KeyboardFocusManager
41 class KeyboardFocusManager : public Dali::BaseObject
46 * @copydoc Toolkit::KeyboardFocusManager::Get
48 static Toolkit::KeyboardFocusManager Get();
51 * Construct a new KeyboardFocusManager.
53 KeyboardFocusManager();
56 * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
58 bool SetCurrentFocusActor(Actor actor);
61 * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
63 Actor GetCurrentFocusActor();
66 * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
68 bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction);
71 * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
76 * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
78 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
81 * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
83 bool IsFocusGroup(Actor actor) const;
86 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
88 Actor GetFocusGroup(Actor actor);
91 * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
93 void SetFocusGroupLoop(bool enabled);
96 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
98 bool GetFocusGroupLoop() const;
101 * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
103 void SetFocusIndicatorActor(Actor indicator);
106 * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
108 Actor GetFocusIndicatorActor();
111 * Move current focus to backward
113 void MoveFocusBackward();
118 * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
120 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& PreFocusChangeSignal();
123 * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
125 Toolkit::KeyboardFocusManager::FocusChangedSignalType& FocusChangedSignal();
128 * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
130 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& FocusGroupChangedSignal();
133 * @copydoc Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignal()
135 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
138 * Connects a callback function with the object's signals.
139 * @param[in] object The object providing the signal.
140 * @param[in] tracker Used to disconnect the signal.
141 * @param[in] signalName The signal to connect to.
142 * @param[in] functor A newly allocated FunctorDelegate.
143 * @return True if the signal was connected.
144 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
146 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
153 virtual ~KeyboardFocusManager();
157 typedef Dali::Vector< Dali::BaseObject* > FocusStack; ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
158 typedef FocusStack::Iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
161 * Get the focus group of current focused actor.
162 * @pre The FocusManager has been initialized.
163 * @return A handle to the parent of the current focused actor which is a focus group,
164 * or an empty handle if no actor is focused.
166 Actor GetCurrentFocusGroup();
169 * Move the focus to the specified actor and send notification for the focus change.
170 * @param actorID The ID of the actor to be queried
171 * @return Whether the focus is successful or not
173 bool DoSetCurrentFocusActor(const unsigned int actorID);
176 * Move the focus to the next actor towards the specified direction within the layout control
177 * @param control The layout control to move the focus in
178 * @param actor The current focused actor
179 * @param direction The direction of focus movement
180 * @return Whether the focus is successful or not
182 bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction);
185 * Move the focus to the first focusable actor in the next focus group in the forward
186 * or backward direction. The "Tab" key changes the focus group in the forward direction
187 * and the "Shift-Tab" key changes it in the backward direction.
188 * @param forward Whether the direction of focus group change is forward or backward
189 * @return Whether the focus group change is successful or not
191 bool DoMoveFocusToNextFocusGroup(bool forward);
194 * Enter has been pressed on the actor. If the actor is control, call the OnKeybaordEnter virtual function.
195 * This function will emit FocusedActorEnterKeySignal.
196 * @param actor The actor to notify
198 void DoKeyboardEnter( Actor actor );
201 * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
202 * The layout control needs to internally set the focus order for the child actor and be able to
203 * tell KeyboardFocusmanager the next focusable actor in the given direction.
204 * @pre The KeyboardFocusManager has been initialized.
205 * @pre The Actor has been initialized.
206 * @param actor The actor to be checked.
207 * @return Whether the actor is a layout control or not.
209 bool IsLayoutControl(Actor actor) const;
212 * Returns the closest ancestor of the given actor that is a layout control.
213 * @param actor The actor to be checked for its parent layout control
214 * @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
216 Toolkit::Control GetParentLayoutControl(Actor actor) const;
219 * Callback for the key event when no actor in the stage has gained the key input focus
220 * @param[in] event The KeyEvent event.
222 void OnKeyEvent(const KeyEvent& event);
225 * Callback for the touch event when the screen is touched and when the touch ends
226 * (i.e. the down & up touch events only).
227 * @param[in] touch The touch information
229 void OnTouch( const TouchData& touch );
232 * Change the keyboard focus status when keyboard focus feature turned on or off.
233 * @return Whether the status is changed or not.
235 void OnPhysicalKeyboardStatusChanged(PhysicalKeyboard keyboard);
240 KeyboardFocusManager(const KeyboardFocusManager&);
242 KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
246 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType mPreFocusChangeSignal; ///< The signal to notify the focus will be changed
247 Toolkit::KeyboardFocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
248 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType mFocusGroupChangedSignal; ///< The signal to notify the focus group change
249 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType mFocusedActorEnterKeySignal; ///< The signal to notify that enter has been pressed on the focused actor
251 unsigned int mCurrentFocusActor; ///< The actor ID of current focused actor
253 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
255 bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
257 bool mIsKeyboardFocusEnabled:1; ///< Whether keyboard focus feature turned on/off
259 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.
261 bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
263 FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
265 FocusStackIterator mFocusHistoryIter; ///< Iterator for mFocusHistory
267 SlotDelegate< KeyboardFocusManager > mSlotDelegate;
271 } // namespace Internal
273 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
275 DALI_ASSERT_ALWAYS(obj);
277 Dali::BaseObject& handle = obj.GetBaseObject();
279 return static_cast<Internal::KeyboardFocusManager&>(handle);
282 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
284 DALI_ASSERT_ALWAYS(obj);
286 const Dali::BaseObject& handle = obj.GetBaseObject();
288 return static_cast<const Internal::KeyboardFocusManager&>(handle);
291 } // namespace Toolkit
295 #endif // __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__