Skip to content

Commit

Permalink
fix: Channels not being selected on the edge of the window
Browse files Browse the repository at this point in the history
Sometimes, if an element was on screen but too low to be reachable,
we wouldn't scroll to it. Now we do.
  • Loading branch information
JoshuaVandaele committed May 10, 2023
1 parent 337e4ca commit 5666bd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions addon/appModules/captvty.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def _directSelectedChannelCallback(self, selectedElement: NVDAObject):
element=selectedElement,
max_attempts=30,
scrollable_container=scroll_area,
bounds_offset=(0, 0, 250, 250),
)
if mainFrame:
mainFrame.prePopup()
Expand Down
23 changes: 15 additions & 8 deletions addon/appModules/modules/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ def scroll_element_with_mouse(


def where_is_element_trespassing(
element: Union[IAccessible, NVDAObject], window: Union[IAccessible, NVDAObject]
element: Union[IAccessible, NVDAObject],
window: Union[IAccessible, NVDAObject],
bounds_offset: Tuple[int, int, int, int] = (0, 0, 0, 0),
) -> Optional[str]:
"""
Determines which side of a window an element is trespassing on, if any.
Args:
element (Union[IAccessible, NVDAObject]): The element to check.
window (Union[IAccessible, NVDAObject]): The window to check.
bounds_offset (Tuple[int, int, int, int], optional): Offsets for detecting the left, right, top and bottom of the element.
Returns:
A string indicating the side of the window the element is trespassing on (i.e. "above", "below", "left", "right"),
Expand All @@ -169,8 +172,10 @@ def where_is_element_trespassing(
log.error("window.location is unbound")
return

element_right = element_location.left + element_location.width
element_bottom = element_location.top + element_location.height
element_left = element_location.left + bounds_offset[0]
element_right = element_location.left + element_location.width + bounds_offset[1]
element_bottom = element_location.top + element_location.height + bounds_offset[2]
element_top = element_location.top + bounds_offset[3]
window_right = window_location.left + window_location.width
window_bottom = window_location.top + window_location.height

Expand All @@ -179,19 +184,19 @@ def where_is_element_trespassing(
)
log.info(f"window {window_location}, bottom {window_bottom}, right {window_right}")
is_inside_horizontal = (
element_location.left >= window_location.left and element_right <= window_right
element_left >= window_location.left and element_right <= window_right
)
is_inside_vertical = (
element_location.top >= window_location.top and element_bottom <= window_bottom
element_top >= window_location.top and element_bottom <= window_bottom
)

if is_inside_horizontal and is_inside_vertical:
return None
elif element_location.top > window_bottom:
elif element_top > window_bottom:
return "below"
elif element_bottom < window_location.top:
return "above"
elif element_location.left > window_right:
elif element_left > window_right:
return "right"
elif element_right < window_location.left:
return "left"
Expand All @@ -203,6 +208,7 @@ def scroll_to_element(
scroll_delta: int = 120,
max_attempts: int = 10,
scrollable_container: Optional[Union[IAccessible, NVDAObject]] = None,
bounds_offset: Tuple[int, int, int, int] = (0, 0, 0, 0),
) -> None:
"""
Scrolls the current foreground window to bring the specified element into view.
Expand All @@ -212,6 +218,7 @@ def scroll_to_element(
scroll_delta (int, optional): The delta for the mouse wheel scrolling. Defaults to 120.
max_attempts (int, optional): The maximum number of scroll attempts. Defaults to 10.
scrollable_container: (Union[IAccessible, NVDAObject], optional): Container in which we will scroll.
bounds_offset (Tuple[int, int, int, int], optional): Offsets for detecting the left, right, top and bottom of the element.
Returns:
None
Expand All @@ -225,7 +232,7 @@ def scroll_to_element(
return

for _ in range(max_attempts):
trespassing_side = where_is_element_trespassing(element, window)
trespassing_side = where_is_element_trespassing(element, window, bounds_offset)

log.info(f"trespassing: {trespassing_side}")

Expand Down

0 comments on commit 5666bd2

Please sign in to comment.