forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support UI Automation custom annotations such as notes in MS Excel (n…
…vaccess#12861) The Microsoft UI Automation accessibility API has a concept of annotations, which are essentially a way of attaching extra meta information (or annotations) to content. E.g. comments. An annotation is made up of both a known type ID E.g. AnnotationType_Comment, and an object (an extra UI automation element containing properties such as the author, date etc). NVDA already supports standard UI Automation annotations. In Windows 11, UI Automation has been extended to support custom annotations. these are annotations with an application-defined type ID. E.g. an Excel note, or an MS word bookmark. In order for these type IDs to be agreed upon by both the application and assistive technology at runtime, a mechanism very similar to UI Automation custom property registration was introduced to UI automation for registering custom annotation types, exposed via the Windows.UI.UIAutomation.Core.CoreAutomationRegistrar winRT interface. Description of how this pull request fixes the issue: • implemented a new registerUIAAnnotationType function in nvdaHelperLocal that uses the Windows.UI.UIAutomation.Core.CoreAutomationRegistrar winRT interface to register an annotation type GUID, resulting in a new annotation type ID that can be used like any other standard UI automation annotation type ID. • Implemented infrastructure in NVDA to aide in registering UI Automation annotation types, pretty much identical to the UI Automation custom property registration infrastructure. • Added support for detecting notes in MS Excel, which are exposed as a custom annotation on cells. • Added support for detecting bookmarks in Microsoft Word documents in both speech and braille. • Added support for detecting draft comments and resolved comments in Microsoft Word in both speech and braille.
- Loading branch information
1 parent
0c09fff
commit 4778752
Showing
16 changed files
with
259 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#ifndef NVDAHELPERLOCAL_UIAUTILS_H | ||
#define NVDAHELPERLOCAL_UIAUTILS_H | ||
|
||
// The following header included to allow winrt::guid to be converted to GUID | ||
#include <unknwn.h> | ||
|
||
#include <winrt/windows.ui.uiautomation.core.h> | ||
#include <uiAutomationCore.h> | ||
|
||
PROPERTYID registerUIAProperty(GUID* guid, LPCWSTR programmaticName, UIAutomationType propertyType); | ||
int registerUIAAnnotationType(GUID* guid); | ||
|
||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# A part of NonVisual Desktop Access (NVDA) | ||
# Copyright (C) 2021 NV Access Limited | ||
# This file is covered by the GNU General Public License. | ||
# See the file COPYING for more details. | ||
|
||
from dataclasses import ( | ||
dataclass, | ||
field, | ||
) | ||
from typing import Optional | ||
|
||
from comtypes import ( | ||
GUID, | ||
byref, | ||
) | ||
import winVersion | ||
|
||
|
||
""" | ||
This module provides helpers and a common format to define UIA custom annotation types. | ||
The common custom annotation types are defined here. | ||
Custom annotation types specific to an application should be defined within a NVDAObjects/UIA | ||
submodule specific to that application, E.G. 'NVDAObjects/UIA/excel.py' | ||
UIA originally had hard coded 'static' ID's for annotation types. | ||
For an example see 'AnnotationType_SpellingError' in | ||
`source/comInterfaces/_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py` | ||
imported via `UIAutomationClient.py`. | ||
When a new annotation type was added the UIA spec had to be updated. | ||
Now a mechanism is in place to allow applications to register "custom annotation types". | ||
This relies on both the UIA server application and the UIA client application sharing a known | ||
GUID for the annotation type. | ||
""" | ||
|
||
|
||
@dataclass | ||
class CustomAnnotationTypeInfo: | ||
"""Holds information about a CustomAnnotationType | ||
This makes it easy to define custom annotation types to be loaded. | ||
""" | ||
guid: GUID | ||
id: int = field(init=False) | ||
|
||
def __post_init__(self) -> None: | ||
""" The id field must be initialised at runtime. | ||
A GUID uniquely identifies a custom annotation, but the UIA system relies on integer IDs. | ||
Any application (clients or providers) can register a custom annotation type, subsequent applications | ||
will get the same id for a given GUID. | ||
Registering custom annotations is only supported on Windows 11 and above. | ||
For any lesser version, id will be 0. | ||
""" | ||
if winVersion.getWinVer() >= winVersion.WIN11: | ||
import NVDAHelper | ||
self.id = NVDAHelper.localLib.registerUIAAnnotationType( | ||
byref(self.guid), | ||
) | ||
else: | ||
self.id = 0 | ||
|
||
|
||
class CustomAnnotationTypesCommon: | ||
"""UIA 'custom annotation types' common to all applications. | ||
Once registered, all subsequent registrations will return the same ID value. | ||
This class should be used as a singleton via CustomAnnotationTypesCommon.get() | ||
to prevent unnecessary work by repeatedly interacting with UIA. | ||
""" | ||
#: Singleton instance | ||
_instance: "Optional[CustomAnnotationTypesCommon]" = None | ||
|
||
@classmethod | ||
def get(cls) -> "CustomAnnotationTypesCommon": | ||
"""Get the singleton instance or initialise it. | ||
""" | ||
if cls._instance is None: | ||
cls._instance = cls() | ||
return cls._instance | ||
|
||
def __init__(self): | ||
# Registration of Custom annotation types used across multiple applications or frameworks should go here. | ||
self.microsoftWord_resolvedComment = CustomAnnotationTypeInfo( | ||
guid=GUID("{A015030C-5B44-4EAC-B0CC-21BA35DE6D07}"), | ||
) | ||
self.microsoftWord_draftComment = CustomAnnotationTypeInfo( | ||
guid=GUID("{26BAEBC6-591E-4116-BBCF-E9A7996CD169}"), | ||
) | ||
self.microsoftWord_bookmark = CustomAnnotationTypeInfo( | ||
guid=GUID("{25330951-A372-4DB9-A88A-85137AD008D2}"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.