@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/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
 
@@ -69,6 +69,7 @@ public:
69
69
  bool hasAttribute(int node, const char *name) const;
70
70
  void setTagName(int node, const char *tagName);
71
71
  const char *tagName(int node) const;
72
+ int generatedPseudoChild(int node, bool before) const;
72
73
  void setClassName(int node, const char *className);
73
74
  void setClassName(int node, const std::string &className);
74
75
  bool addClass(int node, const std::string &token);
@@ -114,11 +115,13 @@ public:
114
115
 
115
116
  void mount(int root, int width, int height);
116
117
  void refresh(int root, int width, int height);
118
+ void paintCapture(int root, bool transparent);
117
119
  // Native targets (macOS) that bypass the display-list pipeline and drive
118
120
  // platform widgets directly need just the flex-layout pass without any
119
121
  // rendering / dirty-region / present side effects. computeLayout is that
120
122
  // pass in isolation; other targets keep calling refresh() unchanged.
121
123
  void computeLayout(int root, int width, int height);
124
+ void flushLayoutFor(int node);
122
125
  void frame(int timestampMs);
123
126
  void clear();
124
127
 
package/ui/tree_nodes.cpp CHANGED
@@ -322,6 +322,9 @@ int Tree::cloneNode(int sourceId, bool deep)
322
322
  // srcRd stays valid.)
323
323
  if (const NodeRareData *srcRd = rareDataFor(sourceId)) {
324
324
  NodeRareData &cloneRd = ensureRareData(id);
325
+ cloneRd.hasExplicitNamespace = srcRd->hasExplicitNamespace;
326
+ cloneRd.namespaceUri = srcRd->namespaceUri;
327
+ cloneRd.namespacePrefix = srcRd->namespacePrefix;
325
328
  cloneRd.attributes = srcRd->attributes;
326
329
  cloneRd.customProperties = srcRd->customProperties;
327
330
  cloneRd.defaultStyles = srcRd->defaultStyles;
@@ -1942,6 +1942,30 @@ namespace gea::embedded::ui
1942
1942
  LayoutSnapshot::capture();
1943
1943
  }
1944
1944
 
1945
+ void Tree::paintCapture(int root, bool transparent)
1946
+ {
1947
+ using gea::platform::display::Display;
1948
+ using gea::framework::graphics::pixel::nativeColor;
1949
+ using gea::framework::graphics::pixel::preserveCaptureAlpha;
1950
+
1951
+ struct RestoreCaptureAlpha {
1952
+ bool previous = preserveCaptureAlpha;
1953
+ ~RestoreCaptureAlpha() { preserveCaptureAlpha = previous; }
1954
+ } restoreAlpha;
1955
+ preserveCaptureAlpha = transparent;
1956
+
1957
+ auto &list = DisplayList::instance();
1958
+ Display::resetClip();
1959
+ Display::setAlpha(255);
1960
+ Display::canvas()->clear(transparent ? 0 : nativeColor(255, 255, 255));
1961
+
1962
+ list.clear();
1963
+ list.recordNode(root, 255, false, !transparent);
1964
+ list.weldTransformedFaces();
1965
+ list.replay();
1966
+ markDisplayListDirty();
1967
+ }
1968
+
1945
1969
  void Tree::computeLayout(int root, int width, int height)
1946
1970
  {
1947
1971
  auto &state = treeState();
@@ -2000,6 +2024,23 @@ namespace gea::embedded::ui
2000
2024
  state.refreshSerial = 1;
2001
2025
  }
2002
2026
 
2027
+ void Tree::flushLayoutFor(int node)
2028
+ {
2029
+ auto &state = treeState();
2030
+ bool belongsToViewport = false;
2031
+ int remaining = state.nodeCount;
2032
+ for (int ancestor = node; ancestor >= 0 && ancestor < state.nodeCount && remaining-- > 0;
2033
+ ancestor = state.nodes[ancestor].parent) {
2034
+ if (ancestor == gLayoutViewportRoot) belongsToViewport = true;
2035
+ if (ancestor != state.mountedRoot) continue;
2036
+ if (belongsToViewport && gLayoutViewportRoot != state.mountedRoot)
2037
+ computeLayout(gLayoutViewportRoot, gLayoutViewportWidth, gLayoutViewportHeight);
2038
+ else
2039
+ computeLayout(state.mountedRoot, state.mountedWidth, state.mountedHeight);
2040
+ return;
2041
+ }
2042
+ }
2043
+
2003
2044
  namespace
