
    g
f                         d Z dZdZdZdZdZddlZ ej                  dd	       dd
lm	Z	 ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZ G d d      Z G d d      Z G d d      Z G d de      Z G d d e      Z  G d! d"e      Z! G d# d$      Z" G d% d&      Z#y)'z=Provides the default implementation for flat review for Orca.z$Id$z
$Revision$z$Date$zLCopyright (c) 2005-2008 Sun Microsystems Inc.Copyright (c) 2016 Igalia, S.L.LGPL    NAtspiz2.0)r      )braille)debug)focus_manager)script_manager)settings)AXComponent)AXEventSynthesizer)AXObject)AXText)AXUtilitiesu   ￼c                       e Zd ZdZd Zy)Charz/A character's worth of presentable information.c	                     || _         || _        || _        |dz   | _        || _        || _        || _        || _        || _        y)a  Creates a new char.

        Arguments:
        - word: the Word instance this belongs to
        - startOffset: the start offset with respect to the accessible
        - string: the actual char
        - x, y, width, height: the extents of this Char on the screen
        r   N)	wordindexstartOffset	endOffsetstringxywidthheight)	selfr   r   r   r   r   r   r   r   s	            2/usr/lib/python3/dist-packages/orca/flat_review.py__init__zChar.__init__4   sH     	
&$q
    N)__name__
__module____qualname____doc__r    r   r   r   r   1   s
    9r   r   c                   4     e Zd ZdZd Zd Z fdZd Z xZS )Wordz;A single chunk (word or object) of presentable information.c	                     || _         || _        || _        || _        t	        |      | _        | j                  t	        |      z   | _        || _        || _        || _	        || _
        g | _        y)aG  Creates a new Word.

        Arguments:
        - zone: the Zone instance this belongs to
        - index: the index of this Word in the Zone
        - startOffset: the start offset with respect to the accessible
        - string: the actual string
        - x, y, width, height: the extents of this Word on the screen
        N)zoner   r   r   lenlengthr   r   r   r   r   chars)	r   r(   r   r   r   r   r   r   r   s	            r   r   zWord.__init__L   se     	
&&k))CK7

r   c                     d| j                   j                  dd      | j                  | j                  | j                  j
                  fz  S )NzWORD: '%s' (%i-%i) %s
\n)r   replacer   r   r(   
accessibler   s    r   __str__zWord.__str__c   sE    &[[  u-^^YY!!## 	#r   c           	      x   |dk7  rt         |   |      S g }t        | j                        D ]  \  }}|| j                  z   }t        j                  | j                  j                  |      }|j                  |j                  |j                  |j                  f}|j                  t        | |||g|         |S )Nr+   )super__getattribute__	enumerater   r   r   get_character_rectr(   r0   r   r   r   r   appendr   )	r   attrr+   icharstartrect1extents	__class__s	           r   r5   zWord.__getattribute__j   s    7?7+D11 - 	?GAt(((E--dii.B.BEJEgguwwU\\AGLLdAud=W=>		? r   c                     | j                   |cxk  r%| j                   t        | j                        z   k  rn y|| j                   z
  S y)z8Returns the char offset with respect to this word or -1.)r   r)   r   )r   offsets     r   getRelativeOffsetzWord.getRelativeOffsetw   sF     vK(8(83t{{;K(KK  D,,,,r   )	r    r!   r"   r#   r   r2   r5   rC   __classcell__r?   s   @r   r&   r&   I   s    E.#r   r&   c                        e Zd ZdZ ej
                  dej                        ZddZd Z	 fdZ
d ZddZd Zd	 Zd
 Zd Z xZS )Zonez>Represents text that is a portion of a single horizontal line.z(\S+\s*)c                     || _         d| _        || _        t        |      | _        || _        || _        || _        || _        |xs t        j                  |      | _        g | _        y)a  Creates a new Zone.

        Arguments:
        - accessible: the Accessible associated with this Zone
        - string: the string being displayed for this Zone
        - extents: x, y, width, height in screen coordinates
        - role: Role to override accessible's role.
        r   N)r0   r   _stringr)   r*   r   r   r   r   r   get_rolerole_words)r   r0   r   r   r   r   r   rK   s           r   r   zZone.__init__   s_     %&k
9H--j9	r   c                 Z    d| j                   j                  dd      d| j                  S )NzZONE: 'r-   r.   z' )rI   r/   r0   r1   s    r   r2   zZone.__str__   s"    "&,,"6"6tU"CT__UUr   c           
         |dvrt         |   |      S |dk(  r| j                  S | j                         s| j                  S | j
                  | j                  | j                  | j                  f}g }t        t        j                  | j                  | j                              D ]?  \  }}|j                  t        | ||j                         |j!                         g|        A || _        |S ) To ensure we update the content.wordsr   r   )r4   r5   rI   _shouldFakeTextrL   r   r   r   r   r6   refinditerWORDS_REr8   r&   r<   group)r   r9   r>   rQ   r:   r   r?   s         r   r5   zZone.__getattribute__   s     **7+D118<<##%;; &&$&&$**dkk9 T]]DLL!IJ 	NGAtLLdAtzz|TZZ\LGLM	N r   c                    t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j
                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  g}| j                  |v ryy)z8Returns True if we should try to fake the text interfaceTF)r   RoleLABELMENU	MENU_ITEMCHECK_MENU_ITEMRADIO_MENU_ITEMPAGE_TABPUSH_BUTTON
