[AT-SPI] Remove SetAccessibilityConstructor()
[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/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    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
145    */
146   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual);
147
148   /**
149    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
150    */
151   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
152
153   /**
154    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
155    */
156   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
157
158   /**
159    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
160    */
161   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
162
163   /**
164    * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
165    */
166   void UnregisterVisual(Property::Index index);
167
168   /**
169    * @copydoc Dali::Toolkit::DevelControl::GetVisual()
170    */
171   Toolkit::Visual::Base GetVisual(Property::Index index) const;
172
173   /**
174    * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
175    */
176   void EnableVisual(Property::Index index, bool enable);
177
178   /**
179    * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
180    */
181   bool IsVisualEnabled(Property::Index index) const;
182
183   /**
184    * @brief Stops observing the given visual.
185    * @param[in] visual The visual to stop observing
186    */
187   void StopObservingVisual(Toolkit::Visual::Base& visual);
188
189   /**
190    * @brief Starts observing the given visual.
191    * @param[in] visual The visual to start observing
192    */
193   void StartObservingVisual(Toolkit::Visual::Base& visual);
194
195   /**
196    * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
197    */
198   Toolkit::Visual::ResourceStatus GetVisualResourceStatus(Property::Index index) const;
199
200   /**
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
205    */
206   void AddTransitions(Dali::Animation&               animation,
207                       const Toolkit::TransitionData& transitionData,
208                       bool                           createAnimation = false);
209
210   /**
211    * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
212    */
213   Dali::Animation CreateTransition(const Toolkit::TransitionData& transitionData);
214
215   /**
216    * @copydoc Dali::Toolkit::DevelControl::DoAction()
217    */
218   void DoAction(Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
219
220   /**
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
225    */
226   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
227
228   /**
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
233    */
234   static Property::Value GetProperty(BaseObject* object, Property::Index index);
235
236   /**
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
240    */
241   void SetState(DevelControl::State newState, bool withTransitions = true);
242
243   /**
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
247    */
248   void SetSubState(const std::string& subStateName, bool withTransitions = true);
249
250   /**
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
255    */
256   void ReplaceStateVisualsAndProperties(const StylePtr oldState, const StylePtr newState, const std::string& subState);
257
258   /**
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
262    */
263   void RemoveVisual(RegisteredVisualContainer& visuals, const std::string& visualName);
264
265   /**
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
269    */
270   void RemoveVisuals(RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals);
271
272   /**
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
276    */
277   void CopyInstancedProperties(RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties);
278
279   /**
280    * @brief On state change, ensures visuals are moved or created appropriately.
281    *
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
285    *
286    * @param[in] stateVisualsToChange The visuals to change
287    * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
288    */
289   void RecreateChangedVisuals(Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties);
290
291   /**
292    * @brief Whether the resource is ready
293    * @return True if the resource is read.
294    */
295   bool IsResourceReady() const;
296
297   /**
298    * @copydoc CustomActorImpl::OnSceneDisconnection()
299    */
300   void OnSceneDisconnection();
301
302   /**
303    * @brief Sets the margin.
304    * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
305    */
306   void SetMargin(Extents margin);
307
308   /**
309    * @brief Returns the value of margin
310    * @return The value of margin
311    */
312   Extents GetMargin() const;
313
314   /**
315    * @brief Sets the padding.
316    * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
317    */
318   void SetPadding(Extents padding);
319
320   /**
321    * @brief Returns the value of padding
322    * @return The value of padding
323    */
324   Extents GetPadding() const;
325
326   /**
327    * @brief Set the input method context.
328    * @param[in] inputMethodContext The input method context.
329    */
330   void SetInputMethodContext(InputMethodContext& inputMethodContext);
331
332   /**
333    * @brief Filter an key event.
334    * @param[in] event The key to be filtered.
335    * @return True if the key handled, otherwise false.
336    */
337   bool FilterKeyEvent(const KeyEvent& event);
338
339   /**
340    * @brief Adds accessibility attribute
341    * @param[in] key Attribute name to set
342    * @param[in] value Attribute value to set
343    *
344    * Attribute is added if not existed previously or updated
345    * if existed.
346    */
347   void AppendAccessibilityAttribute(const std::string& key, const std::string value);
348
349   /**
350    * @brief Removes accessibility attribute
351    * @param[in] key Attribute name to remove
352    *
353    * Function does nothing if attribute doesn't exist.
354    */
355   void RemoveAccessibilityAttribute(const std::string& key);
356
357   /**
358    * @brief Removes all accessibility attributes
359    */
360   void ClearAccessibilityAttributes();
361
362   /**
363    * @brief Sets reading info type attributes
364    * @param[in] types info type attributes to set
365    *
366    * This function sets, which part of object will be read out
367    * by screen-reader.
368    */
369   void SetAccessibilityReadingInfoType(const Dali::Accessibility::ReadingInfoTypes types);
370
371   /**
372    * @brief Gets currently active reading info type attributes
373    */
374   Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
375
376   /**
377    * @copydoc DevelControl::VisualEventSignal()
378    */
379   DevelControl::VisualEventSignalType& VisualEventSignal();
380
381   /**
382    * @brief Sets the shadow with a property map.
383    * @param[in] map The shadow property map
384    */
385   void SetShadow(const Property::Map& map);
386
387   /**
388    * @brief Clear the shadow.
389    */
390   void ClearShadow();
391
392   /**
393    * @copydoc DevelControl::GetVisualProperty()
394    */
395   Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
396
397   /**
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.
402    *
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.
407    *
408    * @note This method do not handle Actor properties.
409    * And the size and order of the sourceProperties and destinationProperties must be synchronized.
410    *
411    * This method triggers Control::OnCreateTransition().
412    */
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);
416
417   /**
418    * @brief Update visual properties.
419    * @param[in] properties Property list to be used to update visual properties of this Control.
420    *
421    * @note This method triggers Control::OnUpdateVisualProperties().
422    */
423   void UpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties);
424
425   /**
426    * @copydoc Dali::Toolkit::Internal::Control::GetAccessibleObject()
427    */
428   Toolkit::DevelControl::ControlAccessible* GetAccessibleObject();
429
430 private:
431   /**
432    * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
433    */
434   struct VisualState
435   {
436     enum Type
437     {
438       DISABLED = 0, ///< Visual disabled.
439       ENABLED  = 1  ///< Visual enabled.
440     };
441   };
442
443   /**
444    * 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.
445    */
446   struct DepthIndexValue
447   {
448     enum Type
449     {
450       NOT_SET = 0, ///< Visual depth value not set by caller.
451       SET     = 1  ///< Visual depth value set by caller.
452     };
453   };
454
455   /**
456    * @brief Adds the visual to the list of registered visuals.
457    * @param[in] index The Property index of the visual, used to reference visual
458    * @param[in,out] visual The visual to register, which can be altered in this function
459    * @param[in] enabled false if derived class wants to control when visual is set on stage
460    * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
461    * @param[in] depthIndex The visual's depth-index is set to this
462    *
463    * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
464    *       occur once the replacement visual is ready (loaded).
465    */
466   void RegisterVisual(Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0);
467
468   /**
469    * @brief Emits the resource ready signal.
470    */
471   void EmitResourceReadySignal();
472
473   /**
474    * @brief Callbacks called on idle.
475    */
476   void OnIdleCallback();
477
478   /**
479    * @brief Checks highlighted object geometry if it is showing or not
480    */
481   void CheckHighlightedObjectGeometry();
482
483   /**
484    * @brief Register property notification to check highlighted object position
485    */
486   void RegisterAccessibilityPositionPropertyNotification();
487
488   /**
489    * @brief Remove property notification added by RegisterPropertyNotification
490    */
491   void UnregisterAccessibilityPositionPropertyNotification();
492
493 public:
494   Control&            mControlImpl;
495   DevelControl::State mState;
496   std::string         mSubStateName;
497   Property::Map       mAccessibilityAttributes;
498
499   int mLeftFocusableActorId;  ///< Actor ID of Left focusable control.
500   int mRightFocusableActorId; ///< Actor ID of Right focusable control.
501   int mUpFocusableActorId;    ///< Actor ID of Up focusable control.
502   int mDownFocusableActorId;  ///< Actor ID of Down focusable control.
503
504   RegisteredVisualContainer                 mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
505   std::string                               mStyleName;
506   Vector4                                   mBackgroundColor;    ///< The color of the background visual
507   Vector3*                                  mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
508   Extents                                   mMargin;             ///< The margin values
509   Extents                                   mPadding;            ///< The padding values
510   Toolkit::Control::KeyEventSignalType      mKeyEventSignal;
511   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
512   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
513   Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
514   DevelControl::VisualEventSignalType       mVisualEventSignal;
515
516   // Accessibility
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   std::string mAccessibilityDescription;
530   std::string mAccessibilityTranslationDomain;
531
532   bool mAccessibilityHighlightable = false;
533   bool mAccessibilityHidden        = false;
534
535   Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
536
537   std::map<Dali::Accessibility::RelationType, std::set<Accessibility::Accessible*>> mAccessibilityRelations;
538   std::unique_ptr<Toolkit::DevelControl::ControlAccessible>                         mAccessibleObject;
539
540   // Gesture Detection
541   PinchGestureDetector     mPinchGestureDetector;
542   PanGestureDetector       mPanGestureDetector;
543   TapGestureDetector       mTapGestureDetector;
544   LongPressGestureDetector mLongPressGestureDetector;
545
546   // Tooltip
547   TooltipPtr mTooltip;
548
549   InputMethodContext mInputMethodContext;
550   CallbackBase*      mIdleCallback; ///< The idle callback to emit the resource ready signal.
551
552   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
553   bool             mIsKeyboardNavigationSupported : 1;    ///< Stores whether keyboard navigation is supported by the control.
554   bool             mIsKeyboardFocusGroup : 1;             ///< Stores whether the control is a focus group.
555   bool             mIsEmittingResourceReadySignal : 1;    ///< True during ResourceReady().
556   bool             mNeedToEmitResourceReady : 1;          ///< True if need to emit the resource ready signal again.
557   bool             mDispatchKeyEvents : 1;                ///< Whether the actor emits key event signals
558
559   RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
560
561   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
562   static const PropertyRegistration PROPERTY_1;
563   static const PropertyRegistration PROPERTY_2;
564   static const PropertyRegistration PROPERTY_3;
565   static const PropertyRegistration PROPERTY_4;
566   static const PropertyRegistration PROPERTY_5;
567   static const PropertyRegistration PROPERTY_6;
568   static const PropertyRegistration PROPERTY_7;
569   static const PropertyRegistration PROPERTY_8;
570   static const PropertyRegistration PROPERTY_9;
571   static const PropertyRegistration PROPERTY_10;
572   static const PropertyRegistration PROPERTY_11;
573   static const PropertyRegistration PROPERTY_12;
574   static const PropertyRegistration PROPERTY_13;
575   static const PropertyRegistration PROPERTY_14;
576   static const PropertyRegistration PROPERTY_15;
577   static const PropertyRegistration PROPERTY_16;
578   static const PropertyRegistration PROPERTY_17;
579   static const PropertyRegistration PROPERTY_18;
580   static const PropertyRegistration PROPERTY_19;
581   static const PropertyRegistration PROPERTY_20;
582   static const PropertyRegistration PROPERTY_21;
583   static const PropertyRegistration PROPERTY_22;
584   static const PropertyRegistration PROPERTY_23;
585
586 private:
587   // Accessibility - notification for highlighted object to check if it is showing.
588   bool                                        mIsAccessibilityPositionPropertyNotificationSet{false};
589   Dali::PropertyNotification                  mAccessibilityPositionNotification;
590   Dali::Accessibility::ScreenRelativeMoveType mAccessibilityLastScreenRelativeMoveType{Accessibility::ScreenRelativeMoveType::OUTSIDE};
591 };
592
593 } // namespace Internal
594
595 } // namespace Toolkit
596
597 } // namespace Dali
598
599 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H