Ë
    g
fB8  ã                   ó–   — d Z dZdZdZdZdZddlZddlZ ej                  dd	«       dd
l	m
Z
 ddlmZ ddlmZ ddlmZ  G d„ d«      Zy)aØ  
Utilities for obtaining position-related information about accessible objects.
These utilities are app-type- and toolkit-agnostic. Utilities that might have
different implementations or results depending on the type of app (e.g. terminal,
chat, web) or toolkit (e.g. Qt, Gtk) should be in script_utilities.py file(s).

N.B. There are currently utilities that should never have custom implementations
that live in script_utilities.py files. These will be moved over time.
z$Id$z
$Revision$z$Date$zGCopyright (c) 2024 Igalia, S.L.Copyright (c) 2024 GNOME Foundation Inc.ÚLGPLé    NÚAtspiz2.0)r   é   )Údebug)ÚAXObject)ÚAXUtilitiesc                   ó’  — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zed	„ «       Zed
„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zedd„«       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zy)ÚAXComponentzNUtilities for obtaining position-related information about accessible objects.c                 óœ   — t         j                  | «      }|j                  |j                  dz  z   |j                  |j
                  dz  z   fS )z;Returns the center point of obj with respect to its window.é   )r
   Úget_rectÚxÚwidthÚyÚheight©ÚobjÚrects     ú3/usr/lib/python3/dist-packages/orca/ax_component.pyÚget_center_pointzAXComponent.get_center_point5   sA   € ô ×#Ñ# CÓ(ˆØ�v‰v˜Ÿ
™
 Q™Ñ&¨¯©°·±¸q±Ñ(@Ð@Ð@ó    c                 óP  — t        j                  | «      sy	 t        j                  j	                  | t        j
                  j                  «      }|j                  |j                  fS # t        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)zBReturns the x, y position tuple of obj with respect to its window.©éÿÿÿÿr   ú(AXComponent: Exception in get_position: TN)r   Úsupports_componentr   Ú	ComponentÚget_positionÚ	CoordTypeÚWINDOWÚ	Exceptionr   ÚprintMessageÚ
LEVEL_INFOr   r   ©r   ÚpointÚerrorÚmsgs       r   r   zAXComponent.get_position<   sˆ   € ô ×*Ñ*¨3Ô/Øð	Ü—O‘O×0Ñ0°´e·o±o×6LÑ6LÓMˆEð �w‰w˜Ÿ™ÐÐøô ò 	Ø<¸U¸GÐDˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	úó   ˜8A( Á(	B%Á1*B Â B%c                 ór  — t        j                  | «      st        j                  «       S 	 t        j                  j                  | t        j                  j                  «      }|S # t        $ rH}d|› �}t        j                  t        j                  |d«       t        j                  «       cY d}~S d}~ww xY w)z9Returns the Atspi rect of obj with respect to its window.z$AXComponent: Exception in get_rect: TN)r   r   r   ÚRectr   Úget_extentsr   r    r!   r   r"   r#   )r   r   r&   r'   s       r   r   zAXComponent.get_rectL   sŒ   € ô ×*Ñ*¨3Ô/Ü—:‘:“<Ðð	 Ü—?‘?×.Ñ.¨s´E·O±O×4JÑ4JÓKˆDð ˆøô ò 	 Ø8¸¸Ð@ˆCÜ×Ñœu×/Ñ/°°dÔ;Ü—:‘:“<Õûð	 ús   «8A% Á%	B6Á.=B1Â+B6Â1B6c                 óD  — t        j                  «       }t        | j                  | j                  | j                  z   dz   «      }t        |j                  |j                  |j                  z   dz   «      }t        t        |«      j                  t        |«      «      «      }t        | j                  | j                  | j                  z   dz   «      }t        |j                  |j                  |j                  z   dz   «      }t        t        |«      j                  t        |«      «      «      }|rD|rB|d   |_        |d   |_        |d   |j                  z
  |_        |d   |j                  z
  |_	        d| d|d|g}	t        j                  t        j                  |	d«       |S )z@Returns a rect representing the intersection of rect1 and rect2.r   r   r   z AXComponent: The intersection ofÚandzis:T)r   r*   Úranger   r   ÚsortedÚsetÚintersectionr   r   r   ÚprintTokensr#   )
