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