TABLE_CELLrK   )r   	textRoless     r   rR   zZone._shouldFakeText   s     ZZ%%ZZ__ZZ))ZZ//ZZ//ZZ((ZZ++ZZ**,	 99	!r   c                    | j                   dk(  rJ| j                  dk(  r;|j                  | j                  cxk  xr |j                  |j                  z   k  S c S |j                   dk(  rJ| j                  dk(  r;| j                  |j                  cxk  xr | j                  | j                  z   k  S c S t        | j                  | j                  z   |j                  |j                  z         }t	        | j                  |j                        }||k\  ry| j                  | j                  dz  z   }|j                  |j                  dz  z   }t        ||z
        |kD  ryy)zAReturns True if this Zone is physically on the same line as zone.r   F   T)r   r   r   minmaxabs)r   r(   
pixelDeltahighestBottom	lowestTopmiddle
zoneMiddles          r   _extentsAreOnSameLinezZone._extentsAreOnSameLine   s    ::?t{{a/66TVV;tvv';;;;;::?t{{a/66TVV;tvv';;;;;DFFT[[0$&&4;;2FG'	%$++/)VVdkkAo-
v
"#j0r   c                    t         j                  j                  | j                  |j                  fv r| j                  |j                  k(  S t        j                  | j                        }t        j                  |      }t        j                  |j                        }t        j                  |      }t         j                  j                  ||fv r||k(  S | j                  |      S )zAReturns True if we treat this Zone and zone as being on one line.)
r   rX   
SCROLL_BARrK   r0   r   
get_parentrJ   MENU_BARrl   )r   r(   
thisParentthisParentRole
zoneParentzoneParentRoles         r   
onSameLinezZone.onSameLine   s     ::  TYY		$::??doo55((9
!**:6((9
!**:6::>>"BB++))$//r   c                 t   d| }t        j                  t         j                  |d       | j                  D ]G  }d|g}t        j                  t         j                  |d       |j                  |      }|dk\  sC||fc S  | j                  |k(  r)| j                  r| j                  d   }||j                  fS y)Nz*FLAT REVIEW: Searching for word at offset TzFLAT REVIEW: Checkingr   rA   NrA   )r   printMessage
LEVEL_INFOrQ   printTokensrC   r*   )r   
charOffsetmsgr   tokensrB   lastWords          r   getWordAtOffsetzZone.getWordAtOffset   s    ::,G5++S$7JJ 	$D-t4Fe..=++J7F{V|#	$ ;;*$zz"~HX__,,r   c                      y)-Returns True if this Zone contains the caret.Fr$   r1   s    r   hasCaretzZone.hasCaret   s     r   c                      yz4Returns the Word and relative offset with the caret.rw   r$   r1   s    r   wordWithCaretzZone.wordWithCaret   s     r   N)   )r    r!   r"   r#   rS   compileUNICODErU   r   r2   r5   rR   rl   ru   r   r   r   rD   rE   s   @r   rG   rG      sJ    Hrzz+rzz2H*V."*0$
r   rG   c                   :     e Zd ZdZd fd	Z fdZd Zd Z xZS )TextZonez5A Zone whose purpose is to display text of an object.c	           	      x    t         	|   |||||||       || _        | j                  t        |      z   | _        y r   )r4   r   r   r)   r   )
r   r0   r   r   r   r   r   r   rK   r?   s
            r   r   zTextZone.__init__  s:    VQ5&$G&))CK7r   c           
      l    |dvrt         
   |      S t        j                   j                   j
                   j                        }g }t        t        j                   j                  |            D ]  \  }}t         fd|j                               \  }}t        j                   j                  ||      }|j                  |j                  |j                   |j"                  f}	|j%                  t'         |||j)                         g|	         | _        | _        t         
   |      S )rO   rP   c                 "    | j                   z   S r   )r   )r   r   s    r   <lambda>z+TextZone.__getattribute__.<locals>.<lambda>  s    q4+;+;'; r   )r4   r5   r   get_substringr0   r   r   r6   rS   rT   rU   mapspanget_range_rectr   r   r   r   r8   r&   rV   rI   rL   )r   r9   r   rQ   r:   r   r<   endrectr>   r?   s   `         r   r5   zTextZone.__getattribute__  s     **7+D11%%doot7G7GX T]]F!CD 	GGAt;TYY[IJE3((%EDffdffdjj$++=GLLdAudjjlEWEF		G w'--r   c                     | j                   t        j                  | j                        cxk  r| j                  k  ry | j                  t        j
                  | j                        k(  S )r   T)r   r   get_caret_offsetr0   r   get_character_countr1   s    r   r   zTextZone.hasCaret   sS     v66tGX$..X Y ~~!;!;DOO!LLLr   c                     | j                         sy| j                  t        j                  | j                              S r   )r   r   r   r   r0   r1   s    r   r   zTextZone.wordWithCaret(  s0     }}##F$;$;DOO$LMMr   r   )	r    r!   r"   r#   r   r5   r   r   rD   rE   s   @r   r   r     s    ?8.$MNr   r   c                   .     e Zd ZdZd fd	Z fdZ xZS )	StateZonez:A Zone whose purpose is to display the state of an object.c           	      0    t         |   |d|||||       y N r4   r   r   r0   r   r   r   r   rK   r?   s          r   r   zStateZone.__init__4      RAufdCr   c                    |dvrt         |   |      S t        j                         j	                         }|dk(  r|j
                  }n|j                  }|j                  | j                  | j                        }|r|d   S y)zTo ensure we update the state.r   brailleStringr   )rK   r   r   )
