Пример #1
0
	def _get_isCurrent(self):
		isCurrent = self.HTMLAttributes["aria-current"]
		try:
			return controlTypes.IsCurrent(isCurrent)
		except ValueError:
			log.debugWarning(f"Unknown aria-current value: {isCurrent}")
			return controlTypes.IsCurrent.NO
Пример #2
0
	def _get_isCurrent(self) -> controlTypes.IsCurrent:
		ia2attrCurrent: str = self.IA2Attributes.get("current", "false")
		try:
			return controlTypes.IsCurrent(ia2attrCurrent)
		except ValueError:
			log.debugWarning(f"Unknown 'current' IA2Attribute value: {ia2attrCurrent}")
			return controlTypes.IsCurrent.NO
Пример #3
0
def _getNormalizedCurrentAttrs(
        attrs: textInfos.ControlField) -> typing.Dict[str, typing.Any]:
    valForCurrent = attrs.get("IAccessible2::attribute_current", "false")
    try:
        isCurrent = controlTypes.IsCurrent(valForCurrent)
    except ValueError:
        log.debugWarning(f"Unknown isCurrent value: {valForCurrent}")
        isCurrent = controlTypes.IsCurrent.NO
    if isCurrent != controlTypes.IsCurrent.NO:
        return {'current': isCurrent}
    return {}
Пример #4
0
 def _getIsCurrentAttribute(self, attrs: dict) -> controlTypes.IsCurrent:
     defaultAriaCurrentStringVal = "false"
     ariaCurrentValue = attrs.get('HTMLAttrib::aria-current',
                                  defaultAriaCurrentStringVal)
     # key 'HTMLAttrib::aria-current' may be in attrs with a value of None
     ariaCurrentValue = defaultAriaCurrentStringVal if ariaCurrentValue is None else ariaCurrentValue
     try:
         ariaCurrent = controlTypes.IsCurrent(ariaCurrentValue)
     except ValueError:
         log.debugWarning(f"Unknown aria-current value: {ariaCurrentValue}")
         ariaCurrent = controlTypes.IsCurrent.NO
     return ariaCurrent
Пример #5
0
 def _get_isCurrent(self) -> controlTypes.IsCurrent:
     ariaProperties = self._getUIACacheablePropertyValue(
         UIAHandler.UIA_AriaPropertiesPropertyId)
     match = self.RE_ARIA_CURRENT_PROP_VALUE.search(ariaProperties)
     if match:
         valueOfAriaCurrent = match.group(1)
         try:
             return controlTypes.IsCurrent(valueOfAriaCurrent)
         except ValueError:
             log.debugWarning(
                 f"Unknown aria-current value: {valueOfAriaCurrent}, ariaProperties: {ariaProperties}"
             )
     return controlTypes.IsCurrent.NO
Пример #6
0
    def _get_isCurrent(self) -> controlTypes.IsCurrent:
        try:
            isCurrent = self.HTMLAttributes["aria-current"]
        except LookupError:
            return controlTypes.IsCurrent.NO

        # key may be in HTMLAttributes with a value of None
        if isCurrent is None:
            return controlTypes.IsCurrent.NO

        try:
            return controlTypes.IsCurrent(isCurrent)
        except ValueError:
            log.debugWarning(f"Unknown aria-current value: {isCurrent}")
            return controlTypes.IsCurrent.NO
