[AT-SPI] Prevent flooding D-Bus with PostRender events 27/290027/1
authorArtur Świgoń <a.swigon@samsung.com>
Fri, 17 Mar 2023 09:15:30 +0000 (10:15 +0100)
committerArtur Świgoń <a.swigon@samsung.com>
Fri, 17 Mar 2023 09:16:35 +0000 (10:16 +0100)
When enabled with SetListenPostRender, the window Accessible emits countless
PostRender events on D-Bus. The CoalescableMessages mechanism can be used here
just like for BoundsChanged and SetOffset. This way, with this patch, the
PostRender events come at a steady rate. With CoalescableMessages at least one
event will still be emitted if requested, which is important for clients who
may depend on there being a PostRender event on the AT-SPI bus after a
particular operation -- there still is, but without the flooding.

Change-Id: Iab9451d3bff7bf57007388ed641ba543d40b52c1

dali/devel-api/adaptor-framework/accessibility-bridge.h
dali/devel-api/adaptor-framework/accessibility.cpp
dali/internal/accessibility/bridge/bridge-base.h
dali/internal/accessibility/bridge/bridge-object.cpp
dali/internal/accessibility/bridge/bridge-object.h
dali/internal/accessibility/bridge/dummy/dummy-atspi.h

index 0737c69..22dbb5e 100644 (file)
@@ -339,6 +339,19 @@ 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
index b780b3f..4c83f43 100644 (file)
@@ -507,9 +507,8 @@ public:
 
   void OnPostRender()
   {
-    Accessibility::Bridge::GetCurrentBridge()->Emit(Accessibility::Accessible::Get(Self()), Accessibility::WindowEvent::POST_RENDER);
+    Accessibility::Bridge::GetCurrentBridge()->EmitPostRender(this);
   }
-
 }; // AdaptorAccessible
 
 using AdaptorAccessiblesType = std::unordered_map<const Dali::RefObject*, std::unique_ptr<AdaptorAccessible> >;
index 094d2c5..4b5d815 100644 (file)
@@ -281,6 +281,7 @@ enum class CoalescableMessages
 {
   BOUNDS_CHANGED, ///< Bounds changed
   SET_OFFSET, ///< Set offset
+  POST_RENDER, ///< Post render
 };
 
 // Custom specialization of std::hash
index bacbd6e..ee57751 100644 (file)
@@ -238,6 +238,13 @@ void BridgeObject::EmitBoundsChanged(Accessible* obj, Dali::Rect<> rect)
   });
 }
 
+void BridgeObject::EmitPostRender(Accessible *obj)
+{
+  AddCoalescableMessage(CoalescableMessages::POST_RENDER, obj, 0.5f, [=]() {
+    Emit(obj, WindowEvent::POST_RENDER);
+  });
+}
+
 void BridgeObject::EmitCursorMoved(Accessible* obj, unsigned int cursorPosition)
 {
   if(!IsUp() || obj->IsHidden() || obj->GetSuppressedEvents()[AtspiEvent::TEXT_CARET_MOVED])
@@ -343,4 +350,4 @@ void BridgeObject::EmitScrollFinished(Accessible* obj)
     Accessible::GetInterfaceName(AtspiInterface::EVENT_OBJECT),
     "ScrollFinished",
     {"", "root"});
-}
\ No newline at end of file
+}
index 1b6637d..8ca6924 100644 (file)
@@ -81,6 +81,11 @@ protected:
   void EmitBoundsChanged(Dali::Accessibility::Accessible* obj, Dali::Rect<> rect) override;
 
   /**
+   * @copydoc Dali::Accessibility::Bridge::EmitPostRender()
+   */
+  void EmitPostRender(Dali::Accessibility::Accessible* obj) override;
+
+  /**
    * @copydoc Dali::Accessibility::Bridge::EmitMovedOutOfScreen()
    */
   void EmitMovedOutOfScreen(Dali::Accessibility::Accessible* obj, Dali::Accessibility::ScreenRelativeMoveType type) override;
index 0bbaccd..447ba4d 100644 (file)
@@ -166,6 +166,10 @@ struct DummyBridge : Dali::Accessibility::Bridge
   {
   }
 
+  void EmitPostRender(Accessibility::Accessible *obj) override
+  {
+  }
+
   Accessibility::Consumed Emit(Accessibility::KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) override
   {
     return Accessibility::Consumed::YES;