2004
2045
  {
2005
2046
  // Scoped-relayout root for the current dirty set: the lowest ancestor
package/ui/tree_state.h CHANGED
@@ -208,6 +208,9 @@ struct GridTrackLayout {
208
208
  struct ChildNodeListIdentity;
209
209
 
210
210
  struct NodeRareData {
211
+ CssAtomId namespaceUri = kInvalidCssAtom;
212
+ CssAtomId namespacePrefix = kInvalidCssAtom;
213
+ bool hasExplicitNamespace = false;
211
214
  std::shared_ptr<const ChildNodeListIdentity> childNodeListIdentity;
212
215
  // Reuse the listener record's tail padding for inline-position metadata.
213
216
  // Both members remain ordinary embedded fields with fixed-offset access.
@@ -248,6 +251,9 @@ struct NodeRareData {
248
251
 
249
252
  void clear()
250
253
  {
254
+ namespaceUri = kInvalidCssAtom;
255
+ namespacePrefix = kInvalidCssAtom;
256
+ hasExplicitNamespace = false;
251
257
  childNodeListIdentity.reset();
252
258
  attributes.clear();
253
259
  listeners.clear();
package/ui/view.cpp CHANGED
@@ -1,5 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #include "internal.h"
3
+ #include "node.h"
3
4
  #include "state_init.h"
4
5
  #include "renderer_features.h"
5
6
  #include "style_values.h"
@@ -1321,6 +1322,12 @@ public:
1321
1322
  return pr;
1322
1323
  }
1323
1324
  static void GEA_VIEW_HOT_SRAM_SECTION("project_point") projectPoint(const ChainProjector &pr, float x, float y, float z, int16_t *outX, int16_t *outY)
1325
+ {
1326
+ const auto p = projectPoint(pr, x, y, z);
1327
+ *outX = static_cast<int16_t>(std::lroundf(p.x));
1328
+ *outY = static_cast<int16_t>(std::lroundf(p.y));
1329
+ }
1330
+ static Point3 projectPoint(const ChainProjector &pr, float x, float y, float z)
1324
1331
  {
1325
1332
  Point3 p{x, y, z};
1326
1333
  if (pr.depth >= 0) {
@@ -1331,8 +1338,7 @@ public:
1331
1338
  applyNodeTransform(state.nodes[id], false, p);
1332
1339
  }
1333
1340
  applyPerspective(pr.perspectiveNode, false, p);
1334
- *outX = static_cast<int16_t>(std::lroundf(p.x));
1335
- *outY = static_cast<int16_t>(std::lroundf(p.y));
1341
+ return p;
1336
1342
  }
1337
1343
 
1338
1344
  static int GEA_VIEW_HOT_SRAM_SECTION("average_depth_compute") averageDepthCompute(const Node &node, bool usePrevious)
@@ -2380,6 +2386,34 @@ void GEA_VIEW_HOT_SRAM_SECTION("view_renderer_transformed_rect_corners") ViewRen
2380
2386
  ViewGeometry::transformRectCorners(node, usePrevious, x, y, w, h, xs, ys, xs8, ys8);
2381
2387
  }
2382
2388
 
2389
+ gea::host::DOMRect NodeHandle::getBoundingClientRect() const
2390
+ {
2391
+ if (!isConnected()) return gea::host::DOMRect::create();
2392
+ auto &tree = Tree::instance();
2393
+ tree.flushLayoutFor(id());
2394
+ if (!valid()) return gea::host::DOMRect::create();
2395
+
2396
+ int remaining = tree.nodeCount();
2397
+ for (int ancestor = id(); ancestor >= 0 && ancestor < tree.nodeCount() && remaining-- > 0;
2398
+ ancestor = tree.node(ancestor).parent) {
2399
+ if (tree.node(ancestor).computedStyle().display == kDisplayNone)
2400
+ return gea::host::DOMRect::create();
2401
+ }
2402
+ const auto &node = tree.node(id());
2403
+ const auto &box = node.layout;
2404
+ if (!ViewGeometry::hasTransformChain(node, false))
2405
+ return gea::host::DOMRect::create(box.x, box.y, box.width, box.height);
2406
+
2407
+ const auto projector = ViewGeometry::prepareProjector(node);
2408
+ const auto topLeft = ViewGeometry::projectPoint(projector, box.x, box.y, 0);
2409
+ const auto topRight = ViewGeometry::projectPoint(projector, box.x + box.width, box.y, 0);
2410
+ const auto bottomLeft = ViewGeometry::projectPoint(projector, box.x, box.y + box.height, 0);
2411
+ const auto bottomRight = ViewGeometry::projectPoint(projector, box.x + box.width, box.y + box.height, 0);
2412
+ const auto [left, right] = std::minmax({topLeft.x, topRight.x, bottomLeft.x, bottomRight.x});
2413
+ const auto [top, bottom] = std::minmax({topLeft.y, topRight.y, bottomLeft.y, bottomRight.y});
2414
+ return gea::host::DOMRect::create(left, top, right - left, bottom - top);
2415
+ }
2416
+
2383
2417
  int GEA_VIEW_HOT_SRAM_SECTION("view_renderer_transformed_depth") ViewRenderer::transformedDepth(const Node &node, bool usePrevious)
2384
2418
  {
2385
2419
  return ViewGeometry::averageDepth(node, usePrevious);
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2013-14 Mikko Mononen memon@inside.org
2
+
3
+ This software is provided 'as-is', without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+ 2. Altered source versions must be plainly marked as such, and must not be
16
+ misrepresented as being the original software.
17
+ 3. This notice may not be removed or altered from any source distribution.
18
+