[orca] Use document script utilities rather than explicit role checks



commit 0c8454654400bb84fa58c5082b8741af0f1a30e0
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Jul 28 00:21:05 2016 -0400

    Use document script utilities rather than explicit role checks

 src/orca/bookmarks.py                              |    3 +-
 src/orca/scripts/apps/Instantbird/chat.py          |   18 +++-----
 src/orca/scripts/apps/Thunderbird/script.py        |   47 ++++++--------------
 .../scripts/apps/evolution/script_utilities.py     |    4 +-
 src/orca/scripts/apps/gnome-documents/script.py    |    3 +-
 .../apps/gnome-documents/script_utilities.py       |    4 +-
 src/orca/scripts/apps/soffice/script_utilities.py  |    9 ++--
 src/orca/scripts/apps/soffice/speech_generator.py  |    2 +-
 src/orca/scripts/toolkits/WebKitGtk/script.py      |    6 ++-
 9 files changed, 34 insertions(+), 62 deletions(-)
---
diff --git a/src/orca/bookmarks.py b/src/orca/bookmarks.py
index 4dda4d9..a81e07c 100644
--- a/src/orca/bookmarks.py
+++ b/src/orca/bookmarks.py
@@ -219,8 +219,7 @@ class Bookmarks:
         if not start_obj:
             return []
 
-        docRoles = [pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_DOCUMENT_WEB]
-        if start_obj.getRole() in docRoles:
+        if self._script.utilities.isDocument(start_obj):
             return []
 
         path = []
diff --git a/src/orca/scripts/apps/Instantbird/chat.py b/src/orca/scripts/apps/Instantbird/chat.py
index dbb262a..edbdb83 100644
--- a/src/orca/scripts/apps/Instantbird/chat.py
+++ b/src/orca/scripts/apps/Instantbird/chat.py
@@ -38,12 +38,6 @@ import orca.chat as chat
 class Chat(chat.Chat):
 
     def __init__(self, script, buddyListAncestries):
-        # IMs get inserted as embedded object characters in these roles.
-        #
-        self._messageParentRoles = [pyatspi.ROLE_DOCUMENT_FRAME,
-                                    pyatspi.ROLE_SECTION,
-                                    pyatspi.ROLE_PARAGRAPH]
-
         chat.Chat.__init__(self, script, buddyListAncestries)
 
     ########################################################################
@@ -70,7 +64,7 @@ class Chat(chat.Chat):
         # document frame. The first paragraph is the bubble title; the
         # rest (usually just one) are the message itself.
         #
-        if event.source.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+        if self._script.utilities.isDocument(event.source):
             bubble = event.source[event.detail1]
             hasRole = lambda x: x and x.getRole() == pyatspi.ROLE_PARAGRAPH
             paragraphs = pyatspi.findAllDescendants(bubble, hasRole)
@@ -122,13 +116,13 @@ class Chat(chat.Chat):
         - obj: the accessible object to examine.
         """
 
-        # We might need to refine this later. For now, just get things
-        # working.
-        #
-        if obj and obj.getRole() in self._messageParentRoles:
+        if not obj:
+            return False
+
+        if self._script.utilities.isDocument(obj):
             return True
 
-        return False
+        return obj.getRole() in [pyatspi.ROLE_SECTION, pyatspi.ROLE_PARAGRAPH]
 
     def getChatRoomName(self, obj):
         """Attempts to find the name of the current chat room.
diff --git a/src/orca/scripts/apps/Thunderbird/script.py b/src/orca/scripts/apps/Thunderbird/script.py
index 33bd9f9..4bc77b4 100644
--- a/src/orca/scripts/apps/Thunderbird/script.py
+++ b/src/orca/scripts/apps/Thunderbird/script.py
@@ -186,7 +186,7 @@ class Script(Gecko.Script):
         """Callback for object:state-changed:busy accessibility events."""
 
         obj = event.source
-        if obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME and not event.detail1:
+        if self.utilities.isDocument(obj) and not event.detail1:
             try:
                 role = orca_state.locusOfFocus.getRole()
                 name = orca_state.locusOfFocus.name
@@ -338,25 +338,13 @@ class Script(Gecko.Script):
             self.spellcheck.presentErrorDetails()
             return
 
