@geastack/engine 0.1.17 → 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 +43 -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_state.h +4 -0
- package/ui/tree_style.cpp +4 -0
- package/ui/virtual_keyboard.cpp +8 -1
package/touch_runtime.cpp
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
#include "ui/tree_internal.h"
|
|
10
10
|
#include "ui/virtual_keyboard.h"
|
|
11
11
|
#include "ui/debugger_picker.h"
|
|
12
|
+
#include "ui/input_retirement.h"
|
|
13
|
+
#include <stdexcept>
|
|
14
|
+
#include <exception>
|
|
12
15
|
|
|
13
16
|
#include <cstring>
|
|
14
17
|
|
|
@@ -89,6 +92,7 @@ public:
|
|
|
89
92
|
|
|
90
93
|
void resetGesture()
|
|
91
94
|
{
|
|
95
|
+
++primaryTicket_;primaryOwner_={};primaryQuarantined_=false;primaryEnding_=false;
|
|
92
96
|
wasActive_ = false;
|
|
93
97
|
lastX_ = 0;
|
|
94
98
|
lastY_ = 0;
|
|
@@ -97,7 +101,7 @@ public:
|
|
|
97
101
|
dragged_ = false;
|
|
98
102
|
activeDefaultPrevented_ = false;
|
|
99
103
|
activeTargetId_ = -1;
|
|
100
|
-
for (Secondary &s : secondary_)
|
|
104
|
+
for (Secondary &s : secondary_) {const auto next=s.ticket+1;s=Secondary{};s.ticket=next;}
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
// Returns true if this event may have changed on-screen state (a real
|
|
@@ -134,6 +138,13 @@ public:
|
|
|
134
138
|
return dispatchSecondary(event);
|
|
135
139
|
}
|
|
136
140
|
|
|
141
|
+
if (retireInvalidPrimary(!event.touching && event.touchPhase == TouchPhase::Up)) return false;
|
|
142
|
+
if(primaryQuarantined_){
|
|
143
|
+
if(event.touchPhase==TouchPhase::Move) gea::platform::touch::Touchscreen::consumeLatestMove(nullptr,nullptr);
|
|
144
|
+
if(!event.touching && event.touchPhase==TouchPhase::Up)primaryQuarantined_=false;
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
auto dispatchTicket=primaryTicket_;bool primaryBegan=false;
|
|
137
148
|
bool changed = false;
|
|
138
149
|
|
|
139
150
|
int tx = event.x;
|
|
@@ -151,19 +162,22 @@ public:
|
|
|
151
162
|
|
|
152
163
|
if (touching && !wasActive_) {
|
|
153
164
|
changed = true;
|
|
154
|
-
startX_ = tx;
|
|
155
|
-
startY_ = ty;
|
|
165
|
+
startX_ = lastX_ = tx;
|
|
166
|
+
startY_ = lastY_ = ty;
|
|
156
167
|
dragged_ = false;
|
|
157
168
|
activeDefaultPrevented_ = false;
|
|
158
169
|
gea::embedded::ui::Tree::instance().pointerDown(tx, ty);
|
|
159
170
|
const int targetId = gea::embedded::ui::Tree::instance().hitTestNode(tx, ty);
|
|
160
171
|
if (targetId >= 0) {
|
|
161
|
-
activeTargetId_ = targetId;
|
|
162
|
-
|
|
172
|
+
activeTargetId_ = targetId;primaryOwner_=gea::embedded::ui::NodeHandle(targetId);
|
|
173
|
+
wasActive_=true;primaryBegan=true;primaryEnding_=false;dispatchTicket=++primaryTicket_;
|
|
174
|
+
const bool prevented = dispatchPointer(PointerEventType::TouchStart, targetId, tx, ty, true);
|
|
175
|
+
if(dispatchTicket!=primaryTicket_ || retireInvalidPrimary(primaryEnding_))return true;
|
|
176
|
+
activeDefaultPrevented_ = prevented;
|
|
163
177
|
}
|
|
164
178
|
}
|
|
165
179
|
|
|
166
|
-
if (touching && wasActive_ && (tx != lastX_ || ty != lastY_)) {
|
|
180
|
+
if (touching && wasActive_ && !primaryBegan && (tx != lastX_ || ty != lastY_)) {
|
|
167
181
|
changed = true;
|
|
168
182
|
if (!dragged_) {
|
|
169
183
|
int dx = tx - startX_;
|
|
@@ -181,12 +195,13 @@ public:
|
|
|
181
195
|
bool defaultPrevented = activeDefaultPrevented_;
|
|
182
196
|
if (activeTargetId_ >= 0) {
|
|
183
197
|
defaultPrevented = dispatchPointer(PointerEventType::TouchMove, activeTargetId_, tx, ty, true) || defaultPrevented;
|
|
198
|
+
if(dispatchTicket!=primaryTicket_ || retireInvalidPrimary(primaryEnding_))return true;
|
|
184
199
|
}
|
|
185
200
|
if (!defaultPrevented) gea::embedded::ui::Tree::instance().pointerMove(tx, ty);
|
|
186
201
|
}
|
|
187
202
|
|
|
188
203
|
if (!touching && wasActive_) {
|
|
189
|
-
changed = true;
|
|
204
|
+
changed = true;primaryEnding_=true;
|
|
190
205
|
// Captured BEFORE any click handler runs: if a handler
|
|
191
206
|
// programmatically focuses an input (element.focus()), the
|
|
192
207
|
// focus-management default below must not clear it.
|
|
@@ -208,9 +223,11 @@ public:
|
|
|
208
223
|
gea::embedded::ui::VirtualKeyboard::instance().sync();
|
|
209
224
|
} else if (activeTargetId_ >= 0) {
|
|
210
225
|
dispatchPointer(PointerEventType::TouchEnd, activeTargetId_, lastX_, lastY_, false);
|
|
226
|
+
if(dispatchTicket!=primaryTicket_ || retireInvalidPrimary(primaryEnding_))return true;
|
|
211
227
|
}
|
|
212
228
|
if (!dragged_ && !activeDefaultPrevented_ && activeTargetId_ >= 0) {
|
|
213
229
|
if (!keyboardDismissTap) dispatchPointer(PointerEventType::Click, activeTargetId_, lastX_, lastY_, false);
|
|
230
|
+
if(dispatchTicket!=primaryTicket_ || retireInvalidPrimary(primaryEnding_))return true;
|
|
214
231
|
// Focus management — set the active input if the tap
|
|
215
232
|
// landed on one (or the closest input ancestor); clear
|
|
216
233
|
// focus on taps outside any input.
|
|
@@ -238,7 +255,8 @@ public:
|
|
|
238
255
|
gea::embedded::ui::VirtualKeyboard::instance().sync();
|
|
239
256
|
}
|
|
240
257
|
}
|
|
241
|
-
|
|
258
|
+
if(dispatchTicket!=primaryTicket_ || retireInvalidPrimary(primaryEnding_))return true;
|
|
259
|
+
activeTargetId_ = -1;primaryOwner_={};primaryEnding_=false;
|
|
242
260
|
activeDefaultPrevented_ = false;
|
|
243
261
|
}
|
|
244
262
|
|
|
@@ -251,6 +269,44 @@ public:
|
|
|
251
269
|
return changed;
|
|
252
270
|
}
|
|
253
271
|
|
|
272
|
+
// A raw allocation index is never a gesture lease. Destructive removal
|
|
273
|
+
// invalidates the captured birth owner, even if that index is reused.
|
|
274
|
+
bool retireInvalidPrimary(bool physicalUp)
|
|
275
|
+
{
|
|
276
|
+
if (!wasActive_ || activeTargetId_ < 0 || primaryOwner_.valid()) return false;
|
|
277
|
+
primaryQuarantined_ = !physicalUp;primaryEnding_=false;++primaryTicket_;
|
|
278
|
+
primaryOwner_={};activeTargetId_=-1;wasActive_=false;activeDefaultPrevented_=false;
|
|
279
|
+
gea::embedded::ui::cancelPrimaryPointerInput();
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
void retireSubtrees(const gea::embedded::ui::InputRetirementRoots &removed,const gea::embedded::ui::InputRetirementRoots &retained)
|
|
284
|
+
{
|
|
285
|
+
using namespace gea::embedded::ui;
|
|
286
|
+
struct Cancel {NodeHandle owner;int x,y,pointer;bool primary,emit;};
|
|
287
|
+
std::vector<Cancel> cancelled;cancelled.reserve(1+kMaxSecondaryPointers);
|
|
288
|
+
if(inputOwnerLeaving(primaryOwner_,removed,retained)){
|
|
289
|
+
cancelled.push_back({primaryOwner_,lastX_,lastY_,1,true,!primaryEnding_});
|
|
290
|
+
primaryQuarantined_=!primaryEnding_;primaryEnding_=false;++primaryTicket_;
|
|
291
|
+
primaryOwner_={};activeTargetId_=-1;wasActive_=false;activeDefaultPrevented_=false;
|
|
292
|
+
cancelPrimaryPointerInput();
|
|
293
|
+
}
|
|
294
|
+
for(int i=0;i<kMaxSecondaryPointers;++i){auto &slot=secondary_[i];
|
|
295
|
+
if(!inputOwnerLeaving(slot.owner,removed,retained))continue;
|
|
296
|
+
cancelled.push_back({slot.owner,slot.lastX,slot.lastY,i+2,false,!slot.ending});
|
|
297
|
+
slot.quarantined=!slot.ending;slot.ending=false;++slot.ticket;slot.active=false;slot.targetId=-1;slot.owner={};
|
|
298
|
+
}
|
|
299
|
+
// All admitted leases are closed before the first user cancellation callback.
|
|
300
|
+
std::exception_ptr failure;
|
|
301
|
+
for(const auto &entry:cancelled)if(entry.emit&&entry.owner.valid()) {
|
|
302
|
+
try {dispatchPointer(PointerEventType::PointerCancel,entry.owner.id(),entry.x,entry.y,false,entry.pointer,entry.primary);}
|
|
303
|
+
catch(...) {if(!failure)failure=std::current_exception();}
|
|
304
|
+
}
|
|
305
|
+
if(failure)std::rethrow_exception(failure);
|
|
306
|
+
if(inputOwnerLeaving(primaryOwner_,removed,retained))throw std::runtime_error("primary gesture revived during retirement");
|
|
307
|
+
for(const auto &slot:secondary_)if(inputOwnerLeaving(slot.owner,removed,retained))throw std::runtime_error("secondary gesture revived during retirement");
|
|
308
|
+
}
|
|
309
|
+
|
|
254
310
|
// Finger down now AND a down/move/up fired within the last windowMs. Used by
|
|
255
311
|
// the frame loop to render a drag back-to-back; a static hold posts no moves,
|
|
256
312
|
// so this lapses to false after the window and rendering quiesces.
|
|
@@ -285,65 +341,43 @@ private:
|
|
|
285
341
|
// owned by the primary pointer (pointerId 0).
|
|
286
342
|
bool dispatchSecondary(const Event &event)
|
|
287
343
|
{
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
dispatchPointer(PointerEventType::TouchMove, s.targetId, tx, ty, true, webPointerId, false);
|
|
326
|
-
}
|
|
327
|
-
s.lastX = tx;
|
|
328
|
-
s.lastY = ty;
|
|
329
|
-
}
|
|
330
|
-
return moved;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (!touching && s.active) {
|
|
334
|
-
if (s.targetId >= 0) {
|
|
335
|
-
dispatchPointer(PointerEventType::TouchEnd, s.targetId, s.lastX, s.lastY, false, webPointerId, false);
|
|
336
|
-
if (!s.dragged && !s.defaultPrevented) {
|
|
337
|
-
dispatchPointer(PointerEventType::Click, s.targetId, s.lastX, s.lastY, false, webPointerId, false);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
s.active = false;
|
|
341
|
-
s.targetId = -1;
|
|
342
|
-
s.dragged = false;
|
|
343
|
-
s.defaultPrevented = false;
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
return false;
|
|
344
|
+
const int index=event.pointerId-1;
|
|
345
|
+
if(index<0||index>=kMaxSecondaryPointers)return false;
|
|
346
|
+
auto &slot=secondary_[index];const int x=event.x,y=event.y;
|
|
347
|
+
const bool touching=event.touching||event.touchPhase==TouchPhase::Move;
|
|
348
|
+
const int pointer=event.pointerId+1;
|
|
349
|
+
auto retireInvalid=[&](){
|
|
350
|
+
if(!slot.active || slot.targetId<0 || slot.owner.valid())return false;
|
|
351
|
+
slot.quarantined=touching;slot.ending=false;++slot.ticket;slot.active=false;
|
|
352
|
+
slot.targetId=-1;slot.owner={};slot.dragged=false;slot.defaultPrevented=false;return true;
|
|
353
|
+
};
|
|
354
|
+
if(retireInvalid())return false;
|
|
355
|
+
if(slot.quarantined){if(!touching&&event.touchPhase==TouchPhase::Up)slot.quarantined=false;return false;}
|
|
356
|
+
if(touching&&!slot.active){
|
|
357
|
+
slot.active=true;slot.ending=false;const auto ticket=++slot.ticket;
|
|
358
|
+
slot.startX=slot.lastX=x;slot.startY=slot.lastY=y;slot.dragged=false;slot.defaultPrevented=false;
|
|
359
|
+
slot.targetId=gea::embedded::ui::Tree::instance().hitTestNode(x,y);
|
|
360
|
+
slot.owner=gea::embedded::ui::NodeHandle(slot.targetId);
|
|
361
|
+
if(slot.targetId>=0){const bool prevented=dispatchPointer(PointerEventType::TouchStart,slot.targetId,x,y,true,pointer,false);if(ticket!=slot.ticket || retireInvalid())return true;slot.defaultPrevented=prevented;}
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
const auto ticket=slot.ticket;
|
|
365
|
+
if(touching&&slot.active){
|
|
366
|
+
const bool moved=x!=slot.lastX||y!=slot.lastY;
|
|
367
|
+
if(moved){if(!slot.dragged){const int dx=x-slot.startX,dy=y-slot.startY;slot.dragged=dx>16||dx< -16||dy>16||dy< -16;}
|
|
368
|
+
if(slot.targetId>=0)dispatchPointer(PointerEventType::TouchMove,slot.targetId,x,y,true,pointer,false);
|
|
369
|
+
if(ticket!=slot.ticket || retireInvalid())return true;slot.lastX=x;slot.lastY=y;
|
|
370
|
+
}return moved;
|
|
371
|
+
}
|
|
372
|
+
if(!touching&&slot.active){
|
|
373
|
+
slot.ending=true;
|
|
374
|
+
if(slot.targetId>=0){dispatchPointer(PointerEventType::TouchEnd,slot.targetId,slot.lastX,slot.lastY,false,pointer,false);
|
|
375
|
+
if(ticket!=slot.ticket || retireInvalid())return true;
|
|
376
|
+
if(!slot.dragged&&!slot.defaultPrevented)dispatchPointer(PointerEventType::Click,slot.targetId,slot.lastX,slot.lastY,false,pointer,false);
|
|
377
|
+
if(ticket!=slot.ticket || retireInvalid())return true;
|
|
378
|
+
}
|
|
379
|
+
slot.active=false;slot.ending=false;slot.targetId=-1;slot.owner={};slot.dragged=false;slot.defaultPrevented=false;return true;
|
|
380
|
+
}return false;
|
|
347
381
|
}
|
|
348
382
|
|
|
349
383
|
// Immediate-mode (no UI tree) path: synthesize the pointer event from the raw
|
|
@@ -367,6 +401,8 @@ private:
|
|
|
367
401
|
}
|
|
368
402
|
PointerEvent pe{};
|
|
369
403
|
pe.type = type;
|
|
404
|
+
pe.button = type == PointerEventType::TouchMove ? -1 : 0;
|
|
405
|
+
pe.buttons = event.touching ? 1u : 0u;
|
|
370
406
|
pe.targetId = -1;
|
|
371
407
|
// Match the mounted-tree path and the public TypeScript surface:
|
|
372
408
|
// web-facing pointer ids start at 1, while internal touch slots start at 0.
|
|
@@ -395,6 +431,8 @@ private:
|
|
|
395
431
|
{
|
|
396
432
|
PointerEvent event{};
|
|
397
433
|
event.type = type;
|
|
434
|
+
event.button = (type == PointerEventType::TouchStart || type == PointerEventType::TouchEnd || type == PointerEventType::Click) ? 0 : -1;
|
|
435
|
+
event.buttons = activeTouch ? 1u : 0u;
|
|
398
436
|
// Skip entirely when no node listens for this type — don't build the
|
|
399
437
|
// event payload or walk the tree. Apps that bind only touch* never pay
|
|
400
438
|
// for the paired pointer* dispatch (and vice versa).
|
|
@@ -455,9 +493,15 @@ private:
|
|
|
455
493
|
int startY_ = 0;
|
|
456
494
|
bool dragged_ = false;
|
|
457
495
|
int activeTargetId_ = -1;
|
|
496
|
+
gea::embedded::ui::NodeHandle primaryOwner_;
|
|
497
|
+
unsigned int primaryTicket_=0;
|
|
498
|
+
bool primaryQuarantined_=false,primaryEnding_=false;
|
|
458
499
|
|
|
459
500
|
// Per-pointer state for non-primary (pointerId >= 1) simultaneous fingers.
|
|
460
501
|
struct Secondary {
|
|
502
|
+
gea::embedded::ui::NodeHandle owner;
|
|
503
|
+
unsigned int ticket=0;
|
|
504
|
+
bool quarantined=false,ending=false;
|
|
461
505
|
bool active = false;
|
|
462
506
|
bool dragged = false;
|
|
463
507
|
bool defaultPrevented = false;
|
|
@@ -473,6 +517,13 @@ private:
|
|
|
473
517
|
|
|
474
518
|
} // namespace
|
|
475
519
|
|
|
520
|
+
} // namespace gea::framework::events
|
|
521
|
+
namespace gea::embedded::ui {
|
|
522
|
+
void retireTouchInputForSubtrees(const InputRetirementRoots &removed,const InputRetirementRoots &retained)
|
|
523
|
+
{gea::framework::events::TouchEventDispatcher::instance().retireSubtrees(removed,retained);}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
namespace gea::framework::events {
|
|
476
527
|
// Touch controllers report PANEL-NATIVE coordinates; the UI hit-tests in
|
|
477
528
|
// LOGICAL (orientation-rotated) space. Inverse of the display's
|
|
478
529
|
// panelForSourcePixel mapping. Applied to QUEUED events AND to the raw
|
package/ui/canvas_element.h
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "node.h"
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <cmath>
|
|
7
|
+
#include <limits>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <optional>
|
|
10
|
+
#include <utility>
|
|
11
|
+
|
|
12
|
+
namespace gea::embedded::ui {
|
|
13
|
+
|
|
14
|
+
// The parent owns the token in its existing rare data. The token has no node
|
|
15
|
+
// backpointer; a retained list owns a birth-checked handle, never a raw slot.
|
|
16
|
+
struct ChildNodeListIdentity final {};
|
|
17
|
+
|
|
18
|
+
class ChildNodeListIterator;
|
|
19
|
+
|
|
20
|
+
class ChildNodeList {
|
|
21
|
+
public:
|
|
22
|
+
ChildNodeList() = default;
|
|
23
|
+
const void *identity() const { return identity_.get(); }
|
|
24
|
+
std::shared_ptr<const void> weakIdentityOwner() const { return identity_; }
|
|
25
|
+
|
|
26
|
+
std::uint32_t length() const
|
|
27
|
+
{
|
|
28
|
+
std::uint32_t count = 0;
|
|
29
|
+
for (auto child = parent_.firstChildHandle(); child; child = child.nextSiblingHandle()) ++count;
|
|
30
|
+
return count;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The caller must already have performed WebIDL unsigned-long conversion.
|
|
34
|
+
// The collection does not conflate that conversion with JS property keys.
|
|
35
|
+
NodeHandle itemAt(std::uint32_t index) const
|
|
36
|
+
{
|
|
37
|
+
if (index > static_cast<std::uint32_t>(std::numeric_limits<int>::max())) return NodeHandle();
|
|
38
|
+
return parent_.childAt(static_cast<int>(index));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// WebIDL unsigned long converts nonfinite values to 0, truncates toward
|
|
42
|
+
// zero and wraps modulo 2^32. Conversion is bounded before the integer cast.
|
|
43
|
+
NodeHandle item(double index) const
|
|
44
|
+
{
|
|
45
|
+
double integer = std::isfinite(index) ? std::trunc(index) : 0.0;
|
|
46
|
+
double wrapped = std::fmod(integer, 4294967296.0);
|
|
47
|
+
if (wrapped < 0) wrapped += 4294967296.0;
|
|
48
|
+
return itemAt(static_cast<std::uint32_t>(wrapped));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Internal absence is explicit. A host adapter must publish undefined for a
|
|
52
|
+
// missing indexed property, unlike item's null, without boxing a typed node.
|
|
53
|
+
std::optional<NodeHandle> indexed(std::uint32_t index) const
|
|
54
|
+
{
|
|
55
|
+
auto child = itemAt(index);
|
|
56
|
+
if (!child) return std::nullopt;
|
|
57
|
+
return child;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ChildNodeListIterator values() const;
|
|
61
|
+
|
|
62
|
+
private:
|
|
63
|
+
friend class NodeHandle;
|
|
64
|
+
ChildNodeList(NodeHandle parent, std::shared_ptr<const ChildNodeListIdentity> identity)
|
|
65
|
+
: parent_(std::move(parent)), identity_(std::move(identity)) {}
|
|
66
|
+
NodeHandle parent_;
|
|
67
|
+
std::shared_ptr<const ChildNodeListIdentity> identity_;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
class ChildNodeListIterator {
|
|
71
|
+
public:
|
|
72
|
+
explicit ChildNodeListIterator(ChildNodeList list) : list_(std::move(list)) {}
|
|
73
|
+
|
|
74
|
+
std::optional<NodeHandle> next()
|
|
75
|
+
{
|
|
76
|
+
if (done_) return std::nullopt;
|
|
77
|
+
auto value = list_.indexed(index_);
|
|
78
|
+
if (!value) {
|
|
79
|
+
done_ = true;
|
|
80
|
+
return std::nullopt;
|
|
81
|
+
}
|
|
82
|
+
++index_;
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private:
|
|
87
|
+
ChildNodeList list_;
|
|
88
|
+
std::uint32_t index_ = 0;
|
|
89
|
+
bool done_ = false;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
inline ChildNodeListIterator ChildNodeList::values() const { return ChildNodeListIterator(*this); }
|
|
93
|
+
|
|
94
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
#include "node.h"
|
|
4
|
+
#include "selector.h"
|
|
5
|
+
#include "tree_internal.h"
|
|
6
|
+
#include <string>
|
|
7
|
+
namespace gea::embedded::ui {
|
|
8
|
+
// User edit transaction, not an attribute observer. A recycled slot cannot
|
|
9
|
+
// inherit the allocation captured when editing began.
|
|
10
|
+
class ControlCommit {
|
|
11
|
+
NodeHandle owner_;std::string field_="value",initial_;bool edited_=false;
|
|
12
|
+
std::string value()const{const auto*p=owner_.getAttribute(field_);return p?p:"";}
|
|
13
|
+
public:
|
|
14
|
+
void begin(int node,const char*field="value"){owner_=NodeHandle(node);field_=field;initial_=owner_.valid()?value():"";edited_=false;}
|
|
15
|
+
bool owns(int node)const{return owner_.valid()&&owner_.id()==node;}
|
|
16
|
+
bool admitted(int node)const{return owns(node)&&!selector::disabled(Tree::instance(),node);}
|
|
17
|
+
void edited(int node){if(admitted(node))edited_=true;}
|
|
18
|
+
// Retire this commit before callbacks; never retain a Tree pointer across
|
|
19
|
+
// listener-driven teardown, replacement or nested focus transitions.
|
|
20
|
+
bool commit(){const int id=owner_.id();if(!admitted(id)){edited_=false;return false;}const auto current=value();const bool changed=edited_&¤t!=initial_;initial_=current;edited_=false;if(!changed)return false;
|
|
21
|
+
gea::framework::events::PointerEvent event{};event.type=gea::framework::events::PointerEventType::Change;event.targetId=id;event.cancelable=false;Tree::instance().dispatchEvent(event);return true;}
|
|
22
|
+
};
|
|
23
|
+
}
|
package/ui/css_features.h
CHANGED
package/ui/document.cpp
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "document.h"
|
|
3
|
+
#include "selector.h"
|
|
4
|
+
#include "tree_state.h"
|
|
3
5
|
|
|
4
6
|
#include "internal.h"
|
|
5
7
|
|
|
6
8
|
#include "display.h"
|
|
7
9
|
#include "display_underlay.h"
|
|
8
10
|
#include "tree_internal.h"
|
|
11
|
+
#include "tree_events.h"
|
|
9
12
|
|
|
10
13
|
#include <algorithm>
|
|
11
14
|
#include <cctype>
|
|
@@ -37,24 +40,6 @@ std::string lowerAscii(std::string value)
|
|
|
37
40
|
return value;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
bool matchesSelector(Tree &tree, int nodeId, const std::string &selector)
|
|
41
|
-
{
|
|
42
|
-
if (selector.empty()) return false;
|
|
43
|
-
if (selector == "body") {
|
|
44
|
-
const int mountedRoot = tree.mountedRoot();
|
|
45
|
-
return (mountedRoot >= 0 && nodeId == mountedRoot) || (mountedRoot < 0 && nodeId == 0);
|
|
46
|
-
}
|
|
47
|
-
if (selector[0] == '#') {
|
|
48
|
-
if (selector.size() <= 1) return false;
|
|
49
|
-
return std::strcmp(tree.getAttribute(nodeId, "id"), selector.c_str() + 1) == 0;
|
|
50
|
-
}
|
|
51
|
-
if (selector[0] == '.') {
|
|
52
|
-
if (selector.size() <= 1) return false;
|
|
53
|
-
return tree.hasClass(nodeId, selector.substr(1));
|
|
54
|
-
}
|
|
55
|
-
return lowerAscii(tree.tagName(nodeId)) == lowerAscii(selector);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
43
|
NodeHandle findElementById(Tree &tree, const char *id)
|
|
59
44
|
{
|
|
60
45
|
if (!id || id[0] == '\0') return NodeHandle();
|
|
@@ -135,7 +120,15 @@ NodeHandle Document::createAudio() const
|
|
|
135
120
|
|
|
136
121
|
NodeHandle Document::createDocumentFragment() const
|
|
137
122
|
{
|
|
138
|
-
return NodeHandle(Tree::instance().
|
|
123
|
+
return NodeHandle(Tree::instance().createDocumentFragment());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
NodeHandle Document::createComment(const char *text) const
|
|
127
|
+
{
|
|
128
|
+
auto &tree = Tree::instance();
|
|
129
|
+
const int id = tree.createComment();
|
|
130
|
+
if (id >= 0) tree.setText(id, text ? text : "");
|
|
131
|
+
return NodeHandle(id);
|
|
139
132
|
}
|
|
140
133
|
|
|
141
134
|
ViewElement Document::createVirtualList() const
|
|
@@ -143,6 +136,12 @@ ViewElement Document::createVirtualList() const
|
|
|
143
136
|
return ViewElement(Tree::instance().createVirtualList());
|
|
144
137
|
}
|
|
145
138
|
|
|
139
|
+
NodeHandle Document::activeElement() const {
|
|
140
|
+
const auto native=queryNativeFocus();
|
|
141
|
+
auto node=native.handled?native.node:NodeHandle(Tree::instance().activeInputId());
|
|
142
|
+
return node.valid()&&node.isConnected()?node:NodeHandle();
|
|
143
|
+
}
|
|
144
|
+
|
|
146
145
|
NodeHandle Document::createElement(const char *tag) const
|
|
147
146
|
{
|
|
148
147
|
std::string lowered = tag ? tag : "";
|
|
@@ -161,36 +160,28 @@ NodeHandle Document::createElement(const char *tag) const
|
|
|
161
160
|
|
|
162
161
|
NodeHandle Document::getElementById(const char *id) const
|
|
163
162
|
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
if (!id || !*id) return {};
|
|
164
|
+
auto &tree=Tree::instance();
|
|
165
|
+
if(tree.mountedRoot()<0) return std::strcmp(id,"app")==0?ensureAppRoot("app"):NodeHandle();
|
|
166
|
+
NodeHandle root(tree.mountedRoot());
|
|
167
|
+
if(root.valid()&&std::strcmp(root.getAttribute("id"),id)==0)return root;
|
|
168
|
+
for(auto node:root.querySelectorAll("*"))if(std::strcmp(node.getAttribute("id"),id)==0)return node;
|
|
169
|
+
return {};
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
-
NodeHandle Document::querySelector(const char *selector) const
|
|
171
|
+
NodeHandle Document::querySelector(const char *s) const
|
|
172
172
|
{
|
|
173
|
-
|
|
174
|
-
if (normalized == "body" || normalized == "#app") return ensureAppRoot("app");
|
|
175
|
-
const std::vector<NodeHandle> matches = querySelectorAll(normalized.c_str());
|
|
176
|
-
return matches.empty() ? NodeHandle() : matches.front();
|
|
173
|
+
auto all=querySelectorAll(s);return all.empty()?NodeHandle():all.front();
|
|
177
174
|
}
|
|
178
|
-
|
|
179
|
-
std::vector<NodeHandle> Document::querySelectorAll(const char *selector) const
|
|
175
|
+
std::vector<NodeHandle> Document::querySelectorAll(const char *s) const
|
|
180
176
|
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
Tree &tree = Tree::instance();
|
|
190
|
-
for (int nodeId = 0; nodeId < tree.nodeCount(); nodeId++) {
|
|
191
|
-
if (matchesSelector(tree, nodeId, normalized)) matches.push_back(NodeHandle(nodeId));
|
|
192
|
-
}
|
|
193
|
-
return matches;
|
|
177
|
+
auto q=selector::parse(s);q.requireValid();auto &tree=Tree::instance();
|
|
178
|
+
// Generated application bootstrap queries its single native root before
|
|
179
|
+
// any node is mounted. Ordinary queries never manufacture nodes.
|
|
180
|
+
const auto normalized=normalizeSelector(s);
|
|
181
|
+
if(tree.mountedRoot()<0&&(normalized=="body"||normalized=="#app"))ensureAppRoot("app");
|
|
182
|
+
NodeHandle root(tree.mountedRoot());std::vector<NodeHandle> out;if(!root.valid())return out;
|
|
183
|
+
if(q.matches(tree,root.id(),root.id()))out.push_back(root);
|
|
184
|
+
auto descendants=root.querySelectorAll(s);out.insert(out.end(),descendants.begin(),descendants.end());return out;
|
|
194
185
|
}
|
|
195
186
|
|
|
196
187
|
namespace {
|
|
@@ -200,29 +191,6 @@ namespace {
|
|
|
200
191
|
int g_preferred_mount_w = 0;
|
|
201
192
|
int g_preferred_mount_h = 0;
|
|
202
193
|
|
|
203
|
-
struct DocumentEventListener {
|
|
204
|
-
std::string type;
|
|
205
|
-
gea::framework::events::EventListener listener;
|
|
206
|
-
int boundRoot = -1;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
std::vector<DocumentEventListener> &documentEventListeners()
|
|
210
|
-
{
|
|
211
|
-
static std::vector<DocumentEventListener> listeners;
|
|
212
|
-
return listeners;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
void bindDocumentEventListeners()
|
|
216
|
-
{
|
|
217
|
-
const int root = Tree::instance().mountedRoot();
|
|
218
|
-
if (root < 0) return;
|
|
219
|
-
for (auto &entry : documentEventListeners()) {
|
|
220
|
-
if (entry.boundRoot == root) continue;
|
|
221
|
-
Tree::instance().setEventListener(root, entry.type.c_str(), entry.listener);
|
|
222
|
-
entry.boundRoot = root;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
194
|
// Map a pointer/touch event type to a slot index, aliasing pointer* onto its
|
|
227
195
|
// touch* sibling (the web binds onPointerDown/Move/Up; the device synthesizes
|
|
228
196
|
// touch*). Mirrors eventTypeIndex's pointer/touch grouping in tree_events.cpp.
|
|
@@ -232,9 +200,8 @@ int pointerTypeIndex(const char *type)
|
|
|
232
200
|
if (std::strcmp(type, "click") == 0) return 0;
|
|
233
201
|
if (std::strcmp(type, "touchstart") == 0 || std::strcmp(type, "pointerdown") == 0) return 1;
|
|
234
202
|
if (std::strcmp(type, "touchmove") == 0 || std::strcmp(type, "pointermove") == 0) return 2;
|
|
235
|
-
if (std::strcmp(type, "touchend") == 0 || std::strcmp(type, "pointerup") == 0
|
|
236
|
-
|
|
237
|
-
return 3;
|
|
203
|
+
if (std::strcmp(type, "touchend") == 0 || std::strcmp(type, "pointerup") == 0) return 3;
|
|
204
|
+
if (std::strcmp(type, "pointercancel") == 0 || std::strcmp(type, "touchcancel") == 0) return 4;
|
|
238
205
|
return -1;
|
|
239
206
|
}
|
|
240
207
|
} // namespace
|
|
@@ -243,21 +210,13 @@ bool dispatchDocumentPointer(gea::framework::events::PointerEvent &event)
|
|
|
243
210
|
{
|
|
244
211
|
const int wantIdx = pointerTypeIndex(event.typeName());
|
|
245
212
|
if (wantIdx < 0) return false;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
entry.listener(event);
|
|
251
|
-
fired = true;
|
|
252
|
-
if (event.propagationStopped) break;
|
|
253
|
-
}
|
|
213
|
+
bool fired = dispatchWindowEvent(event, true);
|
|
214
|
+
if (!event.propagationStopped) fired = dispatchDocumentEvent(event, true) || fired;
|
|
215
|
+
if (!event.propagationStopped) fired = dispatchDocumentEvent(event, false) || fired;
|
|
216
|
+
if (!event.propagationStopped && event.bubbles) fired = dispatchWindowEvent(event, false) || fired;
|
|
254
217
|
return fired;
|
|
255
218
|
}
|
|
256
219
|
|
|
257
|
-
void resetDocumentDelegatedEventListeners()
|
|
258
|
-
{
|
|
259
|
-
documentEventListeners().clear();
|
|
260
|
-
}
|
|
261
220
|
|
|
262
221
|
void Document::setPreferredMountSize(int width, int height)
|
|
263
222
|
{
|
|
@@ -324,7 +283,6 @@ void Document::mount(NodeHandle root, int width, int height) const
|
|
|
324
283
|
root.style().height(height);
|
|
325
284
|
}
|
|
326
285
|
Tree::instance().mount(root.id(), width, height);
|
|
327
|
-
bindDocumentEventListeners();
|
|
328
286
|
}
|
|
329
287
|
|
|
330
288
|
void Document::refresh(NodeHandle root, int width, int height) const
|
|
@@ -352,18 +310,7 @@ void Document::frame(int timestampMs) const
|
|
|
352
310
|
|
|
353
311
|
void Document::addEventListener(const char *type, gea::framework::events::EventListener listener) const
|
|
354
312
|
{
|
|
355
|
-
|
|
356
|
-
// `rotary` (and `keydown` bound on a non-input) is a genuine document-level
|
|
357
|
-
// event — it has no element target, so it is stored off-tree as a singleton
|
|
358
|
-
// and dispatched directly by the runtime, never bound to a node.
|
|
359
|
-
if (std::strcmp(type, "rotary") == 0 || std::strcmp(type, "keydown") == 0 || std::strcmp(type, "keyup") == 0) {
|
|
360
|
-
setDocumentEventListener(type, std::move(listener));
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
// Everything else delegates through the native body node (event bubbles up
|
|
364
|
-
// the tree to the mounted root, where this listener filters by target).
|
|
365
|
-
documentEventListeners().push_back(DocumentEventListener{type, std::move(listener), -1});
|
|
366
|
-
bindDocumentEventListeners();
|
|
313
|
+
setDocumentEventListener(type, std::move(listener));
|
|
367
314
|
}
|
|
368
315
|
|
|
369
316
|
} // namespace gea::embedded::ui
|