Package NVDAObjects :: Package IAccessible :: Module mozilla
[hide private]
[frames] | no frames]

Source Code for Module NVDAObjects.IAccessible.mozilla

  1  #NVDAObjects/IAccessible/mozilla.py 
  2  #A part of NonVisual Desktop Access (NVDA) 
  3  #This file is covered by the GNU General Public License. 
  4  #See the file COPYING for more details. 
  5  #Copyright (C) 2006-2010 Michael Curran <mick@kulgan.net>, James Teh <jamie@jantrid.net> 
  6   
  7  import IAccessibleHandler 
  8  import oleacc 
  9  import winUser 
 10  from comtypes import IServiceProvider, COMError 
 11  import eventHandler 
 12  import controlTypes 
 13  from . import IAccessible, Dialog 
 14  from logHandler import log 
 15   
16 -class Mozilla(IAccessible):
17 18 IAccessibleTableUsesTableCellIndexAttrib=True 19
21 if not hasattr(self,'IAccessibleTextObject') and self.role==controlTypes.ROLE_EDITABLETEXT and controlTypes.STATE_READONLY in self.states: 22 return True 23 return super(Mozilla,self).beTransparentToMouse
24
25 - def _get_parent(self):
26 #Special code to support Mozilla node_child_of relation (for comboboxes) 27 res=IAccessibleHandler.accNavigate(self.IAccessibleObject,self.IAccessibleChildID,IAccessibleHandler.NAVRELATION_NODE_CHILD_OF) 28 if res and res!=(self.IAccessibleObject,self.IAccessibleChildID): 29 #Gecko can sometimes give back a broken application node with a windowHandle of 0 30 #The application node is annoying, even if it wasn't broken 31 #So only use the node_child_of object if it has a valid IAccessible2 windowHandle 32 try: 33 windowHandle=res[0].windowHandle 34 except (COMError,AttributeError): 35 windowHandle=None 36 if windowHandle: 37 newObj=IAccessible(windowHandle=windowHandle,IAccessibleObject=res[0],IAccessibleChildID=res[1]) 38 if newObj: 39 return newObj 40 return super(Mozilla,self).parent
41
42 - def _get_states(self):
43 states = super(Mozilla, self).states 44 if self.IAccessibleStates & oleacc.STATE_SYSTEM_MARQUEED: 45 states.add(controlTypes.STATE_CHECKABLE) 46 return states
47
48 - def _get_presentationType(self):
49 presType=super(Mozilla,self).presentationType 50 if presType==self.presType_content: 51 if self.role==controlTypes.ROLE_TABLE and self.IA2Attributes.get('layout-guess')=='true': 52 presType=self.presType_layout 53 elif self.table and self.table.presentationType==self.presType_layout: 54 presType=self.presType_layout 55 return presType
56
57 - def _get_positionInfo(self):
58 info=super(Mozilla,self).positionInfo 59 level=info.get('level',None) 60 if not level: 61 level=self.IA2Attributes.get('level',None) 62 if level: 63 info['level']=level 64 return info
65
66 -class Gecko1_9(Mozilla):
67
68 - def _get_description(self):
69 rawDescription=super(Mozilla,self).description 70 if isinstance(rawDescription,basestring) and rawDescription.startswith('Description: '): 71 return rawDescription[13:] 72 else: 73 return ""
74
75 - def event_scrollingStart(self):
76 #Firefox 3.6 fires scrollingStart on leaf nodes which is not useful to us. 77 #Bounce the event up to the node's parent so that any possible virtualBuffers will detect it. 78 if self.role==controlTypes.ROLE_EDITABLETEXT and controlTypes.STATE_READONLY in self.states: 79 eventHandler.queueEvent("scrollingStart",self.parent)
80
81 -class BrokenFocusedState(Mozilla):
82 shouldAllowIAccessibleFocusEvent=True
83
84 -class RootApplication(Mozilla):
85 """Mozilla exposes a root application accessible as the parent of all top level frames. 86 See MozillaBug:555861. 87 This is non-standard; the top level accessible should be the top level window. 88 NVDA expects the standard behaviour, so we never want to see this object. 89 """ 90
91 - def __nonzero__(self):
92 # As far as NVDA is concerned, this is a useless object. 93 return False
94
95 -class Document(Mozilla):
96 97 value=None 98
100 states=self.states 101 ver=_getGeckoVersion(self) 102 if (not ver or ver.startswith('1.9')) and self.windowClassName!="MozillaContentWindowClass": 103 return super(Document,self).treeInterceptorClass 104 if controlTypes.STATE_READONLY in states: 105 import virtualBuffers.gecko_ia2 106 return virtualBuffers.gecko_ia2.Gecko_ia2 107 return super(Document,self).treeInterceptorClass
108
109 -class ListItem(Mozilla):
110
111 - def _get_name(self):
112 name=super(ListItem,self)._get_name() 113 if self.IAccessibleStates&oleacc.STATE_SYSTEM_READONLY: 114 children=super(ListItem,self)._get_children() 115 if len(children)>0 and (children[0].IAccessibleRole in ["bullet",oleacc.ROLE_SYSTEM_STATICTEXT]): 116 name=children[0].value 117 return name
118
119 - def _get_children(self):
120 children=super(ListItem,self)._get_children() 121 if self.IAccessibleStates&oleacc.STATE_SYSTEM_READONLY and len(children)>0 and (children[0].IAccessibleRole in ("bullet",oleacc.ROLE_SYSTEM_STATICTEXT)): 122 del children[0] 123 return children
124
125 -class EmbeddedObject(Mozilla):
126
128 focusWindow = winUser.getGUIThreadInfo(self.windowThreadID).hwndFocus 129 if self.windowHandle != focusWindow: 130 # This window doesn't have the focus, which means the embedded object's window probably already has the focus. 131 # We don't want to override the focus event fired by the embedded object. 132 return False 133 return super(EmbeddedObject, self).shouldAllowIAccessibleFocusEvent
134
135 -def _getGeckoVersion(obj):
136 appMod = obj.appModule 137 try: 138 return appMod._geckoVersion 139 except AttributeError: 140 pass 141 try: 142 ver = obj.IAccessibleObject.QueryInterface(IServiceProvider).QueryService(IAccessibleHandler.IAccessibleApplication._iid_, IAccessibleHandler.IAccessibleApplication).toolkitVersion 143 except COMError: 144 return None 145 appMod._geckoVersion = ver 146 return ver
147
148 -class GeckoPluginWindowRoot(IAccessible):
149
150 - def _get_parent(self):
151 parent=super(GeckoPluginWindowRoot,self).parent 152 ver=_getGeckoVersion(parent) 153 if ver and not ver.startswith('1.'): 154 res=IAccessibleHandler.accNavigate(parent.IAccessibleObject,0,IAccessibleHandler.NAVRELATION_EMBEDS) 155 if res: 156 obj=IAccessible(IAccessibleObject=res[0],IAccessibleChildID=res[1]) 157 if obj and controlTypes.STATE_OFFSCREEN not in obj.states: 158 return obj 159 return parent
160 161
162 -def findExtraOverlayClasses(obj, clsList):
163 """Determine the most appropriate class if this is a Mozilla object. 164 This works similarly to L{NVDAObjects.NVDAObject.findOverlayClasses} except that it never calls any other findOverlayClasses method. 165 """ 166 if not isinstance(obj.IAccessibleObject, IAccessibleHandler.IAccessible2): 167 # We require IAccessible2; i.e. Gecko >= 1.9. 168 return 169 170 iaRole = obj.IAccessibleRole 171 cls = None 172 if iaRole == oleacc.ROLE_SYSTEM_APPLICATION: 173 try: 174 if not obj.IAccessibleObject.windowHandle: 175 cls = RootApplication 176 except COMError: 177 pass 178 if not cls: 179 cls = _IAccessibleRolesToOverlayClasses.get(iaRole) 180 if cls: 181 clsList.append(cls) 182 if iaRole in _IAccessibleRolesWithBrokenFocusedState: 183 clsList.append(BrokenFocusedState) 184 185 ver = _getGeckoVersion(obj) 186 if ver and ver.startswith("1.9"): 187 clsList.append(Gecko1_9) 188 189 clsList.append(Mozilla)
190 191 #: Maps IAccessible roles to NVDAObject overlay classes. 192 _IAccessibleRolesToOverlayClasses = { 193 oleacc.ROLE_SYSTEM_ALERT: Dialog, 194 oleacc.ROLE_SYSTEM_LISTITEM: ListItem, 195 oleacc.ROLE_SYSTEM_DOCUMENT: Document, 196 IAccessibleHandler.IA2_ROLE_EMBEDDED_OBJECT: EmbeddedObject, 197 "embed": EmbeddedObject, 198 "object": EmbeddedObject, 199 } 200 201 #: Roles that mightn't set the focused state when they are focused. 202 _IAccessibleRolesWithBrokenFocusedState = frozenset(( 203 oleacc.ROLE_SYSTEM_COMBOBOX, 204 oleacc.ROLE_SYSTEM_LIST, 205 oleacc.ROLE_SYSTEM_LISTITEM, 206 oleacc.ROLE_SYSTEM_DOCUMENT, 207 oleacc.ROLE_SYSTEM_APPLICATION, 208 oleacc.ROLE_SYSTEM_TABLE, 209 oleacc.ROLE_SYSTEM_OUTLINE, 210 )) 211