6#include <Ultralight/CAPI/CAPI_DOMDocument.h>
74 std::swap(
detail_.handle, other.detail_.handle);
93 return ulDOMFragmentAppendElement(
raw(), child.
raw(),
nullptr) ? child :
Element();
104 return detail::EmptyHandleError();
105 detail::ErrorScope error;
106 if (ulDOMFragmentAppendElement(
raw(), child.
raw(), error.out()))
108 return Unexpected<Error>(error.TakeError());
124 ULDOMNodeOrString item = detail::NodeItem(child);
125 return ulDOMFragmentAppend(
raw(), &item, 1,
nullptr) ? child :
Node();
136 return detail::EmptyHandleError();
137 ULDOMNodeOrString item = detail::NodeItem(child);
138 detail::ErrorScope error;
139 if (ulDOMFragmentAppend(
raw(), &item, 1, error.out()))
141 return Unexpected<Error>(error.TakeError());
153 template <
typename... T>
154 requires((detail::NodeOrString<T> && ...))
156 auto items = detail::NodeOrStringItems(std::forward<T>(nodes)...);
157 ulDOMFragmentAppend(
raw(), items.data(), items.size(),
nullptr);
168 template <
typename... T>
169 requires((detail::NodeOrString<T> && ...))
171 auto items = detail::NodeOrStringItems(std::forward<T>(nodes)...);
172 if (
IsEmpty() || detail::HasEmptyItem(items))
173 return detail::EmptyHandleError();
174 detail::ErrorScope error;
175 if (ulDOMFragmentAppend(
raw(), items.data(), items.size(), error.out()))
177 return Unexpected<Error>(error.TakeError());
188 template <
typename... T>
189 requires((detail::NodeOrString<T> && ...))
191 auto items = detail::NodeOrStringItems(std::forward<T>(nodes)...);
192 ulDOMFragmentPrepend(
raw(), items.data(), items.size(),
nullptr);
203 template <
typename... T>
204 requires((detail::NodeOrString<T> && ...))
206 auto items = detail::NodeOrStringItems(std::forward<T>(nodes)...);
207 if (
IsEmpty() || detail::HasEmptyItem(items))
208 return detail::EmptyHandleError();
209 detail::ErrorScope error;
210 if (ulDOMFragmentPrepend(
raw(), items.data(), items.size(), error.out()))
212 return Unexpected<Error>(error.TakeError());
248 ULDOMFragment
raw()
const {
return reinterpret_cast<ULDOMFragment
>(
detail_.handle); }
263static_assert(std::is_standard_layout_v<DocumentFragment>,
264 "DocumentFragment must stay standard-layout");
265static_assert(
sizeof(DocumentFragment) ==
sizeof(Node),
266 "DocumentFragment must not declare data members of its own");
269 ulDOMElementAppendFragment(
raw(), fragment.
raw(),
nullptr);
274 return detail::EmptyHandleError();
275 detail::ErrorScope error;
276 if (ulDOMElementAppendFragment(
raw(), fragment.
raw(), error.out()))
278 return Unexpected<Error>(error.TakeError());
A container for assembling DOM nodes off the page.
Definition DocumentFragment.h:43
void prepend(T &&... nodes) const
Add nodes and strings to the start of the fragment, before its first child (prepend).
Definition DocumentFragment.h:190
DocumentFragment()=default
Create an empty DocumentFragment.
ULDOMFragment LeakRef()
Give up ownership of the C handle and return it.
Definition DocumentFragment.h:255
Element appendChild(const Element &child) const
Append an element to the fragment (appendChild).
Definition DocumentFragment.h:92
Result< void > append(Checked_t, T &&... nodes) const
Same as append(), but returns a Result with the reason for a failure.
Definition DocumentFragment.h:170
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.
Definition DocumentFragment.h:134
Result< Element > appendChild(const Element &child, Checked_t) const
Same as appendChild(), but returns a Result with the reason for a failure.
Definition DocumentFragment.h:102
static DocumentFragment Adopt(ULDOMFragment handle)
Wrap a C handle you own, taking ownership of it.
Definition DocumentFragment.h:229
DocumentFragment(ULDOMFragment handle)
Definition DocumentFragment.h:258
Result< void > prepend(Checked_t, T &&... nodes) const
Same as prepend(), but returns a Result with the reason for a failure.
Definition DocumentFragment.h:205
DocumentFragment & operator=(DocumentFragment other) noexcept
Assignment (copies or moves).
Definition DocumentFragment.h:73
Node appendChild(const Node &child) const
Append a node of any kind to the fragment (appendChild).
Definition DocumentFragment.h:123
DocumentFragment(const DocumentFragment &other)
Copy constructor (both handles refer to the same fragment).
Definition DocumentFragment.h:57
DocumentFragment(DocumentFragment &&other) noexcept
Move constructor (other becomes empty).
Definition DocumentFragment.h:64
static DocumentFragment FromBorrowed(ULDOMFragment handle)
Wrap a C handle the library owns, adding a reference.
Definition DocumentFragment.h:238
ULDOMFragment raw() const
Get the C handle, for passing to the C API (eg, ulDOMElementAppendFragment()).
Definition DocumentFragment.h:248
void append(T &&... nodes) const
Add nodes and strings to the end of the fragment (append).
Definition DocumentFragment.h:155
A handle to an element on a page.
Definition Element.h:142
Element appendChild(const Element &child) const
Add an element as the last child of this element (appendChild).
Definition Element.h:676
Element()
Create an empty Element.
Definition Element.h:368
ULDOMElement raw() const
Get the C handle, for passing to the <Ultralight/CAPI/CAPI_DOMElement.h> functions.
Definition Element.h:2006
detail::NodeStorage detail_
Internal storage (not part of the API).
Definition Node.h:166
Node()
Create an empty Node.
Definition Node.h:171
ULDOMNode LeakRef()
Give up ownership of the C handle and return it.
Definition Node.h:546
DocumentFragment AsFragment() const
Get this node as a DocumentFragment.
Definition DocumentFragment.h:281
bool IsEmpty() const
Whether or not this Node is empty (it holds no handle).
Definition Node.h:216
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