Пример #7
0
    def _normalizeControlField(self, attrs):
        level = None

        ariaCurrentValue = attrs.get('HTMLAttrib::aria-current', 'false')
        try:
            ariaCurrent = controlTypes.IsCurrent(ariaCurrentValue)
        except ValueError:
            log.debugWarning(f"Unknown aria-current value: {ariaCurrentValue}")
            ariaCurrent = controlTypes.IsCurrent.NO

        if ariaCurrent != controlTypes.IsCurrent.NO:
            attrs['current'] = ariaCurrent

        placeholder = self._getPlaceholderAttribute(
            attrs, 'HTMLAttrib::aria-placeholder')
        if placeholder:
            attrs['placeholder'] = placeholder
        accRole = attrs.get('IAccessible::role', 0)
        accRole = int(accRole) if isinstance(
            accRole, str) and accRole.isdigit() else accRole
        nodeName = attrs.get('IHTMLDOMNode::nodeName', "")
        roleAttrib = attrs.get("HTMLAttrib::role", "")
        ariaRoles = [ar for ar in roleAttrib.split(" ") if ar]
        #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 role == controlTypes.ROLE_UNKNOWN and nodeName:
            role = NVDAObjects.IAccessible.MSHTML.nodeNamesToNVDARoles.get(
                nodeName, controlTypes.ROLE_UNKNOWN)
        if role == controlTypes.ROLE_UNKNOWN:
            role = IAccessibleHandler.IAccessibleRolesToNVDARoles.get(
                accRole, controlTypes.ROLE_UNKNOWN)
        roleText = attrs.get('HTMLAttrib::aria-roledescription')
        if roleText:
            attrs['roleText'] = roleText
        states = set(IAccessibleHandler.IAccessibleStatesToNVDAStates[x]
                     for x in [1 << y for y in range(32)]
                     if int(attrs.get('IAccessible::state_%s' % x, 0))
                     and x in IAccessibleHandler.IAccessibleStatesToNVDAStates)
        if attrs.get('HTMLAttrib::longdesc'):
            states.add(controlTypes.STATE_HASLONGDESC)
        #IE exposes destination anchors as links, this is wrong
        if nodeName == "A" and role == controlTypes.ROLE_LINK and controlTypes.STATE_LINKED not in states:
            role = controlTypes.ROLE_TEXTFRAME
        if 'IHTMLElement::isContentEditable' in attrs:
            states.add(controlTypes.STATE_EDITABLE)
        if 'HTMLAttrib::onclick' in attrs or 'HTMLAttrib::onmousedown' in attrs or 'HTMLAttrib::onmouseup' in attrs:
            states.add(controlTypes.STATE_CLICKABLE)
        if 'HTMLAttrib::required' in attrs or attrs.get(
                'HTMLAttrib::aria-required', 'false') == 'true':
            states.add(controlTypes.STATE_REQUIRED)
        description = None
        ariaDescribedBy = attrs.get('HTMLAttrib::aria-describedby')
        if ariaDescribedBy:
            ariaDescribedByIds = ariaDescribedBy.split()
            description = ""
            for ariaDescribedById in ariaDescribedByIds:
                descNode = None
                try:
                    descNode = self.obj.rootNVDAObject.HTMLNode.document.getElementById(
                        ariaDescribedById)
                except (COMError, NameError):
                    descNode = None
                if not descNode:
                    try:
                        descNode = NVDAObjects.IAccessible.MSHTML.locateHTMLElementByID(
                            self.obj.rootNVDAObject.HTMLNode.document,
                            ariaDescribedById)
                    except (COMError, NameError):
                        descNode = None
                if descNode:
                    try:
                        description = description + " " + self.obj.makeTextInfo(
                            NVDAObjects.IAccessible.MSHTML.MSHTML(
                                HTMLNode=descNode)).text
                    except:
                        pass
        ariaSort = attrs.get('HTMLAttrib::aria-sort')
        state = aria.ariaSortValuesToNVDAStates.get(ariaSort)
        if state is not None:
            states.add(state)
        ariaSelected = attrs.get('HTMLAttrib::aria-selected')
        if ariaSelected == "true":
            states.add(controlTypes.STATE_SELECTED)
        elif ariaSelected == "false":
            states.discard(controlTypes.STATE_SELECTED)
        ariaExpanded = attrs.get('HTMLAttrib::aria-expanded')
        if ariaExpanded == "true":
            states.add(controlTypes.STATE_EXPANDED)
        elif ariaExpanded == "false":
            states.add(controlTypes.STATE_COLLAPSED)
        if attrs.get('HTMLAttrib::aria-invalid', 'false') == 'true':
            states.add(controlTypes.STATE_INVALID_ENTRY)
        if attrs.get('HTMLAttrib::aria-multiline', 'false') == 'true':
            states.add(controlTypes.STATE_MULTILINE)
        if attrs.get('HTMLAttrib::aria-dropeffect', 'none') != 'none':
            states.add(controlTypes.STATE_DROPTARGET)
        ariaGrabbed = attrs.get('HTMLAttrib::aria-grabbed', None)
        if ariaGrabbed == 'false':
            states.add(controlTypes.STATE_DRAGGABLE)
        elif ariaGrabbed == 'true':
            states.add(controlTypes.STATE_DRAGGING)
        if nodeName == "TEXTAREA":
            states.add(controlTypes.STATE_MULTILINE)
        if "H1" <= nodeName <= "H6":
            level = nodeName[1:]
        if nodeName in ("UL", "OL", "DL"):
            states.add(controlTypes.STATE_READONLY)
        if role == controlTypes.ROLE_UNKNOWN:
            role = controlTypes.ROLE_TEXTFRAME
        if role == controlTypes.ROLE_GRAPHIC:
            # MSHTML puts the unavailable state on all graphics when the showing of graphics is disabled.
            # This is rather annoying and irrelevant to our users, so discard it.
            states.discard(controlTypes.STATE_UNAVAILABLE)
        lRole = aria.htmlNodeNameToAriaRoles.get(nodeName.lower())
        if lRole:
            ariaRoles.append(lRole)
        # If the first role is a landmark role, use it.
        landmark = ariaRoles[
            0] if ariaRoles and ariaRoles[0] in aria.landmarkRoles else None
        ariaLevel = attrs.get('HTMLAttrib::aria-level', None)
        ariaLevel = int(ariaLevel) if ariaLevel is not None else None
        if ariaLevel:
            level = ariaLevel
        if role:
            attrs['role'] = role
        attrs['states'] = states
        if level:
            attrs["level"] = level
        if landmark:
            attrs["landmark"] = landmark
        if description:
            attrs["description"] = description
        return super(MSHTMLTextInfo, self)._normalizeControlField(attrs)
