From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- layout/base/tests/marionette/selection.py | 337 ++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 layout/base/tests/marionette/selection.py (limited to 'layout/base/tests/marionette/selection.py') diff --git a/layout/base/tests/marionette/selection.py b/layout/base/tests/marionette/selection.py new file mode 100644 index 0000000000..40e4e052df --- /dev/null +++ b/layout/base/tests/marionette/selection.py @@ -0,0 +1,337 @@ +# -*- coding: utf-8 -*- +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from __future__ import absolute_import + +from marionette_driver.marionette import Actions, errors + + +class CaretActions(Actions): + def __init__(self, marionette): + super(CaretActions, self).__init__(marionette) + self._reset_action_chain() + + def _reset_action_chain(self): + self.mouse_chain = self.sequence( + "pointer", "pointer_id", {"pointerType": "mouse"} + ) + self.key_chain = self.sequence("key", "keyboard_id") + + def flick(self, element, x1, y1, x2, y2, duration=200): + """Perform a flick gesture on the target element. + + :param element: The element to perform the flick gesture on. + :param x1: Starting x-coordinate of flick, relative to the top left + corner of the element. + :param y1: Starting y-coordinate of flick, relative to the top left + corner of the element. + :param x2: Ending x-coordinate of flick, relative to the top left + corner of the element. + :param y2: Ending y-coordinate of flick, relative to the top left + corner of the element. + + """ + rect = element.rect + el_x, el_y = rect["x"], rect["y"] + + # Add element's (x, y) to make the coordinate relative to the viewport. + from_x, from_y = int(el_x + x1), int(el_y + y1) + to_x, to_y = int(el_x + x2), int(el_y + y2) + + self.mouse_chain.pointer_move(from_x, from_y).pointer_down().pointer_move( + to_x, to_y, duration=duration + ).pointer_up() + return self + + def send_keys(self, keys): + """Perform a keyDown and keyUp action for each character in `keys`. + + :param keys: String of keys to perform key actions with. + + """ + self.key_chain.send_keys(keys) + return self + + def perform(self): + """Perform the action chain built so far to the server side for execution + and clears the current chain of actions. + + Warning: This method performs all the mouse actions before all the key + actions! + + """ + self.mouse_chain.perform() + self.key_chain.perform() + self._reset_action_chain() + + +class SelectionManager(object): + """Interface for manipulating the selection and carets of the element. + + We call the blinking cursor (nsCaret) as cursor, and call AccessibleCaret as + caret for short. + + Simple usage example: + + :: + + element = marionette.find_element(By.ID, 'input') + sel = SelectionManager(element) + sel.move_caret_to_front() + + """ + + def __init__(self, element): + self.element = element + + def _input_or_textarea(self): + """Return True if element is either or