6#include <Ultralight/CAPI/CAPI_DOMSelection.h>
122 other.handle_ =
nullptr;
133 std::swap(
handle_, other.handle_);
145 explicit operator bool()
const {
return IsAlive(); }
205 std::string
type()
const {
return detail::TakeString(ulDOMSelectionGetType(
handle_)); }
211 return detail::TakeString(ulDOMSelectionToString(
handle_));
226 ulDOMSelectionCollapse(
handle_, node.
raw(), offset,
nullptr);
247 return detail::EmptyHandleError();
248 detail::ErrorScope error;
249 if (ulDOMSelectionCollapse(
handle_, node.
raw(), offset, error.out()))
251 return Unexpected<Error>(error.TakeError());
267 return detail::EmptyHandleError();
268 detail::ErrorScope error;
269 if (ulDOMSelectionCollapseToStart(
handle_, error.out()))
271 return Unexpected<Error>(error.TakeError());
287 return detail::EmptyHandleError();
288 detail::ErrorScope error;
289 if (ulDOMSelectionCollapseToEnd(
handle_, error.out()))
291 return Unexpected<Error>(error.TakeError());
306 ulDOMSelectionExtend(
handle_, node.
raw(), offset,
nullptr);
329 return detail::EmptyHandleError();
330 detail::ErrorScope error;
331 if (ulDOMSelectionExtend(
handle_, node.
raw(), offset, error.out()))
333 return Unexpected<Error>(error.TakeError());
360 size_t focus_offset)
const {
361 ulDOMSelectionSetBaseAndExtent(
handle_, anchor_node.
raw(), anchor_offset, focus_node.
raw(),
362 focus_offset,
nullptr);
372 size_t anchor_offset,
373 const Node& focus_node,
377 return detail::EmptyHandleError();
378 detail::ErrorScope error;
379 if (ulDOMSelectionSetBaseAndExtent(
handle_, anchor_node.
raw(), anchor_offset,
380 focus_node.
raw(), focus_offset, error.out()))
382 return Unexpected<Error>(error.TakeError());
392 ulDOMSelectionSelectAllChildren(
handle_, node.
raw(),
nullptr);
402 return detail::EmptyHandleError();
403 detail::ErrorScope error;
404 if (ulDOMSelectionSelectAllChildren(
handle_, node.
raw(), error.out()))
406 return Unexpected<Error>(error.TakeError());
452 return detail::EmptyHandleError();
453 detail::ErrorScope error;
454 if (ULDOMRange range = ulDOMSelectionGetRangeAt(
handle_, index, error.out()))
456 return Unexpected<Error>(error.TakeError());
478 return ulDOMSelectionContainsNode(
handle_, node.
raw(), partial);
495 void modify(std::string_view alter, std::string_view direction,
496 std::string_view granularity)
const {
497 detail::CString a(alter);
498 detail::CString d(direction);
499 detail::CString g(granularity);
500 ulDOMSelectionModify(
handle_, a.c_str(), d.c_str(), g.c_str());
523 return Selection(handle ? ulCreateDOMSelectionRef(handle) :
nullptr);
540 ULDOMSelection handle =
handle_;
558 ulDestroyDOMDocument(doc);
struct C_DOMDocument * ULDOMDocument
Opaque handle to a page's DOM document.
Definition View.h:39
Selection getSelection() const
Get the document's selection (getSelection).
Definition Selection.h:551
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
A handle to a live range (a span of a page between two boundary points).
Definition Range.h:58
static Range Adopt(ULDOMRange handle)
Wrap a C handle you own, taking ownership of it.
Definition Range.h:525
ULDOMRange raw() const
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMRange.h> functions.
Definition Range.h:544
A handle to the active user selection or caret in a document.
Definition Selection.h:101
size_t focusOffset() const
Get the offset of the focus in focusNode() (focusOffset).
Definition Selection.h:183
void addRange(const Range &range) const
Select a range (addRange).
Definition Selection.h:426
void selectAllChildren(const Node &node) const
Select everything inside a node (selectAllChildren).
Definition Selection.h:391
Selection & operator=(Selection other) noexcept
Assignment (copies or moves).
Definition Selection.h:132
Result< void > selectAllChildren(const Node &node, Checked_t) const
Same as selectAllChildren(), but returns a Result with the reason for a failure.
Definition Selection.h:400
Result< void > collapse(const Node &node, Checked_t) const
Same as collapse(), but returns a Result with the reason for a failure.
Definition Selection.h:235
bool isCollapsed() const
Whether or not the selection is a caret (isCollapsed).
Definition Selection.h:191
void collapseToStart() const
Collapse the selection to its start (collapseToStart).
Definition Selection.h:257
std::string toString() const
Get the selected text (toString).
Definition Selection.h:210
Result< void > collapse(const Node &node, size_t offset, Checked_t) const
Same as collapse() with an offset, but returns a Result with the reason for a failure.
Definition Selection.h:245
bool containsNode(const Node &node, bool partial=false) const
Whether or not a node is in the selection (containsNode).
Definition Selection.h:477
size_t rangeCount() const
Get the number of ranges in the selection (rangeCount).
Definition Selection.h:198
void collapseToEnd() const
Collapse the selection to its end (collapseToEnd).
Definition Selection.h:277
Result< void > collapseToStart(Checked_t) const
Same as collapseToStart(), but returns a Result with the reason for a failure (eg,...
Definition Selection.h:265
void removeAllRanges() const
Clear the selection (removeAllRanges or empty).
Definition Selection.h:412
~Selection()
Destroy this handle (the selection itself isn't affected).
Definition Selection.h:140
Result< void > extend(const Node &node, Checked_t) const
Same as extend(), but returns a Result with the reason for a failure (eg, an InvalidStateError if not...
Definition Selection.h:316
Selection(const Selection &other)
Copy constructor (both handles refer to the same selection).
Definition Selection.h:113
Result< void > collapseToEnd(Checked_t) const
Same as collapseToEnd(), but returns a Result with the reason for a failure (eg, an InvalidStateError...
Definition Selection.h:285
ULDOMSelection raw() const
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMSelection.h> functions.
Definition Selection.h:532
Selection(Selection &&other) noexcept
Move constructor (other becomes empty).
Definition Selection.h:121
Range getRangeAt(size_t index) const
Get a range with the selection's start and end (getRangeAt).
Definition Selection.h:439
void modify(std::string_view alter, std::string_view direction, std::string_view granularity) const
Move or extend the selection by a unit of text (modify), like the arrow keys do.
Definition Selection.h:495
bool IsEmpty() const
Whether or not this Selection is empty (it holds no handle).
Definition Selection.h:150
bool IsAlive() const
Whether or not this Selection is valid (it isn't empty and its page is still alive).
Definition Selection.h:157
std::string type() const
Get the kind of selection (type).
Definition Selection.h:205
void collapse(const Node &node, size_t offset=0) const
Place a caret (collapse or setPosition).
Definition Selection.h:225
Result< void > extend(const Node &node, size_t offset, Checked_t) const
Same as extend() with an offset, but returns a Result with the reason for a failure (eg,...
Definition Selection.h:327
static Selection FromBorrowed(ULDOMSelection handle)
Wrap a C handle you don't own, adding a reference.
Definition Selection.h:522
static Selection Adopt(ULDOMSelection handle)
Wrap a C handle you own, taking ownership of it.
Definition Selection.h:513
void setBaseAndExtent(const Node &anchor_node, size_t anchor_offset, const Node &focus_node, size_t focus_offset) const
Set the anchor and the focus in one call (setBaseAndExtent).
Definition Selection.h:359
Node anchorNode() const
Get the node the selection starts in (anchorNode).
Definition Selection.h:166
Selection()
Create an empty Selection.
Definition Selection.h:106
Selection(ULDOMSelection handle)
Definition Selection.h:546
void deleteFromDocument() const
Remove the selected content from the page (deleteFromDocument).
Definition Selection.h:464
Result< void > setBaseAndExtent(const Node &anchor_node, size_t anchor_offset, const Node &focus_node, size_t focus_offset, Checked_t) const
Same as setBaseAndExtent(), but returns a Result with the reason for a failure.
Definition Selection.h:371
size_t anchorOffset() const
Get the offset of the anchor in anchorNode() (anchorOffset).
Definition Selection.h:171
void extend(const Node &node, size_t offset=0) const
Move the focus and keep the anchor where it is (extend).
Definition Selection.h:305
Node focusNode() const
Get the node the selection ends in (focusNode).
Definition Selection.h:178
ULDOMSelection handle_
Definition Selection.h:548
Result< Range > getRangeAt(size_t index, Checked_t) const
Same as getRangeAt(), but returns a Result with the reason for a failure (eg, an IndexSizeError if in...
Definition Selection.h:450
ULDOMSelection LeakRef()
Give up ownership of the C handle and return it.
Definition Selection.h:539
Selection getSelection() const
Get the page's selection (getSelection), the caret or the highlighted text.
Definition Selection.h:555
Direct C++ access to modify page elements and handle events.
constexpr Checked_t Checked
Pass to a DOM call to get a dom::Result holding the reason for a failure instead of an empty value.
Definition Error.h:299
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