Merge "VectorImageRenderer: Remove TizenVectorImageRenderer dependency" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-object.cpp
1 /*
2  * Copyright (c) 2021 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 #include <dali/internal/accessibility/bridge/bridge-object.h>
20
21 // EXTERNAL INCLUDES
22 #include <iostream>
23 #include <string>
24
25 using namespace Dali::Accessibility;
26
27 BridgeObject::BridgeObject()
28 {
29 }
30
31 void BridgeObject::RegisterInterfaces()
32 {
33   // DBus::DBusInterfaceDescription desc{ AtspiDbusInterfaceEventObject };
34   // stateChanged = addSignal<std::string, int, int, DBus::EldbusVariant<int>, Accessible*>(desc, "StateChanged");
35   // mDbusServer.addInterface("/", desc, true);
36 }
37
38 void BridgeObject::EmitActiveDescendantChanged(Accessible* obj, Accessible* child)
39 {
40   if(!IsUp()) return;
41   auto index = child->GetIndexInParent();
42
43   auto        addr = obj->GetAddress();
44   std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
45
46   mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<Address>, Address>(
47     path,
48     AtspiDbusInterfaceEventObject,
49     "ActiveDescendantChanged",
50     "",
51     index,
52     0,
53     {child->GetAddress()},
54     {"", "root"});
55 }
56
57 void BridgeObject::Emit(Accessible* obj, Dali::Accessibility::ObjectPropertyChangeEvent ev)
58 {
59   if(!IsUp()) return;
60   const char* name = nullptr;
61
62   switch(ev)
63   {
64     case ObjectPropertyChangeEvent::NAME:
65     {
66       name = "accessible-name";
67       break;
68     }
69     case ObjectPropertyChangeEvent::DESCRIPTION:
70     {
71       name = "accessible-description";
72       break;
73     }
74     case ObjectPropertyChangeEvent::VALUE:
75     {
76       name = "accessible-value";
77       break;
78     }
79     case ObjectPropertyChangeEvent::PARENT:
80     {
81       name = "accessible-parent";
82       break;
83     }
84     case ObjectPropertyChangeEvent::ROLE:
85     {
86       name = "accessible-role";
87       break;
88     }
89   }
90
91   if(name)
92   {
93     auto        addr = obj->GetAddress();
94     std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
95
96     mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<int>, Address>(
97       path,
98       AtspiDbusInterfaceEventObject,
99       "PropertyChange",
100       name,
101       0,
102       0,
103       {0},
104       {"", "root"});
105   }
106 }
107
108 void BridgeObject::Emit(Accessible* obj, WindowEvent event, unsigned int detail)
109 {
110   if(!IsUp()) return;
111   const char* name = nullptr;
112
113   switch(event)
114   {
115     case WindowEvent::PROPERTY_CHANGE:
116     {
117       name = "PropertyChange";
118       break;
119     }
120     case WindowEvent::MINIMIZE:
121     {
122       name = "Minimize";
123       break;
124     }
125     case WindowEvent::MAXIMIZE:
126     {
127       name = "Maximize";
128       break;
129     }
130     case WindowEvent::RESTORE:
131     {
132       name = "Restore";
133       break;
134     }
135     case WindowEvent::CLOSE:
136     {
137       name = "Close";
138       break;
139     }
140     case WindowEvent::CREATE:
141     {
142       name = "Create";
143       break;
144     }
145     case WindowEvent::REPARENT:
146     {
147       name = "Reparent";
148       break;
149     }
150     case WindowEvent::DESKTOP_CREATE:
151     {
152       name = "DesktopCreate";
153       break;
154     }
155     case WindowEvent::DESKTOP_DESTROY:
156     {
157       name = "DesktopDestroy";
158       break;
159     }
160     case WindowEvent::DESTROY:
161     {
162       name = "Destroy";
163       break;
164     }
165     case WindowEvent::ACTIVATE:
166     {
167       name = "Activate";
168       break;
169     }
170     case WindowEvent::DEACTIVATE:
171     {
172       name = "Deactivate";
173       break;
174     }
175     case WindowEvent::RAISE:
176     {
177       name = "Raise";
178       break;
179     }
180     case WindowEvent::LOWER:
181     {
182       name = "Lower";
183       break;
184     }
185     case WindowEvent::MOVE:
186     {
187       name = "Move";
188       break;
189     }
190     case WindowEvent::RESIZE:
191     {
192       name = "Resize";
193       break;
194     }
195     case WindowEvent::SHADE:
196     {
197       name = "Shade";
198       break;
199     }
200     case WindowEvent::UU_SHADE:
201     {
202       name = "uUshade";
203       break;
204     }
205     case WindowEvent::RESTYLE:
206     {
207       name = "Restyle";
208       break;
209     }
210   }
211
212   if(name)
213   {
214     auto        addr = obj->GetAddress();
215     std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
216
217     mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<int>, Address>(
218       path,
219       AtspiDbusInterfaceEventWindow,
220       name,
221       "",
222       detail,
223       0,
224       {0},
225       {"", "root"});
226   }
227 }
228
229 void BridgeObject::EmitStateChanged(Accessible* obj, State state, int newValue, int reserved)
230 {
231   if(!IsUp()) return;
232   const char* stateName = nullptr;
233
234   switch(state)
235   {
236     case State::INVALID:
237     {
238       stateName = "invalid";
239       break;
240     }
241     case State::ACTIVE:
242     {
243       stateName = "active";
244       break;
245     }
246     case State::ARMED:
247     {
248       stateName = "armed";
249       break;
250     }
251     case State::BUSY:
252     {
253       stateName = "busy";
254       break;
255     }
256     case State::CHECKED:
257     {
258       stateName = "checked";
259       break;
260     }
261     case State::COLLAPSED:
262     {
263       stateName = "collapsed";
264       break;
265     }
266     case State::DEFUNCT:
267     {
268       stateName = "defunct";
269       break;
270     }
271     case State::EDITABLE:
272     {
273       stateName = "editable";
274       break;
275     }
276     case State::ENABLED:
277     {
278       stateName = "enabled";
279       break;
280     }
281     case State::EXPANDABLE:
282     {
283       stateName = "expandable";
284       break;
285     }
286     case State::EXPANDED:
287     {
288       stateName = "expanded";
289       break;
290     }
291     case State::FOCUSABLE:
292     {
293       stateName = "focusable";
294       break;
295     }
296     case State::FOCUSED:
297     {
298       stateName = "focused";
299       break;
300     }
301     case State::HAS_TOOLTIP:
302     {
303       stateName = "has-tooltip";
304       break;
305     }
306     case State::HORIZONTAL:
307     {
308       stateName = "horizontal";
309       break;
310     }
311     case State::ICONIFIED:
312     {
313       stateName = "iconified";
314       break;
315     }
316     case State::MODAL:
317     {
318       stateName = "modal";
319       break;
320     }
321     case State::MULTI_LINE:
322     {
323       stateName = "multi-line";
324       break;
325     }
326     case State::MULTI_SELECTABLE:
327     {
328       stateName = "multiselectable";
329       break;
330     }
331     case State::OPAQUE:
332     {
333       stateName = "opaque";
334       break;
335     }
336     case State::PRESSED:
337     {
338       stateName = "pressed";
339       break;
340     }
341     case State::RESIZEABLE:
342     {
343       stateName = "resizable";
344       break;
345     }
346     case State::SELECTABLE:
347     {
348       stateName = "selectable";
349       break;
350     }
351     case State::SELECTED:
352     {
353       stateName = "selected";
354       break;
355     }
356     case State::SENSITIVE:
357     {
358       stateName = "sensitive";
359       break;
360     }
361     case State::SHOWING:
362     {
363       stateName = "showing";
364       break;
365     }
366     case State::SINGLE_LINE:
367     {
368       stateName = "single-line";
369       break;
370     }
371     case State::STALE:
372     {
373       stateName = "stale";
374       break;
375     }
376     case State::TRANSIENT:
377     {
378       stateName = "transient";
379       break;
380     }
381     case State::VERTICAL:
382     {
383       stateName = "vertical";
384       break;
385     }
386     case State::VISIBLE:
387     {
388       stateName = "visible";
389       break;
390     }
391     case State::MANAGES_DESCENDANTS:
392     {
393       stateName = "manages-descendants";
394       break;
395     }
396     case State::INDETERMINATE:
397     {
398       stateName = "indeterminate";
399       break;
400     }
401     case State::REQUIRED:
402     {
403       stateName = "required";
404       break;
405     }
406     case State::TRUNCATED:
407     {
408       stateName = "truncated";
409       break;
410     }
411     case State::ANIMATED:
412     {
413       stateName = "animated";
414       break;
415     }
416     case State::INVALID_ENTRY:
417     {
418       stateName = "invalid-entry";
419       break;
420     }
421     case State::SUPPORTS_AUTOCOMPLETION:
422     {
423       stateName = "supports-autocompletion";
424       break;
425     }
426     case State::SELECTABLE_TEXT:
427     {
428       stateName = "selectable-text";
429       break;
430     }
431     case State::IS_DEFAULT:
432     {
433       stateName = "is-default";
434       break;
435     }
436     case State::VISITED:
437     {
438       stateName = "visited";
439       break;
440     }
441     case State::CHECKABLE:
442     {
443       stateName = "checkable";
444       break;
445     }
446     case State::HAS_POPUP:
447     {
448       stateName = "has-popup";
449       break;
450     }
451     case State::READ_ONLY:
452     {
453       stateName = "read-only";
454       break;
455     }
456     case State::HIGHLIGHTED:
457     {
458       stateName = "highlighted";
459       break;
460     }
461     case State::HIGHLIGHTABLE:
462     {
463       stateName = "highlightable";
464       break;
465     }
466     case State::MAX_COUNT:
467     {
468       break;
469     }
470   }
471
472   if(stateName)
473   {
474     auto        addr = obj->GetAddress();
475     std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
476
477     mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<int>, Address>(
478       path,
479       AtspiDbusInterfaceEventObject,
480       "StateChanged",
481       stateName,
482       newValue,
483       reserved,
484       {0},
485       {"", "root"});
486   }
487 }
488
489 void BridgeObject::EmitBoundsChanged(Accessible* obj, Dali::Rect<> rect)
490 {
491   if(!IsBoundsChangedEventAllowed) return;
492
493   auto        addr = obj->GetAddress();
494   std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
495
496   DBus::EldbusVariant<std::tuple<int32_t, int32_t, int32_t, int32_t> > tmp{
497     std::tuple<int32_t, int32_t, int32_t, int32_t>{rect.x, rect.y, rect.width, rect.height}};
498
499   AddFilteredEvent(FilteredEvents::BOUNDS_CHANGED, obj, 1.0f, [=]() {
500     mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<std::tuple<int32_t, int32_t, int32_t, int32_t> >, Address>(
501       path,
502       AtspiDbusInterfaceEventObject,
503       "BoundsChanged",
504       "",
505       0,
506       0,
507       tmp,
508       {"", "root"});
509   });
510 }
511
512 void BridgeObject::EmitCursorMoved(Accessible* obj, unsigned int cursorPosition)
513 {
514   auto        addr = obj->GetAddress();
515   std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
516
517   mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<int>, Address>(
518     path,
519     AtspiDbusInterfaceEventObject,
520     "TextCaretMoved",
521     "",
522     cursorPosition,
523     0,
524     {0},
525     {"", "root"});
526 }
527
528 void BridgeObject::EmitTextChanged(Accessible* obj, TextChangedState state, unsigned int position, unsigned int length, const std::string& content)
529 {
530   const char* stateName = nullptr;
531   switch(state)
532   {
533     case TextChangedState::INSERTED:
534     {
535       stateName = "insert";
536       break;
537     }
538     case TextChangedState::DELETED:
539     {
540       stateName = "delete";
541       break;
542     }
543     case TextChangedState::MAX_COUNT:
544     {
545       break;
546     }
547   }
548
549   if(stateName)
550   {
551     auto        addr = obj->GetAddress();
552     std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
553
554     mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<std::string>, Address>(
555       path,
556       AtspiDbusInterfaceEventObject,
557       "TextChanged",
558       stateName,
559       position,
560       length,
561       {content},
562       {"", "root"});
563   }
564 }
565
566 void BridgeObject::EmitMovedOutOfScreen(Accessible* obj, ScreenRelativeMoveType type)
567 {
568   auto        addr = obj->GetAddress();
569   std::string path = addr ? ATSPI_PREFIX_PATH + addr.GetPath() : ATSPI_NULL_PATH;
570
571   mDbusServer.emit2<std::string, int, int, DBus::EldbusVariant<int>, Address>(
572     path,
573     AtspiDbusInterfaceEventObject,
574     "MoveOuted",
575     "",
576     static_cast<int>(type),
577     0,
578     {0},
579     {"", "root"});
580 }