[AT-SPI] Add Dali::AtspiAccessibility::StopReading()
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / accessibility-impl.h
1 #ifndef DALI_INTERNAL_ATSPI_ACCESSIBILITY_IMPL_H
2 #define DALI_INTERNAL_ATSPI_ACCESSIBILITY_IMPL_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
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/object/object-registry.h>
25 #include <atomic>
26 #include <bitset>
27 #include <exception>
28 #include <functional>
29 #include <memory>
30 #include <stdexcept>
31 #include <string>
32 #include <unordered_map>
33 #include <unordered_set>
34 #include <vector>
35
36 //INTERNAL INCLUDES
37 #include <dali/devel-api/adaptor-framework/accessibility.h>
38 #include <dali/integration-api/debug.h>
39
40 namespace Dali
41 {
42 namespace Accessibility
43 {
44 class DALI_ADAPTOR_API Accessible;
45 class DALI_ADAPTOR_API Text;
46 class DALI_ADAPTOR_API Value;
47 class DALI_ADAPTOR_API Component;
48 class DALI_ADAPTOR_API Collection;
49 class DALI_ADAPTOR_API Action;
50
51 /**
52  * @brief Base class for different accessibility bridges
53  *
54  * Bridge is resposible for initializing and managing connection on accessibility bus.
55  * Accessibility clients will not get any information about UI without initialized and upraised bridge.
56  * Concrete implementation depends on the accessibility technology available on the platform.
57  *
58  * @note This class is singleton.
59  */
60 struct DALI_ADAPTOR_API Bridge
61 {
62   enum class ForceUpResult
63   {
64     JUST_STARTED,
65     ALREADY_UP
66   };
67
68   /**
69    * @brief Destructor
70    */
71   virtual ~Bridge() = default;
72
73   /**
74    * @brief Get bus name which bridge is initialized on
75    */
76   virtual const std::string& GetBusName() const = 0;
77
78   /**
79    * @brief Registers top level window
80    *
81    * Hierarchy of objects visible for accessibility clients is based on tree-like
82    * structure created from Actors objects. This method allows to connect chosen
83    * object as direct ancestor of application and therefore make it visible for
84    * accessibility clients.
85    */
86   virtual void AddTopLevelWindow(Accessible*) = 0;
87
88   /**
89    * @brief Removes top level window
90    *
91    * Hierarchy of objects visible for accessibility clients is based on tree-like
92    * structure created from Actors objects. This method removes previously added
93    * window from visible accessibility objects.
94    */
95   virtual void RemoveTopLevelWindow(Accessible*) = 0;
96
97   /**
98    * @brief Adds popup window
99    *
100    * Hierarchy of objects visible for accessibility clients is based on tree-like
101    * structure created from Actors objects. This method adds new popup to the tree.
102    */
103   virtual void AddPopup(Accessible*) = 0;
104
105   /**
106    * @brief Removes popup window
107    *
108    * Hierarchy of objects visible for accessibility clients is based on tree-like
109    * structure created from Actors objects. This method removes previously added
110    * popup window.
111    */
112   virtual void RemovePopup(Accessible*) = 0;
113
114   /**
115    * @brief Set name of current application which will be visible on accessibility bus
116    */
117   virtual void SetApplicationName(std::string) = 0;
118
119   /**
120    * @brief Get object being root of accessibility tree
121    *
122    * @return handler to accessibility object
123    */
124   virtual Accessible* GetApplication() const = 0;
125
126   /**
127    * @brief Find an object in accessibility tree
128    *
129    * @param[in] s path to object
130    *
131    * @return handler to accessibility object
132    */
133   virtual Accessible* FindByPath(const std::string& s) const = 0;
134
135   /**
136    * @brief Show application on accessibility bus
137    */
138   virtual void ApplicationShown() = 0;
139
140   /**
141    * @brief Hide application on accessibility bus
142    */
143   virtual void ApplicationHidden() = 0;
144
145   /**
146    * @brief Initialize accessibility bus
147    */
148   virtual void Initialize() = 0;
149
150   /**
151    * @brief Terminate accessibility bus
152    */
153   virtual void Terminate() = 0;
154
155   /**
156    * @brief This method is called, when bridge is being activated.
157    */
158   virtual ForceUpResult ForceUp()
159   {
160     if(data)
161     {
162       return ForceUpResult::ALREADY_UP;
163     }
164     data         = std::make_shared<Data>();
165     data->bridge = this;
166     return ForceUpResult::JUST_STARTED;
167   }
168
169   /**
170    * @brief This method is called, when bridge is being deactivated.
171    */
172   virtual void ForceDown() = 0;
173
174   /**
175    * @brief Check if bridge is activated or not.
176    * @return True if brige is activated.
177    */
178   bool IsUp() const
179   {
180     return bool(data);
181   }
182
183   /**
184    * @brief Emits caret-moved event on at-spi bus.
185    **/
186   virtual void EmitCaretMoved(Accessible* obj, unsigned int cursorPosition) = 0;
187
188   /**
189    * @brief Emits active-descendant-changed event on at-spi bus.
190    **/
191   virtual void EmitActiveDescendantChanged(Accessible* obj, Accessible* child) = 0;
192
193   /**
194    * @brief Emits text-changed event on at-spi bus.
195    **/
196   virtual void EmitTextChanged(Accessible* obj, TextChangedState state, unsigned int position, unsigned int length, const std::string& content) = 0;
197
198   /**
199    * @brief Emits state-changed event on at-spi bus.
200    **/
201   virtual void EmitStateChanged(Accessible* obj, State state, int val1, int val2 = 0) = 0;
202
203   /**
204    * @brief Emits window event on at-spi bus.
205    **/
206   virtual void Emit(Accessible* obj, WindowEvent we, unsigned int detail1 = 0) = 0;
207
208   /**
209    * @brief Emits property-changed event on at-spi bus.
210    **/
211   virtual void Emit(Accessible* obj, ObjectPropertyChangeEvent event) = 0;
212
213   /**
214    * @brief Emits bounds-changed event on at-spi bus.
215    **/
216   virtual void EmitBoundsChanged(Accessible* obj, Rect<> rect) = 0;
217
218   /**
219    * @brief Emits key event on at-spi bus.
220    *
221    * Screen-reader might receive this event and reply, that given keycode is consumed. In that case
222    * further processing of the keycode should be ignored.
223    **/
224   virtual Consumed Emit(KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) = 0;
225
226   /**
227    * @brief Reads given text by screen reader
228    *
229    * @param text The text to read
230    * @param discardable If TRUE, reading can be discarded by subsequent reading requests,
231    * if FALSE the reading must finish before next reading request can be started
232    * @param callback the callback function that is called on reading signals emitted
233    * during processing of this reading request.
234    * Callback can be one of the following signals:
235    * ReadingCancelled, ReadingStopped, ReadingSkipped
236    */
237   virtual void Say(const std::string& text, bool discardable, std::function<void(std::string)> callback) = 0;
238
239   /**
240    * @brief Force accessibility client to pause.
241    */
242   virtual void Pause() = 0;
243
244   /**
245    * @brief Force accessibility client to resume.
246    */
247   virtual void Resume() = 0;
248
249   /**
250    * @brief Cancels anything screen-reader is reading / has queued to read
251    *
252    * @param alsoNonDiscardable whether to cancel non-discardable readings as well
253    */
254   virtual void StopReading(bool alsoNonDiscardable) = 0;
255
256   /**
257    * @brief Get screen reader status.
258    */
259   virtual bool GetScreenReaderEnabled() = 0;
260
261   /**
262    * @brief Get ATSPI status.
263    */
264   virtual bool GetIsEnabled() = 0;
265
266   /**
267    * @brief Returns instance of bridge singleton object.
268    **/
269   static Bridge* GetCurrentBridge();
270
271 protected:
272   struct Data
273   {
274     std::unordered_set<Accessible*> knownObjects;
275     std::string                     busName;
276     Bridge*                         bridge = nullptr;
277     Actor                           highlightActor, currentlyHighlightedActor;
278   };
279   std::shared_ptr<Data> data;
280   friend class Accessible;
281
282   /**
283    * @brief Registers accessible object to be known in bridge object
284    *
285    * Bridge must known about all currently alive accessible objects, as some requst
286    * might come and object will be identified by number id (it's memory address).
287    * To avoid memory corruption number id is checked against set of known objects.
288    **/
289   void RegisterOnBridge(Accessible*);
290
291   /**
292    * @brief Tells bridge, that given object is considered root (doesn't have any parents).
293    *
294    * All root objects will have the same parent - application object. Application object
295    * is controlled by bridge and private.
296    **/
297   void SetIsOnRootLevel(Accessible*);
298 };
299
300 /**
301  * @brief Check if ATSPI is activated or not.
302  * @return True if ATSPI is activated.
303  */
304 inline bool IsUp()
305 {
306   if(Bridge::GetCurrentBridge() == nullptr)
307   {
308     return false;
309   }
310   if(Bridge::GetCurrentBridge()->GetIsEnabled() == false)
311   {
312     return false;
313   }
314   return Bridge::GetCurrentBridge()->IsUp();
315 }
316
317 /**
318  * @brief Basic interface implemented by all accessibility objects
319  */
320 class Accessible
321 {
322 public:
323   virtual ~Accessible();
324
325   using utf8_t = unsigned char;
326
327   /**
328    * @brief Calculaties word boundaries in given utf8 text.
329    *
330    * s and length represents source text pointer and it's length respectively. langauge represents
331    * language to use. Word boundaries are returned as non-zero values in table breaks, which
332    * must be of size at least length.
333    **/
334   void FindWordSeparationsUtf8(const utf8_t* s, size_t length, const char* language, char* breaks);
335
336   /**
337    * @brief Calculaties line boundaries in given utf8 text.
338    *
339    * s and length represents source text pointer and it's length respectively. langauge represents
340    * language to use. Line boundaries are returned as non-zero values in table breaks, which
341    * must be of size at least length.
342    **/
343   void FindLineSeparationsUtf8(const utf8_t* s, size_t length, const char* language, char* breaks);
344
345   /**
346    * @brief Helper function for emiting active-descendant-changed event
347    **/
348   void EmitActiveDescendantChanged(Accessible* obj, Accessible* child);
349
350   /**
351    * @brief Helper function for emiting state-changed event
352    **/
353   void EmitStateChanged(State state, int newValue1, int newValue2 = 0);
354
355   /**
356    * @brief Helper function for emiting bounds-changed event
357    **/
358   void EmitBoundsChanged(Rect<> rect);
359
360   /**
361    * @brief Emit "showing" event.
362    * The method inform accessibility clients about "showing" state
363    *
364    * @param[in] showing flag pointing if object is showing
365    */
366   void EmitShowing(bool showing);
367
368   /**
369    * @brief Emit "visible" event.
370    * The method inform accessibility clients about "visible" state
371    *
372    * @param[in] visible flag pointing if object is visible
373    */
374   void EmitVisible(bool visible);
375
376   /**
377    * @brief Emit "highlighted" event.
378    * The method inform accessibility clients about "highlighted" state
379    *
380    * @param[in] set flag pointing if object is highlighted
381    */
382   void EmitHighlighted(bool set);
383
384   /**
385    * @brief Emit "focused" event.
386    * The method inform accessibility clients about "focused" state
387    *
388    * @param[in] set flag pointing if object is focused
389    */
390   void EmitFocused(bool set);
391
392   /**
393    * @brief Emit "text inserted" event
394    *
395    * @param[in] position caret position
396    * @param[in] length text length
397    * @param[in] content inserted text
398    */
399   void EmitTextInserted(unsigned int position, unsigned int length, const std::string& content);
400
401   /**
402    * @brief Emit "text deleted" event
403    *
404    * @param[in] position caret position
405    * @param[in] length text length
406    * @param[in] content deleted text
407    */
408   void EmitTextDeleted(unsigned int position, unsigned int length, const std::string& content);
409
410   /**
411    * @brief Emit "caret moved" event
412    *
413    * @param[in] cursorPosition new caret position
414    */
415   void EmitTextCaretMoved(unsigned int cursorPosition);
416
417   /**
418    * @brief Emit "highlighted" event
419    *
420    * @param[in] we enumerated window event
421    * @param[in] detail1 additional parameter which interpretation depends on chosen event
422    */
423   void Emit(WindowEvent we, unsigned int detail1 = 0);
424
425   /**
426    * @brief Emits property-changed event
427    * @param[in] event Property changed event
428    **/
429   void Emit(ObjectPropertyChangeEvent event);
430
431   /**
432    * @brief Get accessibility name
433    *
434    * @return string with name
435    */
436   virtual std::string GetName() = 0;
437
438   /**
439    * @brief Get accessibility description
440    *
441    * @return string with description
442    */
443   virtual std::string GetDescription() = 0;
444
445   /**
446    * @brief Get parent
447    *
448    * @return handler to accessibility object
449    */
450   virtual Accessible* GetParent() = 0;
451
452   /**
453    * @brief Get count of children
454    *
455    * @return unsigned integer value
456    */
457   virtual size_t GetChildCount() = 0;
458
459   /**
460    * @brief Get collection with all children
461    *
462    * @return collection of accessibility objects
463    */
464   virtual std::vector<Accessible*> GetChildren();
465
466   /**
467    * @brief Get nth child
468    *
469    * @return accessibility object
470    */
471   virtual Accessible* GetChildAtIndex(size_t index) = 0;
472
473   /**
474    * @brief Get index that current object has in its parent's children collection
475    *
476    * @return unsigned integer index
477    */
478   virtual size_t GetIndexInParent() = 0;
479
480   /**
481    * @brief Get accessibility role
482    *
483    * @return Role enumeration
484    *
485    * @see Dali::Accessibility::Role
486    */
487   virtual Role GetRole() = 0;
488
489   /**
490    * @brief Get name of accessibility role
491    *
492    * @return string with human readable role converted from enumeration
493    *
494    * @see Dali::Accessibility::Role
495    * @see Accessibility::Accessible::GetRole
496    */
497   virtual std::string GetRoleName();
498
499   /**
500    * @brief Get localized name of accessibility role
501    *
502    * @return string with human readable role translated according to current
503    * translation domain
504    *
505    * @see Dali::Accessibility::Role
506    * @see Accessibility::Accessible::GetRole
507    * @see Accessibility::Accessible::GetRoleName
508    *
509    * @note translation is not supported in this version
510    */
511   virtual std::string GetLocalizedRoleName();
512
513   /**
514    * @brief Get accessibility states
515    *
516    * @return collection of states
517    *
518    * @note States class is instatation of ArrayBitset template class
519    *
520    * @see Dali::Accessibility::State
521    * @see Dali::Accessibility::ArrayBitset
522    */
523   virtual States GetStates() = 0;
524
525   /**
526    * @brief Get accessibility attributes
527    *
528    * @return map of attributes and their values
529    */
530   virtual Attributes GetAttributes() = 0;
531
532   /**
533    * @brief Check if this is proxy
534    *
535    * @return True if this is proxy
536    */
537   virtual bool IsProxy();
538
539   /**
540    * @brief Get unique address on accessibility bus
541    *
542    * @return class containing address
543    *
544    * @see Dali::Accessibility::Address
545    */
546   virtual Address GetAddress();
547
548   /**
549    * @brief Get accessibility object, which is "default label" for this object
550    */
551   virtual Accessible* GetDefaultLabel();
552
553   /**
554    * @brief Depute an object to perform provided gesture
555    *
556    * @param[in] gestureInfo structure describing the gesture
557    *
558    * @return true on success, false otherwise
559    *
560    * @see Dali::Accessibility::GestureInfo
561    */
562   virtual bool DoGesture(const GestureInfo& gestureInfo) = 0;
563
564   /**
565    * @brief Re-emits selected states of an Accessibility Object
566    *
567    * @param[in] states chosen states to re-emit
568    * @param[in] doRecursive if true all children of the Accessibility Object will also re-emit the states
569    */
570   void NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool doRecursive);
571
572   /**
573    * @brief Get information about current object and all relations that connects
574    * it with other accessibility objects
575    *
576    * @return iterable collection of Relation objects
577    *
578    * @see Dali::Accessibility::Relation
579    */
580   virtual std::vector<Relation> GetRelationSet() = 0;
581
582   /**
583    * @brief Get all implemented interfaces
584    *
585    * @return collection of strings with implemented interfaces
586    */
587   std::vector<std::string> GetInterfaces();
588
589   /**
590    * @brief Check if object is on root level
591    */
592   bool GetIsOnRootLevel() const
593   {
594     return isOnRootLevel;
595   }
596
597   /**
598    * @brief The method registers functor resposible for converting Actor into Accessible
599    * @param functor returning Accessible handle from Actor object
600    */
601   static void RegisterControlAccessibilityGetter(std::function<Accessible*(Dali::Actor)> functor);
602
603   /**
604    * @brief Acquire Accessible object from Actor object
605    *
606    * @param[in] actor Actor object
607    * @param[in] root true, if it's top level object (window)
608    *
609    * @return handle to Accessible object
610    */
611   static Accessible* Get(Dali::Actor actor, bool root = false);
612
613 protected:
614   Accessible();
615   Accessible(const Accessible&)         = delete;
616   Accessible(Accessible&&)              = delete;
617   Accessible&                   operator=(const Accessible&) = delete;
618   Accessible&                   operator=(Accessible&&) = delete;
619   std::shared_ptr<Bridge::Data> GetBridgeData();
620
621 public:
622   static Dali::Actor GetHighlightActor();
623   static void        SetHighlightActor(Dali::Actor actor);
624   static Dali::Actor GetCurrentlyHighlightedActor();
625   static void        SetCurrentlyHighlightedActor(Dali::Actor);
626   static void        SetObjectRegistry(ObjectRegistry registry);
627
628 private:
629   friend class Bridge;
630
631   std::weak_ptr<Bridge::Data> bridgeData;
632   bool                        isOnRootLevel = false;
633 };
634
635 /**
636  * @brief Interface enabling to perform provided actions
637  */
638 class Action : public virtual Accessible
639 {
640 public:
641   /**
642    * @brief Get name of action with given index
643    *
644    * @param[in] index index of action
645    *
646    * @return string with name of action
647    */
648   virtual std::string GetActionName(size_t index) = 0;
649
650   /**
651    * @brief Get translated name of action with given index
652    *
653    * @param[in] index index of action
654    *
655    * @return string with name of action translated according to current translation domain
656    *
657    * @note translation is not supported in this version
658    */
659   virtual std::string GetLocalizedActionName(size_t index) = 0;
660
661   /**
662    * @brief Get description of action with given index
663    *
664    * @param[in] index index of action
665    *
666    * @return string with description of action
667    */
668   virtual std::string GetActionDescription(size_t index) = 0;
669
670   /**
671    * @brief Get key code binded to action with given index
672    *
673    * @param[in] index index of action
674    *
675    * @return string with key name
676    */
677   virtual std::string GetActionKeyBinding(size_t index) = 0;
678
679   /**
680    * @brief Get number of provided actions
681    *
682    * @return unsigned integer with number of actions
683    */
684   virtual size_t GetActionCount() = 0;
685
686   /**
687    * @brief Perform an action with given index
688    *
689    * @param index index of action
690    *
691    * @return true on success, false otherwise
692    */
693   virtual bool DoAction(size_t index) = 0;
694
695   /**
696    * @brief Perform an action with given name
697    *
698    * @param name name of action
699    *
700    * @return true on success, false otherwise
701    */
702   virtual bool DoAction(const std::string& name) = 0;
703 };
704
705 /**
706  * @brief Interface enabling advanced quering of accessibility objects
707  *
708  * @note since all mathods can be implemented inside bridge,
709  * none methods have to be overrided
710  */
711 class Collection : public virtual Accessible
712 {
713 public:
714 };
715
716 /**
717  * @brief Interface representing objects having screen coordinates
718  */
719 class Component : public virtual Accessible
720 {
721 public:
722   /**
723    * @brief Get rectangle describing size
724    *
725    * @param[in] ctype enumeration with type of coordinate systems
726    *
727    * @return Rect<> object
728    *
729    * @see Dali::Rect
730    */
731   virtual Rect<> GetExtents(CoordType ctype) = 0;
732
733   /**
734    * @brief Get layer current object is localized on
735    *
736    * @return enumeration pointing layer
737    *
738    * @see Dali::Accessibility::ComponentLayer
739    */
740   virtual ComponentLayer GetLayer() = 0;
741
742   /**
743    * @brief Get value of z-order
744    *
745    * @return value of z-order
746    */
747   virtual int16_t GetMdiZOrder() = 0;
748
749   /**
750    * @brief Set current object as "focused"
751    *
752    * @return true on success, false otherwise
753    */
754   virtual bool GrabFocus() = 0;
755
756   /**
757    * @brief Get value of alpha channel
758    *
759    * @return alpha channel value in range [0.0, 1.0]
760    */
761   virtual double GetAlpha() = 0;
762
763   /**
764    * @brief Set current object as "highlighted"
765    *
766    * The method assings "highlighted" state, simultaneously removing it
767    * from currently highlighted object.
768    *
769    * @return true on success, false otherwise
770    */
771   virtual bool GrabHighlight() = 0;
772
773   /**
774    * @brief Set current object as "unhighlighted"
775    *
776    * The method removes "highlighted" state from object.
777    *
778    * @return true on success, false otherwise
779    *
780    * @see Dali:Accessibility::State
781    */
782   virtual bool ClearHighlight() = 0;
783
784   /**
785    * @brief Check whether object can be scrolled
786    *
787    * @return true if object is scrollable, false otherwise
788    *
789    * @see Dali:Accessibility::State
790    */
791   virtual bool IsScrollable();
792
793   /**
794    * @brief Get Accessible object containing given point
795    *
796    * @param[in] p two-dimensional point
797    * @param[in] ctype enumeration with type of coordinate system
798    *
799    * @return handle to last child of current object which contains given point
800    *
801    * @see Dali::Accessibility::Point
802    */
803   virtual Accessible* GetAccessibleAtPoint(Point p, CoordType ctype);
804
805   /**
806    * @brief Check if current object contains given point
807    *
808    * @param[in] p two-dimensional point
809    * @param[in] ctype enumeration with type of coordinate system
810    *
811    * @return handle to Accessible object
812    *
813    * @see Dali::Accessibility::Point
814    */
815   virtual bool Contains(Point p, CoordType ctype);
816 };
817
818 /**
819  * @brief Interface representing objects which can store numeric value
820  */
821 class Value : public virtual Accessible
822 {
823 public:
824   /**
825    * @brief Get the lowest possible value
826    *
827    * @return double value
828   */
829   virtual double GetMinimum() = 0;
830
831   /**
832    * @brief Get current value
833    *
834    * @return double value
835   */
836   virtual double GetCurrent() = 0;
837
838   /**
839    * @brief Get the highest possible value
840    *
841    * @return double value
842   */
843   virtual double GetMaximum() = 0;
844
845   /**
846    * @brief Set value
847    *
848    * @param[in] val double value
849    *
850    * @return true if value could have been assigned, false otherwise
851   */
852   virtual bool SetCurrent(double val) = 0;
853
854   /**
855    * @brief Get the lowest increment that can be distinguished
856    *
857    * @return double value
858   */
859   virtual double GetMinimumIncrement() = 0;
860 };
861
862 /**
863  * @brief Interface representing objects which can store immutable texts
864  *
865  * @see Dali::Accessibility::EditableText
866  */
867 class DALI_ADAPTOR_API Text : public virtual Accessible
868 {
869 public:
870   /**
871    * @brief Get stored text in given range
872    *
873    * @param[in] startOffset index of first character
874    * @param[in] endOffset index of first character after the last one expected
875    *
876    * @return substring of stored text
877    */
878   virtual std::string GetText(size_t startOffset, size_t endOffset) = 0;
879
880   /**
881    * @brief Get number of all stored characters
882    *
883    * @return number of characters
884    */
885   virtual size_t GetCharacterCount() = 0;
886
887   /**
888    * @brief Get caret offset
889    *
890    * @return Value of caret offset
891    */
892   virtual size_t GetCaretOffset() = 0;
893
894   /**
895    * @brief Set caret offset
896    *
897    * @param[in] offset Caret offset
898    *
899    * @return True if successful
900    */
901   virtual bool SetCaretOffset(size_t offset) = 0;
902
903   /**
904    * @brief Get substring of stored text truncated in concrete gradation
905    *
906    * @param[in] offset position in stored text
907    * @param[in] boundary enumeration describing text gradation
908    *
909    * @return Range structure containing acquired text and offsets in original string
910    *
911    * @see Dali::Accessibility::Range
912    */
913   virtual Range GetTextAtOffset(size_t offset, TextBoundary boundary) = 0;
914
915   /**
916    * @brief Get selected text
917    *
918    * @param[in] selectionNum selection index
919    * @note Currently only one selection (i.e. with index = 0) is supported
920    *
921    * @return Range structure containing acquired text and offsets in original string
922    *
923    * @see Dali::Accessibility::Range
924    */
925   virtual Range GetSelection(size_t selectionNum) = 0;
926
927   /**
928    * @brief Remove selection
929    *
930    * @param[in] selectionNum selection index
931    * @note Currently only one selection (i.e. with index = 0) is supported
932    *
933    * @return bool on success, false otherwise
934    */
935   virtual bool RemoveSelection(size_t selectionNum) = 0;
936
937   /**
938    * @brief Get selected text
939    *
940    * @param[in] selectionNum selection index
941    * @param[in] startOffset index of first character
942    * @param[in] endOffset index of first character after the last one expected
943    *
944    * @note Currently only one selection (i.e. with index = 0) is supported
945    *
946    * @return true on success, false otherwise
947    */
948   virtual bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) = 0;
949 };
950
951 /**
952  * @brief Interface representing objects which can store editable texts
953  *
954  * @note Paste method is entirely implemented inside bridge
955  *
956  * @see Dali::Accessibility::EditableText
957  */
958 class DALI_ADAPTOR_API EditableText : public virtual Accessible
959 {
960 public:
961   /**
962    * @brief Copy text in range to system clipboard
963    *
964    * @param[in] startPosition index of first character
965    * @param[in] endPosition index of first character after the last one expected
966    *
967    * @return true on success, false otherwise
968    */
969   virtual bool CopyText(size_t startPosition, size_t endPosition) = 0;
970
971   /**
972    * @brief Cut text in range to system clipboard
973    *
974    * @param[in] startPosition index of first character
975    * @param[in] endPosition index of first character after the last one expected
976    *
977    * @return true on success, false otherwise
978    */
979   virtual bool CutText(size_t startPosition, size_t endPosition) = 0;
980 };
981
982 /**
983  * @brief minimalistic, always empty Accessible object with settable address
984  *
985  * For those situations, where you want to return address in different bridge
986  * (embedding for example), but the object itself ain't planned to be used otherwise.
987  * This object has null parent, no children, empty name and so on
988  */
989 class DALI_ADAPTOR_API EmptyAccessibleWithAddress : public virtual Accessible
990 {
991 public:
992   EmptyAccessibleWithAddress() = default;
993   EmptyAccessibleWithAddress(Address address)
994   : address(std::move(address))
995   {
996   }
997
998   void SetAddress(Address address)
999   {
1000     this->address = std::move(address);
1001   }
1002
1003   std::string GetName() override
1004   {
1005     return "";
1006   }
1007   std::string GetDescription() override
1008   {
1009     return "";
1010   }
1011   Accessible* GetParent() override
1012   {
1013     return nullptr;
1014   }
1015   size_t GetChildCount() override
1016   {
1017     return 0;
1018   }
1019   std::vector<Accessible*> GetChildren() override
1020   {
1021     return {};
1022   }
1023   Accessible* GetChildAtIndex(size_t index) override
1024   {
1025     throw std::domain_error{"out of bounds index (" + std::to_string(index) + ") - no children"};
1026   }
1027   size_t GetIndexInParent() override
1028   {
1029     return static_cast<size_t>(-1);
1030   }
1031   Role GetRole() override
1032   {
1033     return {};
1034   }
1035   std::string GetRoleName() override;
1036   States      GetStates() override
1037   {
1038     return {};
1039   }
1040   Attributes GetAttributes() override
1041   {
1042     return {};
1043   }
1044   Address GetAddress() override
1045   {
1046     return address;
1047   }
1048   bool DoGesture(const GestureInfo& gestureInfo) override
1049   {
1050     return false;
1051   }
1052   std::vector<Relation> GetRelationSet() override
1053   {
1054     return {};
1055   }
1056
1057 private:
1058   Address address;
1059 };
1060
1061 } // namespace Accessibility
1062 } // namespace Dali
1063
1064 #endif // DALI_INTERNAL_ATSPI_ACCESSIBILITY_IMPL_H