[orca] Fix for bug 585871.



commit 2a0177f1985cecd39c1c93e7f2abcb3a5a4f5818
Author: Joanmarie Diggs <joanmarie diggs gmail com>
Date:   Sat Jun 20 18:08:46 2009 -0400

    Fix for bug 585871.
    
    This fix moves some of the handling of embedded object characters
    from the Gecko script to default.py. This change helps with solving
    the immediate problem of bug 585871 (WhereAmI info in FF doesn't
    include link text). It presumably will also come in handy as we begin
    to deal with the presence of embedded object characters in other apps,
    such as OOo Writer documents (e.g. forms) and potentially WebKit.

 src/orca/default.py                       |   79 +++++++++++++++++++++++++++++
 src/orca/scripts/toolkits/Gecko/script.py |   65 -----------------------
 src/orca/speech_generator.py              |   12 ++++
 3 files changed, 91 insertions(+), 65 deletions(-)
---
diff --git a/src/orca/default.py b/src/orca/default.py
index 736ab12..e6efbd3 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -6591,6 +6591,85 @@ class Script(script.Script):
 
         return newLine.encode("UTF-8")
 
+    def getCharacterOffsetInParent(self, obj):
+        """Returns the character offset of the embedded object
+        character for this object in its parent's accessible text.
+
+        Arguments:
+        - obj: an Accessible that should implement the accessible hyperlink
+               specialization.
+
+        Returns an integer representing the character offset of the
+        embedded object character for this hyperlink in its parent's
+        accessible text, or -1 something was amuck.
+        """
+
+        try:
+            hyperlink = obj.queryHyperlink()
+        except NotImplementedError:
+            offset = -1
+        else:
+            # We need to make sure that this is an embedded object in
+            # some accessible text (as opposed to an imagemap link).
+            #
+            try:
+                obj.parent.queryText()
+            except NotImplementedError:
+                offset = -1
+            else:
+                offset = hyperlink.startIndex
+
+        return offset
+
+    def expandEOCs(self, obj, startOffset=0, endOffset=-1):
+        """Expands the current object replacing EMBEDDED_OBJECT_CHARACTERS
+        with their text.
+
+        Arguments
+        - obj: the object whose text should be expanded
+        - startOffset: the offset of the first character to be included
+        - endOffset: the offset of the last character to be included
+
+        Returns the fully expanded text for the object.
+        """
+
+        if not obj:
+            return None
+
+        string = None
+        try:
+            text = obj.queryText()
+        except:
+            text = None
+
+        if text and text.characterCount:
+            string = text.getText(startOffset, endOffset)
+            unicodeText = string.decode("UTF-8")
+            if unicodeText \
+                and self.EMBEDDED_OBJECT_CHARACTER in unicodeText:
+                # If we're not getting the full text of this object, but
+                # rather a substring, we need to figure out the offset of
+                # the first child within this substring.
+                #
+                childOffset = 0
+                for child in obj:
+                    if self.getCharacterOffsetInParent(child) >= startOffset:
+                        break
+                    childOffset += 1
+
+                toBuild = list(unicodeText)
+                count = toBuild.count(self.EMBEDDED_OBJECT_CHARACTER)
+                for i in xrange(count):
+                    index = toBuild.index(self.EMBEDDED_OBJECT_CHARACTER)
+                    child = obj[i + childOffset]
+                    childText = self.expandEOCs(child)
+                    if not childText:
+                        childText = ""
+                    toBuild[index] = childText.decode("UTF-8")
+                string = "".join(toBuild)
+
+        return string
+
     def _getPronunciationForSegment(self, segment):
         """Adjust the word segment to potentially replace it with what
         those words actually sound like. Two pronunciation dictionaries
diff --git a/src/orca/scripts/toolkits/Gecko/script.py b/src/orca/scripts/toolkits/Gecko/script.py
index c204de9..d4d4501 100644
--- a/src/orca/scripts/toolkits/Gecko/script.py
+++ b/src/orca/scripts/toolkits/Gecko/script.py
@@ -3097,36 +3097,6 @@ class Script(default.Script):
         else:
             return False
 
-    def getCharacterOffsetInParent(self, obj):
-        """Returns the character offset of the embedded object
-        character for this object in its parent's accessible text.
-
-        Arguments:
-        - obj: an Accessible that should implement the accessible hyperlink
-               specialization.
-
-        Returns an integer representing the character offset of the
-        embedded object character for this hyperlink in its parent's
-        accessible text, or -1 something was amuck.
-        """
-
-        try:
-            hyperlink = obj.queryHyperlink()
-        except NotImplementedError:
-            offset = -1
-        else:
-            # We need to make sure that this is an embedded object in
-            # some accessible text (as opposed to an imagemap link).
-            #
-            try:
-                obj.parent.queryText()
-            except NotImplementedError:
-                offset = -1
-            else:
-                offset = hyperlink.startIndex
-
-        return offset
-
     def getChildIndex(self, obj, characterOffset):
         """Given an object that implements accessible text, determine
         the index of the child that is represented by an
@@ -3740,41 +3710,6 @@ class Script(default.Script):
 
         return [newCell, text, extents, isField]
 
-    def expandEOCs(self, obj, startOffset=0, endOffset= -1):
-        """Expands the current object replacing EMBEDDED_OBJECT_CHARACTERS
-        with their text.
-
-        Arguments
-        - obj: the object whose text should be expanded
-        - startOffset: the offset of the first character to be included
-        - endOffset: the offset of the last character to be included
-
-        Returns the fully expanded text for the object.
-        """
-
-        if not obj:
-            return None
-
-        string = None
-        text = self.queryNonEmptyText(obj)
-        if text:
-            string = text.getText(startOffset, endOffset)
-            unicodeText = string.decode("UTF-8")
-            if unicodeText \
-                and self.EMBEDDED_OBJECT_CHARACTER in unicodeText:
-                toBuild = list(unicodeText)
-                count = toBuild.count(self.EMBEDDED_OBJECT_CHARACTER)
-                for i in xrange(count):
-                    index = toBuild.index(self.EMBEDDED_OBJECT_CHARACTER)
-                    child = obj[i]
-                    childText = self.expandEOCs(child)
-                    if not childText:
-                        childText = ""
-                    toBuild[index] = childText.decode("UTF-8")
-                string = "".join(toBuild)
-
-        return string
-
     def getObjectsFromEOCs(self, obj, offset, boundary=None):
         """Expands the current object replacing EMBEDDED_OBJECT_CHARACTERS
         with [obj, startOffset, endOffset, string] tuples.
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index dba22db..ac48a0c 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -1343,6 +1343,18 @@ class SpeechGenerator:
                 textObj.caretOffset,
                 pyatspi.TEXT_BOUNDARY_LINE_START)
             if len(line):
+                # Check for embedded object characters. If we find any,
+                # expand the text. TODO - JD: This expansion doesn't 
+                # include the role information; just the text. However,
+                # the handling of roles should probably be dealt with as
+                # a formatting string. We have not yet worked out how to
+                # do this with Gecko (primary user of embedded object
+                # characters). Until we do, this expansion is better than
+                # presenting the actual embedded object character.
+                #
+                unicodeText = line.decode("UTF-8")
+                if self._script.EMBEDDED_OBJECT_CHARACTER in unicodeText:
+                    line = self._script.expandEOCs(obj, startOffset, endOffset)
                 line = self._script.adjustForRepeats(line)
                 textContents = line
             else:



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