@geastack/engine 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +70 -0
  2. package/canvas.cpp +86 -30
  3. package/css/animation.h +64 -0
  4. package/css/declarative.h +6 -0
  5. package/css/engine.h +25 -1
  6. package/image_store.cpp +136 -33
  7. package/package.json +2 -2
  8. package/ui/CSS_FEATURES.md +261 -0
  9. package/ui/absolute_leaf_refresh.cpp +42 -39
  10. package/ui/core.cpp +32 -1
  11. package/ui/css_atom.cpp +6 -0
  12. package/ui/css_atom.h +2 -0
  13. package/ui/css_features.h +282 -0
  14. package/ui/display_invalidation.cpp +29 -0
  15. package/ui/flex_balance.h +73 -0
  16. package/ui/image_node.cpp +33 -28
  17. package/ui/input.cpp +88 -38
  18. package/ui/input_render.cpp +17 -13
  19. package/ui/internal.h +51 -5
  20. package/ui/layout.cpp +2601 -441
  21. package/ui/layout_snapshot.cpp +49 -6
  22. package/ui/node_features.h +18 -0
  23. package/ui/node_lifecycle.cpp +204 -71
  24. package/ui/node_lifecycle.h +1 -0
  25. package/ui/node_model.h +930 -70
  26. package/ui/node_text.h +82 -0
  27. package/ui/render.cpp +793 -352
  28. package/ui/renderer_features.h +19 -0
  29. package/ui/root_scroll_refresh.cpp +46 -24
  30. package/ui/style.cpp +4155 -1073
  31. package/ui/style.h +143 -6
  32. package/ui/style_values.h +16 -0
  33. package/ui/text.cpp +401 -106
  34. package/ui/tree_events.cpp +138 -95
  35. package/ui/tree_events.h +28 -19
  36. package/ui/tree_inspection.h +15 -0
  37. package/ui/tree_internal.h +19 -0
  38. package/ui/tree_nodes.cpp +38 -4
  39. package/ui/tree_render.cpp +119 -40
  40. package/ui/tree_scroll_mirror.cpp +26 -0
  41. package/ui/tree_state.cpp +261 -114
  42. package/ui/tree_state.h +121 -16
  43. package/ui/tree_style.cpp +609 -82
  44. package/ui/view.cpp +720 -299
  45. package/ui/virtual_keyboard.cpp +10 -3
