Merge "Add class for encoded image buffer" into 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 // 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::IsAccessibleContainedAtPoint);
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   dbusServer.addInterface("/", desc, true);
51 }
52
53 Component* BridgeComponent::FindSelf() const
54 {
55   auto s = BridgeBase::FindSelf();
56   assert(s);
57   auto s2 = dynamic_cast<Component*>(s);
58   if(!s2)
59     throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Component interface"};
60   return s2;
61 }
62
63 DBus::ValueOrError<bool> BridgeComponent::IsAccessibleContainedAtPoint(int32_t x, int32_t y, uint32_t coordType)
64 {
65   return FindSelf()->IsAccessibleContainedAtPoint({x, y}, static_cast<CoordinateType>(coordType));
66 }
67 DBus::ValueOrError<Accessible*> BridgeComponent::GetAccessibleAtPoint(int32_t x, int32_t y, uint32_t coordType)
68 {
69   return FindSelf()->GetAccessibleAtPoint({x, y}, static_cast<CoordinateType>(coordType));
70 }
71 DBus::ValueOrError<std::tuple<int32_t, int32_t, int32_t, int32_t> > BridgeComponent::GetExtents(uint32_t coordType)
72 {
73   auto p = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
74   return std::tuple<int32_t, int32_t, int32_t, int32_t>{p.x, p.y, p.width, p.height};
75 }
76 DBus::ValueOrError<int32_t, int32_t> BridgeComponent::GetPosition(uint32_t coordType)
77 {
78   auto p = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
79   return {static_cast<int32_t>(p.x), static_cast<int32_t>(p.y)};
80 }
81 DBus::ValueOrError<int32_t, int32_t> BridgeComponent::GetSize(uint32_t coordType)
82 {
83   auto p = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
84   return {static_cast<int32_t>(p.width), static_cast<int32_t>(p.height)};
85 }
86 DBus::ValueOrError<ComponentLayer> BridgeComponent::GetLayer()
87 {
88   return FindSelf()->GetLayer();
89 }
90 DBus::ValueOrError<double> BridgeComponent::GetAlpha()
91 {
92   return FindSelf()->GetAlpha();
93 }
94 DBus::ValueOrError<bool> BridgeComponent::GrabFocus()
95 {
96   return FindSelf()->GrabFocus();
97 }
98 DBus::ValueOrError<bool> BridgeComponent::GrabHighlight()
99 {
100   return FindSelf()->GrabHighlight();
101 }
102 DBus::ValueOrError<bool> BridgeComponent::ClearHighlight()
103 {
104   return FindSelf()->ClearHighlight();
105 }
106 DBus::ValueOrError<int16_t> BridgeComponent::GetMdiZOrder()
107 {
108   return FindSelf()->GetMdiZOrder();
109 }