Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Automation in Windows Console: disable some GetVisibleRanges dependent logic when consoles are maximized #9899

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ def _get_UIATextEditPattern(self):
self.UIATextEditPattern=self._getUIAPattern(UIAHandler.UIA_TextEditPatternId,UIAHandler.IUIAutomationTextEditPattern,cache=False)
return self.UIATextEditPattern

def _get_UIAWindowPattern(self):
self.UIAWindowPattern=self._getUIAPattern(UIAHandler.UIA_WindowPatternId,UIAHandler.IUIAutomationWindowPattern)
return self.UIAWindowPattern

def _get_UIALegacyIAccessiblePattern(self):
self.UIALegacyIAccessiblePattern=self._getUIAPattern(UIAHandler.UIA_LegacyIAccessiblePatternId,UIAHandler.IUIAutomationLegacyIAccessiblePattern)
return self.UIALegacyIAccessiblePattern
Expand Down
23 changes: 22 additions & 1 deletion source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import config
import ctypes
import globalVars
import NVDAHelper
import speech
import time
Expand Down Expand Up @@ -112,7 +113,7 @@ def move(self, unit, direction, endPoint=None):
self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, firstVisiRange,
UIAHandler.TextPatternRangeEndpoint_Start) < 0
or self._rangeObj.CompareEndPoints(
or not self.obj.maximized and self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange,
UIAHandler.TextPatternRangeEndpoint_End) >= 0):
self._rangeObj = oldRange
Expand Down Expand Up @@ -290,8 +291,28 @@ def script_flush_queuedChars(self, gesture):
self._queuedChars = []
speech.curWordChars = []

def _get_maximized(self):
res = self.UIAElement.getRuntimeId() in globalVars.maximizedUIAConsoles
if (
self.parent.UIAWindowPattern.CurrentWindowVisualState
== UIAHandler.WindowVisualState_Maximized
and not res
):
globalVars.maximizedUIAConsoles.append(self.UIAElement.getRuntimeId())
return True
return res

def _getTextLines(self):
# Filter out extraneous empty lines from UIA
# Since GetVisibleRanges seems to be broken for at least Win10 1903
# we can only do this if the window isn't maximized.
if self.maximized:
return (
self.makeTextInfo(textInfos.POSITION_ALL)
._rangeObj.getText(-1)
.strip()
.split("\r\n")
)
ptr = self.UIATextPattern.GetVisibleRanges()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs this will return multiple ranges if something is obscuring part of the text (such as a another window in the way). The obscured text will not be returned. In practice this may not be a concern, though an "always on top window" such as speech viewer may interfere.

I wonder if there is another way to get only the text on the current "screen". I haven't investigated this at all, but consider this as a general idea: The number of lines in the console is fixed until the window resizes, after each resize we could count and cache this number of lines. Then when we want all lines on screen we expand a text range from the last line, back n lines. Counting caching the number of lines on a window resize might happen by iterating through the text ranges (per line) checking if it is visible.

res = [ptr.GetElement(i).GetText(-1) for i in range(ptr.length)]
return res
Expand Down
2 changes: 2 additions & 0 deletions source/globalVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@type navigatorObject: L{NVDAObjects.NVDAObject}
@var navigatorTracksFocus: if true, the navigator object will follow the focus as it changes
@type navigatorTracksFocus: boolean
@var maximizedUIAConsoles: stores state for maximized consoles, see #9899
"""

startTime=0
Expand All @@ -38,3 +39,4 @@
settingsRing = None
speechDictionaryProcessing=True
exitCode=0
maximizedUIAConsoles = []