Úrect1Úrect2ÚresultÚ	x_points1Ú	x_points2Úx_intersectionÚ	y_points1Ú	y_points2Úy_intersectionÚtokenss
             r   Úget_rect_intersectionz!AXComponent.get_rect_intersection\   sH  € ô —‘“ˆä˜%Ÿ'™' 5§7¡7¨U¯[©[Ñ#8¸1Ñ#<Ó=ˆ	Ü˜%Ÿ'™' 5§7¡7¨U¯[©[Ñ#8¸1Ñ#<Ó=ˆ	Ü¤ I£× ;Ñ ;¼CÀ	»NÓ KÓLˆä˜%Ÿ'™' 5§7¡7¨U¯\©\Ñ#9¸AÑ#=Ó>ˆ	Ü˜%Ÿ'™' 5§7¡7¨U¯\©\Ñ#9¸AÑ#=Ó>ˆ	Ü¤ I£× ;Ñ ;¼CÀ	»NÓ KÓLˆá™nØ% aÑ(ˆFŒHØ% aÑ(ˆFŒHØ)¨"Ñ-°·±Ñ8ˆFŒLØ*¨2Ñ.°·±Ñ9ˆFŒMà4°e¸UÀEÈ5ÐRXÐYˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr   c                 óP  — t        j                  | «      sy	 t        j                  j	                  | t        j
                  j                  «      }|j                  |j                  fS # t        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)zBReturns the width, height tuple of obj with respect to its window.r   r   TN)r   r   r   r   Úget_sizer   r    r!   r   r"   r#   r   r   r$   s       r   r?   zAXComponent.get_sizet   sˆ   € ô ×*Ñ*¨3Ô/Øð	Ü—O‘O×,Ñ,¨S´%·/±/×2HÑ2HÓIˆEð �w‰w˜Ÿ™ÐÐøô ò 	Ø<¸U¸GÐDˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	úr(   c                 ób   — t         j                  | «      }|j                  xs |j                   S )z0Returns True if obj has a width and height of 0.©r
   r   r   r   r   s     r   Úhas_no_sizezAXComponent.has_no_size…   s*   € ô ×#Ñ# CÓ(ˆØ—:‘:Ò, §¡Ð-Ð-r   c                 óT  — t         j                  | «      }|j                  s|j                  sy|j                  |j
                  cxk(  r%|j                  cxk(  r|j                  cxk(  rdk(  ry |j                  dk  s|j                  dk  r›d| d|g}t        j                  t        j                  |d«       t        j                  | «       t         j                  | «      }|j                  dk  s|j                  dk  r(d}t        j                  t        j                  |d«       yy)zDReturns True if the rect associated with obj is sizeless or invalid.Tr   z	WARNING: zhas a broken rect:z0AXComponent: Clearing cache did not fix the rectF)r
   r   r   r   r   r   r   r2   r#   r   Úclear_cacher"   )r   r   r<   r'   s       r   Úhas_no_size_or_invalid_rectz'AXComponent.has_no_size_or_invalid_rectŒ   sé   € ô ×#Ñ# CÓ(ˆØ—
’
˜dŸkškØà�6‰6�T—V‘VÔ>˜tŸz™zÔ>¨T¯[©[Ô>¸BÒ>Øð ?ð �J‰J˜ŠO˜tŸ{™{¨RÒ/Ø! 3Ð(<¸dÐCˆFÜ×Ñœe×.Ñ.°¸Ô=Ü× Ñ  Ô%Ü×'Ñ'¨Ó,ˆDØ—
‘
˜R’ 4§;¡;°Ò#3ØH�Ü×"Ñ"¤5×#3Ñ#3°S¸$Ô?Øàr   c                 ó†   — | j                   dk(  xr1 | j                  dk(  xr  | j                  dk(  xr | j                  dk(  S )z9Returns True if rect's x, y, width, and height are all 0.r   ©r   r   r   r   )r   s    r   Úis_empty_rectzAXComponent.is_empty_rect£   s;   € ð �v‰v˜‰{ÒS˜tŸv™v¨™{ÒS¨t¯z©z¸Q©ÒSÀ4Ç;Á;ÐRSÑCSÐSr   c                 óÖ   — | j                   |j                   k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )z@Returns True if rect1 and rect2 represent the same bounding box.rG   )r3   r4   s     r   Úis_same_rectzAXComponent.is_same_rect©   sZ   € ð �w‰w˜%Ÿ'™'Ñ!ò -Ø—‘˜5Ÿ7™7Ñ"ò-à—‘˜uŸ{™{Ñ*ò-ð —‘ §¡Ñ,ð	-r   c                 óº  — t        j                  | «      syt        j                  | «      ry	 t        j                  j                  | ||t        j                  j                  «      }d| d|› d|› d|› �g}t        j                  t        j                  |d«       |S # t        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)	z8Returns True if obj's rect contains the specified point.Fz1AXComponent: Exception in object_contains_point: TNzAXComponent: zcontains point ú, ú: )r   r   Úis_bogusr   r   Úcontainsr   r    r!   r   r"   r#   r2   ©r   r   r   r5   r&   r'   r<   s          r   Úobject_contains_pointz!AXComponent.object_contains_point²   sÆ   € ô ×*Ñ*¨3Ô/Øä×Ñ˜SÔ!Øð	Ü—_‘_×-Ñ-¨c°1°a¼¿¹×9OÑ9OÓPˆFð " 3¨/¸!¸¸B¸q¸cÀÀFÀ8Ð(LÐMˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	ØEÀeÀWÐMˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ús   ®:B Â	CÂ&*CÃCc                 ó€   — t         j                  t         j                  | «      |«      }t         j                  |«       S )zCReturns True if the Atspi.Rect associated with obj intersects rect.©r
   r=   r   rH   )r   r   r1   s      r   Úobject_intersects_rectz"AXComponent.object_intersects_rectÇ   s6   € ô #×8Ñ8¼×9MÑ9MÈcÓ9RÐTXÓYˆÜ×,Ñ,¨\Ó:Ð:Ð:r   c                 óF  — t         j                  | «      }t        |j                  «      dkD  st        |j                  «      dkD  r+d| dg}t        j                  t
        j                  |d«       y|j                  dk(  s|j                  dk(  r«t        j                  | «      s+d| dg}t        j                  t
        j                  |d«       yt        j                  | «      r+d| dg}t        j                  t
        j                  |d«       yd| d	g}t        j                  t
        j                  |d«       y
|j                  |j                  z   dk  xr |j                  |j                  z   dk  }d| d|› �g}t        j                  t
        j                  |d«       |S )z:Returns True if the rect associated with obj is off-screeni'  zAXComponent: Treatingzas offscreen due to positionTr   z(as offscreen due to size and no childrenz!as offscreen due to size and rolezAXComponent: Treating sizelesszas onscreenFzAXComponent:zis off-screen: )r
   r   Úabsr   r   r   r2   r#   r   r   r   Úget_child_countr   Úis_menu)r   r   r<   r5   s       r   Úobject_is_off_screenz AXComponent.object_is_off_screenÎ   sb  € ô ×#Ñ# CÓ(ˆÜˆt�v‰v‹;˜Ò¤# d§f¡f£+°Ò"5Ø-¨sÐ4RÐSˆFÜ×Ñœe×.Ñ.°¸Ô=Øà�:‰:˜Š?˜dŸk™k¨QÒ.Ü×+Ñ+¨CÔ0Ø1°3Ð8bÐc�Ü×!Ñ!¤%×"2Ñ"2°F¸DÔAØÜ×"Ñ" 3Ô'Ø1°3Ð8[Ð\�Ü×!Ñ!¤%×"2Ñ"2°F¸DÔAØØ6¸¸]ÐKˆFÜ×Ñœe×.Ñ.°¸Ô=Øà—‘˜$Ÿ*™*Ñ$ qÑ(ÒE¨T¯V©V°d·k±kÑ-AÀAÑ-EˆØ  #¨¸¸Ð'AÐBˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr   c                 óz   — t         j                  t         j                  | «      t         j                  |«      «      S )z1Returns True if obj1 and obj2 have the same rect.)r
   rJ   r   )Úobj1Úobj2s     r   Úobjects_have_same_rectz"AXComponent.objects_have_same_rectê   s.   € ô ×'Ñ'¬×(<Ñ(<¸TÓ(BÄ;×CWÑCWÐX\ÓC]Ó^Ð^r   c                 ó¦   — t         j                  t         j                  | «      t         j                  |«      «      }t         j                  |«       S )z@Returns True if the rects associated with obj1 and obj2 overlap.rS   )r[   r\   r1   s      r   Úobjects_overlapzAXComponent.objects_overlapð   sD   € ô #×8Ñ8Ü× Ñ  Ó&¬×(<Ñ(<¸TÓ(BóDˆä×,Ñ,¨\Ó:Ð:Ð:r   c                 ó„   — t         j                  | «      d   }t         j                  |«      d   }t        ||z
  «      |k  S )zNReturns True if obj1 and obj2 are on the same line based on the center points.r   )r
   r   rV   )r[   r\   ÚdeltaÚ	y1_centerÚ	y2_centers        r   Úon_same_linezAXComponent.on_same_lineø   sC   € ô  ×0Ñ0°Ó6°qÑ9ˆ	Ü×0Ñ0°Ó6°qÑ9ˆ	Ü�9˜yÑ(Ó)¨UÑ2Ð2r   c                 óÂ   — t        j                  | «      st        j                  | «      ryt        j	                  | «      }|j
                  dkD  xr |j                  dkD  S )zLReturns True if obj's rect is expected to include the rects of its children.Fr   )r   rX   Úis_page_tabr
   r   r   r   r   s     r   Ú _object_bounds_includes_childrenz,AXComponent._object_bounds_includes_children   sM   € ô ×Ñ˜sÔ#¤{×'>Ñ'>¸sÔ'CØä×#Ñ# CÓ(ˆØ�z‰z˜A‰~Ò1 $§+¡+°¡/Ð1r   c                 óÒ   — t        j                  | «      D ]O  }t        j                  |«      rŒt        j                  |«      D ]  }t        j	                  |||«      sŒ|c c S  ŒQ y)zGChecks each child to see if it has a descendant at the specified point.N)r   Úiter_childrenr
   rg   rQ   ©r   r   r   ÚchildÚ
