[orca] Prevent double-presentation of description for alerts



commit 04d6320b7e8d38a6dcb3a1a40aeb9039d85d1fe2
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Fri Mar 19 16:39:00 2021 +0100

    Prevent double-presentation of description for alerts
    
    In (at least) Firefox's native alerts, the alert text is exposed as
    the accessible description. Knowing this, that's our last resort for
    the displayed text. But when we rely upon that and the user also has
    descriptions spoken (which they are by default), we double-present
    the text.
    
    Also ensure this last resort kicks in even if the user has disabled
    spoken descriptions.

 src/orca/formatting.py       |  2 +-
 src/orca/speech_generator.py | 27 ++++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/formatting.py b/src/orca/formatting.py
index 39f21f334..823e9b4d2 100644
--- a/src/orca/formatting.py
+++ b/src/orca/formatting.py
@@ -129,7 +129,7 @@ formatting = {
             'detailedWhereAmI' : 'pageSummary'
             },
         pyatspi.ROLE_ALERT: {
-            'unfocused': 'roleName + labelOrName + pause + (expandedEOCs or unrelatedLabels or description)'
+            'unfocused': 'roleName + labelOrName + pause + alertText'
             },
         pyatspi.ROLE_ANIMATION: {
             'unfocused': 'labelAndName'
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index 6de2c3eaf..8ae3658a2 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -231,15 +231,40 @@ class SpeechGenerator(generator.Generator):
             result.extend(acss)
         return result
 
+    def _generateAlertText(self, obj, **args):
+        result = self._generateExpandedEOCs(obj, **args) or self._generateUnrelatedLabels(obj, **args)
+        if result:
+            self._script.pointOfReference['usedDescriptionForAlert'] = False
+            return result
+
+        args['alerttext'] = True
+        result = self._generateDescription(obj, **args)
+        if result:
+            self._script.pointOfReference['usedDescriptionForAlert'] = True
+
+        return result
+
     def _generateDescription(self, obj, **args):
         """Returns an array of strings fo use by speech and braille that
         represent the description of the object, if that description
         is different from that of the name and label.
         """
+
+        alreadyUsed = False
+        role = args.get('role', obj.getRole())
+        if role == pyatspi.ROLE_ALERT:
+            try:
+                alreadyUsed = self._script.pointOfReference.pop('usedDescriptionForAlert')
+            except:
+                pass
+
+        if alreadyUsed:
+            return []
+
         if _settingsManager.getSetting('onlySpeakDisplayedText'):
             return []
 
-        if not _settingsManager.getSetting('speakDescription'):
+        if not _settingsManager.getSetting('speakDescription') and not args.get('alerttext'):
             return []
 
         if args.get('inMouseReview') and not _settingsManager.getSetting('presentToolTips'):


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