[orca] Store row and column info even when the focused object isn't a cell



commit 62f485114ac58f84e7446ba0a7c76d7a4df23d1b
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Jun 30 15:53:38 2022 +0200

    Store row and column info even when the focused object isn't a cell
    
    The logic to determine whether or not the row and/or column header
    has changed relies on the values stored when the location changes.
    We were only storing those values when the new location was a cell
    (or cell-like thing). If instead the new location is a focusable
    descendant of the cell, we are at risk of duplicating header info.
    
    This commit fixes that by looking for the most immediate ancestor
    cell and storing its coordinates if found.
    
    See issue #253.

 src/orca/script_utilities.py             | 8 ++++++--
 src/orca/scripts/default.py              | 2 +-
 src/orca/scripts/web/script_utilities.py | 8 ++++++--
 3 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index d75acffb3..40ed63418 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -4486,14 +4486,18 @@ class Utilities:
         rowIndex = table.getRowAtIndex(index)
         return table.getRowHeader(rowIndex)
 
-    def coordinatesForCell(self, obj, preferAttribute=True):
+    def coordinatesForCell(self, obj, preferAttribute=True, findCellAncestor=False):
         roles = [pyatspi.ROLE_TABLE_CELL,
                  pyatspi.ROLE_TABLE_COLUMN_HEADER,
                  pyatspi.ROLE_TABLE_ROW_HEADER,
                  pyatspi.ROLE_COLUMN_HEADER,
                  pyatspi.ROLE_ROW_HEADER]
         if not (obj and obj.getRole() in roles):
-            return -1, -1
+            if not findCellAncestor:
+                return -1, -1
+
+            cell = pyatspi.findAncestor(obj, lambda x: x and x.getRole() in roles)
+            return self.coordinatesForCell(cell, preferAttribute, False)
 
         isTable = lambda x: x and 'Table' in pyatspi.listInterfaces(x)
         parent = pyatspi.findAncestor(obj, isTable)
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index fd7dfba94..b0d8409f0 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -837,7 +837,7 @@ class Script(script.Script):
         # We want to save the current row and column of a newly focused
         # or selected table cell so that on subsequent cell focus/selection
         # we only present the changed location.
-        row, column = self.utilities.coordinatesForCell(obj)
+        row, column = self.utilities.coordinatesForCell(obj, findCellAncestor=True)
         self.pointOfReference['lastColumn'] = column
         self.pointOfReference['lastRow'] = row
 
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 45c0bc81a..2d80fc20d 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -2985,14 +2985,18 @@ class Utilities(script_utilities.Utilities):
 
         return ''
 
-    def coordinatesForCell(self, obj, preferAttribute=True):
+    def coordinatesForCell(self, obj, preferAttribute=True, findCellAncestor=False):
         roles = [pyatspi.ROLE_TABLE_CELL,
                  pyatspi.ROLE_TABLE_COLUMN_HEADER,
                  pyatspi.ROLE_TABLE_ROW_HEADER,
                  pyatspi.ROLE_COLUMN_HEADER,
                  pyatspi.ROLE_ROW_HEADER]
         if not (obj and obj.getRole() in roles):
-            return -1, -1
+            if not findCellAncestor:
+                return -1, -1
+
+            cell = pyatspi.findAncestor(obj, lambda x: x and x.getRole() in roles)
+            return self.coordinatesForCell(cell, preferAttribute, False)
 
         if not preferAttribute:
             return super().coordinatesForCell(obj, preferAttribute)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]