1 #ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H
2 #define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_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/public-api/dali-adaptor-version.h>
23 #include <dali/public-api/signals/connection-tracker.h>
24 #include <dali/public-api/actors/layer.h>
28 #include <dali/devel-api/adaptor-framework/window-devel.h>
29 #include <dali/internal/accessibility/bridge/accessibility-common.h>
32 * @brief The AppAccessible class is to define Accessibility Application.
34 class AppAccessible : public virtual Dali::Accessibility::Accessible, public virtual Dali::Accessibility::Collection, public virtual Dali::Accessibility::Application
37 Dali::Accessibility::EmptyAccessibleWithAddress mParent;
38 std::vector<Dali::Accessibility::Accessible*> mChildren;
41 std::string GetName() override
46 std::string GetDescription() override
51 Dali::Accessibility::Accessible* GetParent() override
56 size_t GetChildCount() override
58 return mChildren.size();
61 Dali::Accessibility::Accessible* GetChildAtIndex(size_t index) override
63 auto size = mChildren.size();
66 throw std::domain_error{"invalid index " + std::to_string(index) + " for object with " + std::to_string(size) + " children"};
68 return mChildren[index];
71 size_t GetIndexInParent() override
73 throw std::domain_error{"can't call GetIndexInParent on application object"};
76 Dali::Accessibility::Role GetRole() override
78 return Dali::Accessibility::Role::APPLICATION;
81 Dali::Accessibility::States GetStates() override
86 Dali::Accessibility::Attributes GetAttributes() override
92 * @brief Gets the Accessible object from the window.
94 * @param[in] window The window to find
95 * @return Null if mChildren is empty, otherwise the Accessible object
96 * @note Currently, the default window would be returned when mChildren is not empty.
98 Dali::Accessibility::Accessible* GetWindowAccessible(Dali::Window window)
100 if(mChildren.empty())
105 Dali::Layer rootLayer = window.GetRootLayer();
107 // Find a child which is related to the window.
108 for(auto i = 0u; i < mChildren.size(); ++i)
110 if(rootLayer == mChildren[i]->GetInternalActor())
116 // If can't find its children, return the default window.
120 bool DoGesture(const Dali::Accessibility::GestureInfo& gestureInfo) override
125 std::vector<Dali::Accessibility::Relation> GetRelationSet() override
130 Dali::Actor GetInternalActor() override
132 return Dali::Actor{};
135 Dali::Accessibility::Address GetAddress() override
140 std::string GetToolkitName() override
145 std::string GetVersion() override
147 return std::to_string(Dali::ADAPTOR_MAJOR_VERSION) + "." + std::to_string(Dali::ADAPTOR_MINOR_VERSION);
152 * @brief Enumeration for FilteredEvents.
154 enum class FilteredEvents
156 BOUNDS_CHANGED ///< Bounds changed
159 // Custom specialization of std::hash
163 struct hash<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>>
165 size_t operator()(std::pair<FilteredEvents, Dali::Accessibility::Accessible*> value) const
167 return (static_cast<size_t>(value.first) * 131) ^ reinterpret_cast<size_t>(value.second);
173 * @brief The BridgeBase class is basic class for Bridge functions.
175 class BridgeBase : public Dali::Accessibility::Bridge, public Dali::ConnectionTracker
177 std::unordered_map<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>, std::pair<unsigned int, std::function<void()>>> mFilteredEvents;
180 * @brief Removes all FilteredEvents using Tick signal.
182 * @return False if mFilteredEvents is empty, otherwise true.
184 bool TickFilteredEvents();
188 * @brief Adds FilteredEvents, Accessible, and delay time to mFilteredEvents.
190 * @param[in] kind FilteredEvents enum value
191 * @param[in] obj Accessible object
192 * @param[in] delay The delay time
193 * @param[in] functor The function to be called // NEED TO UPDATE!
195 void AddFilteredEvent(FilteredEvents kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor);
198 * @brief Callback when the visibility of the window is changed.
200 * @param[in] window The window to be changed
201 * @param[in] visible The visibility of the window
203 void OnWindowVisibilityChanged(Dali::Window window, bool visible);
206 * @brief Callback when the window focus is changed.
208 * @param[in] window The window whose focus is changed
209 * @param[in] focusIn Whether the focus is in/out
211 void OnWindowFocusChanged(Dali::Window window, bool focusIn);
214 * @copydoc Dali::Accessibility::Bridge::GetBusName()
216 const std::string& GetBusName() const override;
219 * @copydoc Dali::Accessibility::Bridge::AddTopLevelWindow()
221 void AddTopLevelWindow(Dali::Accessibility::Accessible* windowAccessible) override;
224 * @copydoc Dali::Accessibility::Bridge::RemoveTopLevelWindow()
226 void RemoveTopLevelWindow(Dali::Accessibility::Accessible* windowAccessible) override;
229 * @copydoc Dali::Accessibility::Bridge::AddPopup()
231 void AddPopup(Dali::Accessibility::Accessible* object) override;
234 * @copydoc Dali::Accessibility::Bridge::RemovePopup()
236 void RemovePopup(Dali::Accessibility::Accessible* object) override;
239 * @copydoc Dali::Accessibility::Bridge::GetApplication()
241 Dali::Accessibility::Accessible* GetApplication() const override
243 return &mApplication;
247 * @brief Adds function to dbus interface.
249 template<typename SELF, typename... RET, typename... ARGS>
250 void AddFunctionToInterface(
251 DBus::DBusInterfaceDescription& desc, const std::string& funcName, DBus::ValueOrError<RET...> (SELF::*funcPtr)(ARGS...))
253 if(auto self = dynamic_cast<SELF*>(this))
254 desc.addMethod<DBus::ValueOrError<RET...>(ARGS...)>(
256 [=](ARGS... args) -> DBus::ValueOrError<RET...> {
259 return (self->*funcPtr)(std::move(args)...);
261 catch(std::domain_error& e)
263 return DBus::Error{e.what()};
269 * @brief Adds 'Get' property to dbus interface.
271 template<typename T, typename SELF>
272 void AddGetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
273 const std::string& funcName,
274 T (SELF::*funcPtr)())
276 if(auto self = dynamic_cast<SELF*>(this))
277 desc.addProperty<T>(funcName,
278 [=]() -> DBus::ValueOrError<T> {
281 return (self->*funcPtr)();
283 catch(std::domain_error& e)
285 return DBus::Error{e.what()};
292 * @brief Adds 'Set' property to dbus interface.
294 template<typename T, typename SELF>
295 void AddSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
296 const std::string& funcName,
297 void (SELF::*funcPtr)(T))
299 if(auto self = dynamic_cast<SELF*>(this))
300 desc.addProperty<T>(funcName, {}, [=](T t) -> DBus::ValueOrError<void> {
303 (self->*funcPtr)(std::move(t));
306 catch(std::domain_error& e)
308 return DBus::Error{e.what()};
314 * @brief Adds 'Set' and 'Get' properties to dbus interface.
316 template<typename T, typename T1, typename SELF>
317 void AddGetSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
318 const std::string& funcName,
319 T1 (SELF::*funcPtrGet)(),
320 DBus::ValueOrError<void> (SELF::*funcPtrSet)(T))
322 if(auto self = dynamic_cast<SELF*>(this))
325 [=]() -> DBus::ValueOrError<T> {
328 return (self->*funcPtrGet)();
330 catch(std::domain_error& e)
332 return DBus::Error{e.what()};
335 [=](T t) -> DBus::ValueOrError<void> {
338 (self->*funcPtrSet)(std::move(t));
341 catch(std::domain_error& e)
343 return DBus::Error{e.what()};
349 * @brief Adds 'Get' and 'Set' properties to dbus interface.
351 template<typename T, typename T1, typename SELF>
352 void AddGetSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
353 const std::string& funcName,
354 T1 (SELF::*funcPtrGet)(),
355 void (SELF::*funcPtrSet)(T))
357 if(auto self = dynamic_cast<SELF*>(this))
360 [=]() -> DBus::ValueOrError<T> {
363 return (self->*funcPtrGet)();
365 catch(std::domain_error& e)
367 return DBus::Error{e.what()};
370 [=](T t) -> DBus::ValueOrError<void> {
373 (self->*funcPtrSet)(std::move(t));
376 catch(std::domain_error& e)
378 return DBus::Error{e.what()};
384 * @brief Gets the string of the path excluding the specified prefix.
386 * @param path The path to get
387 * @return The string stripped of the specific prefix
389 static std::string StripPrefix(const std::string& path);
392 * @brief Finds the Accessible object according to the path.
394 * @param[in] path The path for Accessible object
395 * @return The Accessible object corresponding to the path
397 Dali::Accessibility::Accessible* Find(const std::string& path) const;
400 * @brief Finds the Accessible object with the given address.
402 * @param[in] ptr The unique Address of the object
403 * @return The Accessible object corresponding to the path
405 Dali::Accessibility::Accessible* Find(const Dali::Accessibility::Address& ptr) const;
408 * @brief Returns the target object of the currently executed DBus method call.
410 * And any subclasses redefine `FindSelf` with a different return type as a convenient wrapper around dynamic_cast.
411 * @return The Accessible object
412 * @note When a DBus method is called on some object, this target object (`currentObject`) is temporarily saved by the bridge,
413 * because DBus handles the invocation target separately from the method arguments.
414 * We then use the saved object inside the 'glue' method (e.g. BridgeValue::GetMinimum)
415 * to call the equivalent method on the respective C++ object (this could be ScrollBar::AccessibleImpl::GetMinimum in the example given).
417 Dali::Accessibility::Accessible* FindSelf() const;
420 * @copydoc Dali::Accessibility::Bridge::FindByPath()
422 Dali::Accessibility::Accessible* FindByPath(const std::string& name) const override;
425 * @copydoc Dali::Accessibility::Bridge::SetApplicationName()
427 void SetApplicationName(std::string name) override
429 mApplication.mName = std::move(name);
433 mutable AppAccessible mApplication;
434 std::vector<Dali::Accessibility::Accessible*> mPopups;
435 bool mIsScreenReaderSuppressed = false;
441 * @param[in] id An ID (integer value)
446 * @brief Gets the ID.
447 * @return The ID to be set
452 * @brief Update registered events.
454 void UpdateRegisteredEvents();
456 using CacheElementType = std::tuple<
457 Dali::Accessibility::Address,
458 Dali::Accessibility::Address,
459 Dali::Accessibility::Address,
460 std::vector<Dali::Accessibility::Address>,
461 std::vector<std::string>,
463 Dali::Accessibility::Role,
465 std::array<uint32_t, 2>>;
468 * @brief Gets Items // NEED TO UPDATE!
472 DBus::ValueOrError<std::vector<CacheElementType>> GetItems();
475 * @brief Creates CacheElement.
477 * CreateCacheElement method works for GetItems which is a part of ATSPI protocol.
478 * ATSPI client library (libatspi from at-spi2-core) depending on cacheing policy configuration uses GetItems
479 * to pre-load entire accessible tree from application to its own cache in single dbus call.
480 * Otherwise the particular nodes in a tree are cached lazily when client library tries to access them.
481 * @param item Accessible to get information
482 * @return The elements to be cached
484 CacheElementType CreateCacheElement(Dali::Accessibility::Accessible* item);
488 virtual ~BridgeBase();
491 * @copydoc Dali::Accessibility::Bridge::ForceUp()
493 ForceUpResult ForceUp() override;
496 * @copydoc Dali::Accessibility::Bridge::ForceDown()
498 void ForceDown() override;
500 DBus::DBusServer mDbusServer;
501 DBusWrapper::ConnectionPtr mConnectionPtr;
503 DBus::DBusClient mRegistry;
504 bool IsBoundsChangedEventAllowed{false};
507 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H