Пример #8
0
	def _normalizeControlField(self,attrs):
		for attr in ("table-rownumber-presentational","table-columnnumber-presentational","table-rowcount-presentational","table-columncount-presentational"):
			attrVal=attrs.get(attr)
			if attrVal is not None:
				attrs[attr]=int(attrVal)

		valForCurrent = attrs.get("IAccessible2::attribute_current", "false")
		try:
			isCurrent = controlTypes.IsCurrent(valForCurrent)
		except ValueError:
			log.debugWarning(f"Unknown isCurrent value: {valForCurrent}")
			isCurrent = controlTypes.IsCurrent.NO
		if isCurrent != controlTypes.IsCurrent.NO:
			attrs['current'] = isCurrent
		placeholder = self._getPlaceholderAttribute(attrs, "IAccessible2::attribute_placeholder")
		if placeholder is not None:
			attrs['placeholder']= placeholder
		accRole=attrs['IAccessible::role']
		accRole=int(accRole) if accRole.isdigit() else accRole
		role=IAccessibleHandler.IAccessibleRolesToNVDARoles.get(accRole,controlTypes.ROLE_UNKNOWN)
		if attrs.get('IAccessible2::attribute_tag',"").lower()=="blockquote":
			role=controlTypes.ROLE_BLOCKQUOTE
		states=set(IAccessibleHandler.IAccessibleStatesToNVDAStates[x] for x in [1<<y for y in range(32)] if int(attrs.get('IAccessible::state_%s'%x,0)) and x in IAccessibleHandler.IAccessibleStatesToNVDAStates)
		states|=set(IAccessibleHandler.IAccessible2StatesToNVDAStates[x] for x in [1<<y for y in range(32)] if int(attrs.get('IAccessible2::state_%s'%x,0)) and x in IAccessibleHandler.IAccessible2StatesToNVDAStates)
		if role == controlTypes.ROLE_EDITABLETEXT and not (controlTypes.STATE_FOCUSABLE in states or controlTypes.STATE_UNAVAILABLE in states or controlTypes.STATE_EDITABLE in states):
			# This is a text leaf.
			# See NVDAObjects.Iaccessible.mozilla.findOverlayClasses for an explanation of these checks.
			role = controlTypes.ROLE_STATICTEXT
		if attrs.get("IAccessibleAction_showlongdesc") is not None:
			states.add(controlTypes.STATE_HASLONGDESC)
		if "IAccessibleAction_click" in attrs:
			states.add(controlTypes.STATE_CLICKABLE)
		grabbed = attrs.get("IAccessible2::attribute_grabbed")
		if grabbed == "false":
			states.add(controlTypes.STATE_DRAGGABLE)
		elif grabbed == "true":
			states.add(controlTypes.STATE_DRAGGING)
		sorted = attrs.get("IAccessible2::attribute_sort")
		if sorted=="ascending":
			states.add(controlTypes.STATE_SORTED_ASCENDING)
		elif sorted=="descending":
			states.add(controlTypes.STATE_SORTED_DESCENDING)
		elif sorted=="other":
			states.add(controlTypes.STATE_SORTED)
		roleText=attrs.get("IAccessible2::attribute_roledescription")
		if roleText:
			attrs['roleText']=roleText
		if attrs.get("IAccessible2::attribute_dropeffect", "none") != "none":
			states.add(controlTypes.STATE_DROPTARGET)
		if role==controlTypes.ROLE_LINK and controlTypes.STATE_LINKED not in states:
			# This is a named link destination, not a link which can be activated. The user doesn't care about these.
			role=controlTypes.ROLE_TEXTFRAME
		level=attrs.get('IAccessible2::attribute_level',"")
		xmlRoles = attrs.get("IAccessible2::attribute_xml-roles", "").split(" ")
		landmark = next((xr for xr in xmlRoles if xr in aria.landmarkRoles), None)
		if landmark and role != controlTypes.ROLE_LANDMARK and landmark != xmlRoles[0]:
			# Ignore the landmark role
			landmark = None
		if role == controlTypes.ROLE_DOCUMENT and xmlRoles[0] == "article":
			role = controlTypes.ROLE_ARTICLE
		elif role == controlTypes.ROLE_GROUPING and xmlRoles[0] == "figure":
			role = controlTypes.ROLE_FIGURE
		elif role in (controlTypes.ROLE_LANDMARK, controlTypes.ROLE_SECTION) and xmlRoles[0] == "region":
			role = controlTypes.ROLE_REGION
		elif xmlRoles[0] == "switch":
			# role="switch" gets mapped to IA2_ROLE_TOGGLE_BUTTON, but it uses the
			# checked state instead of pressed. The simplest way to deal with this
			# identity crisis is to map it to a check box.
			role = controlTypes.ROLE_CHECKBOX
			states.discard(controlTypes.STATE_PRESSED)
		attrs['role']=role
		attrs['states']=states
		if level != "" and level is not None:
			attrs['level']=level
		if landmark:
			attrs["landmark"]=landmark
		return super(Gecko_ia2_TextInfo,self)._normalizeControlField(attrs)