docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C++ API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
DOM.h
Go to the documentation of this file.
1
///
2
/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3
/// A license is required for commercial use. https://ultralig.ht
4
///
5
6
///
7
/// @namespace ultralight::dom
8
///
9
/// Direct C++ access to modify page elements and handle events.
10
///
11
/// `#include <Ultralight/DOM.h>`
12
///
13
/// @note This API is a preview and may still change after 2.0.
14
///
15
/// The DOM API connects your application to the HTML pages a View loads, letting native code update
16
/// the user interface and respond to user input.
17
///
18
/// Names and behavior follow the web's DOM, so page script ports over nearly line for line.
19
///
20
/// This example configures a DOM-ready hook and a click listener on a View before loading a page:
21
///
22
/// ```
23
/// dom::Triggers page;
24
///
25
/// page.OnDOMReady([](dom::Document document) {
26
/// auto status = document.getElementById("status");
27
/// status.textContent = "Connected";
28
/// status.classList.add("online");
29
/// });
30
///
31
/// page.On("#save", "click", [](dom::Element button) {
32
/// button.textContent = "Saved";
33
/// });
34
///
35
/// if (page.AttachTo(view.get()))
36
/// view->LoadURL("file:///app.html");
37
/// ```
38
///
39
/// ## Accessing Page Content
40
///
41
/// You can interact with a View through persistent listeners or a direct document handle:
42
///
43
/// - **Attach a dom::Triggers set to handle every page a View loads.** Listeners and hooks persist
44
/// across navigations until you detach the set or destroy the object.
45
/// - **Obtain a dom::Document from the View in LoadListener::OnDOMReady().** The handle applies to
46
/// the current page only.
47
///
48
/// ## Where to Start
49
///
50
/// Recommended types and headers for common tasks:
51
///
52
/// | Task | Starting Point |
53
/// |--------------------------------|----------------------------------|
54
/// | Finding and changing elements | dom::Document, dom::Element |
55
/// | Listening for events | dom::Element::addEventListener() |
56
/// | Viewport and window events | dom::Window |
57
/// | Inspecting call failures | dom::Error |
58
/// | Passing elements to JavaScript | `<Ultralight/dom/JSInterop.h>` |
59
///
60
/// ## Rules for All DOM Types
61
///
62
/// Every DOM class follows these common conventions:
63
///
64
/// - **Call DOM operations on the Renderer's thread.** To work with the DOM from another thread,
65
/// post tasks using Renderer::PostTask(). Copying, moving, and destroying handles is safe on any
66
/// thread.
67
/// - **A handle never keeps its page alive.** Once a page navigates away, calls on its handles fail
68
/// safely (for handle states, see dom::Element).
69
/// - **The API never throws C++ exceptions.** A call that fails returns an empty value, or a
70
/// dom::Result holding a dom::Error if you pass dom::Checked.
71
/// - **Callbacks that throw are caught and logged.**
72
/// - **A const handle can still modify its node.** Constness applies to the handle itself rather
73
/// than the page element, so you can still assign to properties and insert child nodes.
74
/// - **Counts and indices use `size_t`.** Where web standards return `-1` or `null` for a missing
75
/// position, methods return `std::optional<size_t>` holding `std::nullopt`.
76
///
77
/// @note The DOM API works even with JavaScript disabled
78
/// (`ViewConfig::enable_javascript = false`).
79
///
80
/// @see dom::Document, dom::Element, dom::Triggers, LoadListener::OnDOMReady()
81
///
82
#pragma once
83
#include <
Ultralight/dom/Triggers.h
>
84
#include <
Ultralight/Color.h
>
85
#include <
Ultralight/dom/ComputedStyle.h
>
86
#include <
Ultralight/dom/CSSPropertyName.h
>
87
#include <
Ultralight/dom/Document.h
>
88
#include <
Ultralight/dom/DocumentFragment.h
>
89
#include <
Ultralight/dom/DOMRect.h
>
90
#include <
Ultralight/dom/Element.h
>
91
#include <
Ultralight/dom/ElementList.h
>
92
#include <
Ultralight/dom/Error.h
>
93
#include <
Ultralight/dom/Event.h
>
94
#include <
Ultralight/dom/EventListener.h
>
95
#include <
Ultralight/dom/Node.h
>
96
#include <
Ultralight/dom/NodeList.h
>
97
#include <
Ultralight/dom/Range.h
>
98
#include <
Ultralight/dom/Selection.h
>
99
#include <
Ultralight/dom/StyleValue.h
>
100
#include <
Ultralight/dom/Window.h
>
CSSPropertyName.h
Color.h
ComputedStyle.h
DOMRect.h
Document.h
DocumentFragment.h
Element.h
ElementList.h
Event.h
EventListener.h
Node.h
NodeList.h
Range.h
Selection.h
StyleValue.h
Triggers.h
Window.h
Error.h
Ultralight
DOM.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4