From 658c374819fe515d3cad9930eb0250c2f63a111a Mon Sep 17 00:00:00 2001 From: Reef Turner Date: Wed, 3 Nov 2021 19:49:54 +0800 Subject: [PATCH 1/2] Relations constants Compat breaking refactor: - Removed IA2_RELATION_FLOWS_FROM - Removed IA2_RELATION_FLOWS_TO - Removed IA2_RELATION_CONTAINING_DOCUMENT - Replaced with IAccessibleHandler.RelationType enum --- source/IAccessibleHandler/__init__.py | 7 ++++--- source/IAccessibleHandler/types.py | 12 +++++++++++- source/NVDAObjects/IAccessible/__init__.py | 14 ++++++++++---- source/virtualBuffers/gecko_ia2.py | 9 +++++---- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/source/IAccessibleHandler/__init__.py b/source/IAccessibleHandler/__init__.py index 15993690fd0..31863eb1124 100644 --- a/source/IAccessibleHandler/__init__.py +++ b/source/IAccessibleHandler/__init__.py @@ -3,6 +3,10 @@ # This file is covered by the GNU General Public License. # See the file COPYING for more details. +# F401 imported but unused. RelationType should be exposed from IAccessibleHandler, in future __all__ +# should be used to export it. +from .types import RelationType # noqa: F401 + import re import struct from typing import Optional, Tuple @@ -52,9 +56,6 @@ NAVRELATION_NODE_CHILD_OF = 0x1005 NAVRELATION_EMBEDS = 0x1009 -# IAccessible2 relations (not included in the typelib) -IA2_RELATION_FLOWS_FROM = "flowsFrom" -IA2_RELATION_FLOWS_TO = "flowsTo" # A place to store live IAccessible NVDAObjects, that can be looked up by their window,objectID, # childID event params. diff --git a/source/IAccessibleHandler/types.py b/source/IAccessibleHandler/types.py index 29e50268fe5..5c532f1eb1e 100644 --- a/source/IAccessibleHandler/types.py +++ b/source/IAccessibleHandler/types.py @@ -7,7 +7,7 @@ """Types used in IAccessibleHander. Kept here so they can be re-used without having to worry about circular imports. """ - +import enum from typing import Tuple IAccessibleObjectIdentifierType = Tuple[ @@ -15,3 +15,13 @@ int, # objectID int, # childID ] + + +# IAccessible2 relations (not included in the typelib) +@enum.unique +class RelationType(enum.Enum): + FLOWS_FROM = "flowsFrom" + FLOWS_TO = "flowsTo" + CONTAINING_DOCUMENT = "containingDocument" + DETAILS = "details" + DETAILS_FOR = "detailsFor" diff --git a/source/NVDAObjects/IAccessible/__init__.py b/source/NVDAObjects/IAccessible/__init__.py index 1e7ead4ffc8..67d268a7d7c 100644 --- a/source/NVDAObjects/IAccessible/__init__.py +++ b/source/NVDAObjects/IAccessible/__init__.py @@ -1470,11 +1470,17 @@ def _getIA2RelationFirstTarget(self, relationType): pass return None - def _get_flowsTo(self): - return self._getIA2RelationFirstTarget(IAccessibleHandler.IA2_RELATION_FLOWS_TO) + #: Type definition for auto prop '_get_flowsTo' + flowsTo: typing.Optional["IAccessible"] - def _get_flowsFrom(self): - return self._getIA2RelationFirstTarget(IAccessibleHandler.IA2_RELATION_FLOWS_FROM) + def _get_flowsTo(self) -> typing.Optional["IAccessible"]: + return self._getIA2RelationFirstTarget(IAccessibleHandler.RelationType.FLOWS_TO) + + #: Type definition for auto prop '_get_flowsFrom' + flowsFrom: typing.Optional["IAccessible"] + + def _get_flowsFrom(self) -> typing.Optional["IAccessible"]: + return self._getIA2RelationFirstTarget(IAccessibleHandler.RelationType.FLOWS_FROM) def event_valueChange(self): if isinstance(self, EditableTextWithAutoSelectDetection): diff --git a/source/virtualBuffers/gecko_ia2.py b/source/virtualBuffers/gecko_ia2.py index 0da6682ae9b..d157328c855 100755 --- a/source/virtualBuffers/gecko_ia2.py +++ b/source/virtualBuffers/gecko_ia2.py @@ -13,6 +13,7 @@ import winUser import mouseHandler import IAccessibleHandler + import oleacc from logHandler import log import textInfos @@ -23,9 +24,6 @@ import config from NVDAObjects.IAccessible import normalizeIA2TextFormatField, IA2TextTextInfo -IA2_RELATION_CONTAINING_DOCUMENT = "containingDocument" - - def _getNormalizedCurrentAttrs(attrs: textInfos.ControlField) -> typing.Dict[str, typing.Any]: valForCurrent = attrs.get("IAccessible2::attribute_current", "false") try: @@ -193,7 +191,10 @@ def _getEmbedderFrame(acc): # IAccessible NVDAObjects currently fetch IA2, but we need IA2_2 for relationTargetsOfType. # (Out-of-process, for a single relation, this is cheaper than IA2::relations.) acc = acc.QueryInterface(IA2.IAccessible2_2) - targets, count = acc.relationTargetsOfType(IA2_RELATION_CONTAINING_DOCUMENT, 1) + targets, count = acc.relationTargetsOfType( + IAccessibleHandler.RelationType.CONTAINING_DOCUMENT, + 1 # max relations to fetch + ) if count == 0: return None doc = targets[0].QueryInterface(IA2.IAccessible2_2) From 559acfc7bcdaa409e27fa537b0dc17535360d619 Mon Sep 17 00:00:00 2001 From: Reef Turner Date: Tue, 30 Nov 2021 14:06:43 +0800 Subject: [PATCH 2/2] update changes file for PR #13096 --- user_docs/en/changes.t2t | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index ebbf7bdf0ca..3a985e9268e 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -78,6 +78,11 @@ This ensures code will honor the Windows user setting for swapping the primary m - ``_UIAConstants`` is now ``UIAHandler.constants`` - ``_UIACustomProps`` is now ``UIAHandler.customProps`` - ``_UIACustomAnnotations`` is now ``UIAHandler.customAnnotations`` +- The ``IAccessibleHandler`` ``IA2_RELATION_*`` constants have been replaced with the ``IAccessibleHandler.RelationType`` enum. (#13096) + - Removed ``IA2_RELATION_FLOWS_FROM`` + - Removed ``IA2_RELATION_FLOWS_TO`` + - Removed ``IA2_RELATION_CONTAINING_DOCUMENT`` + - -