o
    ѷ6i=7                     @   s  d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 G dd dZ
G dd	 d	ZeG d
d dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG d d! d!ZeG d"d# d#ZeG d$d% d%ZeG d&d' d'ZG d(d) d)ZG d*d+ d+ZdS ),    N)	dataclassfield)Any)command_builder)Sessionc                   @   s&   e Zd ZdZdZdZdZeeehZdS )PointerTypez&Represents the possible pointer types.mousepentouchN)__name__
__module____qualname____doc__MOUSEPENTOUCHVALID_TYPES r   r   i/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/selenium/webdriver/common/bidi/input.pyr      s    r   c                   @   s   e Zd ZdZdZdZdS )Originz%Represents the possible origin types.viewportpointerN)r   r   r   r   VIEWPORTPOINTERr   r   r   r   r   $   s    r   c                   @   s>   e Zd ZU dZeed< eed< defddZdefdd	Zd
S )ElementOriginz/Represents an element origin for input actions.typeelementelement_referencec                 C   s   d| _ || _d S )Nr   r   r   )selfr   r   r   r   __init__2   s   
zElementOrigin.__init__returnc                 C      | j | jdS )z*Convert the ElementOrigin to a dictionary.r   r   r   r   r   r   to_dict6      zElementOrigin.to_dictN)	r   r   r   r   str__annotations__dictr    r$   r   r   r   r   r   +   s   
 r   c                   @   s6   e Zd ZU dZejZeed< dd Z	de
fddZdS )	PointerParametersz2Represents pointer parameters for pointer actions.pointer_typec                 C   s(   | j tjvrtd| j  dtj d S )NzInvalid pointer type: z. Must be one of )r*   r   r   
ValueErrorr#   r   r   r   __post_init__A   s   zPointerParameters.__post_init__r!   c                 C   s
   d| j iS )z.Convert the PointerParameters to a dictionary.pointerType)r*   r#   r   r   r   r$   E   s   
zPointerParameters.to_dictN)r   r   r   r   r   r   r*   r&   r'   r,   r(   r$   r   r   r   r   r)   ;   s
   
 r)   c                   @   s|   e Zd ZU dZdZeed< dZeed< dZe	ed< dZ
e	ed< dZeed	< dZe	ed
< dZe	ed< dd ZdefddZdS )PointerCommonPropertiesz&Common properties for pointer actions.   widthheight        pressuretangential_pressurer   twistaltitude_angleazimuth_anglec                 C   s   | j dk r	td| jdk rtdd| j  kr dks%td tdd| j  kr3dks8td tdd| j  krFd	ksKtd
 td
d| j  kr\tjd ksatd tdd| j	  krrdtj kswtd tdd S )Nr/   zwidth must be at least 1zheight must be at least 1r2   g      ?z$pressure must be between 0.0 and 1.0z/tangential_pressure must be between 0.0 and 1.0r   ig  ztwist must be between 0 and 359   u+   altitude_angle must be between 0.0 and π/2u)   azimuth_angle must be between 0.0 and 2π)
r0   r+   r1   r3   r4   r5   r6   mathpir7   r#   r   r   r   r,   V   s2   

z%PointerCommonProperties.__post_init__r!   c                 C   s   i }| j dkr| j |d< | jdkr| j|d< | jdkr | j|d< | jdkr*| j|d< | jdkr4| j|d< | jdkr>| j|d	< | jdkrH| j|d
< |S )z4Convert the PointerCommonProperties to a dictionary.r/   r0   r1   r2   r3   tangentialPressurer   r5   altitudeAngleazimuthAngle)r0   r1   r3   r4   r5   r6   r7   r   resultr   r   r   r$   f   s    













zPointerCommonProperties.to_dictN)r   r   r   r   r0   intr'   r1   r3   floatr4   r5   r6   r7   r,   r(   r$   r   r   r   r   r.   J   s   
 r.   c                   @   sB   e Zd ZU dZdZedB ed< edefddZ	de
