summaryrefslogtreecommitdiff
path: root/dali/devel-api/adaptor-framework/accessibility.h
blob: a8d0d35d5b565c05071b984a161a3257af5c3963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
#ifndef DALI_ATSPI_ACCESSIBILITY_H
#define DALI_ATSPI_ACCESSIBILITY_H
/*
 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

// EXTERNAL INCLUDES

#include <string.h>
#include <array>
#include <atomic>
#include <bitset>
#include <cassert>
#include <exception>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

// INTERNAL INCLUDES
#include <dali/public-api/dali-adaptor-common.h>

namespace Dali
{
namespace Accessibility
{
/**
 * @brief Enumeration describing a relation between accessible objects
 * 1 to 0..N relation model is supported. By default relation is not symmetrical.
 * Symmetry must be explicitly maintained.
 */
enum class RelationType : uint32_t
{
  NULL_OF,          ///< Null Relation.
  LABEL_FOR,        ///< Label For.
  LABELLED_BY,      ///< Labelled By.
  CONTROLLER_FOR,   ///< Controller For.
  CONTROLLED_BY,    ///< Controlled By.
  MEMBER_OF,        ///< Member Of.
  TOOLTIP_FOR,      ///< ToolTip For.
  NODE_CHILD_OF,    ///< Node Child Of.
  NODE_PARENT_OF,   ///< Node Parent Of.
  EXTENDED,         ///< Extended.
  FLOWS_TO,         ///< Flows To.
  FLOWS_FROM,       ///< Flows From.
  SUBWINDOW_OF,     ///< Sub Window Of.
  EMBEDS,           ///< Embeds.
  EMBEDDED_BY,      ///< Embedded By.
  POPUP_FOR,        ///< Popup For
  PARENT_WINDOW_OF, ///< Parent Window Of.
  DESCRIPTION_FOR,  ///< Description For.
  DESCRIBED_BY,     ///< Described By.
  DETAILS,          ///< Details.
  DETAILS_FOR,      ///< Details For.
  ERROR_MESSAGE,    ///< Error Message.
  ERROR_FOR,        ///< Error For.
  MAX_COUNT
};

/**
 * @brief Enumeration describing if coordinates are relative to screen or window
 * @see Accessibility::Component::GetExtents
 * @see Accessibility::Component::Contains
 */
enum class CoordType
{
  SCREEN, ///< Screen.
  WINDOW  ///< Window.
};

/**
 * @brief Enumeration indicating relative stacking order
 * ComponentLayer allows to describe visibility of all parts of UI
 * basing on the concrete stacking order
 * @see Accessibility::Component::GetLayer
 * @note currently only ComponentLayer::Window is supported
 */
enum class ComponentLayer
{
  INVALID,    ///< Invalid.
  BACKGROUND, ///< Background.
  CANVAS,     ///< Canvas.
  WIDGET,     ///< Widget.
  MDI,        ///< MDI.
  POPUP,      ///< Popup.
  OVERLAY,    ///< Overlay.
  WINDOW,     ///< Window.
  MAX_COUNT
};

/**
 * @brief Enumeration describing role of the Accessibility object
 * Object can be described by only one role.
 * @see Accessibility::Accessible::GetRole
 */
