1 #ifndef DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H
2 #define DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/debug.h>
28 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
29 #include <dali/internal/accessibility/bridge/dbus-locators.h>
30 #include <dali/internal/accessibility/bridge/dbus.h>
31 #include <dali/public-api/dali-adaptor-common.h>
35 #define A11yDbusName "org.a11y.Bus"
36 #define A11yDbusPath "/org/a11y/bus"
37 #define A11yDbusStatusInterface "org.a11y.Status"
38 #define AtspiDbusNameRegistry "org.a11y.atspi.Registry"
39 #define AtspiDbusPathRegistry "/org/a11y/atspi/registry"
40 #define AtspiDbusInterfaceRegistry "org.a11y.atspi.Registry"
41 #define AtspiDbusPathRoot "/org/a11y/atspi/accessible/root"
42 #define AtspiDbusInterfaceSocket "org.a11y.atspi.Socket"
43 #define AtspiPath "/org/a11y/atspi/accessible"
44 #define AtspiDbusInterfaceAccessible "org.a11y.atspi.Accessible"
45 #define AtspiDbusInterfaceAction "org.a11y.atspi.Action"
46 #define AtspiDbusInterfaceApplication "org.a11y.atspi.Application"
47 #define AtspiDbusInterfaceCache "org.a11y.atspi.Cache"
48 #define AtspiDbusPathCache "/org/a11y/atspi/cache"
49 #define AtspiDbusInterfaceCollection "org.a11y.atspi.Collection"
50 #define AtspiDbusInterfaceComponent "org.a11y.atspi.Component"
51 #define AtspiDbusInterfaceDocument "org.a11y.atspi.Document"
52 #define AtspiDbusInterfaceEditableText "org.a11y.atspi.EditableText"
53 #define AtspiDbusInterfaceEventKeyboard "org.a11y.atspi.Event.Keyboard"
54 #define AtspiDbusInterfaceEventMouse "org.a11y.atspi.Event.Mouse"
55 #define AtspiDbusInterfaceEventObject "org.a11y.atspi.Event.Object"
56 #define AtspiDbusInterfaceHyperlink "org.a11y.atspi.Hyperlink"
57 #define AtspiDbusInterfaceHypertext "org.a11y.atspi.Hypertext"
58 #define AtspiDbusInterfaceImage "org.a11y.atspi.Image"
59 #define AtspiDbusInterfaceSelection "org.a11y.atspi.Selection"
60 #define AtspiDbusInterfaceTable "org.a11y.atspi.Table"
61 #define AtspiDbusInterfaceTableCell "org.a11y.atspi.TableCell"
62 #define AtspiDbusInterfaceText "org.a11y.atspi.Text"
63 #define AtspiDbusInterfaceValue "org.a11y.atspi.Value"
64 #define AtspiDbusInterfaceSocket "org.a11y.atspi.Socket"
65 #define AtspiDbusInterfaceEventWindow "org.a11y.atspi.Event.Window"
67 #define AtspiDbusPathDec "/org/a11y/atspi/registry/deviceeventcontroller"
68 #define AtspiDbusInterfaceDec "org.a11y.atspi.DeviceEventController"
69 #define AtspiDbusInterfaceDeviceEventListener "org.a11y.atspi.DeviceEventListener"
71 #define DirectReadingDBusName "org.tizen.ScreenReader"
72 #define DirectReadingDBusPath "/org/tizen/DirectReading"
73 #define DirectReadingDBusInterface "org.tizen.DirectReading"
78 * @brief Enumeration used for quering Accessibility objects
80 enum class MatchType : int32_t
90 * @brief Enumeration used for quering Accessibility objects
91 * SortOrder::Canonical uses breadth-first search and sort objects in order of indexes in parent
92 * SortOrder::ReverseCanonical uses SortOrder::Canonical and reverse collection
93 * The rest of orders is not supported.
95 enum class SortOrder : uint32_t
111 * @brief The CurrentBridgePtr class is to save the current Accessibility Bridge.
113 class CurrentBridgePtr
115 static Dali::Accessibility::Bridge*& Get()
117 static thread_local Dali::Accessibility::Bridge* bridge = nullptr;
120 Dali::Accessibility::Bridge* mPrev;
121 CurrentBridgePtr(const CurrentBridgePtr&) = delete;
122 CurrentBridgePtr(CurrentBridgePtr&&) = delete;
123 CurrentBridgePtr& operator=(const CurrentBridgePtr&) = delete;
124 CurrentBridgePtr& operator=(CurrentBridgePtr&&) = delete;
127 CurrentBridgePtr(Dali::Accessibility::Bridge* bridge)
138 static Dali::Accessibility::Bridge* GetCurrentBridge()
142 }; // CurrentBridgePtr
145 // Templates for setting and getting Accessible values
149 struct SignatureAccessibleImpl : signature_helper<SignatureAccessibleImpl<T>>
151 using subtype = std::pair<std::string, ObjectPath>;
153 static constexpr auto name_v = concat("AtspiAccessiblePtr");
154 static constexpr auto sig_v = concat("(so)");
157 * @brief Marshals value address as marshalled type into message
159 static void set(const DBusWrapper::MessageIterPtr& iter, T* accessible)
163 auto address = accessible->GetAddress();
164 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{std::string{ATSPI_PREFIX_PATH} + address.GetPath()}});
168 signature<subtype>::set(iter, {"", ObjectPath{ATSPI_NULL_PATH}});
173 * @brief Marshals value from marshalled type into variable path
175 static bool get(const DBusWrapper::MessageIterPtr& iter, T*& path)
178 if(!signature<subtype>::get(iter, tmp))
183 if(tmp.second.value == ATSPI_NULL_PATH)
189 if(tmp.second.value.substr(0, strlen(ATSPI_PREFIX_PATH)) != ATSPI_PREFIX_PATH)
194 auto currentBridge = CurrentBridgePtr::GetCurrentBridge();
195 if(currentBridge->GetBusName() != tmp.first)
200 path = currentBridge->FindByPath(tmp.second.value.substr(strlen(ATSPI_PREFIX_PATH)));
201 return path != nullptr;
206 struct signature<Dali::Accessibility::Accessible*> : public SignatureAccessibleImpl<Dali::Accessibility::Accessible>
211 struct signature<Dali::Accessibility::Address> : signature_helper<signature<Dali::Accessibility::Address>>
213 using subtype = std::pair<std::string, ObjectPath>;
215 static constexpr auto name_v = concat("AtspiAccessiblePtr");
216 static constexpr auto sig_v = concat("(so)");
219 * @brief Marshals value address as marshalled type into message
221 static void set(const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::Address& address)
225 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{std::string{ATSPI_PREFIX_PATH} + address.GetPath()}});
229 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{ATSPI_NULL_PATH}});
234 * @brief Marshals value from marshalled type into variable address
236 static bool get(const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::Address& address)
239 if(!signature<subtype>::get(iter, tmp))
244 if(tmp.second.value == ATSPI_NULL_PATH)
249 if(tmp.second.value.substr(0, strlen(ATSPI_PREFIX_PATH)) != ATSPI_PREFIX_PATH)
254 address = {std::move(tmp.first), tmp.second.value.substr(strlen(ATSPI_PREFIX_PATH))};
260 struct signature<Dali::Accessibility::States> : signature_helper<signature<Dali::Accessibility::States>>
262 using subtype = std::array<uint32_t, 2>;
264 static constexpr auto name_v = signature<subtype>::name_v;
265 static constexpr auto sig_v = signature<subtype>::sig_v;
268 * @brief Marshals value state as marshalled type into message
270 static void set(const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::States& states)
272 signature<subtype>::set(iter, states.GetRawData());
276 * @brief Marshals value from marshalled type into variable state
278 static bool get(const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::States& state)
281 if(!signature<subtype>::get(iter, tmp))
285 state = Dali::Accessibility::States{tmp};
289 } // namespace detail
296 std::ostringstream mTmp;
298 _Logger(const char* file, int line)
306 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d: %s", mFile, mLine, mTmp.str().c_str());
310 _Logger& operator<<(T&& t)
312 mTmp << std::forward<T>(t);
320 _LoggerEmpty& operator<<(T&& t)
331 _LoggerScope(const char* file, int line)
335 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d: +", mFile, mLine);
340 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d: -", mFile, mLine);
344 #define LOG() _Logger(__FILE__, __LINE__)
345 #define SCOPE() _LoggerScope _l##__LINE__(__FILE__, __LINE__)
347 #endif // DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H