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