#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;
BridgeBase::~BridgeBase()
{
mApplication.mChildren.clear();
- mApplication.mWindows.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::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())
- {
- object->Emit(WindowEvent::ACTIVATE, 0);
- }
-}
-void BridgeBase::RemovePopup(Accessible* object)
-{
- auto it = std::find(mPopups.begin(), mPopups.end(), object);
- if(it == mPopups.end())
+ // Prevent adding the default window twice.
+ if(!mApplication.mChildren.empty() &&
+ mApplication.mChildren[0]->GetInternalActor() == windowAccessible->GetInternalActor())
{
return;
}
- mPopups.erase(it);
- if(IsUp())
+ // 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::DEACTIVATE, 0);
- if(mPopups.empty())
- {
- mApplication.mChildren.back()->Emit(WindowEvent::ACTIVATE, 0);
- }
- else
+ if(mApplication.mChildren[i] == windowAccessible)
{
- mPopups.back()->Emit(WindowEvent::ACTIVATE, 0);
+ mApplication.mChildren.erase(mApplication.mChildren.begin() + i);
+ break;
}
}
}
-void BridgeBase::OnWindowVisibilityChanged(Dali::Window window, bool visible)
+void BridgeBase::CompressDefaultLabels()
{
- if(visible)
- {
- // TODO : Should we check 'out of screen' here? -> Then, we need an actor of this change.
- Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(window); // Called when Window is shown.
- }
- else
- {
- Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(window); // Called when Window is hidden and iconified.
- }
-
+ // Remove entries for objects which no longer exist
+ mDefaultLabels.remove_if([](const DefaultLabelType& label) {
+ return !label.first.GetBaseHandle(); // Check window's weak handle
+ // TODO: Once Accessible becomes a handle type, check its weak handle here as well
+ });
}
-void BridgeBase::OnWindowFocusChanged(Dali::Window window, bool focusIn)
+void BridgeBase::RegisterDefaultLabel(Accessible* object)
{
- if(focusIn)
+ CompressDefaultLabels();
+
+ Dali::WeakHandle<Dali::Window> window = GetWindow(object);
+ if(!window.GetBaseHandle()) // true also if `object` is null
{
- Dali::Accessibility::Bridge::GetCurrentBridge()->WindowFocused(window); // Called when Window is focused.
+ DALI_LOG_ERROR("Cannot register default label: object does not belong to any window");
+ return;
}
- else
+
+ auto it = std::find_if(mDefaultLabels.begin(), mDefaultLabels.end(), [object](const DefaultLabelType& label) {
+ return object == label.second;
+ });
+
+ if(it == mDefaultLabels.end())
{
- Dali::Accessibility::Bridge::GetCurrentBridge()->WindowUnfocused(window); // Called when Window is out of focus.
+ mDefaultLabels.push_back({window, object});
}
-}
-
-void BridgeBase::AddTopLevelWindow(Accessible* windowAccessible)
-{
- if(windowAccessible->GetInternalActor() == nullptr)
+ else if(it->first != window)
{
- return;
+ // 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};
}
-
- // Prevent adding the default window twice.
- if(!mApplication.mChildren.empty() &&
- mApplication.mChildren[0]->GetInternalActor() == windowAccessible->GetInternalActor())
+ else // it->first == window && it->second == object
{
- return;
+ // Nothing to do
}
+}
- // Adds Window to a list of Windows.
- mApplication.mChildren.push_back(windowAccessible);
- SetIsOnRootLevel(windowAccessible);
+void BridgeBase::UnregisterDefaultLabel(Accessible* object)
+{
+ CompressDefaultLabels();
- Dali::Window window = Dali::DevelWindow::Get(windowAccessible->GetInternalActor());
- if(window)
- {
- mApplication.mWindows.push_back(window);
- Dali::DevelWindow::VisibilityChangedSignal(window).Connect(this, &BridgeBase::OnWindowVisibilityChanged);
- window.FocusChangeSignal().Connect(this, &BridgeBase::OnWindowFocusChanged);
- }
+ mDefaultLabels.remove_if([object](const DefaultLabelType& label) {
+ return object == label.second;
+ });
}
-void BridgeBase::RemoveTopLevelWindow(Accessible* windowAccessible)
+Accessible* BridgeBase::GetDefaultLabel(Accessible* root) const
{
- for(auto i = 0u; i < mApplication.mWindows.size(); ++i)
+ Dali::WeakHandle<Dali::Window> window = GetWindow(root);
+ if(!window.GetBaseHandle())
{
- if(windowAccessible->GetInternalActor() == mApplication.mWindows[i].GetRootLayer())
- {
- Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(mApplication.mWindows[i]);
- Dali::DevelWindow::VisibilityChangedSignal(mApplication.mWindows[i]).Disconnect(this, &BridgeBase::OnWindowVisibilityChanged);
- mApplication.mWindows[i].FocusChangeSignal().Disconnect(this, &BridgeBase::OnWindowFocusChanged);
- mApplication.mWindows.erase(mApplication.mWindows.begin() + i);
- break;
- }
+ return root;
}
- for(auto i = 0u; i < mApplication.mChildren.size(); ++i)
- {
- if(mApplication.mChildren[i] == windowAccessible)
- {
- mApplication.mChildren.erase(mApplication.mChildren.begin() + i);
- break;
- }
- }
+ auto it = std::find_if(mDefaultLabels.rbegin(), mDefaultLabels.rend(), [&window](const DefaultLabelType& label) {
+ return window == label.first;
+ });
+
+ return (it == mDefaultLabels.rend()) ? root : it->second;
}
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() || (*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;
+}