[orca] Improve presentation of graphical/icon-based push buttons



commit c86f2d05b0738f9ecd550c846782437b72305cb8
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Feb 12 10:00:20 2019 -0500

    Improve presentation of graphical/icon-based push buttons

 src/orca/script_utilities.py              |  3 +++
 src/orca/scripts/web/braille_generator.py | 12 ++++++++++++
 src/orca/scripts/web/script_utilities.py  | 25 +++++++++++++++++++++++++
 src/orca/scripts/web/speech_generator.py  |  8 +++++++-
 4 files changed, 47 insertions(+), 1 deletion(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 2427e1353..8f6dabbc6 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -437,6 +437,9 @@ class Utilities:
         self._script.generatorCache[self.DISPLAYED_LABEL][obj] = labelString
         return self._script.generatorCache[self.DISPLAYED_LABEL][obj]
 
+    def preferDescriptionOverName(self, obj):
+        return False
+
     def descriptionsForObject(self, obj):
         """Return a list of objects describing obj."""
 
diff --git a/src/orca/scripts/web/braille_generator.py b/src/orca/scripts/web/braille_generator.py
index b3075f432..8ac500099 100644
--- a/src/orca/scripts/web/braille_generator.py
+++ b/src/orca/scripts/web/braille_generator.py
@@ -128,6 +128,18 @@ class BrailleGenerator(braille_generator.BrailleGenerator):
 
         return super()._generateLabelAndName(obj, **args)
 
+    def _generateDescription(self, obj, **args):
+        if self._script.utilities.preferDescriptionOverName(obj):
+            return []
+
+        return super()._generateDescription(obj, **args)
+
+    def _generateName(self, obj, **args):
+        if self._script.utilities.preferDescriptionOverName(obj):
+            return [obj.description]
+
+        return super()._generateDescription(obj, **args)
+
     def _generateExpandedEOCs(self, obj, **args):
         """Returns the expanded embedded object characters for an object."""
         result = []
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 7c3054dec..6fe0aaa05 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -96,6 +96,7 @@ class Utilities(script_utilities.Utilities):
         self._displayedLabelText = {}
         self._mimeType = {}
         self._roleDescription = {}
+        self._preferDescriptionOverName = {}
         self._shouldFilter = {}
         self._shouldInferLabelFor = {}
         self._text = {}
@@ -166,6 +167,7 @@ class Utilities(script_utilities.Utilities):
         self._displayedLabelText = {}
         self._mimeType = {}
         self._roleDescription = {}
+        self._preferDescriptionOverName = {}
         self._shouldFilter = {}
         self._shouldInferLabelFor = {}
         self._tag = {}
@@ -3975,6 +3977,29 @@ class Utilities(script_utilities.Utilities):
 
         return messages.PAGE_SUMMARY_PREFIX % ", ".join(result)
 
+    def preferDescriptionOverName(self, obj):
+        if not self.inDocumentContent(obj):
+            return super().preferDescriptionOverName(obj)
+
+        rv = self._preferDescriptionOverName.get(hash(obj))
+        if rv is not None:
+            return rv
+
+        try:
+            role = obj.getRole()
+            name = obj.name
+            description = obj.description
+        except:
+            msg = "WEB: Exception getting name, description, and role for %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            rv = False
+        else:
+            roles = [pyatspi.ROLE_PUSH_BUTTON]
+            rv = role in roles and len(name) == 1 and description
+
+        self._preferDescriptionOverName[hash(obj)] = rv
+        return rv
+
     def _getCtrlShiftSelectionsStrings(self):
         """Hacky and to-be-obsoleted method."""
         return [messages.LINE_SELECTED_DOWN,
diff --git a/src/orca/scripts/web/speech_generator.py b/src/orca/scripts/web/speech_generator.py
index dec21f107..90a4f9594 100644
--- a/src/orca/scripts/web/speech_generator.py
+++ b/src/orca/scripts/web/speech_generator.py
@@ -119,6 +119,9 @@ class SpeechGenerator(speech_generator.SpeechGenerator):
         if self._script.utilities.isZombie(obj):
             return []
 
+        if self._script.utilities.preferDescriptionOverName(obj):
+            return []
+
         role = args.get('role', obj.getRole())
         if obj != orca_state.locusOfFocus:
             if role in [pyatspi.ROLE_ALERT, pyatspi.ROLE_DIALOG]:
@@ -187,7 +190,10 @@ class SpeechGenerator(speech_generator.SpeechGenerator):
             return []
 
         if self._script.utilities.inDocumentContent(obj) and obj.name:
-            result = [obj.name]
+            if self._script.utilities.preferDescriptionOverName(obj):
+                result = [obj.description]
+            else:
+                result = [obj.name]
             result.extend(self.voice(speech_generator.DEFAULT))
             return result
 


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