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>
47 * Struct used to store Visual within the control, index is a unique key for each visual.
49 struct RegisteredVisual
51 Property::Index index;
52 Toolkit::Visual::Base visual;
56 RegisteredVisual(Property::Index aIndex, Toolkit::Visual::Base& aVisual, bool aEnabled, bool aPendingReplacement)
60 pending(aPendingReplacement)
65 typedef Dali::OwnerContainer<RegisteredVisual*> RegisteredVisualContainer;
68 * @brief Holds the Implementation for the internal control class
70 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
72 friend class Toolkit::DevelControl::AccessibleImpl;
76 * @brief Retrieves the implementation of the internal control class.
77 * @param[in] internalControl A ref to the control whose internal implementation is required
78 * @return The internal implementation
80 static Control::Impl& Get(Internal::Control& internalControl);
83 * @copydoc Get( Internal::Control& )
85 static const Control::Impl& Get(const Internal::Control& internalControl);
89 * @param[in] controlImpl The control which owns this implementation
91 Impl(Control& controlImpl);
99 * @brief Called when a pinch is detected.
100 * @param[in] actor The actor the pinch occurred on
101 * @param[in] pinch The pinch gesture details
103 void PinchDetected(Actor actor, const PinchGesture& pinch);
106 * @brief Called when a pan is detected.
107 * @param[in] actor The actor the pan occurred on
108 * @param[in] pinch The pan gesture details
110 void PanDetected(Actor actor, const PanGesture& pan);
113 * @brief Called when a tap is detected.
114 * @param[in] actor The actor the tap occurred on
115 * @param[in] pinch The tap gesture details
117 void TapDetected(Actor actor, const TapGesture& tap);
120 * @brief Called when a long-press is detected.
121 * @param[in] actor The actor the long-press occurred on
122 * @param[in] pinch The long-press gesture details
124 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
127 * @brief Called when a resource is ready.
128 * @param[in] object The visual whose resources are ready
129 * @note Overriding method in Visual::EventObserver.
131 void ResourceReady(Visual::Base& object) override;
134 * @brief Called when an event occurs.
135 * @param[in] object The visual whose events occur
136 * @param[in] signalId The signal to emit. See Visual to find supported signals
137 * @note Overriding method in Visual::EventObserver.
139 void NotifyVisualEvent(Visual::Base& object, Property::Index signalId) override;
142 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
144 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual);
147 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
149 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
152 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
154 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
157 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
159 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
162 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
164 void UnregisterVisual(Property::Index index);
167 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
169 Toolkit::Visual::Base GetVisual(Property::Index index) const;
172 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
174 void EnableVisual(Property::Index index, bool enable);
177 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
179 bool IsVisualEnabled(Property::Index index) const;
182 * @brief Stops observing the given visual.
183 * @param[in] visual The visual to stop observing
185 void StopObservingVisual(Toolkit::Visual::Base& visual);
188 * @brief Starts observing the given visual.
189 * @param[in] visual The visual to start observing
191 void StartObservingVisual(Toolkit::Visual::Base& visual);
194 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
196 Toolkit::Visual::ResourceStatus GetVisualResourceStatus(Property::Index index) const;
199 * @param[in,out] animation Handle to existing animation, or an empty handle that
200 * can be set to a New animation if createAnimation is true
201 * @param[in] transitionData The transition data describing the animation
202 * @param[in] createAnimation True if the animation should be created
204 void AddTransitions(Dali::Animation& animation,
205 const Toolkit::TransitionData& transitionData,
206 bool createAnimation = false);
209 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
211 Dali::Animation CreateTransition(const Toolkit::TransitionData& transitionData);
214 * @copydoc Dali::Toolkit::DevelControl::DoAction()
216 void DoAction(Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
219 * @brief Function used to set control properties.
220 * @param[in] object The object whose property to set
221 * @param[in] index The index of the property to set
222 * @param[in] value The value of the property to set
224 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
227 * @brief Function used to retrieve the value of control properties.
228 * @param[in] object The object whose property to get
229 * @param[in] index The index of the property to get
230 * @return The value of the property
232 static Property::Value GetProperty(BaseObject* object, Property::Index index);
235 * @brief Sets the state of the control.
236 * @param[in] newState The state to set
237 * @param[in] withTransitions Whether to show a transition when changing to the new state
239 void SetState(DevelControl::State newState, bool withTransitions = true);
242 * @brief Sets the sub-state of the control.
243 * @param[in] newState The sub-state to set
244 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
246 void SetSubState(const std::string& subStateName, bool withTransitions = true);
249 * @brief Replaces visuals and properties from the old state to the new state.
250 * @param[in] oldState The old state
251 * @param[in] newState The new state
252 * @param[in] subState The current sub state
254 void ReplaceStateVisualsAndProperties(const StylePtr oldState, const StylePtr newState, const std::string& subState);
257 * @brief Removes a visual from the control's container.
258 * @param[in] visuals The container of visuals
259 * @param[in] visualName The name of the visual to remove
261 void RemoveVisual(RegisteredVisualContainer& visuals, const std::string& visualName);
264 * @brief Removes several visuals from the control's container.
265 * @param[in] visuals The container of visuals
266 * @param[in] removeVisuals The visuals to remove
268 void RemoveVisuals(RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals);
271 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
272 * @param[in] visuals The control's visual container
273 * @param[out] instancedProperties The instanced properties are added to this container
275 void CopyInstancedProperties(RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties);
278 * @brief On state change, ensures visuals are moved or created appropriately.
280 * Go through the list of visuals that are common to both states.
281 * If they are different types, or are both image types with different
282 * URLs, then the existing visual needs moving and the new visual needs creating
284 * @param[in] stateVisualsToChange The visuals to change
285 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
287 void RecreateChangedVisuals(Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties);
290 * @brief Whether the resource is ready
291 * @return True if the resource is read.
293 bool IsResourceReady() const;
296 * @copydoc CustomActorImpl::OnSceneDisconnection()
298 void OnSceneDisconnection();
301 * @brief Sets the margin.
302 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
304 void SetMargin(Extents margin);
307 * @brief Returns the value of margin
308 * @return The value of margin
310 Extents GetMargin() const;
313 * @brief Sets the padding.
314 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
316 void SetPadding(Extents padding);
319 * @brief Returns the value of padding
320 * @return The value of padding
322 Extents GetPadding() const;
325 * @brief Set the input method context.
326 * @param[in] inputMethodContext The input method context.
328 void SetInputMethodContext(InputMethodContext& inputMethodContext);
331 * @brief Filter an key event.
332 * @param[in] event The key to be filtered.
333 * @return True if the key handled, otherwise false.
335 bool FilterKeyEvent(const KeyEvent& event);
338 * @brief Adds accessibility attribute
339 * @param[in] key Attribute name to set
340 * @param[in] value Attribute value to set
342 * Attribute is added if not existed previously or updated
345 void AppendAccessibilityAttribute(const std::string& key, const std::string value);
348 * @brief Removes accessibility attribute
349 * @param[in] key Attribute name to remove
351 * Function does nothing if attribute doesn't exist.
353 void RemoveAccessibilityAttribute(const std::string& key);
356 * @brief Removes all accessibility attributes
358 void ClearAccessibilityAttributes();
361 * @brief Sets reading info type attributes
362 * @param[in] types info type attributes to set
364 * This function sets, which part of object will be read out
367 void SetAccessibilityReadingInfoType(const Dali::Accessibility::ReadingInfoTypes types);
370 * @brief Gets currently active reading info type attributes
372 Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
375 * @copydoc DevelControl::VisualEventSignal()
377 DevelControl::VisualEventSignalType& VisualEventSignal();
380 * @brief Sets the shadow with a property map.
381 * @param[in] map The shadow property map
383 void SetShadow(const Property::Map& map);
386 * @brief Clear the shadow.
391 * @copydoc DevelControl::GetVisualProperty()
393 Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
396 * @brief Retrieves source and destination visual properties for the Transition of this Control.
397 * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
398 * If a property value is different between source and destination Control,
399 * the property information of each Control will be included in sourceProperties and destinationProperties.
401 * @param[out] sourceProperties Source property list to be applied on this Control.
402 * @param[out] destinationProperties Destination property list to be applied on this Control.
403 * @param[in] source Source control of the animation.
404 * @param[in] destination Destination control of the animation.
406 * @note This method do not handle Actor properties.
407 * And the size and order of the sourceProperties and destinationProperties must be synchronized.
409 * This method triggers Control::OnCreateTransition().
411 void CreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
412 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
413 Dali::Toolkit::Control source, Dali::Toolkit::Control destination);
416 * @brief Update visual properties.
417 * @param[in] properties Property list to be used to update visual properties of this Control.
419 * @note This method triggers Control::OnUpdateVisualProperties().
421 void UpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties);
424 * @brief Gets the current control's accessible object.
426 * @return The handle to Accessible object
428 Dali::Accessibility::Accessible* GetAccessibilityObject();
431 * @brief Gets Accessible object handle.
433 * The method acquires Accessible handle from Actor object
434 * @param actor Actor object
435 * @return The handle to Accessible object
437 static Dali::Accessibility::Accessible* GetAccessibilityObject(Dali::Actor actor);
441 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
447 DISABLED = 0, ///< Visual disabled.
448 ENABLED = 1 ///< Visual enabled.
453 * 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.
455 struct DepthIndexValue
459 NOT_SET = 0, ///< Visual depth value not set by caller.
460 SET = 1 ///< Visual depth value set by caller.
465 * @brief Adds the visual to the list of registered visuals.
466 * @param[in] index The Property index of the visual, used to reference visual
467 * @param[in,out] visual The visual to register, which can be altered in this function
468 * @param[in] enabled false if derived class wants to control when visual is set on stage
469 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
470 * @param[in] depthIndex The visual's depth-index is set to this
472 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
473 * occur once the replacement visual is ready (loaded).
475 void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0);
478 * @brief Emits the resource ready signal.
480 void EmitResourceReadySignal();
483 * @brief Callbacks called on idle.
485 void OnIdleCallback();
488 * @brief Checks highlighted object geometry if it is showing or not
490 void CheckHighlightedObjectGeometry();
493 * @brief Register property notification to check highlighted object position
495 void RegisterAccessibilityPositionPropertyNotification();
498 * @brief Remove property notification added by RegisterPropertyNotification
500 void UnregisterAccessibilityPositionPropertyNotification();
503 Control& mControlImpl;
504 DevelControl::State mState;
505 std::string mSubStateName;
506 Property::Map mAccessibilityAttributes;
508 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
509 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
510 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
511 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
513 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
514 std::string mStyleName;
515 Vector4 mBackgroundColor; ///< The color of the background visual
516 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
517 Extents mMargin; ///< The margin values
518 Extents mPadding; ///< The padding values
519 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
520 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
521 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
522 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
523 DevelControl::VisualEventSignalType mVisualEventSignal;
526 Toolkit::DevelControl::AccessibilityActivateSignalType mAccessibilityActivateSignal;
527 Toolkit::DevelControl::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
528 Toolkit::DevelControl::AccessibilityReadingPausedSignalType mAccessibilityReadingPausedSignal;
529 Toolkit::DevelControl::AccessibilityReadingResumedSignalType mAccessibilityReadingResumedSignal;
530 Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
531 Toolkit::DevelControl::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
533 Toolkit::DevelControl::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
534 Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
535 Toolkit::DevelControl::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
537 std::string mAccessibilityName;
538 std::string mAccessibilityDescription;
539 std::string mAccessibilityTranslationDomain;
540 bool mAccessibilityNameSet = false;
541 bool mAccessibilityDescriptionSet = false;
542 bool mAccessibilityTranslationDomainSet = false;
544 bool mAccessibilityHighlightable = false;
545 bool mAccessibilityHighlightableSet = false;
547 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
549 std::vector<std::vector<Accessibility::Address>> mAccessibilityRelations;
550 std::function<std::unique_ptr<Dali::Accessibility::Accessible>(Actor)> mAccessibilityConstructor;
551 std::unique_ptr<Dali::Accessibility::Accessible> mAccessibilityObject;
554 PinchGestureDetector mPinchGestureDetector;
555 PanGestureDetector mPanGestureDetector;
556 TapGestureDetector mTapGestureDetector;
557 LongPressGestureDetector mLongPressGestureDetector;
562 InputMethodContext mInputMethodContext;
563 CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
565 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
566 bool mIsKeyboardNavigationSupported : 1; ///< Stores whether keyboard navigation is supported by the control.
567 bool mIsKeyboardFocusGroup : 1; ///< Stores whether the control is a focus group.
568 bool mIsEmittingResourceReadySignal : 1; ///< True during ResourceReady().
569 bool mNeedToEmitResourceReady : 1; ///< True if need to emit the resource ready signal again.
570 bool mDispatchKeyEvents : 1; ///< Whether the actor emits key event signals
572 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
574 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
575 static const PropertyRegistration PROPERTY_1;
576 static const PropertyRegistration PROPERTY_2;
577 static const PropertyRegistration PROPERTY_3;
578 static const PropertyRegistration PROPERTY_4;
579 static const PropertyRegistration PROPERTY_5;
580 static const PropertyRegistration PROPERTY_6;
581 static const PropertyRegistration PROPERTY_7;
582 static const PropertyRegistration PROPERTY_8;
583 static const PropertyRegistration PROPERTY_9;
584 static const PropertyRegistration PROPERTY_10;
585 static const PropertyRegistration PROPERTY_11;
586 static const PropertyRegistration PROPERTY_12;
587 static const PropertyRegistration PROPERTY_13;
588 static const PropertyRegistration PROPERTY_14;
589 static const PropertyRegistration PROPERTY_15;
590 static const PropertyRegistration PROPERTY_16;
591 static const PropertyRegistration PROPERTY_17;
592 static const PropertyRegistration PROPERTY_18;
593 static const PropertyRegistration PROPERTY_19;
594 static const PropertyRegistration PROPERTY_20;
595 static const PropertyRegistration PROPERTY_21;
596 static const PropertyRegistration PROPERTY_22;
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