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 Gets object being root of accessibility tree.
137 * @return handler to accessibility object
139 virtual Accessible* GetApplication() const = 0;
142 * @brief Finds an object in accessibility tree.
144 * @param[in] path The path to object
146 * @return The handler to accessibility object
148 virtual Accessible* FindByPath(const std::string& path) const = 0;
151 * @brief Notifies accessibility dbus that window has just been shown.
153 * @param[in] window The window to be shown
155 virtual void WindowShown(Window window) = 0;
158 * @brief Notifies accessibility dbus that window has just been hidden.
160 * @param[in] window The window to be hidden
162 virtual void WindowHidden(Window window) = 0;
165 * @brief Notifies accessibility dbus that window has just been focused.
167 * @param[in] window The window to be focused
169 virtual void WindowFocused(Window window) = 0;
172 * @brief Notifies accessibility dbus that window has just been out of focus.
174 * @param[in] window The window to be out of focus
176 virtual void WindowUnfocused(Window window) = 0;
179 * @brief Initializes accessibility bus.
181 virtual void Initialize() = 0;
184 * @brief Terminates accessibility bus.
186 virtual void Terminate() = 0;
189 * @brief This method is called, when bridge is being activated.
191 virtual ForceUpResult ForceUp()
195 return ForceUpResult::ALREADY_UP;
197 mData = std::make_shared<Data>();
198 mData->mBridge = this;
199 return ForceUpResult::JUST_STARTED;
203 * @brief This method is called, when bridge is being deactivated.
205 virtual void ForceDown() = 0;
208 * @brief Checks if bridge is activated or not.
209 * @return True if brige is activated.
217 * @brief Emits cursor-moved event on at-spi bus.
219 * @param[in] obj The accessible object
220 * @param[in] cursorPosition The new cursor position
222 virtual void EmitCursorMoved(Accessible* obj, unsigned int cursorPosition) = 0;
225 * @brief Emits active-descendant-changed event on at-spi bus.
227 * @param[in] obj The accessible object
228 * @param[in] child The child of the object
230 virtual void EmitActiveDescendantChanged(Accessible* obj, Accessible* child) = 0;
233 * @brief Emits text-changed event on at-spi bus.
235 * @param[in] obj The accessible object
236 * @param[in] state The changed state for text, such as Inserted or Deleted
237 * @param[in] position The cursor position
238 * @param[in] length The text length
239 * @param[in] content The changed text
241 virtual void EmitTextChanged(Accessible* obj, TextChangedState state, unsigned int position, unsigned int length, const std::string& content) = 0;
244 * @brief Emits MoveOuted event on at-spi bus.
246 * @param[in] obj Accessible object
247 * @param[in] type Direction type when an Accessible object moves out of screen
249 virtual void EmitMovedOutOfScreen(Accessible* obj, ScreenRelativeMoveType type) = 0;
252 * @brief Emits "org.a11y.atspi.Socket.Available" event on AT-SPI bus.
254 * @param obj Accessible object
256 virtual void EmitSocketAvailable(Accessible* obj) = 0;
259 * @brief Emits state-changed event on at-spi bus.
261 * @param[in] obj The accessible object
262 * @param[in] state The accessibility state (SHOWING, HIGHLIGHTED, etc)
263 * @param[in] newValue Whether the state value is changed to new value or not.
264 * @param[in] reserved Reserved. (Currently, this argument is not implemented in dali)
266 virtual void EmitStateChanged(Accessible* obj, State state, int newValue, int reserved = 0) = 0;
269 * @brief Emits window event on at-spi bus.
271 * @param[in] obj The accessible object
272 * @param[in] event The enumerated window event
273 * @param[in] detail The additional parameter which interpretation depends on chosen event
275 virtual void Emit(Accessible* obj, WindowEvent event, unsigned int detail = 0) = 0;
278 * @brief Emits property-changed event on at-spi bus.
280 * @param[in] obj The accessible object
281 * @param[in] event Property changed event
283 virtual void Emit(Accessible* obj, ObjectPropertyChangeEvent event) = 0;
286 * @brief Emits bounds-changed event on at-spi bus.
288 * @param[in] obj The accessible object
289 * @param[in] rect The rectangle for changed bounds
291 virtual void EmitBoundsChanged(Accessible* obj, Rect<> rect) = 0;
294 * @brief Emits key event on at-spi bus.
296 * Screen-reader might receive this event and reply, that given keycode is consumed. In that case
297 * further processing of the keycode should be ignored.
299 * @param[in] type Key event type
300 * @param[in] keyCode Key code
301 * @param[in] keyName Key name
302 * @param[in] timeStamp Time stamp
303 * @param[in] isText Whether it's text or not
304 * @return Whether this event is consumed or not
306 virtual Consumed Emit(KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) = 0;
309 * @brief Reads given text by screen reader
311 * @param[in] text The text to read
312 * @param[in] discardable If TRUE, reading can be discarded by subsequent reading requests,
313 * if FALSE the reading must finish before next reading request can be started
314 * @param[in] callback the callback function that is called on reading signals emitted
315 * during processing of this reading request.
316 * Callback can be one of the following signals:
317 * ReadingCancelled, ReadingStopped, ReadingSkipped
319 virtual void Say(const std::string& text, bool discardable, std::function<void(std::string)> callback) = 0;
322 * @brief Force accessibility client to pause.
324 virtual void Pause() = 0;
327 * @brief Force accessibility client to resume.
329 virtual void Resume() = 0;
332 * @brief Cancels anything screen-reader is reading / has queued to read
334 * @param[in] alsoNonDiscardable whether to cancel non-discardable readings as well
336 virtual void StopReading(bool alsoNonDiscardable) = 0;
339 * @brief Suppresses reading of screen-reader
341 * @param[in] suppress whether to suppress reading of screen-reader
343 virtual void SuppressScreenReader(bool suppress) = 0;
346 * @brief Gets screen reader status.
348 * @return True if screen reader is enabled
350 virtual bool GetScreenReaderEnabled() = 0;
353 * @brief Gets ATSPI status.
355 * @return True if ATSPI is enabled
357 virtual bool IsEnabled() = 0;
360 * @brief Returns instance of bridge singleton object.
362 * @return The current bridge object
364 static std::shared_ptr<Bridge> GetCurrentBridge();
367 * @brief Blocks auto-initialization of AT-SPI bridge
369 * Use this only if your application starts before DBus does, and call it early in main()
370 * (before GetCurrentBridge() is called by anyone). GetCurrentBridge() will then return an
371 * instance of DummyBridge.
373 * When DBus is ready, call EnableAutoInit(). Please note that GetCurrentBridge() may still
374 * return an instance of DummyBridge if AT-SPI was disabled at compile time or using an
375 * environment variable, or if creating the real bridge failed.
377 * @see Dali::Accessibility::DummyBridge
378 * @see Dali::Accessibility::Bridge::EnableAutoInit
380 static void DisableAutoInit();
383 * @brief Re-enables auto-initialization of AT-SPI bridge
385 * Normal applications do not have to call this function. GetCurrentBridge() tries to
386 * initialize the AT-SPI bridge when it is called for the first time.
388 * @see Dali::Accessibility::Bridge::DisableAutoInit
389 * @see Dali::Accessibility::Bridge::AddTopLevelWindow
390 * @see Dali::Accessibility::Bridge::SetApplicationName
392 static void EnableAutoInit();
394 static Signal<void()>& EnabledSignal()
396 return mEnabledSignal;
399 static Signal<void()>& DisabledSignal()
401 return mDisabledSignal;
404 static Signal<void()>& ScreenReaderEnabledSignal()
406 return mScreenReaderEnabledSignal;
409 static Signal<void()>& ScreenReaderDisabledSignal()
411 return mScreenReaderDisabledSignal;
417 std::unordered_set<const Accessible*> mKnownObjects;
418 std::string mBusName;
419 Bridge* mBridge = nullptr;
420 Actor mHighlightActor;
421 Actor mCurrentlyHighlightedActor;
423 std::shared_ptr<Data> mData;
424 friend class Accessible;
426 enum class AutoInitState
432 inline static AutoInitState mAutoInitState = AutoInitState::ENABLED;
434 inline static Signal<void()> mEnabledSignal;
435 inline static Signal<void()> mDisabledSignal;
436 inline static Signal<void()> mScreenReaderEnabledSignal;
437 inline static Signal<void()> mScreenReaderDisabledSignal;
440 * @brief Registers accessible object to be known in bridge object.
442 * Bridge must known about all currently alive accessible objects, as some requst
443 * might come and object will be identified by number id (it's memory address).
444 * To avoid memory corruption number id is checked against set of known objects.
446 * @param[in] object The accessible object
448 void RegisterOnBridge(const Accessible* object);
451 * @brief Tells bridge, that given object is considered root (doesn't have any parents).
453 * All root objects will have the same parent - application object. Application object
454 * is controlled by bridge and private.
456 * @param[in] owner The accessible object
458 void SetIsOnRootLevel(Accessible* owner);
462 * @brief Checks if ATSPI is activated or not.
463 * @return True if ATSPI is activated.
467 if(Bridge::GetCurrentBridge() == nullptr)
472 if(Bridge::GetCurrentBridge()->IsEnabled() == false)
477 return Bridge::GetCurrentBridge()->IsUp();
480 } // namespace Accessibility
483 #endif // DALI_ADAPTOR_ACCESSIBILITY_BRIDGE_H