1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_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-toolkit/devel-api/controls/control-devel.h>
23 #include <dali/devel-api/adaptor-framework/accessibility.h>
24 #include <dali/public-api/object/property-notification.h>
25 #include <dali/public-api/object/type-registry.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
30 #include <dali-toolkit/internal/builder/dictionary.h>
31 #include <dali-toolkit/internal/builder/style.h>
32 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
33 #include <dali-toolkit/internal/visuals/visual-event-observer.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali-toolkit/public-api/visuals/visual-properties.h>
36 #include <dali/devel-api/common/owner-container.h>
37 #include <dali/integration-api/debug.h>
49 * Struct used to store Visual within the control, index is a unique key for each visual.
51 struct RegisteredVisual
53 Property::Index index;
54 Toolkit::Visual::Base visual;
58 RegisteredVisual(Property::Index aIndex, Toolkit::Visual::Base& aVisual, bool aEnabled, bool aPendingReplacement)
62 pending(aPendingReplacement)
67 typedef Dali::OwnerContainer<RegisteredVisual*> RegisteredVisualContainer;
70 * @brief Holds the Implementation for the internal control class
72 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
74 friend class Toolkit::DevelControl::ControlAccessible;
78 * @brief Retrieves the implementation of the internal control class.
79 * @param[in] internalControl A ref to the control whose internal implementation is required
80 * @return The internal implementation
82 static Control::Impl& Get(Internal::Control& internalControl);
85 * @copydoc Get( Internal::Control& )
87 static const Control::Impl& Get(const Internal::Control& internalControl);
91 * @param[in] controlImpl The control which owns this implementation
93 Impl(Control& controlImpl);
101 * @brief Called when a pinch is detected.
102 * @param[in] actor The actor the pinch occurred on
103 * @param[in] pinch The pinch gesture details
105 void PinchDetected(Actor actor, const PinchGesture& pinch);
108 * @brief Called when a pan is detected.
109 * @param[in] actor The actor the pan occurred on
110 * @param[in] pinch The pan gesture details
112 void PanDetected(Actor actor, const PanGesture& pan);
115 * @brief Called when a tap is detected.
116 * @param[in] actor The actor the tap occurred on
117 * @param[in] pinch The tap gesture details
119 void TapDetected(Actor actor, const TapGesture& tap);
122 * @brief Called when a long-press is detected.
123 * @param[in] actor The actor the long-press occurred on
124 * @param[in] pinch The long-press gesture details
126 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
129 * @brief Called when a resource is ready.
130 * @param[in] object The visual whose resources are ready
131 * @note Overriding method in Visual::EventObserver.
133 void ResourceReady(Visual::Base& object) override;
136 * @brief Called when an event occurs.
137 * @param[in] object The visual whose events occur
138 * @param[in] signalId The signal to emit. See Visual to find supported signals
139 * @note Overriding method in Visual::EventObserver.
141 void NotifyVisualEvent(Visual::Base& object, Property::Index signalId) override;
144 * @brief Called when the visual needs relayout request.
145 * @param[in] object The visual who requests relayout
147 void RelayoutRequest(Visual::Base& object) override;
150 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
152 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual);
155 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
157 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
160 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
162 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
165 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
167 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
170 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
172 void UnregisterVisual(Property::Index index);
175 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
177 Toolkit::Visual::Base GetVisual(Property::Index index) const;
180 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
182 void EnableVisual(Property::Index index, bool enable);
185 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
187 bool IsVisualEnabled(Property::Index index) const;
190 * @brief Stops observing the given visual.
191 * @param[in] visual The visual to stop observing
193 void StopObservingVisual(Toolkit::Visual::Base& visual);
196 * @brief Starts observing the given visual.
197 * @param[in] visual The visual to start observing
199 void StartObservingVisual(Toolkit::Visual::Base& visual);
202 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
204 Toolkit::Visual::ResourceStatus GetVisualResourceStatus(Property::Index index) const;
207 * @param[in,out] animation Handle to existing animation, or an empty handle that
208 * can be set to a New animation if createAnimation is true
209 * @param[in] transitionData The transition data describing the animation
210 * @param[in] createAnimation True if the animation should be created
212 void AddTransitions(Dali::Animation& animation,
213 const Toolkit::TransitionData& transitionData,
214 bool createAnimation = false);
217 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
219 Dali::Animation CreateTransition(const Toolkit::TransitionData& transitionData);
222 * @copydoc Dali::Toolkit::DevelControl::DoAction()
224 void DoAction(Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
227 * @copydoc Dali::Toolkit::DevelControl::DoActionExtension()
229 void DoActionExtension(Dali::Property::Index visualIndex, Dali::Property::Index actionId, Dali::Any attributes);
232 * @brief Function used to set control properties.
233 * @param[in] object The object whose property to set
234 * @param[in] index The index of the property to set
235 * @param[in] value The value of the property to set
237 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
240 * @brief Function used to retrieve the value of control properties.
241 * @param[in] object The object whose property to get
242 * @param[in] index The index of the property to get
243 * @return The value of the property
245 static Property::Value GetProperty(BaseObject* object, Property::Index index);
248 * @brief Sets the state of the control.
249 * @param[in] newState The state to set
250 * @param[in] withTransitions Whether to show a transition when changing to the new state
252 void SetState(DevelControl::State newState, bool withTransitions = true);
255 * @brief Sets the sub-state of the control.
256 * @param[in] newState The sub-state to set
257 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
259 void SetSubState(const std::string& subStateName, bool withTransitions = true);
262 * @brief Replaces visuals and properties from the old state to the new state.
263 * @param[in] oldState The old state
264 * @param[in] newState The new state
265 * @param[in] subState The current sub state
267 void ReplaceStateVisualsAndProperties(const StylePtr oldState, const StylePtr newState, const std::string& subState);
270 * @brief Removes a visual from the control's container.
271 * @param[in] visuals The container of visuals
272 * @param[in] visualName The name of the visual to remove
274 void RemoveVisual(RegisteredVisualContainer& visuals, const std::string& visualName);
277 * @brief Removes several visuals from the control's container.
278 * @param[in] visuals The container of visuals
279 * @param[in] removeVisuals The visuals to remove
281 void RemoveVisuals(RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals);
284 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
285 * @param[in] visuals The control's visual container
286 * @param[out] instancedProperties The instanced properties are added to this container
288 void CopyInstancedProperties(RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties);
291 * @brief On state change, ensures visuals are moved or created appropriately.
293 * Go through the list of visuals that are common to both states.
294 * If they are different types, or are both image types with different
295 * URLs, then the existing visual needs moving and the new visual needs creating
297 * @param[in] stateVisualsToChange The visuals to change
298 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
300 void RecreateChangedVisuals(Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties);
303 * @brief Whether the resource is ready
304 * @return True if the resource is read.
306 bool IsResourceReady() const;
309 * @copydoc CustomActorImpl::OnSceneDisconnection()
311 void OnSceneDisconnection();
314 * @brief Sets the margin.
315 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
317 void SetMargin(Extents margin);
320 * @brief Returns the value of margin
321 * @return The value of margin
323 Extents GetMargin() const;
326 * @brief Sets the padding.
327 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
329 void SetPadding(Extents padding);
332 * @brief Returns the value of padding
333 * @return The value of padding
335 Extents GetPadding() const;
338 * @brief Set the input method context.
339 * @param[in] inputMethodContext The input method context.
341 void SetInputMethodContext(InputMethodContext& inputMethodContext);
344 * @brief Filter an key event.
345 * @param[in] event The key to be filtered.
346 * @return True if the key handled, otherwise false.
348 bool FilterKeyEvent(const KeyEvent& event);
351 * @brief Adds accessibility attribute
352 * @param[in] key Attribute name to set
353 * @param[in] value Attribute value to set
355 * Attribute is added if not existed previously or updated
358 void AppendAccessibilityAttribute(const std::string& key, const std::string value);
361 * @brief Removes accessibility attribute
362 * @param[in] key Attribute name to remove
364 * Function does nothing if attribute doesn't exist.
366 void RemoveAccessibilityAttribute(const std::string& key);
369 * @brief Removes all accessibility attributes
371 void ClearAccessibilityAttributes();
374 * @brief Sets reading info type attributes
375 * @param[in] types info type attributes to set
377 * This function sets, which part of object will be read out
380 void SetAccessibilityReadingInfoType(const Dali::Accessibility::ReadingInfoTypes types);
383 * @brief Gets currently active reading info type attributes
385 Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
388 * @copydoc DevelControl::VisualEventSignal()
390 DevelControl::VisualEventSignalType& VisualEventSignal();
393 * @brief Sets the shadow with a property map.
394 * @param[in] map The shadow property map
396 void SetShadow(const Property::Map& map);
399 * @brief Clear the shadow.
404 * @copydoc DevelControl::GetVisualProperty()
406 Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
409 * @brief Retrieves source and destination visual properties for the Transition of this Control.
410 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
411 * If a property value is different between source and destination Control,
412 * the property information of each Control will be included in sourceProperties and destinationProperties.
414 * @param[out] sourceProperties Source property list to be applied on this Control.
415 * @param[out] destinationProperties Destination property list to be applied on this Control.
416 * @param[in] source Source control of the animation.
417 * @param[in] destination Destination control of the animation.
419 * @note This method do not handle Actor properties.
420 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
422 * This method triggers Control::OnCreateTransition().
424 void CreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
425 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
426 Dali::Toolkit::Control source,
427 Dali::Toolkit::Control destination);
430 * @brief Update visual properties.
431 * @param[in] properties Property list to be used to update visual properties of this Control.
433 * @note This method triggers Control::OnUpdateVisualProperties().
435 void UpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties);
438 * @copydoc Dali::Toolkit::Internal::Control::GetAccessibleObject()
440 Toolkit::DevelControl::ControlAccessible* GetAccessibleObject();
444 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
450 DISABLED = 0, ///< Visual disabled.
451 ENABLED = 1 ///< Visual enabled.
456 * Used as an alternative to boolean so that it is obvious whether a visual's depth value has been set or not by the caller.
458 struct DepthIndexValue
462 NOT_SET = 0, ///< Visual depth value not set by caller.
463 SET = 1 ///< Visual depth value set by caller.
468 * @brief Adds the visual to the list of registered visuals.
469 * @param[in] index The Property index of the visual, used to reference visual
470 * @param[in,out] visual The visual to register, which can be altered in this function
471 * @param[in] enabled false if derived class wants to control when visual is set on stage
472 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
473 * @param[in] depthIndex The visual's depth-index is set to this
475 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
476 * occur once the replacement visual is ready (loaded).
478 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0);
481 * @brief Emits the resource ready signal.
483 void EmitResourceReadySignal();
486 * @brief Callbacks called on idle.
488 void OnIdleCallback();
491 * @brief Checks highlighted object geometry if it is showing or not
493 void CheckHighlightedObjectGeometry();
496 * @brief Register property notification to check highlighted object position
498 void RegisterAccessibilityPositionPropertyNotification();
501 * @brief Remove property notification added by RegisterPropertyNotification
503 void UnregisterAccessibilityPositionPropertyNotification();
506 Control& mControlImpl;
507 DevelControl::State mState;
508 std::string mSubStateName;
509 Property::Map mAccessibilityAttributes;
511 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
512 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
513 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
514 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
515 int mClockwiseFocusableActorId; ///< Actor ID of Clockwise focusable control.
516 int mCounterClockwiseFocusableActorId; ///< Actor ID of Counter clockwise focusable control.
518 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
519 std::string mStyleName;
520 Vector4 mBackgroundColor; ///< The color of the background visual
521 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
522 Extents mMargin; ///< The margin values
523 Extents mPadding; ///< The padding values
524 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
525 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
526 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
527 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
528 DevelControl::VisualEventSignalType mVisualEventSignal;
531 Toolkit::DevelControl::AccessibilityActivateSignalType mAccessibilityActivateSignal;
532 Toolkit::DevelControl::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
533 Toolkit::DevelControl::AccessibilityReadingPausedSignalType mAccessibilityReadingPausedSignal;
534 Toolkit::DevelControl::AccessibilityReadingResumedSignalType mAccessibilityReadingResumedSignal;
535 Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
536 Toolkit::DevelControl::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
538 Toolkit::DevelControl::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
539 Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
540 Toolkit::DevelControl::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
542 std::string mAccessibilityName;
543 std::string mAccessibilityDescription;
544 std::string mAccessibilityTranslationDomain;
545 std::string mAutomationId;
547 bool mAccessibilityHighlightable = false;
548 bool mAccessibilityHidden = false;
550 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
552 std::map<Dali::Accessibility::RelationType, std::set<Accessibility::Accessible*>> mAccessibilityRelations;
553 std::unique_ptr<Toolkit::DevelControl::ControlAccessible> mAccessibleObject;
556 PinchGestureDetector mPinchGestureDetector;
557 PanGestureDetector mPanGestureDetector;
558 TapGestureDetector mTapGestureDetector;
559 LongPressGestureDetector mLongPressGestureDetector;
564 InputMethodContext mInputMethodContext;
565 CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
567 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
568 bool mIsKeyboardNavigationSupported : 1; ///< Stores whether keyboard navigation is supported by the control.
569 bool mIsKeyboardFocusGroup : 1; ///< Stores whether the control is a focus group.
570 bool mIsEmittingResourceReadySignal : 1; ///< True during ResourceReady().
571 bool mNeedToEmitResourceReady : 1; ///< True if need to emit the resource ready signal again.
572 bool mDispatchKeyEvents : 1; ///< Whether the actor emits key event signals
574 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
576 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
577 static const PropertyRegistration PROPERTY_1;
578 static const PropertyRegistration PROPERTY_2;
579 static const PropertyRegistration PROPERTY_3;
580 static const PropertyRegistration PROPERTY_4;
581 static const PropertyRegistration PROPERTY_5;
582 static const PropertyRegistration PROPERTY_6;
583 static const PropertyRegistration PROPERTY_7;
584 static const PropertyRegistration PROPERTY_8;
585 static const PropertyRegistration PROPERTY_9;
586 static const PropertyRegistration PROPERTY_10;
587 static const PropertyRegistration PROPERTY_11;
588 static const PropertyRegistration PROPERTY_12;
589 static const PropertyRegistration PROPERTY_13;
590 static const PropertyRegistration PROPERTY_14;
591 static const PropertyRegistration PROPERTY_15;
592 static const PropertyRegistration PROPERTY_16;
593 static const PropertyRegistration PROPERTY_17;
594 static const PropertyRegistration PROPERTY_18;
595 static const PropertyRegistration PROPERTY_19;
596 static const PropertyRegistration PROPERTY_20;
597 static const PropertyRegistration PROPERTY_21;
598 static const PropertyRegistration PROPERTY_22;
599 static const PropertyRegistration PROPERTY_23;
600 static const PropertyRegistration PROPERTY_24;
601 static const PropertyRegistration PROPERTY_25;
602 static const PropertyRegistration PROPERTY_26;
605 // Accessibility - notification for highlighted object to check if it is showing.
606 bool mIsAccessibilityPositionPropertyNotificationSet{false};
607 Dali::PropertyNotification mAccessibilityPositionNotification;
608 Dali::Accessibility::ScreenRelativeMoveType mAccessibilityLastScreenRelativeMoveType{Accessibility::ScreenRelativeMoveType::OUTSIDE};
611 } // namespace Internal
613 } // namespace Toolkit
617 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H