enum class Role : uint32_t
{
  INVALID,
  ACCELERATOR_LABEL,
  ALERT,
  ANIMATION,
  ARROW,
  CALENDAR,
  CANVAS,
  CHECK_BOX,
  CHECK_MENU_ITEM,
  COLOR_CHOOSER,
  COLUMN_HEADER,
  COMBO_BOX,
  DATE_EDITOR,
  DESKTOP_ICON,
  DESKTOP_FRAME,
  DIAL,
  DIALOG,
  DIRECTORY_PANE,
  DRAWING_AREA,
  FILE_CHOOSER,
  FILLER,
  FOCUS_TRAVERSABLE,
  FONT_CHOOSER,
  FRAME,
  GLASS_PANE,
  HTML_CONTAINER,
  ICON,
  IMAGE,
  INTERNAL_FRAME,
  LABEL,
  LAYERED_PANE,
  LIST,
  LIST_ITEM,
  MENU,
  MENU_BAR,
  MENU_ITEM,
  OPTION_PANE,
  PAGE_TAB,
  PAGE_TAB_LIST,
  PANEL,
  PASSWORD_TEXT,
  POPUP_MENU,
  PROGRESS_BAR,
  PUSH_BUTTON,
  RADIO_BUTTON,
  RADIO_MENU_ITEM,
  ROOT_PANE,
  ROW_HEADER,
  SCROLL_BAR,
  SCROLL_PANE,
  SEPARATOR,
  SLIDER,
  SPIN_BUTTON,
  SPLIT_PANE,
  STATUS_BAR,
  TABLE,
  TABLE_CELL,
  TABLE_COLUMN_HEADER,
  TABLE_ROW_HEADER,
  TEAROFF_MENU_ITEM,
  TERMINAL,
  TEXT,
  TOGGLE_BUTTON,
  TOOL_BAR,
  TOOL_TIP,
  TREE,
  TREE_TABLE,
  UNKNOWN,
  VIEWPORT,
  WINDOW,
  EXTENDED,
  HEADER,
  FOOTER,
  PARAGRAPH,
  RULER,
  APPLICATION,
  AUTOCOMPLETE,
  EDITBAR,
  EMBEDDED,
  ENTRY,
  CHART,
  CAPTION,
  DOCUMENT_FRAME,
  HEADING,
  PAGE,
  SECTION,
  REDUNDANT_OBJECT,
  FORM,
  LINK,
  INPUT_METHOD_WINDOW,
  TABLE_ROW,
  TREE_ITEM,
  DOCUMENT_SPREADSHEET,
  DOCUMENT_PRESENTATION,
  DOCUMENT_TEXT,
  DOCUMENT_WEB,
  DOCUMENT_EMAIL,
  COMMENT,
  LIST_BOX,
  GROUPING,
  IMAGE_MAP,
  NOTIFICATION,
  INFO_BAR,
  LEVEL_BAR,
  TITLE_BAR,
  BLOCK_QUOTE,
  AUDIO,
  VIDEO,
  DEFINITION,
  ARTICLE,
  LANDMARK,
  LOG,
  MARQUEE,
  MATH,
  RATING,
  TIMER,
  STATIC,
  MATH_FRACTION,
  MATH_ROOT,
  SUBSCRIPT,
  SUPERSCRIPT,
  MAX_COUNT
};

/**
 * @brief Enumeration describing states of the Accessibility object
 * Object can be in many states at the same time.
 * @see Accessibility::Accessible::GetStates
 */
enum class State : uint32_t
{
  INVALID,
  ACTIVE,
  ARMED,
  BUSY,
  CHECKED,
  COLLAPSED,
  DEFUNCT,
  EDITABLE,
  ENABLED,
  EXPANDABLE,
  EXPANDED,
  FOCUSABLE,
  FOCUSED,
  HAS_TOOLTIP,
  HORIZONTAL,
  ICONIFIED,
  MODAL,
  MULTI_LINE,
  MULTI_SELECTABLE,
  OPAQUE,
  PRESSED,
  RESIZEABLE,
  SELECTABLE,
  SELECTED,
  SENSITIVE,
  SHOWING,
  SINGLE_LINE,
  STALE,
  TRANSIENT,
  VERTICAL,
  VISIBLE,
  MANAGES_DESCENDANTS,
  INDETERMINATE,
  REQUIRED,
  TRUNCATED,
  ANIMATED,
  INVALID_ENTRY,
  SUPPORTS_AUTOCOMPLETION,
  SELECTABLE_TEXT,
  IS_DEFAULT,
  VISITED,
  CHECKABLE,
  HAS_POPUP,
  READ_ONLY,
  HIGHLIGHTED,
  HIGHLIGHTABLE,
  MAX_COUNT
};

/**
 * @brief Enumeration describing change of text object
 */
enum class TextChangedState : uint32_t
{
  INSERTED,
  DELETED,
  MAX_COUNT
};

/**
 * @brief Enumeration describing change of object property
 */
enum class ObjectPropertyChangeEvent
{
  NAME,
  DESCRIPTION,
  VALUE,
  ROLE,
  PARENT,
};

