[orca] Attempt to identify elements serving as placeholders



commit f2ac024b91563292a32cbb10aa3305b32d2b840c
Author: Joanmarie Diggs <joanmarie diggs gmail com>
Date:   Wed Jan 22 01:04:28 2020 -0500

    Attempt to identify elements serving as placeholders
    
    If the author has created a fake placeholder out of divs and spans,
    try to present it like a real placeholder rather than entry content.

 src/orca/scripts/web/script_utilities.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
---
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 478dbf19a..0aae05c9b 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -1029,6 +1029,10 @@ class Utilities(script_utilities.Utilities):
                 msg = "WEB: Treating %s as non-text: is non-navigable embedded document." % obj
                 debug.println(debug.LEVEL_INFO, msg, True)
                 rv = None
+            if rv and self.isFakePlaceholderForEntry(obj):
+                msg = "WEB: Treating %s as non-text: is fake placeholder for entry." % obj
+                debug.println(debug.LEVEL_INFO, msg, True)
+                rv = None
 
         self._text[hash(obj)] = rv
         return rv
@@ -1098,6 +1102,9 @@ class Utilities(script_utilities.Utilities):
         if self.isNonNavigableEmbeddedDocument(obj):
             return True
 
+        if self.isFakePlaceholderForEntry(obj):
+            return True
+
         return False
 
     def __findRange(self, text, offset, start, end, boundary):
@@ -3236,6 +3243,26 @@ class Utilities(script_utilities.Utilities):
         self._isErrorMessage[hash(obj)] = rv
         return rv
 
+    def isFakePlaceholderForEntry(self, obj):
+        if not (obj and self.inDocumentContent(obj)):
+            return False
+
+        if not (obj.parent.getRole() == pyatspi.ROLE_ENTRY and obj.parent.name):
+            return False
+
+        def _isMatch(x):
+            try:
+                role = x.getRole()
+                string = x.queryText().getText(0, -1).strip()
+            except:
+                return False
+            return role in [pyatspi.ROLE_SECTION, pyatspi.ROLE_STATIC] and obj.parent.name == string
+
+        if _isMatch(obj):
+            return True
+
+        return pyatspi.findDescendant(obj, _isMatch) is not None
+
     def isInlineListItem(self, obj):
         if not (obj and self.inDocumentContent(obj)):
             return False
@@ -4103,6 +4130,10 @@ class Utilities(script_utilities.Utilities):
             msg = "WEB: Static text leaf cannot have caret context %s" % obj
             debug.println(debug.LEVEL_INFO, msg, True)
             return False
+        if self.isFakePlaceholderForEntry(obj):
+            msg = "WEB: Fake placeholder for entry cannot have caret context %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
 
         return True
 


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