X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali%2Finternal%2Faccessibility%2Fbridge%2Fbridge-impl.cpp;h=b5c275ede8cf3cb6f8f0049ff5924110a091bcd7;hb=7b3e06d477c70c002b2fdcec1e7ba112f1ab09c8;hp=b424b6a86b5de5f942f2e25a5169e7d38b7f40cb;hpb=ea839b978d6cdc4e23d8322157f16ba6d703a3e1;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/accessibility/bridge/bridge-impl.cpp b/dali/internal/accessibility/bridge/bridge-impl.cpp index b424b6a..b5c275e 100644 --- a/dali/internal/accessibility/bridge/bridge-impl.cpp +++ b/dali/internal/accessibility/bridge/bridge-impl.cpp @@ -43,6 +43,9 @@ using namespace Dali::Accessibility; +/** + * @brief The BridgeImpl class is to implement some Bridge functions. + */ class BridgeImpl : public virtual BridgeBase, public BridgeAccessible, public BridgeObject, @@ -55,45 +58,25 @@ class BridgeImpl : public virtual BridgeBase, public BridgeSelection, public BridgeApplication { - DBus::DBusClient listenOnAtspiEnabledSignalClient; - DBus::DBusClient registryClient, directReadingClient; - bool screenReaderEnabled = false; - bool isEnabled = false; - bool isShown = false; - std::unordered_map> directReadingCallbacks; - Dali::Actor highlightedActor; - std::function highlightClearAction; + DBus::DBusClient mAccessibilityStatusClient; + DBus::DBusClient mRegistryClient; + DBus::DBusClient mDirectReadingClient; + bool mIsScreenReaderEnabled = false; + bool mIsEnabled = false; + bool mIsShown = false; + std::unordered_map> mDirectReadingCallbacks; + Dali::Actor mHighlightedActor; + std::function mHighlightClearAction; + Dali::CallbackBase* mIdleCallback = NULL; public: BridgeImpl() { - listenOnAtspiEnabledSignalClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION}; - - listenOnAtspiEnabledSignalClient.addPropertyChangedEvent("ScreenReaderEnabled", [this](bool res) { - screenReaderEnabled = res; - if(screenReaderEnabled || isEnabled) - { - ForceUp(); - } - else - { - ForceDown(); - } - }); - - listenOnAtspiEnabledSignalClient.addPropertyChangedEvent("IsEnabled", [this](bool res) { - isEnabled = res; - if(screenReaderEnabled || isEnabled) - { - ForceUp(); - } - else - { - ForceDown(); - } - }); } + /** + * @copydoc Dali::Accessibility::Bridge::Emit() + */ Consumed Emit(KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) override { if(!IsUp()) @@ -120,8 +103,9 @@ public: return Consumed::NO; } } - auto m = registryClient.method)>("NotifyListenersSync"); - auto result = m.call(std::tuple{keyType, 0, static_cast(keyCode), 0, static_cast(timeStamp), keyName, isText ? 1 : 0}); + + auto methodObject = mRegistryClient.method)>("NotifyListenersSync"); + auto result = methodObject.call(std::tuple{keyType, 0, static_cast(keyCode), 0, static_cast(timeStamp), keyName, isText ? 1 : 0}); if(!result) { LOG() << result.getError().message; @@ -130,6 +114,9 @@ public: return std::get<0>(result) ? Consumed::YES : Consumed::NO; } + /** + * @copydoc Dali::Accessibility::Bridge::Pause() + */ void Pause() override { if(!IsUp()) @@ -137,7 +124,7 @@ public: return; } - directReadingClient.method(bool)>("PauseResume").asyncCall([](DBus::ValueOrError msg) { + mDirectReadingClient.method(bool)>("PauseResume").asyncCall([](DBus::ValueOrError msg) { if(!msg) { LOG() << "Direct reading command failed (" << msg.getError().message << ")"; @@ -146,6 +133,9 @@ public: true); } + /** + * @copydoc Dali::Accessibility::Bridge::Resume() + */ void Resume() override { if(!IsUp()) @@ -153,7 +143,7 @@ public: return; } - directReadingClient.method(bool)>("PauseResume").asyncCall([](DBus::ValueOrError msg) { + mDirectReadingClient.method(bool)>("PauseResume").asyncCall([](DBus::ValueOrError msg) { if(!msg) { LOG() << "Direct reading command failed (" << msg.getError().message << ")"; @@ -162,6 +152,9 @@ public: false); } + /** + * @copydoc Dali::Accessibility::Bridge::StopReading() + */ void StopReading(bool alsoNonDiscardable) override { if(!IsUp()) @@ -169,7 +162,7 @@ public: return; } - directReadingClient.method(bool)>("StopReading").asyncCall([](DBus::ValueOrError msg) { + mDirectReadingClient.method(bool)>("StopReading").asyncCall([](DBus::ValueOrError msg) { if(!msg) { LOG() << "Direct reading command failed (" << msg.getError().message << ")"; @@ -178,6 +171,9 @@ public: alsoNonDiscardable); } + /** + * @copydoc Dali::Accessibility::Bridge::Say() + */ void Say(const std::string& text, bool discardable, std::function callback) override { if(!IsUp()) @@ -185,20 +181,23 @@ public: return; } - directReadingClient.method(std::string, bool)>("ReadCommand").asyncCall([=](DBus::ValueOrError msg) { + mDirectReadingClient.method(std::string, bool)>("ReadCommand").asyncCall([=](DBus::ValueOrError msg) { if(!msg) { LOG() << "Direct reading command failed (" << msg.getError().message << ")"; } else if(callback) { - directReadingCallbacks.emplace(std::get<2>(msg), callback); + mDirectReadingCallbacks.emplace(std::get<2>(msg), callback); } }, text, discardable); } + /** + * @copydoc Dali::Accessibility::Bridge::ForceDown() + */ void ForceDown() override { if(mData) @@ -209,15 +208,22 @@ public: } mData->mCurrentlyHighlightedActor = {}; mData->mHighlightActor = {}; + + mDisabledSignal.Emit(); } - highlightedActor = {}; - highlightClearAction = {}; + mHighlightedActor = {}; + mHighlightClearAction = {}; BridgeAccessible::ForceDown(); - registryClient = {}; - directReadingClient = {}; - directReadingCallbacks.clear(); + mRegistryClient = {}; + mDirectReadingClient = {}; + mDirectReadingCallbacks.clear(); + mApplication.mChildren.clear(); + mApplication.mWindows.clear(); } + /** + * @copydoc Dali::Accessibility::Bridge::Terminate() + */ void Terminate() override { if(mData) @@ -226,11 +232,18 @@ public: mData->mHighlightActor = {}; } ForceDown(); - listenOnAtspiEnabledSignalClient = {}; - dbusServer = {}; - con = {}; + if((NULL != mIdleCallback) && Dali::Adaptor::IsAvailable()) + { + Dali::Adaptor::Get().RemoveIdle(mIdleCallback); + } + mAccessibilityStatusClient = {}; + mDbusServer = {}; + mConnectionPtr = {}; } + /** + * @copydoc Dali::Accessibility::Bridge::ForceUp() + */ ForceUpResult ForceUp() override { if(BridgeAccessible::ForceUp() == ForceUpResult::ALREADY_UP) @@ -249,21 +262,24 @@ public: BridgeSelection::RegisterInterfaces(); BridgeApplication::RegisterInterfaces(); - RegisterOnBridge(&application); + RegisterOnBridge(&mApplication); + + mRegistryClient = {AtspiDbusNameRegistry, AtspiDbusPathDec, AtspiDbusInterfaceDec, mConnectionPtr}; + mDirectReadingClient = DBus::DBusClient{DirectReadingDBusName, DirectReadingDBusPath, DirectReadingDBusInterface, mConnectionPtr}; - registryClient = {AtspiDbusNameRegistry, AtspiDbusPathDec, AtspiDbusInterfaceDec, con}; - directReadingClient = DBus::DBusClient{DirectReadingDBusName, DirectReadingDBusPath, DirectReadingDBusInterface, con}; - directReadingClient.addSignal("ReadingStateChanged", [=](int32_t id, std::string readingState) { - auto it = directReadingCallbacks.find(id); - if(it != directReadingCallbacks.end()) + mDirectReadingClient.addSignal("ReadingStateChanged", [=](int32_t id, std::string readingState) { + auto it = mDirectReadingCallbacks.find(id); + if(it != mDirectReadingCallbacks.end()) { it->second(readingState); if(readingState != "ReadingPaused" && readingState != "ReadingResumed" && readingState != "ReadingStarted") - directReadingCallbacks.erase(it); + { + mDirectReadingCallbacks.erase(it); + } } }); - auto proxy = DBus::DBusClient{AtspiDbusNameRegistry, AtspiDbusPathRoot, AtspiDbusInterfaceSocket, con}; + auto proxy = DBus::DBusClient{AtspiDbusNameRegistry, AtspiDbusPathRoot, AtspiDbusInterfaceSocket, mConnectionPtr}; Address root{"", "root"}; auto res = proxy.method("Embed").call(root); if(!res) @@ -271,87 +287,285 @@ public: LOG() << "Call to Embed failed: " << res.getError().message; } assert(res); - application.parent.SetAddress(std::move(std::get<0>(res))); - if(isShown) + + mApplication.mParent.SetAddress(std::move(std::get<0>(res))); + + if(mIsShown) { - EmitActivate(); + auto rootLayer = Dali::Stage::GetCurrent().GetRootLayer(); + auto window = Dali::DevelWindow::Get(rootLayer); + EmitActivate(window); // Currently, sends a signal that the default window is activated here. } + + mEnabledSignal.Emit(); + return ForceUpResult::JUST_STARTED; } - void EmitActivate() + /** + * @brief Sends a signal to dbus that the window is shown. + * + * @param[in] window The window to be shown + * @see Accessible::EmitShowing() and BridgeObject::EmitStateChanged() + */ + void EmitShown(Dali::Window window) { - auto win = application.getActiveWindow(); - if(win) + auto windowAccessible = mApplication.GetWindowAccessible(window); + if(windowAccessible) { - win->Emit(WindowEvent::ACTIVATE, 0); + windowAccessible->EmitShowing(true); } } - void EmitDeactivate() + /** + * @brief Sends a signal to dbus that the window is hidden. + * + * @param[in] window The window to be hidden + * @see Accessible::EmitShowing() and BridgeObject::EmitStateChanged() + */ + void EmitHidden(Dali::Window window) { - auto win = application.getActiveWindow(); - if(win) + auto windowAccessible = mApplication.GetWindowAccessible(window); + if(windowAccessible) { - win->Emit(WindowEvent::DEACTIVATE, 0); + windowAccessible->EmitShowing(false); } } - void ApplicationHidden() override + /** + * @brief Sends a signal to dbus that the window is activated. + * + * @param[in] window The window to be activated + * @see BridgeObject::Emit() + */ + void EmitActivate(Dali::Window window) { - if(isShown && IsUp()) + auto windowAccessible = mApplication.GetWindowAccessible(window); + if(windowAccessible) { - EmitDeactivate(); + windowAccessible->Emit(WindowEvent::ACTIVATE, 0); } - isShown = false; } - void ApplicationShown() override + /** + * @brief Sends a signal to dbus that the window is deactivated. + * + * @param[in] window The window to be deactivated + * @see BridgeObject::Emit() + */ + void EmitDeactivate(Dali::Window window) { - if(!isShown && IsUp()) + auto windowAccessible = mApplication.GetWindowAccessible(window); + if(windowAccessible) { - EmitActivate(); + windowAccessible->Emit(WindowEvent::DEACTIVATE, 0); } - isShown = true; } - void Initialize() override + /** + * @copydoc Dali::Accessibility::Bridge::WindowShown() + */ + void WindowShown(Dali::Window window) override + { + if(!mIsShown && IsUp()) + { + EmitShown(window); + } + mIsShown = true; + } + + /** + * @copydoc Dali::Accessibility::Bridge::WindowHidden() + */ + void WindowHidden(Dali::Window window) override + { + if(mIsShown && IsUp()) + { + EmitHidden(window); + } + mIsShown = false; + } + + /** + * @copydoc Dali::Accessibility::Bridge::WindowFocused() + */ + void WindowFocused(Dali::Window window) override + { + if(mIsShown && IsUp()) + { + EmitActivate(window); + } + } + + /** + * @copydoc Dali::Accessibility::Bridge::WindowUnfocused() + */ + void WindowUnfocused(Dali::Window window) override + { + if(mIsShown && IsUp()) + { + EmitDeactivate(window); + } + } + + void ReadIsEnabledProperty() + { + mAccessibilityStatusClient.property("IsEnabled").asyncGet([this](DBus::ValueOrError msg) { + if(!msg) + { + DALI_LOG_ERROR("Get IsEnabled property error: %s\n", msg.getError().message.c_str()); + if(msg.getError().errorType == DBus::ErrorType::INVALID_REPLY) + { + ReadIsEnabledProperty(); + } + return; + } + mIsEnabled = std::get<0>(msg); + if(mIsEnabled) + { + ForceUp(); + } + }); + } + + void ListenIsEnabledProperty() + { + mAccessibilityStatusClient.addPropertyChangedEvent("IsEnabled", [this](bool res) { + mIsEnabled = res; + if(mIsScreenReaderEnabled || mIsEnabled) + { + ForceUp(); + } + else + { + ForceDown(); + } + }); + } + + void ReadScreenReaderEnabledProperty() + { + mAccessibilityStatusClient.property("ScreenReaderEnabled").asyncGet([this](DBus::ValueOrError msg) { + if(!msg) + { + DALI_LOG_ERROR("Get ScreenReaderEnabled property error: %s\n", msg.getError().message.c_str()); + if(msg.getError().errorType == DBus::ErrorType::INVALID_REPLY) + { + ReadScreenReaderEnabledProperty(); + } + return; + } + mIsScreenReaderEnabled = std::get<0>(msg); + if(mIsScreenReaderEnabled) + { + ForceUp(); + } + }); + } + + void ListenScreenReaderEnabledProperty() + { + mAccessibilityStatusClient.addPropertyChangedEvent("ScreenReaderEnabled", [this](bool res) { + mIsScreenReaderEnabled = res; + if(mIsScreenReaderEnabled || mIsEnabled) + { + ForceUp(); + } + else + { + ForceDown(); + } + }); + } + + void ReadAndListenProperties() + { + ReadIsEnabledProperty(); + ListenIsEnabledProperty(); + + ReadScreenReaderEnabledProperty(); + ListenScreenReaderEnabledProperty(); + } + + bool InitializeAccessibilityStatusClient() { - auto dbusClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION}; - auto enabled = dbusClient.property("ScreenReaderEnabled").get(); - if(enabled) + mAccessibilityStatusClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION}; + + if (!mAccessibilityStatusClient) { - screenReaderEnabled = std::get<0>(enabled); + DALI_LOG_ERROR("Accessibility Status DbusClient is not ready\n"); + return false; } - enabled = dbusClient.property("IsEnabled").get(); - if(enabled) + return true; + } + + bool OnIdleSignal() + { + if ( InitializeAccessibilityStatusClient() ) { - isEnabled = std::get<0>(enabled); + ReadAndListenProperties(); + mIdleCallback = NULL; + return false; } - if(screenReaderEnabled || isEnabled) + return true; + } + + /** + * @copydoc Dali::Accessibility::Bridge::Initialize() + */ + void Initialize() override + { + if ( InitializeAccessibilityStatusClient() ) { - ForceUp(); + ReadAndListenProperties(); + return; + } + + // Initialize failed. Try it again on Idle + if( Dali::Adaptor::IsAvailable() ) + { + Dali::Adaptor& adaptor = Dali::Adaptor::Get(); + if( NULL == mIdleCallback ) + { + mIdleCallback = MakeCallback( this, &BridgeImpl::OnIdleSignal ); + adaptor.AddIdle( mIdleCallback, true ); + } } } - bool GetScreenReaderEnabled() + /** + * @copydoc Dali::Accessibility::Bridge::GetScreenReaderEnabled() + */ + bool GetScreenReaderEnabled() override { - return screenReaderEnabled; + return mIsScreenReaderEnabled; } - bool IsEnabled() + /** + * @copydoc Dali::Accessibility::Bridge::IsEnabled() + */ + bool IsEnabled() override { - return isEnabled; + return mIsEnabled; } -}; +}; // BridgeImpl -static bool bridgeInitialized; +namespace // unnamed namespace +{ + +bool INITIALIZED_BRIDGE = false; -static Bridge* CreateBridge() +/** + * @brief Creates BridgeImpl instance. + * + * @return The BridgeImpl instance + * @note This method is to check environment variable first. If ATSPI is disable using env, it returns dummy bridge instance. + */ +Bridge* CreateBridge() { - bridgeInitialized = true; + INITIALIZED_BRIDGE = true; try { @@ -371,6 +585,10 @@ static Bridge* CreateBridge() } } +} // unnamed namespace + +// Dali::Accessibility::Bridge class implementation + Bridge* Bridge::GetCurrentBridge() { static Bridge* bridge; @@ -379,7 +597,7 @@ Bridge* Bridge::GetCurrentBridge() { return bridge; } - else if(autoInitState == AutoInitState::ENABLED) + else if(mAutoInitState == AutoInitState::ENABLED) { bridge = CreateBridge(); @@ -398,34 +616,36 @@ Bridge* Bridge::GetCurrentBridge() void Bridge::DisableAutoInit() { - if(bridgeInitialized) + if(INITIALIZED_BRIDGE) { DALI_LOG_ERROR("Bridge::DisableAutoInit() called after bridge auto-initialization"); } - autoInitState = AutoInitState::DISABLED; + mAutoInitState = AutoInitState::DISABLED; } void Bridge::EnableAutoInit() { - autoInitState = AutoInitState::ENABLED; + mAutoInitState = AutoInitState::ENABLED; - if(bridgeInitialized) + if(INITIALIZED_BRIDGE) { return; } - auto rootLayer = Dali::Stage::GetCurrent().GetRootLayer(); + auto rootLayer = Dali::Stage::GetCurrent().GetRootLayer(); // A root layer of the default window. auto window = Dali::DevelWindow::Get(rootLayer); auto applicationName = Dali::Internal::Adaptor::Adaptor::GetApplicationPackageName(); + auto accessible = Accessibility::Accessible::Get(rootLayer, true); + auto* bridge = Bridge::GetCurrentBridge(); - bridge->AddTopLevelWindow(Dali::Accessibility::Accessible::Get(rootLayer, true)); + bridge->AddTopLevelWindow(accessible); bridge->SetApplicationName(applicationName); bridge->Initialize(); if(window && window.IsVisible()) { - bridge->ApplicationShown(); + bridge->WindowShown(window); } }