1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_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-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 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
146 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual);
149 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
151 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
154 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
156 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
159 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
161 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
164 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
166 void UnregisterVisual(Property::Index index);
169 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
171 Toolkit::Visual::Base GetVisual(Property::Index index) const;
174 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
176 void EnableVisual(Property::Index index, bool enable);
179 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
181 bool IsVisualEnabled(Property::Index index) const;
184 * @brief Stops observing the given visual.
185 * @param[in] visual The visual to stop observing
187 void StopObservingVisual(Toolkit::Visual::Base& visual);
190 * @brief Starts observing the given visual.
191 * @param[in] visual The visual to start observing
193 void StartObservingVisual(Toolkit::Visual::Base& visual);
196 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
198 Toolkit::Visual::ResourceStatus GetVisualResourceStatus(Property::Index index) const;
201 * @param[in,out] animation Handle to existing animation, or an empty handle that
202 * can be set to a New animation if createAnimation is true
203 * @param[in] transitionData The transition data describing the animation
204 * @param[in] createAnimation True if the animation should be created
206 void AddTransitions(Dali::Animation& animation,
207 const Toolkit::TransitionData& transitionData,
208 bool createAnimation = false);
211 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
213 Dali::Animation CreateTransition(const Toolkit::TransitionData& transitionData);
216 * @copydoc Dali::Toolkit::DevelControl::DoAction()
218 void DoAction(Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
221 * @brief Function used to set control properties.
222 * @param[in] object The object whose property to set
223 * @param[in] index The index of the property to set
224 * @param[in] value The value of the property to set
226 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
229 * @brief Function used to retrieve the value of control properties.
230 * @param[in] object The object whose property to get
231 * @param[in] index The index of the property to get
232 * @return The value of the property
234 static Property::Value GetProperty(BaseObject* object, Property::Index index);
237 * @brief Sets the state of the control.
238 * @param[in] newState The state to set
239 * @param[in] withTransitions Whether to show a transition when changing to the new state
241 void SetState(DevelControl::State newState, bool withTransitions = true);
244 * @brief Sets the sub-state of the control.
245 * @param[in] newState The sub-state to set
246 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
248 void SetSubState(const std::string& subStateName, bool withTransitions = true);
251 * @brief Replaces visuals and properties from the old state to the new state.
252 * @param[in] oldState The old state
253 * @param[in] newState The new state
254 * @param[in] subState The current sub state
256 void ReplaceStateVisualsAndProperties(const StylePtr oldState, const StylePtr newState, const std::string& subState);
259 * @brief Removes a visual from the control's container.
260 * @param[in] visuals The container of visuals
261 * @param[in] visualName The name of the visual to remove
263 void RemoveVisual(RegisteredVisualContainer& visuals, const std::string& visualName);
266 * @brief Removes several visuals from the control's container.
267 * @param[in] visuals The container of visuals
268 * @param[in] removeVisuals The visuals to remove
270 void RemoveVisuals(RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals);
273 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
274 * @param[in] visuals The control's visual container
275 * @param[out] instancedProperties The instanced properties are added to this container
277 void CopyInstancedProperties(RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties);
280 * @brief On state change, ensures visuals are moved or created appropriately.
282 * Go through the list of visuals that are common to both states.
283 * If they are different types, or are both image types with different
284 * URLs, then the existing visual needs moving and the new visual needs creating
286 * @param[in] stateVisualsToChange The visuals to change
287 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
289 void RecreateChangedVisuals(Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties);
292 * @brief Whether the resource is ready
293 * @return True if the resource is read.
295 bool IsResourceReady() const;
298 * @copydoc CustomActorImpl::OnSceneDisconnection()
300 void OnSceneDisconnection();
303 * @brief Sets the margin.
304 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
306 void SetMargin(Extents margin);
309 * @brief Returns the value of margin
310 * @return The value of margin
312 Extents GetMargin() const;
315 * @brief Sets the padding.
316 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
318 void SetPadding(Extents padding);
321 * @brief Returns the value of padding
322 * @return The value of padding
324 Extents GetPadding() const;
327 * @brief Set the input method context.
328 * @param[in] inputMethodContext The input method context.
330 void SetInputMethodContext(InputMethodContext& inputMethodContext);
333 * @brief Filter an key event.
334 * @param[in] event The key to be filtered.
335 * @return True if the key handled, otherwise false.
337 bool FilterKeyEvent(const KeyEvent& event);
340 * @brief Adds accessibility attribute
341 * @param[in] key Attribute name to set
342 * @param[in] value Attribute value to set
344 * Attribute is added if not existed previously or updated
347 void AppendAccessibilityAttribute(const std::string& key, const std::string value);
350 * @brief Removes accessibility attribute
351 * @param[in] key Attribute name to remove
353 * Function does nothing if attribute doesn't exist.
355 void RemoveAccessibilityAttribute(const std::string& key);
358 * @brief Removes all accessibility attributes
360 void ClearAccessibilityAttributes();
363 * @brief Sets reading info type attributes
364 * @param[in] types info type attributes to set
366 * This function sets, which part of object will be read out
369 void SetAccessibilityReadingInfoType(const Dali::Accessibility::ReadingInfoTypes types);
372 * @brief Gets currently active reading info type attributes
374 Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
377 * @copydoc DevelControl::VisualEventSignal()
379 DevelControl::VisualEventSignalType& VisualEventSignal();
382 * @brief Sets the shadow with a property map.
383 * @param[in] map The shadow property map
385 void SetShadow(const Property::Map& map);
388 * @brief Clear the shadow.
393 * @copydoc DevelControl::GetVisualProperty()
395 Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
398 * @brief Retrieves source and destination visual properties for the Transition of this Control.
399 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
400 * If a property value is different between source and destination Control,
401 * the property information of each Control will be included in sourceProperties and destinationProperties.
403 * @param[out] sourceProperties Source property list to be applied on this Control.
404 * @param[out] destinationProperties Destination property list to be applied on this Control.
405 * @param[in] source Source control of the animation.
406 * @param[in] destination Destination control of the animation.
408 * @note This method do not handle Actor properties.
409 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
411 * This method triggers Control::OnCreateTransition().
413 void CreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
414 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
415 Dali::Toolkit::Control source, Dali::Toolkit::Control destination);
418 * @brief Update visual properties.
419 * @param[in] properties Property list to be used to update visual properties of this Control.
421 * @note This method triggers Control::OnUpdateVisualProperties().
423 void UpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties);
426 * @brief Gets the current control's accessible object.
428 * @return The handle to Accessible object
430 Dali::Accessibility::Accessible* GetAccessibilityObject();
433 * @brief Gets Accessible object handle.
435 * The method acquires Accessible handle from Actor object
436 * @param actor Actor object
437 * @return The handle to Accessible object
439 static Dali::Accessibility::Accessible* GetAccessibilityObject(Dali::Actor actor);
443 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
449 DISABLED = 0, ///< Visual disabled.
450 ENABLED = 1 ///< Visual enabled.
455 * 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.
457 struct DepthIndexValue
461 NOT_SET = 0, ///< Visual depth value not set by caller.
462 SET = 1 ///< Visual depth value set by caller.
467 * @brief Adds the visual to the list of registered visuals.
468 * @param[in] index The Property index of the visual, used to reference visual
469 * @param[in,out] visual The visual to register, which can be altered in this function
470 * @param[in] enabled false if derived class wants to control when visual is set on stage
471 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
472 * @param[in] depthIndex The visual's depth-index is set to this
474 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
475 * occur once the replacement visual is ready (loaded).
477 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0);
480 * @brief Emits the resource ready signal.
482 void EmitResourceReadySignal();
485 * @brief Callbacks called on idle.
487 void OnIdleCallback();
490 * @brief Checks highlighted object geometry if it is showing or not
492 void CheckHighlightedObjectGeometry();
495 * @brief Register property notification to check highlighted object position
497 void RegisterAccessibilityPositionPropertyNotification();
500 * @brief Remove property notification added by RegisterPropertyNotification
502 void UnregisterAccessibilityPositionPropertyNotification();
505 Control& mControlImpl;
506 DevelControl::State mState;
507 std::string mSubStateName;
508 Property::Map mAccessibilityAttributes;
510 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
511 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
512 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
513 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
515 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
516 std::string mStyleName;
517 Vector4 mBackgroundColor; ///< The color of the background visual
518 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
519 Extents mMargin; ///< The margin values
520 Extents mPadding; ///< The padding values
521 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
522 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
523 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
524 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
525 DevelControl::VisualEventSignalType mVisualEventSignal;
528 Toolkit::DevelControl::AccessibilityActivateSignalType mAccessibilityActivateSignal;
529 Toolkit::DevelControl::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
530 Toolkit::DevelControl::AccessibilityReadingPausedSignalType mAccessibilityReadingPausedSignal;
531 Toolkit::DevelControl::AccessibilityReadingResumedSignalType mAccessibilityReadingResumedSignal;
532 Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
533 Toolkit::DevelControl::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
535 Toolkit::DevelControl::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
536 Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
537 Toolkit::DevelControl::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
539 std::string mAccessibilityName;
540 std::string mAccessibilityDescription;
541 std::string mAccessibilityTranslationDomain;
543 bool mAccessibilityHighlightable = false;
544 bool mAccessibilityHidden = false;
546 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
548 std::map<Dali::Accessibility::RelationType, std::set<Accessibility::Accessible*>> mAccessibilityRelations;
549 std::function<std::unique_ptr<Dali::Accessibility::Accessible>(Actor)> mAccessibilityConstructor;
550 std::unique_ptr<Dali::Accessibility::Accessible> mAccessibilityObject;
553 PinchGestureDetector mPinchGestureDetector;
554 PanGestureDetector mPanGestureDetector;
555 TapGestureDetector mTapGestureDetector;
556 LongPressGestureDetector mLongPressGestureDetector;
561 InputMethodContext mInputMethodContext;
562 CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
564 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
565 bool mIsKeyboardNavigationSupported : 1; ///< Stores whether keyboard navigation is supported by the control.
566 bool mIsKeyboardFocusGroup : 1; ///< Stores whether the control is a focus group.
567 bool mIsEmittingResourceReadySignal : 1; ///< True during ResourceReady().
568 bool mNeedToEmitResourceReady : 1; ///< True if need to emit the resource ready signal again.
569 bool mDispatchKeyEvents : 1; ///< Whether the actor emits key event signals
571 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
573 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
574 static const PropertyRegistration PROPERTY_1;
575 static const PropertyRegistration PROPERTY_2;
576 static const PropertyRegistration PROPERTY_3;
577 static const PropertyRegistration PROPERTY_4;
578 static const PropertyRegistration PROPERTY_5;
579 static const PropertyRegistration PROPERTY_6;
580 static const PropertyRegistration PROPERTY_7;
581 static const PropertyRegistration PROPERTY_8;
582 static const PropertyRegistration PROPERTY_9;
583 static const PropertyRegistration PROPERTY_10;
584 static const PropertyRegistration PROPERTY_11;
585 static const PropertyRegistration PROPERTY_12;
586 static const PropertyRegistration PROPERTY_13;
587 static const PropertyRegistration PROPERTY_14;
588 static const PropertyRegistration PROPERTY_15;
589 static const PropertyRegistration PROPERTY_16;
590 static const PropertyRegistration PROPERTY_17;
591 static const PropertyRegistration PROPERTY_18;
592 static const PropertyRegistration PROPERTY_19;
593 static const PropertyRegistration PROPERTY_20;
594 static const PropertyRegistration PROPERTY_21;
595 static const PropertyRegistration PROPERTY_22;
596 static const PropertyRegistration PROPERTY_23;
599 // Accessibility - notification for highlighted object to check if it is showing.
600 bool mIsAccessibilityPositionPropertyNotificationSet{false};
601 Dali::PropertyNotification mAccessibilityPositionNotification;
602 Dali::Accessibility::ScreenRelativeMoveType mAccessibilityLastScreenRelativeMoveType{Accessibility::ScreenRelativeMoveType::OUTSIDE};
605 } // namespace Internal
607 } // namespace Toolkit
611 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H