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