/**
 * @brief Enumeration describing change of window object
 * @see Accessibility::Accessible::Emit
 */
enum class WindowEvent
{
  PROPERTY_CHANGE,
  MINIMIZE,
  MAXIMIZE,
  RESTORE,
  CLOSE,
  CREATE,
  REPARENT,
  DESKTOP_CREATE,
  DESKTOP_DESTROY,
  DESTROY,
  ACTIVATE,
  DEACTIVATE,
  RAISE,
  LOWER,
  MOVE,
  RESIZE,
  SHADE,
  UU_SHADE,
  RESTYLE,
};

/**
 * @brief Enumeration used to acquire bounded text from accessible object having textual content.
 * @see Accessibility::Text::GetTextAtOffset
 * @note Currently only TextBoundary::Character is supported
 */
enum class TextBoundary : uint32_t
{
  CHARACTER, ///> Only one character is acquired.
  WORD,      ///> Not supported.
  SENTENCE,  ///> Not supported.
  LINE,      ///> Not supported.
  PARAGRAPH, ///> Not supported.
  MAX_COUNT
};

/**
 * @brief Enumeration describing type of gesture
 * @see Accessibility::Accessible::DoGesture
 */
enum class Gesture : int32_t
{
  ONE_FINGER_HOVER,
  TWO_FINGER_HOVER,
  THREE_FINGER_HOVER,
  ONE_FINGER_FLICK_LEFT,
  ONE_FINGER_FLICK_RIGHT,
  ONE_FINGER_FLICK_UP,
  ONE_FINGER_FLICK_DOWN,
  TWO_FINGERS_FLICK_LEFT,
  TWO_FINGERS_FLICK_RIGHT,
  TWO_FINGERS_FLICK_UP,
  TWO_FINGERS_FLICK_DOWN,
  THREE_FINGERS_FLICK_LEFT,
  THREE_FINGERS_FLICK_RIGHT,
  THREE_FINGERS_FLICK_UP,
  THREE_FINGERS_FLICK_DOWN,
  ONE_FINGER_SINGLE_TAP,
  ONE_FINGER_DOUBLE_TAP,
  ONE_FINGER_TRIPLE_TAP,
  TWO_FINGERS_SINGLE_TAP,
  TWO_FINGERS_DOUBLE_TAP,
  TWO_FINGERS_TRIPLE_TAP,
  THREE_FINGERS_SINGLE_TAP,
  THREE_FINGERS_DOUBLE_TAP,
  THREE_FINGERS_TRIPLE_TAP,
  ONE_FINGER_FLICK_LEFT_RETURN,
  ONE_FINGER_FLICK_RIGHT_RETURN,
  ONE_FINGER_FLICK_UP_RETURN,
  ONE_FINGER_FLICK_DOWN_RETURN,
  TWO_FINGERS_FLICK_LEFT_RETURN,
  TWO_FINGERS_FLICK_RIGHT_RETURN,
  TWO_FINGERS_FLICK_UP_RETURN,
  TWO_FINGERS_FLICK_DOWN_RETURN,
  THREE_FINGERS_FLICK_LEFT_RETURN,
  THREE_FINGERS_FLICK_RIGHT_RETURN,
  THREE_FINGERS_FLICK_UP_RETURN,
  THREE_FINGERS_FLICK_DOWN_RETURN,
  ONE_FINGER_DOUBLE_TAP_N_HOLD,
  TWO_FINGERS_DOUBLE_TAP_N_HOLD,
  THREE_FINGERS_DOUBLE_TAP_N_HOLD,
  MAX_COUNT
};

/**
 * @brief Enumeration indicating current state of gesture
 * @see Dali::Accessibility::GestureInfo
 */
enum class GestureState : int32_t
{
  BEGIN,
  ONGOING,
  ENDED,
  ABORTED
};

/**
 * @brief Enumeration of ReadingInfoType
 */
enum class ReadingInfoType
{
  NAME,
  ROLE,
  DESCRIPTION,
  STATE
};

