af6c76cc32824c4155fbd172b4b161b5ffe13db2
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / control-devel.h
1 #ifndef DALI_TOOLKIT_CONTROL_DEVEL_H
2 #define DALI_TOOLKIT_CONTROL_DEVEL_H
3
4 /*
5  * Copyright (c) 2020 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 // EXTERNAL INCLUDES
21 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
22 #include <dali/devel-api/adaptor-framework/input-method-context.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
26 #include <dali-toolkit/public-api/controls/control.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 class TransitionData;
33
34 namespace Visual
35 {
36 class Base;
37 }
38
39 namespace DevelControl
40 {
41 /// @brief AccessibilityActivate signal type.
42 typedef Signal< void ( ) > AccessibilityActivateSignalType;
43
44 /// @brief AccessibilityReadingSkipped signal type.
45 typedef Signal< void ( ) > AccessibilityReadingSkippedSignalType;
46
47 /// @brief AccessibilityReadingPaused signal type.
48 typedef Signal< void ( ) > AccessibilityReadingPausedSignalType;
49
50 /// @brief AccessibilityReadingResumed signal type.
51 typedef Signal< void ( ) > AccessibilityReadingResumedSignalType;
52
53 /// @brief AccessibilityReadingCancelled signal type.
54 typedef Signal< void ( ) > AccessibilityReadingCancelledSignalType;
55
56 /// @brief AccessibilityReadingStopped signal type.
57 typedef Signal< void ( ) > AccessibilityReadingStoppedSignalType;
58
59 /// @brief AccessibilityGetName signal type.
60 typedef Signal< void ( std::string& ) > AccessibilityGetNameSignalType;
61
62 /// @brief AccessibilityGetDescription signal type.
63 typedef Signal< void ( std::string& ) > AccessibilityGetDescriptionSignalType;
64
65 /// @brief AccessibilityDoGesture signal type.
66 typedef Signal< void ( std::pair<Dali::Accessibility::GestureInfo, bool>& ) > AccessibilityDoGestureSignalType;
67
68 enum State
69 {
70   NORMAL,
71   FOCUSED,
72   DISABLED
73 };
74
75 namespace Property
76 {
77 enum
78 {
79   STYLE_NAME      = Control::Property::STYLE_NAME,
80   KEY_INPUT_FOCUS = Control::Property::KEY_INPUT_FOCUS,
81   BACKGROUND      = Control::Property::BACKGROUND,
82   MARGIN          = Control::Property::MARGIN,
83   PADDING         = Control::Property::PADDING,
84
85   /**
86    * @brief Displays a tooltip when the control is hovered over.
87    * @details Name "tooltip", type Property::STRING, Property::ARRAY or Property::MAP.
88    *          If Property::STRING, then the style specified in the stylesheet is used.
89    *          If Property::ARRAY of Visuals then all are displayed in one row.
90    *          If Property::MAP, then it should be a map of Tooltip properties.
91    * @note The tooltip is only activated if display content is received, i.e. a string (text) or visual to show.
92    *       The rest is used to just build up the style of the tooltip (i.e. background, text color/point-size etc.)
93    * @note When retrieved, a Property::MAP is returned.
94    * @see Toolkit::Tooltip
95    */
96   TOOLTIP = PADDING + 1,
97
98   /**
99    * @brief The current state of the control.
100    * @details Name "state", type DevelControl::State ( Property::INTEGER ) or Property::STRING
101    *
102    * @see DevelControl::State
103    */
104   STATE = PADDING + 2,
105
106   /**
107    * @brief The current sub state of the control.
108    * @details Name "subState", type Property::INTEGER or Property::STRING. The enumeration used is dependent on the derived control.
109    *
110    * @see DevelControl::State
111    */
112   SUB_STATE = PADDING + 3,
113
114   /**
115    * @brief The actor ID of the left focusable control.
116    * @details Name "leftFocusableActorId", type Property::INTEGER.
117    *
118    */
119   LEFT_FOCUSABLE_ACTOR_ID = PADDING + 4,
120
121   /**
122    * @brief The actor ID of the right focusable control.
123    * @details Name "rightFocusableActorId", type Property::INTEGER.
124    *
125    */
126   RIGHT_FOCUSABLE_ACTOR_ID = PADDING + 5,
127
128   /**
129    * @brief The actor ID of the up focusable control.
130    * @details Name "upFocusableActorId", type Property::INTEGER.
131    *
132    */
133   UP_FOCUSABLE_ACTOR_ID = PADDING + 6,
134
135   /**
136    * @brief The actor ID of the down focusable control.
137    * @details Name "downFocusableActorId", type Property::INTEGER.
138    *
139    */
140   DOWN_FOCUSABLE_ACTOR_ID = PADDING + 7,
141
142   /**
143    * @brief The shadow of the control.
144    * @details Name "shadow", type Property::MAP.
145    */
146   SHADOW = PADDING + 8,
147
148   /**
149    * @brief The name of object visible in accessibility tree.
150    * @details Name "accessibilityName", type Property::STRING.
151    */
152   ACCESSIBILITY_NAME,
153
154   /**
155    * @brief The description of object visible in accessibility tree.
156    * @details Name "accessibilityDescription", type Property::STRING.
157    */
158   ACCESSIBILITY_DESCRIPTION,
159
160   /**
161    * @brief Current translation domain for accessibility clients.
162    * @details Name "accessibilityTranslationDomain", type Property::STRING.
163    */
164   ACCESSIBILITY_TRANSLATION_DOMAIN,
165
166   /**
167    * @brief Role being performed in accessibility hierarchy.
168    * @details Name "accessibilityRole", type Property::INTEGER.
169    * @note Property is stored as INTEGER, however its interpretaton
170    * depend on enumeration Dali::Accessibility::Role and should be read and written
171    * with usage of enumerated values.
172    * @see Dali::Accessibility::Role
173    */
174   ACCESSIBILITY_ROLE,
175   /**
176    * @brief Mark of able to highlight object.
177    * @details Name "accessibilityHighlightable", type Property::BOOLEAN.
178    */
179   ACCESSIBILITY_HIGHLIGHTABLE,
180   /**
181    * @brief Set of accessibility attributes describing object in accessibility hierarchy
182    * @details Name "accessibilityAttributes", type Property::MAP
183    */
184   ACCESSIBILITY_ATTRIBUTES,
185
186   /**
187    * @brief Boolean flag describing object as animated
188    * @details Name "accessibilityAnimated", type Property::BOOLEAN
189    * @note Flag set to true will prevent BoundChanged accessibility signal from emiting
190    */
191   ACCESSIBILITY_ANIMATED
192 };
193
194 } // namespace Property
195
196 /**
197  * @brief Register a visual by Property Index.
198  *
199  * @param[in] control The control
200  * @param[in] index The Property index of the visual, used to reference visual
201  * @param[in] visual The visual to register
202  *
203  * @note Derived class should not call visual.SetOnScene(actor). It is the responsibility of the base class to connect/disconnect registered visual to stage.
204  *       Use below API with enabled set to false if derived class wishes to control when visual is staged.
205  * @note If the depth-index is not set on the visual, then it is set to be above the currently registered visuals.
206  * @note If replacing a visual, then the depth-index of the visual being replaced is used for the visual.
207  */
208 DALI_TOOLKIT_API void RegisterVisual(Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual);
209
210 /**
211  * @brief Register a visual by Property Index with a depth index.
212  *
213  * @param[in] control The control
214  * @param[in] index The Property index of the visual, used to reference visual
215  * @param[in] visual The visual to register
216  * @param[in] depthIndex The visual's depth-index is set to this
217  *
218  * @note Derived class should not call visual.SetOnScene(actor). It is the responsibility of the base class to connect/disconnect registered visual to stage.
219  *       Use below API with enabled set to false if derived class wishes to control when visual is staged.
220  *
221  * @see Visual::Base::GetDepthIndex()
222  * @see Visual::Base::SetDepthIndex()
223  */
224 DALI_TOOLKIT_API void RegisterVisual(Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, int depthIndex);
225
226 /**
227  * @brief Register a visual by Property Index with the option of enabling/disabling it.
228  *
229  * @param[in] control The control
230  * @param[in] index The Property index of the visual, used to reference visual
231  * @param[in] visual The visual to register
232  * @param[in] enabled false if derived class wants to control when visual is set on stage.
233  *
234  * @note If the depth-index is not set on the visual, then it is set to be above the currently registered visuals.
235  * @note If replacing a visual, then the depth-index of the visual being replaced is used for the visual.
236  *
237  * @see EnableVisual()
238  */
239 DALI_TOOLKIT_API void RegisterVisual(Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, bool enabled);
240
241 /**
242  * @brief Register a visual by Property Index with a depth index with the option of enabling/disabling it.
243  *
244  * @param[in] control The control
245  * @param[in] index The Property index of the visual, used to reference visual
246  * @param[in] visual The visual to register
247  * @param[in] enabled false if derived class wants to control when visual is set on stage.
248  * @param[in] depthIndex The visual's depth-index is set to this
249  *
250  * @see EnableVisual()
251  * @see Visual::Base::GetDepthIndex()
252  * @see Visual::Base::SetDepthIndex()
253  */
254 DALI_TOOLKIT_API void RegisterVisual(Internal::Control& control, Dali::Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex);
255
256 /**
257  * @brief Erase the entry matching the given index from the list of registered visuals
258  *
259  * @param[in] control The control
260  * @param[in] index The Property index of the visual, used to reference visual
261  */
262 DALI_TOOLKIT_API void UnregisterVisual(Internal::Control& control, Dali::Property::Index index);
263
264 /**
265  * @brief Retrieve the visual associated with the given property index.
266  *
267  * @param[in] control The control
268  * @param[in] index The Property index of the visual.
269  * @return The registered visual if exist, otherwise empty handle.
270  * @note For managing object life-cycle, do not store the returned visual as a member which increments its reference count.
271  */
272 DALI_TOOLKIT_API Toolkit::Visual::Base GetVisual(const Internal::Control& control, Dali::Property::Index index);
273
274 /**
275  * @brief Sets the given visual to be displayed or not when parent staged.
276  *
277  * @param[in] control The control
278  * @param[in] index The Property index of the visual
279  * @param[in] enable flag to set enabled or disabled.
280  */
281 DALI_TOOLKIT_API void EnableVisual(Internal::Control& control, Dali::Property::Index index, bool enable);
282
283 /**
284  * @brief Queries if the given visual is to be displayed when parent staged.
285  *
286  * @param[in] control The control
287  * @param[in] index The Property index of the visual
288  * @return bool whether visual is enabled or not
289  */
290 DALI_TOOLKIT_API bool IsVisualEnabled(const Internal::Control& control, Dali::Property::Index index);
291
292 /**
293  * @brief Add a transition effect on the control to the given animation
294  *
295  * Only generates an animator if the properties described in the transition
296  * data are staged (e.g. the visual is Enabled and the control is on stage).
297  * Otherwise the target values are stored, and will get set onto the properties
298  * when the visual is next staged.
299  *
300  * @param[in] control The control
301  * @param[in] animation The Animation to add valid transitions to
302  * @param[in] transitionData The transition data describing the effect to create
303  */
304 DALI_TOOLKIT_API void AddTransitions(Internal::Control&             control,
305                                      Dali::Animation                animation,
306                                      const Toolkit::TransitionData& transitionData);
307
308 /**
309  * @brief Create a transition effect on the control.
310  *
311  * Only generates an animation if the properties described in the transition
312  * data are staged (e.g. the visual is Enabled and the control is on stage).
313  * Otherwise the target values are stored, and will get set onto the properties
314  * when the visual is next staged.
315  *
316  * @param[in] control The control
317  * @param[in] transitionData The transition data describing the effect to create
318  * @return A handle to an animation defined with the given effect, or an empty
319  * handle if no properties match.
320  */
321 DALI_TOOLKIT_API Dali::Animation CreateTransition(Internal::Control&             control,
322                                                   const Toolkit::TransitionData& transitionData);
323
324 /**
325  * @brief Perform an action on a visual registered to this control.
326  *
327  * Visuals will have actions, this API is used to perform one of these actions with the given attributes.
328  *
329  * @param[in] control The control.
330  * @param[in] visualIndex The Property index of the visual.
331  * @param[in] actionId The action to perform.  See Visual to find supported actions.
332  * @param[in] attributes Optional attributes for the action.
333  */
334 DALI_TOOLKIT_API void DoAction(Control& control, Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes);
335
336 /**
337  * @brief Set input method context.
338  *
339  * @param[in] control The control.
340  * @param[in] inputMethodContext The input method context.
341  */
342 DALI_TOOLKIT_API void SetInputMethodContext(Internal::Control& control, InputMethodContext& inputMethodContext);
343
344 /**
345  * @brief Visual Event signal type
346  */
347 using VisualEventSignalType = Signal<void(Control, Dali::Property::Index, Dali::Property::Index)>;
348
349 /**
350  * @brief This signal is emitted when a visual has an event to notify.
351  *
352  * A callback of the following type may be connected:
353  * @code
354  *   void YourCallbackName( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId );
355  * @endcode
356  * @return The signal to connect to
357  */
358 DALI_TOOLKIT_API VisualEventSignalType& VisualEventSignal(Control control);
359
360 /**
361  * @brief Retrieve the property object associated with the given property index and the visual property key.
362  *
363  * @param[in] control The control
364  * @param[in] index The Property index of the visual.
365  * @param[in] visualPropertyKey The key of the visual's property.
366  * @return The Property object
367  * @pre The control should be added to the Scene.
368  * @pre The returned object is valid for as long as the control is on the Scene.
369  */
370 DALI_TOOLKIT_API Dali::Property GetVisualProperty(Control control, Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
371
372 /**
373  * @brief The signal is emmited as a succession of "activate" signal send by accessibility client.
374  * @return The signal to connect to
375  */
376 DALI_TOOLKIT_API AccessibilityActivateSignalType &AccessibilityActivateSignal( Toolkit::Control control );
377
378 /**
379  * @brief The signal is emmited when text send via Dali::Accessibility::Bridge::Say
380  * was placed in TTS queue but other text with higher priority prevented it from being read.
381  *
382  * @return The signal to connect to
383  */
384 DALI_TOOLKIT_API AccessibilityReadingSkippedSignalType &AccessibilityReadingSkippedSignal( Toolkit::Control control );
385
386 /**
387  * @brief
388  *
389  * @return The signal to connect to
390  */
391 DALI_TOOLKIT_API AccessibilityReadingPausedSignalType &AccessibilityReadingPausedSignal( Toolkit::Control control );
392
393 /**
394  * @brief
395  *
396  * @return The signal to connect to
397  */
398 DALI_TOOLKIT_API AccessibilityReadingResumedSignalType &AccessibilityReadingResumedSignal( Toolkit::Control control );
399
400 /**
401  * @brief The signal is emmited when text send via Dali::Accessibility::Bridge::Say
402  * was placed in TTS queue and reading was started but other text with higher priority cancelled it.
403  *
404  * @return The signal to connect to
405  */
406 DALI_TOOLKIT_API AccessibilityReadingCancelledSignalType &AccessibilityReadingCancelledSignal( Toolkit::Control control );
407
408 /**
409  * @brief The signal is emmited when text send via Dali::Accessibility::Bridge::Say
410  * was fully read by TTS module.
411  *
412  * @return The signal to connect to
413  */
414 DALI_TOOLKIT_API AccessibilityReadingStoppedSignalType &AccessibilityReadingStoppedSignal( Toolkit::Control control );
415
416 /**
417  * @brief The signal is emmited when accessibility client asks for object's name.
418  *
419  * Connected callback should assign name to std::string call parameter.
420  * Accessibility name can be stored in two ways:
421  *     this signal,
422  *     ACCESSIBILITY_NAME property,
423  * Priority is as above. If none is used, default implementation is provided.
424  * @return [description]
425  */
426 DALI_TOOLKIT_API AccessibilityGetNameSignalType &AccessibilityGetNameSignal( Toolkit::Control control );
427
428 /**
429  * @brief The signal is emmited when accessibility client asks for object's description.
430  *
431  * Connected callback should assign description to std::string call parameter.
432  * Accessibility description can be stored in two ways:
433  *     this signal,
434  *     ACCESSIBILITY_DESCRIPTION property,
435  * Priority is as above. If none is used, default implementation is provided.
436  * @return signal handler
437  */
438 DALI_TOOLKIT_API AccessibilityGetDescriptionSignalType &AccessibilityGetDescriptionSignal( Toolkit::Control control );
439
440 /**
441  * @brief The signal is emitted when accessibility client call "DoGesture" method via IPC mechanism.
442  *
443  * This signal allows developers to serve incoming gesture in specific way.
444  * @return signal handler
445  */
446 DALI_TOOLKIT_API AccessibilityDoGestureSignalType &AccessibilityDoGestureSignal( Toolkit::Control control );
447
448 /**
449  * @brief The method allows connection with other actor with usage of concrete accessibility relation type.
450  *
451  * @param control object to append attribute to
452  * @param destination Actor object
453  * @param relation    enumerated value describing relation
454  */
455 DALI_TOOLKIT_API void AppendAccessibilityRelation( Dali::Actor control, Actor destination, Dali::Accessibility::RelationType relation );
456
457 /**
458  * @brief The method allows removing relation
459  *
460  * @param control object to append attribute to
461  * @param destination Actor object
462  * @param relation    enumerated value describing relation
463  */
464 DALI_TOOLKIT_API void RemoveAccessibilityRelation( Dali::Actor control, Actor destination, Dali::Accessibility::RelationType relation );
465
466 /**
467  * @brief The method returns collection accessibility addresses representing objects connected with current object
468  *
469  * @param control object to append attribute to
470  * @return std::vector, where index is casted value of Accessibility::RelationType and value is std::vector of type Accessibility::Address
471  */
472 DALI_TOOLKIT_API std::vector<std::vector<Accessibility::Address>> GetAccessibilityRelations( Dali::Actor control );
473
474 /**
475  * @brief The method removes all previously appended relations
476  *
477  * @param control object to append attribute to
478  */
479 DALI_TOOLKIT_API void ClearAccessibilityRelations( Dali::Actor control );
480
481 /**
482  * @brief The method allows to add or modify value matched with given key.
483  * Modification take place if key was previously set.
484  *
485  * @param control object to append attribute to
486  * @param key   std::string value
487  * @param value std::string value
488  */
489 DALI_TOOLKIT_API void AppendAccessibilityAttribute( Dali::Actor control, const std::string& key, const std::string value );
490
491 /**
492  * @brief The method erases key with its value from accessibility attributes
493  * @param control object to append attribute to
494  * @param key std::string value
495  */
496 DALI_TOOLKIT_API void RemoveAccessibilityAttribute( Dali::Actor control, const std::string& key );
497
498 /**
499  * @brief The method clears accessibility attributes
500  *
501  * @param control object to append attribute to
502  */
503 DALI_TOOLKIT_API void ClearAccessibilityAttributes( Dali::Actor control );
504
505 /**
506  * @brief The method inserts reading information of an accessible object into attributes
507  *
508  * @param control object to append attribute to
509  * @param types Reading information types
510  */
511 DALI_TOOLKIT_API void SetAccessibilityReadingInfoType( Dali::Actor control, const Dali::Accessibility::ReadingInfoTypes types );
512
513 /**
514  * @brief The method returns reading information of an accessible object
515  *
516  * @param control object to append attribute to
517  * @return Reading information types
518  */
519 DALI_TOOLKIT_API Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType( Dali::Actor control );
520
521 /**
522  * @brief The method erases highlight.
523  *
524  * @param control object to append attribute to
525  * @return bool value, false when it is not possible or something went wrong, at the other way true.
526  */
527 DALI_TOOLKIT_API bool ClearAccessibilityHighlight( Dali::Actor control );
528
529 /**
530  * @brief The method grabs highlight.
531  *
532  * @param control object to append attribute to
533  * @return bool value, false when it is not possible or something went wrong, at the other way true.
534  */
535 DALI_TOOLKIT_API bool GrabAccessibilityHighlight( Dali::Actor control );
536
537 /**
538  * @brief The metod presents bitset of control's states.
539  *
540  * @param control object to append attribute to
541  * @return Dali::Accessibility::States is vector of enumerated State.
542  */
543 DALI_TOOLKIT_API Dali::Accessibility::States GetAccessibilityStates( Dali::Actor control );
544
545 /**
546  * @brief The method force sending notifications about current states to accessibility clients
547  *
548  * @param control object to append attribute to
549  * @param states      mask with states expected to broadcast
550  * @param doRecursive flag pointing if notifications of children's state would be sent
551  */
552 DALI_TOOLKIT_API void NotifyAccessibilityStateChange( Dali::Actor control, Dali::Accessibility::States states, bool doRecursive );
553
554 /**
555  * The method allows to set specific constructor for creating accessibility structure
556  *
557  * Thank to this method hierarchy of accessibility objects can be based on internal hierarchy of Actors.
558  * It prevents from necessity of keeping two trees synchronized.
559  * The method should be called inside OnInitialize method of all classes inheriting from Control.
560  *
561  * Possible usage can be as follows:
562  * @code
563  *   SetAccessibilityConstructor( []( Dali::Actor actor ) {
564        return std::unique_ptr< Dali::Accessibility::Accessible >(
565        new AccessibleImpl( actor, Dali::Accessibility::Role::DIALOG, true ) );
566       } );
567   * @endcode
568   *
569   * param constructor callback creating Accessible object
570   */
571 DALI_TOOLKIT_API void SetAccessibilityConstructor( Dali::Actor control, std::function<std::unique_ptr<Dali::Accessibility::Accessible>(Dali::Actor)> constructor);
572
573 /**
574  * Returns accessibility object bound to actor, if any
575  *
576  * This method won't bound new accessibility object. Use Dali::Accessibility::Accessible::Get in that case.
577  */
578 DALI_TOOLKIT_API Dali::Accessibility::Accessible *GetBoundAccessibilityObject( Dali::Actor control );
579
580 } // namespace DevelControl
581
582 } // namespace Toolkit
583
584 } // namespace Dali
585
586 #endif // DALI_TOOLKIT_CONTROL_DEVEL_H