[orca] Fix for bug 701787 - Add structural navigation support for Evince documents



commit 0cdc10aa0ac080a8950863140878ddc5af6734ec
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Jun 18 06:13:44 2013 -0400

    Fix for bug 701787 - Add structural navigation support for Evince documents
    
    Important: This will not actually do anything until Evince has support
    for tagged PDFs. But when that work has been completed, we'll be ready.

 configure.ac                             |    1 +
 src/orca/scripts/apps/Makefile.am        |    1 +
 src/orca/scripts/apps/__init__.py        |    1 +
 src/orca/scripts/apps/evince/Makefile.am |    7 ++
 src/orca/scripts/apps/evince/__init__.py |   23 ++++++
 src/orca/scripts/apps/evince/script.py   |  108 ++++++++++++++++++++++++++++++
 src/orca/structural_navigation.py        |   11 +++
 7 files changed, 152 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0aaf3e4..3f8914f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,6 +91,7 @@ src/orca/scripts/apps/ddu/Makefile
 src/orca/scripts/apps/Eclipse/Makefile
 src/orca/scripts/apps/ekiga/Makefile
 src/orca/scripts/apps/empathy/Makefile
+src/orca/scripts/apps/evince/Makefile
 src/orca/scripts/apps/evolution/Makefile
 src/orca/scripts/apps/gajim/Makefile
 src/orca/scripts/apps/gcalctool/Makefile
diff --git a/src/orca/scripts/apps/Makefile.am b/src/orca/scripts/apps/Makefile.am
index dd6fe1d..0605329 100644
--- a/src/orca/scripts/apps/Makefile.am
+++ b/src/orca/scripts/apps/Makefile.am
@@ -4,6 +4,7 @@ SUBDIRS = \
        Eclipse \
        ekiga \
        empathy \
+       evince \
        evolution \
        gajim \
        gcalctool \
