2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/integration-api/debug.h>
23 #include <unordered_map>
26 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-accessible.h>
27 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-action.h>
28 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-collection.h>
29 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-component.h>
30 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-object.h>
31 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-value.h>
32 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-text.h>
33 #include <dali/internal/accessibility/tizen-wayland/atspi/bridge-editable-text.h>
35 using namespace Dali::Accessibility;
37 class BridgeImpl : public virtual BridgeBase,
38 public BridgeAccessible,
40 public BridgeComponent,
41 public BridgeCollection,
45 public BridgeEditableText
47 DBus::DBusClient listenOnAtspiEnabledSignalClient;
48 DBus::DBusClient registryClient, directReadingClient;
49 bool screenReaderEnabled = false;
50 bool isEnabled = false;
52 std::unordered_map <int32_t, std::function<void(std::string)>> directReadingCallbacks;
53 Dali::Actor highlightedActor;
54 std::function<void(Dali::Actor)> highlightClearAction;
59 listenOnAtspiEnabledSignalClient = DBus::DBusClient{ A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION };
61 listenOnAtspiEnabledSignalClient.addPropertyChangedEvent< bool >( "ScreenReaderEnabled", [this]( bool res )
63 screenReaderEnabled = res;
64 if( screenReaderEnabled || isEnabled )
75 listenOnAtspiEnabledSignalClient.addPropertyChangedEvent< bool >( "IsEnabled", [this]( bool res )
78 if( screenReaderEnabled || isEnabled )
90 Consumed Emit( KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText ) override
97 unsigned int evType = 0;
101 case KeyEventType::KEY_PRESSED:
106 case KeyEventType::KEY_RELEASED:
116 auto m = registryClient.method< bool( std::tuple< uint32_t, int32_t, int32_t, int32_t, int32_t, std::string, bool > ) >( "NotifyListenersSync" );
117 auto result = m.call( std::tuple< uint32_t, int32_t, int32_t, int32_t, int32_t, std::string, bool >{evType, 0, static_cast< int32_t >( keyCode ), 0, static_cast< int32_t >( timeStamp ), keyName, isText ? 1 : 0} );
120 LOG() << result.getError().message;
123 return std::get< 0 >( result ) ? Consumed::YES : Consumed::NO;
126 void Pause() override
128 auto r = directReadingClient.method< DBus::ValueOrError< void >( bool ) > ( "PauseResume" ).call( true );
131 LOG() << "Direct reading command failed (" << r.getError().message << ")";
135 void Resume() override
137 auto r = directReadingClient.method< DBus::ValueOrError< void >( bool ) > ( "PauseResume" ).call( false );
140 LOG() << "Direct reading command failed (" << r.getError().message << ")";
144 void Say( const std::string& text, bool discardable, std::function< void(std::string) > callback ) override
146 auto commandId = directReadingClient.method< DBus::ValueOrError< std::string, bool, int32_t >( std::string, bool ) > ( "ReadCommand" ).call( text, discardable );
149 LOG() << "Direct reading command failed (" << commandId.getError().message << ")";
153 directReadingCallbacks.emplace( std::get< 2 >( commandId ), callback);
157 void ForceDown() override
161 if (data->currentlyHighlightedActor && data->highlightActor)
163 data->currentlyHighlightedActor.Remove(data->highlightActor);
165 data->currentlyHighlightedActor = {};
166 data->highlightActor = {};
168 highlightedActor = {};
169 highlightClearAction = {};
170 BridgeAccessible::ForceDown();
172 directReadingClient = {};
173 directReadingCallbacks.clear();
176 void Terminate() override
180 data->currentlyHighlightedActor = {};
181 data->highlightActor = {};
184 listenOnAtspiEnabledSignalClient = {};
189 ForceUpResult ForceUp() override
191 if( BridgeAccessible::ForceUp() == ForceUpResult::ALREADY_UP )
193 return ForceUpResult::ALREADY_UP;
196 BridgeObject::RegisterInterfaces();
197 BridgeAccessible::RegisterInterfaces();
198 BridgeComponent::RegisterInterfaces();
199 BridgeCollection::RegisterInterfaces();
200 BridgeAction::RegisterInterfaces();
201 BridgeValue::RegisterInterfaces();
202 BridgeText::RegisterInterfaces();
203 BridgeEditableText::RegisterInterfaces();
205 RegisterOnBridge( &application );
207 registryClient = { AtspiDbusNameRegistry, AtspiDbusPathDec, AtspiDbusInterfaceDec, con };
208 directReadingClient = DBus::DBusClient{ DirectReadingDBusName, DirectReadingDBusPath, DirectReadingDBusInterface, con };
209 directReadingClient.addSignal< void(int32_t, std::string) >( "ReadingStateChanged", [=]( int32_t id, std::string readingState )
211 auto it = directReadingCallbacks.find( id );
212 if (it != directReadingCallbacks.end())
214 it->second( readingState );
215 directReadingCallbacks.erase( it );
220 auto proxy = DBus::DBusClient{AtspiDbusNameRegistry, AtspiDbusPathRoot, AtspiDbusInterfaceSocket, con};
221 Address root{"", "root"};
222 auto res = proxy.method< Address( Address ) >( "Embed" ).call( root );
225 LOG() << "Call to Embed failed: " << res.getError().message;
228 application.parent.SetAddress( std::move( std::get< 0 >( res ) ) );
233 return ForceUpResult::JUST_STARTED;
238 auto win = application.getActiveWindow();
241 win->Emit( WindowEvent::ACTIVATE, 0 );
245 void EmitDeactivate()
247 auto win = application.getActiveWindow();
250 win->Emit( WindowEvent::DEACTIVATE, 0 );
254 void ApplicationHidden() override
256 if ( isShown && IsUp() )
263 void ApplicationShown() override
265 if ( !isShown && IsUp() )
272 void Initialize() override
274 auto req = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
275 auto p = req.property< bool >( "ScreenReaderEnabled" ).get();
278 screenReaderEnabled = std::get< 0 >( p );
280 p = req.property< bool >( "IsEnabled" ).get();
283 isEnabled = std::get< 0 >( p );
285 if( screenReaderEnabled || isEnabled )
291 bool GetScreenReaderEnabled()
293 return screenReaderEnabled;
303 Bridge* Bridge::GetCurrentBridge()
305 static BridgeImpl *bridge = new BridgeImpl;