@geastack/engine 0.1.5 → 0.1.7
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 +86 -30
- package/css/animation.h +64 -0
- package/css/declarative.h +6 -0
- package/css/engine.h +25 -1
- package/image_store.cpp +136 -33
- package/package.json +2 -2
- package/ui/CSS_FEATURES.md +261 -0
- package/ui/absolute_leaf_refresh.cpp +42 -39
- package/ui/core.cpp +32 -1
- package/ui/css_atom.cpp +6 -0
- package/ui/css_atom.h +2 -0
- package/ui/css_features.h +282 -0
- package/ui/display_invalidation.cpp +29 -0
- package/ui/flex_balance.h +73 -0
- package/ui/image_node.cpp +33 -28
- package/ui/input.cpp +88 -38
- package/ui/input_render.cpp +17 -13
- package/ui/internal.h +51 -5
- package/ui/layout.cpp +2601 -441
- package/ui/layout_snapshot.cpp +49 -6
- package/ui/node_features.h +18 -0
- package/ui/node_lifecycle.cpp +204 -71
- package/ui/node_lifecycle.h +1 -0
- package/ui/node_model.h +930 -70
- package/ui/node_text.h +82 -0
- package/ui/render.cpp +793 -352
- package/ui/renderer_features.h +19 -0
- package/ui/root_scroll_refresh.cpp +46 -24
- package/ui/style.cpp +4155 -1073
- package/ui/style.h +143 -6
- package/ui/style_values.h +16 -0
- package/ui/text.cpp +401 -106
- package/ui/tree_events.cpp +138 -95
- package/ui/tree_events.h +28 -19
- package/ui/tree_inspection.h +15 -0
- package/ui/tree_internal.h +19 -0
- package/ui/tree_nodes.cpp +38 -4
- package/ui/tree_render.cpp +119 -40
- package/ui/tree_scroll_mirror.cpp +26 -0
- package/ui/tree_state.cpp +261 -114
- package/ui/tree_state.h +121 -16
- package/ui/tree_style.cpp +609 -82
- package/ui/view.cpp +720 -299
- package/ui/virtual_keyboard.cpp +10 -3
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
|
|
|
@@ -57,7 +58,7 @@ void applyAudioAttribute(Tree &tree, int node, const char *name, const char *val
|
|
|
57
58
|
// Index order mirrors NodeEventListeners' slots and is kept in sync by
|
|
58
59
|
// setEventListener (on the empty->set transition) and NodeEventListeners::clear()
|
|
59
60
|
// (which every removal path calls).
|
|
60
|
-
constexpr int kEventTypeCount =
|
|
61
|
+
constexpr int kEventTypeCount = 7;
|
|
61
62
|
int g_listenerTypeCounts[kEventTypeCount] = {};
|
|
62
63
|
EventListenerId g_nextEventListenerId = 1;
|
|
63
64
|
|
|
@@ -75,6 +76,7 @@ int eventTypeIndex(const char *type)
|
|
|
75
76
|
if (sameName(type, "touchend") || sameName(type, "pointerup")) return 3;
|
|
76
77
|
if (sameName(type, "input")) return 4;
|
|
77
78
|
if (sameName(type, "keydown")) return 5;
|
|
79
|
+
if (sameName(type, "scroll")) return 6;
|
|
78
80
|
return -1;
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -153,12 +155,13 @@ bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event)
|
|
|
153
155
|
// Cold/optional per-node state (currently event listeners) lives here instead
|
|
154
156
|
// of a dense [kMaxNodes] array. A node holds an int16 handle (Node::rare_data,
|
|
155
157
|
// -1 = none) into this pool; a block is allocated lazily the first time a node
|
|
156
|
-
// needs one and returned to a free list when the node is reset.
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
158
|
+
// needs one and returned to a free list when the node is reset. Owned records
|
|
159
|
+
// keep their addresses STABLE while the pointer table grows: the dispatcher
|
|
160
|
+
// retains NodeRareData* across re-entrant handlers. A direct pointer table also
|
|
161
|
+
// avoids deque's block arithmetic changing when record compaction crosses its
|
|
162
|
+
// block-size thresholds. The free list keeps allocations bounded and reused.
|
|
160
163
|
namespace {
|
|
161
|
-
std::
|
|
164
|
+
std::vector<std::unique_ptr<NodeRareData>> g_rareDataPool;
|
|
162
165
|
std::vector<int16_t> g_rareDataFreeList;
|
|
163
166
|
} // namespace
|
|
164
167
|
|
|
@@ -166,16 +169,16 @@ NodeRareData &ensureRareData(int node)
|
|
|
166
169
|
{
|
|
167
170
|
auto &state = treeState();
|
|
168
171
|
int16_t handle = state.nodes[node].rare_data;
|
|
169
|
-
if (handle >= 0) return g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
172
|
+
if (handle >= 0) return *g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
170
173
|
if (!g_rareDataFreeList.empty()) {
|
|
171
174
|
handle = g_rareDataFreeList.back();
|
|
172
175
|
g_rareDataFreeList.pop_back();
|
|
173
176
|
} else {
|
|
174
177
|
handle = static_cast<int16_t>(g_rareDataPool.size());
|
|
175
|
-
g_rareDataPool.emplace_back();
|
|
178
|
+
g_rareDataPool.emplace_back(std::make_unique<NodeRareData>());
|
|
176
179
|
}
|
|
177
180
|
state.nodes[node].rare_data = handle;
|
|
178
|
-
return g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
181
|
+
return *g_rareDataPool[static_cast<std::size_t>(handle)];
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
NodeRareData *rareDataFor(int node)
|
|
@@ -183,7 +186,7 @@ NodeRareData *rareDataFor(int node)
|
|
|
183
186
|
auto &state = treeState();
|
|
184
187
|
if (node < 0 || node >= kMaxNodes) return nullptr;
|
|
185
188
|
const int16_t handle = state.nodes[node].rare_data;
|
|
186
|
-
return handle >= 0 ?
|
|
189
|
+
return handle >= 0 ? g_rareDataPool[static_cast<std::size_t>(handle)].get() : nullptr;
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
void releaseRareData(int node)
|
|
@@ -192,52 +195,115 @@ void releaseRareData(int node)
|
|
|
192
195
|
if (node < 0 || node >= kMaxNodes) return;
|
|
193
196
|
const int16_t handle = state.nodes[node].rare_data;
|
|
194
197
|
if (handle < 0) return;
|
|
195
|
-
g_rareDataPool[static_cast<std::size_t>(handle)]
|
|
198
|
+
g_rareDataPool[static_cast<std::size_t>(handle)]->clear();
|
|
196
199
|
g_rareDataFreeList.push_back(handle);
|
|
197
200
|
state.nodes[node].rare_data = -1;
|
|
198
201
|
}
|
|
199
202
|
|
|
203
|
+
void NodeAttributeDeleter::operator()(NodeAttributeEntry *entry) const
|
|
204
|
+
{
|
|
205
|
+
entry->~NodeAttributeEntry();
|
|
206
|
+
::operator delete(entry);
|
|
207
|
+
}
|
|
208
|
+
NodeAttributePtr NodeAttributeEntry::create(const char *name, const char *value)
|
|
209
|
+
{
|
|
210
|
+
if (!value) value = "";
|
|
211
|
+
const auto nameBytes = std::min(std::strlen(name), std::size_t(kNodeAttributeNameMax - 1)) + 1;
|
|
212
|
+
const auto valueBytes = std::min(std::strlen(value), std::size_t(kNodeAttributeValueMax - 1)) + 1;
|
|
213
|
+
auto *entry = new (::operator new(sizeof(NodeAttributeEntry) + nameBytes + valueBytes)) NodeAttributeEntry;
|
|
214
|
+
entry->nameBytes = nameBytes;
|
|
215
|
+
entry->valueCapacity = valueBytes;
|
|
216
|
+
copyBounded(reinterpret_cast<char *>(entry + 1), nameBytes, name);
|
|
217
|
+
copyBounded(entry->value(), valueBytes, value);
|
|
218
|
+
return NodeAttributePtr(entry);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
NodeAttributeStore::NodeAttributeStore(const NodeAttributeStore &other)
|
|
222
|
+
: pressId(other.pressId), pressValue(other.pressValue), idAtom(other.idAtom), count(other.count)
|
|
223
|
+
{
|
|
224
|
+
auto *tail = &values;
|
|
225
|
+
for (auto *entry = other.values.get(); entry; entry = entry->next.get()) {
|
|
226
|
+
*tail = NodeAttributeEntry::create(entry->name(), entry->value());
|
|
227
|
+
tail = &(*tail)->next;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
NodeAttributeStore &NodeAttributeStore::operator=(const NodeAttributeStore &other)
|
|
232
|
+
{
|
|
233
|
+
if (this != &other) {
|
|
234
|
+
NodeAttributeStore copy(other);
|
|
235
|
+
*this = std::move(copy);
|
|
236
|
+
}
|
|
237
|
+
return *this;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
NodeAttributeStore::NodeAttributeStore(NodeAttributeStore &&other) noexcept
|
|
241
|
+
{
|
|
242
|
+
*this = std::move(other);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
NodeAttributeStore &NodeAttributeStore::operator=(NodeAttributeStore &&other) noexcept
|
|
246
|
+
{
|
|
247
|
+
if (this == &other) return *this;
|
|
248
|
+
values = std::move(other.values);
|
|
249
|
+
pressId = other.pressId;
|
|
250
|
+
pressValue = other.pressValue;
|
|
251
|
+
idAtom = other.idAtom;
|
|
252
|
+
count = other.count;
|
|
253
|
+
other.clear();
|
|
254
|
+
return *this;
|
|
255
|
+
}
|
|
256
|
+
|
|
200
257
|
void NodeAttributeStore::clear()
|
|
201
258
|
{
|
|
202
259
|
pressId = -1;
|
|
203
260
|
pressValue = -1;
|
|
204
261
|
idAtom = kInvalidCssAtom;
|
|
205
262
|
count = 0;
|
|
206
|
-
|
|
207
|
-
attr.name[0] = '\0';
|
|
208
|
-
attr.value[0] = '\0';
|
|
209
|
-
}
|
|
263
|
+
values.reset();
|
|
210
264
|
}
|
|
211
265
|
|
|
212
266
|
void NodeAttributeStore::set(const char *name, const char *value)
|
|
213
267
|
{
|
|
214
|
-
if (!name || name
|
|
268
|
+
if (!name || !*name) return;
|
|
269
|
+
if (!value) value = "";
|
|
215
270
|
const bool isId = sameName(name, "id");
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (
|
|
220
|
-
|
|
271
|
+
auto *tail = &values;
|
|
272
|
+
while (*tail) {
|
|
273
|
+
auto &entry = **tail;
|
|
274
|
+
if (sameName(entry.name(), name)) {
|
|
275
|
+
const auto bytes = std::min(std::strlen(value), std::size_t(kNodeAttributeValueMax - 1)) + 1;
|
|
276
|
+
if (bytes > entry.valueCapacity) {
|
|
277
|
+
// Allocate/copy first: value may point into the existing entry.
|
|
278
|
+
auto replacement = NodeAttributeEntry::create(name, value);
|
|
279
|
+
replacement->next = std::move(entry.next);
|
|
280
|
+
*tail = std::move(replacement);
|
|
281
|
+
} else {
|
|
282
|
+
std::memmove(entry.value(), value, bytes - 1);
|
|
283
|
+
entry.value()[bytes - 1] = 0;
|
|
284
|
+
}
|
|
285
|
+
if (isId) idAtom = internCssAtom((*tail)->value());
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
tail = &entry.next;
|
|
221
289
|
}
|
|
222
290
|
if (count >= kMaxNodeAttributes) return;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
count
|
|
291
|
+
auto entry = NodeAttributeEntry::create(name, value);
|
|
292
|
+
if (isId) idAtom = internCssAtom(entry->value());
|
|
293
|
+
*tail = std::move(entry);
|
|
294
|
+
++count;
|
|
227
295
|
}
|
|
228
296
|
|
|
229
297
|
bool NodeAttributeStore::remove(const char *name)
|
|
230
298
|
{
|
|
231
299
|
if (!name) return false;
|
|
232
|
-
for (
|
|
233
|
-
if (!sameName(
|
|
300
|
+
for (auto *link = &values; *link; link = &(*link)->next) {
|
|
301
|
+
if (!sameName((*link)->name(), name)) continue;
|
|
234
302
|
if (sameName(name, "id")) idAtom = kInvalidCssAtom;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
303
|
+
// Keep the removed owner alive while moving its next link.
|
|
304
|
+
auto removed = std::move(*link);
|
|
305
|
+
*link = std::move(removed->next);
|
|
238
306
|
count--;
|
|
239
|
-
values[count].name[0] = '\0';
|
|
240
|
-
values[count].value[0] = '\0';
|
|
241
307
|
return true;
|
|
242
308
|
}
|
|
243
309
|
return false;
|
|
@@ -246,8 +312,8 @@ bool NodeAttributeStore::remove(const char *name)
|
|
|
246
312
|
const char *NodeAttributeStore::get(const char *name) const
|
|
247
313
|
{
|
|
248
314
|
if (!name) return "";
|
|
249
|
-
for (
|
|
250
|
-
if (sameName(
|
|
315
|
+
for (auto *entry = values.get(); entry; entry = entry->next.get()) {
|
|
316
|
+
if (sameName(entry->name(), name)) return entry->value();
|
|
251
317
|
}
|
|
252
318
|
return "";
|
|
253
319
|
}
|
|
@@ -255,50 +321,18 @@ const char *NodeAttributeStore::get(const char *name) const
|
|
|
255
321
|
bool NodeAttributeStore::has(const char *name) const
|
|
256
322
|
{
|
|
257
323
|
if (!name) return false;
|
|
258
|
-
for (
|
|
259
|
-
if (sameName(
|
|
324
|
+
for (auto *entry = values.get(); entry; entry = entry->next.get()) {
|
|
325
|
+
if (sameName(entry->name(), name)) return true;
|
|
260
326
|
}
|
|
261
327
|
return false;
|
|
262
328
|
}
|
|
263
329
|
|
|
264
330
|
void NodeEventListeners::clear()
|
|
265
331
|
{
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (!list.empty() && g_listenerTypeCounts[index] > 0) g_listenerTypeCounts[index]--;
|
|
271
|
-
list.entries.clear();
|
|
272
|
-
};
|
|
273
|
-
release(click, 0);
|
|
274
|
-
release(touchstart, 1);
|
|
275
|
-
release(touchmove, 2);
|
|
276
|
-
release(touchend, 3);
|
|
277
|
-
release(input, 4);
|
|
278
|
-
release(keydown, 5);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
NodeEventListenerList *NodeEventListeners::listenersFor(const char *type)
|
|
282
|
-
{
|
|
283
|
-
if (sameName(type, "click")) return &click;
|
|
284
|
-
// Pointer events alias onto their touch* sibling slot — see eventTypeIndex.
|
|
285
|
-
if (sameName(type, "touchstart") || sameName(type, "pointerdown")) return &touchstart;
|
|
286
|
-
if (sameName(type, "touchmove") || sameName(type, "pointermove")) return &touchmove;
|
|
287
|
-
if (sameName(type, "touchend") || sameName(type, "pointerup")) return &touchend;
|
|
288
|
-
if (sameName(type, "input")) return &input;
|
|
289
|
-
if (sameName(type, "keydown")) return &keydown;
|
|
290
|
-
return nullptr;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const NodeEventListenerList *NodeEventListeners::listenersFor(const char *type) const
|
|
294
|
-
{
|
|
295
|
-
return const_cast<NodeEventListeners *>(this)->listenersFor(type);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
bool NodeEventListeners::hasAny() const
|
|
299
|
-
{
|
|
300
|
-
return !click.empty() || !touchstart.empty() || !touchmove.empty() ||
|
|
301
|
-
!touchend.empty() || !input.empty() || !keydown.empty();
|
|
332
|
+
for (int type = 0; type < 7; ++type)
|
|
333
|
+
if (hasType(type) && g_listenerTypeCounts[type] > 0) --g_listenerTypeCounts[type];
|
|
334
|
+
entries.clear();
|
|
335
|
+
types = 0;
|
|
302
336
|
}
|
|
303
337
|
|
|
304
338
|
EventListenerId Tree::setEventListener(int node, const char *type, gea::framework::events::EventListener listener)
|
|
@@ -309,16 +343,16 @@ EventListenerId Tree::setEventListener(int node, const char *type, gea::framewor
|
|
|
309
343
|
// Don't allocate a rare-data block for an unrecognized event type (the set
|
|
310
344
|
// listenerFor knows == the set eventTypeIndex tracks).
|
|
311
345
|
if (eventTypeIndex(type) < 0) return kInvalidEventListenerId;
|
|
312
|
-
auto
|
|
313
|
-
if (!list) return kInvalidEventListenerId;
|
|
314
|
-
// First listener for this (node, type): bump the type's live count so the
|
|
315
|
-
// dispatcher knows the type is worth walking the tree for.
|
|
346
|
+
auto &list = ensureRareData(node).listeners;
|
|
316
347
|
const int typeIndex = eventTypeIndex(type);
|
|
317
|
-
if (list
|
|
348
|
+
if (!list.hasType(typeIndex)) {
|
|
349
|
+
++g_listenerTypeCounts[typeIndex];
|
|
350
|
+
list.types |= 1u << typeIndex;
|
|
351
|
+
}
|
|
318
352
|
EventListenerId id = g_nextEventListenerId++;
|
|
319
353
|
if (id == kInvalidEventListenerId) id = g_nextEventListenerId++;
|
|
320
|
-
list
|
|
321
|
-
id,
|
|
354
|
+
list.entries.push_back(NodeEventListenerEntry{
|
|
355
|
+
id, static_cast<std::uint8_t>(typeIndex),
|
|
322
356
|
std::make_shared<gea::framework::events::EventListener>(std::move(listener))});
|
|
323
357
|
return id;
|
|
324
358
|
}
|
|
@@ -329,14 +363,17 @@ bool Tree::removeEventListener(int node, const char *type, EventListenerId liste
|
|
|
329
363
|
if (node < 0 || node >= state.nodeCount || listenerId == kInvalidEventListenerId) return false;
|
|
330
364
|
NodeRareData *rd = rareDataFor(node);
|
|
331
365
|
if (!rd) return false;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
366
|
+
auto &list = rd->listeners;
|
|
367
|
+
const int typeIndex = eventTypeIndex(type);
|
|
368
|
+
if (!list.hasType(typeIndex)) return false;
|
|
369
|
+
for (auto it = list.entries.begin(); it != list.entries.end(); ++it) {
|
|
370
|
+
if (it->id != listenerId || it->type != typeIndex) continue;
|
|
371
|
+
list.entries.erase(it);
|
|
372
|
+
const bool remains = std::any_of(list.entries.begin(), list.entries.end(),
|
|
373
|
+
[typeIndex](const auto &entry) { return entry.type == typeIndex; });
|
|
374
|
+
if (!remains) {
|
|
375
|
+
list.types &= ~(1u << typeIndex);
|
|
376
|
+
if (g_listenerTypeCounts[typeIndex] > 0) --g_listenerTypeCounts[typeIndex];
|
|
340
377
|
}
|
|
341
378
|
return true;
|
|
342
379
|
}
|
|
@@ -367,10 +404,11 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
|
367
404
|
event.target = gea::framework::events::EventTarget(event.targetId);
|
|
368
405
|
bool dispatched = false;
|
|
369
406
|
for (int node = event.targetId; node >= 0 && node < state.nodeCount; node = state.nodes[node].parent) {
|
|
407
|
+
if (!event.bubbles && node != event.targetId) break;
|
|
370
408
|
NodeRareData *rd = rareDataFor(node);
|
|
371
409
|
if (!rd) continue;
|
|
372
|
-
|
|
373
|
-
if (!
|
|
410
|
+
const int typeIndex = eventTypeIndex(event.typeName());
|
|
411
|
+
if (!rd->listeners.hasType(typeIndex)) continue;
|
|
374
412
|
|
|
375
413
|
event.currentTargetId = node;
|
|
376
414
|
event.currentTarget = gea::framework::events::EventTarget(node);
|
|
@@ -389,16 +427,16 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
|
389
427
|
// keeps the in-flight function alive after its entry is erased. Reacquire the
|
|
390
428
|
// list after every callback and advance by monotonic listener id; listeners
|
|
391
429
|
// added during this dispatch are above maxId and do not receive this event.
|
|
392
|
-
const EventListenerId maxId =
|
|
430
|
+
const EventListenerId maxId = rd->listeners.entries.back().id;
|
|
393
431
|
EventListenerId cursor = kInvalidEventListenerId;
|
|
394
432
|
for (;;) {
|
|
395
433
|
rd = rareDataFor(node);
|
|
396
434
|
if (!rd) break;
|
|
397
|
-
|
|
398
|
-
if (!list || list->empty()) break;
|
|
435
|
+
if (!rd->listeners.hasType(typeIndex)) break;
|
|
399
436
|
EventListenerId nextId = kInvalidEventListenerId;
|
|
400
437
|
std::shared_ptr<gea::framework::events::EventListener> callback;
|
|
401
|
-
for (const auto &entry :
|
|
438
|
+
for (const auto &entry : rd->listeners.entries) {
|
|
439
|
+
if (entry.type != typeIndex) continue;
|
|
402
440
|
if (entry.id <= cursor || entry.id > maxId) continue;
|
|
403
441
|
nextId = entry.id;
|
|
404
442
|
callback = entry.listener;
|
|
@@ -408,7 +446,6 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
|
|
|
408
446
|
cursor = nextId;
|
|
409
447
|
(*callback)(event);
|
|
410
448
|
dispatched = true;
|
|
411
|
-
if (event.propagationStopped || !event.bubbles) break;
|
|
412
449
|
}
|
|
413
450
|
if (event.propagationStopped || !event.bubbles) break;
|
|
414
451
|
}
|
|
@@ -495,7 +532,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
|
|
|
495
532
|
// (e.g. an EPUB cover applied via setAttribute) never paints.
|
|
496
533
|
markDisplayListDirty();
|
|
497
534
|
state.nodes[node].render.dirty = 1;
|
|
535
|
+
#if GEA_CSS_SCROLLING
|
|
498
536
|
state.nodes[node].render.non_scroll_dirty = 1;
|
|
537
|
+
#endif
|
|
499
538
|
}
|
|
500
539
|
}
|
|
501
540
|
if (state.nodes[node].type == NodeType::Image && sameName(name, "fit")) {
|
|
@@ -515,7 +554,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
|
|
|
515
554
|
state.displayListDirty = true;
|
|
516
555
|
state.nodes[node].render.dirty = 1;
|
|
517
556
|
state.nodes[node].render.layout_dirty = 1;
|
|
557
|
+
#if GEA_CSS_SCROLLING
|
|
518
558
|
state.nodes[node].render.non_scroll_dirty = 1;
|
|
559
|
+
#endif
|
|
519
560
|
}
|
|
520
561
|
}
|
|
521
562
|
|
|
@@ -538,7 +579,9 @@ void Tree::removeAttribute(int node, const char *name)
|
|
|
538
579
|
state.displayListDirty = true;
|
|
539
580
|
state.nodes[node].render.dirty = 1;
|
|
540
581
|
state.nodes[node].render.layout_dirty = 1;
|
|
582
|
+
#if GEA_CSS_SCROLLING
|
|
541
583
|
state.nodes[node].render.non_scroll_dirty = 1;
|
|
584
|
+
#endif
|
|
542
585
|
}
|
|
543
586
|
}
|
|
544
587
|
|
package/ui/tree_events.h
CHANGED
|
@@ -15,9 +15,20 @@ inline constexpr int kMaxNodeAttributes = 8;
|
|
|
15
15
|
inline constexpr int kNodeAttributeNameMax = 32;
|
|
16
16
|
inline constexpr int kNodeAttributeValueMax = 64;
|
|
17
17
|
|
|
18
|
-
struct
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
struct NodeAttributeEntry;
|
|
19
|
+
struct NodeAttributeDeleter {
|
|
20
|
+
void operator()(NodeAttributeEntry *entry) const;
|
|
21
|
+
};
|
|
22
|
+
using NodeAttributePtr = std::unique_ptr<NodeAttributeEntry, NodeAttributeDeleter>;
|
|
23
|
+
struct NodeAttributeEntry {
|
|
24
|
+
NodeAttributePtr next;
|
|
25
|
+
std::uint8_t nameBytes = 0, valueCapacity = 0;
|
|
26
|
+
// The allocation continues with nameBytes + valueCapacity bytes. Updating
|
|
27
|
+
// another attribute never moves this entry or invalidates its string.
|
|
28
|
+
const char *name() const { return reinterpret_cast<const char *>(this + 1); }
|
|
29
|
+
char *value() { return reinterpret_cast<char *>(this + 1) + nameBytes; }
|
|
30
|
+
const char *value() const { return reinterpret_cast<const char *>(this + 1) + nameBytes; }
|
|
31
|
+
static NodeAttributePtr create(const char *name, const char *value);
|
|
21
32
|
};
|
|
22
33
|
|
|
23
34
|
struct NodeAttributeStore {
|
|
@@ -25,7 +36,15 @@ struct NodeAttributeStore {
|
|
|
25
36
|
int16_t pressValue = -1;
|
|
26
37
|
CssAtomId idAtom = kInvalidCssAtom;
|
|
27
38
|
uint8_t count = 0;
|
|
28
|
-
|
|
39
|
+
// Allocate only attributes that exist. Entries stay at stable addresses
|
|
40
|
+
// as other attributes are added/removed; an empty store allocates nothing.
|
|
41
|
+
NodeAttributePtr values;
|
|
42
|
+
|
|
43
|
+
NodeAttributeStore() = default;
|
|
44
|
+
NodeAttributeStore(const NodeAttributeStore &other);
|
|
45
|
+
NodeAttributeStore &operator=(const NodeAttributeStore &other);
|
|
46
|
+
NodeAttributeStore(NodeAttributeStore &&other) noexcept;
|
|
47
|
+
NodeAttributeStore &operator=(NodeAttributeStore &&other) noexcept;
|
|
29
48
|
|
|
30
49
|
void clear();
|
|
31
50
|
void set(const char *name, const char *value);
|
|
@@ -39,27 +58,17 @@ using gea::framework::events::kInvalidEventListenerId;
|
|
|
39
58
|
|
|
40
59
|
struct NodeEventListenerEntry {
|
|
41
60
|
EventListenerId id = kInvalidEventListenerId;
|
|
61
|
+
std::uint8_t type = 0;
|
|
42
62
|
std::shared_ptr<gea::framework::events::EventListener> listener;
|
|
43
63
|
};
|
|
44
64
|
|
|
45
|
-
struct NodeEventListenerList {
|
|
46
|
-
std::vector<NodeEventListenerEntry> entries;
|
|
47
|
-
|
|
48
|
-
bool empty() const { return entries.empty(); }
|
|
49
|
-
};
|
|
50
|
-
|
|
51
65
|
struct NodeEventListeners {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
NodeEventListenerList touchmove;
|
|
55
|
-
NodeEventListenerList touchend;
|
|
56
|
-
NodeEventListenerList input;
|
|
57
|
-
NodeEventListenerList keydown;
|
|
66
|
+
std::vector<NodeEventListenerEntry> entries;
|
|
67
|
+
std::uint8_t types = 0;
|
|
58
68
|
|
|
59
69
|
void clear();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
bool hasAny() const;
|
|
70
|
+
bool hasType(int type) const { return type >= 0 && (types & (1u << type)); }
|
|
71
|
+
bool hasAny() const { return types != 0; }
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
// 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
|
package/ui/tree_internal.h
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#include "style.h"
|
|
8
8
|
|
|
9
9
|
#include <string>
|
|
10
|
+
#include <string_view>
|
|
10
11
|
|
|
11
12
|
namespace gea::embedded::ui {
|
|
12
13
|
|
|
@@ -105,6 +106,10 @@ public:
|
|
|
105
106
|
|
|
106
107
|
int hitTest(int x, int y);
|
|
107
108
|
int hitTestNode(int x, int y);
|
|
109
|
+
// Hover-capable pointing devices only; touch dragging remains pointerMove.
|
|
110
|
+
// Negative coordinates clear hover when the pointer leaves the surface.
|
|
111
|
+
int pointerHover(int x, int y);
|
|
112
|
+
bool isHovered(int node) const;
|
|
108
113
|
void pointerDown(int x, int y);
|
|
109
114
|
int pointerMove(int x, int y);
|
|
110
115
|
int pointerUp();
|
|
@@ -176,6 +181,20 @@ bool dispatchDocumentPointer(gea::framework::events::PointerEvent &event);
|
|
|
176
181
|
int16_t internTag(const char *tag);
|
|
177
182
|
const char *tagFromId(int16_t id);
|
|
178
183
|
|
|
184
|
+
inline bool isDocumentCanvasRoot(const Node &node)
|
|
185
|
+
{
|
|
186
|
+
return node.parent < 0 && std::string_view(tagFromId(node.tag_id)) == "html";
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
// HTML importers mark DOM text separately from Gea's styleable TextElement.
|
|
191
|
+
// The former inherits text properties but is never an element selector target.
|
|
192
|
+
inline bool isAnonymousTextNode(const Node &node)
|
|
193
|
+
{
|
|
194
|
+
if (node.type != NodeType::Text) return false;
|
|
195
|
+
return std::string_view(tagFromId(node.tag_id)) == "#text";
|
|
196
|
+
}
|
|
197
|
+
|
|
179
198
|
// Blink-style rare-data pool accessors. A node's cold/optional state lives in a
|
|
180
199
|
// pooled NodeRareData block referenced by Node::rare_data (-1 = none).
|
|
181
200
|
struct NodeRareData;
|