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;
39 std::vector<Dali::Window> mWindows;
42 std::string GetName() override
47 std::string GetDescription() override
52 Dali::Accessibility::Accessible* GetParent() override
57 size_t GetChildCount() override
59 return mChildren.size();
62 Dali::Accessibility::Accessible* GetChildAtIndex(size_t index) override
64 auto size = mChildren.size();
67 throw std::domain_error{"invalid index " + std::to_string(index) + " for object with " + std::to_string(size) + " children"};
69 return mChildren[index];
72 size_t GetIndexInParent() override
74 throw std::domain_error{"can't call GetIndexInParent on application object"};
77 Dali::Accessibility::Role GetRole() override
79 return Dali::Accessibility::Role::APPLICATION;
82 Dali::Accessibility::States GetStates() override
87 Dali::Accessibility::Attributes GetAttributes() override
93 * @brief Gets the Accessible object from the window.
95 * @param[in] window The window to find
96 * @return Null if mChildren is empty, otherwise the Accessible object
97 * @note Currently, the default window would be returned when mChildren is not empty.
99 Dali::Accessibility::Accessible* GetWindowAccessible(Dali::Window window)
101 if(mChildren.empty())
106 Dali::Layer rootLayer = window.GetRootLayer();
108 // Find a child which is related to the window.
109 for(auto i = 0u; i < mChildren.size(); ++i)
111 if(rootLayer == mChildren[i]->GetInternalActor())
117 // If can't find its children, return the default window.
121 bool DoGesture(const Dali::Accessibility::GestureInfo& gestureInfo) override
126 std::vector<Dali::Accessibility::Relation> GetRelationSet() override
131 Dali::Actor GetInternalActor() override
133 return Dali::Actor{};
136 Dali::Accessibility::Address GetAddress() override
141 std::string GetToolkitName() override
146 std::string GetVersion() override
148 return std::to_string(Dali::ADAPTOR_MAJOR_VERSION) + "." + std::to_string(Dali::ADAPTOR_MINOR_VERSION);
153 * @brief Enumeration for FilteredEvents.
155 enum class FilteredEvents
157 BOUNDS_CHANGED ///< Bounds changed
160 // Custom specialization of std::hash
164 struct hash<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>>
166 size_t operator()(std::pair<FilteredEvents, Dali::Accessibility::Accessible*> value) const
168 return (static_cast<size_t>(value.first) * 131) ^ reinterpret_cast<size_t>(value.second);
174 * @brief The BridgeBase class is basic class for Bridge functions.
176 class BridgeBase : public Dali::Accessibility::Bridge, public Dali::ConnectionTracker
178 std::unordered_map<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>, std::pair<unsigned int, std::function<void()>>> mFilteredEvents;
181 * @brief Removes all FilteredEvents using Tick signal.
183 * @return False if mFilteredEvents is empty, otherwise true.
185 bool TickFilteredEvents();
189 * @brief Adds FilteredEvents, Accessible, and delay time to mFilteredEvents.
191 * @param[in] kind FilteredEvents enum value
192 * @param[in] obj Accessible object
193 * @param[in] delay The delay time
194 * @param[in] functor The function to be called // NEED TO UPDATE!
196 void AddFilteredEvent(FilteredEvents kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor);
199 * @brief Callback when the visibility of the window is changed.
201 * @param[in] window The window to be changed
202 * @param[in] visible The visibility of the window
204 void OnWindowVisibilityChanged(Dali::Window window, bool visible);
207 * @brief Callback when the window focus is changed.
209 * @param[in] window The window whose focus is changed
210 * @param[in] focusIn Whether the focus is in/out
212 void OnWindowFocusChanged(Dali::Window window, bool focusIn);
215 * @copydoc Dali::Accessibility::Bridge::GetBusName()
217 const std::string& GetBusName() const override;
220 * @copydoc Dali::Accessibility::Bridge::AddTopLevelWindow()
222 void AddTopLevelWindow(Dali::Accessibility::Accessible* windowAccessible) override;
225 * @copydoc Dali::Accessibility::Bridge::RemoveTopLevelWindow()
227 void RemoveTopLevelWindow(Dali::Accessibility::Accessible* windowAccessible) override;
230 * @copydoc Dali::Accessibility::Bridge::AddPopup()
232 void AddPopup(Dali::Accessibility::Accessible* object) override;
235 * @copydoc Dali::Accessibility::Bridge::RemovePopup()
237 void RemovePopup(Dali::Accessibility::Accessible* object) override;
240 * @copydoc Dali::Accessibility::Bridge::GetApplication()
242 Dali::Accessibility::Accessible* GetApplication() const override
244 return &mApplication;
248 * @brief Adds function to dbus interface.
250 template<typename SELF, typename... RET, typename... ARGS>
251 void AddFunctionToInterface(
252 DBus::DBusInterfaceDescription& desc, const std::string& funcName, DBus::ValueOrError<RET...> (SELF::*funcPtr)(ARGS...))
254 if(auto self = dynamic_cast<SELF*>(this))
255 desc.addMethod<DBus::ValueOrError<RET...>(ARGS...)>(
257 [=](ARGS... args) -> DBus::ValueOrError<RET...> {
260 return (self->*funcPtr)(std::move(args)...);
262 catch(std::domain_error& e)
264 return DBus::Error{e.what()};
270 * @brief Adds 'Get' property to dbus interface.
272 template<typename T, typename SELF>
273 void AddGetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
274 const std::string& funcName,
275 T (SELF::*funcPtr)())
277 if(auto self = dynamic_cast<SELF*>(this))
278 desc.addProperty<T>(funcName,
279 [=]() -> DBus::ValueOrError<T> {
282 return (self->*funcPtr)();
284 catch(std::domain_error& e)
286 return DBus::Error{e.what()};
293 * @brief Adds 'Set' property to dbus interface.
295 template<typename T, typename SELF>
296 void AddSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
297 const std::string& funcName,
298 void (SELF::*funcPtr)(T))
300 if(auto self = dynamic_cast<SELF*>(this))
301 desc.addProperty<T>(funcName, {}, [=](T t) -> DBus::ValueOrError<void> {
304 (self->*funcPtr)(std::move(t));
307 catch(std::domain_error& e)
309 return DBus::Error{e.what()};
315 * @brief Adds 'Set' and 'Get' properties to dbus interface.
317 template<typename T, typename T1, typename SELF>
318 void AddGetSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
319 const std::string& funcName,
320 T1 (SELF::*funcPtrGet)(),
321 DBus::ValueOrError<void> (SELF::*funcPtrSet)(T))
323 if(auto self = dynamic_cast<SELF*>(this))
326 [=]() -> DBus::ValueOrError<T> {
329 return (self->*funcPtrGet)();
331 catch(std::domain_error& e)
333 return DBus::Error{e.what()};
336 [=](T t) -> DBus::ValueOrError<void> {
339 (self->*funcPtrSet)(std::move(t));
342 catch(std::domain_error& e)
344 return DBus::Error{e.what()};
350 * @brief Adds 'Get' and 'Set' properties to dbus interface.
352 template<typename T, typename T1, typename SELF>
353 void AddGetSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
354 const std::string& funcName,
355 T1 (SELF::*funcPtrGet)(),
356 void (SELF::*funcPtrSet)(T))
358 if(auto self = dynamic_cast<SELF*>(this))
361 [=]() -> DBus::ValueOrError<T> {
364 return (self->*funcPtrGet)();
366 catch(std::domain_error& e)
368 return DBus::Error{e.what()};
371 [=](T t) -> DBus::ValueOrError<void> {
374 (self->*funcPtrSet)(std::move(t));
377 catch(std::domain_error& e)
379 return DBus::Error{e.what()};
385 * @brief Gets the string of the path excluding the specified prefix.
387 * @param path The path to get
388 * @return The string stripped of the specific prefix
390 static std::string StripPrefix(const std::string& path);
393 * @brief Finds the Accessible object according to the path.
395 * @param[in] path The path for Accessible object
396 * @return The Accessible object corresponding to the path
398 Dali::Accessibility::Accessible* Find(const std::string& path) const;
401 * @brief Finds the Accessible object with the given address.
403 * @param[in] ptr The unique Address of the object
404 * @return The Accessible object corresponding to the path
406 Dali::Accessibility::Accessible* Find(const Dali::Accessibility::Address& ptr) const;
409 * @brief Returns the target object of the currently executed DBus method call.
411 * And any subclasses redefine `FindSelf` with a different return type as a convenient wrapper around dynamic_cast.
412 * @return The Accessible object
413 * @note When a DBus method is called on some object, this target object (`currentObject`) is temporarily saved by the bridge,
414 * because DBus handles the invocation target separately from the method arguments.
415 * We then use the saved object inside the 'glue' method (e.g. BridgeValue::GetMinimum)
416 * to call the equivalent method on the respective C++ object (this could be ScrollBar::AccessibleImpl::GetMinimum in the example given).
418 Dali::Accessibility::Accessible* FindSelf() const;
421 * @copydoc Dali::Accessibility::Bridge::FindByPath()
423 Dali::Accessibility::Accessible* FindByPath(const std::string& name) const override;
426 * @copydoc Dali::Accessibility::Bridge::SetApplicationName()
428 void SetApplicationName(std::string name) override
430 mApplication.mName = std::move(name);
434 mutable AppAccessible mApplication;
435 std::vector<Dali::Accessibility::Accessible*> mPopups;
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