[ATSPI] Add some descriptions to Bridge objects
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-component.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-component.h>
20
21 // EXTERNAL INCLUDES
22 #include <iostream>
23
24 #define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties"
25
26 using namespace Dali::Accessibility;
27
28 BridgeComponent::BridgeComponent()
29 {
30 }
31
32 void BridgeComponent::RegisterInterfaces()
33 {
34   // The second arguments below are the names (or signatures) of DBus methods.
35   // Screen Reader will call the methods with the exact names as specified in the AT-SPI Component interface:
36   // https://gitlab.gnome.org/GNOME/at-spi2-core/-/blob/master/xml/Component.xml
37
38   DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceComponent};
39   AddFunctionToInterface(desc, "Contains", &BridgeComponent::IsAccessibleContainingPoint);
40   AddFunctionToInterface(desc, "GetAccessibleAtPoint", &BridgeComponent::GetAccessibleAtPoint);
41   AddFunctionToInterface(desc, "GetExtents", &BridgeComponent::GetExtents);
42   AddFunctionToInterface(desc, "GetPosition", &BridgeComponent::GetPosition);
43   AddFunctionToInterface(desc, "GetSize", &BridgeComponent::GetSize);
44   AddFunctionToInterface(desc, "GetLayer", &BridgeComponent::GetLayer);
45   AddFunctionToInterface(desc, "GetAlpha", &BridgeComponent::GetAlpha);
46   AddFunctionToInterface(desc, "GetMDIZOrder", &BridgeComponent::GetMdiZOrder);
47   AddFunctionToInterface(desc, "GrabHighlight", &BridgeComponent::GrabHighlight);
48   AddFunctionToInterface(desc, "GrabFocus", &BridgeComponent::GrabFocus);
49   AddFunctionToInterface(desc, "ClearHighlight", &BridgeComponent::ClearHighlight);
50   mDbusServer.addInterface("/", desc, true);
51 }
52
53 Component* BridgeComponent::FindSelf() const
54 {
55   auto self = BridgeBase::FindSelf();
56   assert(self);
57   auto componentInterface = dynamic_cast<Component*>(self);
58   if(!componentInterface)
59   {
60     throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Component interface"};
61   }
62   return componentInterface;
63 }
64
65 DBus::ValueOrError<bool> BridgeComponent::IsAccessibleContainingPoint(int32_t x, int32_t y, uint32_t coordType)
66 {
67   return FindSelf()->IsAccessibleContainingPoint({x, y}, static_cast<CoordinateType>(coordType));
68 }
69
70 DBus::ValueOrError<Accessible*> BridgeComponent::GetAccessibleAtPoint(int32_t x, int32_t y, uint32_t coordType)
71 {
72   return FindSelf()->GetAccessibleAtPoint({x, y}, static_cast<CoordinateType>(coordType));
73 }
74
75 DBus::ValueOrError<std::tuple<int32_t, int32_t, int32_t, int32_t> > BridgeComponent::GetExtents(uint32_t coordType)
76 {
77   auto rect = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
78   return std::tuple<int32_t, int32_t, int32_t, int32_t>{rect.x, rect.y, rect.width, rect.height};
79 }
80
81 DBus::ValueOrError<int32_t, int32_t> BridgeComponent::GetPosition(uint32_t coordType)
82 {
83   auto rect = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
84   return {static_cast<int32_t>(rect.x), static_cast<int32_t>(rect.y)};
85 }
86
87 DBus::ValueOrError<int32_t, int32_t> BridgeComponent::GetSize(uint32_t coordType)
88 {
89   auto rect = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
90   return {static_cast<int32_t>(rect.width), static_cast<int32_t>(rect.height)};
91 }
92
93 DBus::ValueOrError<ComponentLayer> BridgeComponent::GetLayer()
94 {
95   return FindSelf()->GetLayer();
96 }
97
98 DBus::ValueOrError<double> BridgeComponent::GetAlpha()
99 {
100   return FindSelf()->GetAlpha();
101 }
102
103 DBus::ValueOrError<bool> BridgeComponent::GrabFocus()
104 {
105   return FindSelf()->GrabFocus();
106 }
107
108 DBus::ValueOrError<bool> BridgeComponent::GrabHighlight()
109 {
110   return FindSelf()->GrabHighlight();
111 }
112
113 DBus::ValueOrError<bool> BridgeComponent::ClearHighlight()
114 {
115   return FindSelf()->ClearHighlight();
116 }
117
118 DBus::ValueOrError<int16_t> BridgeComponent::GetMdiZOrder()
119 {
120   return FindSelf()->GetMdiZOrder();
121 }