fddZdS )	PauseActionzRepresents a pause action.Ndurationr!   c                 C      dS )Npauser   r#   r   r   r   r         zPauseAction.typec                 C   s"   d| j i}| jdur| j|d< |S )z(Convert the PauseAction to a dictionary.r   NrC   )r   rC   r>   r   r   r   r$      s   


zPauseAction.to_dict)r   r   r   r   rC   r@   r'   propertyr&   r   r(   r$   r   r   r   r   rB   {   s   
 rB   c                   @   >   e Zd ZU dZdZeed< edefddZde	fddZ
d	S )
KeyDownActionzRepresents a key down action. valuer!   c                 C   rD   )NkeyDownr   r#   r   r   r   r      rF   zKeyDownAction.typec                 C   r"   )z*Convert the KeyDownAction to a dictionary.r   rK   rM   r#   r   r   r   r$      r%   zKeyDownAction.to_dictNr   r   r   r   rK   r&   r'   rG   r   r(   r$   r   r   r   r   rI         
 rI   c                   @   rH   )
KeyUpActionzRepresents a key up action.rJ   rK   r!   c                 C   rD   )NkeyUpr   r#   r   r   r   r      rF   zKeyUpAction.typec                 C   r"   )z(Convert the KeyUpAction to a dictionary.rM   rM   r#   r   r   r   r$      r%   zKeyUpAction.to_dictNrN   r   r   r   r   rP      rO   rP   c                   @   sN   e Zd ZU dZdZeed< dZedB ed< e	de
fddZdefd	d
ZdS )PointerDownActionz!Represents a pointer down action.r   buttonN
propertiesr!   c                 C   rD   )NpointerDownr   r#   r   r   r   r      rF   zPointerDownAction.typec                 C   s(   | j | jd}| jr|| j  |S )z.Convert the PointerDownAction to a dictionary.r   rS   )r   rS   rT   updater$   r>   r   r   r   r$      s   zPointerDownAction.to_dict)r   r   r   r   rS   r@   r'   rT   r.   rG   r&   r   r(   r$   r   r   r   r   rR      s   
 rR   c                   @   s>   e Zd ZU dZdZeed< edefddZ	de
fddZd	S )
PointerUpActionzRepresents a pointer up action.r   rS   r!   c                 C   rD   )N	pointerUpr   r#   r   r   r   r      rF   zPointerUpAction.typec                 C   r"   )z,Convert the PointerUpAction to a dictionary.rV   rV   r#   r   r   r   r$      r%   zPointerUpAction.to_dictN)r   r   r   r   rS   r@   r'   rG   r&   r   r(   r$   r   r   r   r   rX      rO   rX   c                   @   s~   e Zd ZU dZdZeed< dZeed< dZe	dB ed< dZ
eeB dB ed< dZedB ed< ed	efd
dZd	efddZdS )PointerMoveActionz!Represents a pointer move action.r   xyNrC   originrT   r!   c                 C   rD   )NpointerMover   r#   r   r   r   r      rF   zPointerMoveAction.typec                 C   sp   | j | j| jd}| jdur| j|d< | jdur+t| jtr&| j |d< n| j|d< | jr6|	| j  |S )z.Convert the PointerMoveAction to a dictionary.)r   r[   r\   NrC   r]   )
r   r[   r\   rC   r]   
isinstancer   r$   rT   rW   r>   r   r   r   r$      s   



zPointerMoveAction.to_dict)r   r   r   r   r[   rA   r'   r\   rC   r@   r]   r&   r   rT   r.   rG   r   r(   r$   r   r   r   r   rZ      s   
 rZ   c                   @   s   e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed< dZ
edB ed< ejZeeB dB ed	< ed
efddZd
efddZdS )WheelScrollActionz!Represents a wheel scroll action.r   r[   r\   delta_xdelta_yNrC   r]   r!   c                 C   rD   )Nscrollr   r#   r   r   r   r      rF   zWheelScrollAction.typec                 C   sd   | j | j| j| j| jd}| jdur| j|d< | jdur0t| jtr+| j	 |d< |S | j|d< |S )z.Convert the WheelScrollAction to a dictionary.)r   r[   r\   deltaXdeltaYNrC   r]   )
r   r[   r\   ra   rb   rC   r]   r_   r   r$   r>   r   r   r   r$      s   



