[ATSPI] Introduce SetListenPostRender interface
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / atspi-interfaces / accessible.h
index 0eb7794..554fb73 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_ADAPTOR_ATSPI_ACCESSIBLE_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -26,8 +26,8 @@
 #include <vector>
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/accessibility.h>
 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
+#include <dali/devel-api/adaptor-framework/accessibility.h>
 
 namespace Dali::Accessibility
 {
@@ -39,32 +39,6 @@ class DALI_ADAPTOR_API Accessible
 public:
   virtual ~Accessible() noexcept;
 
-  using utf8_t = unsigned char;
-
-  /**
-   * @brief Calculates and finds word boundaries in given utf8 text.
-   *
-   * @param[in] string The source text to find
-   * @param[in] length The length of text to find
-   * @param[in] language The language to use
-   * @param[out] breaks The word boundaries in given text
-   *
-   * @note Word boundaries are returned as non-zero values in table breaks, which must be of size at least length.
-   */
-  static void FindWordSeparationsUtf8(const utf8_t* string, std::size_t length, const char* language, char* breaks);
-
-  /**
-   * @brief Calculates and finds line boundaries in given utf8 text.
-   *
-   * @param[in] string The source text to find
-   * @param[in] length The length of text to find
-   * @param[in] language The language to use
-   * @param[out] breaks The line boundaries in given text
-   *
-   * @note Line boundaries are returned as non-zero values in table breaks, which must be of size at least length.
-   */
-  static void FindLineSeparationsUtf8(const utf8_t* string, std::size_t length, const char* language, char* breaks);
-
   /**
    * @brief Helper function for emiting active-descendant-changed event.
    *
@@ -157,6 +131,14 @@ public:
   void EmitMovedOutOfScreen(ScreenRelativeMoveType type);
 
   /**
+   * @brief Emits "org.a11y.atspi.Socket.Available" signal.
+   */
+  // This belongs to Dali::Accessibility::Socket. However, all Emit*() helpers
+  // are here in Accessible, regardless of what interface they belong to (perhaps
+  // to spare a dynamic_cast if used like this: Accessible::Get()->Emit*(...)).
+  void EmitSocketAvailable();
+
+  /**
    * @brief Emits "highlighted" event.
    *
    * @param[in] event The enumerated window event
@@ -327,18 +309,42 @@ public:
   virtual std::vector<Relation> GetRelationSet() = 0;
 
   /**
-   * @brief Gets internal Actor to be saved before.
+   * @brief Gets the Actor associated with this Accessible (if there is one).
    *
    * @return The internal Actor
    */
   virtual Dali::Actor GetInternalActor() = 0;
 
   /**
+   * @brief Sets whether to listen for post render callback.
+   *
+   * @param[in] enabled If ture, registration post render callback, false otherwise
+   */
+  virtual void SetListenPostRender(bool enabled);
+
+  /**
+   * @brief Gets all implemented interfaces.
+   *
+   * Override DoGetInterfaces() to customize the return value of this method.
+   *
+   * @return The collection of implemented interfaces
+   *
+   * @see DoGetInterfaces()
+   */
+  AtspiInterfaces GetInterfaces() const;
+
+  /**
    * @brief Gets all implemented interfaces.
    *
-   * @return The collection of strings with implemented interfaces
+   * Converts all interfaces returned by GetInterfaces() to their DBus names
+   * using GetInterfaceName().
+   *
+   * @return The collection of names of implemented interfaces
+   *
+   * @see GetInterfaces()
+   * @see GetInterfaceName()
    */
-  std::vector<std::string> GetInterfaces() const;
+  std::vector<std::string> GetInterfacesAsStrings() const;
 
   /**
    * @brief Checks if object is on root level.
@@ -350,6 +356,26 @@ public:
     return mIsOnRootLevel;
   }
 
+  /**
+   * @brief Gets all suppressed events.
+   *
+   * @return All suppressed events
+   */
+  AtspiEvents GetSuppressedEvents() const
+  {
+    return mSuppressedEvents;
+  }
+
+  /**
+   * @brief Gets all suppressed events.
+   *
+   * @return All suppressed events
+   */
+  AtspiEvents& GetSuppressedEvents()
+  {
+    return mSuppressedEvents;
+  }
+
 protected:
   Accessible();
   Accessible(const Accessible&)         = delete;
@@ -358,6 +384,20 @@ protected:
   Accessible&                   operator=(Accessible&&) = delete;
   std::shared_ptr<Bridge::Data> GetBridgeData() const;
 
+  /**
+   * @brief Returns the collection of AT-SPI interfaces implemented by this Accessible.
+   *
+   * This method is called only once and its return value is cached. The default implementation
+   * uses dynamic_cast to determine which interfaces are implemented. Override this if you
+   * conceptually provide fewer interfaces than dynamic_cast can see.
+   *
+   * @return The collection of implemented interfaces
+   *
+   * @see GetInterfaces()
+   * @see GetInterfaceName()
+   */
+  virtual AtspiInterfaces DoGetInterfaces() const;
+
 public:
   /**
    * @brief Gets the highlight actor.
@@ -406,20 +446,58 @@ public:
    * @brief Acquires Accessible object from Actor object.
    *
    * @param[in] actor Actor object
-   * @param[in] isRoot True, if it's top level object (window)
    *
    * @return The handle to Accessible object
    */
-  static Accessible* Get(Dali::Actor actor, bool isRoot = false);
+  static Accessible* Get(Dali::Actor actor);
+
+  /**
+   * @brief Obtains the DBus interface name for the specified AT-SPI interface.
+   *
+   * @param interface AT-SPI interface identifier (e.g. AtspiInterface::ACCESSIBLE)
+   * @return AT-SPI interface name (e.g. "org.a11y.atspi.Accessible")
+   */
+  static std::string GetInterfaceName(AtspiInterface interface);
+
+  /**
+   * @brief Downcasts an Accessible pointer to an AT-SPI interface pointer.
+   *
+   * @tparam I Desired AT-SPI interface
+   *
+   * @param obj Object to cast.
+   *
+   * @return Pointer to an AT-SPI interface or null if the interface is not implemented.
+   */
+  template<AtspiInterface I>
+  static AtspiInterfaceType<I>* DownCast(Accessible* obj)
+  {
+    if(!obj || !obj->GetInterfaces()[I])
+    {
+      return nullptr;
+    }
+
+    return dynamic_cast<AtspiInterfaceType<I>*>(obj);
+  }
 
 private:
   friend class Bridge;
 
   mutable std::weak_ptr<Bridge::Data> mBridgeData;
+  mutable AtspiInterfaces             mInterfaces;
+  AtspiEvents                         mSuppressedEvents;
   bool                                mIsOnRootLevel = false;
 
 }; // Accessible class
 
+namespace Internal
+{
+template<>
+struct AtspiInterfaceTypeHelper<AtspiInterface::ACCESSIBLE>
+{
+  using Type = Accessible;
+};
+} // namespace Internal
+
 } // namespace Dali::Accessibility
 
 #endif // DALI_ADAPTOR_ATSPI_ACCESSIBLE_H