r4   r5   r	   
getManagergetActiveScriptspeechGeneratorbrailleGeneratorgetStateIndicatorr0   rK   )r   r9   script	generatorresultr?   s        r   r5   zStateZone.__getattribute__7  s     227+D11**,<<>8..I//I,,T__499,M!9r   r   r    r!   r"   r#   r   r5   rD   rE   s   @r   r   r   1  s    DD r   r   c                   .     e Zd ZdZd fd	Z fdZ xZS )	ValueZonez:A Zone whose purpose is to display the value of an object.c           	      0    t         |   |d|||||       y r   r   r   s          r   r   zValueZone.__init__M  r   r   c                 :   |dvrt         |   |      S t        j                         j	                         }|dk(  r|j
                  }n|j                  }d}|j                  | j                        }|j                  | j                        }|r|r
| d|d    }|S )zTo ensure we update the value.r   r   r    r   )
r4   r5   r	   r   r   r   r   getLocalizedRoleNamer0   getValue)r   r9   r   r   r   rolenamevaluer?   s          r   r5   zValueZone.__getattribute__P  s     227+D11**,<<>8..I//I 11$//B""4??3 z58*-Fr   r   r   rE   s   @r   r   r   J  s    DD r   r   c                   .     e Zd ZdZd Z fdZd Z xZS )LinezAA Line is a single line across a window and is composed of Zones.c                 .    || _         || _        d| _        y)zCreates a new Line, which is a horizontal region of text.

        Arguments:
        - index: the index of this Line in the window
        - zones: the Zones that make up this line
        N)r   zonesbrailleRegions)r   r   r   s      r   r   zLine.__init__k  s     

"r   c                 T   |dk(  r3dj                  | j                  D cg c]  }|j                   c}      S |dk(  r-t        | j                  D cg c]  }|j                   c}      S |dk(  r-t        | j                  D cg c]  }|j
                   c}      S |dk(  r-t        | j                  D cg c]  }|j                   c}      S |dk(  r-t        | j                  D cg c]  }|j                   c}      S t        | -  |      S c c}w c c}w c c}w c c}w c c}w )Nr   r   r   r   r   r   )joinr   r   rd   r   r   sumr   re   r   r4   r5   )r   r9   r(   r?   s      r   r5   zLine.__getattribute__x  s    888TZZ@TT[[@AA3;4::646773;4::646777?tzz:t

:;;8

;;<<w'-- A 7 7 ; <s   DDD6D (D%c                    	 g | _         d}| j                  D ]  }t        |t              rt	        j
                  |j                        t        j                  j                  t        j                  j                  t        j                  j                  fv slt	        j
                  |j                        t        j                  j                  t        j                  j                  t        j                  j                  fv r7t        j                   |j                  |j"                  |j$                  |      }n/	 |j&                  }t        j*                  |j                  |d|      }t-        | j                         r<t        j.                  d      }||_        | j                   j3                  |       |dz  }||_        ||_        | j                   j3                  |       |j"                  }|t-        |      z  } t6        j8                  st-        | j                         r<t        j.                  d      }||_        | j                   j3                  |       |dz  }t        j.                  d      }||_        | j                   j3                  |       | j                   S # t(        $ r |j"                  }Y uw xY w)Nr   r   r   z$l)r   r   
isinstancer   r   rJ   r0   r   rX   TEXTPASSWORD_TEXTTERMINAL	PARAGRAPHHEADINGLINKr   
ReviewTextr   r   r   	ExceptionReviewComponentr)   RegionbrailleOffsetr8   brailleRegionr
   disableBrailleEOL)r   r   r(   regionr   padregionStringeols           r   getBrailleRegionszLine.getBrailleRegions  s2   
 "$DM

 )3 dH-&&t7**//**22**--// &&t7**..**,,**//++ %//04040@0@046F
4(,(:(: %44T__5B5659;F t**+!..-C(5C%''..s3!Q&M%+"'4$##**62%}}\!22S)3V --t**+!..-C(5C%''..s3!Q&MnnT*$1!##**3/"""; % 4(,4s   <J%%J>=J>)r    r!   r"   r#   r   r5   r   rD   rE   s   @r   r   r   h  s    K#.$=#r   r   c                       e Zd ZdZdZdZdZdZdZdZ	dZ
dZe
ez  Zd!dZd	 Zd
 Zd Zd Zd Zd Zd Zd!dZd ZefdZd Zd Zd Zd"dZd Zd Zd ZefdZefdZ eedfdZ!eedfdZ"eefdZ#eefd Z$y)#ContextzBContains the flat review regions for the current top-level object.r   r   rc         Nc                 B   || _         g | _        g | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        t        j                         j                         | _        d| _        t        j                          | _        |j$                  j'                  | j                        \  }}|1|| _        d|g}t)        j*                  t(        j,                  |d       n|xs || _        d|d|d| j                  g}t)        j*                  t(        j,                  |d       t/        j0                  | j                        | _        t        j2                  j4                  gfd}t7        j8                  | j                  |      }|s || j                        r| j                  }|xs | j                  | _	        | j;                  | j                        \  | _        | _        | j=                  | j                        | _        | j                  r| j                  syt?        | j                        D ]  \  }}	| j                  |	j                  v s|| _        |	j                  jA                  | j                        | _        | j                  jC                         \  }
}|
r|
j@                  | _        || _         n d	| j                   d
| j                   d| j
                   d| j                   }t)        jD                  t(        j,                  |d       y)z Create a new Context for script.r   Nz'FLAT REVIEW: Restricting flat review toTzFLAT REVIEW: Frame:zDialog:z. Top level:c                 2    t        j                  |       v S r   )r   rJ   )r   containerRoless    r   isContainerz%Context.__init__.<locals>.isContainer  s    $$Q'>99r   zFLAT REVIEW: On line z, zone z word z, char )#r   r   lines	lineIndex	zoneIndex	wordIndex	charIndextargetCharInfo	focusZone	containerr   r   get_locus_of_focusfocusObjtopLevelr   Rectbounds	utilitiesframeAndDialogr   rz   ry   r   get_rectrX   rZ   r   find_ancestorgetShowingZonesclusterZonesByLiner6   r   r   rx   )r   r   rootframedialogr}   r   r   r:   liner   rB   r|   r   s                @r   r   zContext.__init__  s    