zWheelScrollAction.to_dict)r   r   r   r   r[   r@   r'   r\   ra   rb   rC   r   r   r]   r&   r   rG   r   r(   r$   r   r   r   r   r`      s   
 r`   c                   @   sT   e Zd ZU dZdZeed< eedZ	ee
 ed< edefddZdefd	d
ZdS )NoneSourceActionsz&Represents a sequence of none actions.rJ   iddefault_factoryactionsr!   c                 C   rD   )Nnoner   r#   r   r   r   r     rF   zNoneSourceActions.typec                 C      | j | jdd | jD dS )z.Convert the NoneSourceActions to a dictionary.c                 S      g | ]}|  qS r   r$   .0actionr   r   r   
<listcomp>      z-NoneSourceActions.to_dict.<locals>.<listcomp>r   rg   rj   rt   r#   r   r   r   r$        zNoneSourceActions.to_dictN)r   r   r   r   rg   r&   r'   r   listrj   rB   rG   r   r(   r$   r   r   r   r   rf     s   
 rf   c                   @   s\   e Zd ZU dZdZeed< eedZ	ee
eB eB  ed< edefddZdefd	d
ZdS )KeySourceActionsz%Represents a sequence of key actions.rJ   rg   rh   rj   r!   c                 C   rD   )Nkeyr   r#   r   r   r   r   $  rF   zKeySourceActions.typec                 C   rl   )z-Convert the KeySourceActions to a dictionary.c                 S   rm   r   rn   ro   r   r   r   rr   *  rs   z,KeySourceActions.to_dict.<locals>.<listcomp>rt   rt   r#   r   r   r   r$   (  ru   zKeySourceActions.to_dictN)r   r   r   r   rg   r&   r'   r   rv   rj   rB   rI   rP   rG   r   r(   r$   r   r   r   r   rw     s   
 rw   c                   @   sx   e Zd ZU dZdZeed< dZedB ed< e	e
dZe
eeB eB eB  ed< dd	 Zed
efddZd
efddZdS )PointerSourceActionsz)Represents a sequence of pointer actions.rJ   rg   N
parametersrh   rj   c                 C   s   | j d u rt | _ d S d S N)rz   r)   r#   r   r   r   r,   5  s   
z"PointerSourceActions.__post_init__r!   c                 C   rD   )Nr   r   r#   r   r   r   r   9  rF   zPointerSourceActions.typec                 C   s4   | j | jdd | jD d}| jr| j |d< |S )z1Convert the PointerSourceActions to a dictionary.c                 S   rm   r   rn   ro   r   r   r   rr   B  rs   z0PointerSourceActions.to_dict.<locals>.<listcomp>rt   rz   )r   rg   rj   rz   r$   r>   r   r   r   r$   =  s   zPointerSourceActions.to_dict)r   r   r   r   rg   r&   r'   rz   r)   r   rv   rj   rB   rR   rX   rZ   r,   rG   r   r(   r$   r   r   r   r   ry   -  s   
 "ry   c                   @   sX   e Zd ZU dZdZeed< eedZ	ee
eB  ed< edefddZdefd	d
ZdS )WheelSourceActionsz'Represents a sequence of wheel actions.rJ   rg   rh   rj   r!   c                 C   rD   )Nwheelr   r#   r   r   r   r   P  rF   zWheelSourceActions.typec                 C   rl   )z/Convert the WheelSourceActions to a dictionary.c                 S   rm   r   rn   ro   r   r   r   rr   V  rs   z.WheelSourceActions.to_dict.<locals>.<listcomp>rt   rt   r#   r   r   r   r$   T  ru   zWheelSourceActions.to_dictN)r   r   r   r   rg   r&   r'   r   rv   rj   rB   r`   rG   r   r(   r$   r   r   r   r   r|   I  s   
 r|   c                   @   sH   e Zd ZU dZeed< eed< dZedB ed< e	dedd fdd	Z
dS )
FileDialogInfozERepresents file dialog information from input.fileDialogOpened event.contextmultipleNr   datar!   c                 C   s   | |d |d | ddS )zCreates a FileDialogInfo instance from a dictionary.

        Args:
            data: A dictionary containing the file dialog information.

        Returns:
            FileDialogInfo: A new instance of FileDialogInfo.
        r   r   r   )r   r   r   )get)clsr   r   r   r   	from_dicta  s   
