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