"%002EEGjjl((77Fv DM?FFe..="OeDM'	6>SWS`S`a%**FD9!**4==9**//*	: **4==+F	[7I"3dmm%)%9%9$..%I"
DN,,TZZ8


t~~ , 	GAt~~+!"!%!1!1$..!A#~~;;=f%)ZZDN%+DN	 $DNN#374>>:J KNN#74>>*:< 	 	5++S$7r   c                    g }t        j                  d|      D cg c]&  }g |j                         |j                  d      ( }}t	        t        fd|            }|D ]  \  }}	}
t        j                  |||	      }t        j                  ||      }t        j                  |      rJ|j                  |j                  |j                  |j                  f}|j                  t!        |||
g|         |S c c}w )a.  Traverses the string, splitting it up into separate zones if the
        string contains the EMBEDDED_OBJECT_CHARACTER, which is used by apps
        such as Firefox to handle containment of things such as links in
        paragraphs.

        Arguments:
        - accessible: the accessible
        - string: a substring from the accessible's text specialization
        - startOffset: the starting character offset of the string
        - cliprect: the extents that the Zones must fit inside.

        Returns a list of Zones for the visible text.
        z
[^\ufffc]+r   c                 ,    | d   z   | d   z   | d   fS )Nr   r   rc   r$   )r   r   s    r   r   z,Context.splitTextIntoZones.<locals>.<lambda>%  s'    1);QqTK=OQRSTQU(V r   )rS   rT   r   rV   listr   r   r   r   get_rect_intersectionis_empty_rectr   r   r   r   r8   r   )r   r0   r   r   cliprectr   m
substringsr<   r   	substringr   intersectionclippings      `          r   splitTextIntoZoneszContext.splitTextIntoZones  s     8:MSY8Z[1--!''!*-[
[#VXbcd
'1 	P#UC((UC@D&<<T8LL,,\:'>><>><;M;M|ObObbXj%NXNO	P  \s   +C<c           	         | j                   j                  j                  |      sg S g }d }t        j                  ||      }|rpt        j                  |      }t        j                  ||      }t        j                  ||      r/d|d|d|g}t        j                  t        j                  |d       |}t        j                  |      rzt        j                  |      ret        j                  |      }|j                  |j                   |j"                  |j$                  f}	t'        |dt)        j*                  |      g|	 gS d|g}t        j                  t        j                  |d       t)        j,                  ||      }
dt/        |
      d	|g}t        j                  t        j                  |d       |
D ])  \  }}}|j1                  | j3                  ||||             + |S )
a  Gets a list of Zones from an object that implements the
        AccessibleText specialization.

        Arguments:
        - accessible: the accessible
        - cliprect: the extents that the Zones must fit inside.

        Returns a list of Zones.
        c                 Z    t        j                  |       xs t        j                  |       S r   )r   is_scroll_paneis_documentr   s    r   _is_containerz/Context.getZonesFromText.<locals>._is_container?  s#    --a0NK4K4KA4NNr   zFLAT REVIEW: Cliprectz->fromTr   zFLAT REVIEW: Getting lines forFLAT REVIEW:zlines found for)r   r   hasPresentableTextr   r   r   r   r   is_same_rectr   rz   ry   supports_editable_textr   is_single_liner   r   r   r   r   r   get_all_textget_visible_linesr)   extendr   )r   r0   r   r   r  r   r   r   r}   r>   r   r   r   r   s                 r   getZonesFromTextzContext.getZonesFromText/  s    {{$$77
CI	O **:}E	''	2D&<<T8LL''l;18T4QZ[!!%"2"2FDA**:6;;U;UV`;a''
3Dffdffdjj$++=GZF,?,?
,KVgVWW2J?%**FD9((X> #e*.?L%**FD9.3 	]*FKLL00V[RZ[\	] r   c                    |d   |d   d|d   g}t        j                  |      }|t        j                  j                  k(  r$t        |g|d|i}|r|j                  d|       y|t        j                  j                  k(  r?| j                  j                  j                  |      rt        j                  j                  }|t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  fvryd}d}t        |      dk(  rt!        |d   t"              rq|d   }|j$                  |j$                  z
  }	|d   |d   z   |j$                  |j&                  z   z
  }
|	dkD  }|r|	|d<   n!|j$                  |j&                  z   |d<   |
|d<   t        |g|d|i}|r'|r|j                  d|       y|j)                  |       yy)	zIf the accessible presents non-textual state, such as a
        checkbox or radio button, insert a StateZone representing
        that state.r   r   r   rK   NTrc      )r   rJ   r   rX   TOGGLE_BUTTONr   insertr`   r   r   hasMeaningfulToggleAction	CHECK_BOXr\   RADIO_BUTTONr]   r)   r   r   r   r   r8   )r   r   r0   r>   indicatorExtentsrK   r(   stateOnLefttextZonetextToLeftEdgetextToRightEdges              r   _insertStateZonezContext._insertStateZone\  s    $AJ
AwqzB  ,5::+++ZF*:FFDQ%5::((({{$$>>zJ::''D

,,

22

//

224 4 u:?z%(H=QxH%ZZ'))3N&qzGAJ68::;VWO(2-K&4 #&.jj8>>&A #&5 #B&6BTBQ%T"	 r   c                 h   t        j                  |      }|j                  |j                  |j                  |j
                  f}t        j                  |      }| j                  ||      }|sk|t        j                  j                  t        j                  j                  t        j                  j                  fv r|j                  t        |g|        n|sd}t        j                  j                   g}||vr'| j"                  j$                  j'                  |d      }t        j                  j(                  t        j                  j*                  g}	|s)||	vr%| j"                  j$                  j-                  |      }|r|j                  t/        ||g|        | j1                  |||       |S )z1Returns a list of Zones for the given accessible.r   T)inFlatReview)r   r   r   r   r   r   r   rJ   r  r   rX   rn   SLIDERPROGRESS_BARr8   r   	TABLE_ROWr   r   getNamer`   rY   getRoleNamerG   r  )
