@geastack/engine 0.1.16 → 0.1.18
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/canvas.cpp +40 -5
- package/package.json +1 -1
- package/rasterized_font.cpp +118 -7
- package/touch_runtime.cpp +118 -67
- package/ui/canvas_element.h +1 -1
- package/ui/child_node_list.h +94 -0
- package/ui/control_commit.h +23 -0
- package/ui/css_features.h +5 -0
- package/ui/document.cpp +44 -96
- package/ui/document.h +61 -6
- package/ui/input.cpp +72 -20
- package/ui/input_retirement.h +22 -0
- package/ui/internal.h +3 -1
- package/ui/layout.cpp +31 -25
- package/ui/node.cpp +123 -31
- package/ui/node.h +55 -16
- package/ui/node_lifecycle.cpp +3 -0
- package/ui/node_model.h +20 -1
- package/ui/render.cpp +16 -3
- package/ui/selector.cpp +527 -0
- package/ui/selector.h +32 -0
- package/ui/style.cpp +94 -23
- package/ui/style.h +8 -3
- package/ui/text.cpp +73 -49
- package/ui/tree_events.cpp +376 -85
- package/ui/tree_events.h +34 -2
- package/ui/tree_internal.h +17 -5
- package/ui/tree_nodes.cpp +218 -13
- package/ui/tree_render.cpp +3 -0
- package/ui/tree_state.h +4 -0
- package/ui/tree_style.cpp +4 -0
- package/ui/virtual_keyboard.cpp +8 -1
package/ui/tree_internal.h
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
#include <string>
|
|
10
10
|
#include <string_view>
|
|
11
|
+
#include <vector>
|
|
11
12
|
|
|
12
13
|
// Framebuffer-free retained rendering: each dirty band is rasterized into the
|
|
13
14
|
// display's internal-RAM DMA chunk and streamed to the panel while the next
|
|
@@ -36,6 +37,8 @@ public:
|
|
|
36
37
|
int createView();
|
|
37
38
|
int createButton();
|
|
38
39
|
int createText();
|
|
40
|
+
int createComment();
|
|
41
|
+
int createDocumentFragment();
|
|
39
42
|
int createImage();
|
|
40
43
|
int createCanvas();
|
|
41
44
|
int createCamera();
|
|
@@ -52,6 +55,8 @@ public:
|
|
|
52
55
|
|
|
53
56
|
void setParent(int child, int parent);
|
|
54
57
|
void insertBefore(int child, int parent, int reference);
|
|
58
|
+
void detachNode(int child);
|
|
59
|
+
void replaceChildren(int parent, const std::vector<int> &children);
|
|
55
60
|
void setStyle(int node, Property prop, int value);
|
|
56
61
|
void setDefaultStyle(int node, Property prop, int value);
|
|
57
62
|
void setStyleFromClass(int node, Property prop, int value);
|
|
@@ -86,6 +91,8 @@ public:
|
|
|
86
91
|
// event types not tracked by the listener tables.
|
|
87
92
|
bool hasListenersForType(const char *type) const;
|
|
88
93
|
bool dispatchEvent(gea::framework::events::PointerEvent &event);
|
|
94
|
+
bool dispatchEventAlongPath(gea::framework::events::PointerEvent &event,
|
|
95
|
+
const std::vector<gea::framework::events::EventTarget> &path);
|
|
89
96
|
bool containsNode(int ancestor, int node) const;
|
|
90
97
|
void removeNode(int node);
|
|
91
98
|
gea::framework::graphics::Canvas *ensureCanvas(int node, int width = 0, int height = 0);
|
|
@@ -141,6 +148,10 @@ public:
|
|
|
141
148
|
// setActiveInput(-1) clears focus.
|
|
142
149
|
int activeInputId() const;
|
|
143
150
|
void setActiveInput(int nodeId);
|
|
151
|
+
// Pixel user-edit boundary, separate from programmatic attribute writes.
|
|
152
|
+
bool activeInputAdmitted() const;
|
|
153
|
+
void markActiveInputEdited();
|
|
154
|
+
void commitActiveInput();
|
|
144
155
|
bool activeInputCaretVisible() const;
|
|
145
156
|
void tickInputCaret(int timestampMs);
|
|
146
157
|
|
|
@@ -164,16 +175,17 @@ private:
|
|
|
164
175
|
Tree() = default;
|
|
165
176
|
};
|
|
166
177
|
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
// the runtime rather than through Tree::dispatchEvent's tree walk.
|
|
178
|
+
// Legacy anonymous registration and native document-target producers. The
|
|
179
|
+
// off-tree registry owns callback identity/capture/once; mounted pointer/key
|
|
180
|
+
// delivery reaches it through explicit document phases, never a body proxy.
|
|
171
181
|
void setDocumentEventListener(const char *type, gea::framework::events::EventListener listener);
|
|
172
182
|
void dispatchDocumentRotary(int delta);
|
|
173
183
|
bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event);
|
|
174
184
|
bool dispatchDocumentKeyUp(gea::framework::events::PointerEvent &event);
|
|
185
|
+
// Native keyboard root authority: real window capture, node/document phases, window bubble.
|
|
186
|
+
bool dispatchRootKeyEvent(gea::framework::events::PointerEvent &event, bool legacyDocumentFirst = false);
|
|
175
187
|
void resetDocumentEventListeners();
|
|
176
|
-
void
|
|
188
|
+
void resetRootEventListeners() noexcept;
|
|
177
189
|
|
|
178
190
|
// Deliver a pointer/touch event straight to document-level listeners with no
|
|
179
191
|
// tree walk. Immediate-mode apps (Display.ctx games) mount no UI tree, so there
|
package/ui/tree_nodes.cpp
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "internal.h"
|
|
3
|
+
#include "node.h"
|
|
4
|
+
#include "input_retirement.h"
|
|
5
|
+
#include <stdexcept>
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <string>
|
|
3
8
|
#include <image.h>
|
|
4
9
|
#include "canvas_element.h"
|
|
5
10
|
#include "display.h"
|
|
@@ -15,6 +20,9 @@
|
|
|
15
20
|
|
|
16
21
|
namespace gea::embedded::ui {
|
|
17
22
|
|
|
23
|
+
// Internal cross-TU cleanup; no public/native SDK surface.
|
|
24
|
+
void resetTreeEventStorage();
|
|
25
|
+
|
|
18
26
|
namespace {
|
|
19
27
|
|
|
20
28
|
bool nodeCanDrawWithoutCanvas(const Node &node)
|
|
@@ -100,6 +108,7 @@ bool canUseDisplayFramebuffer(TreeState &state, int id, int width, int height)
|
|
|
100
108
|
void resetNodeSlot(TreeState &state, int id)
|
|
101
109
|
{
|
|
102
110
|
if (id < 0 || id >= kMaxNodes) return;
|
|
111
|
+
gea::framework::identity::retire(id);
|
|
103
112
|
forgetNodeCssAnimations(id);
|
|
104
113
|
#if GEA_UI_IMAGE_NODES
|
|
105
114
|
gea::framework::graphics::ImageStore::instance().release(state.nodes[id].image_id);
|
|
@@ -109,7 +118,10 @@ void resetNodeSlot(TreeState &state, int id)
|
|
|
109
118
|
// before NodeLifecycle::init frees the string, or a stale-list replay in the
|
|
110
119
|
// gap before the next record reads freed memory.
|
|
111
120
|
if (!state.nodes[id].text.empty()) DisplayList::instance().scrubNodeText(state.nodes[id].text.c_str());
|
|
112
|
-
releaseRareData(id); //
|
|
121
|
+
releaseRareData(id); // releases detached listener captures after pool mutation
|
|
122
|
+
// The intentional retirement above expected no live owner. A destructor
|
|
123
|
+
// may clear/recreate this slot; never finish cleanup against its successor.
|
|
124
|
+
if (gea::framework::identity::node(id)) return;
|
|
113
125
|
#if GEA_CSS_RARE_STYLE
|
|
114
126
|
releaseRareStyle(state.nodes[id].mutableStyle().rare_style); // frees the cold-style block
|
|
115
127
|
#endif
|
|
@@ -152,6 +164,7 @@ bool localAbsoluteLeafTreeMutation(const TreeState &state, int child)
|
|
|
152
164
|
|
|
153
165
|
void Tree::clear()
|
|
154
166
|
{
|
|
167
|
+
gea::framework::identity::clear();
|
|
155
168
|
LayoutEngine::instance().endLayoutPass();
|
|
156
169
|
LayoutEngine::instance().releasePersistentLayoutStorage();
|
|
157
170
|
auto &state = treeState();
|
|
@@ -159,16 +172,9 @@ void Tree::clear()
|
|
|
159
172
|
if (state.refreshSerial == 0) state.refreshSerial = 1;
|
|
160
173
|
for (int i = 0; i < state.nodeCount; i++) {
|
|
161
174
|
forgetNodeCssAnimations(i);
|
|
162
|
-
|
|
175
|
+
// Listener captures stay owned until ALL structural clear writes finish.
|
|
163
176
|
state.classLists[i].clear();
|
|
164
177
|
}
|
|
165
|
-
// Document-level handlers live off-tree; drop them so the next app doesn't
|
|
166
|
-
// inherit the previous app's dial/hardware-button/pointer handlers.
|
|
167
|
-
// Delegated document pointer/touch handlers also bind onto the mounted root;
|
|
168
|
-
// releaseRareData above drops those per-node listener slots, so the binding
|
|
169
|
-
// cache must be reset with them.
|
|
170
|
-
resetDocumentEventListeners();
|
|
171
|
-
resetDocumentDelegatedEventListeners();
|
|
172
178
|
resetRareStylePool(); // drop all cold-style entries; node handles reset by the Node{} loop below
|
|
173
179
|
state.canvases.clear();
|
|
174
180
|
std::memset(state.nodeActive, 0, sizeof(state.nodeActive));
|
|
@@ -226,6 +232,9 @@ void Tree::clear()
|
|
|
226
232
|
// be reused. Dropping our handles forces re-mount on the next focus
|
|
227
233
|
// event in the new app.
|
|
228
234
|
VirtualKeyboard::instance().reset();
|
|
235
|
+
// No outgoing Tree bookkeeping may run after capture destruction: it can
|
|
236
|
+
// synchronously clear and mount a successor tree.
|
|
237
|
+
resetTreeEventStorage();
|
|
229
238
|
}
|
|
230
239
|
|
|
231
240
|
int Tree::createNode(NodeType type)
|
|
@@ -241,12 +250,17 @@ int Tree::createNode(NodeType type)
|
|
|
241
250
|
if (state.nodeCount >= kMaxNodes) return -1;
|
|
242
251
|
id = state.nodeCount++;
|
|
243
252
|
}
|
|
253
|
+
gea::framework::identity::activate(id);
|
|
254
|
+
const auto allocatedOwner = gea::framework::identity::node(id);
|
|
244
255
|
state.nodeActive[id] = 1;
|
|
245
256
|
releaseRareData(id); // free any block from a prior occupant before reinit
|
|
257
|
+
if (!gea::framework::identity::current(id, allocatedOwner)) return -1;
|
|
246
258
|
NodeLifecycle::init(&state.nodes[id], type);
|
|
247
259
|
LayoutEngine::instance().resetNodeLayoutState(id);
|
|
248
260
|
state.classLists[id].clear();
|
|
249
261
|
if (type == NodeType::VirtualList) VirtualListRenderer::init(id);
|
|
262
|
+
// The typed native Button factory carries the same semantic tag as JSX/DOM creation.
|
|
263
|
+
if (type == NodeType::Button) setTagName(id, "button");
|
|
250
264
|
return id;
|
|
251
265
|
}
|
|
252
266
|
|
|
@@ -325,6 +339,8 @@ int Tree::childAt(int node, int index)
|
|
|
325
339
|
int Tree::createView() { return createNode(NodeType::View); }
|
|
326
340
|
int Tree::createButton() { return createNode(NodeType::Button); }
|
|
327
341
|
int Tree::createText() { return createNode(NodeType::Text); }
|
|
342
|
+
int Tree::createComment() { return createNode(NodeType::Comment); }
|
|
343
|
+
int Tree::createDocumentFragment() { return createNode(NodeType::DocumentFragment); }
|
|
328
344
|
int Tree::createImage() { return createNode(NodeType::Image); }
|
|
329
345
|
int Tree::createCanvas() { return createNode(NodeType::Canvas); }
|
|
330
346
|
int Tree::createCamera() { return createNode(NodeType::Camera); }
|
|
@@ -534,12 +550,23 @@ bool reparentWouldCycle(const TreeState &state, int child, int parent)
|
|
|
534
550
|
return false;
|
|
535
551
|
}
|
|
536
552
|
|
|
553
|
+
namespace { void prepareDisconnectedMove(Tree &tree, int child, int parent, int reference = -1); }
|
|
554
|
+
|
|
537
555
|
void Tree::setParent(int child, int parent)
|
|
538
556
|
{
|
|
539
557
|
auto &state = treeState();
|
|
540
558
|
if (child < 0 || child >= state.nodeCount || parent < 0 || parent >= state.nodeCount) return;
|
|
541
559
|
if (child == parent) return;
|
|
542
560
|
if (reparentWouldCycle(state, child, parent)) return;
|
|
561
|
+
if (state.nodes[parent].type == NodeType::Comment ||
|
|
562
|
+
(state.nodes[parent].type == NodeType::Text && !*tagName(parent))) return;
|
|
563
|
+
if (state.nodes[child].type == NodeType::DocumentFragment) {
|
|
564
|
+
// Insertion moves the children in order; the fragment remains detached
|
|
565
|
+
// and reusable. Never insert a visual container in its place.
|
|
566
|
+
while (state.nodes[child].first_child >= 0) setParent(state.nodes[child].first_child, parent);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
prepareDisconnectedMove(*this,child,parent);
|
|
543
570
|
Node *c = &state.nodes[child];
|
|
544
571
|
const bool localMutation = localAbsoluteLeafTreeMutation(state, child);
|
|
545
572
|
if (c->parent >= 0) {
|
|
@@ -590,13 +617,21 @@ void Tree::insertBefore(int child, int parent, int reference)
|
|
|
590
617
|
if (child < 0 || child >= state.nodeCount || parent < 0 || parent >= state.nodeCount) return;
|
|
591
618
|
if (child == parent) return;
|
|
592
619
|
if (reparentWouldCycle(state, child, parent)) return;
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
620
|
+
if (state.nodes[parent].type == NodeType::Comment ||
|
|
621
|
+
(state.nodes[parent].type == NodeType::Text && !*tagName(parent))) return;
|
|
622
|
+
if (reference >= 0 && (reference >= state.nodeCount || !state.nodeActive[reference] || state.nodes[reference].parent != parent))
|
|
623
|
+
throw std::invalid_argument("insertBefore reference is not a child of parent");
|
|
624
|
+
if (child == reference) return;
|
|
625
|
+
if (state.nodes[child].type == NodeType::DocumentFragment) {
|
|
626
|
+
while (state.nodes[child].first_child >= 0) insertBefore(state.nodes[child].first_child, parent, reference);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (reference < 0) {
|
|
596
630
|
setParent(child, parent);
|
|
597
631
|
return;
|
|
598
632
|
}
|
|
599
633
|
|
|
634
|
+
prepareDisconnectedMove(*this,child,parent,reference);
|
|
600
635
|
Node *c = &state.nodes[child];
|
|
601
636
|
const bool localMutation = localAbsoluteLeafTreeMutation(state, child);
|
|
602
637
|
// Detach `child` from its current position first; this may mutate the
|
|
@@ -645,14 +680,178 @@ void Tree::insertBefore(int child, int parent, int reference)
|
|
|
645
680
|
StyleSheet::instance().recomputeSubtree(child);
|
|
646
681
|
}
|
|
647
682
|
|
|
683
|
+
namespace {
|
|
684
|
+
struct TopologySnapshot {
|
|
685
|
+
NodeHandle owner;
|
|
686
|
+
int parent, previous, next, first, last;
|
|
687
|
+
NodeType type;
|
|
688
|
+
std::string tag;
|
|
689
|
+
};
|
|
690
|
+
void captureTopology(Tree &tree, std::vector<TopologySnapshot> &snapshot, int id)
|
|
691
|
+
{
|
|
692
|
+
if (id < 0) return;
|
|
693
|
+
for (const auto &entry : snapshot) if (entry.owner.id() == id) return;
|
|
694
|
+
NodeHandle owner(id);
|
|
695
|
+
if (!owner.valid()) throw std::invalid_argument("mutation requires live nodes");
|
|
696
|
+
const auto &n = tree.node(id);
|
|
697
|
+
snapshot.push_back({owner,n.parent,n.prev_sibling,n.next_sibling,n.first_child,n.last_child,n.type,tree.tagName(id)});
|
|
698
|
+
}
|
|
699
|
+
void validateTopology(Tree &tree, const std::vector<TopologySnapshot> &snapshot)
|
|
700
|
+
{
|
|
701
|
+
for (const auto &entry : snapshot) {
|
|
702
|
+
if (!entry.owner.valid()) throw std::runtime_error("topology changed during focus retirement");
|
|
703
|
+
const auto &n = tree.node(entry.owner.id());
|
|
704
|
+
if (n.parent != entry.parent || n.prev_sibling != entry.previous || n.next_sibling != entry.next ||
|
|
705
|
+
n.first_child != entry.first || n.last_child != entry.last || n.type != entry.type || entry.tag != tree.tagName(entry.owner.id()))
|
|
706
|
+
throw std::runtime_error("topology changed during focus retirement");
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
void retireLeavingFocus(Tree &tree, const std::vector<int> &removed, const std::vector<int> &retained)
|
|
710
|
+
{
|
|
711
|
+
std::vector<NodeHandle> removedOwners, retainedOwners;
|
|
712
|
+
for (int id : removed) removedOwners.emplace_back(id);
|
|
713
|
+
for (int id : retained) retainedOwners.emplace_back(id);
|
|
714
|
+
auto contains = [&](int id, const std::vector<NodeHandle> &roots) {
|
|
715
|
+
if (id < 0) return false;
|
|
716
|
+
for (const auto &root : roots) if (root.valid() && tree.containsNode(root.id(),id)) return true;
|
|
717
|
+
return false;
|
|
718
|
+
};
|
|
719
|
+
auto leaving = [&](int id) { return contains(id,removedOwners) && !contains(id,retainedOwners); };
|
|
720
|
+
const auto native = queryNativeFocus();
|
|
721
|
+
if (native.node.valid() && leaving(native.node.id())) native.node.blur();
|
|
722
|
+
const NodeHandle logical(tree.activeInputId());
|
|
723
|
+
if (logical.valid() && leaving(logical.id())) logical.blur();
|
|
724
|
+
retirePointerInputForSubtrees(removedOwners,retainedOwners);
|
|
725
|
+
retireTouchInputForSubtrees(removedOwners,retainedOwners);
|
|
726
|
+
retirePlatformInputForSubtrees(removedOwners,retainedOwners);
|
|
727
|
+
const auto currentNative = queryNativeFocus();
|
|
728
|
+
if (leaving(tree.activeInputId()) || (currentNative.node.valid() && leaving(currentNative.node.id())))
|
|
729
|
+
throw std::runtime_error("focus retirement refused or reentered removed subtree");
|
|
730
|
+
}
|
|
731
|
+
void prepareDisconnectedMove(Tree &tree, int child, int parent, int reference)
|
|
732
|
+
{
|
|
733
|
+
if (!NodeHandle(child).isConnected() || NodeHandle(parent).isConnected()) return;
|
|
734
|
+
std::vector<TopologySnapshot> snapshot;
|
|
735
|
+
captureTopology(tree,snapshot,child);
|
|
736
|
+
captureTopology(tree,snapshot,tree.node(child).prev_sibling);
|
|
737
|
+
captureTopology(tree,snapshot,tree.node(child).next_sibling);
|
|
738
|
+
for (int ancestor = tree.node(child).parent; ancestor >= 0; ancestor = tree.node(ancestor).parent)
|
|
739
|
+
captureTopology(tree,snapshot,ancestor);
|
|
740
|
+
if (reference >= 0) {
|
|
741
|
+
captureTopology(tree,snapshot,reference);
|
|
742
|
+
captureTopology(tree,snapshot,tree.node(reference).prev_sibling);
|
|
743
|
+
captureTopology(tree,snapshot,tree.node(reference).next_sibling);
|
|
744
|
+
}
|
|
745
|
+
for (int ancestor = parent; ancestor >= 0; ancestor = tree.node(ancestor).parent)
|
|
746
|
+
captureTopology(tree,snapshot,ancestor);
|
|
747
|
+
retireLeavingFocus(tree,{child},{});
|
|
748
|
+
validateTopology(tree,snapshot);
|
|
749
|
+
}
|
|
750
|
+
// No user callbacks here. The allocation, descendants and listeners remain live.
|
|
751
|
+
void unlinkRetainedNode(Tree &tree, int id)
|
|
752
|
+
{
|
|
753
|
+
auto &n = tree.node(id);
|
|
754
|
+
if (n.parent < 0) return;
|
|
755
|
+
auto &parent = tree.node(n.parent);
|
|
756
|
+
if (parent.first_child == id) parent.first_child = n.next_sibling;
|
|
757
|
+
if (parent.last_child == id) parent.last_child = n.prev_sibling;
|
|
758
|
+
if (n.prev_sibling >= 0) tree.node(n.prev_sibling).next_sibling = n.next_sibling;
|
|
759
|
+
if (n.next_sibling >= 0) tree.node(n.next_sibling).prev_sibling = n.prev_sibling;
|
|
760
|
+
parent.render.dirty = parent.render.layout_dirty = 1;
|
|
761
|
+
n.parent = n.prev_sibling = n.next_sibling = -1;
|
|
762
|
+
n.render.dirty = n.render.layout_dirty = 1;
|
|
763
|
+
#if GEA_CSS_SCROLLING
|
|
764
|
+
parent.render.non_scroll_dirty = n.render.non_scroll_dirty = 1;
|
|
765
|
+
#endif
|
|
766
|
+
tree.markDisplayListDirty();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
void Tree::detachNode(int child)
|
|
771
|
+
{
|
|
772
|
+
NodeHandle owner(child);
|
|
773
|
+
if (!owner.valid()) throw std::invalid_argument("detach requires a live node");
|
|
774
|
+
if (node(child).parent < 0) return;
|
|
775
|
+
std::vector<TopologySnapshot> snapshot;
|
|
776
|
+
captureTopology(*this,snapshot,child);
|
|
777
|
+
captureTopology(*this,snapshot,node(child).prev_sibling);
|
|
778
|
+
captureTopology(*this,snapshot,node(child).next_sibling);
|
|
779
|
+
for (int ancestor = node(child).parent; ancestor >= 0; ancestor = node(ancestor).parent)
|
|
780
|
+
captureTopology(*this,snapshot,ancestor);
|
|
781
|
+
retireLeavingFocus(*this,{child},{});
|
|
782
|
+
validateTopology(*this,snapshot);
|
|
783
|
+
unlinkRetainedNode(*this,child);
|
|
784
|
+
StyleSheet::instance().recomputeSubtree(child);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
void Tree::replaceChildren(int parent, const std::vector<int> &children)
|
|
788
|
+
{
|
|
789
|
+
auto &state = treeState();
|
|
790
|
+
NodeHandle parentOwner(parent);
|
|
791
|
+
if (!parentOwner.valid()) throw std::invalid_argument("replaceChildren requires a live parent");
|
|
792
|
+
if (state.nodes[parent].type == NodeType::Comment ||
|
|
793
|
+
(state.nodes[parent].type == NodeType::Text && !*tagName(parent)))
|
|
794
|
+
throw std::invalid_argument("parent cannot contain children");
|
|
795
|
+
std::vector<TopologySnapshot> snapshot;
|
|
796
|
+
for (int ancestor = parent; ancestor >= 0; ancestor = node(ancestor).parent) captureTopology(*this,snapshot,ancestor);
|
|
797
|
+
std::vector<int> old, incoming, moved;
|
|
798
|
+
for (int child = node(parent).first_child; child >= 0; child = node(child).next_sibling) {
|
|
799
|
+
old.push_back(child); captureTopology(*this,snapshot,child);
|
|
800
|
+
}
|
|
801
|
+
auto admit = [&](int child) {
|
|
802
|
+
if (!NodeHandle(child).valid() || reparentWouldCycle(state,child,parent))
|
|
803
|
+
throw std::invalid_argument("replaceChildren invalid child or cycle");
|
|
804
|
+
captureTopology(*this,snapshot,child);
|
|
805
|
+
captureTopology(*this,snapshot,node(child).prev_sibling);
|
|
806
|
+
captureTopology(*this,snapshot,node(child).next_sibling);
|
|
807
|
+
for (int ancestor = node(child).parent; ancestor >= 0; ancestor = node(ancestor).parent)
|
|
808
|
+
captureTopology(*this,snapshot,ancestor);
|
|
809
|
+
// DOM duplicate arguments move the same node to its final occurrence.
|
|
810
|
+
incoming.erase(std::remove(incoming.begin(),incoming.end(),child),incoming.end());
|
|
811
|
+
incoming.push_back(child);
|
|
812
|
+
if (std::find(moved.begin(),moved.end(),child) == moved.end()) moved.push_back(child);
|
|
813
|
+
};
|
|
814
|
+
std::vector<int> drainedFragments;
|
|
815
|
+
for (int child : children) {
|
|
816
|
+
if (!NodeHandle(child).valid() || reparentWouldCycle(state,child,parent))
|
|
817
|
+
throw std::invalid_argument("replaceChildren invalid child or cycle");
|
|
818
|
+
captureTopology(*this,snapshot,child);
|
|
819
|
+
if (node(child).type == NodeType::DocumentFragment) {
|
|
820
|
+
if (std::find(drainedFragments.begin(),drainedFragments.end(),child) != drainedFragments.end()) continue;
|
|
821
|
+
drainedFragments.push_back(child);
|
|
822
|
+
for (int entry = node(child).first_child; entry >= 0; entry = node(entry).next_sibling)
|
|
823
|
+
if (std::find(moved.begin(),moved.end(),entry) == moved.end()) admit(entry);
|
|
824
|
+
} else admit(child);
|
|
825
|
+
}
|
|
826
|
+
retireLeavingFocus(*this,old,incoming);
|
|
827
|
+
validateTopology(*this,snapshot);
|
|
828
|
+
// Finish all topology writes before style recomputation; no user code runs.
|
|
829
|
+
for (int child : old) unlinkRetainedNode(*this,child);
|
|
830
|
+
for (int child : incoming) {
|
|
831
|
+
unlinkRetainedNode(*this,child);
|
|
832
|
+
auto &n = node(child);
|
|
833
|
+
n.parent = parent; n.prev_sibling = node(parent).last_child; n.next_sibling = -1;
|
|
834
|
+
if (n.prev_sibling >= 0) node(n.prev_sibling).next_sibling = child;
|
|
835
|
+
else node(parent).first_child = child;
|
|
836
|
+
node(parent).last_child = child;
|
|
837
|
+
n.render.dirty = n.render.layout_dirty = 1;
|
|
838
|
+
}
|
|
839
|
+
node(parent).render.dirty = node(parent).render.layout_dirty = 1;
|
|
840
|
+
markDisplayListDirty();
|
|
841
|
+
for (int child : old) StyleSheet::instance().recomputeSubtree(child);
|
|
842
|
+
for (int child : incoming) StyleSheet::instance().recomputeSubtree(child);
|
|
843
|
+
}
|
|
844
|
+
|
|
648
845
|
void Tree::removeNode(int id)
|
|
649
846
|
{
|
|
650
847
|
auto &state = treeState();
|
|
651
848
|
if (id < 0 || id >= state.nodeCount || !state.nodeActive[id]) return;
|
|
849
|
+
const auto removingOwner = gea::framework::identity::node(id);
|
|
652
850
|
if (containsNode(id, state.hoveredNodeId)) pointerHover(-1, -1);
|
|
653
851
|
while (state.nodes[id].first_child >= 0) {
|
|
654
852
|
removeNode(state.nodes[id].first_child);
|
|
655
|
-
if (id >= state.nodeCount || !state.nodeActive[id]
|
|
853
|
+
if (id >= state.nodeCount || !state.nodeActive[id] ||
|
|
854
|
+
!gea::framework::identity::current(id, removingOwner)) return;
|
|
656
855
|
}
|
|
657
856
|
Node *n = &state.nodes[id];
|
|
658
857
|
markDisplayListDirty();
|
|
@@ -679,6 +878,12 @@ void Tree::removeNode(int id)
|
|
|
679
878
|
n->last_child = -1;
|
|
680
879
|
n->prev_sibling = -1;
|
|
681
880
|
n->next_sibling = -1;
|
|
881
|
+
// A recycled numeric slot must not inherit the removed root's mount authority.
|
|
882
|
+
if (state.mountedRoot == id) {
|
|
883
|
+
state.mountedRoot = -1;
|
|
884
|
+
state.mountedWidth = 0;
|
|
885
|
+
state.mountedHeight = 0;
|
|
886
|
+
}
|
|
682
887
|
resetNodeSlot(state, id);
|
|
683
888
|
trimInactiveTail(state);
|
|
684
889
|
}
|
package/ui/tree_render.cpp
CHANGED
|
@@ -3614,6 +3614,9 @@ namespace gea::embedded::ui
|
|
|
3614
3614
|
}
|
|
3615
3615
|
n->render.dirty = 1;
|
|
3616
3616
|
n->render.layout_dirty = 1;
|
|
3617
|
+
// record() copies the latest camera pixels into the retained surface.
|
|
3618
|
+
// A repaint alone can replay the cached blit without refreshing it.
|
|
3619
|
+
markNodeDisplayCommandsDirty(i);
|
|
3617
3620
|
#if GEA_CSS_SCROLLING
|
|
3618
3621
|
n->render.non_scroll_dirty = 1;
|
|
3619
3622
|
#endif
|
package/ui/tree_state.h
CHANGED
|
@@ -205,7 +205,10 @@ struct GridTrackLayout {
|
|
|
205
205
|
int columnOrigin = 0, rowOrigin = 0;
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
+
struct ChildNodeListIdentity;
|
|
209
|
+
|
|
208
210
|
struct NodeRareData {
|
|
211
|
+
std::shared_ptr<const ChildNodeListIdentity> childNodeListIdentity;
|
|
209
212
|
// Reuse the listener record's tail padding for inline-position metadata.
|
|
210
213
|
// Both members remain ordinary embedded fields with fixed-offset access.
|
|
211
214
|
[[no_unique_address]] NodeEventListeners listeners;
|
|
@@ -245,6 +248,7 @@ struct NodeRareData {
|
|
|
245
248
|
|
|
246
249
|
void clear()
|
|
247
250
|
{
|
|
251
|
+
childNodeListIdentity.reset();
|
|
248
252
|
attributes.clear();
|
|
249
253
|
listeners.clear();
|
|
250
254
|
customProperties.clear();
|
package/ui/tree_style.cpp
CHANGED
|
@@ -168,6 +168,7 @@ bool isLayoutProperty(Property prop)
|
|
|
168
168
|
case Property::Overflow:
|
|
169
169
|
case Property::OverflowX:
|
|
170
170
|
case Property::OverflowY:
|
|
171
|
+
case Property::FontStretch:
|
|
171
172
|
case Property::FontId:
|
|
172
173
|
case Property::FontSize:
|
|
173
174
|
case Property::FontWeight:
|
|
@@ -937,6 +938,9 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
|
|
|
937
938
|
changed = 1;
|
|
938
939
|
}
|
|
939
940
|
break;
|
|
941
|
+
#endif
|
|
942
|
+
#if GEA_CSS_FONT_STRETCH
|
|
943
|
+
case Property::FontStretch: if (style.font_stretch != value) { style.font_stretch = value; changed = 1; } break;
|
|
940
944
|
#endif
|
|
941
945
|
case Property::FontId: if (style.font_id != value) { style.font_id = value; changed = 1; } break;
|
|
942
946
|
case Property::FontSize: if (style.font_size != value) { style.font_size = value; changed = 1; } break;
|
package/ui/virtual_keyboard.cpp
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#include "node.h"
|
|
1
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
3
|
// On-screen keyboard implemented as document-tree nodes.
|
|
3
4
|
//
|
|
@@ -540,7 +541,7 @@ void applyKeyToActiveInput(int code)
|
|
|
540
541
|
{
|
|
541
542
|
Tree &tree = Tree::instance();
|
|
542
543
|
const int activeId = tree.activeInputId();
|
|
543
|
-
if (activeId < 0) return;
|
|
544
|
+
if (activeId < 0 || !tree.activeInputAdmitted()) return;
|
|
544
545
|
|
|
545
546
|
if (code == kCodeShift) {
|
|
546
547
|
gState.shiftHeld = !gState.shiftHeld;
|
|
@@ -589,6 +590,7 @@ void applyKeyToActiveInput(int code)
|
|
|
589
590
|
if (!next.empty()) {
|
|
590
591
|
next.pop_back();
|
|
591
592
|
tree.setAttribute(activeId, "value", next.c_str());
|
|
593
|
+
tree.markActiveInputEdited();
|
|
592
594
|
markInputDirty(activeId);
|
|
593
595
|
gea::framework::events::PointerEvent ev{};
|
|
594
596
|
ev.type = gea::framework::events::PointerEventType::Input;
|
|
@@ -603,11 +605,15 @@ void applyKeyToActiveInput(int code)
|
|
|
603
605
|
return;
|
|
604
606
|
}
|
|
605
607
|
if (code == kCodeReturn) {
|
|
608
|
+
const NodeHandle originalInput(activeId);
|
|
609
|
+
const char*tag=tree.tagName(activeId);
|
|
610
|
+
const bool commitsReturn=!tag || std::strcmp(tag,"textarea")!=0;
|
|
606
611
|
gea::framework::events::PointerEvent kd{};
|
|
607
612
|
kd.type = gea::framework::events::PointerEventType::KeyDown;
|
|
608
613
|
kd.targetId = activeId;
|
|
609
614
|
kd.keyCode = kCodeReturn;
|
|
610
615
|
tree.dispatchEvent(kd);
|
|
616
|
+
if(commitsReturn && originalInput.valid() && tree.activeInputId()==activeId)tree.commitActiveInput();
|
|
611
617
|
return;
|
|
612
618
|
}
|
|
613
619
|
|
|
@@ -620,6 +626,7 @@ void applyKeyToActiveInput(int code)
|
|
|
620
626
|
}
|
|
621
627
|
next.push_back(c);
|
|
622
628
|
tree.setAttribute(activeId, "value", next.c_str());
|
|
629
|
+
tree.markActiveInputEdited();
|
|
623
630
|
markInputDirty(activeId);
|
|
624
631
|
|
|
625
632
|
gea::framework::events::PointerEvent ev{};
|