[orca] Web: Eliminate some chattiness entering elements with a caption



commit abbaff8c55aa312aa64ad3cbc20a8a176cc92a4e
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Mar 22 13:47:54 2021 +0100

    Web: Eliminate some chattiness entering elements with a caption
    
    If an element has a caption there is an excellent chance that its
    accessible name will be derived from it. If that caption is visible/
    navigable, we'll likely end up presenting it again during navigation.
    In addition, captions (e.g. on figures and tables) can get rather long.
    The least chatty thing to do in this case seems to be to not present
    visible captions as the name but rather wait until the user navigates
    to it.

 src/orca/script_utilities.py             |  3 +++
 src/orca/scripts/web/script_utilities.py | 19 +++++++++++++++++++
 src/orca/scripts/web/speech_generator.py |  3 +++
 3 files changed, 25 insertions(+)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index ab707aac6..ffc1ca570 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -4211,6 +4211,9 @@ class Utilities:
     def detailsFor(self, obj):
         return []
 
+    def hasVisibleCaption(self, obj):
+        return False
+
     def popupType(self, obj):
         return ''
 
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 6de84eccb..677f933d7 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -77,6 +77,7 @@ class Utilities(script_utilities.Utilities):
         self._elementLinesAreSingleWords= {}
         self._hasNoSize = {}
         self._hasLongDesc = {}
+        self._hasVisibleCaption = {}
         self._hasDetails = {}
         self._isDetails = {}
         self._hasUselessCanvasDescendant = {}
@@ -168,6 +169,7 @@ class Utilities(script_utilities.Utilities):
         self._elementLinesAreSingleWords= {}
         self._hasNoSize = {}
         self._hasLongDesc = {}
+        self._hasVisibleCaption = {}
         self._hasDetails = {}
         self._isDetails = {}
         self._hasUselessCanvasDescendant = {}
@@ -4016,6 +4018,23 @@ class Utilities(script_utilities.Utilities):
         self._hasLongDesc[hash(obj)] = rv
         return rv
 
+    def hasVisibleCaption(self, obj):
+        if not (obj and self.inDocumentContent(obj)):
+            return super().hasVisibleCaption(obj)
+
+        if not (self.isFigure(obj) or "Table" in pyatspi.listInterfaces(obj)):
+            return False
+
+        rv = self._hasVisibleCaption.get(hash(obj))
+        if rv is not None:
+            return rv
+
+        labels = self.labelsForObject(obj)
+        pred = lambda x: x and x.getRole() == pyatspi.ROLE_CAPTION and self.isShowingAndVisible(x)
+        rv = bool(list(filter(pred, labels)))
+        self._hasVisibleCaption[hash(obj)] = rv
+        return rv
+
     def hasDetails(self, obj):
         if not (obj and self.inDocumentContent(obj)):
             return super().hasDetails(obj)
diff --git a/src/orca/scripts/web/speech_generator.py b/src/orca/scripts/web/speech_generator.py
index b3a073408..68348da38 100644
--- a/src/orca/scripts/web/speech_generator.py
+++ b/src/orca/scripts/web/speech_generator.py
@@ -362,6 +362,9 @@ class SpeechGenerator(speech_generator.SpeechGenerator):
            and not args.get('inFlatReview'):
             return []
 
+        if self._script.utilities.hasVisibleCaption(obj):
+            return []
+
         if self._script.utilities.isFigure(obj) and args.get('ancestorOf'):
             caption = args.get('ancestorOf')
             if caption.getRole() != pyatspi.ROLE_CAPTION:


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