r   r0   r   r   r>   rK   r   r   	redundantuselesss
             r   getZonesFromAccessiblezContext.getZonesFromAccessible  sW    ##J/&&$&&$**dkk9  ,%%j(;%**"7"7"'**"3"3"'**"9"9"; ; LL:889F--.I9$44<<ZVZ<[zz,,ejj.>.>?Gd'144@@LT*f?w?@eZ9r   c                 L    |rsy|k(  ryt        j                  |fd      S )NFTc                     | k(  S r   r$   )r   parents    r   r   z#Context._isOrIsIn.<locals>.<lambda>  s    qF{ r   )r   r   )r   childr'  s     `r   	_isOrIsInzContext._isOrIsIn  s)    &F?%%e-BCCr   c                    d| j                         d| j                   d| j                   dd| j                   d| j                   dg}t        j                  t
        j                  |d       | j                  |      }d	|d
|g}t        j                  t
        j                  |d       |yt        | j                        D ]  \  }}||j                  v s|| _        |j                  j                  |      | _        |j                         \  }}|r|j                  | _        || _        d}t        j                  t
        j                  |d        n) d}t        j                  t
        j                  |d       yd| j                         d| j                   d| j                   dd| j                   d| j                   dg}t        j                  t
        j                  |d       y)zJAttempts to set the current zone to obj, if obj is in the current context.zFLAT REVIEW: Currentzline: z, zone: ,zword: z, char: )TzFLAT REVIEW: Zone withisFz"FLAT REVIEW: Updated current zone.z+FLAT REVIEW: Failed to update current zone.zFLAT REVIEW: Updated)getCurrentAccessibler   r   r   r   r   rz   ry   _findZoneWithObjectr6   r   r   r   r   rx   )	r   objr}   r(   r:   r   r   rB   r|   s	            r   setCurrentToZoneWithObjectz"Context.setCurrentToZoneWithObject  s    )$*C*C*E4>>*(4>>2B!D4>>*(4>>2B!DF 	%**FD9'',*Ct<%**FD9< , 	GAttzz!!"!%!1!1$!7#113f%)ZZDN%+DN:""5#3#3S$?	 @Cu//d;($*C*C*E4>>*(4>>2B!D4>>*(4>>2B!DF 	%**FD9r   c                    |y| j                   D ]n  }|j                  |k(  r|c S t        j                  |j                  |      s7d|j                  d|g}t	        j
                  t        j                  |d       |c S  y)z-Returns the existing zone which contains obj.Nr  zis ancestor of zone accessibleT)r   r0   r   is_ancestorr   rz   ry   )r   r0  r(   r}   s       r   r/  zContext._findZoneWithObject  s|     ;JJ 	D#% ##DOOS9($//;[]`a!!%"2"2FDA	 r   c                    || j                   }| j                  j                  j                  ||      }dt	        |      d|g}t        j                  t
        j                  |d       g d}}|D ]  }| j                  ||      }|s9| j                  j                  j                  |      }	|	r| j                  |	|      }|sS|j                  |       |rg|sj| j                  sw| j                  || j                        st        t        d |            xs |}|d   } dt	        |      d|g}t        j                  t
        j                  |d       ||fS )zGReturns an unsorted list of all the zones under root and the focusZone.Nr  zon-screen objects found forTc                 "    | j                         S r   )r   zs    r   r   z)Context.getShowingZones.<locals>.<lambda>  s    ajjl r   r   zzones found for)r   r   r   getOnScreenObjectsr)   r   rz   ry   r$  realActiveDescendantr  r   r)  r   filter)
r   r   boundingboxobjsr}   allZonesr   or   
descendants
             r   r   zContext.getShowingZones  s<    ++K{{$$77kJ #d)-JDQ%**FD9 $) 	%A//;?E![[22GGJ
 77
KPEOOE"4==T^^At}}=]V$:EBCLu!!H		% !#h-1BDI%**FD9""r   c                 8   |sg S g }t        |d       }|j                  d      g}|D ]H  }|j                  |d         r|j                  |       )|j                  t        |d              |g}J |r|j                  t        |d              g }t	        |      D ]D  \  }}|j                  t        ||             t	        |      D ]  \  }	}||   |_        |	|_         F dt        |      dg}
t        j                  t        j                  |
d	       |S )
z?Returns a sorted list of Line clusters containing sorted Zones.c                     | j                   S r   )r   r6  s    r   r   z,Context.clusterZonesByLine.<locals>.<lambda>  s
    !## r   )keyr   rA   c                     | j                   S r   r  r6  s    r   r   z,Context.clusterZonesByLine.<locals>.<lambda>  s
    QSS r   c                     | j                   S r   r  r6  s    r   r   z,Context.clusterZonesByLine.<locals>.<lambda>  s
     r   z!FLAT REVIEW: Zones clustered intor   T)sortedpopru   r8   r6   r   r   r   r)   r   rz   ry   )r   r   lineClusterssortedZones
