Remove ResourceReady before rasterization in SvgVisual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / control / control-data-impl.h
1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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>
26 #include <string>
27
28 // INTERNAL INCLUDES
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>
38 #include <map>
39 #include <memory>
40 #include <set>
41
42 namespace Dali
43 {
44 namespace Toolkit
45 {
46 namespace Internal
47 {
48 /**
49   * Struct used to store Visual within the control, index is a unique key for each visual.
50   */
51 struct RegisteredVisual
52 {
53   Property::Index       index;
54   Toolkit::Visual::Base visual;
55   bool                  enabled : 1;
56   bool                  pending : 1;
57
58   RegisteredVisual(Property::Index aIndex, Toolkit::Visual::Base& aVisual, bool aEnabled, bool aPendingReplacement)
59   : index(aIndex),
60     visual(aVisual),
61     enabled(aEnabled),
62     pending(aPendingReplacement)
63   {
64   }
65 };
66
67 typedef Dali::OwnerContainer<RegisteredVisual*> RegisteredVisualContainer;
68
69 /**
70  * @brief Holds the Implementation for the internal control class
71  */
72 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
73 {
74   friend class Toolkit::DevelControl::ControlAccessible;
75
76 public:
77   /**
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
81    */
82   static Control::Impl& Get(Internal::Control& internalControl);
83
84   /**
85    * @copydoc Get( Internal::Control& )
86    */
87   static const Control::Impl& Get(const Internal::Control& internalControl);
88
89   /**
90    * @brief Constructor.
91    * @param[in] controlImpl The control which owns this implementation
92    */
93   Impl(Control& controlImpl);
94
95   /**
96    * @brief Destructor.
97    */
98   ~Impl();
99
100   /**
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
104    */
105   void PinchDetected(Actor actor, const PinchGesture& pinch);
106
107   /**
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
111    */
112   void PanDetected(Actor actor, const PanGesture& pan);
113
114   /**
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
118    */
119   void TapDetected(Actor actor, const TapGesture& tap);
120
121   /**
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
125    */
126   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
127
128   /**
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.
132    */
133   void ResourceReady(Visual::Base& object) override;
134
135   /**
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.
140    */
141   void NotifyVisualEvent(Visual::Base& object, Property::Index signalId) override;
142
143   /**
144    * @brief Called when the visual needs relayout request.
145    * @param[in] object The visual who requests relayout
146    */
147   void RelayoutRequest(Visual::Base& object) override;
148
149   /**
150    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
151    */
152   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual);
153
154   /**
155    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
156    */
157   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
158
159   /**
160    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
161    */
162   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
163
164   /**
165    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
166    */
167   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
168
169   /**
170    * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
171    */
172   void UnregisterVisual(Property::Index index);
173
174   /**
175    * @copydoc Dali::Toolkit::DevelControl::GetVisual()
176    */
177   Toolkit::Visual::Base GetVisual(Property::Index index) const;
178
179   /**
180    * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
181    */
182   void EnableVisual(Property::Index index, bool enable);
183
184   /**
185    * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
186    */
187   bool IsVisualEnabled(Property::Index index) const;
188
189   /**
190    * @brief Stops observing the given visual.
191    * @param[in] visual The visual to stop observing
192    */
193   void StopObservingVisual(Toolkit::Visual::Base& visual);
194
195   /**
196    * @brief Starts observing the given visual.
197    * @param[in] visual The visual to start observing
198    */
199   void StartObservingVisual(Toolkit::Visual::Base& visual);
200
201   /**
202    * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
203    */
204   Toolkit::Visual::ResourceStatus GetVisualResourceStatus(Property::Index index) const;
205
206   /**
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
211    */
212   void AddTransitions(Dali::Animation&               animation,
213                       const Toolkit::TransitionData& transitionData,
214                       bool                           createAnimation = false);
215
216   /**
217    * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
218    */
219   Dali::Animation CreateTransition(const Toolkit::TransitionData& transitionData);
220
221   /**
222    * @copydoc Dali::Toolkit::DevelControl::DoAction()
223    */
224   void DoAction(Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
225
226   /**
227    * @brief Function used to set control properties.
228    * @param[in] object The object whose property to set
229    * @param[in] index The index of the property to set
230    * @param[in] value The value of the property to set
231    */
232   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
233
234   /**
235    * @brief Function used to retrieve the value of control properties.
236    * @param[in] object The object whose property to get
237    * @param[in] index The index of the property to get
238    * @return The value of the property
239    */
240   static Property::Value GetProperty(BaseObject* object, Property::Index index);
241
242   /**
243    * @brief Sets the state of the control.
244    * @param[in] newState The state to set
245    * @param[in] withTransitions Whether to show a transition when changing to the new state
246    */
247   void SetState(DevelControl::State newState, bool withTransitions = true);
248
249   /**
250    * @brief Sets the sub-state of the control.
251    * @param[in] newState The sub-state to set
252    * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
253    */
254   void SetSubState(const std::string& subStateName, bool withTransitions = true);
255
256   /**
257    * @brief Replaces visuals and properties from the old state to the new state.
258    * @param[in] oldState The old state
259    * @param[in] newState The new state
260    * @param[in] subState The current sub state
261    */
262   void ReplaceStateVisualsAndProperties(const StylePtr oldState, const StylePtr newState, const std::string& subState);
263
264   /**
265    * @brief Removes a visual from the control's container.
266    * @param[in] visuals The container of visuals
267    * @param[in] visualName The name of the visual to remove
268    */
269   void RemoveVisual(RegisteredVisualContainer& visuals, const std::string& visualName);
270
271   /**
272    * @brief Removes several visuals from the control's container.
273    * @param[in] visuals The container of visuals
274    * @param[in] removeVisuals The visuals to remove
275    */
276   void RemoveVisuals(RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals);
277
278   /**
279    * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
280    * @param[in] visuals The control's visual container
281    * @param[out] instancedProperties The instanced properties are added to this container
282    */
283   void CopyInstancedProperties(RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties);
284
285   /**
286    * @brief On state change, ensures visuals are moved or created appropriately.
287    *
288    * Go through the list of visuals that are common to both states.
289    * If they are different types, or are both image types with different
290    * URLs, then the existing visual needs moving and the new visual needs creating
291    *
292    * @param[in] stateVisualsToChange The visuals to change
293    * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
294    */
295   void RecreateChangedVisuals(Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties);
296
297   /**
298    * @brief Whether the resource is ready
299    * @return True if the resource is read.
300    */
301   bool IsResourceReady() const;
302
303   /**
304    * @copydoc CustomActorImpl::OnSceneDisconnection()
305    */
306   void OnSceneDisconnection();
307
308   /**
309    * @brief Sets the margin.
310    * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
311    */
312   void SetMargin(Extents margin);
313
314   /**
315    * @brief Returns the value of margin
316    * @return The value of margin
317    */
318   Extents GetMargin() const;
319
320   /**
321    * @brief Sets the padding.
322    * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
323    */
324   void SetPadding(Extents padding);
325
326   /**
327    * @brief Returns the value of padding
328    * @return The value of padding
329    */
330   Extents GetPadding() const;
331
332   /**
333    * @brief Set the input method context.
334    * @param[in] inputMethodContext The input method context.
335    */
336   void SetInputMethodContext(InputMethodContext& inputMethodContext);
337
338   /**
339    * @brief Filter an key event.
340    * @param[in] event The key to be filtered.
341    * @return True if the key handled, otherwise false.
342    */
343   bool FilterKeyEvent(const KeyEvent& event);
344
345   /**
346    * @brief Adds accessibility attribute
347    * @param[in] key Attribute name to set
348    * @param[in] value Attribute value to set
349    *
350    * Attribute is added if not existed previously or updated
351    * if existed.
352    */
353   void AppendAccessibilityAttribute(const std::string& key, const std::string value);
354
355   /**
356    * @brief Removes accessibility attribute
357    * @param[in] key Attribute name to remove
358    *
359    * Function does nothing if attribute doesn't exist.
360    */
361   void RemoveAccessibilityAttribute(const std::string& key);
362
363   /**
364    * @brief Removes all accessibility attributes
365    */
366   void ClearAccessibilityAttributes();
367
368   /**
369    * @brief Sets reading info type attributes
370    * @param[in] types info type attributes to set
371    *
372    * This function sets, which part of object will be read out
373    * by screen-reader.
374    */
375   void SetAccessibilityReadingInfoType(const Dali::Accessibility::ReadingInfoTypes types);
376
377   /**
378    * @brief Gets currently active reading info type attributes
379    */
380   Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
381
382   /**
383    * @copydoc DevelControl::VisualEventSignal()
384    */
385   DevelControl::VisualEventSignalType& VisualEventSignal();
386
387   /**
388    * @brief Sets the shadow with a property map.
389    * @param[in] map The shadow property map
390    */
391   void SetShadow(const Property::Map& map);
392
393   /**
394    * @brief Clear the shadow.
395    */
396   void ClearShadow();
397
398   /**
399    * @copydoc DevelControl::GetVisualProperty()
400    */
401   Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
402
403   /**
404    * @brief Retrieves source and destination visual properties for the Transition of this Control.
405    * The properties of this Control will be transitioned from the propeties of source Control to that of destination control.
406    * If a property value is different between source and destination Control,
407    * the property information of each Control will be included in sourceProperties and destinationProperties.
408    *
409    * @param[out] sourceProperties Source property list to be applied on this Control.
410    * @param[out] destinationProperties Destination property list to be applied on this Control.
411    * @param[in] source Source control of the animation.
412    * @param[in] destination Destination control of the animation.
413    *
414    * @note This method do not handle Actor properties.
415    * And the size and order of the sourceProperties and destinationProperties must be synchronized.
416    *
417    * This method triggers Control::OnCreateTransition().
418    */
419   void CreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
420                          std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
421                          Dali::Toolkit::Control                                              source,
422                          Dali::Toolkit::Control                                              destination);
423
424   /**
425    * @brief Update visual properties.
426    * @param[in] properties Property list to be used to update visual properties of this Control.
427    *
428    * @note This method triggers Control::OnUpdateVisualProperties().
429    */
430   void UpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties);
431
432   /**
433    * @copydoc Dali::Toolkit::Internal::Control::GetAccessibleObject()
434    */
435   Toolkit::DevelControl::ControlAccessible* GetAccessibleObject();
436
437 private:
438   /**
439    * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
440    */
441   struct VisualState
442   {
443     enum Type
444     {
445       DISABLED = 0, ///< Visual disabled.
446       ENABLED  = 1  ///< Visual enabled.
447     };
448   };
449
450   /**
451    * 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.
452    */
453   struct DepthIndexValue
454   {
455     enum Type
456     {
457       NOT_SET = 0, ///< Visual depth value not set by caller.
458       SET     = 1  ///< Visual depth value set by caller.
459     };
460   };
461
462   /**
463    * @brief Adds the visual to the list of registered visuals.
464    * @param[in] index The Property index of the visual, used to reference visual
465    * @param[in,out] visual The visual to register, which can be altered in this function
466    * @param[in] enabled false if derived class wants to control when visual is set on stage
467    * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
468    * @param[in] depthIndex The visual's depth-index is set to this
469    *
470    * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
471    *       occur once the replacement visual is ready (loaded).
472    */
473   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0);
474
475   /**
476    * @brief Emits the resource ready signal.
477    */
478   void EmitResourceReadySignal();
479
480   /**
481    * @brief Callbacks called on idle.
482    */
483   void OnIdleCallback();
484
485   /**
486    * @brief Checks highlighted object geometry if it is showing or not
487    */
488   void CheckHighlightedObjectGeometry();
489
490   /**
491    * @brief Register property notification to check highlighted object position
492    */
493   void RegisterAccessibilityPositionPropertyNotification();
494
495   /**
496    * @brief Remove property notification added by RegisterPropertyNotification
497    */
498   void UnregisterAccessibilityPositionPropertyNotification();
499
500 public:
501   Control&            mControlImpl;
502   DevelControl::State mState;
503   std::string         mSubStateName;
504   Property::Map       mAccessibilityAttributes;
505
506   int mLeftFocusableActorId;             ///< Actor ID of Left focusable control.
507   int mRightFocusableActorId;            ///< Actor ID of Right focusable control.
508   int mUpFocusableActorId;               ///< Actor ID of Up focusable control.
509   int mDownFocusableActorId;             ///< Actor ID of Down focusable control.
510   int mClockwiseFocusableActorId;        ///< Actor ID of Clockwise focusable control.
511   int mCounterClockwiseFocusableActorId; ///< Actor ID of Counter clockwise focusable control.
512
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;
524
525   // Accessibility
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;
532
533   Toolkit::DevelControl::AccessibilityGetNameSignalType        mAccessibilityGetNameSignal;
534   Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
535   Toolkit::DevelControl::AccessibilityDoGestureSignalType      mAccessibilityDoGestureSignal;
536
537   std::string mAccessibilityName;
538   std::string mAccessibilityDescription;
539   std::string mAccessibilityTranslationDomain;
540
541   bool mAccessibilityHighlightable = false;
542   bool mAccessibilityHidden        = false;
543
544   Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
545
546   std::map<Dali::Accessibility::RelationType, std::set<Accessibility::Accessible*>> mAccessibilityRelations;
547   std::unique_ptr<Toolkit::DevelControl::ControlAccessible>                         mAccessibleObject;
548
549   // Gesture Detection
550   PinchGestureDetector     mPinchGestureDetector;
551   PanGestureDetector       mPanGestureDetector;
552   TapGestureDetector       mTapGestureDetector;
553   LongPressGestureDetector mLongPressGestureDetector;
554
555   // Tooltip
556   TooltipPtr mTooltip;
557
558   InputMethodContext mInputMethodContext;
559   CallbackBase*      mIdleCallback; ///< The idle callback to emit the resource ready signal.
560
561   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
562   bool             mIsKeyboardNavigationSupported : 1;    ///< Stores whether keyboard navigation is supported by the control.
563   bool             mIsKeyboardFocusGroup : 1;             ///< Stores whether the control is a focus group.
564   bool             mIsEmittingResourceReadySignal : 1;    ///< True during ResourceReady().
565   bool             mNeedToEmitResourceReady : 1;          ///< True if need to emit the resource ready signal again.
566   bool             mDispatchKeyEvents : 1;                ///< Whether the actor emits key event signals
567
568   RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
569
570   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
571   static const PropertyRegistration PROPERTY_1;
572   static const PropertyRegistration PROPERTY_2;
573   static const PropertyRegistration PROPERTY_3;
574   static const PropertyRegistration PROPERTY_4;
575   static const PropertyRegistration PROPERTY_5;
576   static const PropertyRegistration PROPERTY_6;
577   static const PropertyRegistration PROPERTY_7;
578   static const PropertyRegistration PROPERTY_8;
579   static const PropertyRegistration PROPERTY_9;
580   static const PropertyRegistration PROPERTY_10;
581   static const PropertyRegistration PROPERTY_11;
582   static const PropertyRegistration PROPERTY_12;
583   static const PropertyRegistration PROPERTY_13;
584   static const PropertyRegistration PROPERTY_14;
585   static const PropertyRegistration PROPERTY_15;
586   static const PropertyRegistration PROPERTY_16;
587   static const PropertyRegistration PROPERTY_17;
588   static const PropertyRegistration PROPERTY_18;
589   static const PropertyRegistration PROPERTY_19;
590   static const PropertyRegistration PROPERTY_20;
591   static const PropertyRegistration PROPERTY_21;
592   static const PropertyRegistration PROPERTY_22;
593   static const PropertyRegistration PROPERTY_23;
594   static const PropertyRegistration PROPERTY_24;
595   static const PropertyRegistration PROPERTY_25;
596
597 private:
598   // Accessibility - notification for highlighted object to check if it is showing.
599   bool                                        mIsAccessibilityPositionPropertyNotificationSet{false};
600   Dali::PropertyNotification                  mAccessibilityPositionNotification;
601   Dali::Accessibility::ScreenRelativeMoveType mAccessibilityLastScreenRelativeMoveType{Accessibility::ScreenRelativeMoveType::OUTSIDE};
602 };
603
604 } // namespace Internal
605
606 } // namespace Toolkit
607
608 } // namespace Dali
609
610 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H