1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2023 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/adaptor-framework/style-change.h>
23 #include <dali/public-api/animation/alpha-function.h>
24 #include <dali/public-api/animation/time-period.h>
25 #include <dali/public-api/events/long-press-gesture.h>
26 #include <dali/public-api/events/pan-gesture.h>
27 #include <dali/public-api/events/pinch-gesture.h>
28 #include <dali/public-api/events/tap-gesture.h>
29 #include <dali/public-api/object/property-index-ranges.h>
30 #include <dali/public-api/object/type-info.h>
33 #include <dali-toolkit/public-api/controls/control.h>
40 * @addtogroup dali_toolkit_controls
46 namespace DevelControl
48 class ControlAccessible;
50 } // namespace DevelControl
55 * @brief This is the internal base class for all controls.
57 * It will provide some common functionality required by all controls.
58 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
59 * be disconnected automatically when the control is destroyed.
62 class DALI_TOOLKIT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
65 class Extension; ///< Forward declare future extension interface
67 // Creation & Destruction
69 * @brief Creates a new ControlImpl instance that does not require touch by default.
71 * If touch is required, then the user can connect to this class' touch signal.
73 * @return A handle to the ControlImpl instance
75 static Toolkit::Control New();
79 * @brief Virtual destructor.
88 * @copydoc Dali::Toolkit::Control::SetStyleName
90 void SetStyleName(const std::string& styleName);
93 * @copydoc Dali::Toolkit::Control::GetStyleName
95 const std::string& GetStyleName() const;
100 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
102 void SetBackgroundColor(const Vector4& color);
105 * @brief Sets the background with a property map.
108 * @param[in] map The background property map
110 void SetBackground(const Property::Map& map);
113 * @copydoc Dali::Toolkit::Control::ClearBackground
115 void ClearBackground();
118 * @copydoc Dali::Toolkit::Control::SetRenderEffect
120 void SetRenderEffect(Toolkit::RenderEffect effect);
123 * @copydoc Dali::Toolkit::Control::ClearRenderEffect
125 void ClearRenderEffect();
128 * @brief Called when resources of control are ready. this api does not request relayout.
130 void SetResourceReady();
135 * @brief Gets the Accessible object that represents this control.
137 * This method calls CreateAccessibleObject() if CreateAccessible is true.
139 * @return The Accessible object
141 * @see CreateAccessibleObject()
143 std::shared_ptr<Toolkit::DevelControl::ControlAccessible> GetAccessibleObject();
148 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
150 * Gesture detection can be enabled one at a time or in bitwise format as shown:
152 * EnableGestureDetection(GestureType::Value(GestureType::PINCH | GestureType::TAP | GestureType::PAN));
155 * @param[in] type The gesture type(s) to enable
157 void EnableGestureDetection(GestureType::Value type);
160 * @brief Allows deriving classes to disable any of the gesture detectors.
162 * Like EnableGestureDetection, this can also be called using bitwise or.
164 * @param[in] type The gesture type(s) to disable
165 * @see EnableGetureDetection
167 void DisableGestureDetection(GestureType::Value type);
170 * @brief If deriving classes wish to fine tune pinch gesture
171 * detection, then they can access the gesture detector through this
172 * API and modify the detection.
175 * @return The pinch gesture detector
176 * @pre Pinch detection should have been enabled via EnableGestureDetection().
177 * @see EnableGestureDetection
179 PinchGestureDetector GetPinchGestureDetector() const;
182 * @brief If deriving classes wish to fine tune pan gesture
183 * detection, then they can access the gesture detector through this
184 * API and modify the detection.
187 * @return The pan gesture detector
188 * @pre Pan detection should have been enabled via EnableGestureDetection().
189 * @see EnableGestureDetection
191 PanGestureDetector GetPanGestureDetector() const;
194 * @brief If deriving classes wish to fine tune tap gesture
195 * detection, then they can access the gesture detector through this
196 * API and modify the detection.
199 * @return The tap gesture detector
200 * @pre Tap detection should have been enabled via EnableGestureDetection().
201 * @see EnableGestureDetection
203 TapGestureDetector GetTapGestureDetector() const;
206 * @brief If deriving classes wish to fine tune long press gesture
207 * detection, then they can access the gesture detector through this
208 * API and modify the detection.
211 * @return The long press gesture detector
212 * @pre Long press detection should have been enabled via EnableGestureDetection().
213 * @see EnableGestureDetection
215 LongPressGestureDetector GetLongPressGestureDetector() const;
217 // Keyboard Navigation
220 * @brief Sets whether this control supports two dimensional
221 * keyboard navigation (i.e. whether it knows how to handle the
222 * keyboard focus movement between its child actors).
224 * The control doesn't support it by default.
226 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
228 void SetKeyboardNavigationSupport(bool isSupported);
231 * @brief Gets whether this control supports two dimensional keyboard navigation.
234 * @return true if this control supports two dimensional keyboard navigation
236 bool IsKeyboardNavigationSupported();
241 * @copydoc Toolkit::Control::SetKeyInputFocus()
243 void SetKeyInputFocus();
246 * @copydoc Toolkit::Control::HasKeyInputFocus()
248 bool HasKeyInputFocus();
251 * @copydoc Toolkit::Control::ClearKeyInputFocus()
253 void ClearKeyInputFocus();
258 * @brief Sets whether this control is a focus group for keyboard navigation.
260 * (i.e. the scope of keyboard focus movement
261 * can be limited to its child actors). The control is not a focus group by default.
263 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
265 void SetAsKeyboardFocusGroup(bool isFocusGroup);
268 * @brief Gets whether this control is a focus group for keyboard navigation.
271 * @return true if this control is set as a focus group for keyboard navigation
273 bool IsKeyboardFocusGroup();
277 * @brief Called by the KeyboardFocusManager.
280 DALI_INTERNAL void KeyboardEnter();
286 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
288 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
291 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
293 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
296 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
298 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
302 * @brief Called by the KeyInputFocusManager to emit key event signals.
305 * @param[in] event The key event
306 * @return True if the event was consumed
308 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
311 protected: // For derived classes to call
313 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
315 * Should be called last by the control after it acts on the Input Focus change.
318 * @param[in] focusGained True if gained, False if lost
320 void EmitKeyInputFocusSignal(bool focusGained);
322 protected: // From CustomActorImpl
324 * @copydoc CustomActorImpl::OnSceneConnection()
325 * @note If overridden, then an up-call to Control::OnSceneConnection MUST be made at the end.
327 void OnSceneConnection(int depth) override;
330 * @copydoc CustomActorImpl::OnSceneDisconnection()
331 * @note If overridden, then an up-call to Control::OnSceneDisconnection MUST be made at the end.
333 void OnSceneDisconnection() override;
336 * @copydoc CustomActorImpl::OnChildAdd()
337 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
339 void OnChildAdd(Actor& child) override;
342 * @copydoc CustomActorImpl::OnChildRemove()
343 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
345 void OnChildRemove(Actor& child) override;
348 * @copydoc CustomActorImpl::OnPropertySet()
349 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
351 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
354 * @copydoc CustomActorImpl::OnSizeSet()
355 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
357 void OnSizeSet(const Vector3& targetSize) override;
360 * @copydoc CustomActorImpl::OnSizeAnimation()
361 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
363 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
366 * @copydoc CustomActorImpl::OnRelayout()
368 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
371 * @copydoc CustomActorImpl::OnSetResizePolicy()
373 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
376 * @copydoc CustomActorImpl::GetNaturalSize()
378 Vector3 GetNaturalSize() override;
381 * @copydoc CustomActorImpl::CalculateChildSize()
383 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
386 * @copydoc CustomActorImpl::GetHeightForWidth()
388 float GetHeightForWidth(float width) override;
391 * @copydoc CustomActorImpl::GetWidthForHeight()
393 float GetWidthForHeight(float height) override;
396 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
398 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
401 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
403 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
406 * @copydoc CustomActorImpl::OnLayoutNegotiated()
408 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
410 public: // Helpers for deriving classes
412 * @brief Flags for the constructor.
415 enum ControlBehaviour
417 CONTROL_BEHAVIOUR_DEFAULT = 0, ///< Default behaviour: Size negotiation is enabled & listens to Style Change signal, but doesn't receive event callbacks. @SINCE_1_2_10
418 NOT_IN_USE_1 = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 0),
419 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 1), ///< True if needs to support keyboard navigation @SINCE_1_0.0
420 DISABLE_STYLE_CHANGE_SIGNALS = 1 << (CustomActorImpl::ACTOR_FLAG_COUNT + 2), ///< True if control should not monitor style change signals @SINCE_1_2_10
422 LAST_CONTROL_BEHAVIOUR_FLAG
425 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log<LAST_CONTROL_BEHAVIOUR_FLAG - 1>::value + 1; ///< Total count of flags
428 * @brief Creates a new ControlImpl instance that does not require touch by default.
430 * If touch is required, then the user can connect to this class' touch signal.
432 * @param[in] additionalBehaviour Additional control behaviour.
433 * @return A handle to the ControlImpl instance
435 static Toolkit::Control New(ControlBehaviour additionalBehaviour);
441 * @brief Control constructor.
444 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
446 Control(ControlBehaviour behaviourFlags);
449 * @brief Second phase initialization.
454 public: // API for derived classes to override
458 * @brief This method is called after the Control has been initialized.
460 * Derived classes should do any second phase initialization by overriding this method.
463 virtual void OnInitialize();
466 * @copydoc Dali::Toolkit::Control::IsResourceReady
468 virtual bool IsResourceReady() const;
473 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
476 * @param[in] styleManager The StyleManager object
477 * @param[in] change Information denoting what has changed
479 virtual void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change);
484 * @brief This method is called when the control is accessibility activated.
486 * Derived classes should override this to perform custom accessibility activation.
488 * @return true if this control can perform accessibility activation
490 virtual bool OnAccessibilityActivated();
493 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
497 * @param[in] gesture The pan gesture
498 * @return true if the pan gesture has been consumed by this control
500 virtual bool OnAccessibilityPan(PanGesture gesture);
503 * @brief This method should be overridden by deriving classes when they wish to respond
504 * the accessibility up and down action (i.e. value change of slider control).
507 * @param[in] isIncrease Whether the value should be increased or decreased
508 * @return true if the value changed action has been consumed by this control
510 virtual bool OnAccessibilityValueChange(bool isIncrease);
513 * @brief This method should be overridden by deriving classes when they wish to respond
514 * the accessibility zoom action.
517 * @return true if the zoom action has been consumed by this control
519 virtual bool OnAccessibilityZoom();
522 * @brief This method should be overriden by deriving classes when they wish to be
523 * represented by a custom Accessible object implementation.
525 * The AT-SPI infrastructure is responsible for destroying the returned object.
527 * Currently, this method is called at most once in a given Control's lifetime, when
528 * GetAccessibleObject() is called for the first time. A future version of the
529 * AT-SPI infrastructure, however, may delete the Accessible object and request a new
530 * one to be created (by calling this method) multiple times, for example during
531 * scene connection and disconnection.
533 * @return The newly created Accessible object
535 * @see GetAccessibleObject()
537 virtual DevelControl::ControlAccessible* CreateAccessibleObject();
542 * @brief Called when the control gains key input focus.
544 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
547 virtual void OnKeyInputFocusGained();
550 * @brief Called when the control loses key input focus.
552 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
555 virtual void OnKeyInputFocusLost();
558 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
560 * A control needs to override this function in order to support two dimensional keyboard navigation.
562 * @param[in] currentFocusedActor The current focused actor
563 * @param[in] direction The direction to move the focus towards
564 * @param[in] loopEnabled Whether the focus movement should be looped within the control
565 * @return The next keyboard focusable actor in this control or an empty handle if no actor can be focused
567 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
570 * @brief Informs this control that its chosen focusable actor will be focused.
572 * This allows the application to perform any actions if wishes
573 * before the focus is actually moved to the chosen actor.
576 * @param[in] commitedFocusableActor The commited focusable actor
578 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
581 * @brief This method is called when the control has enter pressed on it.
583 * Derived classes should override this to perform custom actions.
585 * @return true if this control supported this action
587 virtual bool OnKeyboardEnter();
590 * @brief Called after a key-event is received by the actor that has had its focus set.
593 * @param[in] event The Key Event
594 * @return True if the event should be consumed
596 virtual bool OnKeyEvent(const KeyEvent& event);
601 * @brief Called whenever a pinch gesture is detected on this control.
603 * This can be overridden by deriving classes when pinch detection
604 * is enabled. The default behaviour is to scale the control by the
608 * @param[in] pinch The pinch gesture
609 * @note If overridden, then the default behavior will not occur.
610 * @note Pinch detection should be enabled via EnableGestureDetection().
611 * @see EnableGestureDetection
613 virtual void OnPinch(const PinchGesture& pinch);
616 * @brief Called whenever a pan gesture is detected on this control.
618 * This should be overridden by deriving classes when pan detection
622 * @param[in] pan The pan gesture
623 * @note There is no default behavior with panning.
624 * @note Pan detection should be enabled via EnableGestureDetection().
625 * @see EnableGestureDetection
627 virtual void OnPan(const PanGesture& pan);
630 * @brief Called whenever a tap gesture is detected on this control.
632 * This should be overridden by deriving classes when tap detection
636 * @param[in] tap The tap gesture
637 * @note There is no default behavior with a tap.
638 * @note Tap detection should be enabled via EnableGestureDetection().
639 * @see EnableGestureDetection
641 virtual void OnTap(const TapGesture& tap);
644 * @brief Called whenever a long press gesture is detected on this control.
646 * This should be overridden by deriving classes when long press
647 * detection is enabled.
650 * @param[in] longPress The long press gesture
651 * @note There is no default behaviour associated with a long press.
652 * @note Long press detection should be enabled via EnableGestureDetection().
653 * @see EnableGestureDetection
655 virtual void OnLongPress(const LongPressGesture& longPress);
657 // From ConnectionTrackerInterface
660 * @copydoc ConnectionTrackerInterface::SignalConnected
662 void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
665 * @copydoc ConnectionTrackerInterface::SignalDisconnected
667 void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
670 * @brief Retrieves the extension for this control.
673 * @return The extension if available, NULL otherwise
675 virtual Extension* GetControlExtension()
683 * @brief Make visual transition from source control to destination control about specific Visual.
684 * If both of source and destination control have same visual index, than generates information for the transition of this Control.
686 * @param[out] sourcePropertyMap Source property map to be applied on this Control.
687 * @param[out] destinationPropertyMap Destination property map to be applied on this Control.
688 * @param[in] source Source control of the animation.
689 * @param[in] destination Destination control of the animation.
690 * @param[in] visualIndex Property::Index to make animation.
692 void MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap, Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex);
695 * @brief Retrieves source and destination visual properties for the Transition of this Control.
696 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
697 * If a property value is different between source and destination Control,
698 * the property information of each Control will be included in sourceProperties and destinationProperties.
700 * @param[out] sourceProperties Source property list to be applied on this Control.
701 * @param[out] destinationProperties Destination property list to be applied on this Control.
702 * @param[in] source Source control of the animation.
703 * @param[in] destination Destination control of the animation.
705 * @note This method do not handle Actor properties.
706 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
708 virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
709 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
710 Dali::Toolkit::Control source,
711 Dali::Toolkit::Control destination)
716 * @brief Update visual properties.
717 * @param[in] properties Property list to be used to update visual properties of this Control.
719 virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties)
726 // Not copyable or movable
727 DALI_INTERNAL Control(const Control&) = delete; ///< Deleted copy constructor.
728 DALI_INTERNAL Control(Control&&) = delete; ///< Deleted move constructor.
729 DALI_INTERNAL Control& operator=(const Control&) = delete; ///< Deleted copy assignment operator.
730 DALI_INTERNAL Control& operator=(Control&&) = delete; ///< Deleted move assignment operator.
733 class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
741 * @brief Gets implementation from the handle.
745 * @return Implementation
746 * @pre handle is initialized and points to a control
748 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
751 * @brief Gets implementation from the handle.
755 * @return Implementation
756 * @pre Handle is initialized and points to a control.
758 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
760 } // namespace Internal
765 } // namespace Toolkit
769 #endif // DALI_TOOLKIT_CONTROL_IMPL_H