OSDN Git Service

Edit NVDAObject: when fetching the label for an embedded object and display model...
authorMichael Curran <mick@nvaccess.org>
Fri, 12 Jul 2013 00:30:27 +0000 (10:30 +1000)
committerMichael Curran <mick@nvaccess.org>
Thu, 25 Jul 2013 02:32:56 +0000 (12:32 +1000)
 If the left coordiante seems to be equal or past the right coordinate, then this is wrong and we can collapse the range and try again.

 Also added more comments to remind us in what situations this code is used.

source/NVDAObjects/window/edit.py

index d3e3495..2cc9000 100644 (file)
@@ -34,6 +34,8 @@ import watchdog
 \r
 selOffsetsAtLastCaretEvent=None\r
 \r
+TA_BOTTOM=8\r
+\r
 #Edit control window messages\r
 EM_GETSEL=176\r
 EM_SETSEL=177\r
@@ -557,6 +559,7 @@ class ITextDocumentTextInfo(textInfos.TextInfo):
                        o=None\r
                if not o:\r
                        return None\r
+               # Outlook >=2007 exposes MSAA on its embedded objects thus we can use accName as the label\r
                import oleacc\r
                try:\r
                        label=o.QueryInterface(oleacc.IAccessible).accName(0);\r
@@ -564,12 +567,20 @@ class ITextDocumentTextInfo(textInfos.TextInfo):
                        pass\r
                if label:\r
                        return label\r
+               # Outlook 2003 and Outlook Express write the embedded object text to the display with GDI thus we can use display model \r
                left,top=embedRangeObj.GetPoint(comInterfaces.tom.tomStart)\r
-               right,bottom=embedRangeObj.GetPoint(comInterfaces.tom.tomEnd)\r
+               right,bottom=embedRangeObj.GetPoint(comInterfaces.tom.tomEnd|TA_BOTTOM)\r
+               # Outlook Express bug: when expanding to the first embedded object on lines after the first, the range's start coordinates are the start coordinates of the previous character (on the line above)\r
+               # Therefore if we detect this, collapse the range and try getting left and top again\r
+               if left>=right:\r
+                       r=embedRangeObj.duplicate\r
+                       r.collapse(1)\r
+                       left,top=r.GetPoint(comInterfaces.tom.tomStart)\r
                import displayModel\r
-               label=displayModel.DisplayModelTextInfo(self.obj, textInfos.Rect(left, top, right, bottom+10)).text\r
+               label=displayModel.DisplayModelTextInfo(self.obj, textInfos.Rect(left, top, right, bottom)).text\r
                if label and not label.isspace():\r
                        return label\r
+               # Windows Live Mail exposes the label via the embedded object's data (IDataObject)\r
                try:\r
                        dataObj=o.QueryInterface(oleTypes.IDataObject)\r
                except comtypes.COMError:\r
@@ -586,6 +597,7 @@ class ITextDocumentTextInfo(textInfos.TextInfo):
                                pass\r
                if label:\r
                        return label\r
+               # As a final fallback (e.g. could not get display  model text for Outlook Express), use the embedded object's user type (e.g. "recipient").\r
                try:\r
                        oleObj=o.QueryInterface(oleTypes.IOleObject)\r
                        label=oleObj.GetUserType(1)\r