Commit 09bbfb4c authored by Joanmarie Diggs's avatar Joanmarie Diggs

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.
parent c5866be9
......@@ -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
......
......@@ -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."""
......
......@@ -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."""
......
......@@ -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)
......@@ -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."""
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment