/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/accessibility/bridge/bridge-base.h>
// EXTERNAL INCLUDES
+#include <dali/devel-api/common/stage.h>
#include <atomic>
#include <cstdlib>
#include <memory>
// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/window-devel.h>
#include <dali/public-api/adaptor-framework/timer.h>
using namespace Dali::Accessibility;
static Dali::Timer tickTimer;
-BridgeBase::~BridgeBase()
+BridgeBase::BridgeBase()
{
}
-BridgeBase::BridgeBase()
+BridgeBase::~BridgeBase()
{
+ mApplication.mChildren.clear();
}
-void BridgeBase::AddFilteredEvent(FilteredEvents kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor)
+void BridgeBase::AddCoalescableMessage(CoalescableMessages kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor)
{
if(delay < 0)
{
delay = 0;
}
+ auto countdownBase = static_cast<unsigned int>(delay * 10);
- auto it = mFilteredEvents.insert({{kind, obj}, {static_cast<unsigned int>(delay * 10), {}}});
+ auto it = mCoalescableMessages.insert({{kind, obj}, {countdownBase, countdownBase, {}}});
if(it.second)
{
functor();
}
else
{
- it.first->second.second = std::move(functor);
+ std::get<1>(it.first->second) = countdownBase;
+ std::get<2>(it.first->second) = std::move(functor);
}
if(!tickTimer)
{
tickTimer = Dali::Timer::New(100);
- tickTimer.TickSignal().Connect(this, &BridgeBase::TickFilteredEvents);
+ tickTimer.TickSignal().Connect(this, &BridgeBase::TickCoalescableMessages);
+ }
+
+ if(!tickTimer.IsRunning())
+ {
+ tickTimer.Start();
}
}
-bool BridgeBase::TickFilteredEvents()
+bool BridgeBase::TickCoalescableMessages()
{
- for(auto it = mFilteredEvents.begin(); it != mFilteredEvents.end();)
+ for(auto it = mCoalescableMessages.begin(); it != mCoalescableMessages.end();)
{
- if(it->second.first)
+ auto& countdown = std::get<0>(it->second);
+ auto countdownBase = std::get<1>(it->second);
+ auto& functor = std::get<2>(it->second);
+ if(countdown)
{
- --it->second.first;
+ --countdown;
}
else
{
- if(it->second.second)
+ if(functor)
{
- it->second.second();
- it->second.second = {};
+ functor();
+ functor = {};
+ countdown = countdownBase;
}
else
{
- it = mFilteredEvents.erase(it);
+ it = mCoalescableMessages.erase(it);
continue;
}
}
++it;
}
- return !mFilteredEvents.empty();
+ return !mCoalescableMessages.empty();
}
void BridgeBase::UpdateRegisteredEvents()
BridgeBase::ForceUpResult BridgeBase::ForceUp()
{
- if(Bridge::ForceUp() == ForceUpResult::ALREADY_UP)
+ //TODO: checking mBusName is enough? or a new variable to check bridge state?
+ if(Bridge::ForceUp() == ForceUpResult::ALREADY_UP && !GetBusName().empty())
{
return ForceUpResult::ALREADY_UP;
}
if(!addr)
{
- throw std::domain_error{std::string("failed at call '") + dbusLocators::atspi::GET_ADDRESS + "': " + addr.getError().message};
+ DALI_LOG_ERROR("failed at call '%s': %s\n", dbusLocators::atspi::GET_ADDRESS, addr.getError().message.c_str());
+ return ForceUpResult::FAILED;
}
mConnectionPtr = DBusWrapper::Installed()->eldbus_address_connection_get_impl(std::get<0>(addr));
mDbusServer = {mConnectionPtr};
{
- DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceCache};
+ DBus::DBusInterfaceDescription desc{Accessible::GetInterfaceName(AtspiInterface::CACHE)};
AddFunctionToInterface(desc, "GetItems", &BridgeBase::GetItems);
mDbusServer.addInterface(AtspiDbusPathCache, desc);
}
{
- DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceApplication};
+ DBus::DBusInterfaceDescription desc{Accessible::GetInterfaceName(AtspiInterface::APPLICATION)};
AddGetSetPropertyToInterface(desc, "Id", &BridgeBase::GetId, &BridgeBase::SetId);
mDbusServer.addInterface(AtspiPath, desc);
}
- mRegistry = {AtspiDbusNameRegistry, AtspiDbusPathRegistry, AtspiDbusInterfaceRegistry, mConnectionPtr};
+ mRegistry = {AtspiDbusNameRegistry, AtspiDbusPathRegistry, Accessible::GetInterfaceName(AtspiInterface::REGISTRY), mConnectionPtr};
UpdateRegisteredEvents();
void BridgeBase::ForceDown()
{
Bridge::ForceDown();
+ tickTimer.Reset();
+ mCoalescableMessages.clear();
mRegistry = {};
mDbusServer = {};
mConnectionPtr = {};
}
}
-void BridgeBase::AddPopup(Accessible* object)
+void BridgeBase::AddTopLevelWindow(Accessible* windowAccessible)
{
- if(std::find(mPopups.begin(), mPopups.end(), object) != mPopups.end())
+ if(windowAccessible->GetInternalActor() == nullptr)
{
return;
}
- mPopups.push_back(object);
- if(IsUp())
+
+ // Prevent adding the default window twice.
+ if(!mApplication.mChildren.empty() &&
+ mApplication.mChildren[0]->GetInternalActor() == windowAccessible->GetInternalActor())
+ {
+ return;
+ }
+
+ // Adds Window to a list of Windows.
+ mApplication.mChildren.push_back(windowAccessible);
+ SetIsOnRootLevel(windowAccessible);
+}
+
+void BridgeBase::RemoveTopLevelWindow(Accessible* windowAccessible)
+{
+ for(auto i = 0u; i < mApplication.mChildren.size(); ++i)
{
- object->Emit(WindowEvent::ACTIVATE, 0);
+ if(mApplication.mChildren[i] == windowAccessible)
+ {
+ mApplication.mChildren.erase(mApplication.mChildren.begin() + i);
+ break;
+ }
}
}
-void BridgeBase::RemovePopup(Accessible* object)
+void BridgeBase::CompressDefaultLabels()
+{
+ // Remove entries for objects which no longer exist
+ mDefaultLabels.remove_if([](const DefaultLabelType& label) {
+ // Check 1) window's weak handle; 2) accessible's ref object
+ return !label.first.GetBaseHandle() || label.second.expired();
+ });
+}
+
+void BridgeBase::RegisterDefaultLabel(std::shared_ptr<Accessible> object)
{
- auto it = std::find(mPopups.begin(), mPopups.end(), object);
- if(it == mPopups.end())
+ CompressDefaultLabels();
+
+ Dali::WeakHandle<Dali::Window> window = GetWindow(object.get());
+ if(!window.GetBaseHandle()) // true also if `object` is null
{
+ DALI_LOG_ERROR("Cannot register default label: object does not belong to any window");
return;
}
- mPopups.erase(it);
- if(IsUp())
+ auto it = std::find_if(mDefaultLabels.begin(), mDefaultLabels.end(), [&object](const DefaultLabelType& label) {
+ auto labelPtr = label.second.lock();
+ return labelPtr && object == labelPtr;
+ });
+
+ if(it == mDefaultLabels.end())
{
- object->Emit(WindowEvent::DEACTIVATE, 0);
- if(mPopups.empty())
- {
- mApplication.mChildren.back()->Emit(WindowEvent::ACTIVATE, 0);
- }
- else
- {
- mPopups.back()->Emit(WindowEvent::ACTIVATE, 0);
- }
+ mDefaultLabels.push_back({window, object});
+ }
+ else if(it->first != window)
+ {
+ // TODO: Tentative implementation. It is yet to be specified what should happen
+ // when the same object is re-registered as a default label for another window.
+ *it = {window, object};
+ }
+ else // it->first == window && it->second == object
+ {
+ // Nothing to do
}
}
-void BridgeBase::AddTopLevelWindow(Accessible* root)
+void BridgeBase::UnregisterDefaultLabel(std::shared_ptr<Accessible> object)
{
- mApplication.mChildren.push_back(root);
- SetIsOnRootLevel(root);
+ CompressDefaultLabels();
+
+ mDefaultLabels.remove_if([&object](const DefaultLabelType& label) {
+ auto labelPtr = label.second.lock();
+ return labelPtr && object == labelPtr;
+ });
}
-void BridgeBase::RemoveTopLevelWindow(Accessible* root)
+Accessible* BridgeBase::GetDefaultLabel(Accessible* root)
{
- for(auto i = 0u; i < mApplication.mChildren.size(); ++i)
+ CompressDefaultLabels();
+
+ Dali::WeakHandle<Dali::Window> window = GetWindow(root);
+ if(!window.GetBaseHandle())
{
- if(mApplication.mChildren[i] == root)
+ return root;
+ }
+
+ auto it = std::find_if(mDefaultLabels.rbegin(), mDefaultLabels.rend(), [&window](const DefaultLabelType& label) {
+ return window == label.first;
+ });
+
+ Accessible* rawPtr = root;
+ if(it != mDefaultLabels.rend())
+ {
+ if(auto labelPtr = it->second.lock())
{
- mApplication.mChildren.erase(mApplication.mChildren.begin() + i);
- break;
+ rawPtr = labelPtr.get();
}
}
+
+ return rawPtr;
}
std::string BridgeBase::StripPrefix(const std::string& path)
return &mApplication;
}
- void* accessible;
+ void* accessible;
std::istringstream tmp{path};
if(!(tmp >> accessible))
{
}
auto it = mData->mKnownObjects.find(static_cast<Accessible*>(accessible));
- if(it == mData->mKnownObjects.end())
+ if(it == mData->mKnownObjects.end() || (!mApplication.mShouldIncludeHidden && (*it)->IsHidden()))
{
throw std::domain_error{"unknown object '" + path + "'"};
}
return Find(ptr.GetPath());
}
-Accessible* BridgeBase::FindSelf() const
+Accessible* BridgeBase::FindCurrentObject() const
{
- auto path = DBus::DBusServer::getCurrentObjectPath();
+ auto path = DBus::DBusServer::getCurrentObjectPath();
auto size = strlen(AtspiPath);
if(path.size() <= size)
{
root->GetAddress(),
parent ? parent->GetAddress() : Address{},
children,
- item->GetInterfaces(),
+ item->GetInterfacesAsStrings(),
item->GetName(),
item->GetRole(),
item->GetDescription(),
item->GetStates().GetRawData());
}
+
+Dali::WeakHandle<Dali::Window> BridgeBase::GetWindow(Dali::Accessibility::Accessible* accessible)
+{
+ Dali::WeakHandle<Dali::Window> windowHandle;
+ Dali::Actor actor = accessible ? accessible->GetInternalActor() : Dali::Actor();
+
+ if(actor)
+ {
+ Dali::Window window = Dali::DevelWindow::Get(actor);
+ windowHandle = {window};
+ }
+
+ return windowHandle;
+}