newClusterr(   r   r   lineClusterr   r}   s              r   r   zContext.clusterZonesByLine  s    IU6!ooa()
 	$Dz"~.!!$'##F:=$IJ"V
	$ z} EF&/&= 	'"I{LLi56#,[#9 '	4!),	&
'	' 6s5z7K%**FD9r   c                    | j                         }|sy|}|t        j                  k(  r|j                  }nq|t        j                  k7  r^|j
                  rR|j
                  | j                     }|t        j                  k(  r&|j                  r	 |j                  | j                     }|j                  |j                  |j                  |j                  |j                  fS # t        $ r Y yw xY w)z;Returns the current string, offset, and extent information.)NrA   rA   rA   rA   )_getCurrentZoner   LINEr   ZONErQ   r   CHARr+   r   r   r   r   r   r   r   )r   flatReviewTyper(   currents       r   
getCurrentzContext.getCurrent$  s     ##%'W\\)iiGw||+

jj0G-'--0%mmDNN;G ~~wyy'))W]]GNNRR ! 0/0s   C   	C,+C,c                     || _         || _        || _        || _        | j	                  t
        j                        | _        y)a=  Sets the current character of interest.

        Arguments:
        - lineIndex: index into lines
        - zoneIndex: index into lines[lineIndex].zones
        - wordIndex: index into lines[lineIndex].zones[zoneIndex].words
        - charIndex: index lines[lineIndex].zones[zoneIndex].words[wordIndex].chars
        N)r   r   r   r   rR  r   rO  r   )r   r   r   r   r   s        r   
setCurrentzContext.setCurrent;  s5     #""""oogll;r   c                     | j                  t        j                        \  }}}}}|dk  r|dk  s
|dk  r|dk  ryt        t	        |||dz  z   dz
              }t        ||dz  z         }||fS )Nr   )rA   rA   rc   r   )rR  r   rO  intre   )r   r   r   r   r   r   s         r   _getClickPointzContext._getClickPointK  sv    &*oogll&C#1eVEa!e!
 AqEAI*+,FQJ!tr   c                 j    | j                         \  }}|dk  s|dk  ryt        j                  ||      S )z3Routes the mouse pointer to the current accessible.r   F)rW  r   route_to_point)r   r   r   s      r   routeToCurrentzContext.routeToCurrentV  s9     ""$1q5AE!00A66r   c                     | j                         \  }}|dk\  r|dk\  rt        j                  |||      ryt        j                  | j	                         |      ryy)z1Performs a mouse click on the current accessible.r   TF)rW  r   click_pointclick_objectr.  )r   buttonr   r   s       r   clickCurrentzContext.clickCurrent_  sW     ""$16a1f!3!?!?1f!M**4+D+D+FOr   c                 .   | j                   r*d| j                  cxk  rt        | j                         k  sy  y | j                   | j                     }|r*d| j                  cxk  rt        |j                        k  sy  y |j                  | j                     S )Nr   )r   r   r)   r   r   )r   r   s     r   rL  zContext._getCurrentZonek  sx    

qDNNDS_D  Ezz$..)dnn>s4::> ?zz$..))r   c                 @    | j                         }|sy|j                  S )zReturns the current accessible.N)rL  r0   )r   r(   s     r   r.  zContext.getCurrentAccessibleu  s"     ##%r   c                    | j                   r#| j                   | j                     j                  sddgS d}| j                   | j                     }|j                         }|j                  D ]  }|j                  | j
                  k(  s|j                  }d|_        |j                  r|xj                  |j                  d   j                  |j                  z
  z  c_        t        d| j                        D ]7  }|xj                  t        |j                  |   j                        z  c_        9 |xj                  | j                  z  c_        |j                           ||gS  ||gS )zbGets the braille for the entire current line.

        Returns [regions, regionWithFocus]
        Nr   )r   r   r   r   r   r   r   cursorOffsetrQ   r   ranger   r)   r   r   repositionCursor)r   regionWithFocusr   regionsr(   r   s         r   getCurrentBrailleRegionsz Context.getCurrentBrailleRegions~  s:    

::dnn-33$<zz$..)((*
 JJ 	DzzT^^+"&"4"4/0,::#00DJJqM4M4MPTP`P`4``0%*1dnn%= >	'44

9 5 < <=>4>  ,,>,002))	 ))r   c                    |t         j                  k(  s|t         j                  k(  r| j                  }n$|t         j                  k(  rd}nt        d|z        |t         j                  k(  r| j                  }nd}d}d}| j                  |k7  xs1 | j                  |k7  xs  | j                  |k7  xs | j                  |k7  }|r@|| _        || _        || _        || _        | j                  t         j                        | _        |S )zMoves this context's locus of interest to the first char
        of the first relevant zone.

        Arguments:
        - flatReviewType: one of ZONE, LINE or WINDOW

        Returns True if the locus of interest actually changed.
        r   Invalid type: %d)r   rM  rN  r   WINDOWr   r   r   r   rR  rO  r   )r   rP  r   r   r   r   moveds          r   goBeginzContext.goBegin  s     gll*',,0NIw~~-I.?@@W\\)II		9, 1NNi/1NNi/1 NNi/ 	
 &DN&DN&DN&DN"&//',,"?Dr   c                 T   |t         j                  k(  s|t         j                  k(  r| j                  }n:|t         j                  k(  rt        | j                        dz
  }nt        d|z        |t         j                  k(  r| j                  }n%t        | j                  |   j                        dz
  }| j                  |   j                  |   }|j                  rEt        |j                        dz
  }|j                  |   j                  }|rt        |      dz
  }nd}nd}d}| j                  |k7  xs1 | j                  |k7  xs  | j                  |k7  xs | j                  |k7  }|r@|| _        || _        || _        || _        | j                  t         j                        | _        |S )zMoves this context's locus of interest to the last char
        of the last relevant zone.

        Arguments:
        - flatReviewType: one of ZONE, LINE, or WINDOW

        Returns True if the locus of interest actually changed.
        r   rj  r   )r   rM  rN  r   rk  r)   r   r   r   r   rQ   r+   r   r   rR  rO  r   )	r   rP  r   r   r(   r   r+   r   rl  s	            r   goEndzContext.goEnd  sl    gll*',,0NIw~~-TZZ1,I.?@@W\\)IDJJy17781<Izz)$**95::DJJ!+IJJy)//EJN		II9, 1NNi/1NNi/1 NNi/ 	
 &DN&DN&DN&DN"&//',,"?Dr   Tc                    | j                   s%t        j                  t        j                  d       yd}|t        j
                  k(  r+| j                  dkD  r'| xj                  dz  c_        d| _        d| _        d}n|t        j                  z  r| j                  dkD  r[| xj                  dz  c_
        t        | j                   | j                     j                        dz
  | _        d| _        d| _        d}n"|t        j                  z  rt        | j                         dz
  | _
        t        | j                   | j                     j                        dz
  | _        d| _        d| _        d}n|t        j                  k(  r| j                  dkD  r| xj                  dz  c_        d}np| j                  t        j                   |d      }|rL| j                   | j                     j                  | j                     }|j"                  r|j"                  | j                     j$                  }|rt        |      dz
  | _        n|t        j                   k(  r| j                   | j                     j                  | j                     }|j&                  }| j                  }| j                  }	| j                  }
