Merge "[Tizen][AT-SPI] Rework intercepting key events" into tizen
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / accessibility-bridge.h
index ba26501..6d30da6 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_ADAPTOR_ACCESSIBILITY_BRIDGE_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
+#include <dali/public-api/events/key-event.h>
 #include <dali/public-api/math/rect.h>
 #include <functional>
 #include <memory>
@@ -36,6 +37,7 @@ namespace Dali
 namespace Accessibility
 {
 class Accessible;
+class ProxyAccessible;
 
 /**
  * @brief Base class for different accessibility bridges.
@@ -115,6 +117,8 @@ struct DALI_ADAPTOR_API Bridge
    * that could be read by screen-reader immediately after the navigation context has changed
    * (window activates, popup shows up, tab changes) and before first UI element is highlighted.
    *
+   * @param[in] root The root of the navigation context for which to retrieve the default label.
+   *
    * @return The handler to accessibility object
    * @note This is a Tizen only feature not present in upstream ATSPI.
    * Feature can be enabled/disabled for particular context root object
@@ -122,7 +126,7 @@ struct DALI_ADAPTOR_API Bridge
    * Following strings are valid values for "default_label" attribute: "enabled", "disabled".
    * Any other value will be interpreted as "enabled".
    */
-  virtual Accessible* GetDefaultLabel() const = 0;
+  virtual Accessible* GetDefaultLabel(Accessible* root) const = 0;
 
   /**
    * @brief Sets name of current application which will be visible on accessibility bus.
@@ -132,6 +136,15 @@ struct DALI_ADAPTOR_API Bridge
   virtual void SetApplicationName(std::string name) = 0;
 
   /**
+   * @brief Sets the name of the GUI toolkit that AT-SPI clients can query.
+   *
+   * The default name is "dali".
+   *
+   * @param toolkitName The toolkit name
+   */
+  virtual void SetToolkitName(std::string_view toolkitName) = 0;
+
+  /**
    * @brief Gets object being root of accessibility tree.
    *
    * @return handler to accessibility object
@@ -148,6 +161,13 @@ struct DALI_ADAPTOR_API Bridge
   virtual Accessible* FindByPath(const std::string& path) const = 0;
 
   /**
+   * @brief Notifies accessibility dbus that window has just been created.
+   *
+   * @param[in] window The window to be created
+   */
+  virtual void WindowCreated(Window window) = 0;
+
+  /**
    * @brief Notifies accessibility dbus that window has just been shown.
    *
    * @param[in] window The window to be shown
@@ -176,6 +196,28 @@ struct DALI_ADAPTOR_API Bridge
   virtual void WindowUnfocused(Window window) = 0;
 
   /**
+   * @brief Notifies accessibility dbus that window has just been minimized.
+   *
+   * @param[in] window The window to be minimized
+   */
+  virtual void WindowMinimized(Window window) = 0;
+
+  /**
+   * @brief Notifies accessibility dbus that window has just been restored.
+   *
+   * @param[in] window The window to be restored
+   * @param[in] detail Restored window state
+   */
+  virtual void WindowRestored(Window window, WindowRestoreType detail) = 0;
+
+  /**
+   * @brief Notifies accessibility dbus that window has just been maximized.
+   *
+   * @param[in] window The window to be maximized
+   */
+  virtual void WindowMaximized(Window window) = 0;
+
+  /**
    * @brief Initializes accessibility bus.
    */
   virtual void Initialize() = 0;
@@ -249,6 +291,27 @@ struct DALI_ADAPTOR_API Bridge
   virtual void EmitMovedOutOfScreen(Accessible* obj, ScreenRelativeMoveType type) = 0;
 
   /**
+   * @brief Emits "org.a11y.atspi.Socket.Available" event on AT-SPI bus.
+   *
+   * @param obj Accessible object
+   */
+  virtual void EmitSocketAvailable(Accessible* obj) = 0;
+
+  /**
+   * @brief Emits ScrollStarted event on at-spi bus.
+   *
+   * @param obj Accessible Object
+   */
+  virtual void EmitScrollStarted(Accessible *obj) = 0;
+
+    /**
+   * @brief Emits ScrollFinished event on at-spi bus.
+   *
+   * @param obj Accessible Object
+   */
+  virtual void EmitScrollFinished(Accessible *obj) = 0;
+
+  /**
    * @brief Emits state-changed event on at-spi bus.
    *
    * @param[in] obj The accessible object
@@ -284,19 +347,29 @@ struct DALI_ADAPTOR_API Bridge
   virtual void EmitBoundsChanged(Accessible* obj, Rect<> rect) = 0;
 
   /**
+   * @brief Emits org.a11y.atspi.Event.Window.PostRender on the AT-SPI bus.
+   *
+   * @param[in] obj The Accessible sender object
+   *
+   * The sender of this event is expected to be an Accessible object that
+   * represents a top-level window.
+   *
+   * The actual number of events emitted during a given time interval may be smaller
+   * than the number of calls to this method, but at least one is guaranteed.
+   */
+  virtual void EmitPostRender(Accessible *obj) = 0;
+
+  /**
    * @brief Emits key event on at-spi bus.
    *
    * Screen-reader might receive this event and reply, that given keycode is consumed. In that case
    * further processing of the keycode should be ignored.
    *
-   * @param[in] type Key event type
-   * @param[in] keyCode Key code
-   * @param[in] keyName Key name
-   * @param[in] timeStamp Time stamp
-   * @param[in] isText Whether it's text or not
-   * @return Whether this event is consumed or not
-   **/
-  virtual Consumed Emit(KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) = 0;
+   * @param[in] keyEvent The key event
+   * @param[in] callback Notification if the event was consumed
+   * @return true if the event was emitted
+   */
+  virtual bool EmitKeyEvent(Dali::KeyEvent keyEvent, std::function<void(Dali::KeyEvent, bool)> callback) = 0;
 
   /**
    * @brief Reads given text by screen reader
@@ -350,6 +423,83 @@ struct DALI_ADAPTOR_API Bridge
   virtual bool IsEnabled() = 0;
 
   /**
+   * @brief Calls socket.Embed(plug) via D-Bus.
+   *
+   * @param[in] plug The plug
+   * @param[in] socket The socket
+   *
+   * @return Address returned by the D-Bus call.
+   *
+   * @note Remote object pointed to by 'socket' must implement 'org.a11y.atspi.Socket'.
+   * @see UnembedSocket()
+   */
+  virtual Address EmbedSocket(const Address& plug, const Address& socket) = 0;
+
+  /**
+   * @brief Calls socket.Embedded(plug) via D-Bus.
+   *
+   * The "Embedded" D-Bus method is an ATK extension.
+   * See 'impl_Embedded' in AT_SPI2_ATK/atk-adaptor/adaptors/socket-adaptor.c for more information.
+   *
+   * @param[in] plug The plug
+   * @param[in] socket The socket
+   */
+  virtual void EmbedAtkSocket(const Address& plug, const Address& socket) = 0;
+
+  /**
+   * @brief Calls socket.Unmbed(plug) via D-Bus.
+   *
+   * @param[in] plug The plug
+   * @param[in] socket The socket
+   *
+   * @note Remote object pointed to by 'socket' must implement 'org.a11y.atspi.Socket'.
+   * @see EmbedSocket()
+   */
+  virtual void UnembedSocket(const Address& plug, const Address& socket) = 0;
+
+  /**
+   * @brief Calls socket.SetOffset(x, y) via D-Bus.
+   *
+   * The "SetOffset" D-Bus method is a DALi extension. It can be used to inform a DALi widget about
+   * its position on the screen.
+   *
+   * @param[in] socket The socket
+   * @param[in] x Horizontal offset
+   * @param[in] y Vertical offset
+   *
+   * @note Remote object pointed to by 'socket' must implement 'org.a11y.atspi.Socket'.
+   * @see EmbedSocket()
+   * @see SetExtentsOffset()
+   */
+  virtual void SetSocketOffset(ProxyAccessible* socket, std::int32_t x, std::int32_t y) = 0;
+
+  /**
+   * @brief Sets the global extents offset.
+   *
+   * This offset will be added during serialization of GetExtents() return value to D-Bus.
+   * Local calls to GetExtents() are unaffected.
+   *
+   * @param[in] x Horizontal offset
+   * @param[in] y Vertical offset
+   *
+   * @see SetSocketOffset()
+   * @see Dali::Accessibility::Component::GetExtents()
+   */
+  virtual void SetExtentsOffset(std::int32_t x, std::int32_t y) = 0;
+
+  /**
+   * @brief Sets the preferred bus name.
+   *
+   * If the Bridge is enabled, it will immediately release the previous name and request the new one.
+   *
+   * Otherwise, the Bridge will request this name on AT-SPI activation (and release it on deactivation).
+   * It is up to the caller to determine whether a given name will be available in the system.
+   *
+   * @param preferredBusName The preferred bus name
+   */
+  virtual void SetPreferredBusName(std::string_view preferredBusName) = 0;
+
+  /**
    * @brief Returns instance of bridge singleton object.
    *
    * @return The current bridge object
@@ -384,6 +534,16 @@ struct DALI_ADAPTOR_API Bridge
    */
   static void EnableAutoInit();
 
+  /**
+   * @brief Encodes a widget ID as a usable bus name.
+   *
+   * @param widgetInstanceId The instance ID of a widget
+   * @return std::string Encoded bus name
+   *
+   * @see SetPreferredBusName
+   */
+  static std::string MakeBusNameForWidget(std::string_view widgetInstanceId);
+
   static Signal<void()>& EnabledSignal()
   {
     return mEnabledSignal;
@@ -394,6 +554,16 @@ struct DALI_ADAPTOR_API Bridge
     return mDisabledSignal;
   }
 
+  static Signal<void()>& ScreenReaderEnabledSignal()
+  {
+    return mScreenReaderEnabledSignal;
+  }
+
+  static Signal<void()>& ScreenReaderDisabledSignal()
+  {
+    return mScreenReaderDisabledSignal;
+  }
+
 protected:
   struct Data
   {
@@ -402,6 +572,7 @@ protected:
     Bridge*                               mBridge = nullptr;
     Actor                                 mHighlightActor;
     Actor                                 mCurrentlyHighlightedActor;
+    std::pair<std::int32_t, std::int32_t> mExtentsOffset{0, 0};
   };
   std::shared_ptr<Data> mData;
   friend class Accessible;
@@ -416,6 +587,8 @@ protected:
 
   inline static Signal<void()> mEnabledSignal;
   inline static Signal<void()> mDisabledSignal;
+  inline static Signal<void()> mScreenReaderEnabledSignal;
+  inline static Signal<void()> mScreenReaderDisabledSignal;
 
   /**
    * @brief Registers accessible object to be known in bridge object.