436128000d797e43e97762f4050808967022415e
[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) 2021 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/devel-api/adaptor-framework/autofill-item.h>
25 #include <dali/devel-api/adaptor-framework/autofill-manager.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <string>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
32 #include <dali-toolkit/devel-api/controls/text-controls/autofill-container.h>
33 #include <dali-toolkit/internal/builder/dictionary.h>
34 #include <dali-toolkit/internal/builder/style.h>
35 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
36 #include <dali-toolkit/internal/visuals/visual-event-observer.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/visuals/visual-properties.h>
39 #include <dali/devel-api/common/owner-container.h>
40 #include <dali/integration-api/debug.h>
41 #include <memory>
42
43 namespace Dali
44 {
45 namespace Toolkit
46 {
47 namespace Internal
48 {
49 /**
50   * Struct used to store Visual within the control, index is a unique key for each visual.
51   */
52 struct RegisteredVisual
53 {
54   Property::Index       index;
55   Toolkit::Visual::Base visual;
56   bool                  enabled : 1;
57   bool                  pending : 1;
58
59   RegisteredVisual(Property::Index aIndex, Toolkit::Visual::Base& aVisual, bool aEnabled, bool aPendingReplacement)
60   : index(aIndex),
61     visual(aVisual),
62     enabled(aEnabled),
63     pending(aPendingReplacement)
64   {
65   }
66 };
67
68 typedef Dali::OwnerContainer<RegisteredVisual*> RegisteredVisualContainer;
69
70 /**
71  * @brief Holds the Implementation for the internal control class
72  */
73 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
74 {
75   friend class Toolkit::DevelControl::AccessibleImpl;
76
77 public:
78   /**
79    * @brief Retrieves the implementation of the internal control class.
80    * @param[in] internalControl A ref to the control whose internal implementation is required
81    * @return The internal implementation
82    */
83   static Control::Impl& Get(Internal::Control& internalControl);
84
85   /**
86    * @copydoc Get( Internal::Control& )
87    */
88   static const Control::Impl& Get(const Internal::Control& internalControl);
89
90   /**
91    * @brief Constructor.
92    * @param[in] controlImpl The control which owns this implementation
93    */
94   Impl(Control& controlImpl);
95
96   /**
97    * @brief Destructor.
98    */
99   ~Impl();
100
101   /**
102    * @brief Called when a pinch is detected.
103    * @param[in] actor The actor the pinch occurred on
104    * @param[in] pinch The pinch gesture details
105    */
106   void PinchDetected(Actor actor, const PinchGesture& pinch);
107
108   /**
109    * @brief Called when a pan is detected.
110    * @param[in] actor The actor the pan occurred on
111    * @param[in] pinch The pan gesture details
112    */
113   void PanDetected(Actor actor, const PanGesture& pan);
114
115   /**
116    * @brief Called when a tap is detected.
117    * @param[in] actor The actor the tap occurred on
118    * @param[in] pinch The tap gesture details
119    */
120   void TapDetected(Actor actor, const TapGesture& tap);
121
122   /**
123    * @brief Called when a long-press is detected.
124    * @param[in] actor The actor the long-press occurred on
125    * @param[in] pinch The long-press gesture details
126    */
127   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
128
129   /**
130    * @brief Called when a resource is ready.
131    * @param[in] object The visual whose resources are ready
132    * @note Overriding method in Visual::EventObserver.
133    */
134   void ResourceReady(Visual::Base& object) override;
135
136   /**
137    * @brief Called when an event occurs.
138    * @param[in] object The visual whose events occur
139    * @param[in] signalId The signal to emit. See Visual to find supported signals
140    * @note Overriding method in Visual::EventObserver.
141    */
142   void NotifyVisualEvent(Visual::Base& object, Property::Index signalId) override;
143
144   /**
145    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
146    */
147   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual);
148
149   /**
150    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
151    */
152   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
153
154   /**
155    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
156    */
157   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
158
159   /**
160    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
161    */
162   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
163
164   /**
165    * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
166    */
167   void UnregisterVisual(Property::Index index);
168
169   /**
170    * @copydoc Dali::Toolkit::DevelControl::GetVisual()
171    */
172   Toolkit::Visual::Base GetVisual(Property::Index index) const;
173
174   /**
175    * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
176    */
177   void EnableVisual(Property::Index index, bool enable);
178
179   /**
180    * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
181    */
182   bool IsVisualEnabled(Property::Index index) const;
183
184   /**
185    * @brief Stops observing the given visual.
186    * @param[in] visual The visual to stop observing
187    */
188   void StopObservingVisual(Toolkit::Visual::Base& visual);
189
190   /**
191    * @brief Starts observing the given visual.
192    * @param[in] visual The visual to start observing
193    */
194   void StartObservingVisual(Toolkit::Visual::Base& visual);
195
196   /**
197    * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
198    */
199   Toolkit::Visual::ResourceStatus GetVisualResourceStatus(Property::Index index) const;
200
201   /**
202    * @param[in,out] animation Handle to existing animation, or an empty handle that
203    * can be set to a New animation if createAnimation is true
204    * @param[in] transitionData The transition data describing the animation
205    * @param[in] createAnimation True if the animation should be created
206    */
207   void AddTransitions(Dali::Animation&               animation,
208                       const Toolkit::TransitionData& transitionData,
209                       bool                           createAnimation = false);
210
211   /**
212    * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
213    */
214   Dali::Animation CreateTransition(const Toolkit::TransitionData& transitionData);
215
216   /**
217    * @copydoc Dali::Toolkit::DevelControl::DoAction()
218    */
219   void DoAction(Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
220
221   /**
222    * @brief Function used to set control properties.
223    * @param[in] object The object whose property to set
224    * @param[in] index The index of the property to set
225    * @param[in] value The value of the property to set
226    */
227   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
228
229   /**
230    * @brief Function used to retrieve the value of control properties.
231    * @param[in] object The object whose property to get
232    * @param[in] index The index of the property to get
233    * @return The value of the property
234    */
235   static Property::Value GetProperty(BaseObject* object, Property::Index index);
236
237   /**
238    * @brief Sets the state of the control.
239    * @param[in] newState The state to set
240    * @param[in] withTransitions Whether to show a transition when changing to the new state
241    */
242   void SetState(DevelControl::State newState, bool withTransitions = true);
243
244   /**
245    * @brief Sets the sub-state of the control.
246    * @param[in] newState The sub-state to set
247    * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
248    */
249   void SetSubState(const std::string& subStateName, bool withTransitions = true);
250
251   /**
252    * @brief Replaces visuals and properties from the old state to the new state.
253    * @param[in] oldState The old state
254    * @param[in] newState The new state
255    * @param[in] subState The current sub state
256    */
257   void ReplaceStateVisualsAndProperties(const StylePtr oldState, const StylePtr newState, const std::string& subState);
258
259   /**
260    * @brief Removes a visual from the control's container.
261    * @param[in] visuals The container of visuals
262    * @param[in] visualName The name of the visual to remove
263    */
264   void RemoveVisual(RegisteredVisualContainer& visuals, const std::string& visualName);
265
266   /**
267    * @brief Removes several visuals from the control's container.
268    * @param[in] visuals The container of visuals
269    * @param[in] removeVisuals The visuals to remove
270    */
271   void RemoveVisuals(RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals);
272
273   /**
274    * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
275    * @param[in] visuals The control's visual container
276    * @param[out] instancedProperties The instanced properties are added to this container
277    */
278   void CopyInstancedProperties(RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties);
279
280   /**
281    * @brief On state change, ensures visuals are moved or created appropriately.
282    *
283    * Go through the list of visuals that are common to both states.
284    * If they are different types, or are both image types with different
285    * URLs, then the existing visual needs moving and the new visual needs creating
286    *
287    * @param[in] stateVisualsToChange The visuals to change
288    * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
289    */
290   void RecreateChangedVisuals(Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties);
291
292   /**
293    * @brief Whether the resource is ready
294    * @return True if the resource is read.
295    */
296   bool IsResourceReady() const;
297
298   /**
299    * @copydoc CustomActorImpl::OnSceneDisconnection()
300    */
301   void OnSceneDisconnection();
302
303   /**
304    * @brief Sets the margin.
305    * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
306    */
307   void SetMargin(Extents margin);
308
309   /**
310    * @brief Returns the value of margin
311    * @return The value of margin
312    */
313   Extents GetMargin() const;
314
315   /**
316    * @brief Sets the padding.
317    * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
318    */
319   void SetPadding(Extents padding);
320
321   /**
322    * @brief Returns the value of padding
323    * @return The value of padding
324    */
325   Extents GetPadding() const;
326
327   /**
328    * @brief Set the input method context.
329    * @param[in] inputMethodContext The input method context.
330    */
331   void SetInputMethodContext(InputMethodContext& inputMethodContext);
332
333   /**
334    * @brief Filter an key event.
335    * @param[in] event The key to be filtered.
336    * @return True if the key handled, otherwise false.
337    */
338   bool FilterKeyEvent(const KeyEvent& event);
339
340   /**
341    * @brief Adds accessibility attribute
342    * @param[in] key Attribute name to set
343    * @param[in] value Attribute value to set
344    *
345    * Attribute is added if not existed previously or updated
346    * if existed.
347    */
348   void AppendAccessibilityAttribute(const std::string& key,
349                                     const std::string  value);
350
351   /**
352    * @brief Removes accessibility attribute
353    * @param[in] key Attribute name to remove
354    *
355    * Function does nothing if attribute doesn't exist.
356    */
357   void RemoveAccessibilityAttribute(const std::string& key);
358
359   /**
360    * @brief Removes all accessibility attributes
361    */
362   void ClearAccessibilityAttributes();
363
364   /**
365    * @brief Sets reading info type attributes
366    * @param[in] types info type attributes to set
367    *
368    * This function sets, which part of object will be read out
369    * by screen-reader.
370    */
371   void SetAccessibilityReadingInfoType(const Dali::Accessibility::ReadingInfoTypes types);
372
373   /**
374    * @brief Gets currently active reading info type attributes
375    */
376   Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
377
378   /**
379    * @copydoc DevelControl::VisualEventSignal()
380    */
381   DevelControl::VisualEventSignalType& VisualEventSignal();
382
383   /**
384    * @brief Sets the shadow with a property map.
385    * @param[in] map The shadow property map
386    */
387   void SetShadow(const Property::Map& map);
388
389   /**
390    * @brief Clear the shadow.
391    */
392   void ClearShadow();
393
394   /**
395    * @brief Sets whether the Autofill functionality is enabled.
396    * @param[in] autofillEnabled Set true when Autofill should be enabled.
397    */
398   void SetAutofillEnabled( bool autofillEnabled );
399
400   /**
401    * @brief Check if the Autofill framework is enabled.
402    * @return True if Autofill is enabled
403    */
404   bool IsAutofillEnabled();
405
406   /**
407    * @brief Sets AutofillItemHandle
408    * @param item AutofillItem handle
409    */
410   void SetAutofillItemHandle( Dali::AutofillItem item );
411
412   /**
413    * @brief Gets AutofillItemHandle
414    * @return AutofillItem handle
415    */
416   Dali::AutofillItem GetAutofillItemHandle();
417
418   /**
419    * @brief Sets AutofillContainer which this control belongs to.
420    * @param[in] container
421    */
422   void SetAutofillContainer( Toolkit::AutofillContainer container );
423
424   /**
425    * @brief Gets AutofillContainer that the control belongs to.
426    * @return AutofillContainer handle
427    */
428   Toolkit::AutofillContainer GetAutofillContainer();
429
430   /**
431    * @copydoc DevelControl::GetVisualProperty()
432    */
433   Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
434
435   /**
436    * @brief Make visual transition from source control to this control about specific Property::Index
437    * If both of source and this control have Property::Index property, than create animation between them.
438    *
439    * @param[in] animation Return animation from source to this control.
440    * @param[in] source Source control to be used property animation.
441    * @param[in] visualIndex Property::Index to make animation.
442    * @param[in] alphaFunction alpha function of the animation.
443    * @param[in] timePeriod time period of the animation.
444    */
445   void MakeVisualTransition(Dali::Animation& animation, Dali::Toolkit::Control source, Dali::Property::Index visualIndex, AlphaFunction alphaFunction, TimePeriod timePeriod);
446
447 private:
448   /**
449    * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
450    */
451   struct VisualState
452   {
453     enum Type
454     {
455       DISABLED = 0, ///< Visual disabled.
456       ENABLED  = 1  ///< Visual enabled.
457     };
458   };
459
460   /**
461    * 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.
462    */
463   struct DepthIndexValue
464   {
465     enum Type
466     {
467       NOT_SET = 0, ///< Visual depth value not set by caller.
468       SET     = 1  ///< Visual depth value set by caller.
469     };
470   };
471
472   /**
473    * @brief Adds the visual to the list of registered visuals.
474    * @param[in] index The Property index of the visual, used to reference visual
475    * @param[in,out] visual The visual to register, which can be altered in this function
476    * @param[in] enabled false if derived class wants to control when visual is set on stage
477    * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
478    * @param[in] depthIndex The visual's depth-index is set to this
479    *
480    * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
481    *       occur once the replacement visual is ready (loaded).
482    */
483   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0);
484
485   /**
486    * @brief Emits the resource ready signal.
487    */
488   void EmitResourceReadySignal();
489
490   /**
491    * @brief Callbacks called on idle.
492    */
493   void OnIdleCallback();
494
495 public:
496   Control&            mControlImpl;
497   DevelControl::State mState;
498   std::string         mSubStateName;
499   Property::Map       mAccessibilityAttributes;
500
501   int mLeftFocusableActorId;  ///< Actor ID of Left focusable control.
502   int mRightFocusableActorId; ///< Actor ID of Right focusable control.
503   int mUpFocusableActorId;    ///< Actor ID of Up focusable control.
504   int mDownFocusableActorId;  ///< Actor ID of Down focusable control.
505
506   RegisteredVisualContainer                                      mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
507   std::string                                                    mStyleName;
508   Vector4                                                        mBackgroundColor;    ///< The color of the background visual
509   Vector3*                                                       mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
510   Extents                                                        mMargin;             ///< The margin values
511   Extents                                                        mPadding;            ///< The padding values
512   Toolkit::Control::KeyEventSignalType                           mKeyEventSignal;
513   Toolkit::Control::KeyInputFocusSignalType                      mKeyInputFocusGainedSignal;
514   Toolkit::Control::KeyInputFocusSignalType                      mKeyInputFocusLostSignal;
515   Toolkit::Control::ResourceReadySignalType                      mResourceReadySignal;
516   DevelControl::VisualEventSignalType                            mVisualEventSignal;
517   Toolkit::DevelControl::AccessibilityActivateSignalType         mAccessibilityActivateSignal;
518   Toolkit::DevelControl::AccessibilityReadingSkippedSignalType   mAccessibilityReadingSkippedSignal;
519   Toolkit::DevelControl::AccessibilityReadingPausedSignalType    mAccessibilityReadingPausedSignal;
520   Toolkit::DevelControl::AccessibilityReadingResumedSignalType   mAccessibilityReadingResumedSignal;
521   Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
522   Toolkit::DevelControl::AccessibilityReadingStoppedSignalType   mAccessibilityReadingStoppedSignal;
523
524   Toolkit::DevelControl::AccessibilityGetNameSignalType        mAccessibilityGetNameSignal;
525   Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
526   Toolkit::DevelControl::AccessibilityDoGestureSignalType      mAccessibilityDoGestureSignal;
527
528   std::string mAccessibilityName;
529   bool        mAccessibilityNameSet = false;
530
531   std::string mAccessibilityDescription;
532   bool        mAccessibilityDescriptionSet = false;
533
534   std::string mAccessibilityTranslationDomain;
535   bool        mAccessibilityTranslationDomainSet = false;
536
537   bool mAccessibilityHighlightable    = false;
538   bool mAccessibilityHighlightableSet = false;
539
540   Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
541
542   std::vector<std::vector<Accessibility::Address>> mAccessibilityRelations;
543
544   // Gesture Detection
545   PinchGestureDetector     mPinchGestureDetector;
546   PanGestureDetector       mPanGestureDetector;
547   TapGestureDetector       mTapGestureDetector;
548   LongPressGestureDetector mLongPressGestureDetector;
549
550   // Tooltip
551   TooltipPtr mTooltip;
552
553   InputMethodContext mInputMethodContext;
554   CallbackBase*      mIdleCallback; ///< The idle callback to emit the resource ready signal.
555   AutofillItem       mAutofillItem;
556   Toolkit::AutofillContainer mAutofillContainer;
557
558   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
559   bool             mIsKeyboardNavigationSupported : 1;    ///< Stores whether keyboard navigation is supported by the control.
560   bool             mIsKeyboardFocusGroup : 1;             ///< Stores whether the control is a focus group.
561   bool             mIsEmittingResourceReadySignal : 1;    ///< True during ResourceReady().
562   bool             mNeedToEmitResourceReady : 1;          ///< True if need to emit the resource ready signal again.
563   bool             mIsAutofillEnabled : 1;                ///< Stroes whether the Autofill functionality is enabled.
564
565   RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
566
567   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
568   static const PropertyRegistration PROPERTY_1;
569   static const PropertyRegistration PROPERTY_2;
570   static const PropertyRegistration PROPERTY_3;
571   static const PropertyRegistration PROPERTY_4;
572   static const PropertyRegistration PROPERTY_5;
573   static const PropertyRegistration PROPERTY_6;
574   static const PropertyRegistration PROPERTY_7;
575   static const PropertyRegistration PROPERTY_8;
576   static const PropertyRegistration PROPERTY_9;
577   static const PropertyRegistration PROPERTY_10;
578   static const PropertyRegistration PROPERTY_11;
579   static const PropertyRegistration PROPERTY_12;
580   static const PropertyRegistration PROPERTY_13;
581   static const PropertyRegistration PROPERTY_14;
582   static const PropertyRegistration PROPERTY_15;
583   static const PropertyRegistration PROPERTY_16;
584   static const PropertyRegistration PROPERTY_17;
585   static const PropertyRegistration PROPERTY_18;
586   static const PropertyRegistration PROPERTY_19;
587   static const PropertyRegistration PROPERTY_20;
588   static const PropertyRegistration PROPERTY_21;
589   static const PropertyRegistration PROPERTY_22;
590
591   /**
592    * The method acquires Accessible handle from Actor object
593    * @param  actor Actor object
594    * @return       handle to Accessible object
595    */
596   static Dali::Accessibility::Accessible* GetAccessibilityObject(Dali::Actor actor);
597   Dali::Accessibility::Accessible*        GetAccessibilityObject();
598
599   std::function<std::unique_ptr<Dali::Accessibility::Accessible>(Actor)> accessibilityConstructor;
600   std::unique_ptr<Dali::Accessibility::Accessible>                       accessibilityObject;
601 };
602
603 } // namespace Internal
604
605 } // namespace Toolkit
606
607 } // namespace Dali
608
609 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H