6#include <Ultralight/CAPI/CAPI_DOMRange.h>
65 StartToStart = kULDOMRangeCompareHow_StartToStart,
66 StartToEnd = kULDOMRangeCompareHow_StartToEnd,
67 EndToEnd = kULDOMRangeCompareHow_EndToEnd,
68 EndToStart = kULDOMRangeCompareHow_EndToStart,
99 std::swap(
handle_, other.handle_);
111 explicit operator bool()
const {
return IsAlive(); }
185 ulDOMRangeSetStart(
handle_, node.
raw(), offset,
nullptr);
198 return detail::EmptyHandleError();
199 detail::ErrorScope error;
200 if (ulDOMRangeSetStart(
handle_, node.
raw(), offset, error.out()))
202 return Unexpected<Error>(error.TakeError());
218 ulDOMRangeSetEnd(
handle_, node.
raw(), offset,
nullptr);
231 return detail::EmptyHandleError();
232 detail::ErrorScope error;
233 if (ulDOMRangeSetEnd(
handle_, node.
raw(), offset, error.out()))
235 return Unexpected<Error>(error.TakeError());
265 return detail::EmptyHandleError();
266 detail::ErrorScope error;
267 if (ulDOMRangeSelectNode(
handle_, node.
raw(), error.out()))
269 return Unexpected<Error>(error.TakeError());
282 ulDOMRangeSelectNodeContents(
handle_, node.
raw(),
nullptr);
294 return detail::EmptyHandleError();
295 detail::ErrorScope error;
296 if (ulDOMRangeSelectNodeContents(
handle_, node.
raw(), error.out()))
298 return Unexpected<Error>(error.TakeError());
316 ulDOMRangeCompareBoundaryPoints(
handle_,
static_cast<ULDOMRangeCompareHow
>(how),
317 other.
handle_, &result,
nullptr);
332 return detail::EmptyHandleError();
333 detail::ErrorScope error;
335 if (ulDOMRangeCompareBoundaryPoints(
handle_,
336 static_cast<ULDOMRangeCompareHow
>(how),
337 other.
handle_, &result, error.out()))
339 return Unexpected<Error>(error.TakeError());
358 return detail::EmptyHandleError();
359 detail::ErrorScope error;
360 if (ulDOMRangeDeleteContents(
handle_, error.out()))
362 return Unexpected<Error>(error.TakeError());
387 return detail::EmptyHandleError();
388 detail::ErrorScope error;
389 if (ULDOMFragment fragment = ulDOMRangeExtractContents(
handle_, error.out()))
391 return Unexpected<Error>(error.TakeError());
412 return detail::EmptyHandleError();
413 detail::ErrorScope error;
414 if (ULDOMFragment fragment = ulDOMRangeCloneContents(
handle_, error.out()))
416 return Unexpected<Error>(error.TakeError());
443 return detail::EmptyHandleError();
444 detail::ErrorScope error;
445 if (ulDOMRangeInsertNode(
handle_, node.
raw(), error.out()))
447 return Unexpected<Error>(error.TakeError());
464 return detail::TakeString(ulDOMRangeToString(
handle_));
479 ULDOMRect rect = ulDOMRangeGetBoundingClientRect(
handle_);
480 return DOMRect { rect.x, rect.y, rect.width, rect.height };
500 size_t count = ulDOMRangeGetClientRects(
handle_, local, 8);
501 std::vector<DOMRect> rects;
502 rects.reserve(count);
504 for (
size_t i = 0; i < count; i++)
505 rects.push_back(
DOMRect { local[i].x, local[i].y, local[i].width, local[i].height });
508 std::vector<ULDOMRect> raw_rects(count);
509 ulDOMRangeGetClientRects(
handle_, raw_rects.data(), raw_rects.size());
510 for (
const ULDOMRect& rect : raw_rects)
511 rects.push_back(
DOMRect { rect.x, rect.y, rect.width, rect.height });
535 return Range(handle ? ulCreateDOMRangeRef(handle) :
nullptr);
A container for assembling DOM nodes off the page.
Definition DocumentFragment.h:43
static DocumentFragment Adopt(ULDOMFragment handle)
Wrap a C handle you own, taking ownership of it.
Definition DocumentFragment.h:229
A reference to an item in the DOM tree.
Definition Node.h:147
ULDOMNode raw() const
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMNode.h> functions.
Definition Node.h:539
static Node Adopt(ULDOMNode handle)
Wrap a C handle you own, taking ownership of it.
Definition Node.h:520
bool IsEmpty() const
Whether or not this Node is empty (it holds no handle).
Definition Node.h:216
size_t startOffset() const
Get the offset of the range's start in startContainer() (startOffset).
Definition Range.h:139
Result< DocumentFragment > cloneContents(Checked_t) const
Same as cloneContents(), but returns a Result with the reason for a failure (eg, a HierarchyRequestEr...
Definition Range.h:410
Range & operator=(Range other) noexcept
Assignment (copies or moves).
Definition Range.h:98
size_t endOffset() const
Get the offset of the range's end in endContainer() (endOffset).
Definition Range.h:151
static Range Adopt(ULDOMRange handle)
Wrap a C handle you own, taking ownership of it.
Definition Range.h:525
std::string toString() const
Get the text the range covers (toString).
Definition Range.h:463
DocumentFragment extractContents() const
Move the range's contents out of the page into a new fragment (extractContents).
Definition Range.h:374
ULDOMRange LeakRef()
Give up ownership of the C handle and return it.
Definition Range.h:551
void insertNode(const Node &node) const
Insert a node at the range's start (insertNode).
Definition Range.h:431
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...
Definition Range.h:263
Range cloneRange() const
Create an independent copy of the range (cloneRange).
Definition Range.h:456
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 offs...
Definition Range.h:196
void collapse(bool to_start=false) const
Collapse the range to its start or its end (collapse).
Definition Range.h:243
DOMRect getBoundingClientRect() const
Get the smallest rectangle that contains everything the range covers (getBoundingClientRect).
Definition Range.h:478
DocumentFragment cloneContents() const
Copy the range's contents into a new fragment (cloneContents).
Definition Range.h:399
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,...
Definition Range.h:329
ULDOMRange handle_
Definition Range.h:560
Result< DocumentFragment > extractContents(Checked_t) const
Same as extractContents(), but returns a Result with the reason for a failure (eg,...
Definition Range.h:385
Node startContainer() const
Get the node that holds the range's start (startContainer).
Definition Range.h:132
bool collapsed() const
Whether or not the range's start and end are the same point (collapsed).
Definition Range.h:159
void selectNode(const Node &node) const
Make the range cover a whole node (selectNode).
Definition Range.h:254
Range(Range &&other) noexcept
Move constructor (other becomes empty).
Definition Range.h:89
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...
Definition Range.h:229
void selectNodeContents(const Node &node) const
Make the range cover everything inside a node (selectNodeContents).
Definition Range.h:281
ULDOMRange raw() const
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMRange.h> functions.
Definition Range.h:544
~Range()
Destroy this handle (the page isn't affected).
Definition Range.h:106
bool IsEmpty() const
Whether or not this Range is empty (it holds no handle).
Definition Range.h:116
bool IsAlive() const
Whether or not this Range is valid (it isn't empty and its page is still alive).
Definition Range.h:123
Range(const Range &other)
Copy constructor (both handles refer to the same range).
Definition Range.h:81
Result< void > deleteContents(Checked_t) const
Same as deleteContents(), but returns a Result with the reason for a failure.
Definition Range.h:356
std::vector< DOMRect > getClientRects() const
Get a rectangle for each box the range covers (getClientRects).
Definition Range.h:495
Result< void > selectNodeContents(const Node &node, Checked_t) const
Same as selectNodeContents(), but returns a Result with the reason for a failure (eg,...
Definition Range.h:292
void deleteContents() const
Remove the range's contents from the page (deleteContents).
Definition Range.h:349
Node endContainer() const
Get the node that holds the range's end (endContainer).
Definition Range.h:146
void setEnd(const Node &node, size_t offset) const
Set the range's end (setEnd).
Definition Range.h:217
static Range FromBorrowed(ULDOMRange handle)
Wrap a C handle you don't own, adding a reference.
Definition Range.h:534
int compareBoundaryPoints(CompareHow how, const Range &other) const
Compare a boundary point of this range with one of another range (compareBoundaryPoints).
Definition Range.h:314
Node commonAncestorContainer() const
Get the deepest node that contains both boundary points (commonAncestorContainer).
Definition Range.h:166
Range(ULDOMRange handle)
Definition Range.h:558
void setStart(const Node &node, size_t offset) const
Set the range's start (setStart).
Definition Range.h:184
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...
Definition Range.h:441
Range()
Create an empty Range.
Definition Range.h:74
CompareHow
Which boundary points compareBoundaryPoints() compares (the web's Range.START_TO_START constants).
Definition Range.h:64
Direct C++ access to modify page elements and handle events.
Expected< T, Error > Result
The result of a DOM operation that can fail (either a T or a dom::Error).
Definition Error.h:277
Root namespace for every public Ultralight type, function, and enumeration.
The type of dom::Checked.
Definition Error.h:282
A rectangle in CSS pixels, relative to the viewport (DOMRect).
Definition DOMRect.h:26