-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
Provide a locationHelper module for code related to locations, rectangles and points #7537
Changes from 25 commits
3ad47de
9d84968
fb646bd
8de022d
b9d0bac
b9c04c5
1aaa5c0
e3f8f3a
7308287
070bb36
c2e29fd
2c9ef24
3dbfc75
81d3f98
0ba335a
e49888c
c6d147f
62c380e
7f2cb6f
c7f792d
4487aa7
7e94522
3d351f2
25896ba
dfc7e0d
e407922
3679aac
d456b2e
80de132
4b4adf3
7a05387
6c99d8c
8e808ec
5dfca2f
5d4ec65
f055c9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,12 @@ | |
import api | ||
import eventHandler | ||
import winKernel | ||
import winUser | ||
from . import IAccessible, List | ||
from ..window import Window | ||
import watchdog | ||
from NVDAObjects.behaviors import RowWithoutCellObjects, RowWithFakeNavigation | ||
import config | ||
from locationHelper import RectLTRB | ||
|
||
#Window messages | ||
LVM_FIRST=0x1000 | ||
|
@@ -53,6 +53,15 @@ | |
LVIF_GROUPID=0x100 | ||
LVIF_COLUMNS=0x200 | ||
|
||
#GETSUBITEMRECT flags | ||
# Returns the bounding rectangle of the entire item, including the icon and label | ||
LVIR_BOUNDS = 0 | ||
# Returns the bounding rectangle of the icon or small icon. | ||
LVIR_ICON = 1 | ||
# Returns the bounding rectangle of the entire item, including the icon and label. | ||
# This is identical to LVIR_BOUNDS. | ||
LVIR_LABEL = 2 | ||
|
||
#Item states | ||
LVIS_FOCUSED=0x01 | ||
LVIS_SELECTED=0x02 | ||
|
@@ -298,17 +307,25 @@ class ListItem(RowWithFakeNavigation, RowWithoutCellObjects, ListItemWithoutColu | |
|
||
def _getColumnLocationRaw(self,index): | ||
processHandle=self.processHandle | ||
localRect=RECT(left=2,top=index) | ||
# LVM_GETSUBITEMRECT requires a pointer to a RECT structure that will receive the subitem bounding rectangle information. | ||
localRect=RECT( | ||
left=LVIR_LABEL, # Returns the bounding rectangle of the entire item, including the icon and label | ||
top=index # The one-based index of the subitem | ||
) | ||
internalRect=winKernel.virtualAllocEx(processHandle,None,sizeof(localRect),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) | ||
try: | ||
winKernel.writeProcessMemory(processHandle,internalRect,byref(localRect),sizeof(localRect),None) | ||
watchdog.cancellableSendMessage(self.windowHandle,LVM_GETSUBITEMRECT, (self.IAccessibleChildID-1), internalRect) | ||
winKernel.readProcessMemory(processHandle,internalRect,byref(localRect),sizeof(localRect),None) | ||
finally: | ||
winKernel.virtualFreeEx(processHandle,internalRect,0,winKernel.MEM_RELEASE) | ||
windll.user32.ClientToScreen(self.windowHandle,byref(localRect)) | ||
windll.user32.ClientToScreen(self.windowHandle,byref(localRect,8)) | ||
return (localRect.left,localRect.top,localRect.right-localRect.left,localRect.bottom-localRect.top) | ||
# ##8268: this might be a malformed rectangle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: Too many hash symbols here. |
||
# (i.e. with a left coordinate that is greather than the right coordinate). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned that this might happen in other cases, can we be more specific about when this is the case? Should location helper generally handle this case? If not, I would like to see that it detects it and alerts us. Could you add a unit test specifically for malformed rectangles? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Locationhelper detects this and raises a ValueError for RectLTRB. For RectLTWH, there is currently no detection for negative widths. I'm afraid that we can't make sure that IAccessible or UIA will never return rectangles with negative width and/or height. May be we should no longer raise a ValueError, but log a warning instead. |
||
left = min(localRect.left, localRect.right) | ||
top = min(localRect.top, localRect.bottom) | ||
right = max(localRect.left, localRect.right) | ||
bottom = max(localRect.top, localRect.bottom) | ||
return RectLTRB(left, top, right, bottom).toScreen(self.windowHandle).toLTWH() | ||
|
||
def _getColumnLocation(self,column): | ||
return self._getColumnLocationRaw(self.parent._columnOrderArray[column - 1]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering this is expecting a one-based index, I think this function should assert that
index > 0