1 #ifndef DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H
2 #define DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H
5 * Copyright (c) 2021 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/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/object/weak-handle.h>
27 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
28 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
29 #include <dali/devel-api/adaptor-framework/window-devel.h>
37 } // namespace Integration
44 * @copydoc Toolkit::KeyboardFocusManager
46 class KeyboardFocusManager : public Dali::BaseObject, public ConnectionTracker
49 typedef Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface CustomAlgorithmInterface;
51 enum FocusIndicatorState
53 UNKNOWN = -1, ///< Unknown state
54 HIDE = 0, ///< FocusIndicator is hidden
55 SHOW = 1, ///< FocusIndicator is shown
58 enum EnableFocusedIndicatorState
60 DISABLE = 0, ///< FocusIndicator is disable
61 ENABLE = 1, ///< FocusIndicator is enable
64 enum FocusedIndicatorModeState
66 NONE = 0, ///< Set nothing
67 ALWAYS_SHOW = 1, ///< FocusIndicator is always shown
71 * @copydoc Toolkit::KeyboardFocusManager::Get
73 static Toolkit::KeyboardFocusManager Get();
76 * Construct a new KeyboardFocusManager.
78 KeyboardFocusManager();
81 * @copydoc Toolkit::KeyboardFocusManager::SetCurrentFocusActor
83 bool SetCurrentFocusActor(Actor actor);
86 * @copydoc Toolkit::KeyboardFocusManager::GetCurrentFocusActor
88 Actor GetCurrentFocusActor();
91 * @copydoc Toolkit::KeyboardFocusManager::MoveFocus
93 bool MoveFocus(Toolkit::Control::KeyboardFocus::Direction direction);
96 * @copydoc Toolkit::KeyboardFocusManager::ClearFocus
101 * @copydoc Toolkit::KeyboardFocusManager::SetAsFocusGroup
103 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
106 * @copydoc Toolkit::KeyboardFocusManager::IsFocusGroup
108 bool IsFocusGroup(Actor actor) const;
111 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroup
113 Actor GetFocusGroup(Actor actor);
116 * @copydoc Toolkit::KeyboardFocusManager::SetFocusGroupLoop
118 void SetFocusGroupLoop(bool enabled);
121 * @copydoc Toolkit::KeyboardFocusManager::GetFocusGroupLoop
123 bool GetFocusGroupLoop() const;
126 * @copydoc Toolkit::KeyboardFocusManager::SetFocusIndicatorActor
128 void SetFocusIndicatorActor(Actor indicator);
131 * @copydoc Toolkit::KeyboardFocusManager::GetFocusIndicatorActor
133 Actor GetFocusIndicatorActor();
136 * Move current focus to backward
138 void MoveFocusBackward();
141 * @copydoc Toolkit::DevelKeyboardFocusManager::SetCustomAlgorithm
143 void SetCustomAlgorithm(CustomAlgorithmInterface& interface);
146 * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
148 void EnableFocusIndicator(bool enable);
151 * @copydoc Toolkit::DevelKeyboardFocusManager::UseFocusIndicator
153 bool IsFocusIndicatorEnabled() const;
157 * @copydoc Toolkit::KeyboardFocusManager::PreFocusChangeSignal()
159 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType& PreFocusChangeSignal();
162 * @copydoc Toolkit::KeyboardFocusManager::FocusChangedSignal()
164 Toolkit::KeyboardFocusManager::FocusChangedSignalType& FocusChangedSignal();
167 * @copydoc Toolkit::KeyboardFocusManager::FocusGroupChangedSignal()
169 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType& FocusGroupChangedSignal();
172 * @copydoc Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignal()
174 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType& FocusedActorEnterKeySignal();
177 * Connects a callback function with the object's signals.
178 * @param[in] object The object providing the signal.
179 * @param[in] tracker Used to disconnect the signal.
180 * @param[in] signalName The signal to connect to.
181 * @param[in] functor A newly allocated FunctorDelegate.
182 * @return True if the signal was connected.
183 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
185 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
191 virtual ~KeyboardFocusManager();
194 typedef std::vector<WeakHandle<Actor> > FocusStack; ///< Define Dali::Vector< Dali::BaseObject* > as FocusStack to contain focus history
195 typedef FocusStack::iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack
198 * This will be called when the adaptor is initialized
200 void OnAdaptorInit();
203 * This will be called when a new scene holder is created
204 * @param sceneHolder The new scene holder
206 void OnSceneHolderCreated(Dali::Integration::SceneHolder& sceneHolder);
209 * Get configuration from StyleManager.
211 void GetConfigurationFromStyleManger();
214 * Get the focus group of current focused actor.
215 * @pre The FocusManager has been initialized.
216 * @return A handle to the parent of the current focused actor which is a focus group,
217 * or an empty handle if no actor is focused.
219 Actor GetCurrentFocusGroup();
222 * Move the focus to the specified actor and send notification for the focus change.
223 * @param actor The actor to be queried
224 * @return Whether the focus is successful or not
226 bool DoSetCurrentFocusActor(Actor actor);
229 * Move the focus to the next actor towards the specified direction within the layout control
230 * @param control The layout control to move the focus in
231 * @param actor The current focused actor
232 * @param direction The direction of focus movement
233 * @return Whether the focus is successful or not
235 bool DoMoveFocusWithinLayoutControl(Toolkit::Control control, Actor actor, Toolkit::Control::KeyboardFocus::Direction direction);
238 * Move the focus to the first focusable actor in the next focus group in the forward
239 * or backward direction. The "Tab" key changes the focus group in the forward direction
240 * and the "Shift-Tab" key changes it in the backward direction.
241 * @param forward Whether the direction of focus group change is forward or backward
242 * @return Whether the focus group change is successful or not
244 bool DoMoveFocusToNextFocusGroup(bool forward);
247 * Enter has been pressed on the actor. If the actor is control, call the OnKeybaordEnter virtual function.
248 * This function will emit FocusedActorEnterKeySignal.
249 * @param actor The actor to notify
251 void DoKeyboardEnter(Actor actor);
254 * Check whether the actor is a layout control that supports two dimensional keyboard navigation.
255 * The layout control needs to internally set the focus order for the child actor and be able to
256 * tell KeyboardFocusmanager the next focusable actor in the given direction.
257 * @pre The KeyboardFocusManager has been initialized.
258 * @pre The Actor has been initialized.
259 * @param actor The actor to be checked.
260 * @return Whether the actor is a layout control or not.
262 bool IsLayoutControl(Actor actor) const;
265 * Returns the closest ancestor of the given actor that is a layout control.
266 * @param actor The actor to be checked for its parent layout control
267 * @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
269 Toolkit::Control GetParentLayoutControl(Actor actor) const;
272 * Callback for the key event when no actor in the stage has gained the key input focus
273 * @param[in] event The KeyEvent event.
275 void OnKeyEvent(const KeyEvent& event);
278 * Callback for the touch event when the screen is touched and when the touch ends
279 * (i.e. the down & up touch events only).
280 * @param[in] touch The touch information
282 void OnTouch(const TouchEvent& touch);
285 * Called when the window focus is changed.
286 * @param[in] window The window whose focus is changed
287 * @param[in] focusIn Whether the focus is in/out
289 void OnWindowFocusChanged(Window window, bool focusIn);
292 * Get the focus Actor from current window
294 Actor GetFocusActorFromCurrentWindow();
298 KeyboardFocusManager(const KeyboardFocusManager&);
300 KeyboardFocusManager& operator=(const KeyboardFocusManager& rhs);
303 Toolkit::KeyboardFocusManager::PreFocusChangeSignalType mPreFocusChangeSignal; ///< The signal to notify the focus will be changed
304 Toolkit::KeyboardFocusManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
305 Toolkit::KeyboardFocusManager::FocusGroupChangedSignalType mFocusGroupChangedSignal; ///< The signal to notify the focus group change
306 Toolkit::KeyboardFocusManager::FocusedActorEnterKeySignalType mFocusedActorEnterKeySignal; ///< The signal to notify that enter has been pressed on the focused actor
308 WeakHandle<Actor> mCurrentFocusActor; ///< A weak handle to the current focused actor
310 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight
312 FocusStack mFocusHistory; ///< Stack to contain pre-focused actor's BaseObject*
314 SlotDelegate<KeyboardFocusManager> mSlotDelegate;
316 CustomAlgorithmInterface* mCustomAlgorithmInterface; ///< The user's (application / toolkit) implementation of CustomAlgorithmInterface
318 typedef std::vector<std::pair<WeakHandle<Layer>, WeakHandle<Actor> > > FocusActorContainer;
320 FocusActorContainer mCurrentFocusActors; ///< A container of focused actors
322 WeakHandle<Layer> mCurrentFocusedWindow; ///< A weak handle to the current focused window's root layer
324 FocusIndicatorState mIsFocusIndicatorShown; ///< 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.
326 EnableFocusedIndicatorState mEnableFocusIndicator; ///< Whether use focus indicator
328 FocusedIndicatorModeState mAlwaysShowIndicator; ///< Whether always show indicator. If true, the indicator would be directly shown when focused
330 bool mFocusGroupLoopEnabled : 1; ///< Whether the focus movement is looped within the same focus group
332 bool mIsWaitingKeyboardFocusChangeCommit : 1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet.
334 bool mClearFocusOnTouch : 1; ///< Whether clear focus on touch.
337 } // namespace Internal
339 inline Internal::KeyboardFocusManager& GetImpl(Dali::Toolkit::KeyboardFocusManager& obj)
341 DALI_ASSERT_ALWAYS(obj);
343 Dali::BaseObject& handle = obj.GetBaseObject();
345 return static_cast<Internal::KeyboardFocusManager&>(handle);
348 inline const Internal::KeyboardFocusManager& GetImpl(const Dali::Toolkit::KeyboardFocusManager& obj)
350 DALI_ASSERT_ALWAYS(obj);
352 const Dali::BaseObject& handle = obj.GetBaseObject();
354 return static_cast<const Internal::KeyboardFocusManager&>(handle);
357 } // namespace Toolkit
361 #endif // DALI_TOOLKIT_INTERNAL_KEYBOARD_FOCUS_MANAGER_H