@geastack/engine 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +29 -0
- package/bitmap_font.cpp +165 -0
- package/canvas.cpp +4608 -0
- package/components/Button.d.ts +4 -0
- package/components/Button.tsx +32 -0
- package/components/Image.d.ts +3 -0
- package/components/Image.tsx +17 -0
- package/components/Text.d.ts +3 -0
- package/components/Text.tsx +9 -0
- package/components/View.d.ts +3 -0
- package/components/View.tsx +24 -0
- package/components/index.d.ts +8 -0
- package/components/index.ts +4 -0
- package/css/animation.h +252 -0
- package/css/declarative.h +131 -0
- package/css/easing.h +160 -0
- package/css/engine.h +223 -0
- package/css/interpolate.h +38 -0
- package/image_store.cpp +807 -0
- package/package.json +62 -0
- package/rasterized_font.cpp +570 -0
- package/touch_runtime.cpp +513 -0
- package/ui/absolute_leaf_refresh.cpp +279 -0
- package/ui/absolute_leaf_refresh.h +12 -0
- package/ui/canvas_element.cpp +2314 -0
- package/ui/canvas_element.h +353 -0
- package/ui/canvas_store.cpp +188 -0
- package/ui/canvas_store.h +59 -0
- package/ui/core.cpp +135 -0
- package/ui/css_atom.cpp +155 -0
- package/ui/css_atom.h +21 -0
- package/ui/dirty_regions.cpp +66 -0
- package/ui/dirty_regions.h +34 -0
- package/ui/display_invalidation.cpp +101 -0
- package/ui/display_invalidation.h +15 -0
- package/ui/document.cpp +356 -0
- package/ui/document.h +101 -0
- package/ui/image.h +16 -0
- package/ui/image_element.cpp +13 -0
- package/ui/image_node.cpp +165 -0
- package/ui/input.cpp +936 -0
- package/ui/input_render.cpp +213 -0
- package/ui/internal.h +567 -0
- package/ui/layout.cpp +2025 -0
- package/ui/layout_snapshot.cpp +82 -0
- package/ui/layout_snapshot.h +12 -0
- package/ui/mirror.h +25 -0
- package/ui/node.cpp +243 -0
- package/ui/node.h +154 -0
- package/ui/node_lifecycle.cpp +137 -0
- package/ui/node_lifecycle.h +13 -0
- package/ui/node_model.h +597 -0
- package/ui/refresh_perf.h +235 -0
- package/ui/refresh_trace.h +68 -0
- package/ui/render.cpp +12097 -0
- package/ui/root_scroll_refresh.cpp +859 -0
- package/ui/root_scroll_refresh.h +30 -0
- package/ui/state_init.h +21 -0
- package/ui/style.cpp +14994 -0
- package/ui/style.h +727 -0
- package/ui/style_values.h +31 -0
- package/ui/text.cpp +2010 -0
- package/ui/text.h +15 -0
- package/ui/text_element.cpp +15 -0
- package/ui/tree_events.cpp +621 -0
- package/ui/tree_events.h +69 -0
- package/ui/tree_internal.h +191 -0
- package/ui/tree_nodes.cpp +628 -0
- package/ui/tree_render.cpp +3138 -0
- package/ui/tree_scroll_mirror.cpp +101 -0
- package/ui/tree_state.cpp +574 -0
- package/ui/tree_state.h +235 -0
- package/ui/tree_style.cpp +698 -0
- package/ui/ui.h +9 -0
- package/ui/view.cpp +2232 -0
- package/ui/view.h +14 -0
- package/ui/view_element.cpp +13 -0
- package/ui/viewport_region.cpp +36 -0
- package/ui/viewport_region.h +12 -0
- package/ui/virtual_keyboard.cpp +908 -0
- package/ui/virtual_keyboard.h +59 -0
- package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
- package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
- package/vendor/stb/stb_image.h +7988 -0
- package/vendor/stb/stb_truetype.h +5079 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "layout_snapshot.h"
|
|
3
|
+
#include "internal.h"
|
|
4
|
+
#include "tree_state.h"
|
|
5
|
+
|
|
6
|
+
namespace gea::embedded::ui {
|
|
7
|
+
|
|
8
|
+
void LayoutSnapshot::capture()
|
|
9
|
+
{
|
|
10
|
+
auto &state = treeState();
|
|
11
|
+
// Snapshotting previous_transform_* costs ~15 pooled rstyle() reads per node. They
|
|
12
|
+
// are ONLY read back when a transform is active (transformedBounds early-outs on
|
|
13
|
+
// !anyTransformActive), and anyTransformActive checks both current and previous
|
|
14
|
+
// transforms — so for a tree with no transforms (e.g. bouncing-balls) these reads
|
|
15
|
+
// are pure per-frame waste and the stale previous_* values are never observed. Skip
|
|
16
|
+
// them. The filter snapshot is independent (no transform), so it always runs.
|
|
17
|
+
const bool captureTransforms = ViewRenderer::anyTransformActive();
|
|
18
|
+
for (int i = 0; i < state.nodeCount; i++) {
|
|
19
|
+
state.nodes[i].layout.previous_x = state.nodes[i].layout.x;
|
|
20
|
+
state.nodes[i].layout.previous_y = state.nodes[i].layout.y;
|
|
21
|
+
state.nodes[i].layout.previous_width = state.nodes[i].layout.width;
|
|
22
|
+
state.nodes[i].layout.previous_height = state.nodes[i].layout.height;
|
|
23
|
+
state.nodes[i].layout.previous_scroll_x = state.nodes[i].layout.scroll_x;
|
|
24
|
+
state.nodes[i].layout.previous_scroll_y = state.nodes[i].layout.scroll_y;
|
|
25
|
+
// ONE RareStyle pool lookup per node, not ~16 — rstyle() is an out-of-line
|
|
26
|
+
// deque index (separate cache line from the node). Per-field lookups here cost
|
|
27
|
+
// ~1ms/frame on the spinning css-3d-cube (the "snap" phase); spine read these as
|
|
28
|
+
// direct ComputedStyle fields. (Same regression class as the reproject path.)
|
|
29
|
+
const RareStyle &rs = rstyle(state.nodes[i].style);
|
|
30
|
+
if (captureTransforms) {
|
|
31
|
+
state.nodes[i].render.previous_transform_rotate = rs.transform_rotate;
|
|
32
|
+
state.nodes[i].render.previous_transform_rotate_x = rs.transform_rotate_x;
|
|
33
|
+
state.nodes[i].render.previous_transform_rotate_y = rs.transform_rotate_y;
|
|
34
|
+
state.nodes[i].render.previous_transform_translate_x = rs.transform_translate_x;
|
|
35
|
+
state.nodes[i].render.previous_transform_translate_y = rs.transform_translate_y;
|
|
36
|
+
state.nodes[i].render.previous_transform_translate_z = rs.transform_translate_z;
|
|
37
|
+
state.nodes[i].render.previous_transform_translate_x_percent = rs.transform_translate_x_percent;
|
|
38
|
+
state.nodes[i].render.previous_transform_translate_y_percent = rs.transform_translate_y_percent;
|
|
39
|
+
state.nodes[i].render.previous_transform_scale_x = rs.transform_scale_x;
|
|
40
|
+
state.nodes[i].render.previous_transform_scale_y = rs.transform_scale_y;
|
|
41
|
+
state.nodes[i].render.previous_transform_origin_x = rs.transform_origin_x;
|
|
42
|
+
state.nodes[i].render.previous_transform_origin_y = rs.transform_origin_y;
|
|
43
|
+
state.nodes[i].render.previous_perspective = rs.perspective;
|
|
44
|
+
state.nodes[i].render.previous_perspective_origin_x = rs.perspective_origin_x;
|
|
45
|
+
state.nodes[i].render.previous_perspective_origin_y = rs.perspective_origin_y;
|
|
46
|
+
}
|
|
47
|
+
state.nodes[i].render.previous_filter_blur_radius = rs.filter_blur_radius;
|
|
48
|
+
state.nodes[i].render.dirty = 0;
|
|
49
|
+
state.nodes[i].render.layout_dirty = 0;
|
|
50
|
+
state.nodes[i].render.scroll_dirty = 0;
|
|
51
|
+
state.nodes[i].render.non_scroll_dirty = 0;
|
|
52
|
+
state.nodes[i].render.transform_dirty = 0;
|
|
53
|
+
state.nodes[i].render.bg_recolor_pending = 0;
|
|
54
|
+
state.nodes[i].render.text_layout_stable = 0;
|
|
55
|
+
state.nodes[i].render.text_partial_dirty = 0;
|
|
56
|
+
state.nodeCommandDirty[i] = 0;
|
|
57
|
+
state.nodeCommandDirtyBoundsValid[i] = 0;
|
|
58
|
+
state.nodeCommandDirtyCanOverpaint[i] = 0;
|
|
59
|
+
if (state.nodes[i].type == NodeType::VirtualList) VirtualListRenderer::captureSnapshot(i);
|
|
60
|
+
}
|
|
61
|
+
for (int i = 0; i < kScrollDirtyWordCount; i++)
|
|
62
|
+
state.scrollDirtyNodes[i] = 0;
|
|
63
|
+
state.scrollDirtyAny = false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void LayoutSnapshot::markChangesDirty()
|
|
67
|
+
{
|
|
68
|
+
auto &state = treeState();
|
|
69
|
+
for (int i = 0; i < state.nodeCount; i++) {
|
|
70
|
+
Node *n = &state.nodes[i];
|
|
71
|
+
if (n->layout.x != n->layout.previous_x ||
|
|
72
|
+
n->layout.y != n->layout.previous_y ||
|
|
73
|
+
n->layout.width != n->layout.previous_width ||
|
|
74
|
+
n->layout.height != n->layout.previous_height) {
|
|
75
|
+
n->render.dirty = 1;
|
|
76
|
+
n->render.layout_dirty = 1;
|
|
77
|
+
n->render.non_scroll_dirty = 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} // namespace gea::embedded::ui
|
package/ui/mirror.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
|
|
6
|
+
namespace gea::embedded::ui {
|
|
7
|
+
|
|
8
|
+
class Mirror {
|
|
9
|
+
public:
|
|
10
|
+
static Mirror &instance();
|
|
11
|
+
|
|
12
|
+
bool scrollDirtyAny() const;
|
|
13
|
+
void copyScrollDirty(uint64_t *dst, int wordCount) const;
|
|
14
|
+
void clearScrollDirty() const;
|
|
15
|
+
bool nodeIsScrollable(int node) const;
|
|
16
|
+
int scrollX(int node) const;
|
|
17
|
+
void setScrollX(int node, int scrollX) const;
|
|
18
|
+
int scrollY(int node) const;
|
|
19
|
+
void setScrollY(int node, int scrollY) const;
|
|
20
|
+
|
|
21
|
+
private:
|
|
22
|
+
Mirror() = default;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
} // namespace gea::embedded::ui
|
package/ui/node.cpp
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "node.h"
|
|
3
|
+
|
|
4
|
+
#include "host/audio.h"
|
|
5
|
+
#include "tree_internal.h"
|
|
6
|
+
|
|
7
|
+
#include <cstring>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
namespace gea::embedded::ui {
|
|
11
|
+
|
|
12
|
+
bool ClassList::add(const std::string &token) const
|
|
13
|
+
{
|
|
14
|
+
if (nodeId_ < 0) return false;
|
|
15
|
+
return Tree::instance().addClass(nodeId_, token);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
bool ClassList::remove(const std::string &token) const
|
|
19
|
+
{
|
|
20
|
+
if (nodeId_ < 0) return false;
|
|
21
|
+
return Tree::instance().removeClass(nodeId_, token);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
bool ClassList::toggle(const std::string &token) const
|
|
25
|
+
{
|
|
26
|
+
if (nodeId_ < 0) return false;
|
|
27
|
+
return Tree::instance().toggleClass(nodeId_, token);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
bool ClassList::toggle(const std::string &token, bool force) const
|
|
31
|
+
{
|
|
32
|
+
if (nodeId_ < 0) return false;
|
|
33
|
+
return Tree::instance().toggleClass(nodeId_, token, force);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void ClassList::set(const std::string &className) const
|
|
37
|
+
{
|
|
38
|
+
if (nodeId_ < 0) return;
|
|
39
|
+
Tree::instance().setClassName(nodeId_, className);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void ClassList::set(const char *className) const
|
|
43
|
+
{
|
|
44
|
+
if (nodeId_ < 0) return;
|
|
45
|
+
Tree::instance().setClassName(nodeId_, className);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void ClassList::clear() const
|
|
49
|
+
{
|
|
50
|
+
if (nodeId_ < 0) return;
|
|
51
|
+
Tree::instance().clearClasses(nodeId_);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
bool ClassList::contains(const std::string &token) const
|
|
55
|
+
{
|
|
56
|
+
if (nodeId_ < 0) return false;
|
|
57
|
+
return Tree::instance().hasClass(nodeId_, token);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
std::string ClassList::value() const
|
|
61
|
+
{
|
|
62
|
+
if (nodeId_ < 0) return std::string();
|
|
63
|
+
return Tree::instance().className(nodeId_);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
NodeHandle NodeHandle::cloneNode(bool deep) const
|
|
67
|
+
{
|
|
68
|
+
if (!valid()) return NodeHandle();
|
|
69
|
+
return NodeHandle(Tree::instance().cloneNode(id(), deep));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
NodeHandle NodeHandle::firstChildHandle() const
|
|
73
|
+
{
|
|
74
|
+
if (!valid()) return NodeHandle();
|
|
75
|
+
return NodeHandle(Tree::instance().firstChildOf(id()));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
NodeHandle NodeHandle::nextSiblingHandle() const
|
|
79
|
+
{
|
|
80
|
+
if (!valid()) return NodeHandle();
|
|
81
|
+
return NodeHandle(Tree::instance().node(id()).next_sibling);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void NodeHandle::replaceChildren(const std::vector<NodeHandle> &children) const
|
|
85
|
+
{
|
|
86
|
+
if (!valid()) return;
|
|
87
|
+
auto &tree = Tree::instance();
|
|
88
|
+
// Detach existing children (walk from first_child, capturing next before remove).
|
|
89
|
+
int child = tree.node(id()).first_child;
|
|
90
|
+
while (child >= 0) {
|
|
91
|
+
const int nextChild = tree.node(child).next_sibling;
|
|
92
|
+
NodeHandle(child).remove();
|
|
93
|
+
child = nextChild;
|
|
94
|
+
}
|
|
95
|
+
for (const NodeHandle &c : children)
|
|
96
|
+
if (c.valid()) appendChild(c);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
NodeHandle NodeHandle::childAt(int index) const
|
|
100
|
+
{
|
|
101
|
+
if (!valid()) return NodeHandle();
|
|
102
|
+
return NodeHandle(Tree::instance().childAt(id(), index));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void NodeHandle::appendChild(NodeHandle child) const
|
|
106
|
+
{
|
|
107
|
+
if (!valid() || !child.valid()) return;
|
|
108
|
+
Tree::instance().setParent(child.id(), id());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void NodeHandle::insertBefore(NodeHandle child, NodeHandle reference) const
|
|
112
|
+
{
|
|
113
|
+
if (!valid() || !child.valid()) return;
|
|
114
|
+
Tree::instance().insertBefore(child.id(), id(), reference.valid() ? reference.id() : -1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
void NodeHandle::setParent(NodeHandle parent) const
|
|
118
|
+
{
|
|
119
|
+
parent.appendChild(*this);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void NodeHandle::remove() const
|
|
123
|
+
{
|
|
124
|
+
if (!valid()) return;
|
|
125
|
+
Tree::instance().removeNode(id());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void NodeHandle::setText(const char *text) const
|
|
129
|
+
{
|
|
130
|
+
if (!valid()) return;
|
|
131
|
+
Tree::instance().setText(id(), text);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
void NodeHandle::setAttribute(const char *name, const char *value) const
|
|
135
|
+
{
|
|
136
|
+
if (!valid()) return;
|
|
137
|
+
Tree::instance().setAttribute(id(), name, value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
void NodeHandle::removeAttribute(const char *name) const
|
|
141
|
+
{
|
|
142
|
+
if (!valid()) return;
|
|
143
|
+
Tree::instance().removeAttribute(id(), name);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
bool NodeHandle::toggleAttribute(const char *name, bool force) const
|
|
147
|
+
{
|
|
148
|
+
if (!valid()) return false;
|
|
149
|
+
return Tree::instance().toggleAttribute(id(), name, force);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const char *NodeHandle::getAttribute(const char *name) const
|
|
153
|
+
{
|
|
154
|
+
if (!valid()) return "";
|
|
155
|
+
return Tree::instance().getAttribute(id(), name);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
bool NodeHandle::hasAttribute(const char *name) const
|
|
159
|
+
{
|
|
160
|
+
if (!valid()) return false;
|
|
161
|
+
return Tree::instance().hasAttribute(id(), name);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void NodeHandle::scrollIntoView() const
|
|
165
|
+
{
|
|
166
|
+
if (!valid()) return;
|
|
167
|
+
Tree::instance().scrollIntoView(id());
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
void NodeHandle::focus() const
|
|
171
|
+
{
|
|
172
|
+
if (!valid()) return;
|
|
173
|
+
Tree::instance().setActiveInput(id());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
void NodeHandle::blur() const
|
|
177
|
+
{
|
|
178
|
+
if (!valid()) return;
|
|
179
|
+
// Only clear focus if this node is the one holding it: `blur()` on some
|
|
180
|
+
// other element must not steal the caret away from the focused input.
|
|
181
|
+
if (Tree::instance().activeInputId() != id()) return;
|
|
182
|
+
Tree::instance().setActiveInput(-1);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
bool NodeHandle::play() const
|
|
186
|
+
{
|
|
187
|
+
if (!valid() || std::strcmp(tagName(), "audio") != 0) return false;
|
|
188
|
+
return gea::host::HTMLAudioElement(*this).play();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
void NodeHandle::pause() const
|
|
192
|
+
{
|
|
193
|
+
if (!valid() || std::strcmp(tagName(), "audio") != 0) return;
|
|
194
|
+
gea::host::HTMLAudioElement(*this).pause();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
void NodeHandle::setTagName(const char *tagName) const
|
|
198
|
+
{
|
|
199
|
+
if (!valid()) return;
|
|
200
|
+
Tree::instance().setTagName(id(), tagName);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const char *NodeHandle::tagName() const
|
|
204
|
+
{
|
|
205
|
+
if (!valid()) return "";
|
|
206
|
+
return Tree::instance().tagName(id());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// DOM Node.nodeType for a handle: ELEMENT_NODE (1) for any element-like tree
|
|
210
|
+
// node, TEXT_NODE (3) for a text node, DOCUMENT_FRAGMENT_NODE (11) for an
|
|
211
|
+
// invalid handle (the embedded tree has no fragment node kind, so a real handle
|
|
212
|
+
// is never a fragment).
|
|
213
|
+
NodeHandle::NodeTypeProperty::operator int() const
|
|
214
|
+
{
|
|
215
|
+
if (id < 0) return 11;
|
|
216
|
+
return Tree::instance().node(id).type == NodeType::Text ? 3 : 1;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
void NodeHandle::setPressId(int pressId) const
|
|
220
|
+
{
|
|
221
|
+
if (!valid()) return;
|
|
222
|
+
Tree::instance().setPressId(id(), pressId);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
void NodeHandle::setPressValue(int pressValue) const
|
|
226
|
+
{
|
|
227
|
+
if (!valid()) return;
|
|
228
|
+
Tree::instance().setPressValue(id(), pressValue);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
gea::framework::events::EventListenerId NodeHandle::addEventListener(const char *type, gea::framework::events::EventListener listener) const
|
|
232
|
+
{
|
|
233
|
+
if (!valid()) return gea::framework::events::kInvalidEventListenerId;
|
|
234
|
+
return Tree::instance().setEventListener(id(), type, std::move(listener));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
bool NodeHandle::removeEventListener(const char *type, gea::framework::events::EventListenerId listenerId) const
|
|
238
|
+
{
|
|
239
|
+
if (!valid()) return false;
|
|
240
|
+
return Tree::instance().removeEventListener(id(), type, listenerId);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
} // namespace gea::embedded::ui
|
package/ui/node.h
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "events.h"
|
|
5
|
+
#include "style.h"
|
|
6
|
+
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <utility>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
namespace gea::embedded::ui {
|
|
12
|
+
|
|
13
|
+
class ClassList {
|
|
14
|
+
public:
|
|
15
|
+
explicit ClassList(int nodeId = -1) : nodeId_(nodeId) {}
|
|
16
|
+
|
|
17
|
+
bool add(const std::string &token) const;
|
|
18
|
+
bool remove(const std::string &token) const;
|
|
19
|
+
bool toggle(const std::string &token) const;
|
|
20
|
+
bool toggle(const std::string &token, bool force) const;
|
|
21
|
+
void set(const char *className) const;
|
|
22
|
+
void set(const std::string &className) const;
|
|
23
|
+
void clear() const;
|
|
24
|
+
bool contains(const std::string &token) const;
|
|
25
|
+
std::string value() const;
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
int nodeId_;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class NodeHandle {
|
|
32
|
+
protected:
|
|
33
|
+
int id_;
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
// DOM Node.nodeType, resolved from the backing tree node. geatsc types a
|
|
37
|
+
// compiled component template as `Node` (not a dynamic value), so the
|
|
38
|
+
// runtime's `CompiledStaticComponent::render` element/fragment check
|
|
39
|
+
// (`node.nodeType === 1` / `=== 11`) lowers to a typed member read on this
|
|
40
|
+
// handle rather than a dynamic record lookup — the handle has to answer it.
|
|
41
|
+
// The embedded tree has no document-fragment node kind (every tree node is
|
|
42
|
+
// element-like or Text), so a handle to a real node reports 1 (element) or 3
|
|
43
|
+
// (text); 11 (document fragment) only arises for an invalid handle, e.g. the
|
|
44
|
+
// base `createDocumentFragment()` template no mounted component ever uses.
|
|
45
|
+
// Resolved lazily on read (cheap, rare) rather than at every handle
|
|
46
|
+
// construction (hot path), so it stays a thin id view.
|
|
47
|
+
struct NodeTypeProperty {
|
|
48
|
+
int id;
|
|
49
|
+
operator int() const;
|
|
50
|
+
bool operator==(int other) const { return static_cast<int>(*this) == other; }
|
|
51
|
+
bool operator!=(int other) const { return static_cast<int>(*this) != other; }
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// A real default constructor (not a defaulted-arg explicit ctor): records
|
|
55
|
+
// holding a NodeHandle field aggregate-initialize with `{}`, which is
|
|
56
|
+
// copy-list-initialization — that's not allowed to call an explicit
|
|
57
|
+
// constructor, so `explicit NodeHandle(int = -1)` alone breaks every
|
|
58
|
+
// generated `__gea_type_X __gea_out{};`.
|
|
59
|
+
NodeHandle() : NodeHandle(-1) {}
|
|
60
|
+
explicit NodeHandle(int id) : id_(id), nodeType{id} {}
|
|
61
|
+
// Implicit build from a boxed node value (record carrying "__gea_node_id"),
|
|
62
|
+
// so the compiled-component emitters' `NodeHandle x = <gea_cpp_value>` copy-
|
|
63
|
+
// inits and NodeHandle-typed args accept a boxed node. SFINAE'd on
|
|
64
|
+
// record_get_literal so it only matches the runtime value type.
|
|
65
|
+
template <typename V, typename = decltype(std::declval<const V &>().record_get_literal(""))>
|
|
66
|
+
NodeHandle(const V &value) : NodeHandle(__gea_native_from_value(value)) {}
|
|
67
|
+
|
|
68
|
+
// geatsc boxed-node protocol: rebuild a typed handle from a boxed node
|
|
69
|
+
// value (a record carrying "__gea_node_id"). The emitter's native-type
|
|
70
|
+
// cast prefers this over `static_cast<NodeHandle>(value)`, which would
|
|
71
|
+
// numerically coerce the record (NaN) into a garbage id. Templated so
|
|
72
|
+
// this header stays independent of the geatsc runtime's value type; a
|
|
73
|
+
// missing/non-numeric id yields the invalid handle (NaN != NaN).
|
|
74
|
+
template <typename V>
|
|
75
|
+
static NodeHandle __gea_native_from_value(const V &value)
|
|
76
|
+
{
|
|
77
|
+
const double raw = static_cast<double>(value.record_get_literal("__gea_node_id"));
|
|
78
|
+
return NodeHandle(raw == raw ? static_cast<int>(raw) : -1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Assign a boxed node value (a record carrying "__gea_node_id") straight
|
|
82
|
+
// into a typed handle. The DOM-walk emitters do `n = gea_cpp_key(domParentNode(n))`
|
|
83
|
+
// where `n` is a NodeHandle and the right-hand side is a gea_cpp_value.
|
|
84
|
+
// SFINAE'd on record_get_literal so it only matches the boxed value type and
|
|
85
|
+
// never shadows the compiler-generated NodeHandle copy/move assignment.
|
|
86
|
+
template <typename V>
|
|
87
|
+
auto operator=(const V &value) -> decltype((void)value.record_get_literal(""), *this)
|
|
88
|
+
{
|
|
89
|
+
return *this = __gea_native_from_value(value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
int id() const { return id_; }
|
|
93
|
+
bool valid() const { return id_ >= 0; }
|
|
94
|
+
explicit operator bool() const { return valid(); }
|
|
95
|
+
Style style() const { return Style(id_); }
|
|
96
|
+
ClassList classList() const { return ClassList(id_); }
|
|
97
|
+
|
|
98
|
+
NodeTypeProperty nodeType;
|
|
99
|
+
|
|
100
|
+
NodeHandle cloneNode(bool deep = true) const;
|
|
101
|
+
// Named *Handle to avoid colliding with the DOM `firstChild` PROPERTY
|
|
102
|
+
// lowering (gea_ir::domFirstChild), which geatsc resolves on Node-typed
|
|
103
|
+
// receivers; a same-named member function would shadow it.
|
|
104
|
+
NodeHandle firstChildHandle() const;
|
|
105
|
+
NodeHandle nextSiblingHandle() const;
|
|
106
|
+
// Replace ALL children with `children` (the compiled-component keyed-list
|
|
107
|
+
// reconciler's replaceChildren): detach every current child, then append the
|
|
108
|
+
// new set in order.
|
|
109
|
+
void replaceChildren(const std::vector<NodeHandle> &children) const;
|
|
110
|
+
NodeHandle childAt(int index) const;
|
|
111
|
+
void appendChild(NodeHandle child) const;
|
|
112
|
+
void insertBefore(NodeHandle child, NodeHandle reference) const;
|
|
113
|
+
void setParent(NodeHandle parent) const;
|
|
114
|
+
void remove() const;
|
|
115
|
+
void setText(const char *text) const;
|
|
116
|
+
void setAttribute(const char *name, const char *value) const;
|
|
117
|
+
void removeAttribute(const char *name) const;
|
|
118
|
+
// std::string overloads: geatsc emits std::string arguments when a typed
|
|
119
|
+
// NodeHandle method is called from app code (e.g. el.setAttribute('src', pathVar))
|
|
120
|
+
// and does not coerce to const char*, so accept std::string directly. String
|
|
121
|
+
// literals still bind the const char* overloads above (exact match preferred).
|
|
122
|
+
void setAttribute(const std::string &name, const std::string &value) const { setAttribute(name.c_str(), value.c_str()); }
|
|
123
|
+
void removeAttribute(const std::string &name) const { removeAttribute(name.c_str()); }
|
|
124
|
+
bool toggleAttribute(const char *name, bool force) const;
|
|
125
|
+
// std::string overload, matching setAttribute/removeAttribute above: the patch
|
|
126
|
+
// reconciler carries a dynamic attribute name (`gea_cpp_value extra`), which
|
|
127
|
+
// implicitly converts to std::string but not to const char*.
|
|
128
|
+
bool toggleAttribute(const std::string &name, bool force) const { return toggleAttribute(name.c_str(), force); }
|
|
129
|
+
const char *getAttribute(const char *name) const;
|
|
130
|
+
bool hasAttribute(const char *name) const;
|
|
131
|
+
// std::string overloads, matching set/remove/toggleAttribute above: an app
|
|
132
|
+
// that reads an attribute by a computed name holds a `std::string`, which
|
|
133
|
+
// binds neither `const char *` parameter.
|
|
134
|
+
const char *getAttribute(const std::string &name) const { return getAttribute(name.c_str()); }
|
|
135
|
+
bool hasAttribute(const std::string &name) const { return hasAttribute(name.c_str()); }
|
|
136
|
+
void scrollIntoView() const;
|
|
137
|
+
// Text-input focus, the same state `Tree::setActiveInput` already holds for
|
|
138
|
+
// the virtual keyboard: focusing an `<input>` is what summons the on-screen
|
|
139
|
+
// keyboard and starts the caret blink, and blurring clears both. The state
|
|
140
|
+
// existed and had no handle-level spelling, so an app that wanted it (maps'
|
|
141
|
+
// hidden search input) had nothing typed to call.
|
|
142
|
+
void focus() const;
|
|
143
|
+
void blur() const;
|
|
144
|
+
bool play() const;
|
|
145
|
+
void pause() const;
|
|
146
|
+
void setTagName(const char *tagName) const;
|
|
147
|
+
const char *tagName() const;
|
|
148
|
+
void setPressId(int pressId) const;
|
|
149
|
+
void setPressValue(int pressValue) const;
|
|
150
|
+
gea::framework::events::EventListenerId addEventListener(const char *type, gea::framework::events::EventListener listener) const;
|
|
151
|
+
bool removeEventListener(const char *type, gea::framework::events::EventListenerId listenerId) const;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "node_lifecycle.h"
|
|
3
|
+
|
|
4
|
+
#include "pixel.h"
|
|
5
|
+
|
|
6
|
+
#include <cstring>
|
|
7
|
+
|
|
8
|
+
namespace gea::embedded::ui {
|
|
9
|
+
|
|
10
|
+
void NodeLifecycle::init(Node *n, NodeType type)
|
|
11
|
+
{
|
|
12
|
+
// Node contains a `std::string text` member — it is NOT a trivially-
|
|
13
|
+
// copyable struct, so `std::memset(n, 0, sizeof(*n))` is undefined
|
|
14
|
+
// behavior (it would zero the string's internal _M_dataplus._M_p,
|
|
15
|
+
// and the subsequent .clear() would null-deref writing the NUL
|
|
16
|
+
// terminator to address 0). Every Node field is explicitly assigned
|
|
17
|
+
// below, so the memset was a redundant belt-and-suspenders zero —
|
|
18
|
+
// dropping it both fixes the crash and is no-loss because the next
|
|
19
|
+
// ~80 lines reassign every member.
|
|
20
|
+
n->type = type;
|
|
21
|
+
n->style.display = kDisplayBlock;
|
|
22
|
+
n->style.display_explicit = 0;
|
|
23
|
+
n->style.flex_direction = 0;
|
|
24
|
+
n->style.flex_direction_explicit = 0;
|
|
25
|
+
n->style.flex_wrap = 0;
|
|
26
|
+
n->style.justify_content = 0;
|
|
27
|
+
n->style.align_items = 0;
|
|
28
|
+
n->style.justify_items = 0;
|
|
29
|
+
n->style.align_content = 0;
|
|
30
|
+
n->style.align_self = -1;
|
|
31
|
+
n->style.gap = 0;
|
|
32
|
+
// Grid tracks moved to RareStyle (default 0 for a node with no rare_style),
|
|
33
|
+
// so a fresh node needs no explicit reset here.
|
|
34
|
+
n->style.width = kUnset;
|
|
35
|
+
n->style.height = kUnset;
|
|
36
|
+
n->style.width_percent = kUnset;
|
|
37
|
+
n->style.height_percent = kUnset;
|
|
38
|
+
n->style.min_width = 0;
|
|
39
|
+
n->style.min_height = 0;
|
|
40
|
+
n->style.max_width = kUnset;
|
|
41
|
+
n->style.max_height = kUnset;
|
|
42
|
+
n->style.flex = 0;
|
|
43
|
+
n->style.flex_shrink = 1;
|
|
44
|
+
n->style.flex_basis = kUnset;
|
|
45
|
+
for (int i = 0; i < 4; i++) {
|
|
46
|
+
n->style.padding[i] = 0;
|
|
47
|
+
n->style.margin[i] = 0;
|
|
48
|
+
n->style.pos_offsets[i] = kUnset;
|
|
49
|
+
n->style.pos_offset_percent[i] = kUnset;
|
|
50
|
+
// per-side border width/color/alpha moved to RareStyle (defaults there).
|
|
51
|
+
n->style.border_radius[i] = 0;
|
|
52
|
+
n->style.border_radius_percent[i] = kUnset;
|
|
53
|
+
}
|
|
54
|
+
n->style.position = 0;
|
|
55
|
+
n->style.z_index = 0;
|
|
56
|
+
n->style.bg_color = 0;
|
|
57
|
+
n->style.has_bg = 0;
|
|
58
|
+
n->style.bg_alpha = 255;
|
|
59
|
+
n->style.bg_fill = 0;
|
|
60
|
+
// gradients + background-grid moved to RareStyle (defaults there).
|
|
61
|
+
n->style.active_bg_color = 0;
|
|
62
|
+
n->style.has_active_bg = 0;
|
|
63
|
+
n->style.text_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
64
|
+
n->style.text_alpha = 255;
|
|
65
|
+
n->style.opacity = 255;
|
|
66
|
+
n->style.blink_interval_ms = 0;
|
|
67
|
+
n->style.blink_started_ms = 0;
|
|
68
|
+
n->style.blink_visible = 1;
|
|
69
|
+
n->style.border_width = 0;
|
|
70
|
+
n->style.border_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
71
|
+
n->style.border_alpha = 255;
|
|
72
|
+
// transform / perspective / filter / box-shadow moved to RareStyle; a fresh
|
|
73
|
+
// node (rare_style = -1) reads their correct defaults from the zero entry.
|
|
74
|
+
n->style.font_id = -1;
|
|
75
|
+
n->style.font_size = 0;
|
|
76
|
+
n->style.font_weight = 400;
|
|
77
|
+
n->style.line_height = 0;
|
|
78
|
+
n->style.text_align = 0;
|
|
79
|
+
n->style.text_decoration = 0;
|
|
80
|
+
n->style.text_transform = 0;
|
|
81
|
+
n->style.white_space = 0;
|
|
82
|
+
n->style.text_overflow = 0;
|
|
83
|
+
n->style.overflow = 0;
|
|
84
|
+
n->style.overflow_x = 0;
|
|
85
|
+
n->style.overflow_y = 0;
|
|
86
|
+
n->style.mask_right_fade_width = 0;
|
|
87
|
+
n->text.clear();
|
|
88
|
+
n->image_id = -1;
|
|
89
|
+
n->tag_id = 0; // 0 = empty tag (interned tag table index 0)
|
|
90
|
+
n->style.image_fit = 0;
|
|
91
|
+
n->style.backface_hidden = 0;
|
|
92
|
+
n->style.pointer_events = 0;
|
|
93
|
+
n->parent = -1;
|
|
94
|
+
n->first_child = -1;
|
|
95
|
+
n->last_child = -1;
|
|
96
|
+
n->next_sibling = -1;
|
|
97
|
+
n->prev_sibling = -1;
|
|
98
|
+
n->layout.x = 0;
|
|
99
|
+
n->layout.y = 0;
|
|
100
|
+
n->layout.width = 0;
|
|
101
|
+
n->layout.height = 0;
|
|
102
|
+
n->layout.inline_indent = 0;
|
|
103
|
+
n->layout.scroll_x = 0;
|
|
104
|
+
n->layout.scroll_y = 0;
|
|
105
|
+
n->layout.scroll_content_width = 0;
|
|
106
|
+
n->layout.scroll_content_height = 0;
|
|
107
|
+
n->layout.previous_x = 0;
|
|
108
|
+
n->layout.previous_y = 0;
|
|
109
|
+
n->layout.previous_width = 0;
|
|
110
|
+
n->layout.previous_height = 0;
|
|
111
|
+
n->layout.previous_scroll_x = 0;
|
|
112
|
+
n->layout.previous_scroll_y = 0;
|
|
113
|
+
n->render.previous_transform_rotate = 0;
|
|
114
|
+
n->render.previous_transform_rotate_x = 0;
|
|
115
|
+
n->render.previous_transform_rotate_y = 0;
|
|
116
|
+
n->render.previous_transform_translate_x = 0;
|
|
117
|
+
n->render.previous_transform_translate_y = 0;
|
|
118
|
+
n->render.previous_transform_translate_z = 0;
|
|
119
|
+
n->render.previous_transform_translate_x_percent = 0;
|
|
120
|
+
n->render.previous_transform_translate_y_percent = 0;
|
|
121
|
+
n->render.previous_transform_scale_x = 1000;
|
|
122
|
+
n->render.previous_transform_scale_y = 1000;
|
|
123
|
+
n->render.previous_transform_origin_x = 500;
|
|
124
|
+
n->render.previous_transform_origin_y = 500;
|
|
125
|
+
n->render.previous_perspective = 0;
|
|
126
|
+
n->render.previous_perspective_origin_x = 500;
|
|
127
|
+
n->render.previous_perspective_origin_y = 500;
|
|
128
|
+
n->render.previous_filter_blur_radius = 0;
|
|
129
|
+
n->render.inline_baseline = 0;
|
|
130
|
+
n->render.dirty = 0;
|
|
131
|
+
n->render.scroll_dirty = 0;
|
|
132
|
+
n->render.non_scroll_dirty = 0;
|
|
133
|
+
n->render.transform_dirty = 0;
|
|
134
|
+
n->render.text_layout_stable = 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} // namespace gea::embedded::ui
|