@geastack/engine 0.1.6 → 0.1.8
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/README.md +70 -0
- package/canvas.cpp +105 -48
- package/css/declarative.h +6 -0
- package/css/engine.h +20 -0
- package/image_store.cpp +136 -33
- package/package.json +4 -3
- package/ui/CSS_FEATURES.md +261 -0
- package/ui/absolute_leaf_refresh.cpp +77 -62
- package/ui/core.cpp +26 -3
- package/ui/css_atom.cpp +6 -0
- package/ui/css_atom.h +2 -0
- package/ui/css_features.h +369 -0
- package/ui/document.cpp +11 -0
- package/ui/image_node.cpp +25 -24
- package/ui/input.cpp +46 -26
- package/ui/input_render.cpp +31 -27
- package/ui/internal.h +22 -0
- package/ui/layout.cpp +899 -613
- package/ui/layout_snapshot.cpp +29 -2
- package/ui/node_features.h +36 -0
- package/ui/node_lifecycle.cpp +358 -84
- package/ui/node_lifecycle.h +1 -0
- package/ui/node_model.h +816 -96
- package/ui/node_text.h +84 -0
- package/ui/refresh_perf.h +19 -17
- package/ui/render.cpp +341 -259
- package/ui/renderer_features.h +24 -0
- package/ui/root_scroll_refresh.cpp +86 -69
- package/ui/storage_usage.h +45 -0
- package/ui/style.cpp +1398 -349
- package/ui/style_values.h +2 -2
- package/ui/text.cpp +172 -154
- package/ui/tree_events.cpp +218 -92
- package/ui/tree_events.h +44 -20
- package/ui/tree_inspection.h +15 -0
- package/ui/tree_nodes.cpp +51 -19
- package/ui/tree_render.cpp +159 -126
- package/ui/tree_scroll_mirror.cpp +30 -4
- package/ui/tree_state.cpp +334 -115
- package/ui/tree_state.h +118 -22
- package/ui/tree_style.cpp +679 -303
- package/ui/view.cpp +268 -208
- package/ui/virtual_keyboard.cpp +18 -11
package/ui/tree_events.cpp
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
#include "tree_internal.h"
|
|
7
7
|
#include "tree_state.h"
|
|
8
8
|
|
|
9
|
+
#include <algorithm>
|
|
10
|
+
#include <new>
|
|
9
11
|
#include <cstddef>
|
|
10
12
|
#include <cstdio>
|
|
11
13
|
#include <cstring>
|
|
12
|
-
#include <deque>
|
|
13
14
|
#include <utility>
|
|
14
15
|
#include <vector>
|
|
15
16
|
|
|
@@ -58,8 +59,10 @@ void applyAudioAttribute(Tree &tree, int node, const char *name, const char *val
|
|
|
58
59
|
// setEventListener (on the empty->set transition) and NodeEventListeners::clear()
|
|
59
60
|
// (which every removal path calls).
|
|
60
61
|
constexpr int kEventTypeCount = 7;
|
|
62
|
+
#if GEA_UI_NODE_LISTENERS
|
|
61
63
|
int g_listenerTypeCounts[kEventTypeCount] = {};
|
|
62
64
|
EventListenerId g_nextEventListenerId = 1;
|
|
65
|
+
#endif
|
|
63
66
|
|
|
64
67
|
int eventTypeIndex(const char *type)
|
|
65
68
|
{
|
|
@@ -154,29 +157,79 @@ bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event)
|
|
|
154
157
|
// Cold/optional per-node state (currently event listeners) lives here instead
|
|
155
158
|
// of a dense [kMaxNodes] array. A node holds an int16 handle (Node::rare_data,
|
|
156
159
|
// -1 = none) into this pool; a block is allocated lazily the first time a node
|
|
157
|
-
// needs one and returned to a free list when the node is reset.
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
160
|
+
// needs one and returned to a free list when the node is reset. Owned records
|
|
161
|
+
// keep their addresses STABLE while the pointer table grows: the dispatcher
|
|
162
|
+
// retains NodeRareData* across re-entrant handlers. A direct pointer table also
|
|
163
|
+
// avoids deque's block arithmetic changing when record compaction crosses its
|
|
164
|
+
// block-size thresholds. The free list keeps allocations bounded and reused.
|
|
161
165
|
namespace {
|
|
162
|
-
std::
|
|
166
|
+
std::vector<std::unique_ptr<NodeRareData>> g_rareDataPool;
|
|
163
167
|
std::vector<int16_t> g_rareDataFreeList;
|
|
164
168
|
} // namespace
|
|
165
169
|
|
|
170
|
+
NodeAuxiliaryStorageUsage nodeAuxiliaryStorageUsage()
|
|
171
|
+
{
|
|
172
|
+
NodeAuxiliaryStorageUsage result;
|
|
173
|
+
result.tree = treeStorageUsage();
|
|
174
|
+
result.text = NodeText::storageUsage();
|
|
175
|
+
result.dependencies = styleDependencyStorageUsage();
|
|
176
|
+
auto &usage = result.rare;
|
|
177
|
+
usage.staticBytes = sizeof(g_rareDataPool) + sizeof(g_rareDataFreeList) + sizeof(g_documentKeyDownListener) + sizeof(g_documentRotaryListener);
|
|
178
|
+
#if GEA_UI_NODE_LISTENERS
|
|
179
|
+
usage.staticBytes += sizeof(g_listenerTypeCounts) + sizeof(g_nextEventListenerId);
|
|
180
|
+
#endif
|
|
181
|
+
if (g_documentKeyDownListener) ++usage.untrackedOwners;
|
|
182
|
+
if (g_documentRotaryListener) ++usage.untrackedOwners;
|
|
183
|
+
usage.addVector(g_rareDataPool);
|
|
184
|
+
usage.addVector(g_rareDataFreeList);
|
|
185
|
+
for (const auto &record : g_rareDataPool) {
|
|
186
|
+
usage.addAllocation(record.get(), sizeof(NodeRareData));
|
|
187
|
+
#if GEA_UI_NODE_LISTENERS
|
|
188
|
+
usage.addVector(record->listeners.entries);
|
|
189
|
+
for (const auto &listener : record->listeners.entries)
|
|
190
|
+
if (listener.listener.use_count()) ++usage.untrackedOwners;
|
|
191
|
+
#endif
|
|
192
|
+
#if GEA_UI_NODE_ATTRIBUTES
|
|
193
|
+
for (auto *entry = record->attributes.values.get(); entry; entry = entry->next.get())
|
|
194
|
+
usage.addAllocation(entry, sizeof(NodeAttributeEntry) + entry->nameBytes + entry->valueCapacity);
|
|
195
|
+
#endif
|
|
196
|
+
#if GEA_CSS_CUSTOM_PROPERTIES
|
|
197
|
+
for (const auto *properties : {&record->customProperties, &record->inlineCustomProperties}) {
|
|
198
|
+
usage.addVector(properties->values);
|
|
199
|
+
for (const auto &property : properties->values)
|
|
200
|
+
if (property.value.use_count()) ++usage.untrackedOwners;
|
|
201
|
+
}
|
|
202
|
+
#endif
|
|
203
|
+
result.overrides += record->defaultStyles.storageUsage();
|
|
204
|
+
result.overrides += record->inlineStyles.storageUsage();
|
|
205
|
+
#if GEA_CSS_GRID
|
|
206
|
+
if (record->gridLayout) {
|
|
207
|
+
usage.addAllocation(record->gridLayout.get(), sizeof(GridTrackLayout));
|
|
208
|
+
usage.addVector(record->gridLayout->columnStart); usage.addVector(record->gridLayout->columnEnd);
|
|
209
|
+
usage.addVector(record->gridLayout->rowStart); usage.addVector(record->gridLayout->rowEnd);
|
|
210
|
+
}
|
|
211
|
+
#endif
|
|
212
|
+
#if GEA_CSS_SCROLLING
|
|
213
|
+
usage.addAllocation(record->virtualList.get(), sizeof(VirtualListNodeState));
|
|
214
|
+
#endif
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
|
|
166
219
|
NodeRareData &ensureRareData(int node)
|
|
167
220
|
{
|
|
168
221
|
auto &state = treeState();
|
|
169
222
|
int16_t handle = state.nodes[node].rare_data;
|
|
170
|
-
if (handle >= 0) return g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
223
|
+
if (handle >= 0) return *g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
171
224
|
if (!g_rareDataFreeList.empty()) {
|
|
172
225
|
handle = g_rareDataFreeList.back();
|
|
173
226
|
g_rareDataFreeList.pop_back();
|
|
174
227
|
} else {
|
|
175
228
|
handle = static_cast<int16_t>(g_rareDataPool.size());
|
|
176
|
-
g_rareDataPool.emplace_back();
|
|
229
|
+
g_rareDataPool.emplace_back(std::make_unique<NodeRareData>());
|
|
177
230
|
}
|
|
178
231
|
state.nodes[node].rare_data = handle;
|
|
179
|
-
return g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
232
|
+
return *g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
180
233
|
}
|
|
181
234
|
|
|
182
235
|
NodeRareData *rareDataFor(int node)
|
|
@@ -184,7 +237,7 @@ NodeRareData *rareDataFor(int node)
|
|
|
184
237
|
auto &state = treeState();
|
|
185
238
|
if (node < 0 || node >= kMaxNodes) return nullptr;
|
|
186
239
|
const int16_t handle = state.nodes[node].rare_data;
|
|
187
|
-
return handle >= 0 ?
|
|
240
|
+
return handle >= 0 ? g_rareDataPool[static_cast<std::size_t>(handle)].get() : nullptr;
|
|
188
241
|
}
|
|
189
242
|
|
|
190
243
|
void releaseRareData(int node)
|
|
@@ -193,52 +246,116 @@ void releaseRareData(int node)
|
|
|
193
246
|
if (node < 0 || node >= kMaxNodes) return;
|
|
194
247
|
const int16_t handle = state.nodes[node].rare_data;
|
|
195
248
|
if (handle < 0) return;
|
|
196
|
-
g_rareDataPool[static_cast<std::size_t>(handle)]
|
|
249
|
+
g_rareDataPool[static_cast<std::size_t>(handle)]->clear();
|
|
197
250
|
g_rareDataFreeList.push_back(handle);
|
|
198
251
|
state.nodes[node].rare_data = -1;
|
|
199
252
|
}
|
|
200
253
|
|
|
254
|
+
void NodeAttributeDeleter::operator()(NodeAttributeEntry *entry) const
|
|
255
|
+
{
|
|
256
|
+
entry->~NodeAttributeEntry();
|
|
257
|
+
::operator delete(entry);
|
|
258
|
+
}
|
|
259
|
+
NodeAttributePtr NodeAttributeEntry::create(const char *name, const char *value)
|
|
260
|
+
{
|
|
261
|
+
if (!value) value = "";
|
|
262
|
+
const auto nameBytes = std::min(std::strlen(name), std::size_t(kNodeAttributeNameMax - 1)) + 1;
|
|
263
|
+
const auto valueBytes = std::min(std::strlen(value), std::size_t(kNodeAttributeValueMax - 1)) + 1;
|
|
264
|
+
auto *entry = new (::operator new(sizeof(NodeAttributeEntry) + nameBytes + valueBytes)) NodeAttributeEntry;
|
|
265
|
+
entry->nameBytes = nameBytes;
|
|
266
|
+
entry->valueCapacity = valueBytes;
|
|
267
|
+
copyBounded(reinterpret_cast<char *>(entry + 1), nameBytes, name);
|
|
268
|
+
copyBounded(entry->value(), valueBytes, value);
|
|
269
|
+
return NodeAttributePtr(entry);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
#if GEA_UI_NODE_ATTRIBUTES
|
|
273
|
+
NodeAttributeStore::NodeAttributeStore(const NodeAttributeStore &other)
|
|
274
|
+
: pressId(other.pressId), pressValue(other.pressValue), idAtom(other.idAtom), count(other.count)
|
|
275
|
+
{
|
|
276
|
+
auto *tail = &values;
|
|
277
|
+
for (auto *entry = other.values.get(); entry; entry = entry->next.get()) {
|
|
278
|
+
*tail = NodeAttributeEntry::create(entry->name(), entry->value());
|
|
279
|
+
tail = &(*tail)->next;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
NodeAttributeStore &NodeAttributeStore::operator=(const NodeAttributeStore &other)
|
|
284
|
+
{
|
|
285
|
+
if (this != &other) {
|
|
286
|
+
NodeAttributeStore copy(other);
|
|
287
|
+
*this = std::move(copy);
|
|
288
|
+
}
|
|
289
|
+
return *this;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
NodeAttributeStore::NodeAttributeStore(NodeAttributeStore &&other) noexcept
|
|
293
|
+
{
|
|
294
|
+
*this = std::move(other);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
NodeAttributeStore &NodeAttributeStore::operator=(NodeAttributeStore &&other) noexcept
|
|
298
|
+
{
|
|
299
|
+
if (this == &other) return *this;
|
|
300
|
+
values = std::move(other.values);
|
|
301
|
+
pressId = other.pressId;
|
|
302
|
+
pressValue = other.pressValue;
|
|
303
|
+
idAtom = other.idAtom;
|
|
304
|
+
count = other.count;
|
|
305
|
+
other.clear();
|
|
306
|
+
return *this;
|
|
307
|
+
}
|
|
308
|
+
|
|
201
309
|
void NodeAttributeStore::clear()
|
|
202
310
|
{
|
|
203
311
|
pressId = -1;
|
|
204
312
|
pressValue = -1;
|
|
205
313
|
idAtom = kInvalidCssAtom;
|
|
206
314
|
count = 0;
|
|
207
|
-
|
|
208
|
-
attr.name[0] = '\0';
|
|
209
|
-
attr.value[0] = '\0';
|
|
210
|
-
}
|
|
315
|
+
values.reset();
|
|
211
316
|
}
|
|
212
317
|
|
|
213
318
|
void NodeAttributeStore::set(const char *name, const char *value)
|
|
214
319
|
{
|
|
215
|
-
if (!name || name
|
|
320
|
+
if (!name || !*name) return;
|
|
321
|
+
if (!value) value = "";
|
|
216
322
|
const bool isId = sameName(name, "id");
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
|
|
323
|
+
auto *tail = &values;
|
|
324
|
+
while (*tail) {
|
|
325
|
+
auto &entry = **tail;
|
|
326
|
+
if (sameName(entry.name(), name)) {
|
|
327
|
+
const auto bytes = std::min(std::strlen(value), std::size_t(kNodeAttributeValueMax - 1)) + 1;
|
|
328
|
+
if (bytes > entry.valueCapacity) {
|
|
329
|
+
// Allocate/copy first: value may point into the existing entry.
|
|
330
|
+
auto replacement = NodeAttributeEntry::create(name, value);
|
|
331
|
+
replacement->next = std::move(entry.next);
|
|
332
|
+
*tail = std::move(replacement);
|
|
333
|
+
} else {
|
|
334
|
+
std::memmove(entry.value(), value, bytes - 1);
|
|
335
|
+
entry.value()[bytes - 1] = 0;
|
|
336
|
+
}
|
|
337
|
+
if (isId) idAtom = internCssAtom((*tail)->value());
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
tail = &entry.next;
|
|
222
341
|
}
|
|
223
342
|
if (count >= kMaxNodeAttributes) return;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
count
|
|
343
|
+
auto entry = NodeAttributeEntry::create(name, value);
|
|
344
|
+
if (isId) idAtom = internCssAtom(entry->value());
|
|
345
|
+
*tail = std::move(entry);
|
|
346
|
+
++count;
|
|
228
347
|
}
|
|
229
348
|
|
|
230
349
|
bool NodeAttributeStore::remove(const char *name)
|
|
231
350
|
{
|
|
232
351
|
if (!name) return false;
|
|
233
|
-
for (
|
|
234
|
-
if (!sameName(
|
|
352
|
+
for (auto *link = &values; *link; link = &(*link)->next) {
|
|
353
|
+
if (!sameName((*link)->name(), name)) continue;
|
|
235
354
|
if (sameName(name, "id")) idAtom = kInvalidCssAtom;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
355
|
+
// Keep the removed owner alive while moving its next link.
|
|
356
|
+
auto removed = std::move(*link);
|
|
357
|
+
*link = std::move(removed->next);
|
|
239
358
|
count--;
|
|
240
|
-
values[count].name[0] = '\0';
|
|
241
|
-
values[count].value[0] = '\0';
|
|
242
359
|
return true;
|
|
243
360
|
}
|
|
244
361
|
return false;
|
|
@@ -247,8 +364,8 @@ bool NodeAttributeStore::remove(const char *name)
|
|
|
247
364
|
const char *NodeAttributeStore::get(const char *name) const
|
|
248
365
|
{
|
|
249
366
|
if (!name) return "";
|
|
250
|
-
for (
|
|
251
|
-
if (sameName(
|
|
367
|
+
for (auto *entry = values.get(); entry; entry = entry->next.get()) {
|
|
368
|
+
if (sameName(entry->name(), name)) return entry->value();
|
|
252
369
|
}
|
|
253
370
|
return "";
|
|
254
371
|
}
|
|
@@ -256,94 +373,83 @@ const char *NodeAttributeStore::get(const char *name) const
|
|
|
256
373
|
bool NodeAttributeStore::has(const char *name) const
|
|
257
374
|
{
|
|
258
375
|
if (!name) return false;
|
|
259
|
-
for (
|
|
260
|
-
if (sameName(
|
|
376
|
+
for (auto *entry = values.get(); entry; entry = entry->next.get()) {
|
|
377
|
+
if (sameName(entry->name(), name)) return true;
|
|
261
378
|
}
|
|
262
379
|
return false;
|
|
263
380
|
}
|
|
264
381
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
// Releasing a non-empty list drops a node from its type's live-listener count, so
|
|
268
|
-
// the dispatcher stops walking the tree for a type once its last listener
|
|
269
|
-
// goes away.
|
|
270
|
-
const auto release = [](NodeEventListenerList &list, int index) {
|
|
271
|
-
if (!list.empty() && g_listenerTypeCounts[index] > 0) g_listenerTypeCounts[index]--;
|
|
272
|
-
list.entries.clear();
|
|
273
|
-
};
|
|
274
|
-
release(click, 0);
|
|
275
|
-
release(touchstart, 1);
|
|
276
|
-
release(touchmove, 2);
|
|
277
|
-
release(touchend, 3);
|
|
278
|
-
release(input, 4);
|
|
279
|
-
release(keydown, 5);
|
|
280
|
-
release(scroll, 6);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
NodeEventListenerList *NodeEventListeners::listenersFor(const char *type)
|
|
382
|
+
#else
|
|
383
|
+
void NodeAttributeStore::set(const char *name, const char *)
|
|
284
384
|
{
|
|
285
|
-
if (
|
|
286
|
-
// Pointer events alias onto their touch* sibling slot — see eventTypeIndex.
|
|
287
|
-
if (sameName(type, "touchstart") || sameName(type, "pointerdown")) return &touchstart;
|
|
288
|
-
if (sameName(type, "touchmove") || sameName(type, "pointermove")) return &touchmove;
|
|
289
|
-
if (sameName(type, "touchend") || sameName(type, "pointerup")) return &touchend;
|
|
290
|
-
if (sameName(type, "input")) return &input;
|
|
291
|
-
if (sameName(type, "keydown")) return &keydown;
|
|
292
|
-
if (sameName(type, "scroll")) return &scroll;
|
|
293
|
-
return nullptr;
|
|
385
|
+
if (name && *name) std::abort(); // A source proof must never discard a live attribute.
|
|
294
386
|
}
|
|
387
|
+
#endif
|
|
295
388
|
|
|
296
|
-
|
|
389
|
+
void NodeEventListeners::clear()
|
|
297
390
|
{
|
|
298
|
-
|
|
299
|
-
|
|
391
|
+
#if GEA_UI_NODE_LISTENERS
|
|
392
|
+
for (int type = 0; type < 7; ++type)
|
|
393
|
+
if (hasType(type) && g_listenerTypeCounts[type] > 0) --g_listenerTypeCounts[type];
|
|
394
|
+
entries.clear();
|
|
395
|
+
types = 0;
|
|
396
|
+
#else
|
|
300
397
|
|
|
301
|
-
|
|
302
|
-
{
|
|
303
|
-
return !click.empty() || !touchstart.empty() || !touchmove.empty() ||
|
|
304
|
-
!touchend.empty() || !input.empty() || !keydown.empty() || !scroll.empty();
|
|
398
|
+
#endif
|
|
305
399
|
}
|
|
306
400
|
|
|
307
401
|
EventListenerId Tree::setEventListener(int node, const char *type, gea::framework::events::EventListener listener)
|
|
308
402
|
{
|
|
403
|
+
#if GEA_UI_NODE_LISTENERS
|
|
309
404
|
auto &state = treeState();
|
|
310
405
|
if (node < 0 || node >= state.nodeCount) return kInvalidEventListenerId;
|
|
311
406
|
if (!listener) return kInvalidEventListenerId;
|
|
312
407
|
// Don't allocate a rare-data block for an unrecognized event type (the set
|
|
313
408
|
// listenerFor knows == the set eventTypeIndex tracks).
|
|
314
409
|
if (eventTypeIndex(type) < 0) return kInvalidEventListenerId;
|
|
315
|
-
auto
|
|
316
|
-
if (!list) return kInvalidEventListenerId;
|
|
317
|
-
// First listener for this (node, type): bump the type's live count so the
|
|
318
|
-
// dispatcher knows the type is worth walking the tree for.
|
|
410
|
+
auto &list = ensureRareData(node).listeners;
|
|
319
411
|
const int typeIndex = eventTypeIndex(type);
|
|
320
|
-
if (list
|
|
412
|
+
if (!list.hasType(typeIndex)) {
|
|
413
|
+
++g_listenerTypeCounts[typeIndex];
|
|
414
|
+
list.types |= 1u << typeIndex;
|
|
415
|
+
}
|
|
321
416
|
EventListenerId id = g_nextEventListenerId++;
|
|
322
417
|
if (id == kInvalidEventListenerId) id = g_nextEventListenerId++;
|
|
323
|
-
list
|
|
324
|
-
id,
|
|
418
|
+
list.entries.push_back(NodeEventListenerEntry{
|
|
419
|
+
id, static_cast<std::uint8_t>(typeIndex),
|
|
325
420
|
std::make_shared<gea::framework::events::EventListener>(std::move(listener))});
|
|
326
421
|
return id;
|
|
422
|
+
#else
|
|
423
|
+
if (node >= 0 && node < treeState().nodeCount && listener && eventTypeIndex(type) >= 0) std::abort();
|
|
424
|
+
return kInvalidEventListenerId;
|
|
425
|
+
#endif
|
|
327
426
|
}
|
|
328
427
|
|
|
329
428
|
bool Tree::removeEventListener(int node, const char *type, EventListenerId listenerId)
|
|
330
429
|
{
|
|
430
|
+
#if GEA_UI_NODE_LISTENERS
|
|
331
431
|
auto &state = treeState();
|
|
332
432
|
if (node < 0 || node >= state.nodeCount || listenerId == kInvalidEventListenerId) return false;
|
|
333
433
|
NodeRareData *rd = rareDataFor(node);
|
|
334
434
|
if (!rd) return false;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
435
|
+
auto &list = rd->listeners;
|
|
436
|
+
const int typeIndex = eventTypeIndex(type);
|
|
437
|
+
if (!list.hasType(typeIndex)) return false;
|
|
438
|
+
for (auto it = list.entries.begin(); it != list.entries.end(); ++it) {
|
|
439
|
+
if (it->id != listenerId || it->type != typeIndex) continue;
|
|
440
|
+
list.entries.erase(it);
|
|
441
|
+
const bool remains = std::any_of(list.entries.begin(), list.entries.end(),
|
|
442
|
+
[typeIndex](const auto &entry) { return entry.type == typeIndex; });
|
|
443
|
+
if (!remains) {
|
|
444
|
+
list.types &= ~(1u << typeIndex);
|
|
445
|
+
if (g_listenerTypeCounts[typeIndex] > 0) --g_listenerTypeCounts[typeIndex];
|
|
343
446
|
}
|
|
344
447
|
return true;
|
|
345
448
|
}
|
|
346
449
|
return false;
|
|
450
|
+
#else
|
|
451
|
+
return false;
|
|
452
|
+
#endif
|
|
347
453
|
}
|
|
348
454
|
|
|
349
455
|
bool Tree::hasEventListener(int node) const
|
|
@@ -356,14 +462,19 @@ bool Tree::hasEventListener(int node) const
|
|
|
356
462
|
|
|
357
463
|
bool Tree::hasListenersForType(const char *type) const
|
|
358
464
|
{
|
|
465
|
+
#if GEA_UI_NODE_LISTENERS
|
|
359
466
|
const int index = eventTypeIndex(type);
|
|
360
467
|
// Unknown/untracked types fall through to dispatch — never silently drop an
|
|
361
468
|
// event we don't account for.
|
|
362
469
|
return index < 0 || g_listenerTypeCounts[index] > 0;
|
|
470
|
+
#else
|
|
471
|
+
return false;
|
|
472
|
+
#endif
|
|
363
473
|
}
|
|
364
474
|
|
|
365
475
|
bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
366
476
|
{
|
|
477
|
+
#if GEA_UI_NODE_LISTENERS
|
|
367
478
|
auto &state = treeState();
|
|
368
479
|
if (event.targetId < 0 || event.targetId >= state.nodeCount) return false;
|
|
369
480
|
|
|
@@ -373,8 +484,8 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
|
373
484
|
if (!event.bubbles && node != event.targetId) break;
|
|
374
485
|
NodeRareData *rd = rareDataFor(node);
|
|
375
486
|
if (!rd) continue;
|
|
376
|
-
|
|
377
|
-
if (!
|
|
487
|
+
const int typeIndex = eventTypeIndex(event.typeName());
|
|
488
|
+
if (!rd->listeners.hasType(typeIndex)) continue;
|
|
378
489
|
|
|
379
490
|
event.currentTargetId = node;
|
|
380
491
|
event.currentTarget = gea::framework::events::EventTarget(node);
|
|
@@ -393,16 +504,16 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
|
393
504
|
// keeps the in-flight function alive after its entry is erased. Reacquire the
|
|
394
505
|
// list after every callback and advance by monotonic listener id; listeners
|
|
395
506
|
// added during this dispatch are above maxId and do not receive this event.
|
|
396
|
-
const EventListenerId maxId =
|
|
507
|
+
const EventListenerId maxId = rd->listeners.entries.back().id;
|
|
397
508
|
EventListenerId cursor = kInvalidEventListenerId;
|
|
398
509
|
for (;;) {
|
|
399
510
|
rd = rareDataFor(node);
|
|
400
511
|
if (!rd) break;
|
|
401
|
-
|
|
402
|
-
if (!list || list->empty()) break;
|
|
512
|
+
if (!rd->listeners.hasType(typeIndex)) break;
|
|
403
513
|
EventListenerId nextId = kInvalidEventListenerId;
|
|
404
514
|
std::shared_ptr<gea::framework::events::EventListener> callback;
|
|
405
|
-
for (const auto &entry :
|
|
515
|
+
for (const auto &entry : rd->listeners.entries) {
|
|
516
|
+
if (entry.type != typeIndex) continue;
|
|
406
517
|
if (entry.id <= cursor || entry.id > maxId) continue;
|
|
407
518
|
nextId = entry.id;
|
|
408
519
|
callback = entry.listener;
|
|
@@ -416,6 +527,9 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
|
416
527
|
if (event.propagationStopped || !event.bubbles) break;
|
|
417
528
|
}
|
|
418
529
|
return dispatched;
|
|
530
|
+
#else
|
|
531
|
+
return false;
|
|
532
|
+
#endif
|
|
419
533
|
}
|
|
420
534
|
|
|
421
535
|
bool Tree::containsNode(int ancestor, int node) const
|
|
@@ -498,7 +612,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
|
|
|
498
612
|
// (e.g. an EPUB cover applied via setAttribute) never paints.
|
|
499
613
|
markDisplayListDirty();
|
|
500
614
|
state.nodes[node].render.dirty = 1;
|
|
615
|
+
#if GEA_CSS_SCROLLING
|
|
501
616
|
state.nodes[node].render.non_scroll_dirty = 1;
|
|
617
|
+
#endif
|
|
502
618
|
}
|
|
503
619
|
}
|
|
504
620
|
if (state.nodes[node].type == NodeType::Image && sameName(name, "fit")) {
|
|
@@ -518,7 +634,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
|
|
|
518
634
|
state.displayListDirty = true;
|
|
519
635
|
state.nodes[node].render.dirty = 1;
|
|
520
636
|
state.nodes[node].render.layout_dirty = 1;
|
|
637
|
+
#if GEA_CSS_SCROLLING
|
|
521
638
|
state.nodes[node].render.non_scroll_dirty = 1;
|
|
639
|
+
#endif
|
|
522
640
|
}
|
|
523
641
|
}
|
|
524
642
|
|
|
@@ -534,14 +652,18 @@ void Tree::removeAttribute(int node, const char *name)
|
|
|
534
652
|
if (!rd) return; // no rare-data block → no attributes to remove
|
|
535
653
|
const bool hadAttribute = rd->attributes.remove(name);
|
|
536
654
|
if (!hadAttribute) return;
|
|
655
|
+
#if GEA_UI_NODE_ATTRIBUTES
|
|
537
656
|
if (sameName(name, "data-press-id")) rd->attributes.pressId = -1;
|
|
538
657
|
if (sameName(name, "data-press-value")) rd->attributes.pressValue = -1;
|
|
658
|
+
#endif
|
|
539
659
|
if (attributeAffectsRendering(state.nodes[node], name)) {
|
|
540
660
|
markNodeDisplayCommandsDirty(node);
|
|
541
661
|
state.displayListDirty = true;
|
|
542
662
|
state.nodes[node].render.dirty = 1;
|
|
543
663
|
state.nodes[node].render.layout_dirty = 1;
|
|
664
|
+
#if GEA_CSS_SCROLLING
|
|
544
665
|
state.nodes[node].render.non_scroll_dirty = 1;
|
|
666
|
+
#endif
|
|
545
667
|
}
|
|
546
668
|
}
|
|
547
669
|
|
|
@@ -588,7 +710,9 @@ void Tree::setPressId(int node, int pressId)
|
|
|
588
710
|
auto &state = treeState();
|
|
589
711
|
if (node < 0 || node >= state.nodeCount) return;
|
|
590
712
|
auto &attrs = ensureRareData(node).attributes;
|
|
713
|
+
#if GEA_UI_NODE_ATTRIBUTES
|
|
591
714
|
attrs.pressId = static_cast<int16_t>(pressId);
|
|
715
|
+
#endif
|
|
592
716
|
char value[16];
|
|
593
717
|
std::snprintf(value, sizeof(value), "%d", pressId);
|
|
594
718
|
attrs.set("data-press-id", value);
|
|
@@ -607,7 +731,9 @@ void Tree::setPressValue(int node, int pressValue)
|
|
|
607
731
|
auto &state = treeState();
|
|
608
732
|
if (node < 0 || node >= state.nodeCount) return;
|
|
609
733
|
auto &attrs = ensureRareData(node).attributes;
|
|
734
|
+
#if GEA_UI_NODE_ATTRIBUTES
|
|
610
735
|
attrs.pressValue = static_cast<int16_t>(pressValue);
|
|
736
|
+
#endif
|
|
611
737
|
char value[16];
|
|
612
738
|
std::snprintf(value, sizeof(value), "%d", pressValue);
|
|
613
739
|
attrs.set("data-press-value", value);
|
package/ui/tree_events.h
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "events.h"
|
|
6
6
|
#include "node_model.h"
|
|
7
7
|
|
|
8
|
+
#include <array>
|
|
8
9
|
#include <cstdint>
|
|
9
10
|
#include <memory>
|
|
10
11
|
#include <vector>
|
|
@@ -15,23 +16,52 @@ inline constexpr int kMaxNodeAttributes = 8;
|
|
|
15
16
|
inline constexpr int kNodeAttributeNameMax = 32;
|
|
16
17
|
inline constexpr int kNodeAttributeValueMax = 64;
|
|
17
18
|
|
|
18
|
-
struct
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
struct NodeAttributeEntry;
|
|
20
|
+
struct NodeAttributeDeleter {
|
|
21
|
+
void operator()(NodeAttributeEntry *entry) const;
|
|
22
|
+
};
|
|
23
|
+
using NodeAttributePtr = std::unique_ptr<NodeAttributeEntry, NodeAttributeDeleter>;
|
|
24
|
+
struct NodeAttributeEntry {
|
|
25
|
+
NodeAttributePtr next;
|
|
26
|
+
std::uint8_t nameBytes = 0, valueCapacity = 0;
|
|
27
|
+
// The allocation continues with nameBytes + valueCapacity bytes. Updating
|
|
28
|
+
// another attribute never moves this entry or invalidates its string.
|
|
29
|
+
const char *name() const { return reinterpret_cast<const char *>(this + 1); }
|
|
30
|
+
char *value() { return reinterpret_cast<char *>(this + 1) + nameBytes; }
|
|
31
|
+
const char *value() const { return reinterpret_cast<const char *>(this + 1) + nameBytes; }
|
|
32
|
+
static NodeAttributePtr create(const char *name, const char *value);
|
|
21
33
|
};
|
|
22
34
|
|
|
23
35
|
struct NodeAttributeStore {
|
|
36
|
+
#if GEA_UI_NODE_ATTRIBUTES
|
|
24
37
|
int16_t pressId = -1;
|
|
25
38
|
int16_t pressValue = -1;
|
|
26
39
|
CssAtomId idAtom = kInvalidCssAtom;
|
|
27
40
|
uint8_t count = 0;
|
|
28
|
-
|
|
41
|
+
// Allocate only attributes that exist. Entries stay at stable addresses
|
|
42
|
+
// as other attributes are added/removed; an empty store allocates nothing.
|
|
43
|
+
NodeAttributePtr values;
|
|
44
|
+
|
|
45
|
+
NodeAttributeStore() = default;
|
|
46
|
+
NodeAttributeStore(const NodeAttributeStore &other);
|
|
47
|
+
NodeAttributeStore &operator=(const NodeAttributeStore &other);
|
|
48
|
+
NodeAttributeStore(NodeAttributeStore &&other) noexcept;
|
|
49
|
+
NodeAttributeStore &operator=(NodeAttributeStore &&other) noexcept;
|
|
29
50
|
|
|
30
51
|
void clear();
|
|
31
52
|
void set(const char *name, const char *value);
|
|
32
53
|
bool remove(const char *name);
|
|
33
54
|
const char *get(const char *name) const;
|
|
34
55
|
bool has(const char *name) const;
|
|
56
|
+
#else
|
|
57
|
+
static constexpr int16_t pressId = -1, pressValue = -1;
|
|
58
|
+
static constexpr CssAtomId idAtom = kInvalidCssAtom;
|
|
59
|
+
void clear() {}
|
|
60
|
+
void set(const char *name, const char *value);
|
|
61
|
+
bool remove(const char *) { return false; }
|
|
62
|
+
const char *get(const char *) const { return ""; }
|
|
63
|
+
bool has(const char *) const { return false; }
|
|
64
|
+
#endif
|
|
35
65
|
};
|
|
36
66
|
|
|
37
67
|
using gea::framework::events::EventListenerId;
|
|
@@ -39,28 +69,22 @@ using gea::framework::events::kInvalidEventListenerId;
|
|
|
39
69
|
|
|
40
70
|
struct NodeEventListenerEntry {
|
|
41
71
|
EventListenerId id = kInvalidEventListenerId;
|
|
72
|
+
std::uint8_t type = 0;
|
|
42
73
|
std::shared_ptr<gea::framework::events::EventListener> listener;
|
|
43
74
|
};
|
|
44
75
|
|
|
45
|
-
struct NodeEventListenerList {
|
|
46
|
-
std::vector<NodeEventListenerEntry> entries;
|
|
47
|
-
|
|
48
|
-
bool empty() const { return entries.empty(); }
|
|
49
|
-
};
|
|
50
|
-
|
|
51
76
|
struct NodeEventListeners {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
#if GEA_UI_NODE_LISTENERS
|
|
78
|
+
std::vector<NodeEventListenerEntry> entries;
|
|
79
|
+
std::uint8_t types = 0;
|
|
80
|
+
#else
|
|
81
|
+
inline static constexpr std::array<NodeEventListenerEntry, 0> entries{};
|
|
82
|
+
static constexpr std::uint8_t types = 0;
|
|
83
|
+
#endif
|
|
59
84
|
|
|
60
85
|
void clear();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
bool hasAny() const;
|
|
86
|
+
bool hasType(int type) const { return type >= 0 && (types & (1u << type)); }
|
|
87
|
+
bool hasAny() const { return types != 0; }
|
|
64
88
|
};
|
|
65
89
|
|
|
66
90
|
// NOTE: the NodeRareData block (which bundles attributes + listeners + other
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
namespace gea::embedded::ui {
|
|
5
|
+
|
|
6
|
+
// Read-only native diagnostics. This header intentionally exposes no node or
|
|
7
|
+
// style representation and cannot introduce CSS operations behind the source
|
|
8
|
+
// analyzer's back. As with Tree, callers must respect the UI task's ownership.
|
|
9
|
+
struct TreeInspection {
|
|
10
|
+
static int nodeCount();
|
|
11
|
+
static int mountedWidth();
|
|
12
|
+
static bool hasMountedText(const char *text);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
} // namespace gea::embedded::ui
|