package/ui/image_node.cpp CHANGED
@@ -19,21 +19,23 @@ class ImageFitResolver {
19
19
  public:
20
20
  static ImageFitRect resolve(const Node &node, int imageWidth, int imageHeight)
21
21
  {
22
+ const int contentWidth = node.layout.width - boxInsets(node.style, true);
23
+ const int contentHeight = node.layout.height - boxInsets(node.style, false);
22
24
  ImageFitRect rect{
23
- node.layout.x,
24
- node.layout.y,
25
- node.layout.width,
26
- node.layout.height,
25
+ node.layout.x + boxInset(node.style, 3),
26
+ node.layout.y + boxInset(node.style, 0),
27
+ contentWidth,
28
+ contentHeight,
27
29
  };
28
30
 
29
31
  if (node.style.image_fit == 1 || node.style.image_fit == 4) {
30
- const int scaledWidth = (imageWidth * node.layout.height) / imageHeight;
31
- const int scaledHeight = (imageHeight * node.layout.width) / imageWidth;
32
- if (scaledWidth <= node.layout.width) {
32
+ const int scaledWidth = (imageWidth * contentHeight) / imageHeight;
33
+ const int scaledHeight = (imageHeight * contentWidth) / imageWidth;
34
+ if (scaledWidth <= contentWidth) {
33
35
  rect.width = scaledWidth;
34
- rect.height = node.layout.height;
36
+ rect.height = contentHeight;
35
37
  } else {
36
- rect.width = node.layout.width;
38
+ rect.width = contentWidth;
37
39
  rect.height = scaledHeight;
38
40
  }
39
41
  if (node.style.image_fit == 4 && rect.width >= imageWidth && rect.height >= imageHeight) {
@@ -42,13 +44,13 @@ public:
42
44
  }
43
45
  center(node, rect);
44
46
  } else if (node.style.image_fit == 2) {
45
- const int scaledWidth = (imageWidth * node.layout.height) / imageHeight;
46
- const int scaledHeight = (imageHeight * node.layout.width) / imageWidth;
47
- if (scaledWidth >= node.layout.width) {
47
+ const int scaledWidth = (imageWidth * contentHeight) / imageHeight;
48
+ const int scaledHeight = (imageHeight * contentWidth) / imageWidth;
49
+ if (scaledWidth >= contentWidth) {
48
50
  rect.width = scaledWidth;
49
- rect.height = node.layout.height;
51
+ rect.height = contentHeight;
50
52
  } else {
51
- rect.width = node.layout.width;
53
+ rect.width = contentWidth;
52
54
  rect.height = scaledHeight;
53
55
  }
54
56
  center(node, rect);
@@ -64,25 +66,25 @@ public:
64
66
  private:
65
67
  static void center(const Node &node, ImageFitRect &rect)
66
68
  {
67
- rect.x = node.layout.x + (node.layout.width - rect.width) / 2;
68
- rect.y = node.layout.y + (node.layout.height - rect.height) / 2;
69
+ rect.x = node.layout.x + boxInset(node.style, 3) + (node.layout.width - boxInsets(node.style, true) - rect.width) / 2;
70
+ rect.y = node.layout.y + boxInset(node.style, 0) + (node.layout.height - boxInsets(node.style, false) - rect.height) / 2;
69
71
  }
70
72
  };
71
73
 
72
74
  bool hasImageRadius(const Node &node)
73
75
  {
74
- return node.style.border_radius[0] > 0 ||
75
- node.style.border_radius[1] > 0 ||
76
- node.style.border_radius[2] > 0 ||
77
- node.style.border_radius[3] > 0;
76
+ return node.style.border_radius[GEA_CSS_RADIUS_INDEX(0)] > 0 ||
77
+ node.style.border_radius[GEA_CSS_RADIUS_INDEX(1)] > 0 ||
78
+ node.style.border_radius[GEA_CSS_RADIUS_INDEX(2)] > 0 ||
79
+ node.style.border_radius[GEA_CSS_RADIUS_INDEX(3)] > 0;
78
80
  }
79
81
 
80
82
  void setScaledBlitRadius(DisplayCommand *cmd, const Node &node)
81
83
  {
82
- cmd->scaledBlit.tl = node.style.border_radius[0];
83
- cmd->scaledBlit.tr = node.style.border_radius[1];
84
- cmd->scaledBlit.br = node.style.border_radius[2];
85
- cmd->scaledBlit.bl = node.style.border_radius[3];
84
+ cmd->scaledBlit.tl = node.style.border_radius[GEA_CSS_RADIUS_INDEX(0)];
85
+ cmd->scaledBlit.tr = node.style.border_radius[GEA_CSS_RADIUS_INDEX(1)];
86
+ cmd->scaledBlit.br = node.style.border_radius[GEA_CSS_RADIUS_INDEX(2)];
87
+ cmd->scaledBlit.bl = node.style.border_radius[GEA_CSS_RADIUS_INDEX(3)];
86
88
  }
87
89
 
88
90
  bool applyAxisAlignedTransform(const Node &node, ImageFitRect &rect)
@@ -104,15 +106,18 @@ bool applyAxisAlignedTransform(const Node &node, ImageFitRect &rect)
104
106
 
105
107
  void ImageRenderer::layout(int id)
106
108
  {
109
+ if (!GEA_UI_IMAGE_NODES) return;
107
110
  Node *n = &Tree::instance().nodes()[id];
108
111
  auto &images = gea::framework::graphics::ImageStore::instance();
109
112
  int iw = images.width(n->image_id);
110
113
  int ih = images.height(n->image_id);
111
114
 
112
- if (n->style.width == kUnset && n->style.width_percent == kUnset && iw > 0) n->layout.width = iw;
113
- if (n->style.height == kUnset && n->style.height_percent == kUnset && ih > 0) n->layout.height = ih;
114
- n->layout.width = LayoutEngine::instance().clampSize(n->layout.width, n->style.min_width, n->style.max_width);
115
- n->layout.height = LayoutEngine::instance().clampSize(n->layout.height, n->style.min_height, n->style.max_height);
115
+ if (n->style.width == kUnset && n->style.width_percent == kUnset && n->style.width_expression < 0 && iw > 0)
116
+ n->layout.width = iw + boxInsets(n->style, true);
117
+ if (n->style.height == kUnset && n->style.height_percent == kUnset && n->style.height_expression < 0 && ih > 0)
118
+ n->layout.height = ih + boxInsets(n->style, false);
119
+ n->layout.width = clampBorderBoxSize(n->style, n->layout.width, true);
120
+ n->layout.height = clampBorderBoxSize(n->style, n->layout.height, false);
116
121
  }
117
122
 
118
123
  void ImageRenderer::record(const Node &node)
package/ui/input.cpp CHANGED
@@ -135,7 +135,9 @@ public:
135
135
  activeBackgroundColor_ = node.style.bg_color;
136
136
  activeHasBackground_ = node.style.has_bg;
137
137
  node.render.dirty = 1; // paint-only: press highlight recolors in place
138
+ #if GEA_CSS_SCROLLING
138
139
  node.render.non_scroll_dirty = 1;
140
+ #endif
139
141
  // We mutated bg_color directly (bypassing setStyleValue), so the
140
142
  // direct-replay refresh path would otherwise keep the cached
141
143
  // pre-press color in the display list. Mark commands dirty so the
@@ -300,6 +302,7 @@ public:
300
302
  // velocity samples from a touch the new app never saw.
301
303
  void reset()
302
304
  {
305
+ treeState().hoveredNodeId = -1;
303
306
  activeTouchNode_ = -1;
304
307
  savedBackgroundColor_ = 0;
305
308
  savedHasBackground_ = 0;
@@ -396,20 +399,6 @@ public:
396
399
  private:
397
400
  InputController() = default;
398
401
 
399
- void sortChildrenByZIndex(int *children, int childCount) const
400
- {
401
- Node *nodes = Tree::instance().nodes();
402
- for (int i = 1; i < childCount; i++) {
403
- const int key = children[i];
404
- int j = i - 1;
405
- while (j >= 0 && nodes[children[j]].style.z_index > nodes[key].style.z_index) {
406
- children[j + 1] = children[j];
407
- j--;
408
- }
409
- children[j + 1] = key;
410
- }
411
- }
412
-
413
402
  static bool pointInsideNodeHitArea(const Node &node, int x, int y)
414
403
  {
415
404
  if (node.layout.width <= 0 || node.layout.height <= 0) return false;
@@ -451,10 +440,10 @@ private:
451
440
  return true;
452
441
  }
453
442
 
454
- int hitTestNodeId(int id, int x, int y)
443
+ int hitTestNodeId(int id, int x, int y, bool clipped = false, bool groupRoot = true, bool includePositioned = true)
455
444
  {
456
445
  Node &node = Tree::instance().nodes()[id];
457
- if (node.style.display == 1) return -1;
446
+ if (node.style.display == 1 || isCollapsedFlexSubtree(node)) return -1;
458
447
  // CSS `pointer-events: none` — this node and its subtree are never the
459
448
  // target of a pointer event, so the hit-test falls through to whatever is
460
449
  // painted behind it. Without this, a decorative overlay image positioned
@@ -463,39 +452,63 @@ private:
463
452
  if (node.style.pointer_events == 1) return -1;
464
453
 
465
454
  const bool inside = pointInsideNodeHitArea(node, x, y);
466
- if (!inside && node.style.overflow != 0) return -1;
467
-
468
- int children[kMaxChildren];
469
- const int childCount = LayoutEngine::instance().collectChildren(id, children, kMaxChildren, false);
470
- sortChildrenByZIndex(children, childCount);
471
-
472
- for (int i = childCount - 1; i >= 0; i--) {
473
- const int result = hitTestNodeId(children[i], x, y);
455
+ if (LayoutEngine::isViewportFixed(node)) clipped = false;
456
+ int clipX, clipY, clipW, clipH;
457
+ overflowClipBounds(node, clipX, clipY, clipW, clipH);
458
+ const bool outsideClip = x < clipX || y < clipY || x >= clipX + clipW || y >= clipY + clipH;
459
+ const bool childClipped = clipped || (outsideClip && node.style.overflow != 0);
460
+ if (childClipped && (!inside || clipped) && !LayoutEngine::containsViewportFixed(id)) return -1;
461
+
462
+ const auto children = PaintOrder::collectChildren(id, groupRoot, includePositioned);
463
+ for (auto child = children.rbegin(); child != children.rend(); ++child) {
464
+ bool inheritedClip = childClipped, ignored = false;
465
+ const Node *nodes = Tree::instance().nodes();
466
+ for (int p = nodes[*child].parent; p >= 0 && p != id; p = nodes[p].parent) {
467
+ const auto &ancestor = nodes[p];
468
+ if (ancestor.style.pointer_events == 1) ignored = true;
469
+ int ax, ay, aw, ah;
470
+ overflowClipBounds(ancestor, ax, ay, aw, ah);
471
+ if (ancestor.style.overflow && (x < ax || y < ay || x >= ax + aw || y >= ay + ah)) inheritedClip = true;
472
+ }
473
+ if (ignored) continue;
474
+ const int result = hitTestNodeId(*child, x, y, inheritedClip, PaintOrder::isGroup(*child), PaintOrder::isContext(*child));
474
475
  if (result >= 0) return result;
475
476
  }
476
477
 
477
- if (!inside) return -1;
478
+ if (!inside || clipped || node.style.visibility != 0) return -1;
478
479
  return id;
479
480
  }
480
481
 
481
- int findScrollNodeId(int id, int x, int y)
482
+ int findScrollNodeId(int id, int x, int y, bool clipped = false, bool groupRoot = true, bool includePositioned = true)
482
483
  {
483
484
  Node &node = Tree::instance().nodes()[id];
484
- if (node.style.display == 1) return -1;
485
+ if (node.style.display == 1 || isCollapsedFlexSubtree(node)) return -1;
485
486
 
486
487
  const bool inside = pointInsideNodeHitArea(node, x, y);
487
- if (!inside && node.style.overflow != 0) return -1;
488
-
489
- int children[kMaxChildren];
490
- const int childCount = LayoutEngine::instance().collectChildren(id, children, kMaxChildren, false);
491
- sortChildrenByZIndex(children, childCount);
492
-
493
- for (int i = childCount - 1; i >= 0; i--) {
494
- const int result = findScrollNodeId(children[i], x, y);
488
+ if (LayoutEngine::isViewportFixed(node)) clipped = false;
489
+ int clipX, clipY, clipW, clipH;
490
+ overflowClipBounds(node, clipX, clipY, clipW, clipH);
491
+ const bool outsideClip = x < clipX || y < clipY || x >= clipX + clipW || y >= clipY + clipH;
492
+ const bool childClipped = clipped || (outsideClip && node.style.overflow != 0);
493
+ if (childClipped && (!inside || clipped) && !LayoutEngine::containsViewportFixed(id)) return -1;
494
+
495
+ const auto children = PaintOrder::collectChildren(id, groupRoot, includePositioned);
496
+ for (auto child = children.rbegin(); child != children.rend(); ++child) {
497
+ bool inheritedClip = childClipped, ignored = false;
498
+ const Node *nodes = Tree::instance().nodes();
499
+ for (int p = nodes[*child].parent; p >= 0 && p != id; p = nodes[p].parent) {
500
+ const auto &ancestor = nodes[p];
501
+
502
+ int ax, ay, aw, ah;
503
+ overflowClipBounds(ancestor, ax, ay, aw, ah);
504
+ if (ancestor.style.overflow && (x < ax || y < ay || x >= ax + aw || y >= ay + ah)) inheritedClip = true;
505
+ }
506
+ if (ignored) continue;
507
+ const int result = findScrollNodeId(*child, x, y, inheritedClip, PaintOrder::isGroup(*child), PaintOrder::isContext(*child));
495
508
  if (result >= 0) return result;
496
509
  }
497
510
 
498
- if (!inside) return -1;
511
+ if (!inside || clipped || node.style.visibility != 0) return -1;
499
512
  const bool scrollableVirtualList = node.type == NodeType::VirtualList && VirtualListRenderer::scrollMaxY(id) > 0;
500
513
  const bool scrollableView = node.type != NodeType::VirtualList && isViewLikeNodeType(node.type) &&
501
514
  (nodeCanScrollX(id, node) || nodeCanScrollY(id, node));
@@ -548,6 +561,7 @@ private:
548
561
 
549
562
  static void setScrollLeft(int nodeId, int next)
550
563
  {
564
+ #if GEA_CSS_SCROLLING
551
565
  Tree &tree = Tree::instance();
552
566
  if (nodeId < 0 || nodeId >= tree.nodeCount()) return;
553
567
  Node &node = tree.node(nodeId);
@@ -560,10 +574,14 @@ private:
560
574
  // handles either axis), so it no longer forces the full clipped-replay
561
575
  // path via non_scroll_dirty — mirror the vertical setScrollTop path.
562
576
  tree.markScrollDirty(nodeId);
563
- }
577
+ #else
578
+ (void)nodeId; (void)next;
579
+ #endif
580
+ }
564
581
 
565
582
  static void setScrollTop(int nodeId, int next)
566
583
  {
584
+ #if GEA_CSS_SCROLLING
567
585
  Tree &tree = Tree::instance();
568
586
  if (nodeId < 0 || nodeId >= tree.nodeCount()) return;
569
587
  if (tree.node(nodeId).type == NodeType::VirtualList) {
@@ -576,7 +594,10 @@ private:
576
594
  node.render.dirty = 1;
577
595
  node.render.layout_dirty = 1;
578
596
  tree.markScrollDirty(nodeId);
579
- }
597
+ #else
598
+ (void)nodeId; (void)next;
599
+ #endif
600
+ }
580
601
 
581
602
  static std::uint16_t lightenRgb565(std::uint16_t color)
582
603
  {
@@ -639,7 +660,9 @@ private:
639
660
  node.style.bg_color = savedBackgroundColor_;
640
661
  node.style.has_bg = savedHasBackground_;
641
662
  node.render.dirty = 1; // paint-only: press highlight restore
663
+ #if GEA_CSS_SCROLLING
642
664
  node.render.non_scroll_dirty = 1;
665
+ #endif
643
666
  Tree::instance().markNodeDisplayCommandsDirty(activeTouchNode_);
644
667
  }
645
668
  activeTouchNode_ = -1;
@@ -826,6 +849,25 @@ int Tree::hitTestNode(int x, int y)
826
849
  return InputController::instance().hitTestNode(x, y);
827
850
  }
828
851
 
852
+ int Tree::pointerHover(int x, int y)
853
+ {
854
+ auto &state = treeState();
855
+ const int target = x < 0 || y < 0 ? -1 : hitTestNode(x, y);
856
+ if (target != state.hoveredNodeId) {
857
+ state.hoveredNodeId = target;
858
+ StyleSheet::instance().hoverChanged();
859
+ }
860
+ return target;
861
+ }
862
+
863
+ bool Tree::isHovered(int node) const
864
+ {
865
+ const auto &state = treeState();
866
+ const int target = state.hoveredNodeId;
867
+ return target >= 0 && target < state.nodeCount && state.nodeActive[target] &&
868
+ containsNode(mountedRoot(), target) && containsNode(node, target);
869
+ }
870
+
829
871
  void Tree::pointerDown(int x, int y)
830
872
  {
831
873
  InputController::instance().pointerDown(x, y);
@@ -863,6 +905,7 @@ int Tree::activeInputId() const
863
905
 
864
906
  void Tree::setActiveInput(int nodeId)
865
907
  {
908
+ #if GEA_UI_INPUT_NODES
866
909
  auto &state = treeState();
867
910
  if (nodeId < -1 || nodeId >= state.nodeCount) nodeId = -1;
868
911
  if (state.activeInputId == nodeId) return;
@@ -880,7 +923,9 @@ void Tree::setActiveInput(int nodeId)
880
923
  Node &n = state.nodes[id];
881
924
  n.render.dirty = 1;
882
925
  n.render.layout_dirty = 1;
926
+ #if GEA_CSS_SCROLLING
883
927
  n.render.non_scroll_dirty = 1;
928
+ #endif
884
929
  state.nodeCommandDirty[id] = 1;
885
930
  };
886
931
  markInputDirty(previousId);
@@ -893,6 +938,7 @@ void Tree::setActiveInput(int nodeId)
893
938
  // `displayListDirty`; the keyboard subsystem decides activity in
894
939
  // notifyActiveInputChanged.
895
940
  state.displayListDirty = true;
941
+ #endif
896
942
  }
897
943
 
898
944
  bool Tree::activeInputCaretVisible() const
@@ -902,6 +948,7 @@ bool Tree::activeInputCaretVisible() const
902
948
 
903
949
  void Tree::tickInputCaret(int timestampMs)
904
950
  {
951
+ #if GEA_UI_INPUT_NODES
905
952
  auto &state = treeState();
906
953
  if (state.activeInputId < 0) {
907
954
  state.caretVisible = false;
@@ -929,8 +976,11 @@ void Tree::tickInputCaret(int timestampMs)
929
976
  Node &n = state.nodes[state.activeInputId];
930
977
  n.render.dirty = 1;
931
978
  n.render.layout_dirty = 1;
979
+ #if GEA_CSS_SCROLLING
932
980
  n.render.non_scroll_dirty = 1;
981
+ #endif
933
982
  }
983
+ #endif
934
984
  }
935
985
 
936
986
  } // namespace gea::embedded::ui
@@ -78,6 +78,7 @@ const char *inputMeasureText(int id)
78
78
 
79
79
  void InputRenderer::layout(int id, int)
80
80
  {
81
+ if (!GEA_UI_INPUT_NODES) return;
81
82
  auto &tree = Tree::instance();
82
83
  if (id < 0 || id >= tree.nodeCount()) return;
83
84
  Node &n = tree.node(id);
@@ -86,21 +87,24 @@ void InputRenderer::layout(int id, int)
86
87
 
87
88
  const char *content = inputContentText(id, nullptr, n.style.text_color);
88
89
  const char *measureText = inputMeasureText(id);
89
- int width = TextRenderer::measureWidth(content, n.style.font_id, n.style.font_size, n.style.text_transform) + n.style.padding[1] + n.style.padding[3];
90
- int height = TextRenderer::measureHeight(measureText, n.style.font_id, n.style.font_size, n.style.text_transform, n.style.line_height) + n.style.padding[0] + n.style.padding[2];
91
-
92
- if (n.style.width != kUnset) width = n.style.width;
93
- else if (n.style.width_percent != kUnset && n.layout.width > 0) width = n.layout.width;
94
- if (n.style.height != kUnset) height = n.style.height;
95
- else if (n.style.height_percent != kUnset && n.layout.height > 0) height = n.layout.height;
96
- n.layout.width = LayoutEngine::instance().clampSize(width, n.style.min_width, n.style.max_width);
97
- n.layout.height = LayoutEngine::instance().clampSize(height, n.style.min_height, n.style.max_height);
90
+ int width = TextRenderer::measureWidth(content, n.style.font_id, n.style.font_size, n.style.text_transform) + boxInset(n.style, 1) + boxInset(n.style, 3);
91
+ int height = TextRenderer::measureHeight(measureText, n.style.font_id, n.style.font_size, n.style.text_transform, n.style.line_height) + boxInset(n.style, 0) + boxInset(n.style, 2);
92
+
93
+ if (n.style.width != kUnset) width = contentSizeToBorderSize(n.style, n.style.width, true);
94
+ else if ((n.style.width_percent != kUnset || n.style.width_expression >= 0) && n.layout.width > 0) width = n.layout.width;
95
+ if (n.style.height != kUnset) height = contentSizeToBorderSize(n.style, n.style.height, false);
96
+ else if ((n.style.height_percent != kUnset || n.style.height_expression >= 0) && n.layout.height > 0) height = n.layout.height;
97
+ n.layout.width = clampBorderBoxSize(n.style, width, true);
98
+ n.layout.height = clampBorderBoxSize(n.style, height, false);
99
+ #if GEA_CSS_SCROLLING
98
100
  n.layout.scroll_content_height = n.layout.height;
99
101
  n.layout.scroll_y = 0;
102
+ #endif
100
103
  }
101
104
 
102
105
  void InputRenderer::record(int id)
103
106
  {
107
+ if (!GEA_UI_INPUT_NODES) return;
104
108
  auto &tree = Tree::instance();
105
109
  if (id < 0 || id >= tree.nodeCount()) return;
106
110
  const Node &n = tree.node(id);
@@ -114,10 +118,10 @@ void InputRenderer::record(int id)
114
118
  const int y = n.layout.y;
115
119
  const int w = n.layout.width;
116
120
  const int h = n.layout.height;
117
- const int padLeft = n.style.padding[3];
118
- const int padRight = n.style.padding[1];
119
- const int padTop = n.style.padding[0];
120
- const int padBottom = n.style.padding[2];
121
+ const int padLeft = boxInset(n.style, 3);
122
+ const int padRight = boxInset(n.style, 1);
123
+ const int padTop = boxInset(n.style, 0);
124
+ const int padBottom = boxInset(n.style, 2);
121
125
  const int contentX = x + padLeft;
122
126
  const int contentY = y + padTop;
123
127
  int contentW = w - padLeft - padRight;
package/ui/internal.h CHANGED
@@ -4,6 +4,7 @@
4
4
  #include "tree_internal.h"
5
5
 
6
6
  #include <cstdint>
7
+ #include <vector>
7
8
 
8
9
  #ifdef quad
9
10
  #undef quad
@@ -32,6 +33,9 @@ extern bool gScrollImageHoldPending;
32
33
  // blits marks the tree dirty for one normal full refresh (images included).
33
34
  void rootScrollImageHoldTick();
34
35
 
36
+ bool isCollapsedFlexItem(const Node &node);
37
+ bool isCollapsedFlexSubtree(const Node &node);
38
+
35
39
  class CameraSurfaceProvider;
36
40
 
37
41
  // Max children collected per node in one recordNode level. The record scratch
@@ -73,7 +77,11 @@ void rootScrollImageHoldTick();
73
77
  struct DisplayCommand
74
78
  {
75
79
  DisplayCommandType type;
80
+ bool textDecorationInk = false;
76
81
  int16_t bx, by, bw, bh;
82
+ // Background paint can use descendant glyph coverage without changing
83
+ // foreground text color or allocating a viewport-sized mask.
84
+ int16_t textClipOwner = -1;
77
85
  union
78
86
  {
79
87
  struct
@@ -164,6 +172,10 @@ void rootScrollImageHoldTick();
164
172
  int16_t tl, tr, br, bl;
165
173
  int16_t lineWidth;
166
174
  gea::framework::graphics::pixel::native_t color;
175
+ // CSS radii are already normalized on the outer border box. Inner
176
+ // curves may exceed half the clipped box; do not clamp them again.
177
+ int16_t rx8[4], ry8[4];
178
+ uint8_t cssRadii;
167
179
  } strokeRoundedRect;
168
180
  struct
169
181
  {
@@ -198,6 +210,7 @@ void rootScrollImageHoldTick();
198
210
  gea::framework::graphics::pixel::native_t color;
199
211
  uint8_t alpha;
200
212
  int8_t textTransform;
213
+ int8_t whiteSpace;
201
214
  // CSS backface-visibility:hidden — drop this projected label when its winding
202
215
  // points away from the viewer, matching its (culled) back-facing parent face.
203
216
  uint8_t backfaceHidden;
@@ -286,6 +299,7 @@ void rootScrollImageHoldTick();
286
299
  static DisplayList &instance();
287
300
 
288
301
  DisplayCommand *append();
302
+ int setRecordingTextClipOwner(int owner);
289
303
  void clear();
290
304
  void resetStorage();
291
305
  // allowSkipStatic: caller guarantees this frame will use the direct
@@ -392,6 +406,7 @@ void rootScrollImageHoldTick();
392
406
  bool reprojectDirtyRect(int *x0, int *y0, int *x1, int *y1) const;
393
407
  void filterBlurCacheStats(int *hits, int *misses) const;
394
408
  int commandCount() const;
409
+ bool hasTextClippedBackgrounds() const;
395
410
  int nodeCommandCount(int node) const;
396
411
  const DisplayCommand *nodeCommandAt(int node, int index) const;
397
412
  bool nodeCommandBounds(int node, int *x0, int *y0, int *x1, int *y1) const;
@@ -402,6 +417,13 @@ void rootScrollImageHoldTick();
402
417
  {
403
418
  public:
404
419
  static LayoutEngine &instance();
420
+ static int alignedAbsoluteOffset(const Node &parent, const Node &child, bool horizontal,
421
+ const Node *containing = nullptr, int containingStart = 0, int containingSize = 0);
422
+ static int fixedContainingBlock(const Node &node);
423
+ static bool isViewportFixed(const Node &node);
424
+ static bool containsViewportFixed(int node);
425
+ static bool absoluteGridArea(const Node &parent, const Node &child, int &x, int &y, int &width, int &height);
426
+ static void absoluteContainingArea(const Node &parent, const Node &child, int &x, int &y, int &width, int &height);
405
427
 
406
428
  int clampSize(int size, int minSize, int maxSize) const;
407
429
  int collectChildren(int parent, int *out, int max, bool skipAbsolute) const;
@@ -409,7 +431,7 @@ void rootScrollImageHoldTick();
409
431
  // (LayoutBox::memo_pass). Must be called before each root layoutNode()
410
432
  // so memo hits never leak across passes/frames.
411
433
  void beginLayoutPass();
412
- void layoutNode(int id, int availableWidth, int availableHeight);
434
+ void layoutNode(int id, int availableWidth, int availableHeight, bool intrinsicBoxEdges = false);
413
435
  // Scoped relayout: re-lays ONLY `scope`'s subtree using the available box
414
436
  // remembered from its last layout, then resolves the subtree's absolute
415
437
  // coords from the scope's (unchanged) position. Returns false — caller
@@ -426,6 +448,21 @@ void rootScrollImageHoldTick();
426
448
  // resolveRowDirection). Exposed for refresh fast paths that mirror that
427
449
  // flow decision without running a layout pass.
428
450
  static bool isInlineLevelNode(const Node &n);
451
+ // CSS display classification without layout-only margin heuristics.
452
+ // Inline-level boxes blockified by float, absolute/fixed positioning, or
453
+ // flex/grid-item status return false.
454
+ static bool isCssInlineLevelBox(const Node &n, bool hypothetical = false);
455
+ };
456
+
457
+ // Shared order for recording, retained transform replay, and hit testing.
458
+ class PaintOrder
459
+ {
460
+ public:
461
+ static void sortChildren(int *children, int count, int contextRoot);
462
+ static int compareNodes(int first, int second);
463
+ static bool isContext(int node);
464
+ static bool isGroup(int node);
465
+ static std::vector<int> collectChildren(int node, bool groupRoot = true, bool includePositioned = true);
429
466
  };
430
467
 
431
468
  class ViewRenderer
@@ -434,6 +471,7 @@ void rootScrollImageHoldTick();
434
471
  static bool recordClipBegin(const Node &node);
435
472
  static void recordClipEnd(const Node &node);
436
473
  static void recordBox(const Node &node, uint8_t parentAlpha = 255);
474
+ static int canvasBackgroundSource();
437
475
  static void recordScrollbar(const Node &node);
438
476
  static int scrollMaxX(const Node &node);
439
477
  static int scrollMaxY(const Node &node);
@@ -442,6 +480,8 @@ void rootScrollImageHoldTick();
442
480
  static void transformedCorners(const Node &node, bool usePrevious, int16_t *xs, int16_t *ys);
443
481
  static void transformedRectCorners(const Node &node, bool usePrevious, int x, int y, int w, int h, int16_t *xs, int16_t *ys,
444
482
  int16_t *xs8 = nullptr, int16_t *ys8 = nullptr);
483
+ static bool backfaceSubtreeHidden(const Node &node);
484
+ static bool isTransformableBox(const Node &node);
445
485
  static int transformedDepth(const Node &node, bool usePrevious);
446
486
  // True iff any node in the tree carries a transform/perspective this frame
447
487
  // or last (cached once per refresh). Lets paint-order sorting skip the 3D
@@ -456,6 +496,7 @@ void rootScrollImageHoldTick();
456
496
  struct InlineFlowMeasure {
457
497
  int lineCount = 0;
458
498
  int firstLineWidth = 0;
499
+ int firstLineTrailingSpace = 0;
459
500
  int lastLineWidth = 0;
460
501
  int maxLineWidth = 0;
461
502
  int lineAdvance = 0;
@@ -465,16 +506,17 @@ void rootScrollImageHoldTick();
465
506
  // identically to deleting them — and keeps the run a single unmodified
466
507
  // string for the display list.
467
508
  int firstLineIndentAdjust = 0;
468
- // True when the first line could only be filled by cutting a word open —
469
- // the run does not fit the space left on the line box it was offered, so an
470
- // inline formatting context starts it on the next one instead.
471
- bool firstLineForcedSplit = false;
509
+
472
510
  };
473
511
 
474
512
  class TextRenderer
475
513
  {
476
514
  public:
515
+ // Shared preparation for measuring and replaying authored text. Storage
516
+ // owns the result only when collapsing or case transformation is needed.
517
+ static const char *prepareText(const char *text, int textTransform, int whiteSpace, std::string &storage);
477
518
  static void layout(int id, int availableWidth);
519
+ static int baselineOffset(const Node &node, bool last);
478
520
  // True when a run's line breaking is reproducible from per-glyph advances,
479
521
  // i.e. the same wrapper the draw path uses. A host that measures whole
480
522
  // strings for us (CoreText on Apple targets) does its own breaking, which
@@ -487,12 +529,16 @@ void rootScrollImageHoldTick();
487
529
  // `atLineStart`, as CSS does when a line box begins.
488
530
  static InlineFlowMeasure measureInlineFlow(const Node &node, int firstAvail, int contentWidth, bool atLineStart);
489
531
  static void record(const Node &node, uint8_t parentAlpha = 255);
532
+ static void unionCoverageRow(const DisplayCommand &command, int screenY, int screenX,
533
+ int width, uint8_t *outCoverage);
490
534
  static void drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign,
491
535
  int containerWidth, int fontId, int textTransform = 0, int lineHeight = 0, int whiteSpace = 0, int textOverflow = 0, int maxHeight = 0,
492
536
  int firstLineIndent = 0);
493
537
  // Single-line width measure for places that don't go through layout()
494
538
  // — used by InputRenderer to position the caret at the end of the value.
495
539
  static int measureWidth(const char *text, int fontId, int fontSize, int textTransform = 0);
540
+ static int firstUnbreakableWidth(const Node &node);
541
+ static int minContentWidth(const Node &node, int *pendingWord = nullptr);
496
542
  static int measureHeight(const char *text, int fontId, int fontSize, int textTransform = 0, int lineHeight = 0);
497
543
  // In-place box re-measure for a rebound text node on refresh paths that
498
544
  // skip the layout pass (root-scroll fast path): record() wraps and clips