[Tizen][AT-SPI] Move AccessibilityAttributes to Accessible
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / actor-accessible.h
1 #ifndef DALI_ADAPTOR_ACTOR_ACCESSIBLE_H
2 #define DALI_ADAPTOR_ACTOR_ACCESSIBLE_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/public-api/actors/actor.h>
22 #include <dali/public-api/object/weak-handle.h>
23 #include <dali/public-api/signals/connection-tracker.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/atspi-interfaces/accessible.h>
27 #include <dali/devel-api/atspi-interfaces/collection.h>
28 #include <dali/devel-api/atspi-interfaces/component.h>
29
30 namespace Dali::Accessibility
31 {
32 class DALI_ADAPTOR_API ActorAccessible : public virtual Accessible,
33                                          public virtual Collection,
34                                          public virtual Component,
35                                          public Dali::ConnectionTracker
36 {
37 public:
38   ActorAccessible() = delete;
39
40   ActorAccessible(Actor actor);
41
42   /**
43    * @copydoc Dali::Accessibility::Accessible::GetName()
44    */
45   std::string GetName() const override;
46
47   /**
48    * @copydoc Dali::Accessibility::Accessible::GetDescription()
49    */
50   std::string GetDescription() const override;
51
52   /**
53    * @copydoc Dali::Accessibility::Accessible::GetParent()
54    */
55   Accessible* GetParent() final;
56
57   /**
58    * @copydoc Dali::Accessibility::Accessible::GetChildCount()
59    */
60   std::size_t GetChildCount() const final;
61
62   /**
63    * @copydoc Dali::Accessibility::Accessible::GetChildren()
64    */
65   std::vector<Accessible*> GetChildren() final;
66
67   /**
68    * @copydoc Dali::Accessibility::Accessible::GetChildAtIndex()
69    */
70   Accessible* GetChildAtIndex(std::size_t index) final;
71
72   /**
73    * @copydoc Dali::Accessibility::Accessible::GetIndexInParent()
74    */
75   std::size_t GetIndexInParent() final;
76
77   /**
78    * @copydoc Dali::Accessibility::Accessible::GetInternalActor()
79    */
80   Dali::Actor GetInternalActor() final;
81
82   /**
83    * @copydoc Dali::Accessibility::Component::GetLayer()
84    */
85   ComponentLayer GetLayer() const override;
86
87   /**
88    * @copydoc Dali::Accessibility::Component::GetMdiZOrder()
89    */
90   std::int16_t GetMdiZOrder() const override;
91
92   /**
93    * @copydoc Dali::Accessibility::Component::GetAlpha()
94    */
95   double GetAlpha() const override;
96
97   /**
98    * @copydoc Dali::Accessibility::Component::IsScrollable()
99    */
100   bool IsScrollable() const override;
101
102   /**
103    * @copydoc Dali::Accessibility::Component::GetExtents()
104    */
105   Dali::Rect<> GetExtents(CoordinateType type) const override;
106
107   /**
108    * @brief Notifies this object that its children have changed.
109    *
110    * This is useful if you maintain a custom collection of children that are not derived from
111    * ActorAccessible and the contents or order of elements in that collection change.
112    *
113    * @see DoGetChildren()
114    */
115   void OnChildrenChanged();
116
117 protected:
118   Dali::Actor Self() const
119   {
120     auto handle = mSelf.GetHandle();
121
122     // It is a bug if the Accessible outlives its Actor
123     DALI_ASSERT_ALWAYS(handle);
124
125     return handle;
126   }
127
128   /**
129    * @brief Populates the collection of children of this Accessible.
130    *
131    * The default implementation retrieves the children from the Actor hierarchy. Override this if
132    * you want to report other objects as children, either instead of, or together with the
133    * dependent Actor-derived Accessibles. Remember to call OnChildrenChanged() if you want your
134    * implementation of DoGetChildren() to be called again (in case your custom collection of
135    * children changes).
136    *
137    * @param[out] children The initially empty vector to insert children into
138    *
139    * @note GetChildCound(), GetChildren() and GetChildAtIndex() are not available for overriding,
140    * but they respect the children collection reported by this method.
141    *
142    * @see OnChildrenChanged()
143    * @see GetChildCount()
144    * @see GetChildren()
145    * @see GetChildAtIndex()
146    */
147   virtual void DoGetChildren(std::vector<Accessible*>& children);
148
149   /**
150    * @copydoc Dali::Accessibility::Accessible::UpdateAttributes()
151    */
152   void UpdateAttributes(Attributes& attributes) const override;
153
154 private:
155   // Extra overload for OnChildrenChanged() to connect to signals directly
156   void OnChildrenChanged(Dali::Actor);
157
158   // Ensures children are up to date (calls DoGetChildren() if necessary)
159   void UpdateChildren();
160
161   Dali::WeakHandle<Dali::Actor> mSelf;
162   std::vector<Accessible*>      mChildren;
163   bool                          mChildrenDirty;
164 };
165
166 } // namespace Dali::Accessibility
167
168 #endif // DALI_ADAPTOR_ACTOR_ACCESSIBLE_H