diff --git a/src/orca/scripts/apps/__init__.py b/src/orca/scripts/apps/__init__.py
index 679a25c..34bfc03 100644
--- a/src/orca/scripts/apps/__init__.py
+++ b/src/orca/scripts/apps/__init__.py
@@ -3,6 +3,7 @@ __all__ = ['Banshee',
            'Eclipse',
            'ekiga',
            'empathy',
+           'evince',
            'evolution',
            'gajim',
            'gcalctool',
diff --git a/src/orca/scripts/apps/evince/Makefile.am b/src/orca/scripts/apps/evince/Makefile.am
new file mode 100644
index 0000000..41c13c1
--- /dev/null
+++ b/src/orca/scripts/apps/evince/Makefile.am
@@ -0,0 +1,7 @@
+orca_pathdir=$(pyexecdir)
+
+orca_python_PYTHON = \
+       __init__.py \
+       script.py
+
+orca_pythondir=$(pyexecdir)/orca/scripts/apps/evince
diff --git a/src/orca/scripts/apps/evince/__init__.py b/src/orca/scripts/apps/evince/__init__.py
new file mode 100644
index 0000000..b44e544
--- /dev/null
+++ b/src/orca/scripts/apps/evince/__init__.py
@@ -0,0 +1,23 @@
+# Orca
+#
+# Copyright 2013 The Orca Team.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA  02110-1301 USA.
+
+"""Custom script for evince."""
+
+from .script import Script
+
diff --git a/src/orca/scripts/apps/evince/script.py b/src/orca/scripts/apps/evince/script.py
new file mode 100644
index 0000000..ca103ca
--- /dev/null
+++ b/src/orca/scripts/apps/evince/script.py
@@ -0,0 +1,108 @@
+# Orca
+#
+# Copyright 2013 The Orca Team.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA  02110-1301 USA.
+
+"""Custom script for evince."""
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2013 The Orca Team."
+__license__   = "LGPL"
+
+import pyatspi
+
+import orca.keybindings as keybindings
+import orca.orca_state as orca_state
+import orca.scripts.default as default
+from orca.structural_navigation import StructuralNavigation
+
+########################################################################
+#                                                                      #
+# The evince script class.                                             #
+#                                                                      #
+########################################################################
+
+class Script(default.Script):
+
+    def __init__(self, app):
+        """Creates a new script for the given application.
+
+        Arguments:
+        - app: the application to create a script for.
+        """
+
+        default.Script.__init__(self, app)
+
+    def setupInputEventHandlers(self):
+        """Defines InputEventHandler fields for this script that can be
+        called by the key and braille bindings."""
+
+        default.Script.setupInputEventHandlers(self)
+        self.inputEventHandlers.update(
+            self.structuralNavigation.inputEventHandlers)
+
+    def getAppKeyBindings(self):
+        """Returns the application-specific keybindings for this script."""
+
+        keyBindings = keybindings.KeyBindings()
+        bindings = self.structuralNavigation.keyBindings
+        for keyBinding in bindings.keyBindings:
+            keyBindings.add(keyBinding)
+
+        return keyBindings
+
+    def getStructuralNavigation(self):
+        """Returns the 'structural navigation' class for this script."""
+
+        types = self.getEnabledStructuralNavigationTypes()
+        return StructuralNavigation(self, types, True)
+
+    def getEnabledStructuralNavigationTypes(self):
+        """Returns a list of the structural navigation object types
+        enabled in this script."""
+
+        enabledTypes = [StructuralNavigation.BUTTON,
+                        StructuralNavigation.CHECK_BOX,
+                        StructuralNavigation.COMBO_BOX,
+                        StructuralNavigation.ENTRY,
+                        StructuralNavigation.FORM_FIELD,
+                        StructuralNavigation.HEADING,
+                        StructuralNavigation.LINK,
+                        StructuralNavigation.LIST,
+                        StructuralNavigation.LIST_ITEM,
+                        StructuralNavigation.PARAGRAPH,
+                        StructuralNavigation.RADIO_BUTTON,
+                        StructuralNavigation.TABLE,
+                        StructuralNavigation.TABLE_CELL,
+                        StructuralNavigation.UNVISITED_LINK,
+                        StructuralNavigation.VISITED_LINK]
+
+        return enabledTypes
+
+    def useStructuralNavigationModel(self):
+        """Returns True if we should do our own structural navigation."""
+
+        if not self.structuralNavigation.enabled:
+            return False
+
+        states = orca_state.locusOfFocus.getState()
+        if states.contains(pyatspi.STATE_EDITABLE):
+            return False
+
+        return True
diff --git a/src/orca/structural_navigation.py b/src/orca/structural_navigation.py
index fcc68ca..03cafb6 100644
--- a/src/orca/structural_navigation.py
+++ b/src/orca/structural_navigation.py
@@ -840,6 +840,9 @@ class StructuralNavigation:
 
         wrap = settings.wrappedStructuralNavigation
         document = self._getDocument()
+        if not document:
+            return
+
         collection = document.queryCollection()
         criteria = structuralNavigationObject.criteria(collection, arg)
 
@@ -976,6 +979,10 @@ class StructuralNavigation:
                     break
                 elif wrap:
                     lastObj = self._findLastObject(document)
+                    if self._script.utilities.isSameObject(lastObj, document):
+                        wrapped = True
+                        continue
+
                     # Collection does not do an inclusive search, meaning
                     # that the start object is not part of the search.  So
                     # we need to test the lastobj separately using the given
@@ -1167,6 +1174,10 @@ class StructuralNavigation:
         document = self._script.utilities.ancestorWithRole(
             orca_state.locusOfFocus, docRoles, stopRoles)
 
+        if not document and orca_state.locusOfFocus:
+            if orca_state.locusOfFocus.getRole() in docRoles:
+                return orca_state.locusOfFocus
+
         return document
 
     def _isInDocument(self, obj):


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