/**
 * @brief Helper class for storing values treated as bit sets
 * This class provides all bitset-like methods for bitset size larger, than long long int
 * @see Dali::Accessibility::Accessible::GetStates
 * @see Dali::Accessibility::Accessible::GetRoles
 */
template<size_t I, typename S>
class BitSets
{
  std::array<uint32_t, I> data;

  void _set()
  {
  }

  static constexpr bool _accepts()
  {
    return true;
  }

  template<typename T>
  static constexpr bool _accepts()
  {
    return std::is_enum<T>::value;
  }

  template<typename T, typename T2, typename... ARGS>
  static constexpr bool _accepts()
  {
    return std::is_enum<T>::value && _accepts<T2, ARGS...>();
  }

  template<typename T, typename... ARGS>
  void _set(T t, ARGS... args)
  {
    (*this)[t] = true;
    _set(args...);
  }

public:
  BitSets()
  {
    for(auto& u : data)
    {
      u = 0;
    }
  }
  BitSets(const BitSets&) = default;
  BitSets(BitSets&&)      = default;

  template<typename T, typename... ARGS, typename std::enable_if<_accepts<T, ARGS...>()>::type* = nullptr>
  BitSets(T t, ARGS... args)
  {
    for(auto& u : data)
      u = 0;
    _set(t, args...);
  }

  explicit BitSets(std::array<uint32_t, I> d)
  {
    for(auto i = 0u; i < I; ++i)
    {
      data[i] = d[i];
    }
  }

  explicit BitSets(std::array<int32_t, I> d)
  {
    for(auto i = 0u; i < I; ++i)
    {
      data[i] = static_cast<uint32_t>(d[i]);
    }
  }

  BitSets& operator=(const BitSets&) = default;
  BitSets& operator=(BitSets&&) = default;

  struct reference
  {
    std::array<uint32_t, I>& data;
    size_t                   pos;

    reference& operator=(reference r)
    {
      (*this) = static_cast<bool>(r);
      return *this;
    }

    reference& operator=(bool v)
    {
      if(v)
      {
        data[pos / 32] |= 1 << (pos & 31);
      }
      else
      {
        data[pos / 32] &= ~(1 << (pos & 31));
      }
      return *this;
    }

    operator bool() const
    {
      auto i = static_cast<size_t>(pos);
      return (data[i / 32] & (1 << (i & 31))) != 0;
    }
  };

  reference operator[](S index)
  {
    return {data, static_cast<size_t>(index)};
  }

  bool operator[](S index) const
  {
    auto i = static_cast<size_t>(index);
    return (data[i / 32] & (1 << (i & 31))) != 0;
  }

  std::array<uint32_t, I> GetRawData() const
  {
    return data;
  }

  BitSets operator|(BitSets b) const
  {
    BitSets r;
    for(auto i = 0u; i < I; ++i)
    {
      r.data[i] = data[i] | b.data[i];
    }
    return r;
  }

  BitSets operator^(BitSets b) const
  {
    BitSets r;
    for(auto i = 0u; i < I; ++i)
    {
      r.data[i] = data[i] ^ b.data[i];
    }
    return r;
  }

  BitSets operator&(BitSets b) const
  {
    BitSets r;
    for(auto i = 0u; i < I; ++i)
    {
      r.data[i] = data[i] & b.data[i];
    }
    return r;
  }

  bool operator==(BitSets b) const
  {
    for(auto i = 0u; i < I; ++i)
    {
      if(data[i] != b.data[i])
      {
        return false;
      }
    }
    return true;
  }

  bool operator!=(BitSets b) const
  {
    return !((*this) == b);
  }

  explicit operator bool() const
  {
    for(auto& u : data)
    {
      if(u)
      {
        return true;
      }
    }
    return false;
  }

  size_t size() const
  {
    return I;
  }
};

using ReadingInfoTypes = BitSets<1, ReadingInfoType>;
using States           = BitSets<2, State>;
using Attributes       = std::unordered_map<std::string, std::string>;

/**
 * @brief Class representing unique object address on accessibility bus
 * @see Dali::Accessibility::Accessible::GetAddress
 */
class DALI_ADAPTOR_API Address
{
public:
  Address() = default;

  Address(std::string bus, std::string path)
  : mBus(std::move(bus)),
    mPath(std::move(path))
  {
  }

