1 #ifndef DALI_TOOLKIT_CONTROL_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_IMPL_H
5 * Copyright (c) 2022 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
56 * @brief This is the internal base class for all controls.
58 * It will provide some common functionality required by all controls.
59 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
60 * be disconnected automatically when the control is destroyed.
63 class DALI_TOOLKIT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
66 class Extension; ///< Forward declare future extension interface
68 // Creation & Destruction
70 * @brief Creates a new ControlImpl instance that does not require touch by default.
72 * If touch is required, then the user can connect to this class' touch signal.
74 * @return A handle to the ControlImpl instance
76 static Toolkit::Control New();
80 * @brief Virtual destructor.
89 * @copydoc Dali::Toolkit::Control::SetStyleName
91 void SetStyleName(const std::string& styleName);
94 * @copydoc Dali::Toolkit::Control::GetStyleName
96 const std::string& GetStyleName() const;
101 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
103 void SetBackgroundColor(const Vector4& color);
106 * @brief Sets the background with a property map.
109 * @param[in] map The background property map
111 void SetBackground(const Property::Map& map);
114 * @copydoc Dali::Toolkit::Control::ClearBackground
116 void ClearBackground();
119 * @brief Called when resources of control are ready.
120 * @param[in] relayoutRequest True to request relayout
122 void SetResourceReady(bool relayoutRequest);
127 * @brief Gets the Accessible object that represents this control.
129 * This method calls CreateAccessibleObject() if necessary, so a non-null return is expected.
131 * @return The Accessible object
133 * @see CreateAccessibleObject()
135 Toolkit::DevelControl::ControlAccessible* GetAccessibleObject();
140 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
142 * Gesture detection can be enabled one at a time or in bitwise format as shown:
144 * EnableGestureDetection(GestureType::Value(GestureType::PINCH | GestureType::TAP | GestureType::PAN));
147 * @param[in] type The gesture type(s) to enable
149 void EnableGestureDetection(GestureType::Value type);
152 * @brief Allows deriving classes to disable any of the gesture detectors.
154 * Like EnableGestureDetection, this can also be called using bitwise or.
156 * @param[in] type The gesture type(s) to disable
157 * @see EnableGetureDetection
159 void DisableGestureDetection(GestureType::Value type);
162 * @brief If deriving classes wish to fine tune pinch gesture
163 * detection, then they can access the gesture detector through this
164 * API and modify the detection.
167 * @return The pinch gesture detector
168 * @pre Pinch detection should have been enabled via EnableGestureDetection().
169 * @see EnableGestureDetection
171 PinchGestureDetector GetPinchGestureDetector() const;
174 * @brief If deriving classes wish to fine tune pan gesture
175 * detection, then they can access the gesture detector through this
176 * API and modify the detection.
179 * @return The pan gesture detector
180 * @pre Pan detection should have been enabled via EnableGestureDetection().
181 * @see EnableGestureDetection
183 PanGestureDetector GetPanGestureDetector() const;
186 * @brief If deriving classes wish to fine tune tap gesture
187 * detection, then they can access the gesture detector through this
188 * API and modify the detection.
191 * @return The tap gesture detector
192 * @pre Tap detection should have been enabled via EnableGestureDetection().
193 * @see EnableGestureDetection
195 TapGestureDetector GetTapGestureDetector() const;
198 * @brief If deriving classes wish to fine tune long press gesture
199 * detection, then they can access the gesture detector through this
200 * API and modify the detection.
203 * @return The long press gesture detector
204 * @pre Long press detection should have been enabled via EnableGestureDetection().
205 * @see EnableGestureDetection
207 LongPressGestureDetector GetLongPressGestureDetector() const;
209 // Keyboard Navigation
212 * @brief Sets whether this control supports two dimensional
213 * keyboard navigation (i.e. whether it knows how to handle the
214 * keyboard focus movement between its child actors).
216 * The control doesn't support it by default.
218 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation
220 void SetKeyboardNavigationSupport(bool isSupported);
223 * @brief Gets whether this control supports two dimensional keyboard navigation.
226 * @return true if this control supports two dimensional keyboard navigation
228 bool IsKeyboardNavigationSupported();
233 * @copydoc Toolkit::Control::SetKeyInputFocus()
235 void SetKeyInputFocus();
238 * @copydoc Toolkit::Control::HasKeyInputFocus()
240 bool HasKeyInputFocus();
243 * @copydoc Toolkit::Control::ClearKeyInputFocus()
245 void ClearKeyInputFocus();
250 * @brief Sets whether this control is a focus group for keyboard navigation.
252 * (i.e. the scope of keyboard focus movement
253 * can be limited to its child actors). The control is not a focus group by default.
255 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation
257 void SetAsKeyboardFocusGroup(bool isFocusGroup);
260 * @brief Gets whether this control is a focus group for keyboard navigation.
263 * @return true if this control is set as a focus group for keyboard navigation
265 bool IsKeyboardFocusGroup();
269 * @brief Called by the AccessibilityManager to activate the Control.
272 DALI_INTERNAL void AccessibilityActivate();
275 * @brief Called by the KeyboardFocusManager.
278 DALI_INTERNAL void KeyboardEnter();
285 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
287 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
290 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
292 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
295 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
297 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
301 * @brief Called by the KeyInputFocusManager to emit key event signals.
304 * @param[in] event The key event
305 * @return True if the event was consumed
307 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
310 protected: // For derived classes to call
312 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal.
314 * Should be called last by the control after it acts on the Input Focus change.
317 * @param[in] focusGained True if gained, False if lost
319 void EmitKeyInputFocusSignal(bool focusGained);
321 protected: // From CustomActorImpl
323 * @copydoc CustomActorImpl::OnSceneConnection()
324 * @note If overridden, then an up-call to Control::OnSceneConnection MUST be made at the end.
326 void OnSceneConnection(int depth) override;
329 * @copydoc CustomActorImpl::OnSceneDisconnection()
330 * @note If overridden, then an up-call to Control::OnSceneDisconnection MUST be made at the end.
332 void OnSceneDisconnection() override;
335 * @copydoc CustomActorImpl::OnChildAdd()
336 * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the end.
338 void OnChildAdd(Actor& child) override;
341 * @copydoc CustomActorImpl::OnChildRemove()
342 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
344 void OnChildRemove(Actor& child) override;
347 * @copydoc CustomActorImpl::OnPropertySet()
348 * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
350 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
353 * @copydoc CustomActorImpl::OnSizeSet()
354 * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the end.
356 void OnSizeSet(const Vector3& targetSize) override;
359 * @copydoc CustomActorImpl::OnSizeAnimation()
360 * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the end.
362 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
365 * @copydoc CustomActorImpl::OnRelayout()
367 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
370 * @copydoc CustomActorImpl::OnSetResizePolicy()
372 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
375 * @copydoc CustomActorImpl::GetNaturalSize()
377 Vector3 GetNaturalSize() override;
380 * @copydoc CustomActorImpl::CalculateChildSize()
382 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
385 * @copydoc CustomActorImpl::GetHeightForWidth()
387 float GetHeightForWidth(float width) override;
390 * @copydoc CustomActorImpl::GetWidthForHeight()
392 float GetWidthForHeight(float height) override;
395 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
397 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
400 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
402 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
405 * @copydoc CustomActorImpl::OnLayoutNegotiated()
407 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
409 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,
693 Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex);
696 * @brief Retrieves source and destination visual properties for the Transition of this Control.
697 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
698 * If a property value is different between source and destination Control,
699 * the property information of each Control will be included in sourceProperties and destinationProperties.
701 * @param[out] sourceProperties Source property list to be applied on this Control.
702 * @param[out] destinationProperties Destination property list to be applied on this Control.
703 * @param[in] source Source control of the animation.
704 * @param[in] destination Destination control of the animation.
706 * @note This method do not handle Actor properties.
707 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
709 virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
710 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
711 Dali::Toolkit::Control source,
712 Dali::Toolkit::Control destination)
717 * @brief Update visual properties.
718 * @param[in] properties Property list to be used to update visual properties of this Control.
720 virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties)
727 // Not copyable or movable
728 DALI_INTERNAL Control(const Control&) = delete; ///< Deleted copy constructor.
729 DALI_INTERNAL Control(Control&&) = delete; ///< Deleted move constructor.
730 DALI_INTERNAL Control& operator=(const Control&) = delete; ///< Deleted copy assignment operator.
731 DALI_INTERNAL Control& operator=(Control&&) = delete; ///< Deleted move assignment operator.
734 class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the Controls Impl
742 * @brief Gets implementation from the handle.
746 * @return Implementation
747 * @pre handle is initialized and points to a control
749 DALI_TOOLKIT_API Internal::Control& GetImplementation(Dali::Toolkit::Control& handle);
752 * @brief Gets implementation from the handle.
756 * @return Implementation
757 * @pre Handle is initialized and points to a control.
759 DALI_TOOLKIT_API const Internal::Control& GetImplementation(const Dali::Toolkit::Control& handle);
761 } // namespace Internal
766 } // namespace Toolkit
770 #endif // DALI_TOOLKIT_CONTROL_IMPL_H