A handle to a live range (a span of a page between two boundary points).
A Range works like the JavaScript Range. Get one from Document::createRange() and point it at some content:
A handle to a live range (a span of a page between two boundary points).
Definition Range.h:58
std::string toString() const
Get the text the range covers (toString).
Definition Range.h:463
DOMRect getBoundingClientRect() const
Get the smallest rectangle that contains everything the range covers (getBoundingClientRect).
Definition Range.h:478
void selectNodeContents(const Node &node) const
Make the range cover everything inside a node (selectNodeContents).
Definition Range.h:281
A rectangle in CSS pixels, relative to the viewport (DOMRect).
Definition DOMRect.h:26
Copying a Range copies the handle, so both refer to the same range. Use cloneRange() to make an independent copy.
After its page goes away, a Range stops working like a dom::Element does (see that class).
Boundary Points
Each boundary point is a node plus an offset. In a text or comment node the offset counts UTF-16 code units. In any other node it counts children.
- A new range starts at the document. A boundary point in the document itself reads as an empty Node (the document is never a Node), so point the range at real content first.
- Boundary nodes must come from the range's own document. A node from another document (eg, a subframe's) leaves the range unchanged (with dom::Checked, the call fails with a WrongDocumentError).
Live Updates
The range stays valid while the page changes. When nodes are inserted or removed, the library moves the boundary points to match. If a boundary point's node is removed, the point moves to where that node was in its parent.
Each live range adds a little work to every DOM change in its document, so destroy a Range once you're done with it.
|
| | Range () |
| | Create an empty Range.
|
| | Range (const Range &other) |
| | Copy constructor (both handles refer to the same range).
|
| | Range (Range &&other) noexcept |
| | Move constructor (other becomes empty).
|
| Range & | operator= (Range other) noexcept |
| | Assignment (copies or moves).
|
| | ~Range () |
| | Destroy this handle (the page isn't affected).
|
| | operator bool () const |
| | Whether or not this Range is valid (see IsAlive()).
|
| bool | IsEmpty () const |
| | Whether or not this Range is empty (it holds no handle).
|
| bool | IsAlive () const |
| | Whether or not this Range is valid (it isn't empty and its page is still alive).
|
| Node | startContainer () const |
| | Get the node that holds the range's start (startContainer).
|
| size_t | startOffset () const |
| | Get the offset of the range's start in startContainer() (startOffset).
|
| Node | endContainer () const |
| | Get the node that holds the range's end (endContainer).
|
| size_t | endOffset () const |
| | Get the offset of the range's end in endContainer() (endOffset).
|
| bool | collapsed () const |
| | Whether or not the range's start and end are the same point (collapsed).
|
| Node | commonAncestorContainer () const |
| | Get the deepest node that contains both boundary points (commonAncestorContainer).
|
| void | setStart (const Node &node, size_t offset) const |
| | Set the range's start (setStart).
|
| Result< void > | setStart (const Node &node, size_t offset, Checked_t) const |
| | Same as setStart(), but returns a Result with the reason for a failure (eg, an IndexSizeError if offset is past the end of node).
|
| void | setEnd (const Node &node, size_t offset) const |
| | Set the range's end (setEnd).
|
| Result< void > | setEnd (const Node &node, size_t offset, Checked_t) const |
| | Same as setEnd(), but returns a Result with the reason for a failure (eg, an IndexSizeError if offset is past the end of node).
|
| void | collapse (bool to_start=false) const |
| | Collapse the range to its start or its end (collapse).
|
| void | selectNode (const Node &node) const |
| | Make the range cover a whole node (selectNode).
|
| Result< void > | selectNode (const Node &node, Checked_t) const |
| | Same as selectNode(), but returns a Result with the reason for a failure (eg, an InvalidNodeTypeError if node has no parent).
|
| void | selectNodeContents (const Node &node) const |
| | Make the range cover everything inside a node (selectNodeContents).
|
| Result< void > | selectNodeContents (const Node &node, Checked_t) const |
| | Same as selectNodeContents(), but returns a Result with the reason for a failure (eg, a WrongDocumentError if node is from another document).
|
| int | compareBoundaryPoints (CompareHow how, const Range &other) const |
| | Compare a boundary point of this range with one of another range (compareBoundaryPoints).
|
| Result< int > | compareBoundaryPoints (CompareHow how, const Range &other, Checked_t) const |
| | Same as compareBoundaryPoints(), but returns a Result with the reason for a failure (eg, a WrongDocumentError if the ranges are in different documents).
|
| void | deleteContents () const |
| | Remove the range's contents from the page (deleteContents).
|
| Result< void > | deleteContents (Checked_t) const |
| | Same as deleteContents(), but returns a Result with the reason for a failure.
|
| DocumentFragment | extractContents () const |
| | Move the range's contents out of the page into a new fragment (extractContents).
|
| Result< DocumentFragment > | extractContents (Checked_t) const |
| | Same as extractContents(), but returns a Result with the reason for a failure (eg, a HierarchyRequestError if the range contains a doctype).
|
| DocumentFragment | cloneContents () const |
| | Copy the range's contents into a new fragment (cloneContents).
|
| Result< DocumentFragment > | cloneContents (Checked_t) const |
| | Same as cloneContents(), but returns a Result with the reason for a failure (eg, a HierarchyRequestError if the range contains a doctype).
|
| void | insertNode (const Node &node) const |
| | Insert a node at the range's start (insertNode).
|
| Result< void > | insertNode (const Node &node, Checked_t) const |
| | Same as insertNode(), but returns a Result with the reason for a failure (eg, a HierarchyRequestError if node can't go there).
|
| Range | cloneRange () const |
| | Create an independent copy of the range (cloneRange).
|
| std::string | toString () const |
| | Get the text the range covers (toString).
|
| DOMRect | getBoundingClientRect () const |
| | Get the smallest rectangle that contains everything the range covers (getBoundingClientRect).
|
| std::vector< DOMRect > | getClientRects () const |
| | Get a rectangle for each box the range covers (getClientRects).
|
| ULDOMRange | raw () const |
| | Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMRange.h> functions.
|
| ULDOMRange | LeakRef () |
| | Give up ownership of the C handle and return it.
|