[orca] Web: Fall back on object attributes for absent text attributes



commit 09bbfb4c730402a386cd09ca2d43eceba41d684e
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Aug 17 16:49:11 2020 +0200

    Web: Fall back on object attributes for absent text attributes
    
    Because IAccessible2 treats text attributes which apply to an entire
    object (e.g. alignment) as an object attribute rather than a text
    attribute, neither Gecko nor Chromium are exposing these attributes
    to us via AtkText. So we need to fall back on object attributes for
    those.
    
    In addition, because this exposure is based on the CSS property name
    rather than the ATK name, we need to convert the attribute name into
    the expected name. Ditto for at least one value. The latter is needed
    for localization.
    
    Finally, fix a bug in Orca which was causing certain non-standard
    text attribute names to always be presented, even when they had
    the default value.

 src/orca/scripts/default.py                         |  8 +++-----
 src/orca/scripts/toolkits/Chromium/script.py        | 10 ++++++++++
 src/orca/scripts/toolkits/Gecko/script.py           | 19 ++++++++++---------
 src/orca/scripts/toolkits/Gecko/script_utilities.py |  4 ++++
 src/orca/scripts/web/script.py                      | 12 ++++++++++++
 src/orca/scripts/web/script_utilities.py            | 13 ++++++++++++-
 6 files changed, 51 insertions(+), 15 deletions(-)
---
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 4881fa8ef..5d7a8d5a4 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -1300,13 +1300,11 @@ class Script(script.Script):
         [userAttrList, userAttrDict] = self.utilities.stringToKeysAndDict(
             _settingsManager.getSetting('enabledSpokenTextAttributes'))
 
-        # Because some implementors make up their own attribute names,
-        # we need to convert.
-        userAttrList = list(map(self.utilities.getAppNameForAttribute, userAttrList))
         nullValues = ['0', '0mm', 'none', 'false']
-
         for key in userAttrList:
-            value = attrs.get(key)
+            # Convert the standard key into the non-standard implementor variant.
+            appKey = self.utilities.getAppNameForAttribute(key)
+            value = attrs.get(appKey)
             ignoreIfValue = userAttrDict.get(key)
             if value in nullValues and ignoreIfValue in nullValues:
                 continue
diff --git a/src/orca/scripts/toolkits/Chromium/script.py b/src/orca/scripts/toolkits/Chromium/script.py
index 1c5fd77ab..151845fff 100644
--- a/src/orca/scripts/toolkits/Chromium/script.py
+++ b/src/orca/scripts/toolkits/Chromium/script.py
@@ -357,6 +357,16 @@ class Script(web.Script):
         debug.println(debug.LEVEL_INFO, msg, True)
         default.Script.onShowingChanged(self, event)
 
+    def onTextAttributesChanged(self, event):
+        """Callback for object:text-attributes-changed accessibility events."""
+
+        if super().onTextAttributesChanged(event):
+            return
+
+        msg = "Chromium: Passing along event to default script"
+        debug.println(debug.LEVEL_INFO, msg, True)
+        default.Script.onTextAttributesChanged(self, event)
+
     def onTextDeleted(self, event):
         """Callback for object:text-changed:delete accessibility events."""
 
diff --git a/src/orca/scripts/toolkits/Gecko/script.py b/src/orca/scripts/toolkits/Gecko/script.py
index 4ff369f5b..cfc4a4329 100644
--- a/src/orca/scripts/toolkits/Gecko/script.py
+++ b/src/orca/scripts/toolkits/Gecko/script.py
@@ -42,15 +42,6 @@ class Script(web.Script):
     def __init__(self, app):
         super().__init__(app)
 
-        # This can be removed once this Mozilla bug is fixed:
-        # https://bugzilla.mozilla.org/show_bug.cgi?id=1174204
-        self.attributeNamesDict = {
-            "background-color"        : "bg-color",
-            "color"                   : "fg-color"}
-
-        # This one needs some more consideration for all toolkits.
-        self.attributeNamesDict["invalid"] = "text-spelling"
-
     def getUtilities(self):
         """Returns the utilites for this script."""
 
@@ -305,6 +296,16 @@ class Script(web.Script):
         debug.println(debug.LEVEL_INFO, msg, True)
         default.Script.onShowingChanged(self, event)
 
+    def onTextAttributesChanged(self, event):
+        """Callback for object:text-attributes-changed accessibility events."""
+
+        if super().onTextAttributesChanged(event):
+            return
+
+        msg = "GECKO: Passing along event to default script"
+        debug.println(debug.LEVEL_INFO, msg, True)
+        default.Script.onTextAttributesChanged(self, event)
+
     def onTextDeleted(self, event):
         """Callback for object:text-changed:delete accessibility events."""
 
diff --git a/src/orca/scripts/toolkits/Gecko/script_utilities.py 
b/src/orca/scripts/toolkits/Gecko/script_utilities.py
index dbf5b9f87..671eb7a49 100644
--- a/src/orca/scripts/toolkits/Gecko/script_utilities.py
+++ b/src/orca/scripts/toolkits/Gecko/script_utilities.py
@@ -351,3 +351,7 @@ class Utilities(web.Utilities):
         self._lastAutoTextInputEvent = orca_state.lastInputEvent
         self._lastAutoTextEventTime = time.time()
         return True
+
+    def localizeTextAttribute(self, key, value):
+        value = value.replace("-moz-", "")
+        return super().localizeTextAttribute(key, value)
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 9d51745a0..83afb0594 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -105,6 +105,10 @@ class Script(default.Script):
         self._autoFocusModeCaretNavCheckButton = None
         self._layoutModeCheckButton = None
 
+        self.attributeNamesDict["invalid"] = "text-spelling"
+        self.attributeNamesDict["text-align"] = "justification"
+        self.attributeNamesDict["text-indent"] = "indent"
+
     def deactivate(self):
         """Called when this script is deactivated."""
 
@@ -2139,6 +2143,14 @@ class Script(default.Script):
 
         return True
 
+    def onTextAttributesChanged(self, event):
+        """Callback for object:text-attributes-changed accessibility events."""
+
+        msg = "WEB: Clearing cached text attributes"
+        debug.println(debug.LEVEL_INFO, msg, True)
+        self._currentTextAttrs = {}
+        return False
+
     def onTextDeleted(self, event):
         """Callback for object:text-changed:delete accessibility events."""
 
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index d14769fae..4de05f992 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -878,10 +878,21 @@ class Utilities(script_utilities.Utilities):
             return attrsForObj.get(offset)
 
         attrs = super().textAttributes(acc, offset, get_defaults)
-        self._currentTextAttrs[hash(acc)] = {offset:attrs}
+        objAttributes = self.objectAttributes(acc, False)
+        for key in self._script.attributeNamesDict.keys():
+            value = objAttributes.get(key)
+            if value is not None:
+                attrs[0][key] = value
 
+        self._currentTextAttrs[hash(acc)] = {offset:attrs}
         return attrs
 
+    def localizeTextAttribute(self, key, value):
+        if key == "justification" and value == "justify":
+            value = "fill"
+
+        return super().localizeTextAttribute(key, value)
+
     def findObjectInContents(self, obj, offset, contents, usingCache=False):
         if not obj or not contents:
             return -1


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