@geastack/engine 0.1.32 → 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 +75 -2
- 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/vendor/nanosvg/LICENSE.txt +18 -0
- package/vendor/nanosvg/nanosvg.h +3278 -0
- package/vendor/nanosvg/nanosvgrast.h +1472 -0
package/ui/document.cpp
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "document.h"
|
|
3
|
+
#include "child_node_list.h"
|
|
3
4
|
#include "selector.h"
|
|
4
5
|
#include "tree_state.h"
|
|
5
6
|
|
|
@@ -12,11 +13,14 @@
|
|
|
12
13
|
|
|
13
14
|
#include <algorithm>
|
|
14
15
|
#include <cctype>
|
|
16
|
+
#include <cmath>
|
|
15
17
|
#include <cstdlib>
|
|
16
18
|
#include <cstring>
|
|
19
|
+
#include <limits>
|
|
17
20
|
#include <utility>
|
|
18
21
|
#include <vector>
|
|
19
22
|
#include <string>
|
|
23
|
+
#include <string_view>
|
|
20
24
|
|
|
21
25
|
namespace gea::embedded::ui {
|
|
22
26
|
|
|
@@ -65,6 +69,45 @@ ViewElement Document::body() const
|
|
|
65
69
|
return ViewElement();
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
NodeHandle Document::documentElement() const
|
|
73
|
+
{
|
|
74
|
+
return NodeHandle(Tree::instance().mountedRoot());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
int Document::viewportScrollX() const
|
|
78
|
+
{
|
|
79
|
+
const auto &tree = Tree::instance();
|
|
80
|
+
return tree.scrollLeft(tree.mountedRoot());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int Document::viewportScrollY() const
|
|
84
|
+
{
|
|
85
|
+
const auto &tree = Tree::instance();
|
|
86
|
+
return tree.scrollTop(tree.mountedRoot());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void Document::scrollViewportTo(double x, double y) const
|
|
90
|
+
{
|
|
91
|
+
auto &tree = Tree::instance();
|
|
92
|
+
const int root = tree.mountedRoot();
|
|
93
|
+
if (root < 0) return;
|
|
94
|
+
const auto offset = [](double value) {
|
|
95
|
+
return std::isfinite(value) ? static_cast<int>(std::clamp(value, 0.0, static_cast<double>(std::numeric_limits<int>::max()))) : 0;
|
|
96
|
+
};
|
|
97
|
+
tree.setScrollLeft(root, offset(x));
|
|
98
|
+
tree.setScrollTop(root, offset(y));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NodeHandle Document::head() const
|
|
102
|
+
{
|
|
103
|
+
const NodeHandle root = documentElement();
|
|
104
|
+
if (!root.valid() || std::strcmp(root.tagName(), "html") != 0) return {};
|
|
105
|
+
for (NodeHandle child = root.firstChildHandle(); child.valid(); child = child.nextSiblingHandle()) {
|
|
106
|
+
if (std::strcmp(child.tagName(), "head") == 0) return child;
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
|
|
68
111
|
ViewElement Document::createView() const
|
|
69
112
|
{
|
|
70
113
|
return ViewElement::create();
|
|
@@ -142,6 +185,23 @@ NodeHandle Document::activeElement() const {
|
|
|
142
185
|
return node.valid()&&node.isConnected()?node:NodeHandle();
|
|
143
186
|
}
|
|
144
187
|
|
|
188
|
+
DocumentSelection Document::selection() const
|
|
189
|
+
{
|
|
190
|
+
if (!selection_.anchorNode.isConnected() || !selection_.focusNode.isConnected()) selection_ = {};
|
|
191
|
+
return selection_;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void Document::selectAllChildren(const NodeHandle &node)
|
|
195
|
+
{
|
|
196
|
+
if (!node.isConnected()) return;
|
|
197
|
+
selection_ = {node, node, 0, node.childNodesHandle().length()};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void Document::clearSelection()
|
|
201
|
+
{
|
|
202
|
+
selection_ = {};
|
|
203
|
+
}
|
|
204
|
+
|
|
145
205
|
NodeHandle Document::createElement(const char *tag) const
|
|
146
206
|
{
|
|
147
207
|
std::string lowered = tag ? tag : "";
|
|
@@ -158,6 +218,46 @@ NodeHandle Document::createElement(const char *tag) const
|
|
|
158
218
|
return node;
|
|
159
219
|
}
|
|
160
220
|
|
|
221
|
+
NodeHandle Document::createElementNS(const std::string &namespaceUri, const std::string &qualifiedName) const
|
|
222
|
+
{
|
|
223
|
+
constexpr std::string_view html = "http://www.w3.org/1999/xhtml";
|
|
224
|
+
constexpr std::string_view xml = "http://www.w3.org/XML/1998/namespace";
|
|
225
|
+
constexpr std::string_view xmlns = "http://www.w3.org/2000/xmlns/";
|
|
226
|
+
const auto colon = qualifiedName.find(':');
|
|
227
|
+
const bool prefixed = colon != std::string::npos;
|
|
228
|
+
const auto prefix = prefixed ? qualifiedName.substr(0, colon) : std::string{};
|
|
229
|
+
const auto local = prefixed ? qualifiedName.substr(colon + 1) : qualifiedName;
|
|
230
|
+
const auto alpha = [](unsigned char ch) { return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); };
|
|
231
|
+
const auto nameStart = [&](unsigned char ch) { return alpha(ch) || ch == '_' || ch >= 0x80; };
|
|
232
|
+
const auto restrictedName = [&](unsigned char ch) {
|
|
233
|
+
return nameStart(ch) || (ch >= '0' && ch <= '9') || ch == '.' || ch == '-';
|
|
234
|
+
};
|
|
235
|
+
constexpr std::string_view forbidden("\0\t\n\f\r />", 8);
|
|
236
|
+
const bool validPrefix = !prefixed || (!prefix.empty() && prefix.find_first_of(forbidden) == std::string::npos);
|
|
237
|
+
const bool validLocal = !local.empty() &&
|
|
238
|
+
(alpha(local.front()) ? local.find_first_of(forbidden) == std::string::npos
|
|
239
|
+
: (nameStart(local.front()) || local.front() == ':') &&
|
|
240
|
+
std::all_of(local.begin(), local.end(), [&](unsigned char ch) { return restrictedName(ch) || ch == ':'; }));
|
|
241
|
+
if (!validPrefix || !validLocal) throw std::invalid_argument("InvalidCharacterError: invalid qualified element name");
|
|
242
|
+
if ((prefixed && namespaceUri.empty()) || (prefix == "xml" && namespaceUri != xml) ||
|
|
243
|
+
((prefix == "xmlns" || qualifiedName == "xmlns") != (namespaceUri == xmlns)))
|
|
244
|
+
throw std::invalid_argument("NamespaceError: invalid qualified element namespace");
|
|
245
|
+
const auto uriAtom = internCssAtom(namespaceUri);
|
|
246
|
+
const auto prefixAtom = internCssAtom(prefix);
|
|
247
|
+
if ((!namespaceUri.empty() && uriAtom == kInvalidCssAtom) || (prefixed && prefixAtom == kInvalidCssAtom))
|
|
248
|
+
throw std::length_error("Native namespace table exhausted");
|
|
249
|
+
auto node = namespaceUri == html && std::none_of(local.begin(), local.end(), [](char ch) { return ch >= 'A' && ch <= 'Z'; })
|
|
250
|
+
? createElement(local)
|
|
251
|
+
: NodeHandle(createView());
|
|
252
|
+
if (!node.valid()) return node;
|
|
253
|
+
auto &metadata = ensureRareData(node.id());
|
|
254
|
+
metadata.hasExplicitNamespace = true;
|
|
255
|
+
metadata.namespaceUri = uriAtom;
|
|
256
|
+
metadata.namespacePrefix = prefixAtom;
|
|
257
|
+
node.setTagName(local.c_str());
|
|
258
|
+
return node;
|
|
259
|
+
}
|
|
260
|
+
|
|
161
261
|
NodeHandle Document::getElementById(const char *id) const
|
|
162
262
|
{
|
|
163
263
|
if (!id || !*id) return {};
|
|
@@ -258,8 +358,22 @@ ViewElement Document::ensureAppRoot(const char *id) const
|
|
|
258
358
|
return root;
|
|
259
359
|
}
|
|
260
360
|
|
|
361
|
+
std::shared_ptr<void> Document::propertyStorage(const std::shared_ptr<void> &initial) const
|
|
362
|
+
{
|
|
363
|
+
std::lock_guard lock(propertyStorageMutex_);
|
|
364
|
+
if (!propertyStorage_) propertyStorage_ = initial;
|
|
365
|
+
return propertyStorage_;
|
|
366
|
+
}
|
|
367
|
+
|
|
261
368
|
void Document::clear() const
|
|
262
369
|
{
|
|
370
|
+
selection_ = {};
|
|
371
|
+
std::shared_ptr<void> retiredProperties;
|
|
372
|
+
{
|
|
373
|
+
std::lock_guard lock(propertyStorageMutex_);
|
|
374
|
+
retiredProperties.swap(propertyStorage_);
|
|
375
|
+
}
|
|
376
|
+
retiredProperties.reset();
|
|
263
377
|
g_direct_canvas_context_used = false;
|
|
264
378
|
Tree::instance().clear();
|
|
265
379
|
}
|
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.
|