|
Ultralight C++ API 2.0.0
|
#include <Ultralight/dom/DocumentFragment.h>
A container for assembling DOM nodes off the page.
A DocumentFragment is a DOM node that holds child nodes outside the document tree. It serves as temporary storage for building content in native code before inserting it into the page.
You can build list items from C++ data off the page and insert them in one call:
Because DocumentFragment inherits from dom::Node, you can pass it to any DOM insertion call.
Inserting a fragment moves all its children into the page in order, leaving the fragment empty. The handle remains valid after insertion, so you can fill it with new nodes and insert it again.
Static Public Member Functions | |
| static DocumentFragment | Adopt (ULDOMFragment handle) |
| Wrap a C handle you own, taking ownership of it. | |
| static DocumentFragment | FromBorrowed (ULDOMFragment handle) |
| Wrap a C handle the library owns, adding a reference. | |
| Static Public Member Functions inherited from Node | |
| static Node | Adopt (ULDOMNode handle) |
| Wrap a C handle you own, taking ownership of it. | |
| static Node | FromBorrowed (ULDOMNode handle) |
| Wrap a C handle the library owns (eg, a callback argument), adding a reference. | |
Public Member Functions | |
| DocumentFragment ()=default | |
| Create an empty DocumentFragment. | |
| DocumentFragment (const DocumentFragment &other) | |
| Copy constructor (both handles refer to the same fragment). | |
| DocumentFragment (DocumentFragment &&other) noexcept | |
| Move constructor (other becomes empty). | |
| DocumentFragment & | operator= (DocumentFragment other) noexcept |
| Assignment (copies or moves). | |
| Element | appendChild (const Element &child) const |
| Append an element to the fragment (appendChild). | |
| Result< Element > | appendChild (const Element &child, Checked_t) const |
| Same as appendChild(), but returns a Result with the reason for a failure. | |
| Node | appendChild (const Node &child) const |
| Append a node of any kind to the fragment (appendChild). | |
| Result< Node > | appendChild (const Node &child, Checked_t) const |
| Same as appendChild() with a Node, but returns a Result with the reason for a failure. | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| void | append (T &&... nodes) const |
| Add nodes and strings to the end of the fragment (append). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| Result< void > | append (Checked_t, T &&... nodes) const |
| Same as append(), but returns a Result with the reason for a failure. | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| void | prepend (T &&... nodes) const |
| Add nodes and strings to the start of the fragment, before its first child (prepend). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| Result< void > | prepend (Checked_t, T &&... nodes) const |
| Same as prepend(), but returns a Result with the reason for a failure. | |
| ULDOMFragment | raw () const |
| Get the C handle, for passing to the C API (eg, ulDOMElementAppendFragment()). | |
| ULDOMFragment | LeakRef () |
| Give up ownership of the C handle and return it. | |
| Public Member Functions inherited from Node | |
| Node () | |
| Create an empty Node. | |
| Node (const Node &other) | |
| Copy constructor (both handles refer to the same node). | |
| Node (Node &&other) noexcept | |
| Move constructor (other becomes empty). | |
| Node & | operator= (Node other) noexcept |
| Assignment (copies or moves). | |
| ~Node () | |
| Destroy this handle (the node itself isn't affected). | |
| operator bool () const | |
| Whether or not this Node is valid (see IsAlive()). | |
| bool | IsEmpty () const |
| Whether or not this Node is empty (it holds no handle). | |
| bool | IsAlive () const |
| Whether or not this Node is valid (it isn't empty and its page is still alive). | |
| bool | IsSame (const Node &other) const |
| Whether or not two handles refer to the same node (isSameNode). | |
| NodeType | nodeType () const |
| Get the kind of node (nodeType). | |
| std::string | nodeName () const |
| Get the node's name (nodeName). | |
| Node | parentNode () const |
| Get the node's parent (parentNode). | |
| Element | parentElement () const |
| Get the node's parent element (parentElement). | |
| Node | firstChild () const |
| Get the node's first child of any kind (firstChild). | |
| Node | lastChild () const |
| Get the node's last child of any kind (lastChild). | |
| Node | previousSibling () const |
| Get the node's previous sibling of any kind (previousSibling). | |
| Node | nextSibling () const |
| Get the node's next sibling of any kind (nextSibling). | |
| NodeList | childNodes () const |
| Get the node's children of every kind in order (childNodes). | |
| bool | hasChildNodes () const |
| Whether or not the node has any children (hasChildNodes). | |
| bool | isConnected () const |
| Whether or not the node is in its document (isConnected). | |
| Document | ownerDocument () const |
| Get the document this node belongs to (ownerDocument). | |
| Element | AsElement () const |
| Get this node as an Element. | |
| DocumentFragment | AsFragment () const |
| Get this node as a DocumentFragment. | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| void | before (T &&... nodes) const |
| Insert nodes and strings just before this node, in its parent (before). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| Result< void > | before (Checked_t, T &&... nodes) const |
| Same as before(), but returns a Result with the reason for a failure (eg, a HierarchyRequestError for a cycle). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| void | after (T &&... nodes) const |
| Insert nodes and strings just after this node, in its parent (after). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| Result< void > | after (Checked_t, T &&... nodes) const |
| Same as after(), but returns a Result with the reason for a failure (eg, a HierarchyRequestError for a cycle). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| void | replaceWith (T &&... nodes) const |
| Replace this node with nodes and strings, in its parent (replaceWith). | |
| template<typename... T> requires ((detail::NodeOrString<T> && ...)) | |
| Result< void > | replaceWith (Checked_t, T &&... nodes) const |
| Same as replaceWith(), but returns a Result with the reason for a failure (eg, a HierarchyRequestError for a cycle). | |
| void | remove () const |
| Remove this node from its parent (remove). | |
| Result< void > | remove (Checked_t) const |
| Same as remove(), but returns a Result with the reason for a failure. | |
| ULDOMNode | raw () const |
| Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMNode.h> functions. | |
| ULDOMNode | LeakRef () |
| Give up ownership of the C handle and return it. | |
Protected Member Functions | |
| DocumentFragment (ULDOMFragment handle) | |
| Protected Member Functions inherited from Node | |
| Node (ULDOMNode handle) | |
Additional Inherited Members | |
| Public Attributes inherited from Node | |
| detail::NodeStringProp< detail::NodeValueTag > | nodeValue |
| The text of a text or comment node (nodeValue). | |
| detail::NodeStringProp< detail::NodeTextContentTag > | textContent |
| The text of this node and all its descendants (textContent). | |
| detail::NodeStorage | detail_ |
| Internal storage (not part of the API). | |
|
default |
Create an empty DocumentFragment.
|
inline |
Copy constructor (both handles refer to the same fragment).
| other | The DocumentFragment to copy. |
|
inlinenoexcept |
Move constructor (other becomes empty).
| other | The DocumentFragment to move from. |
|
inlineexplicitprotected |
|
inlinestatic |
Wrap a C handle you own, taking ownership of it.
| handle | A handle from the C API that you would otherwise destroy with ulDestroyDOMFragment() (NULL gives an empty DocumentFragment). |
|
inlinenodiscard |
Same as append(), but returns a Result with the reason for a failure.
dom::Checked comes first here, before the nodes (batch.append(dom::Checked, row, "x")).
|
inline |
Add nodes and strings to the end of the fragment (append).
Pass any mix of nodes (including elements) and strings. Each string is added as a new text node (it's never parsed as markup).
| nodes | The nodes and strings to add, in order. A node that's already in the page (or in another fragment) moves here. |
Append an element to the fragment (appendChild).
If the element is already in the page (or in another fragment), it moves here.
| child | The element to append. |
Same as appendChild(), but returns a Result with the reason for a failure.
Append a node of any kind to the fragment (appendChild).
Use this for text and comment nodes (eg, from Document::createTextNode()). An Element argument goes to the overload that returns an Element.
| child | The node to append. If it's already in the page (or in another fragment), it moves here. |
Same as appendChild() with a Node, but returns a Result with the reason for a failure.
|
inlinestatic |
Wrap a C handle the library owns, adding a reference.
| handle | The borrowed handle (NULL gives an empty DocumentFragment). |
|
inline |
Give up ownership of the C handle and return it.
This DocumentFragment becomes empty.
|
inlinenoexcept |
Assignment (copies or moves).
| other | The DocumentFragment to assign from. |
|
inlinenodiscard |
Same as prepend(), but returns a Result with the reason for a failure.
dom::Checked comes first here, before the nodes (batch.prepend(dom::Checked, row, "x")).
|
inline |
Add nodes and strings to the start of the fragment, before its first child (prepend).
Works like append().
| nodes | The nodes and strings to add, in order. A node that's already in the page (or in another fragment) moves here. |
|
inline |
Get the C handle, for passing to the C API (eg, ulDOMElementAppendFragment()).