DALi Version 1.9.35
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen-wayland / atspi / accessible.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18  // CLASS HEADER
19
20  //INTERNAL INCLUDES
21 #include <dali/internal/accessibility/tizen-wayland/atspi/accessibility-common.h>
22 #include <third-party/libunibreak/wordbreak.h>
23 #include <third-party/libunibreak/linebreak.h>
24
25 using namespace Dali::Accessibility;
26
27 std::vector< std::string > Accessible::GetInterfaces()
28 {
29     std::vector< std::string > tmp;
30     tmp.push_back(AtspiDbusInterfaceAccessible);
31     if (dynamic_cast<Collection*>(this))
32     {
33         tmp.push_back(AtspiDbusInterfaceCollection);
34     }
35     if (dynamic_cast<Text*>(this))
36     {
37         tmp.push_back(AtspiDbusInterfaceText);
38     }
39     if (dynamic_cast<Value*>(this))
40     {
41         tmp.push_back(AtspiDbusInterfaceValue);
42     }
43     if (dynamic_cast<Component*>(this))
44     {
45         tmp.push_back(AtspiDbusInterfaceComponent);
46     }
47     if (auto d = dynamic_cast<Action*>(this))
48     {
49         if (d->GetActionCount() > 0)
50         {
51             tmp.push_back(AtspiDbusInterfaceAction);
52         }
53     }
54     return tmp;
55 }
56
57 Accessible::Accessible()
58 {
59 }
60
61 Accessible::~Accessible()
62 {
63     auto b = bridgeData.lock();
64     if (b)
65         b->knownObjects.erase(this);
66 }
67
68 void Accessible::EmitActiveDescendantChanged(Accessible* obj, Accessible* child)
69 {
70     if (auto b = GetBridgeData())
71     {
72         b->bridge->EmitActiveDescendantChanged(obj, child);
73     }
74 }
75
76 void Accessible::EmitStateChanged(State state, int newValue1, int newValue2)
77 {
78     if (auto b = GetBridgeData())
79     {
80         b->bridge->EmitStateChanged(this, state, newValue1, newValue2);
81     }
82 }
83
84 void Accessible::EmitShowing(bool showing)
85 {
86     if (auto b = GetBridgeData())
87     {
88         b->bridge->EmitStateChanged(this, State::SHOWING, showing ? 1 : 0, 0);
89     }
90 }
91
92 void Accessible::EmitVisible(bool visible)
93 {
94     if (auto b = GetBridgeData())
95     {
96         b->bridge->EmitStateChanged(this, State::VISIBLE, visible ? 1 : 0, 0);
97     }
98 }
99
100 void Accessible::EmitHighlighted(bool set)
101 {
102     if (auto b = GetBridgeData())
103     {
104         b->bridge->EmitStateChanged(this, State::HIGHLIGHTED, set ? 1 : 0, 0);
105     }
106 }
107
108 void Accessible::EmitFocused(bool set)
109 {
110     if (auto b = GetBridgeData()) {
111         b->bridge->EmitStateChanged(this, State::FOCUSED, set ? 1 : 0, 0);
112     }
113 }
114 void Accessible::EmitTextInserted(unsigned int position, unsigned int length, const std::string& content)
115 {
116     if (auto b = GetBridgeData()) {
117         b->bridge->EmitTextChanged(this, TextChangedState::INSERT, position, length, content);
118     }
119 }
120 void Accessible::EmitTextDeleted(unsigned int position, unsigned int length, const std::string& content)
121 {
122     if (auto b = GetBridgeData()) {
123         b->bridge->EmitTextChanged(this, TextChangedState::DELETE, position, length, content);
124     }
125 }
126 void Accessible::EmitTextCaretMoved(unsigned int cursorPosition)
127 {
128     if (auto b = GetBridgeData()) {
129         b->bridge->EmitCaretMoved(this, cursorPosition);
130     }
131 }
132 void Accessible::Emit(WindowEvent we, unsigned int detail1)
133 {
134     if (auto b = GetBridgeData())
135     {
136         b->bridge->Emit(this, we, detail1);
137     }
138 }
139 void Accessible::Emit(ObjectPropertyChangeEvent ev)
140 {
141     if (auto b = GetBridgeData())
142     {
143         b->bridge->Emit(this, ev);
144     }
145 }
146
147 void Accessible::EmitBoundsChanged(Rect<> rect)
148 {
149     if (auto b = GetBridgeData())
150     {
151         b->bridge->EmitBoundsChanged(this, rect);
152     }
153 }
154
155 std::vector< Accessible* > Accessible::GetChildren()
156 {
157     std::vector< Accessible* > tmp(GetChildCount());
158     for (auto i = 0u; i < tmp.size(); ++i)
159     {
160         tmp[i] = GetChildAtIndex(i);
161     }
162     return tmp;
163 }
164
165 std::shared_ptr< Bridge::Data > Accessible::GetBridgeData()
166 {
167     auto b = bridgeData.lock();
168     if (!b)
169     {
170         auto p = Bridge::GetCurrentBridge();
171         b = p->data;
172     }
173     return b;
174 }
175
176 Address Accessible::GetAddress()
177 {
178     auto b = bridgeData.lock();
179     if (!b)
180     {
181         b = GetBridgeData();
182         if (b)
183             b->bridge->RegisterOnBridge(this);
184     }
185     std::ostringstream tmp;
186     tmp << this;
187     return { b ? b->busName : "", tmp.str() };
188 }
189
190 void Bridge::RegisterOnBridge(Accessible* obj)
191 {
192     assert(!obj->bridgeData.lock() || obj->bridgeData.lock() == data);
193     if (!obj->bridgeData.lock())
194     {
195         assert(data);
196         data->knownObjects.insert(obj);
197         obj->bridgeData = data;
198     }
199 }
200
201 bool Accessible::IsProxy()
202 {
203     return false;
204 }
205
206 Accessible* Accessible::GetDefaultLabel()
207 {
208     return this;
209 }
210
211 void Accessible::NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool doRecursive)
212 {
213     if (auto b = GetBridgeData())
214     {
215         auto s = GetStates() & states;
216         for (auto i = 0u; i < s.size(); i++)
217         {
218             auto index = static_cast<Dali::Accessibility::State>(i);
219             if (s[index])
220                 b->bridge->EmitStateChanged(this, index, 1, 0);
221         }
222         if (doRecursive)
223         {
224             auto children = GetChildren();
225             for (auto c : children)
226                 c->NotifyAccessibilityStateChange(states, doRecursive);
227         }
228     }
229 }
230
231 void Accessible::FindWordSeparationsUtf8(const utf8_t* s, size_t length, const char* language, char* breaks)
232 {
233     set_wordbreaks_utf8(s, length, language, breaks);
234 }
235
236 void Accessible::FindLineSeparationsUtf8(const utf8_t* s, size_t length, const char* language, char* breaks)
237 {
238     set_linebreaks_utf8(s, length, language, breaks);
239 }