1 #ifndef __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__
5 * Copyright (c) 2017 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/object/base-object.h>
23 #include <dali/devel-api/object/weak-handle.h>
24 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
28 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
40 * @copydoc Toolkit::KeyboardFocusManager
42 class KeyboardFocusManager : public Dali::BaseObject
46 typedef Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface CustomAlgorithmInterface;
49 * @copydoc Toolkit::KeyboardFocusManager::Get
51 static Toolkit::KeyboardFocusManager Get();
54 * Construct a new KeyboardFocusManager.
56 KeyboardFocusManager();
59 * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
61 bool SetCurrentFocusActor(Actor actor);
64 * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
66 Actor GetCurrentFocusActor();
69 * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
71 bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction);
74 * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
79 * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
81 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
84 * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
86 bool IsFocusGroup(Actor actor) const;
89 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
91 Actor GetFocusGroup(Actor actor);
94 * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
96 void SetFocusGroupLoop(bool enabled);
99 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
101 bool GetFocusGroupLoop() const;
104 * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
106 void SetFocusIndicatorActor(Actor indicator);
109 * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
111 Actor GetFocusIndicatorActor();
114 * Move current focus to backward
116 void MoveFocusBackward();
119 * @copydoc Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm
121 void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
126 * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
128 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& PreFocusChangeSignal();
131 * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
133 Toolkit::KeyboardFocusManager::FocusChangedSignalType& FocusChangedSignal();
136 * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
138 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& FocusGroupChangedSignal();
141 * @copydoc Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignal()
143 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
146 * Connects a callback function with the object's signals.
147 * @param[in] object The object providing the signal.
148 * @param[in] tracker Used to disconnect the signal.
149 * @param[in] signalName The signal to connect to.
150 * @param[in] functor A newly allocated FunctorDelegate.
151 * @return True if the signal was connected.
152 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
154 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
161 virtual ~KeyboardFocusManager();
165 typedef std::vector< WeakHandle< Actor > > FocusStack; ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
166 typedef FocusStack::iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
169 * Get configuration from StyleManager.
171 void GetConfigurationFromStyleManger();
174 * Get the focus group of current focused actor.
175 * @pre The FocusManager has been initialized.
176 * @return A handle to the parent of the current focused actor which is a focus group,
177 * or an empty handle if no actor is focused.
179 Actor GetCurrentFocusGroup();
182 * Move the focus to the specified actor and send notification for the focus change.
183 * @param actor The actor to be queried
184 * @return Whether the focus is successful or not
186 bool DoSetCurrentFocusActor(Actor actor);
189 * Move the focus to the next actor towards the specified direction within the layout control
190 * @param control The layout control to move the focus in
191 * @param actor The current focused actor
192 * @param direction The direction of focus movement
193 * @return Whether the focus is successful or not
195 bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction);
198 * Move the focus to the first focusable actor in the next focus group in the forward
199 * or backward direction. The "Tab" key changes the focus group in the forward direction
200 * and the "Shift-Tab" key changes it in the backward direction.
201 * @param forward Whether the direction of focus group change is forward or backward
202 * @return Whether the focus group change is successful or not
204 bool DoMoveFocusToNextFocusGroup(bool forward);
207 * Enter has been pressed on the actor. If the actor is control, call the OnKeybaordEnter virtual function.
208 * This function will emit FocusedActorEnterKeySignal.
209 * @param actor The actor to notify
211 void DoKeyboardEnter( Actor actor );
214 * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
215 * The layout control needs to internally set the focus order for the child actor and be able to
216 * tell KeyboardFocusmanager the next focusable actor in the given direction.
217 * @pre The KeyboardFocusManager has been initialized.
218 * @pre The Actor has been initialized.
219 * @param actor The actor to be checked.
220 * @return Whether the actor is a layout control or not.
222 bool IsLayoutControl(Actor actor) const;
225 * Returns the closest ancestor of the given actor that is a layout control.
226 * @param actor The actor to be checked for its parent layout control
227 * @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
229 Toolkit::Control GetParentLayoutControl(Actor actor) const;
232 * Callback for the key event when no actor in the stage has gained the key input focus
233 * @param[in] event The KeyEvent event.
235 void OnKeyEvent(const KeyEvent& event);
238 * Callback for the touch event when the screen is touched and when the touch ends
239 * (i.e. the down & up touch events only).
240 * @param[in] touch The touch information
242 void OnTouch( const TouchData& touch );
247 KeyboardFocusManager(const KeyboardFocusManager&);
249 KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
253 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType mPreFocusChangeSignal; ///< The signal to notify the focus will be changed
254 Toolkit::KeyboardFocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
255 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType mFocusGroupChangedSignal; ///< The signal to notify the focus group change
256 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType mFocusedActorEnterKeySignal; ///< The signal to notify that enter has been pressed on the focused actor
258 WeakHandle< Actor > mCurrentFocusActor; ///< A weak handle to the current focused actor
260 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
262 int mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed.
264 bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group
266 bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
268 FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
270 SlotDelegate< KeyboardFocusManager > mSlotDelegate;
272 CustomAlgorithmInterface* mCustomAlgorithmInterface; ///< The user's (application / toolkit) implementation of CustomAlgorithmInterface
276 } // namespace Internal
278 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
280 DALI_ASSERT_ALWAYS(obj);
282 Dali::BaseObject& handle = obj.GetBaseObject();
284 return static_cast<Internal::KeyboardFocusManager&>(handle);
287 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
289 DALI_ASSERT_ALWAYS(obj);
291 const Dali::BaseObject& handle = obj.GetBaseObject();
293 return static_cast<const Internal::KeyboardFocusManager&>(handle);
296 } // namespace Toolkit
300 #endif // __DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H__