zFileDialogInfo.from_dict)r   r   r   r   r&   r'   boolr   r(   classmethodr   r   r   r   r   r~   Y  s   
 r~   c                   @   s    e Zd ZdZdZedd ZdS )FileDialogOpenedz-Event class for input.fileDialogOpened event.zinput.fileDialogOpenedc                 C   s
   t |S )z%Create FileDialogInfo from JSON data.)r~   r   )r   jsonr   r   r   	from_jsont  s   
zFileDialogOpened.from_jsonN)r   r   r   r   event_classr   r   r   r   r   r   r   o  s
    r   c                   @   s   e Zd ZdZdd ZdedeeeB e	B e
B  ddfdd	Zdeddfd
dZdededee ddfddZdefddZdeddfddZdS )Inputz(BiDi implementation of the input module.c                 C   s   || _ i | _i | _d S r{   )connsubscriptions	callbacks)r   r   r   r   r   r    }  s   
zInput.__init__r   rj   r!   Nc                 C   s*   |dd |D d}| j td| dS )zPerforms a sequence of user input actions.

        Args:
            context: The browsing context ID where actions should be performed.
            actions: A list of source actions to perform.
        c                 S   rm   r   rn   ro   r   r   r   rr     rs   z)Input.perform_actions.<locals>.<listcomp>)r   rj   zinput.performActionsNr   executer   )r   r   rj   paramsr   r   r   perform_actions  s   zInput.perform_actionsc                 C   s   d|i}| j td| dS )zReleases all input state for the given context.

        Args:
            context: The browsing context ID to release actions for.
        r   zinput.releaseActionsNr   )r   r   r   r   r   r   release_actions  s   zInput.release_actionsr   filesc                 C   s"   |||d}| j td| dS )zSets files for a file input element.

        Args:
            context: The browsing context ID.
            element: The element reference (script.SharedReference).
            files: A list of file paths to set.
        )r   r   r   zinput.setFilesNr   )r   r   r   r   r   r   r   r   	set_files  s   zInput.set_filesc                 C   sd   t j| jvrt| j}| j|t j g | jt j< | jt |}| jt j | || j	|< |S )zAdd a handler for file dialog opened events.

        Args:
            handler: Callback function that takes a FileDialogInfo object.

        Returns:
            int: Callback ID for removing the handler later.
        )
r   r   r   r   r   r   	subscribeadd_callbackappendr   )r   handlersessioncallback_idr   r   r   add_file_dialog_handler  s   


zInput.add_file_dialog_handlerr   c                 C   s   || j v r	| j |= tj| jv r:|| jtj v r | jtj | | jtj s:t| j}| j|tj | jtj= | j	t| dS )zRemove a file dialog handler.

        Args:
            callback_id: The callback ID returned by add_file_dialog_handler.
        N)
r   r   r   r   remover   r   r   unsubscriberemove_callback)r   r   r   r   r   r   remove_file_dialog_handler  s   


z Input.remove_file_dialog_handler)r   r   r   r   r    r&   rv   rf   rw   ry   r|   r   r   r(   r   r@   r   r   r   r   r   r   r   z  s    
	r   )r9   dataclassesr   r   typingr   %selenium.webdriver.common.bidi.commonr   &selenium.webdriver.common.bidi.sessionr   r   r   r   r)   r.   rB   rI   rP   rR   rX   rZ   r`   rf   rw   ry   r|   r~   r   r   r   r   r   r   <module>   sN   
0"