-        obj = event.source
+        if not self.utilities.lastInputEventWasDelete() \
+           or not self.utilities.isDocument(event.source):
+            return
 
-        # If the user has just deleted an open mail message, then we want to
-        # try to speak the new name of the open mail message frame and also
-        # present the first line of that message to be consistent with what
-        # we do when a new message window is opened. See bug #540039 for more
-        # details.
-        #
-        rolesList = [pyatspi.ROLE_DOCUMENT_FRAME,
-                     pyatspi.ROLE_INTERNAL_FRAME,
-                     pyatspi.ROLE_FRAME,
-                     pyatspi.ROLE_APPLICATION]
-        if self.utilities.hasMatchingHierarchy(event.source, rolesList):
-            lastKey, mods = self.utilities.lastKeyAndModifiers()
-            if lastKey == "Delete":
-                speech.speak(obj.name)
-                [obj, offset] = self.utilities.findFirstCaretContext(obj, 0)
-                self.utilities.setCaretPosition(obj, offset)
-                return
+        speech.speak(obj.name)
+        [obj, offset] = self.utilities.findFirstCaretContext(obj, 0)
+        self.utilities.setCaretPosition(obj, offset)
 
     def _presentMessage(self, documentFrame):
         """Presents the first line of the message, or the entire message,
@@ -419,17 +407,6 @@ class Script(Gecko.Script):
 
         return default.Script.toggleFlatReviewMode(self, inputEvent)
 
-    def isNonHTMLEntry(self, obj):
-        """Checks for ROLE_ENTRY areas that are not part of an HTML
-        document.  See bug #607414.
-
-        Returns True is this is something like the Subject: entry
-        """
-        result = obj and obj.getRole() == pyatspi.ROLE_ENTRY \
-            and not self.utilities.ancestorWithRole(
-                obj, [pyatspi.ROLE_DOCUMENT_FRAME], [pyatspi.ROLE_FRAME])
-        return result
-
     def isEditableMessage(self, obj):
         """Returns True if this is a editable message."""
 
@@ -439,10 +416,14 @@ class Script(Gecko.Script):
         if not obj.getState().contains(pyatspi.STATE_EDITABLE):
             return False
 
-        if self.isNonHTMLEntry(obj):
-            return False
+        if self.utilities.isDocument(obj):
+            return True
+
+        document = self.utilities.containingDocument(obj)
+        if document and document.getState().contains(pyatspi.STATE_EDITABLE):
+            return True
 
-        return True
+        return False
 
     def onWindowActivated(self, event):
         """Callback for window:activate accessibility events."""
diff --git a/src/orca/scripts/apps/evolution/script_utilities.py 
b/src/orca/scripts/apps/evolution/script_utilities.py
index 31a2f1c..fc69806 100644
--- a/src/orca/scripts/apps/evolution/script_utilities.py
+++ b/src/orca/scripts/apps/evolution/script_utilities.py
@@ -70,9 +70,7 @@ class Utilities(WebKitGtk.Utilities, gtk.Utilities):
         return topLevel and topLevel.getRole() == pyatspi.ROLE_WINDOW
 
     def findMessageBodyChild(self, root):
-        roles = [pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_DOCUMENT_WEB]
-        isDocument = lambda x: x and x.getRole() in roles
-        candidate = pyatspi.findDescendant(root, isDocument)
+        candidate = pyatspi.findDescendant(root, self.isDocument)
         if self.isEmbeddedDocument(candidate):
             return self.findMessageBodyChild(candidate)
 
diff --git a/src/orca/scripts/apps/gnome-documents/script.py b/src/orca/scripts/apps/gnome-documents/script.py
index fb513a2..0e1026f 100644
--- a/src/orca/scripts/apps/gnome-documents/script.py
+++ b/src/orca/scripts/apps/gnome-documents/script.py
@@ -58,13 +58,12 @@ class Script(gtk.Script):
 
         try:
             eventRole = event.source.getRole()
-            focusRole = orca_state.locusOfFocus.getRole()
         except:
             return
 
         # Present page changes in the previewer.
         if eventRole == pyatspi.ROLE_LABEL \
-           and focusRole == pyatspi.ROLE_DOCUMENT_FRAME:
+           and self.utilities.isDocument(orca_state.locusOfFocus):
             self.presentMessage(event.any_data)
 
             # HACK: Reposition the caret offset from the last character to the
diff --git a/src/orca/scripts/apps/gnome-documents/script_utilities.py 
b/src/orca/scripts/apps/gnome-documents/script_utilities.py
index 49cf210..fdb93cc 100644
--- a/src/orca/scripts/apps/gnome-documents/script_utilities.py
+++ b/src/orca/scripts/apps/gnome-documents/script_utilities.py
@@ -36,13 +36,13 @@ class Utilities(gtk.Utilities):
         gtk.Utilities.__init__(self, script)
 
     def isReadOnlyTextArea(self, obj):
-        if obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+        if self.isDocument(obj):
             return False
 
         return gtk.Utilities.isReadOnlyTextArea(self, obj)
 
     def isTextArea(self, obj):
-        if obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+        if self.isDocument(obj):
             return True
 
         return gtk.Utilities.isTextArea(self, obj)
diff --git a/src/orca/scripts/apps/soffice/script_utilities.py 
b/src/orca/scripts/apps/soffice/script_utilities.py
index 587055f..7522725 100644
--- a/src/orca/scripts/apps/soffice/script_utilities.py
+++ b/src/orca/scripts/apps/soffice/script_utilities.py
@@ -512,7 +512,7 @@ class Utilities(script_utilities.Utilities):
     def isDrawingView(self, obj):
         """Returns True if obj is the Impress Drawing View."""
 
-        if obj and obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+        if self.isDocument(obj):
             return (":" in obj.name and "/" in obj.name)
 
         return False
@@ -560,8 +560,7 @@ class Utilities(script_utilities.Utilities):
             return None, None
 
         slidePane = taskPane = None
-        hasRole = lambda x: x and x.getRole() == pyatspi.ROLE_DOCUMENT_FRAME
-        if pyatspi.findAllDescendants(panes[0], hasRole):
+        if pyatspi.findAllDescendants(panes[0], self.isDocument):
             slidePane = panes[0]
             if len(panes) == 2:
                 taskPane = panes[1]
@@ -579,10 +578,10 @@ class Utilities(script_utilities.Utilities):
         Returns a (title, position, count) tuple.
         """
 
