sw/source/core/access/acctable.cxx |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

New commits:
commit 308c9bd730ab3296b437a6999f60dd8e03de02e0
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Sep 12 13:10:43 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Sep 12 14:38:42 2024 +0200

    sw a11y: Send table selection-changed event for correct object
    
    Send `AccessibleEventId::SELECTION_CHANGED_ADD`/
    `AccessibleEventId::SELECTION_CHANGED_REMOVE` when
    a cell in a Writer gets (un)selected on the table's a11y
    object and set the cell as the `NewValue`, as documented
    in the documentation for these events
    (see offapi/com/sun/star/accessibility/AccessibleEventId.idl).
    
    For the cell, an `AccessibleEventId::STATE_CHANGED`
    event for the `AccessibleStateType::SELECTED` needs
    to be sent instead, which already happens in
    `SwAccessibleCell::InvalidateMyCursorPos` (where the
    cell is also added to the vector of elements used
    here to send the `SELECTION_CHANGED_*` events).
    
    This now gives the expected result when using
    the following pyatspi script and selecting
    the first 2 cells in a Writer table with
    the gtk3 VCL plugin:
    
        pyatspi script:
        #!/usr/bin/python3
        import pyatspi
        def listener(e):
            try:
                if not e.host_application.name.startswith('soffice'):
                    return
            except:
                return
            print(e)
        pyatspi.Registry.registerEventListener(listener, 
'object:state-changed:selected')
        pyatspi.Registry.registerEventListener(listener, 
'object:selection-changed')
        pyatspi.Registry.start()
    
    Relevant output from the script:
    
        object:state-changed:selected(1, 0, 0)
                source: [table cell | A1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:state-changed:selected(1, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table | Table1-1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table | Table1-1]
                host_application: [application | soffice]
                sender: [application | soffice]
    
    Change-Id: I12a871f748c86fa271fafb839fd9ce8275f93cee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173257
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/acctable.cxx 
b/sw/source/core/access/acctable.cxx
index ab0f8ff9c5be..61b8ace7b932 100644
--- a/sw/source/core/access/acctable.cxx
+++ b/sw/source/core/access/acctable.cxx
@@ -1503,7 +1503,10 @@ void SwAccessibleTable::FireSelectionEvent( )
         // fdo#57197: check if the object is still alive
         rtl::Reference<SwAccessibleContext> const pAccCell(rxCell);
         if (pAccCell)
-            pAccCell->FireAccessibleEvent(aEvent);
+        {
+            aEvent.NewValue <<= uno::Reference<XAccessible>(pAccCell);
+            FireAccessibleEvent(aEvent);
+        }
     }
 
     if (m_vecCellAdd.size() <= SELECTION_WITH_NUM)
@@ -1514,7 +1517,10 @@ void SwAccessibleTable::FireSelectionEvent( )
             // fdo#57197: check if the object is still alive
             rtl::Reference<SwAccessibleContext> const pAccCell(rxCell);
             if (pAccCell)
-                pAccCell->FireAccessibleEvent(aEvent);
+            {
+                aEvent.NewValue <<= uno::Reference<XAccessible>(pAccCell);
+                FireAccessibleEvent(aEvent);
+            }
         }
     }
     else
commit 7d4def4d942bbbdb1688c2947cb621f7f55fa966
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Sep 12 11:51:31 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Sep 12 14:38:35 2024 +0200

    sw a11y: Don't resend obsolete table selection events
    
    When a table cell was (un)selected, it is added to
    the vector of added/removed cells.
    `SwAccessibleTable::FireSelectionEvent` iterates over
    the cells in those vectors and sends an event for every
    element.
    
    The elements were never removed from the vector, however,
    meaning that obsolete events of previous selection activity
    would be resent every time any selection change occured.
    
    Clear the vectors after sending the events to prevent that.
    
    pyatspi script with which the issue could be seen with the gtk3
    VCL plugin:
    
        #!/usr/bin/python3
        import pyatspi
        def listener(e):
            try:
                if not e.host_application.name.startswith('soffice'):
                    return
            except:
                return
            print(e)
        pyatspi.Registry.registerEventListener(listener, 
'object:selection-changed')
        pyatspi.Registry.start()
    
    Selecting the first 2 cells in a newly inserted Writer table would
    result (among others) in these events for the cells:
    
        object:selection-changed(0, 0, 0)
                source: [table cell | A1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
    
    (The fact that "selection-changed" events are sent for
    the cells instead of the table is another issue that will be
    handled separately.)
    Unselecting the second cell would then trigger these
    "selection-changed" events:
    
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table cell | A1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
    
    (Note the two last "selection-changed" events being
    resent from before.)
    
    Selecting the second cell once again would then trigger
    4 events despite only a single cell having been newly
    selected:
    
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table cell | A1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
    
    With this commit in place, only a single event
    for the newly (un)selected cell B1 is sent in
    steps 2 and 3:
    
        object:selection-changed(0, 0, 0)
                source: [table cell | B1]
                host_application: [application | soffice]
                sender: [application | soffice]
    
    Change-Id: I36505d56b032196fa084492a87a118f5366db1dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173255
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sw/source/core/access/acctable.cxx 
b/sw/source/core/access/acctable.cxx
index 2195028783c8..ab0f8ff9c5be 100644
--- a/sw/source/core/access/acctable.cxx
+++ b/sw/source/core/access/acctable.cxx
@@ -1516,13 +1516,15 @@ void SwAccessibleTable::FireSelectionEvent( )
             if (pAccCell)
                 pAccCell->FireAccessibleEvent(aEvent);
         }
-        return ;
     }
     else
     {
         aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
         FireAccessibleEvent(aEvent);
     }
+
+    m_vecCellRemove.clear();
+    m_vecCellAdd.clear();
 }
 
 void SwAccessibleTable::AddSelectionCell(

Reply via email to