~mshinke/nvdajp/betterBraille

« back to all changes in this revision

Viewing changes to source/NVDAObjects/IAccessible/adobeAcrobat.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4175.1.10 jpmain)
  • mto: (4175.1.36 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4193.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import api
1
2
import controlTypes
2
3
import eventHandler
3
4
import winUser
43
44
 
44
45
class AcrobatNode(IAccessible):
45
46
 
46
 
        def _get_virtualBufferClass(self):
47
 
                if self.role in (controlTypes.ROLE_DOCUMENT,controlTypes.ROLE_PAGE):
48
 
                        import virtualBuffers.adobeAcrobat
49
 
                        return virtualBuffers.adobeAcrobat.AdobeAcrobat
50
 
                return super(AcrobatNode,self).virtualBufferClass
51
 
 
52
47
        def initOverlayClass(self):
53
48
                try:
54
49
                        serv = self.IAccessibleObject.QueryInterface(IServiceProvider)
56
51
                        log.debugWarning("Could not get IServiceProvider")
57
52
                        return
58
53
 
59
 
                if self.event_objectID is None:
60
 
                        # This object does not have real event parameters.
61
 
                        # Get the real child ID using IAccID.
 
54
                if self.event_objectID > 0:
 
55
                        self.accID = self.event_objectID
 
56
                elif self.event_childID > 0:
 
57
                        self.accID = self.event_childID
 
58
                else:
62
59
                        try:
63
 
                                self.event_childID = serv.QueryService(SID_AccID, IAccID).get_accID()
 
60
                                self.accID = serv.QueryService(SID_AccID, IAccID).get_accID()
64
61
                        except COMError:
65
62
                                log.debugWarning("Failed to get ID from IAccID", exc_info=True)
 
63
                                self.accID = None
66
64
 
67
65
                # Get the IPDDomNode.
68
66
                try:
78
76
                        except COMError:
79
77
                                pass
80
78
 
81
 
        def _get_shouldAllowIAccessibleFocusEvent(self):
82
 
                #Acrobat document root objects do not have their focused state set when they have the focus.
83
 
                if self.event_childID==0:
84
 
                        return True
85
 
                return super(AcrobatNode,self).shouldAllowIAccessibleFocusEvent
86
 
 
87
79
        def _get_role(self):
88
80
                try:
89
81
                        return normalizeStdName(self.pdDomNode.GetStdName())[0]
96
88
                        role = controlTypes.ROLE_TEXTFRAME
97
89
                return role
98
90
 
99
 
        def event_valueChange(self):
100
 
                if self.event_childID==0 and self.event_objectID == winUser.OBJID_CLIENT and winUser.isDescendantWindow(winUser.getForegroundWindow(),self.windowHandle):
101
 
                        # Acrobat has indicated that a page has died and been replaced by a new one.
102
 
                        # The new page has the same event params, so we must bypass NVDA's IAccessible caching.
103
 
                        obj = getNVDAObjectFromEvent(self.windowHandle, -4, 0)
104
 
                        if not obj:
105
 
                                return
106
 
                        eventHandler.queueEvent("gainFocus",obj)
107
 
 
108
91
        def scrollIntoView(self):
109
92
                try:
110
93
                        self.pdDomNode.ScrollTo()
111
94
                except (AttributeError, COMError):
112
95
                        log.debugWarning("IPDDomNode::ScrollTo failed", exc_info=True)
113
96
 
 
97
        def _isEqual(self, other):
 
98
                if self.windowHandle == other.windowHandle and self.accID and other.accID:
 
99
                        return self.accID == other.accID
 
100
                return super(AcrobatNode, self)._isEqual(other)
 
101
 
 
102
class RootNode(AcrobatNode):
 
103
        shouldAllowIAccessibleFocusEvent = True
 
104
 
 
105
        def event_valueChange(self):
 
106
                # Acrobat has indicated that a page has died and been replaced by a new one.
 
107
                if not self.isInForeground:
 
108
                        # If this isn't in the foreground, it doesn't matter,
 
109
                        # as focus will be fired on the correct object when it is in the foreground again.
 
110
                        return
 
111
                # The new page has the same event params, so we must bypass NVDA's IAccessible caching.
 
112
                obj = getNVDAObjectFromEvent(self.windowHandle, winUser.OBJID_CLIENT, 0)
 
113
                if not obj:
 
114
                        return
 
115
                eventHandler.queueEvent("gainFocus",obj)
 
116
 
 
117
class Document(RootNode):
 
118
 
 
119
        def _get_treeInterceptorClass(self):
 
120
                import virtualBuffers.adobeAcrobat
 
121
                return virtualBuffers.adobeAcrobat.AdobeAcrobat
 
122
 
 
123
        def _get_shouldAllowIAccessibleFocusEvent(self):
 
124
                # HACK: #1659: When moving the focus, Acrobat sometimes fires focus on the document before firing it on the real focus;
 
125
                # e.g. when tabbing through a multi-page form.
 
126
                # This causes extraneous verbosity.
 
127
                # Therefore, if already focused inside this document, only allow focus on the document if it has no active descendant.
 
128
                if api.getFocusObject().windowHandle == self.windowHandle:
 
129
                        try:
 
130
                                return self.IAccessibleObject.accFocus in (None, 0)
 
131
                        except COMError:
 
132
                                pass
 
133
                return super(Document, self).shouldAllowIAccessibleFocusEvent
 
134
 
 
135
class RootTextNode(RootNode):
 
136
        """The message text node that appears instead of the document when the document is not available.
 
137
        """
 
138
 
 
139
        def _get_parent(self):
 
140
                #hack: This code should be taken out once the crash is fixed in Adobe Reader X.
 
141
                #If going parent on a root text node after saying ok to the accessibility options (untagged) and before the processing document dialog appears, Reader X will crash.
 
142
                return api.getDesktopObject()
 
143
 
114
144
class AcrobatTextInfo(NVDAObjectTextInfo):
115
145
 
116
146
        def _getStoryText(self):
125
155
                except (ValueError, TypeError):
126
156
                        raise RuntimeError("Bad caret index")
127
157
 
128
 
class AcrobatTextNode(EditableText, AcrobatNode):
 
158
class EditableTextNode(EditableText, AcrobatNode):
129
159
        TextInfo = AcrobatTextInfo
130
160
 
 
161
        def event_valueChange(self):
 
162
                pass
 
163
 
131
164
class AcrobatSDIWindowClient(IAccessible):
132
165
 
133
166
        def __init__(self, **kwargs):
138
171
                        # The unnamed object's parent is the named object, but when descending into the named object, the unnamed object is skipped.
139
172
                        # Given the brokenness of the unnamed object, just skip it completely and use the parent when it is encountered.
140
173
                        self.IAccessibleObject = self.IAccessibleObject.accParent
 
174
 
 
175
def findExtraOverlayClasses(obj, clsList):
 
176
        """Determine the most appropriate class(es) for Acrobat objects.
 
177
        This works similarly to L{NVDAObjects.NVDAObject.findOverlayClasses} except that it never calls any other findOverlayClasses method.
 
178
        """
 
179
        role = obj.role
 
180
        if obj.event_childID == 0 and obj.event_objectID == winUser.OBJID_CLIENT:
 
181
                # Root node.
 
182
                if role in (controlTypes.ROLE_DOCUMENT,controlTypes.ROLE_PAGE):
 
183
                        clsList.append(Document)
 
184
                elif role == controlTypes.ROLE_EDITABLETEXT:
 
185
                        clsList.append(RootTextNode)
 
186
                else:
 
187
                        clsList.append(RootNode)
 
188
 
 
189
        elif role == controlTypes.ROLE_EDITABLETEXT and controlTypes.STATE_FOCUSABLE in obj.states:
 
190
                clsList.append(EditableTextNode)
 
191
 
 
192
        clsList.append(AcrobatNode)