2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/accessibility/bridge/bridge-component.h>
21 #define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties"
23 using namespace Dali::Accessibility;
25 BridgeComponent::BridgeComponent()
29 void BridgeComponent::RegisterInterfaces()
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
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);
50 Component* BridgeComponent::FindSelf() const
52 return FindCurrentObjectWithInterface<Dali::Accessibility::AtspiInterface::COMPONENT>();
55 DBus::ValueOrError<bool> BridgeComponent::IsAccessibleContainingPoint(int32_t x, int32_t y, uint32_t coordType)
57 return FindSelf()->IsAccessibleContainingPoint({x, y}, static_cast<CoordinateType>(coordType));
60 DBus::ValueOrError<Accessible*> BridgeComponent::GetAccessibleAtPoint(int32_t x, int32_t y, uint32_t coordType)
62 return FindSelf()->GetAccessibleAtPoint({x, y}, static_cast<CoordinateType>(coordType));
65 DBus::ValueOrError<std::tuple<int32_t, int32_t, int32_t, int32_t> > BridgeComponent::GetExtents(uint32_t coordType)
67 auto rect = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
69 rect.x += mData->mExtentsOffset.first;
70 rect.y += mData->mExtentsOffset.second;
72 return std::tuple<int32_t, int32_t, int32_t, int32_t>{rect.x, rect.y, rect.width, rect.height};
75 DBus::ValueOrError<int32_t, int32_t> BridgeComponent::GetPosition(uint32_t coordType)
77 auto rect = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
79 rect.x += mData->mExtentsOffset.first;
80 rect.y += mData->mExtentsOffset.second;
82 return {static_cast<int32_t>(rect.x), static_cast<int32_t>(rect.y)};
85 DBus::ValueOrError<int32_t, int32_t> BridgeComponent::GetSize(uint32_t coordType)
87 auto rect = FindSelf()->GetExtents(static_cast<CoordinateType>(coordType));
88 return {static_cast<int32_t>(rect.width), static_cast<int32_t>(rect.height)};
91 DBus::ValueOrError<ComponentLayer> BridgeComponent::GetLayer()
93 return FindSelf()->GetLayer();
96 DBus::ValueOrError<double> BridgeComponent::GetAlpha()
98 return FindSelf()->GetAlpha();
101 DBus::ValueOrError<bool> BridgeComponent::GrabFocus()
103 return FindSelf()->GrabFocus();
106 DBus::ValueOrError<bool> BridgeComponent::GrabHighlight()
108 return FindSelf()->GrabHighlight();
111 DBus::ValueOrError<bool> BridgeComponent::ClearHighlight()
113 return FindSelf()->ClearHighlight();
116 DBus::ValueOrError<int16_t> BridgeComponent::GetMdiZOrder()
118 return FindSelf()->GetMdiZOrder();