A stale element is an element no longer attached to the DOM or which
node document is not the active document of the current browsing
context.

The currently selected browsing context, specified through
<var>window<var>, is a WebDriver concept defining the target
against which commands will run. As the current browsing context
may differ from <var>el</var>’s associated context, an element is
considered stale even if it is connected to a living (not discarded)
browsing context such as an <tt>&lt;iframe&gt;</tt>.

Arguments:

el (Element) – DOM element to check for staleness. If null, which may be the case if the element has been unwrapped from a weak reference, it is always considered stale.

win (WindowProxy) – Current browsing context, which may differ from the associate browsing context of <var>el</var>. When retrieving XUL elements, this is optional.

An element is considered editable if it is not read-only or
disabled, and one of the following conditions are met:

<ul>
<li>It is a <code>&lt;textarea&gt;</code> element.

<li>It is an <code>&lt;input&gt;</code> element that is not of
the <code>checkbox</code>, <code>radio</code>, <code>hidden</code>,
<code>submit</code>, <code>button</code>, or <code>image</code> types.

An element container is defined by the WebDriver
specification to be an <tt>&lt;option&gt;</tt> element in a
<a href=”https://html.spec.whatwg.org/#concept-element-contexts”>valid
element context</a>, meaning that it has an ancestral element
that is either <tt>&lt;datalist&gt;</tt> or <tt>&lt;select&gt;</tt>.

If the element does not have a valid context, its container element
is itself.

An element is in view if it is a member of its own pointer-interactable
paint tree.

This means an element is considered to be in view, but not necessarily
pointer-interactable, if it is found somewhere in the
<code>elementsFromPoint</code> list at <var>el</var>’s in-view
centre coordinates.

Before running the check, we change <var>el</var>’s pointerEvents
style property to “auto”, since elements without pointer events
enabled do not turn up in the paint tree we get from
document.elementsFromPoint. This is a specialisation that is only
relevant when checking if the element is in view.

Arguments:

el (Element) – Element to check if is in view.

Returns:

boolean – True if <var>el</var> is inside the viewport, or false otherwise.

A pointer-interactable element is defined to be the first
non-transparent element, defined by the paint order found at the centre
point of its rectangle that is inside the viewport, excluding the size
of any rendered scrollbars.

An element is obscured if the pointer-interactable paint tree at its
centre point is empty, or the first element in this tree is not an
inclusive descendant of itself.

The portion of an element that is said to be _in view_, is the
intersection of two squares: the first square being the initial
viewport, and the second a DOM element. From this square we
calculate the in-view _centre point_ and convert it into CSS pixels.

Although Gecko’s system internals allow click points to be
given in floating point precision, the DOM operates in CSS pixels.
When the in-view centre point is later used to retrieve a coordinate’s
paint tree, we need to ensure to operate in the same language.

As a word of warning, there appears to be inconsistencies between
how DOMElement.elementsFromPoint and DOMWindowUtils.sendMouseEvent
internally rounds (ceils/floors) coordinates.

Arguments:

rect (DOMRect) – Element off a DOMRect sequence produced by calling getClientRects on an {@link Element}.

win (WindowProxy) – Current window global.

Returns:

Map.<string, number> – X and Y coordinates that denotes the in-view centre point of rect.

Constructs a {@link ContentWebElement} or {@link ChromeWebElement}
from a a string <var>uuid</var>.

This whole function is a workaround for the fact that clients
to Marionette occasionally pass <code>{id: <uuid>}</code> JSON
Objects instead of web element representations. For that reason
we need the <var>context</var> argument to determine what kind of
{@link WebElement} to return.

Arguments:

uuid (string) – UUID to be associated with the web element.

context (Context) – Context, which is used to determine if the returned type should be a content web element or a chrome web element.

Throws:

InvalidArgumentError – If <var>uuid</var> is not a string or <var>context</var> is an invalid context.

Returns:

WebElement – One of {@link ContentWebElement} or {@link ChromeWebElement}, based on <var>context</var>.