@geastack/engine 0.1.33 → 0.1.34
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 +197 -18
- package/image_store.cpp +9 -1
- package/package.json +2 -2
- package/rasterized_font.cpp +45 -6
- package/ui/canvas_element.cpp +5 -0
- package/ui/canvas_element.h +1 -0
- package/ui/document.cpp +114 -0
- package/ui/document.h +23 -0
- package/ui/internal.h +1 -1
- package/ui/node.cpp +239 -0
- package/ui/node.h +49 -0
- package/ui/render.cpp +32 -2
- package/ui/style.cpp +87 -2
- package/ui/style.h +11 -0
- package/ui/tree_internal.h +3 -0
- package/ui/tree_nodes.cpp +3 -0
- package/ui/tree_render.cpp +41 -0
- package/ui/tree_state.h +6 -0
- package/ui/view.cpp +36 -2
package/ui/document.h
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#include "tree_events.h"
|
|
7
7
|
#include <type_traits>
|
|
8
8
|
#include <cstdlib>
|
|
9
|
+
#include <cstdint>
|
|
9
10
|
#include "image.h"
|
|
10
11
|
#include "canvas_element.h"
|
|
11
12
|
#include "camera_element.h"
|
|
@@ -15,18 +16,35 @@
|
|
|
15
16
|
|
|
16
17
|
#include <string>
|
|
17
18
|
#include <vector>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <mutex>
|
|
18
21
|
|
|
19
22
|
namespace gea { template <typename Signature> struct CallableObject; }
|
|
20
23
|
|
|
21
24
|
namespace gea::embedded::ui {
|
|
22
25
|
|
|
26
|
+
struct DocumentSelection {
|
|
27
|
+
NodeHandle anchorNode;
|
|
28
|
+
NodeHandle focusNode;
|
|
29
|
+
std::uint32_t anchorOffset = 0;
|
|
30
|
+
std::uint32_t focusOffset = 0;
|
|
31
|
+
};
|
|
32
|
+
|
|
23
33
|
class Document {
|
|
24
34
|
public:
|
|
25
35
|
static Document &instance();
|
|
26
36
|
|
|
27
37
|
ViewElement body() const;
|
|
38
|
+
NodeHandle documentElement() const;
|
|
39
|
+
NodeHandle head() const;
|
|
40
|
+
int viewportScrollX() const;
|
|
41
|
+
int viewportScrollY() const;
|
|
42
|
+
void scrollViewportTo(double x, double y) const;
|
|
28
43
|
// No guessed body fallback: null handle when no actual connected focus.
|
|
29
44
|
NodeHandle activeElement() const;
|
|
45
|
+
DocumentSelection selection() const;
|
|
46
|
+
void selectAllChildren(const NodeHandle &node);
|
|
47
|
+
void clearSelection();
|
|
30
48
|
ViewElement createView() const;
|
|
31
49
|
ViewElement createButton() const;
|
|
32
50
|
TextElement createText(const char *text = "") const;
|
|
@@ -55,6 +73,7 @@ public:
|
|
|
55
73
|
// TYPED handle — boxing happens only if the caller stores it dynamically.
|
|
56
74
|
NodeHandle createElement(const char *tag) const;
|
|
57
75
|
NodeHandle createElement(const std::string &tag) const { return createElement(tag.c_str()); }
|
|
76
|
+
NodeHandle createElementNS(const std::string &namespaceUri, const std::string &qualifiedName) const;
|
|
58
77
|
NodeHandle getElementById(const char *id) const;
|
|
59
78
|
// geatsc's `nativeDocumentMethods` binding for `document.getElementById(...)`
|
|
60
79
|
// passes its argument through untouched (see `createElement`'s identical
|
|
@@ -83,6 +102,7 @@ public:
|
|
|
83
102
|
static bool directCanvasContextUsed();
|
|
84
103
|
|
|
85
104
|
void clear() const;
|
|
105
|
+
std::shared_ptr<void> propertyStorage(const std::shared_ptr<void> &initial = {}) const;
|
|
86
106
|
void mount(NodeHandle root, int width, int height) const;
|
|
87
107
|
void refresh(NodeHandle root, int width, int height) const;
|
|
88
108
|
void refreshMountedIfDirty() const;
|
|
@@ -139,6 +159,9 @@ public:
|
|
|
139
159
|
|
|
140
160
|
private:
|
|
141
161
|
Document() = default;
|
|
162
|
+
mutable std::mutex propertyStorageMutex_;
|
|
163
|
+
mutable std::shared_ptr<void> propertyStorage_;
|
|
164
|
+
mutable DocumentSelection selection_;
|
|
142
165
|
};
|
|
143
166
|
|
|
144
167
|
// Bracket the initial app mount. Between these calls, per-node class-style
|
package/ui/internal.h
CHANGED
|
@@ -324,7 +324,7 @@ void rootScrollImageHoldTick();
|
|
|
324
324
|
// allowSkipStatic: caller guarantees this frame will use the direct
|
|
325
325
|
// (backdrop-blit) replay path, so recordNode may skip re-recording fully-static
|
|
326
326
|
// subtrees when the backdrop is baked. Must be false on the full-replay path.
|
|
327
|
-
void recordNode(int id, uint8_t parentAlpha, bool allowSkipStatic = false);
|
|
327
|
+
void recordNode(int id, uint8_t parentAlpha, bool allowSkipStatic = false, bool paintDocumentCanvas = true);
|
|
328
328
|
void recordNodeWithExpandedClip(int id, uint8_t parentAlpha, int clipNode,
|
|
329
329
|
int clipX0, int clipY0, int clipX1, int clipY1);
|
|
330
330
|
void replay();
|
package/ui/node.cpp
CHANGED
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
#include "node.h"
|
|
4
4
|
#include "child_node_list.h"
|
|
5
5
|
#include "tree_state.h"
|
|
6
|
+
#include "internal.h"
|
|
6
7
|
|
|
7
8
|
#include "host/audio.h"
|
|
8
9
|
#include "tree_internal.h"
|
|
9
10
|
#include "input_retirement.h"
|
|
10
11
|
|
|
12
|
+
#include <algorithm>
|
|
11
13
|
#include <cstring>
|
|
14
|
+
#include <functional>
|
|
12
15
|
#include <utility>
|
|
13
16
|
#include <stdexcept>
|
|
14
17
|
|
|
@@ -86,6 +89,43 @@ NodeHandle NodeHandle::nextSiblingHandle() const
|
|
|
86
89
|
return NodeHandle(Tree::instance().node(id()).next_sibling);
|
|
87
90
|
}
|
|
88
91
|
|
|
92
|
+
NodeHandle NodeHandle::previousSiblingHandle() const
|
|
93
|
+
{
|
|
94
|
+
if (!valid()) return NodeHandle();
|
|
95
|
+
return NodeHandle(Tree::instance().node(id()).prev_sibling);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
int NodeHandle::compareDocumentPosition(const NodeHandle &other) const
|
|
99
|
+
{
|
|
100
|
+
using namespace DocumentPosition;
|
|
101
|
+
if (identity() == other.identity()) return 0;
|
|
102
|
+
const auto disconnectedPosition = [&]() {
|
|
103
|
+
const bool otherPrecedes = std::less<const void *>{}(other.identity(), identity());
|
|
104
|
+
return disconnected | implementationSpecific | (otherPrecedes ? preceding : following);
|
|
105
|
+
};
|
|
106
|
+
if (!valid() || !other.valid()) return disconnectedPosition();
|
|
107
|
+
|
|
108
|
+
const auto &tree = Tree::instance();
|
|
109
|
+
const auto ancestors = [&](int current) {
|
|
110
|
+
std::vector<int> path;
|
|
111
|
+
for (; current >= 0; current = tree.node(current).parent) path.push_back(current);
|
|
112
|
+
return path;
|
|
113
|
+
};
|
|
114
|
+
auto selfPath = ancestors(id());
|
|
115
|
+
auto otherPath = ancestors(other.id());
|
|
116
|
+
if (selfPath.back() != otherPath.back()) return disconnectedPosition();
|
|
117
|
+
while (!selfPath.empty() && !otherPath.empty() && selfPath.back() == otherPath.back()) {
|
|
118
|
+
selfPath.pop_back();
|
|
119
|
+
otherPath.pop_back();
|
|
120
|
+
}
|
|
121
|
+
if (selfPath.empty()) return following | containedBy;
|
|
122
|
+
if (otherPath.empty()) return preceding | contains;
|
|
123
|
+
for (int sibling = tree.node(selfPath.back()).next_sibling; sibling >= 0; sibling = tree.node(sibling).next_sibling) {
|
|
124
|
+
if (sibling == otherPath.back()) return following;
|
|
125
|
+
}
|
|
126
|
+
return preceding;
|
|
127
|
+
}
|
|
128
|
+
|
|
89
129
|
ChildNodeList NodeHandle::childNodesHandle() const
|
|
90
130
|
{
|
|
91
131
|
if (!valid()) return ChildNodeList();
|
|
@@ -279,6 +319,205 @@ const char *NodeHandle::tagName() const
|
|
|
279
319
|
return Tree::instance().tagName(id());
|
|
280
320
|
}
|
|
281
321
|
|
|
322
|
+
NativeComputedStyle getComputedStyle(NodeHandle node, std::string_view pseudoElement)
|
|
323
|
+
{
|
|
324
|
+
if (static_cast<int>(node.nodeType) != 1) throw std::invalid_argument("getComputedStyle requires a live element");
|
|
325
|
+
using Target = NativeComputedStyle::Target;
|
|
326
|
+
if (!pseudoElement.starts_with(':')) return NativeComputedStyle(node, Target::element);
|
|
327
|
+
pseudoElement.remove_prefix(1);
|
|
328
|
+
if (pseudoElement.starts_with(':')) pseudoElement.remove_prefix(1);
|
|
329
|
+
std::string name(pseudoElement);
|
|
330
|
+
for (char &ch : name)
|
|
331
|
+
if (ch >= 'A' && ch <= 'Z') ch = static_cast<char>(ch + ('a' - 'A'));
|
|
332
|
+
if (name == "before") return NativeComputedStyle(node, Target::before);
|
|
333
|
+
if (name == "after") return NativeComputedStyle(node, Target::after);
|
|
334
|
+
return NativeComputedStyle(node, Target::absent);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
NodeHandle NativeComputedStyle::selectedNode() const
|
|
338
|
+
{
|
|
339
|
+
if (!owner_.valid()) return {};
|
|
340
|
+
if (target_ == Target::element) return owner_;
|
|
341
|
+
if (target_ == Target::absent) return {};
|
|
342
|
+
return NodeHandle(Tree::instance().generatedPseudoChild(owner_.id(), target_ == Target::before));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
std::string NativeComputedStyle::display() const
|
|
346
|
+
{
|
|
347
|
+
const auto selected = selectedNode();
|
|
348
|
+
if (!selected.valid()) return {};
|
|
349
|
+
const auto &node = Tree::instance().node(selected.id());
|
|
350
|
+
switch (node.computedStyle().display) {
|
|
351
|
+
case kDisplayNone: return "none";
|
|
352
|
+
case kDisplayFlex: return "flex";
|
|
353
|
+
case kDisplayGrid: return "grid";
|
|
354
|
+
default: return LayoutEngine::isCssInlineLevelBox(node) ? "inline" : "block";
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
std::string NativeComputedStyle::position() const
|
|
359
|
+
{
|
|
360
|
+
const auto selected = selectedNode();
|
|
361
|
+
if (!selected.valid()) return {};
|
|
362
|
+
const auto &style = Tree::instance().node(selected.id()).computedStyle();
|
|
363
|
+
switch (style.position) {
|
|
364
|
+
case 1: return "absolute";
|
|
365
|
+
case 2: return "relative";
|
|
366
|
+
case kPositionFixed: return "fixed";
|
|
367
|
+
default: return "static";
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
namespace {
|
|
372
|
+
std::string computedPercentText(int permille)
|
|
373
|
+
{
|
|
374
|
+
std::string text = std::to_string(permille / 10);
|
|
375
|
+
if (permille % 10 != 0) text += '.' + std::to_string(permille % 10);
|
|
376
|
+
return text + '%';
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const char *computedOverflowText(int value)
|
|
380
|
+
{
|
|
381
|
+
switch (value) {
|
|
382
|
+
case 1: return "hidden";
|
|
383
|
+
case 2: return "auto"; // The native engine uses one scrolling mode.
|
|
384
|
+
case 3: return "clip";
|
|
385
|
+
default: return "visible";
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
std::string NativeComputedStyle::overflow() const
|
|
391
|
+
{
|
|
392
|
+
const auto selected = selectedNode();
|
|
393
|
+
if (!selected.valid()) return {};
|
|
394
|
+
const auto &style = Tree::instance().node(selected.id()).computedStyle();
|
|
395
|
+
const int x = overflowX(style), y = overflowY(style);
|
|
396
|
+
std::string text = computedOverflowText(x);
|
|
397
|
+
if (x != y) text += std::string(" ") + computedOverflowText(y);
|
|
398
|
+
return text;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
std::string NativeComputedStyle::borderRadius() const
|
|
402
|
+
{
|
|
403
|
+
const auto selected = selectedNode();
|
|
404
|
+
if (!selected.valid()) return {};
|
|
405
|
+
const auto &style = Tree::instance().node(selected.id()).computedStyle();
|
|
406
|
+
std::string cornerText[4];
|
|
407
|
+
for (int corner = 0; corner < 4; ++corner) {
|
|
408
|
+
const auto index = GEA_CSS_RADIUS_INDEX(corner);
|
|
409
|
+
const int percent = style.border_radius_percent[index];
|
|
410
|
+
cornerText[corner] = percent != kUnset ? computedPercentText(percent) : std::to_string(style.border_radius[index]) + "px";
|
|
411
|
+
}
|
|
412
|
+
int count = 4;
|
|
413
|
+
if (cornerText[3] == cornerText[1]) {
|
|
414
|
+
--count;
|
|
415
|
+
if (cornerText[2] == cornerText[0]) {
|
|
416
|
+
--count;
|
|
417
|
+
if (cornerText[1] == cornerText[0]) --count;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
std::string result = std::move(cornerText[0]);
|
|
421
|
+
for (int corner = 1; corner < count; ++corner) result += ' ' + cornerText[corner];
|
|
422
|
+
return result;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
std::string NativeComputedStyle::filter() const
|
|
426
|
+
{
|
|
427
|
+
const auto selected = selectedNode();
|
|
428
|
+
if (!selected.valid()) return {};
|
|
429
|
+
const auto &style = rstyle(Tree::instance().node(selected.id()).computedStyle());
|
|
430
|
+
return style.filter_present ? "blur(" + std::to_string(style.filter_blur_radius) + "px)" : "none";
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
std::string NativeComputedStyle::resolvedDimension(bool horizontal) const
|
|
434
|
+
{
|
|
435
|
+
const auto selected = selectedNode();
|
|
436
|
+
if (!selected.valid()) return {};
|
|
437
|
+
auto &tree = Tree::instance();
|
|
438
|
+
const int id = selected.id();
|
|
439
|
+
const auto &node = tree.node(id);
|
|
440
|
+
const auto &style = node.computedStyle();
|
|
441
|
+
const bool inlineBox = LayoutEngine::isCssInlineLevelBox(node) && node.type != NodeType::Image;
|
|
442
|
+
if (selected.isConnected() && style.display != kDisplayNone && !inlineBox) {
|
|
443
|
+
tree.flushLayoutFor(id);
|
|
444
|
+
if (!selected.valid()) return {};
|
|
445
|
+
const auto &laidOut = tree.node(id);
|
|
446
|
+
const auto &laidOutStyle = laidOut.computedStyle();
|
|
447
|
+
const int borderBox = horizontal ? laidOut.layout.width : laidOut.layout.height;
|
|
448
|
+
const int insets = laidOutStyle.box_sizing == 0 ? boxInsets(laidOutStyle, horizontal) : 0;
|
|
449
|
+
return std::to_string(std::max(0, borderBox - insets)) + "px";
|
|
450
|
+
}
|
|
451
|
+
const auto expression = horizontal ? style.width_expression : style.height_expression;
|
|
452
|
+
if (expression >= 0) return {}; // This view cannot serialize unresolved CSS expressions.
|
|
453
|
+
const int percent = horizontal ? style.width_percent : style.height_percent;
|
|
454
|
+
if (percent != kUnset) return computedPercentText(percent);
|
|
455
|
+
const int pixels = horizontal ? style.width : style.height;
|
|
456
|
+
return pixels == kUnset ? "auto" : std::to_string(pixels) + "px";
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
std::string NativeComputedStyle::width() const { return resolvedDimension(true); }
|
|
460
|
+
std::string NativeComputedStyle::height() const { return resolvedDimension(false); }
|
|
461
|
+
|
|
462
|
+
std::string NativeComputedStyle::paddingTop() const
|
|
463
|
+
{
|
|
464
|
+
const auto selected = selectedNode();
|
|
465
|
+
return selected.valid() ? std::to_string(Tree::instance().node(selected.id()).computedStyle().padding[0]) + "px" : std::string{};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
std::string NativeComputedStyle::paddingBottom() const
|
|
469
|
+
{
|
|
470
|
+
const auto selected = selectedNode();
|
|
471
|
+
return selected.valid() ? std::to_string(Tree::instance().node(selected.id()).computedStyle().padding[2]) + "px" : std::string{};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
std::string NodeHandle::domNodeName() const
|
|
475
|
+
{
|
|
476
|
+
switch (static_cast<int>(nodeType)) {
|
|
477
|
+
case 3: return "#text";
|
|
478
|
+
case 8: return "#comment";
|
|
479
|
+
case 11: return "#document-fragment";
|
|
480
|
+
case 1: break;
|
|
481
|
+
default: return {};
|
|
482
|
+
}
|
|
483
|
+
std::string qualified;
|
|
484
|
+
if (const auto *prefix = namespacePrefix()) qualified = *prefix + ':';
|
|
485
|
+
qualified += tagName();
|
|
486
|
+
const auto *uri = namespaceURI();
|
|
487
|
+
if (uri && *uri == "http://www.w3.org/1999/xhtml") {
|
|
488
|
+
for (auto &ch : qualified)
|
|
489
|
+
if (ch >= 'a' && ch <= 'z') ch = static_cast<char>(ch - ('a' - 'A'));
|
|
490
|
+
}
|
|
491
|
+
return qualified;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const std::string *NodeHandle::characterData() const
|
|
495
|
+
{
|
|
496
|
+
const int type = static_cast<int>(nodeType);
|
|
497
|
+
if (type != 3 && type != 8) return nullptr;
|
|
498
|
+
return &Tree::instance().node(id()).text.str();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
void NodeHandle::setCharacterData(const char *text) const
|
|
502
|
+
{
|
|
503
|
+
if (characterData()) setText(text ? text : "");
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const std::string *NodeHandle::namespaceURI() const
|
|
507
|
+
{
|
|
508
|
+
if (static_cast<int>(nodeType) != 1) return nullptr;
|
|
509
|
+
const auto *metadata = rareDataFor(id());
|
|
510
|
+
static const std::string html = "http://www.w3.org/1999/xhtml";
|
|
511
|
+
if (!metadata || !metadata->hasExplicitNamespace) return &html;
|
|
512
|
+
return metadata->namespaceUri == kInvalidCssAtom ? nullptr : &cssAtomString(metadata->namespaceUri);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const std::string *NodeHandle::namespacePrefix() const
|
|
516
|
+
{
|
|
517
|
+
const auto *metadata = valid() ? rareDataFor(id()) : nullptr;
|
|
518
|
+
return metadata && metadata->namespacePrefix != kInvalidCssAtom ? &cssAtomString(metadata->namespacePrefix) : nullptr;
|
|
519
|
+
}
|
|
520
|
+
|
|
282
521
|
// DOM Node.nodeType for a handle: ELEMENT_NODE (1) for any element-like tree
|
|
283
522
|
// node, TEXT_NODE (3), COMMENT_NODE (8), or DOCUMENT_FRAGMENT_NODE (11).
|
|
284
523
|
NodeHandle::NodeTypeProperty::operator int() const
|
package/ui/node.h
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#pragma once
|
|
3
3
|
|
|
4
|
+
#include "host/dom_rect.h"
|
|
4
5
|
#include "events.h"
|
|
5
6
|
#include "style.h"
|
|
6
7
|
|
|
7
8
|
#include <cstddef>
|
|
8
9
|
#include <cstdint>
|
|
9
10
|
#include <string>
|
|
11
|
+
#include <string_view>
|
|
10
12
|
#include <utility>
|
|
11
13
|
#include <vector>
|
|
12
14
|
|
|
@@ -14,6 +16,15 @@ namespace gea::embedded::ui {
|
|
|
14
16
|
|
|
15
17
|
class ChildNodeList;
|
|
16
18
|
|
|
19
|
+
namespace DocumentPosition {
|
|
20
|
+
inline constexpr int disconnected = 1;
|
|
21
|
+
inline constexpr int preceding = 2;
|
|
22
|
+
inline constexpr int following = 4;
|
|
23
|
+
inline constexpr int contains = 8;
|
|
24
|
+
inline constexpr int containedBy = 16;
|
|
25
|
+
inline constexpr int implementationSpecific = 32;
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
class ClassList {
|
|
18
29
|
public:
|
|
19
30
|
explicit ClassList(int nodeId = -1)
|
|
@@ -147,6 +158,10 @@ public:
|
|
|
147
158
|
}
|
|
148
159
|
const void *identity() const { return identity_.get(); }
|
|
149
160
|
std::shared_ptr<const void> weakIdentityOwner() const { return identity_; }
|
|
161
|
+
std::shared_ptr<void> propertyStorage(const std::shared_ptr<void> &initial = {}) const
|
|
162
|
+
{
|
|
163
|
+
return gea::framework::identity::nodePropertyStorage(id_, identity_, initial);
|
|
164
|
+
}
|
|
150
165
|
// Event targets and DOM elements are two views of the same tree identity.
|
|
151
166
|
// Pointer/touch event targets declared as Element therefore project to a
|
|
152
167
|
// full node handle without boxing or losing the source node id.
|
|
@@ -227,6 +242,8 @@ public:
|
|
|
227
242
|
NodeHandle firstChildHandle() const;
|
|
228
243
|
ChildNodeList childNodesHandle() const;
|
|
229
244
|
NodeHandle nextSiblingHandle() const;
|
|
245
|
+
NodeHandle previousSiblingHandle() const;
|
|
246
|
+
int compareDocumentPosition(const NodeHandle &other) const;
|
|
230
247
|
NodeHandle parentHandle() const;
|
|
231
248
|
std::vector<NodeHandle> elementChildren() const;
|
|
232
249
|
NodeHandle lastElementChildHandle() const;
|
|
@@ -262,6 +279,7 @@ public:
|
|
|
262
279
|
// binds neither `const char *` parameter.
|
|
263
280
|
const char *getAttribute(const std::string &name) const { return getAttribute(name.c_str()); }
|
|
264
281
|
bool hasAttribute(const std::string &name) const { return hasAttribute(name.c_str()); }
|
|
282
|
+
gea::host::DOMRect getBoundingClientRect() const;
|
|
265
283
|
void scrollIntoView() const;
|
|
266
284
|
// Text-input focus, the same state `Tree::setActiveInput` already holds for
|
|
267
285
|
// the virtual keyboard: focusing an `<input>` is what summons the on-screen
|
|
@@ -278,12 +296,43 @@ public:
|
|
|
278
296
|
void pause() const;
|
|
279
297
|
void setTagName(const char *tagName) const;
|
|
280
298
|
const char *tagName() const;
|
|
299
|
+
std::string domNodeName() const;
|
|
300
|
+
const std::string *characterData() const;
|
|
301
|
+
void setCharacterData(const char *text) const;
|
|
302
|
+
void setCharacterData(const std::string &text) const { setCharacterData(text.c_str()); }
|
|
303
|
+
const std::string *namespaceURI() const;
|
|
304
|
+
const std::string *namespacePrefix() const;
|
|
281
305
|
void setPressId(int pressId) const;
|
|
282
306
|
void setPressValue(int pressValue) const;
|
|
283
307
|
gea::framework::events::EventListenerId addEventListener(const char *type, gea::framework::events::EventListener listener) const;
|
|
284
308
|
bool removeEventListener(const char *type, gea::framework::events::EventListenerId listenerId) const;
|
|
285
309
|
};
|
|
286
310
|
|
|
311
|
+
// Reads the current native cascade each time, including after stylesheet changes.
|
|
312
|
+
class NativeComputedStyle {
|
|
313
|
+
enum class Target { element, before, after, absent };
|
|
314
|
+
NodeHandle owner_;
|
|
315
|
+
Target target_ = Target::absent;
|
|
316
|
+
NodeHandle selectedNode() const;
|
|
317
|
+
std::string resolvedDimension(bool horizontal) const;
|
|
318
|
+
NativeComputedStyle(NodeHandle owner, Target target) : owner_(owner), target_(target) {}
|
|
319
|
+
friend NativeComputedStyle getComputedStyle(NodeHandle, std::string_view);
|
|
320
|
+
public:
|
|
321
|
+
NativeComputedStyle() = default;
|
|
322
|
+
explicit operator bool() const { return owner_.identity() != nullptr; }
|
|
323
|
+
std::string display() const;
|
|
324
|
+
std::string position() const;
|
|
325
|
+
std::string overflow() const;
|
|
326
|
+
std::string borderRadius() const;
|
|
327
|
+
std::string filter() const;
|
|
328
|
+
std::string width() const;
|
|
329
|
+
std::string height() const;
|
|
330
|
+
std::string paddingTop() const;
|
|
331
|
+
std::string paddingBottom() const;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
NativeComputedStyle getComputedStyle(NodeHandle node, std::string_view pseudoElement = {});
|
|
335
|
+
|
|
287
336
|
// Platform focus owns the actual responder transition. Pixel targets use the
|
|
288
337
|
// unhandled default; native targets must explicitly accept or refuse.
|
|
289
338
|
enum class NativeFocusResult { unhandled, accepted, refused };
|
package/ui/render.cpp
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include <pixel.h>
|
|
15
15
|
|
|
16
16
|
#include <algorithm>
|
|
17
|
+
#include <atomic>
|
|
17
18
|
#include <array>
|
|
18
19
|
#include <cctype>
|
|
19
20
|
#include <climits>
|
|
@@ -5600,6 +5601,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
5600
5601
|
// TX). One buffer set per instance, so distinct gradients sharing one fall back to
|
|
5601
5602
|
// the normal render. `span(y,&x0,&x1)` narrows a row to the rounded-corner span;
|
|
5602
5603
|
// `pixel(x,y,&color,&alpha)` computes one pixel (used only on the one-time bake).
|
|
5604
|
+
struct StaticGradientCache;
|
|
5605
|
+
// Every cache instance, so an app reset can free their full-screen bakes:
|
|
5606
|
+
// Sonora's two gradients left ~1.4 MB of PSRAM behind after it unloaded.
|
|
5607
|
+
std::atomic<StaticGradientCache *> gStaticGradientCaches[8] = {};
|
|
5603
5608
|
struct StaticGradientCache
|
|
5604
5609
|
{
|
|
5605
5610
|
gea::framework::graphics::pixel::native_t *color = nullptr;
|
|
@@ -5611,6 +5616,28 @@ int gLastScrollUiFrame = -1000;
|
|
|
5611
5616
|
int stable = 0;
|
|
5612
5617
|
bool valid = false;
|
|
5613
5618
|
|
|
5619
|
+
StaticGradientCache()
|
|
5620
|
+
{
|
|
5621
|
+
for (auto &slot : gStaticGradientCaches)
|
|
5622
|
+
{
|
|
5623
|
+
StaticGradientCache *empty = nullptr;
|
|
5624
|
+
if (slot.compare_exchange_strong(empty, this))
|
|
5625
|
+
break;
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
|
|
5629
|
+
void release()
|
|
5630
|
+
{
|
|
5631
|
+
gea::framework::memory::Allocator::free(color);
|
|
5632
|
+
gea::framework::memory::Allocator::free(alpha);
|
|
5633
|
+
color = nullptr;
|
|
5634
|
+
alpha = nullptr;
|
|
5635
|
+
cap = kw = kh = 0;
|
|
5636
|
+
keyLen = 0;
|
|
5637
|
+
stable = 0;
|
|
5638
|
+
valid = false;
|
|
5639
|
+
}
|
|
5640
|
+
|
|
5614
5641
|
template <typename SpanFn>
|
|
5615
5642
|
bool blit(const GradientKeyWord *keyNow, int kl, int x0, int y0, int x1, int y1, int scrW, int scrH, SpanFn span)
|
|
5616
5643
|
{
|
|
@@ -10690,6 +10717,9 @@ int gLastScrollUiFrame = -1000;
|
|
|
10690
10717
|
void DisplayList::resetStorage()
|
|
10691
10718
|
{
|
|
10692
10719
|
state.resetStorage();
|
|
10720
|
+
for (auto &slot : gStaticGradientCaches)
|
|
10721
|
+
if (StaticGradientCache *cache = slot.load())
|
|
10722
|
+
cache->release();
|
|
10693
10723
|
pruneImageReferences();
|
|
10694
10724
|
invalidateStaticBackdrop();
|
|
10695
10725
|
}
|
|
@@ -11221,7 +11251,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
11221
11251
|
return true;
|
|
11222
11252
|
}
|
|
11223
11253
|
|
|
11224
|
-
void DisplayList::recordNode(int id, uint8_t parent_alpha, bool allowSkipStatic)
|
|
11254
|
+
void DisplayList::recordNode(int id, uint8_t parent_alpha, bool allowSkipStatic, bool paintDocumentCanvas)
|
|
11225
11255
|
{
|
|
11226
11256
|
Tree &tree = Tree::instance();
|
|
11227
11257
|
if (id < 0 || id >= tree.nodeCount())
|
|
@@ -11259,7 +11289,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
11259
11289
|
}
|
|
11260
11290
|
}
|
|
11261
11291
|
}
|
|
11262
|
-
if (isDocumentCanvasRoot(nodes[id])) {
|
|
11292
|
+
if (paintDocumentCanvas && isDocumentCanvasRoot(nodes[id])) {
|
|
11263
11293
|
// The UA canvas is below the root's opacity/visibility scope and is
|
|
11264
11294
|
// independent of its layout box. Replaying it clears removed or
|
|
11265
11295
|
// translucent propagated backgrounds across the whole viewport.
|
package/ui/style.cpp
CHANGED
|
@@ -9393,6 +9393,27 @@ void Style::setProperty(const std::string &property, const std::string &value) c
|
|
|
9393
9393
|
StyleSheet::instance().applyProperty(NodeHandle(nodeId_, identity_), property, value);
|
|
9394
9394
|
}
|
|
9395
9395
|
|
|
9396
|
+
bool Style::setNamedProperty(const std::string &property, const std::string &value) const
|
|
9397
|
+
{
|
|
9398
|
+
std::string name;
|
|
9399
|
+
if (property == "cssFloat") name = "float";
|
|
9400
|
+
else if (property.starts_with("--")) name = property;
|
|
9401
|
+
else {
|
|
9402
|
+
if (property.size() > 2 && property.starts_with("ms") && property[2] >= 'A' && property[2] <= 'Z')
|
|
9403
|
+
name.push_back('-');
|
|
9404
|
+
for (const char ch : property) {
|
|
9405
|
+
if (ch >= 'A' && ch <= 'Z') {
|
|
9406
|
+
name.push_back('-');
|
|
9407
|
+
name.push_back(static_cast<char>(ch + ('a' - 'A')));
|
|
9408
|
+
} else name.push_back(ch);
|
|
9409
|
+
}
|
|
9410
|
+
}
|
|
9411
|
+
if (name.find('\0') != std::string::npos || classifyDeclaration(name) == CssDeclarationId::Unknown) return false;
|
|
9412
|
+
if (value.empty()) removeProperty(name);
|
|
9413
|
+
else setProperty(name, value);
|
|
9414
|
+
return true;
|
|
9415
|
+
}
|
|
9416
|
+
|
|
9396
9417
|
bool NodeHandle::setStyleNumberProperty(const std::string &property, double value) const
|
|
9397
9418
|
{
|
|
9398
9419
|
// applyNumberDeclarationWithSource validates this handle; no Style, so no
|
|
@@ -12910,15 +12931,42 @@ bool mediaQueryMatches(const std::string &query)
|
|
|
12910
12931
|
return true;
|
|
12911
12932
|
}
|
|
12912
12933
|
|
|
12934
|
+
bool viewportMediaQueryMatches(const std::string &query)
|
|
12935
|
+
{
|
|
12936
|
+
std::string rest = trimCssValue(query);
|
|
12937
|
+
for (char &ch : rest)
|
|
12938
|
+
if (ch >= 'A' && ch <= 'Z') ch = static_cast<char>(ch + ('a' - 'A'));
|
|
12939
|
+
if (rest.empty()) return false;
|
|
12940
|
+
|
|
12941
|
+
const auto takeWord = [&]() {
|
|
12942
|
+
const auto end = rest.find_first_of(" \t\r\n\f(");
|
|
12943
|
+
std::string word = rest.substr(0, end);
|
|
12944
|
+
rest = end == std::string::npos ? std::string{} : trimCssValue(rest.substr(end));
|
|
12945
|
+
return word;
|
|
12946
|
+
};
|
|
12947
|
+
if (rest.front() == '(') return mediaQueryMatches(rest);
|
|
12948
|
+
std::string type = takeWord();
|
|
12949
|
+
const bool negate = type == "not";
|
|
12950
|
+
if (negate || type == "only") {
|
|
12951
|
+
if (negate && !rest.empty() && rest.front() == '(') return !mediaQueryMatches(rest);
|
|
12952
|
+
type = takeWord();
|
|
12953
|
+
}
|
|
12954
|
+
if (type.empty()) return false;
|
|
12955
|
+
const bool matchesType = type == "screen" || type == "all";
|
|
12956
|
+
if (rest.empty()) return negate != matchesType;
|
|
12957
|
+
if (takeWord() != "and" || rest.empty() || rest.front() != '(') return false;
|
|
12958
|
+
return negate != (matchesType && mediaQueryMatches(rest));
|
|
12959
|
+
}
|
|
12960
|
+
|
|
12913
12961
|
// Full condition: comma-separated queries are OR'd.
|
|
12914
|
-
bool mediaConditionMatches(const std::string &condition)
|
|
12962
|
+
bool mediaConditionMatches(const std::string &condition, bool matchViewportType = false)
|
|
12915
12963
|
{
|
|
12916
12964
|
if (condition.empty()) return true;
|
|
12917
12965
|
std::size_t start = 0;
|
|
12918
12966
|
while (true) {
|
|
12919
12967
|
const std::size_t comma = condition.find(',', start);
|
|
12920
12968
|
const std::string query = condition.substr(start, comma == std::string::npos ? std::string::npos : comma - start);
|
|
12921
|
-
if (mediaQueryMatches(query)) return true;
|
|
12969
|
+
if (matchViewportType ? viewportMediaQueryMatches(query) : mediaQueryMatches(query)) return true;
|
|
12922
12970
|
if (comma == std::string::npos) break;
|
|
12923
12971
|
start = comma + 1;
|
|
12924
12972
|
}
|
|
@@ -13803,6 +13851,16 @@ public:
|
|
|
13803
13851
|
spillCount_ = 0;
|
|
13804
13852
|
}
|
|
13805
13853
|
|
|
13854
|
+
// clear() keeps the spill chunks for the next plans; release() frees them.
|
|
13855
|
+
void release()
|
|
13856
|
+
{
|
|
13857
|
+
clear();
|
|
13858
|
+
for (ActiveRulePlanCacheEntry *&chunk : chunks_) {
|
|
13859
|
+
delete[] chunk;
|
|
13860
|
+
chunk = nullptr;
|
|
13861
|
+
}
|
|
13862
|
+
}
|
|
13863
|
+
|
|
13806
13864
|
private:
|
|
13807
13865
|
static constexpr std::size_t kInlineCapacity =
|
|
13808
13866
|
static_cast<std::size_t>(GEA_CSS_ACTIVE_RULE_PLAN_INLINE_CACHE_ENTRIES);
|
|
@@ -17785,6 +17843,11 @@ void startAnimationForNode(NodeCssAnimation &entry, std::uint32_t nowMs)
|
|
|
17785
17843
|
|
|
17786
17844
|
} // namespace
|
|
17787
17845
|
|
|
17846
|
+
bool MediaQueryMatch::matches() const
|
|
17847
|
+
{
|
|
17848
|
+
return mediaConditionMatches(query, true);
|
|
17849
|
+
}
|
|
17850
|
+
|
|
17788
17851
|
bool StyleValues::hasTextBackgroundClip(const ComputedStyle &style)
|
|
17789
17852
|
{
|
|
17790
17853
|
const auto handle = rstyle(style).bg_clip;
|
|
@@ -18111,6 +18174,17 @@ void StyleSheet::clear()
|
|
|
18111
18174
|
#endif
|
|
18112
18175
|
g_pendingRecomputeMark.clear();
|
|
18113
18176
|
g_forceFullSubtreeMark.clear();
|
|
18177
|
+
// clear() keeps capacity, so the rule tables would stay at the size of the
|
|
18178
|
+
// largest stylesheet any app registered (Sonora's left ~170 KB of PSRAM
|
|
18179
|
+
// behind its unload). An app's sheet is replaced whole here: release it.
|
|
18180
|
+
const auto release = [](auto &storage) { storage = std::remove_reference_t<decltype(storage)>{}; };
|
|
18181
|
+
release(rules());
|
|
18182
|
+
release(compiledCssValues());
|
|
18183
|
+
release(cssRuleTexts());
|
|
18184
|
+
activeRulePlanCache().release();
|
|
18185
|
+
activeRulePlanCacheLastHit() = static_cast<std::size_t>(-1);
|
|
18186
|
+
release(cachedStyleApplyOps());
|
|
18187
|
+
g_ruleIndex = RuleIndex{};
|
|
18114
18188
|
recomputeAllClassStyles();
|
|
18115
18189
|
}
|
|
18116
18190
|
|
|
@@ -18913,6 +18987,17 @@ const char *Tree::tagName(int node) const
|
|
|
18913
18987
|
return tagFromId(state.nodes[node].tag_id);
|
|
18914
18988
|
}
|
|
18915
18989
|
|
|
18990
|
+
int Tree::generatedPseudoChild(int node, bool before) const
|
|
18991
|
+
{
|
|
18992
|
+
#if GEA_CSS_PSEUDO_ELEMENTS
|
|
18993
|
+
return findPseudoChild(node, before ? CssRule::PseudoElement::Before : CssRule::PseudoElement::After);
|
|
18994
|
+
#else
|
|
18995
|
+
(void)node;
|
|
18996
|
+
(void)before;
|
|
18997
|
+
return -1;
|
|
18998
|
+
#endif
|
|
18999
|
+
}
|
|
19000
|
+
|
|
18916
19001
|
bool Tree::addClass(int node, const std::string &token)
|
|
18917
19002
|
{
|
|
18918
19003
|
auto &state = treeState();
|
package/ui/style.h
CHANGED
|
@@ -11,6 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
namespace gea::embedded::ui {
|
|
13
13
|
|
|
14
|
+
struct MediaQueryMatch {
|
|
15
|
+
std::string query;
|
|
16
|
+
bool matches() const;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
inline MediaQueryMatch matchMedia(const std::string &query)
|
|
20
|
+
{
|
|
21
|
+
return MediaQueryMatch{query};
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
15
25
|
struct DebuggerCssRule {
|
|
16
26
|
std::string selector, property, value, media;
|
|
@@ -404,6 +414,7 @@ public:
|
|
|
404
414
|
// one the CSS parser feeds), rather than duplicating property-name
|
|
405
415
|
// parsing here.
|
|
406
416
|
void setProperty(const std::string &property, const std::string &value) const;
|
|
417
|
+
bool setNamedProperty(const std::string &property, const std::string &value) const;
|
|
407
418
|
bool setNumberProperty(const std::string &property, double value) const;
|
|
408
419
|
bool removeProperty(const std::string &property) const;
|
|
409
420
|
|