#virtualBuffers/MSHTML.py
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2009-2012 NV Access Limited
from comtypes import COMError
import eventHandler
from . import VirtualBuffer, VirtualBufferTextInfo, VBufStorage_findMatch_word, VBufStorage_findMatch_notEmpty
import controlTypes
import NVDAObjects.IAccessible.MSHTML
import winUser
import NVDAHelper
import ctypes
import IAccessibleHandler
import languageHandler
import oleacc
from logHandler import log
import textInfos
import api
import aria
import config
import watchdog
FORMATSTATE_INSERTED=1
FORMATSTATE_DELETED=2
FORMATSTATE_MARKED=4
FORMATSTATE_STRONG=8
FORMATSTATE_EMPH=16
class MSHTMLTextInfo(VirtualBufferTextInfo):
def _normalizeFormatField(self, attrs):
formatState=attrs.get('formatState',"0")
formatState=int(formatState)
if formatState&FORMATSTATE_INSERTED:
attrs['revision-insertion']=True
if formatState&FORMATSTATE_DELETED:
attrs['revision-deletion']=True
if formatState&FORMATSTATE_MARKED:
attrs['marked']=True
if formatState&FORMATSTATE_STRONG:
attrs['strong']=True
if formatState&FORMATSTATE_EMPH:
attrs['emphasised']=True
language=attrs.get('language')
if language:
attrs['language']=languageHandler.normalizeLanguage(language)
return attrs
def _normalizeControlField(self,attrs):
level=None
accRole=attrs.get('IAccessible::role',0)
accRole=int(accRole) if isinstance(accRole,basestring) and accRole.isdigit() else accRole
nodeName=attrs.get('IHTMLDOMNode::nodeName',"")
ariaRoles=attrs.get("HTMLAttrib::role", "").split(" ")
#choose role
#Priority is aria role -> HTML tag name -> IAccessible role
role=next((aria.ariaRolesToNVDARoles[ar] for ar in ariaRoles if ar in aria.ariaRolesToNVDARoles),controlTypes.ROLE_UNKNOWN)
if not role and nodeName:
role=NVDAObjects.IAccessible.MSHTML.nodeNamesToNVDARoles.get(nodeName,controlTypes.ROLE_UNKNOWN)
if not role:
role=IAccessibleHandler.IAccessibleRolesToNVDARoles.get(accRole,controlTypes.ROLE_UNKNOWN)
states=set(IAccessibleHandler.IAccessibleStatesToNVDAStates[x] for x in [1<