-        if obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+        if self.isDocument(obj):
             dv = obj
         else:
-            dv = self.ancestorWithRole(obj, [pyatspi.ROLE_DOCUMENT_FRAME], [])
+            dv = self.getContainingDocument(obj)
 
         if not dv or not self.isDrawingView(dv):
             return "", 0, 0
diff --git a/src/orca/scripts/apps/soffice/speech_generator.py 
b/src/orca/scripts/apps/soffice/speech_generator.py
index a2a99b9..23612e9 100644
--- a/src/orca/scripts/apps/soffice/speech_generator.py
+++ b/src/orca/scripts/apps/soffice/speech_generator.py
@@ -455,7 +455,7 @@ class SpeechGenerator(speech_generator.SpeechGenerator):
         oldTable = pyatspi.findAncestor(priorObj, isTable)
         if oldTable:
             ancestor = self._script.utilities.commonAncestor(oldTable, obj)
-            if ancestor and ancestor.getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+            if self._script.utilities.isDocument(ancestor):
                 result = [messages.TABLE_LEAVING]
                 result.extend(self.voice(speech_generator.SYSTEM))
                 result.extend(self._generatePause(obj, **args))
diff --git a/src/orca/scripts/toolkits/WebKitGtk/script.py b/src/orca/scripts/toolkits/WebKitGtk/script.py
index fd5ff30..f9b2618 100644
--- a/src/orca/scripts/toolkits/WebKitGtk/script.py
+++ b/src/orca/scripts/toolkits/WebKitGtk/script.py
@@ -510,8 +510,10 @@ class Script(default.Script):
         if obj.getRole() == pyatspi.ROLE_LINK:
             obj = obj.parent
 
-        docRoles = [pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_DOCUMENT_WEB]
-        document = utils.findAncestor(obj, lambda x: x.getRole() in docRoles)
+        if self.utilities.isDocument(obj):
+            document = obj
+        else:
+            document = self.utilities.containingDocument(obj)
         if not document or document.getState().contains(pyatspi.STATE_BUSY):
             return
 


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