| j                  }| j                  dkD  r| xj                  dz  c_        d| _        d}n{| j                  t        j
                  |      }|rY| j                   | j                     j                  | j                     }|j"                  rt        |j"                        dz
  | _        | j                   | j                     j                  | j                     }|r|rt        |j(                        dk(  sHt        |j"                        rX|j"                  | j                     j(                  j+                         r&d}| j                  dkD  rTt-        |t.              rD| j                   | j                  dz
     j                  d   }|j&                  |j&                  k(  rd}|j&                  |k(  s|r!| j                  t        j                   |      }n| j                  dz
  }
|
dk\  ro|j"                  |
   j(                  rIt        |j"                  |
   j(                        r'|j"                  |
   j(                  j+                         r|
dz  }
nn|
dk\  ro|
dk\  r|
| _        |s|| _
        |	| _        |
| _        || _        n|t        j0                  k(  r|t        j                  z  r| j                  dkD  r-| xj                  dz  c_
        d| _        d| _        d| _        d}nn|t        j                  z  r[t        | j                         dk7  rCt        | j                         dz
  | _
        d| _        d| _        d| _        d}nt3        d|z        |r7|t        j0                  k7  r$| j5                  t        j                        | _        |S )ai  Moves this context's locus of interest to the first char
        of the previous type.

        Arguments:
        - flatReviewType: one of ZONE, CHAR, WORD, LINE
        - wrap: if True, will cross boundaries, including top and
                bottom; if False, will stop on boundaries.

        Returns True if the locus of interest actually changed.
        z!goPrevious(): no lines in contextFr   r   TrA   rj  )r   r   rx   ry   r   rN  r   r   r   	WRAP_LINEr   r)   r   WRAP_TOP_BOTTOMrO  
goPreviousWORDrQ   r+   r0   r   isspacer   r   rM  r   rR  r   )r   rP  wrapomitWhitespacerl  r(   r+   r0   r   r   r   r   hasMoreTextprevZones                 r   rs  zContext.goPrevious  s    zzu//1TUW\\)~~!!#!"!")))>>A%NNa'N%(DNN)C)I)I%JQ%NDN%&DN%&DN EG333%(_q%8DN%(DNN)C)I)I%JQ%NDN%&DN%&DN Ew||+~~!!#dEB::dnn5;;DNNKDzz $

4>> : @ @ -0Z!^DNw||+::dnn-33DNNCDJIIII~~!!#!"d;::dnn5;;DNNKDzz),TZZ1)<
 ::dnn-33DNNCD%*DJJ JJt~~6==EEG#>>A%*T8*D#zz$..1*<=CCBGH**doo=&* ??j0K OOGLL$?E $ 2I#q. $

9 5 < <#&tzz)'<'C'C#D#zz)4;;CCE%NI! $q. !A~)2!*!*!*!*w||+g'''>>A%NNa'N%&DN%&DN%&DN EW444djj/Q.%(_q%8DN%&DN%&DN%&DN E.?@@n4"&//',,"?Dr   c                 x   | j                   s%t        j                  t        j                  d       yd}|t        j
                  k(  r&| j                  t        | j                   | j                     j                        dz
  k  r'| xj                  dz  c_        d| _
        d| _        d}nV|t        j                  z  rB| j                  t        | j                         dz
  k  rB| xj                  dz  c_        d| _        d| _
        d| _        d}t        j                          n|t        j                  z  rd| _        d| _        d| _
        d| _        d}t        j                          n|t        j                   k(  r| j                   | j                     j                  | j                     }|j"                  r|j"                  | j                     j$                  }|rW| j                  t        |      dz
  k  r| xj                  dz  c_        d}n| j'                  t        j(                  |d      }n| j'                  t        j(                  |      }n| j'                  t        j
                  |      }n|t        j(                  k(  r| j                   | j                     j                  | j                     }|j*                  }| j                  }| j                  }	| j                  }