descendants        r   Ú_find_descendant_at_pointz%AXComponent._find_descendant_at_point
  sf   € ô ×+Ñ+¨CÓ0ò 	&ˆEÜ×;Ñ;¸EÔBØÜ&×4Ñ4°UÓ;ò &�
Ü×4Ñ4°ZÀÀAÕFØ%Ô%ñ&ð	&ð r   c                 óŒ  — t        j                  | «      sy	 t        j                  j	                  | ||t        j
                  j                  «      }d| d|› d|› d�|g}t        j                  t        j                  |d«       |S # t        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)zAReturns the child (or descendant?) of obj at the specified point.Nz.AXComponent: Exception in get_child_at_point: TzAXComponent: Child ofúat rL   ú is)r   r   r   r   Úget_accessible_at_pointr   r    r!   r   r"   r#   r2   rP   s          r   Ú_get_object_at_pointz AXComponent._get_object_at_point  s³   € ô ×*Ñ*¨3Ô/Øð	Ü—_‘_×<Ñ<¸SÀ!ÀQÌÏÉ×H^ÑH^Ó_ˆFð *¨3°#°a°S¸¸1¸#¸SÐ0AÀ6ÐJˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	ØBÀ5À'ÐJˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	úó   ˜:B Â	CÂ*B>Â>Cc                 ó  — t         j                  | ||«      }|€4t         j                  | ||«      rt         j                  | ||«      }|€| S |}|| k(  st	        j
                  |«      s|S t         j                  |||«      S )ú=Returns the deepest descendant of obj at the specified point.)r
   rr   rQ   rm   r   rW   Ú_get_descendant_at_pointrj   s        r   rv   z$AXComponent._get_descendant_at_point(  s€   € ô ×0Ñ0°°a¸Ó;ˆØˆ=œ[×>Ñ>¸sÀAÀqÔIÜ$×>Ñ>¸sÀAÀqÓIˆJØÐ!Ø�
ØˆEà�CŠ<œx×7Ñ7¸Ô>ØˆLä×3Ñ3°E¸1¸aÓ@Ð@r   c                 ó˜   — t         j                  | ||«      }d| d|› d|› d�|g}t        j                  t        j                  |d«       |S )ru   zAXComponent: Descendant ofro   rL   rp   T)r
   rv   r   r2   r#   )r   r   r   r5   r<   s        r   Úget_descendant_at_pointz#AXComponent.get_descendant_at_point8  sR   € ô ×5Ñ5°c¸1¸aÓ@ˆØ.°°s¸1¸#¸RÀ¸sÀ#Ð5FÈÐOˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr   c                 óŒ  — t        j                  | «      sy	 t        j                  j	                  | t        j
                  j                  ||«      }d| d|› d|› d�|g}t        j                  t        j                  |d«       |S # t        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)	z.Attempts to scroll obj to the specified point.Fz2AXComponent: Exception in scroll_object_to_point: TNúAXComponent: Scrolledzto rL   ú:)r   r   r   r   Úscroll_to_pointr   r    r!   r   r"   r#   r2   rP   s          r   Úscroll_object_to_pointz"AXComponent.scroll_object_to_pointA  s´   € ô ×*Ñ*¨3Ô/Øð	Ü—_‘_×4Ñ4°S¼%¿/¹/×:PÑ:PÐRSÐUVÓWˆFð *¨3°#°a°S¸¸1¸#¸Q°ÀÐHˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	ØFÀuÀgÐNˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	úrs   c                 óR  — t        j                  | «      sy	 t        j                  j	                  | |«      }d| d|d|› �g}t        j                  t        j                  |d«       |S # t
        $ r4}d|› �}t        j                  t        j                  |d«       Y d}~yd}~ww xY w)zBAttempts to scroll obj to the specified Atspi.ScrollType location.Fz5AXComponent: Exception in scroll_object_to_location: TNrz   ÚtorM   )
