1 #ifndef DALI_ADAPTOR_ACCESSIBILITY_BRIDGE_H
2 #define DALI_ADAPTOR_ACCESSIBILITY_BRIDGE_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/actors/actor.h>
23 #include <dali/public-api/math/rect.h>
28 #include <unordered_set>
31 #include <dali/devel-api/adaptor-framework/accessibility.h>
32 #include <dali/public-api/adaptor-framework/window.h>
36 namespace Accessibility
41 * @brief Base class for different accessibility bridges.
43 * Bridge is resposible for initializing and managing connection on accessibility bus.
44 * Accessibility clients will not get any information about UI without initialized and upraised bridge.
45 * Concrete implementation depends on the accessibility technology available on the platform.
47 * @note This class is singleton.
49 struct DALI_ADAPTOR_API Bridge
51 enum class ForceUpResult
61 virtual ~Bridge() = default;
64 * @brief Gets bus name which bridge is initialized on.
66 * @return The bus name
68 virtual const std::string& GetBusName() const = 0;
71 * @brief Registers top level window.
73 * Hierarchy of objects visible for accessibility clients is based on tree-like
74 * structure created from Actors objects. This method allows to connect chosen
75 * object as direct ancestor of application and therefore make it visible for
76 * accessibility clients.
78 * @param[in] object The accessible object
80 virtual void AddTopLevelWindow(Accessible* object) = 0;
83 * @brief Removes top level window.
85 * Hierarchy of objects visible for accessibility clients is based on tree-like
86 * structure created from Actors objects. This method removes previously added
87 * window from visible accessibility objects.
89 * @param[in] object The accessible object
91 virtual void RemoveTopLevelWindow(Accessible* object) = 0;
94 * @brief Adds object on the top of the stack of "default label" sourcing objects.
96 * @see GetDefaultLabel
98 * @param[in] object The accessible object
100 virtual void RegisterDefaultLabel(Accessible* object) = 0;
103 * @brief Removes object from the stack of "default label" sourcing objects.
105 * @see GetDefaultLabel
107 * @param[in] object The accessible object
109 virtual void UnregisterDefaultLabel(Accessible* object) = 0;
112 * @brief Gets the top-most object from the stack of "default label" sourcing objects.
114 * The "default label" is a reading material (text) derived from an accesibility object
115 * that could be read by screen-reader immediately after the navigation context has changed
116 * (window activates, popup shows up, tab changes) and before first UI element is highlighted.
118 * @return The handler to accessibility object
119 * @note This is a Tizen only feature not present in upstream ATSPI.
120 * Feature can be enabled/disabled for particular context root object
121 * by setting value of its accessibility attribute "default_label".
122 * Following strings are valid values for "default_label" attribute: "enabled", "disabled".
123 * Any other value will be interpreted as "enabled".
125 virtual Accessible* GetDefaultLabel() const = 0;
128 * @brief Sets name of current application which will be visible on accessibility bus.
130 * @param[in] name The application name
132 virtual void SetApplicationName(std::string name) = 0;
135 * @brief Sets the name of the GUI toolkit that AT-SPI clients can query.
137 * The default name is "dali".
139 * @param toolkitName The toolkit name
141 virtual void SetToolkitName(std::string_view toolkitName) = 0;
144 * @brief Gets object being root of accessibility tree.
146 * @return handler to accessibility object
148 virtual Accessible* GetApplication() const = 0;
151 * @brief Finds an object in accessibility tree.
153 * @param[in] path The path to object
155 * @return The handler to accessibility object
157 virtual Accessible* FindByPath(const std::string& path) const = 0;
160 * @brief Notifies accessibility dbus that window has just been shown.
162 * @param[in] window The window to be shown
164 virtual void WindowShown(Window window) = 0;
167 * @brief Notifies accessibility dbus that window has just been hidden.
169 * @param[in] window The window to be hidden
171 virtual void WindowHidden(Window window) = 0;
174 * @brief Notifies accessibility dbus that window has just been focused.
176 * @param[in] window The window to be focused
178 virtual void WindowFocused(Window window) = 0;
181 * @brief Notifies accessibility dbus that window has just been out of focus.
183 * @param[in] window The window to be out of focus
185 virtual void WindowUnfocused(Window window) = 0;
188 * @brief Initializes accessibility bus.
190 virtual void Initialize() = 0;
193 * @brief Terminates accessibility bus.
195 virtual void Terminate() = 0;
198 * @brief This method is called, when bridge is being activated.
200 virtual ForceUpResult ForceUp()
204 return ForceUpResult::ALREADY_UP;
206 mData = std::make_shared<Data>();
207 mData->mBridge = this;
208 return ForceUpResult::JUST_STARTED;
212 * @brief This method is called, when bridge is being deactivated.
214 virtual void ForceDown() = 0;
217 * @brief Checks if bridge is activated or not.
218 * @return True if brige is activated.
226 * @brief Emits cursor-moved event on at-spi bus.
228 * @param[in] obj The accessible object
229 * @param[in] cursorPosition The new cursor position
231 virtual void EmitCursorMoved(Accessible* obj, unsigned int cursorPosition) = 0;
234 * @brief Emits active-descendant-changed event on at-spi bus.
236 * @param[in] obj The accessible object
237 * @param[in] child The child of the object
239 virtual void EmitActiveDescendantChanged(Accessible* obj, Accessible* child) = 0;
242 * @brief Emits text-changed event on at-spi bus.
244 * @param[in] obj The accessible object
245 * @param[in] state The changed state for text, such as Inserted or Deleted
246 * @param[in] position The cursor position
247 * @param[in] length The text length
248 * @param[in] content The changed text
250 virtual void EmitTextChanged(Accessible* obj, TextChangedState state, unsigned int position, unsigned int length, const std::string& content) = 0;
253 * @brief Emits MoveOuted event on at-spi bus.
255 * @param[in] obj Accessible object
256 * @param[in] type Direction type when an Accessible object moves out of screen
258 virtual void EmitMovedOutOfScreen(Accessible* obj, ScreenRelativeMoveType type) = 0;
261 * @brief Emits "org.a11y.atspi.Socket.Available" event on AT-SPI bus.
263 * @param obj Accessible object
265 virtual void EmitSocketAvailable(Accessible* obj) = 0;
268 * @brief Emits state-changed event on at-spi bus.
270 * @param[in] obj The accessible object
271 * @param[in] state The accessibility state (SHOWING, HIGHLIGHTED, etc)
272 * @param[in] newValue Whether the state value is changed to new value or not.
273 * @param[in] reserved Reserved. (Currently, this argument is not implemented in dali)
275 virtual void EmitStateChanged(Accessible* obj, State state, int newValue, int reserved = 0) = 0;
278 * @brief Emits window event on at-spi bus.
280 * @param[in] obj The accessible object
281 * @param[in] event The enumerated window event
282 * @param[in] detail The additional parameter which interpretation depends on chosen event
284 virtual void Emit(Accessible* obj, WindowEvent event, unsigned int detail = 0) = 0;
287 * @brief Emits property-changed event on at-spi bus.
289 * @param[in] obj The accessible object
290 * @param[in] event Property changed event
292 virtual void Emit(Accessible* obj, ObjectPropertyChangeEvent event) = 0;
295 * @brief Emits bounds-changed event on at-spi bus.
297 * @param[in] obj The accessible object
298 * @param[in] rect The rectangle for changed bounds
300 virtual void EmitBoundsChanged(Accessible* obj, Rect<> rect) = 0;
303 * @brief Emits key event on at-spi bus.
305 * Screen-reader might receive this event and reply, that given keycode is consumed. In that case
306 * further processing of the keycode should be ignored.
308 * @param[in] type Key event type
309 * @param[in] keyCode Key code
310 * @param[in] keyName Key name
311 * @param[in] timeStamp Time stamp
312 * @param[in] isText Whether it's text or not
313 * @return Whether this event is consumed or not
315 virtual Consumed Emit(KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) = 0;
318 * @brief Reads given text by screen reader
320 * @param[in] text The text to read
321 * @param[in] discardable If TRUE, reading can be discarded by subsequent reading requests,
322 * if FALSE the reading must finish before next reading request can be started
323 * @param[in] callback the callback function that is called on reading signals emitted
324 * during processing of this reading request.
325 * Callback can be one of the following signals:
326 * ReadingCancelled, ReadingStopped, ReadingSkipped
328 virtual void Say(const std::string& text, bool discardable, std::function<void(std::string)> callback) = 0;
331 * @brief Force accessibility client to pause.
333 virtual void Pause() = 0;
336 * @brief Force accessibility client to resume.
338 virtual void Resume() = 0;
341 * @brief Cancels anything screen-reader is reading / has queued to read
343 * @param[in] alsoNonDiscardable whether to cancel non-discardable readings as well
345 virtual void StopReading(bool alsoNonDiscardable) = 0;
348 * @brief Suppresses reading of screen-reader
350 * @param[in] suppress whether to suppress reading of screen-reader
352 virtual void SuppressScreenReader(bool suppress) = 0;
355 * @brief Gets screen reader status.
357 * @return True if screen reader is enabled
359 virtual bool GetScreenReaderEnabled() = 0;
362 * @brief Gets ATSPI status.
364 * @return True if ATSPI is enabled
366 virtual bool IsEnabled() = 0;
369 * @brief Returns instance of bridge singleton object.
371 * @return The current bridge object
373 static std::shared_ptr<Bridge> GetCurrentBridge();
376 * @brief Blocks auto-initialization of AT-SPI bridge
378 * Use this only if your application starts before DBus does, and call it early in main()
379 * (before GetCurrentBridge() is called by anyone). GetCurrentBridge() will then return an
380 * instance of DummyBridge.
382 * When DBus is ready, call EnableAutoInit(). Please note that GetCurrentBridge() may still
383 * return an instance of DummyBridge if AT-SPI was disabled at compile time or using an
384 * environment variable, or if creating the real bridge failed.
386 * @see Dali::Accessibility::DummyBridge
387 * @see Dali::Accessibility::Bridge::EnableAutoInit
389 static void DisableAutoInit();
392 * @brief Re-enables auto-initialization of AT-SPI bridge
394 * Normal applications do not have to call this function. GetCurrentBridge() tries to
395 * initialize the AT-SPI bridge when it is called for the first time.
397 * @see Dali::Accessibility::Bridge::DisableAutoInit
398 * @see Dali::Accessibility::Bridge::AddTopLevelWindow
399 * @see Dali::Accessibility::Bridge::SetApplicationName
401 static void EnableAutoInit();
403 static Signal<void()>& EnabledSignal()
405 return mEnabledSignal;
408 static Signal<void()>& DisabledSignal()
410 return mDisabledSignal;
413 static Signal<void()>& ScreenReaderEnabledSignal()
415 return mScreenReaderEnabledSignal;
418 static Signal<void()>& ScreenReaderDisabledSignal()
420 return mScreenReaderDisabledSignal;
426 std::unordered_set<const Accessible*> mKnownObjects;
427 std::string mBusName;
428 Bridge* mBridge = nullptr;
429 Actor mHighlightActor;
430 Actor mCurrentlyHighlightedActor;
432 std::shared_ptr<Data> mData;
433 friend class Accessible;
435 enum class AutoInitState
441 inline static AutoInitState mAutoInitState = AutoInitState::ENABLED;
443 inline static Signal<void()> mEnabledSignal;
444 inline static Signal<void()> mDisabledSignal;
445 inline static Signal<void()> mScreenReaderEnabledSignal;
446 inline static Signal<void()> mScreenReaderDisabledSignal;
449 * @brief Registers accessible object to be known in bridge object.
451 * Bridge must known about all currently alive accessible objects, as some requst
452 * might come and object will be identified by number id (it's memory address).
453 * To avoid memory corruption number id is checked against set of known objects.
455 * @param[in] object The accessible object
457 void RegisterOnBridge(const Accessible* object);
460 * @brief Tells bridge, that given object is considered root (doesn't have any parents).
462 * All root objects will have the same parent - application object. Application object
463 * is controlled by bridge and private.
465 * @param[in] owner The accessible object
467 void SetIsOnRootLevel(Accessible* owner);
471 * @brief Checks if ATSPI is activated or not.
472 * @return True if ATSPI is activated.
476 if(Bridge::GetCurrentBridge() == nullptr)
481 if(Bridge::GetCurrentBridge()->IsEnabled() == false)
486 return Bridge::GetCurrentBridge()->IsUp();
489 } // namespace Accessibility
492 #endif // DALI_ADAPTOR_ACCESSIBILITY_BRIDGE_H