[orca] Move some Gecko predicates into main structural navigation module



commit 68cef358ba3dc6b584844a6964152da4679ae848
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Jun 9 12:30:15 2015 -0400

    Move some Gecko predicates into main structural navigation module

 .../toolkits/Gecko/structural_navigation.py        |  125 --------------------
 src/orca/structural_navigation.py                  |   27 ++--
 2 files changed, 14 insertions(+), 138 deletions(-)
---
diff --git a/src/orca/scripts/toolkits/Gecko/structural_navigation.py 
b/src/orca/scripts/toolkits/Gecko/structural_navigation.py
index 3dbb59f..4287720 100644
--- a/src/orca/scripts/toolkits/Gecko/structural_navigation.py
+++ b/src/orca/scripts/toolkits/Gecko/structural_navigation.py
@@ -137,128 +137,3 @@ class GeckoStructuralNavigation(structural_navigation.StructuralNavigation):
         contents = self._script.utilities.getObjectContentsAtOffset(obj, offset)
         self._script.speakContents(contents)
         self._script.displayContents(contents)
-
-    #########################################################################
-    #                                                                       #
-    # Objects                                                               #
-    #                                                                       #
-    #########################################################################
-
-    ########################
-    #                      #
-    # Chunks/Large Objects #
-    #                      #
-    ########################
-
-    def _chunkPredicate(self, obj, arg=None):
-        """The predicate to be used for verifying that the object
-        obj is a chunk.
-
-        Arguments:
-        - obj: the accessible object under consideration.
-        - arg: an optional argument which may need to be included in
-          the criteria (e.g. the level of a heading).
-        """
-
-        role = obj.getRole()
-        if not role in self.OBJECT_ROLES:
-            return False
- 
-        embeddedObjectChar = self._script.EMBEDDED_OBJECT_CHARACTER
-        if role in [pyatspi.ROLE_LIST, pyatspi.ROLE_TABLE]:
-            # These roles are often serving as containers. We want to see
-            # if what they contain is a bunch of text (as opposed to a
-            # bunch of links or other embedded objects).  As for lists:
-            # We only care about those of the (un)ordered variety. Form
-            # field lists are not chunks.
-            #
-            if not obj.getState().contains(pyatspi.STATE_FOCUSABLE):
-                charCount = 0
-                for child in obj:
-                    try:
-                        text = child.queryText()
-                    except:
-                        text = None
-                    if not text:
-                        continue
-
-                    string = text.getText(0, -1)
-                    if not string.count(embeddedObjectChar):
-                        charCount += text.characterCount
-                        if charCount > settings.largeObjectTextLength:
-                            return True
-            return False
-        else:
-            # We're going to have to take a guess.  It's probably a big
-            # chunk of text if it contains at least the number of characters
-            # specified by largeObjectTextLength, AND
-            # - Guess #1: No more than 5% of the object's total characters
-            #   are EOCs, OR
-            # - Guess #2: No more than 0.5% of the object's initial n
-            #   characters are EOCs, where n is the largeObjectTextLength.
-            #
-            try:
-                text = obj.queryText()
-            except:
-                return False
-            if text \
-               and text.characterCount > settings.largeObjectTextLength:
-                string = text.getText(0, -1)
-                eocs = float(string.count(embeddedObjectChar))
-                if eocs/text.characterCount < 0.05:
-                    return True
-                else:
-                    string = string[0:settings.largeObjectTextLength]
-                    eocs = float(string.count(embeddedObjectChar))
-                    return eocs/len(string) < 0.005
-
-    ########################
-    #                      #
-    # Entries              #
-    #                      #
-    ########################
-
-    def _entryPredicate(self, obj, arg=None):
-        """The predicate to be used for verifying that the object
-        obj is an entry.
-
-        Arguments:
-        - obj: the accessible object under consideration.
-        - arg: an optional argument which may need to be included in
-          the criteria (e.g. the level of a heading).
-        """
-
-        isMatch = False
-        state = obj.getState()
-        isMatch = state.contains(pyatspi.STATE_FOCUSABLE) \
-                  and state.contains(pyatspi.STATE_SENSITIVE) \
-                  and state.contains(pyatspi.STATE_EDITABLE)
-
-        return isMatch
-
-    ########################
-    #                      #
-    # Form Fields          #
-    #                      #
-    ########################
-
-    def _formFieldPredicate(self, obj, arg=None):
-        """The predicate to be used for verifying that the object
-        obj is a form field.
-
-        Arguments:
-        - obj: the accessible object under consideration.
-        - arg: an optional argument which may need to be included in
-          the criteria (e.g. the level of a heading).
-        """
-
-        isMatch = False
-        if obj and obj.getRole() in self.FORM_ROLES:
-            state = obj.getState()
-            isMatch = state.contains(pyatspi.STATE_FOCUSABLE) \
-                  and state.contains(pyatspi.STATE_SENSITIVE)
-
-            if obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
-                isMatch = isMatch and state.contains(pyatspi.STATE_EDITABLE)
-
-        return isMatch
diff --git a/src/orca/structural_navigation.py b/src/orca/structural_navigation.py
index ccd0b88..06bd3fc 100644
--- a/src/orca/structural_navigation.py
+++ b/src/orca/structural_navigation.py
@@ -2095,16 +2095,9 @@ class StructuralNavigation:
         """
 
         isMatch = False
-
         if obj and obj.getRole() in self.OBJECT_ROLES:
-            try:
-                text = obj.queryText()
-                characterCount = text.characterCount
-            except:
-                characterCount = 0
-
-            if characterCount > settings.largeObjectTextLength:
-                isMatch = True
+            text = self._script.utilities.queryNonEmptyText(obj)
+            isMatch = text and text.characterCount > settings.largeObjectTextLength
 
         return isMatch
 
@@ -2372,12 +2365,20 @@ class StructuralNavigation:
           the criteria (e.g. the level of a heading).
         """
 
-        isMatch = False
-        if obj and obj.getRole() in self.FORM_ROLES:
-            state = obj.getState()
-            isMatch = state.contains(pyatspi.STATE_FOCUSABLE) \
+        if not obj:
+            return False
+
+        role = obj.getRole()
+        if not role in self.FORM_ROLES:
+            return False
+
+        state = obj.getState()
+        isMatch = state.contains(pyatspi.STATE_FOCUSABLE) \
                   and state.contains(pyatspi.STATE_SENSITIVE)
 
+        if role == pyatspi.ROLE_DOCUMENT_FRAME:
+            isMatch = isMatch and state.contains(pyatspi.STATE_EDITABLE)
+
         return isMatch
 
     def _formFieldPresentation(self, obj, arg=None):


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