6faa6f5aee3731f1da46d49b74bcab2bbdf272ba
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / accessibility.h
1 #ifndef __DALI_ACCESSIBILITY_H__
2 #define __DALI_ACCESSIBILITY_H__
3
4 #include <dali/public-api/actors/actor.h>
5
6 #include <atomic>
7 #include <bitset>
8 #include <exception>
9 #include <functional>
10 #include <memory>
11 #include <string>
12 #include <unordered_map>
13 #include <vector>
14
15 namespace Dali
16 {
17 class Actor;
18
19 namespace Accessibility
20 {
21 enum class RelationType
22 {
23   FlowsFrom,
24   FlowsTo
25 };
26
27 enum class MatchType : int32_t
28 {
29   Invalid,
30   All,
31   Any,
32   None,
33   Empty
34 };
35
36 enum class SortOrder : uint32_t
37 {
38   Invalid,
39   Canonical,
40   Flow,
41   Tab,
42   ReverseCanonical,
43   ReverseFlow,
44   ReverseTab,
45   LastDefined
46 };
47
48 enum class CoordType
49 {
50   Screen,
51   Window
52 };
53
54 enum class NeighborSearchDirection
55 {
56   Forward,
57   Backward
58 };
59
60 enum class ComponentLayer
61 {
62   Invalid,
63   Background,
64   Canvas,
65   Widget,
66   Mdi,
67   Popup,
68   Overlay,
69   Window,
70   LastDefined,
71 };
72
73 enum class Role : uint32_t
74 {
75   Invalid,
76   AcceleratorLabel,
77   Alert,
78   Animation,
79   Arrow,
80   Calendar,
81   Canvas,
82   CheckBox,
83   CheckMenuItem,
84   ColorChooser,
85   ColumnHeader,
86   ComboBox,
87   DateEditor,
88   DesktopIcon,
89   DesktopFrame,
90   Dial,
91   Dialog,
92   DirectoryPane,
93   DrawingArea,
94   FileChooser,
95   Filler,
96   FocusTraversable,
97   FontChooser,
98   Frame,
99   GlassPane,
100   HtmlContainer,
101   Icon,
102   Image,
103   InternalFrame,
104   Label,
105   LayeredPane,
106   List,
107   ListItem,
108   Menu,
109   MenuBar,
110   MenuItem,
111   OptionPane,
112   PageTab,
113   PageTabList,
114   Panel,
115   PasswordText,
116   PopupMenu,
117   ProgressBar,
118   PushButton,
119   RadioButton,
120   RadioMenuItem,
121   RootPane,
122   RowHeader,
123   ScrollBar,
124   ScrollPane,
125   Separator,
126   Slider,
127   SpinButton,
128   SplitPane,
129   StatusBar,
130   Table,
131   TableCell,
132   TableColumnHeader,
133   TableRowHeader,
134   TearoffMenuItem,
135   Terminal,
136   Text,
137   ToggleButton,
138   ToolBar,
139   ToolTip,
140   Tree,
141   TreeTable,
142   Unknown,
143   Viewport,
144   Window,
145   Extended,
146   Header,
147   Footer,
148   Paragraph,
149   Ruler,
150   Application,
151   Autocomplete,
152   Editbar,
153   Embedded,
154   Entry,
155   Chart,
156   Caption,
157   DocumentFrame,
158   Heading,
159   Page,
160   Section,
161   RedundantObject,
162   Form,
163   Link,
164   InputMethodWindow,
165   TableRow,
166   TreeItem,
167   DocumentSpreadsheet,
168   DocumentPresentation,
169   DocumentText,
170   DocumentWeb,
171   DocumentEmail,
172   Comment,
173   ListBox,
174   Grouping,
175   ImageMap,
176   Notification,
177   InfoBar,
178   LevelBar,
179   TitleBar,
180   BlockQuote,
181   Audio,
182   Video,
183   Definition,
184   Article,
185   Landmark,
186   Log,
187   Marquee,
188   Math,
189   Rating,
190   Timer,
191   Static,
192   MathFraction,
193   MathRoot,
194   Subscript,
195   Superscript,
196   _Count,
197 };
198
199 enum class State : uint32_t
200 {
201   Invalid,
202   Active,
203   Armed,
204   Busy,
205   Checked,
206   Collapsed,
207   Defunct,
208   Editable,
209   Enabled,
210   Expandable,
211   Expanded,
212   Focusable,
213   Focused,
214   HasTooltip,
215   Horizontal,
216   Iconified,
217   Modal,
218   MultiLine,
219   MultiSelectable,
220   Opaque,
221   Pressed,
222   Resizeable,
223   Selectable,
224   Selected,
225   Sensitive,
226   Showing,
227   SingleLine,
228   Stale,
229   Transient,
230   Vertical,
231   Visible,
232   ManagesDescendants,
233   Indeterminate,
234   Required,
235   Truncated,
236   Animated,
237   InvalidEntry,
238   SupportsAutocompletion,
239   SelectableText,
240   IsDefault,
241   Visited,
242   Checkable,
243   HasPopup,
244   ReadOnly,
245   Highlighted,
246   Highlightable,
247   _Count
248 };
249
250 enum class WindowEvent
251 {
252   PropertyChange,
253   Minimize,
254   Maximize,
255   Restore,
256   Close,
257   Create,
258   Reparent,
259   DesktopCreate,
260   DesktopDestroy,
261   Destroy,
262   Activate,
263   Deactivate,
264   Raise,
265   Lower,
266   Move,
267   Resize,
268   Shade,
269   UuShade,
270   Restyle,
271 };
272
273 enum class TextBoundary : uint32_t
274 {
275   Character,
276   WordStart,
277   WordEnd,
278   SentenceStart,
279   SentenceEnd,
280   LineStart,
281   LineEnd,
282   _Count
283 };
284
285 template < size_t I, typename S >
286 class BitStates
287 {
288   std::array< uint32_t, I > data;
289
290 public:
291   BitStates()
292   {
293     for( auto& u : data )
294       u = 0;
295   }
296   explicit BitStates( std::array< uint32_t, I > d )
297   {
298     for( auto i = 0u; i < I; ++i )
299       data[i] = d[i];
300   }
301   explicit BitStates( std::array< int32_t, I > d )
302   {
303     for( auto i = 0u; i < I; ++i )
304       data[i] = static_cast< uint32_t >( d[i] );
305   }
306
307   struct reference
308   {
309     std::array< uint32_t, I >& data;
310     size_t pos;
311     bool operator=( reference r )
312     {
313       return ( *this ) = static_cast< bool >( r );
314     }
315     bool operator=( bool v )
316     {
317       if( v )
318         data[pos / 32] |= 1 << ( pos & 31 );
319       else
320         data[pos / 32] &= ~( 1 << ( pos & 31 ) );
321       return v;
322     }
323     operator bool() const
324     {
325       auto i = static_cast< size_t >( pos );
326       return ( data[i / 32] & ( 1 << ( i & 31 ) ) ) != 0;
327     }
328   };
329   reference operator[]( S index ) { return {data, static_cast< size_t >( index )}; }
330   bool operator[]( S index ) const
331   {
332     auto i = static_cast< size_t >( index );
333     return ( data[i / 32] & ( 1 << ( i & 31 ) ) ) != 0;
334   }
335   std::array< uint32_t, I > GetRawData() const { return data; }
336
337   BitStates operator|( BitStates b ) const
338   {
339     BitStates r;
340     for( auto i = 0u; i < I; ++i )
341       r.data[i] = data[i] | b.data[i];
342     return r;
343   }
344   BitStates operator&( BitStates b ) const
345   {
346     BitStates r;
347     for( auto i = 0u; i < I; ++i )
348       r.data[i] = data[i] & b.data[i];
349     return r;
350   }
351   bool operator==( BitStates b ) const
352   {
353     for( auto i = 0u; i < I; ++i )
354       if( data[i] != b.data[i] )
355         return false;
356     return true;
357   }
358   explicit operator bool() const
359   {
360     for( auto& u : data )
361       if( u )
362         return true;
363     return false;
364   }
365 };
366
367 using States = BitStates< 2, State >;
368 using Attributes = std::unordered_map< std::string, std::string >;
369
370 class DALI_IMPORT_API Address
371 {
372 public:
373   Address() = default;
374   Address( std::string bus, std::string path ) : bus( std::move( bus ) ), path( std::move( path ) ) {}
375
376   explicit operator bool() const { return !path.empty(); }
377   std::string ToString() const
378   {
379     return *this ? bus + ":" + path : "::null";
380   }
381   const std::string& GetBus() const { return bus; }
382   const std::string& GetPath() const { return path; }
383
384 private:
385   std::string bus, path;
386 };
387
388 enum class KeyEventType
389 {
390   KeyPressed,
391   KeyReleased,
392 };
393 enum class Consumed
394 {
395   No,
396   Yes
397 };
398 struct DALI_IMPORT_API Point
399 {
400   int x = 0;
401   int y = 0;
402
403   Point() = default;
404   Point( int x, int y ) : x( x ), y( y ) {}
405
406   bool operator==( Point p ) const
407   {
408     return x == p.x && y == p.y;
409   }
410   bool operator!=( Point p ) const
411   {
412     return !( *this == p );
413   }
414 };
415
416 struct DALI_IMPORT_API Size
417 {
418   int width = 0;
419   int height = 0;
420
421   Size() = default;
422   Size( int w, int h ) : width( w ), height( h ) {}
423
424   bool operator==( Size p ) const
425   {
426     return width == p.width && height == p.height;
427   }
428   bool operator!=( Size p ) const
429   {
430     return !( *this == p );
431   }
432 };
433
434 struct DALI_IMPORT_API Rectangle
435 {
436   Point position;
437   Size size;
438
439   bool operator==( Rectangle p ) const
440   {
441     return position == p.position && size == p.size;
442   }
443   bool operator!=( Rectangle p ) const
444   {
445     return !( *this == p );
446   }
447 };
448 struct DALI_IMPORT_API Range
449 {
450   int startOffset = 0;
451   int endOffset = 0;
452   std::string content;
453
454   Range() = default;
455   Range( size_t start, size_t end ) : startOffset( start ), endOffset( end )
456   {
457   }
458   Range( size_t start, size_t end, std::string content ) : startOffset( start ), endOffset( end ), content( content )
459   {
460   }
461 };
462
463 class DALI_IMPORT_API AccessibleError : public std::exception
464 {
465 public:
466   AccessibleError( std::string msg ) : msg( std::move( msg ) ) {}
467   const char* what() const noexcept override { return msg.c_str(); }
468
469 private:
470   std::string msg;
471 };
472 }
473 }
474
475 namespace std
476 {
477 template <>
478 struct hash< Dali::Accessibility::Point >
479 {
480   size_t operator()( Dali::Accessibility::Point p )
481   {
482     return static_cast< size_t >( p.x ) ^ ( static_cast< size_t >( p.y ) * 11 );
483   }
484 };
485 template <>
486 struct hash< Dali::Accessibility::Size >
487 {
488   size_t operator()( Dali::Accessibility::Size p )
489   {
490     return static_cast< size_t >( p.width ) ^ ( static_cast< size_t >( p.height ) * 11 );
491   }
492 };
493 template <>
494 struct hash< Dali::Accessibility::Rectangle >
495 {
496   size_t operator()( Dali::Accessibility::Rectangle p )
497   {
498     return hash< Dali::Accessibility::Point >()( p.position ) ^ ( hash< Dali::Accessibility::Size >()( p.size ) * 11 );
499   }
500 };
501 }
502
503 #endif