r   r   r   r   Ú	scroll_tor!   r   r"   r#   r2   )r   Úlocationr5   r&   r'   r<   s         r   Úscroll_object_to_locationz%AXComponent.scroll_object_to_locationS  sž   € ô ×*Ñ*¨3Ô/Øð	Ü—_‘_×.Ñ.¨s°HÓ=ˆFð *¨3°°hÀ"ÀVÀHÀÐNˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆøô ò 	ØIÈ%ÈÐQˆCÜ×Ñœu×/Ñ/°°dÔ;Üûð	ús   ˜ A) Á)	B&Á2*B!Â!B&c                 óH   — d„ }t        | t        j                  |«      ¬«      S )z0Returns objects sorted from smallest to largest.c                 ó¼   — t         j                  | «      }t         j                  |«      }|j                  |j                  z  |j                  |j                  z  z
  S )NrA   )r[   r\   r3   r4   s       r   Ú_size_comparisonz:AXComponent.sort_objects_by_size.<locals>._size_comparisoni  sG   € Ü×(Ñ(¨Ó.ˆEÜ×(Ñ(¨Ó.ˆEØ—K‘K %§,¡,Ñ.°5·;±;ÀÇÁÑ3MÑNÐNr   ©Úkey©r/   Ú	functoolsÚ
cmp_to_key)Úobjectsr…   s     r   Úsort_objects_by_sizez AXComponent.sort_objects_by_sizee  s#   € ò	Oô
 �g¤9×#7Ñ#7Ð8HÓ#IÔJÐJr   c                 óH   — d„ }t        | t        j                  |«      ¬«      S )z5Returns objects sorted from top-left to bottom-right.c                 ó¢  — t         j                  | «      }t         j                  |«      }|j                  |j                  z
  xs |j                  |j                  z
  }|sVt	        j
                  | «      t	        j
                  |«      k(  r+t	        j                  | «      t	        j                  |«      z
  }t        |d«      }t        |d«      }|S )Nr   r   )	r
   r   r   r   r   Ú
