Skip to content

Commit 5c330d8

Browse files
authored
Merge 6bf9745 into 8c982cd
2 parents 8c982cd + 6bf9745 commit 5c330d8

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

source/UIAHandler/__init__.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2008-2021 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler
2+
# Copyright (C) 2008-2022 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -99,6 +99,13 @@
9999
"Shell_SystemDialog", # Various dialogs in Windows 10 Settings app
100100
]
101101

102+
textChangeUIAClassNames = (
103+
"_WwG",
104+
"ConsoleWindowClass",
105+
"TermControl",
106+
"TermControl2"
107+
)
108+
102109
NVDAUnitsToUIAUnits: Dict[str, int] = {
103110
textInfos.UNIT_CHARACTER: UIA.TextUnit_Character,
104111
textInfos.UNIT_WORD: UIA.TextUnit_Word,
@@ -206,11 +213,9 @@
206213
autoSelectDetectionAvailable = False
207214
if winVersion.getWinVer() >= winVersion.WIN10:
208215
UIAEventIdsToNVDAEventNames.update({
209-
UIA.UIA_Text_TextChangedEventId: "textChange",
210216
UIA.UIA_Text_TextSelectionChangedEventId: "caret",
211217
})
212218
localEventHandlerGroupUIAEventIds.update({
213-
UIA.UIA_Text_TextChangedEventId,
214219
UIA.UIA_Text_TextSelectionChangedEventId,
215220
})
216221
autoSelectDetectionAvailable = True
@@ -421,21 +426,41 @@ def _registerGlobalEventHandlers(self):
421426
def _createLocalEventHandlerGroup(self):
422427
if isinstance(self.clientObject, UIA.IUIAutomation6):
423428
self.localEventHandlerGroup = self.clientObject.CreateEventHandlerGroup()
429+
self.localEventHandlerGroupWithTextChanges = self.clientObject.CreateEventHandlerGroup()
424430
else:
425431
self.localEventHandlerGroup = utils.FakeEventHandlerGroup(self.clientObject)
432+
self.localEventHandlerGroupWithTextChanges = utils.FakeEventHandlerGroup(self.clientObject)
426433
self.localEventHandlerGroup.AddPropertyChangedEventHandler(
427434
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
428435
self.baseCacheRequest,
429436
self,
430437
*self.clientObject.IntSafeArrayToNativeArray(localEventHandlerGroupUIAPropertyIds)
431438
)
439+
self.localEventHandlerGroupWithTextChanges.AddPropertyChangedEventHandler(
440+
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
441+
self.baseCacheRequest,
442+
self,
443+
*self.clientObject.IntSafeArrayToNativeArray(localEventHandlerGroupUIAPropertyIds)
444+
)
432445
for eventId in localEventHandlerGroupUIAEventIds:
433446
self.localEventHandlerGroup.AddAutomationEventHandler(
434447
eventId,
435448
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
436449
self.baseCacheRequest,
437450
self
438451
)
452+
self.localEventHandlerGroupWithTextChanges.AddAutomationEventHandler(
453+
eventId,
454+
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
455+
self.baseCacheRequest,
456+
self
457+
)
458+
self.localEventHandlerGroupWithTextChanges.AddAutomationEventHandler(
459+
UIA.UIA_Text_TextChangedEventId,
460+
UIA.TreeScope_Ancestors | UIA.TreeScope_Element,
461+
self.baseCacheRequest,
462+
self
463+
)
439464

440465
def addEventHandlerGroup(self, element, eventHandlerGroup):
441466
if isinstance(eventHandlerGroup, UIA.IUIAutomationEventHandlerGroup):
@@ -466,7 +491,12 @@ def func():
466491
if not isStillFocus:
467492
return
468493
try:
469-
self.addEventHandlerGroup(element, self.localEventHandlerGroup)
494+
group = (
495+
self.localEventHandlerGroupWithTextChanges
496+
if element.currentClassName in textChangeUIAClassNames
497+
else self.localEventHandlerGroup
498+
)
499+
self.addEventHandlerGroup(element, group)
470500
except COMError:
471501
log.error("Could not register for UIA events for element", exc_info=True)
472502
else:
@@ -500,7 +530,18 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID):
500530
if _isDebug():
501531
log.debug("HandleAutomationEvent: Ignored MenuOpenedEvent while focus event pending")
502532
return
503-
NVDAEventName=UIAEventIdsToNVDAEventNames.get(eventID,None)
533+
if eventID == UIA.UIA_Text_TextChangedEventId:
534+
if sender.currentClassName in textChangeUIAClassNames:
535+
NVDAEventName = "textChange"
536+
else:
537+
if _isDebug():
538+
log.debugWarning(
539+
"HandleAutomationEvent: Dropping unused textChange event"
540+
+ f" from {sender.currentClassName}" if sender.currentClassName else ""
541+
)
542+
return
543+
else:
544+
NVDAEventName = UIAEventIdsToNVDAEventNames.get(eventID, None)
504545
if not NVDAEventName:
505546
if _isDebug():
506547
log.debugWarning(f"HandleAutomationEvent: Don't know how to handle event {eventID}")

user_docs/en/changes.t2t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ What's New in NVDA
4646
Please refer to [the developer guide https://www.nvaccess.org/files/nvda/documentation/developerGuide.html#API] for information on NVDA's API deprecation and removal process.
4747

4848
- The [NVDA API Announcement mailing list https://groups.google.com/a/nvaccess.org/g/nvda-api/about] was created. (#13999)
49+
- NVDA no longer processes ``textChange`` events for most UI Automation applications due to their extreme negative performance impact. (#11002, #14067)
4950
-
5051

5152

0 commit comments

Comments
 (0)