  explicit operator bool() const
  {
    return !mPath.empty();
  }

  std::string ToString() const
  {
    return *this ? mBus + ":" + mPath : "::null";
  }

  const std::string& GetBus() const;

  const std::string& GetPath() const
  {
    return mPath;
  }

  bool operator==(const Address& a) const
  {
    return mBus == a.mBus && mPath == a.mPath;
  }

  bool operator!=(const Address& a) const
  {
    return !(*this == a);
  }

private:
  mutable std::string mBus, mPath;
};

/**
 * @brief Enumeration describing type of key event
 * @see Adaptor::AccessibilityObserver::OnAccessibleKeyEvent
 */
enum class KeyEventType
{
  KEY_PRESSED,
  KEY_RELEASED,
};

/**
 * @brief Enumeration with human readable values describing state of event
 * @see Dali::Accessibility::Bridge::Emit
 */
enum class Consumed
{
  NO,
  YES
};

/**
 * @brief Helper class representing two dimensional point with integer coordinates
 */
struct DALI_ADAPTOR_API Point
{
  int x = 0;
  int y = 0;

  Point() = default;

  Point(int x, int y)
  : x(x),
    y(y)
  {
  }

  bool operator==(Point p) const
  {
    return x == p.x && y == p.y;
  }
  bool operator!=(Point p) const
  {
    return !(*this == p);
  }
};

/**
* @brief Helper class representing size of rectangle object with usage of two integer values
*/
struct DALI_ADAPTOR_API Size
{
  int width  = 0;
  int height = 0;

  Size() = default;

  Size(int w, int h)
  : width(w),
    height(h)
  {
  }

  bool operator==(Size p) const
  {
    return width == p.width && height == p.height;
  }

  bool operator!=(Size p) const
  {
    return !(*this == p);
  }
};

/**
 * @brief Helper class used to store data related with Accessibility::Text interface
 * @see Dali::Accessibility::Text::GetTextAtOffset
 * @see Dali::Accessibility::Text::GetSelection
 */
struct DALI_ADAPTOR_API Range
{
  int32_t     startOffset = 0;
  int32_t     endOffset   = 0;
  std::string content;

  Range() = default;

  Range(size_t start, size_t end)
  : startOffset(start),
    endOffset(end)
  {
  }

  Range(size_t start, size_t end, std::string content)
  : startOffset(start),
    endOffset(end),
    content(content)
  {
  }
};

/**
 * @brief Structure containing all values needed to invoke Accessible::DoGesture
 * type : numerated gesture type
 * xBeg, yBeg : point where gesture begins
 * xEnd, yEnd : point where gesture ends
 * state : enumerated state of gesture
 * eventTime : time when event occured
 * @see Dali::Accessibility::Accessible::DoGesture
 */
struct DALI_ADAPTOR_API GestureInfo
{
  GestureInfo() = default;
  GestureInfo(Gesture type, int32_t xBeg, int32_t xEnd, int32_t yBeg, int32_t yEnd, GestureState state, uint32_t eventTime)
  : type(type),
    xBeg(xBeg),
    xEnd(xEnd),
    yBeg(yBeg),
    yEnd(yEnd),
    state(state),
    eventTime(eventTime)
  {
  }

  Gesture      type{};
  int32_t      xBeg{};
  int32_t      xEnd{};
  int32_t      yBeg{};
  int32_t      yEnd{};
  GestureState state{};
  uint32_t     eventTime{};
};

/**
 * @brief Class representing accessibility relations
 * Class connecting one source object with multiple target objects with usage
 * of specific relation type.
 * @note std::string representing source and targets are string values of Accessibility::Address
 * @see Dali::Accessibility::Accessible::Address
 * @see Dali::Accessibility::Accessible::RelationType
 */
struct DALI_ADAPTOR_API Relation
{
  Relation(RelationType relationType, std::vector<Address> targets)
  : relationType(relationType),
    targets(targets)
  {
  }

  RelationType         relationType;
  std::vector<Address> targets;
};

} // namespace Accessibility
} // namespace Dali

#endif // DALI_ATSPI_ACCESSIBILITY_H