get_parentÚget_index_in_parentÚmaxÚmin)r[   r\   r3   r4   Úrvs        r   Ú_spatial_comparisonzAAXComponent.sort_objects_by_position.<locals>._spatial_comparisont  s¤   € Ü×(Ñ(¨Ó.ˆEÜ×(Ñ(¨Ó.ˆEØ—‘˜5Ÿ7™7Ñ"Ò7 e§g¡g°·±Ñ&7ˆBñ œ(×-Ñ-¨dÓ3´x×7JÑ7JÈ4Ó7PÒPÜ×1Ñ1°$Ó7¼(×:VÑ:VÐW[Ó:\Ñ\�ä�R˜“ˆBÜ�R˜“ˆBØˆIr   r†   rˆ   )r‹   r”   s     r   Úsort_objects_by_positionz$AXComponent.sort_objects_by_positionp  s"   € ò	ô �g¤9×#7Ñ#7Ð8KÓ#LÔMÐMr   N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r=   r?   rB   rE   rH   rJ   rQ   rT   rY   r]   r_   rd   rg   rm   rr   rv   rx   r}   r‚   rŒ   r•   © r   r   r
   r
   2   sï  „ ÙXàñAó ðAð ñ ó ð ð ñó ðð ñó ðð. ñ ó ð ð  ñ.ó ð.ð ñó ðð, ñTó ðTð
 ñ-ó ð-ð ñó ðð( ñ;ó ð;ð ñó ðð6 ñ_ó ð_ð
 ñ;ó ð;ð ò3ó ð3ð ñ2ó ð2ð ñ	ó ð	ð ñó ðð" ñAó ðAð ñó ðð ñó ðð" ñó ðð" ñKó ðKð ñNó ñNr   r
   )r™   Ú__id__Ú__version__Ú__date__Ú__copyright__Ú__license__r‰   ÚgiÚrequire_versionÚgi.repositoryr   Ú r   Ú	ax_objectr   Úax_utilitiesr   r
   r›   r   r   ú<module>r§      sY   ðñ,ð €Ø€Ø€ð;€à€ã ã 	Ø €× Ñ �7˜EÔ "Ý å Ý Ý %÷PNò PNr   