| j                  }|j"                  re| j                  t        |j"                        dz
  k  r| xj                  dz  c_
        d| _        d}nA| j'                  t        j
                  |      }n | j'                  t        j
                  |      }| j                   | j                     j                  | j                     }|rZ|rWt        |j,                        dk(  sGt        |j"                        r)|j"                  | j                     j,                  j/                         r|j*                  |k(  r!| j'                  t        j(                  |      }n| j                  dz   }
|
t        |j"                        k  r|j"                  |
   j,                  rIt        |j"                  |
   j,                        r'|j"                  |
   j,                  j/                         r|
dz  }
nn|
t        |j"                        k  r|
t        |j"                        k  r|
| _
        |s|| _        |	| _        |
| _
        || _        n|t        j0                  k(  r|t        j                  z  r| j                  t        | j                         dz
  k  r-| xj                  dz  c_        d| _        d| _
        d| _        d}nO|t        j                  z  r<| j                  dk7  r-d| _        d| _        d| _
        d| _        d}nt3        d|z        |r7|t        j0                  k7  r$| j5                  t        j                         | _        |S )a   Moves this context's locus of interest to first char of
        the next type.

        Arguments:
        - flatReviewType: one of ZONE, CHAR, WORD, LINE
        - wrap: if True, will cross boundaries, including top and
                bottom; if False, will stop on boundaries.
        zgoNext(): no lines in contextFr   r   Trj  )r   r   rx   ry   r   rN  r   r)   r   r   r   r   rq  r   clearrr  rO  rQ   r+   goNextrt  r0   r   ru  rM  r   rR  r   )r   rP  rv  rw  rl  r(   r+   r0   r   r   r   r   s               r   r|  zContext.goNext}  s    zzu//1PQW\\)~~TZZ%?%E%E!F!JK!#!"!")))>>S_q%89NNa'N&'DN%&DN%&DN EMMOG333&'DN&'DN%&DN%&DN EMMOw||+::dnn-33DNNCDzz

4>>288~~Ua8!+ $ $GLL$ F KKd;EGLL$7w||+::dnn-33DNNCDJIIIIzz>>S_q%89NNa'N%&DN E KKd;EGLL$7
 ::dnn-33DNNCD%*DJJ JJt~~6==EEG ??j0 KKd;E $ 2I#c$**o5 $

9 5 < <#&tzz)'<'C'C#D#zz)4;;CCE%NI! $c$**o5 !3tzz?2)2!*!*!*!*w||+g'''>>S_q%89NNa'N%&DN%&DN%&DN EW444..A-%&DN%&DN%&DN%&DN E.?@@n4"&//',,"?Dr   c                 >   d}|t         j                  k(  r| j                  s$| j                  t         j                        | _        | j                  }|\  }}}}}	||dz  z   }
| j	                  t         j
                  |      }|r_	 | j                  t         j                        \  }}}}}||z   |
k\  rn0| j                  t         j                  t         j                        sn^|| _        |S |t         j
                  k(  r| j	                  ||      S t        d|z        )a  Moves this context's locus of interest to first char
        of the type that's closest to and above the current locus of
        interest.

        Arguments:
        - flatReviewType: LINE
        - wrap: if True, will cross top/bottom boundaries; if False, will
                stop on top/bottom boundaries.

        Returns: [string, startOffset, endOffset, x, y, width, height]
        Frc   rj  )	r   rO  r   rR  rs  rM  r|  	WRAP_NONEr   r   rP  rv  rl  targetr   r   r   r   r   middleTargetXbxbybwidthbheights                  r   goAbovezContext.goAbove  s    W\\)
 &&&*oogll&C#((F,2)VQ5&OMOOGLL$7E!__W\\: 6VRVWU
}4![[w7H7HI  #)D  w||+??>488.?@@r   c                 B   d}|t         j                  k(  r| j                  s$| j                  t         j                        | _        | j                  }|\  }}}}}	||dz  z   }
| j	                  t         j
                  |      }|r_	 | j                  t         j                        \  }}}}}||z   |
k\  rn0| j	                  t         j                  t         j                        sn^|| _        |S |t         j
                  k(  r| j	                  ||      }|S t        d|z        )a  Moves this context's locus of interest to the first
        char of the type that's closest to and below the current
        locus of interest.

        Arguments:
        - flatReviewType: one of WORD, LINE
        - wrap: if True, will cross top/bottom boundaries; if False, will
                stop on top/bottom boundaries.

        Returns: [string, startOffset, endOffset, x, y, width, height]
        Frc   rj  )r   rO  r   rR  r|  rM  r~  r   r  s                  r   goBelowzContext.goBelow.  s    W\\)
 &&&*oogll&C#((F,2)VQ5&OMKKd3E!__W\\: 6VRVWU
}4![[w7H7HI  #)D  w||+KK5E  .?@@r   r   )r   )%r    r!   r"   r#   rN  rO  rt  rM  rk  r~  rq  rr  WRAP_ALLr   r   r  r  r$  r)  r1  r/  r   r   rR  rT  rW  rZ  r_  rL  r.  rh  rm  ro  rs  r|  r  r  r$   r   r   r   r     s    LDDDDFIIO ?2H;8z6+Z-#^6D"H*#<< )- S.< 	7
**@ &, %N $* .` )- FP %)x @D &* -^ &* -r   r   )$r#   __id____version____date____copyright____license__girequire_versiongi.repositoryr   rS   r   r   r   r   r	   r
   ax_componentr   ax_event_synthesizerr   	ax_objectr   ax_textr   ax_utilitiesr   EMBEDDED_OBJECT_CHARACTERr   r&   rG   r   r   r   r   r   r$   r   r   <module>r     s   * D2 	   7E "  	      % 4   % %  04 4nC CJ)Nt )NX 2 <_# _#BR Rr   