@geastack/engine 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/document.h CHANGED
@@ -2,6 +2,10 @@
2
2
  #pragma once
3
3
 
4
4
  #include "events.h"
5
+ #include "event_listener_options.h"
6
+ #include "tree_events.h"
7
+ #include <type_traits>
8
+ #include <cstdlib>
5
9
  #include "image.h"
6
10
  #include "canvas_element.h"
7
11
  #include "camera_element.h"
@@ -12,6 +16,8 @@
12
16
  #include <string>
13
17
  #include <vector>
14
18
 
19
+ namespace gea { template <typename Signature> struct CallableObject; }
20
+
15
21
  namespace gea::embedded::ui {
16
22
 
17
23
  class Document {
@@ -19,6 +25,8 @@ public:
19
25
  static Document &instance();
20
26
 
21
27
  ViewElement body() const;
28
+ // No guessed body fallback: null handle when no actual connected focus.
29
+ NodeHandle activeElement() const;
22
30
  ViewElement createView() const;
23
31
  ViewElement createButton() const;
24
32
  TextElement createText(const char *text = "") const;
@@ -35,10 +43,9 @@ public:
35
43
  int mountedCanvasNode() const;
36
44
  CameraElement createCamera() const;
37
45
  NodeHandle createAudio() const;
38
- // A DocumentFragment for the compiled-component runtime (batched list /
39
- // conditional children). The embedded tree has no fragment node kind, so this
40
- // returns a detached container node -- children append to it and it is then
41
- // appended to the real parent. Not a dissolving fragment, but functional.
46
+ NodeHandle createComment(const char *text = "") const;
47
+ NodeHandle createComment(const std::string &text) const { return createComment(text.c_str()); }
48
+ // A detached structural owner whose children move into an insertion parent.
42
49
  NodeHandle createDocumentFragment() const;
43
50
  ViewElement createVirtualList() const;
44
51
  // Generic tag-string factory (the DOM document.createElement shape): maps
@@ -60,9 +67,9 @@ public:
60
67
  // adapt it.
61
68
  NodeHandle getElementById(const std::string &id) const { return getElementById(id.c_str()); }
62
69
  NodeHandle querySelector(const char *selector) const;
63
- NodeHandle querySelector(const std::string &selector) const { return querySelector(selector.c_str()); }
70
+ NodeHandle querySelector(const std::string &selector) const { return querySelector(NodeHandle::selectorText(selector)); }
64
71
  std::vector<NodeHandle> querySelectorAll(const char *selector) const;
65
- std::vector<NodeHandle> querySelectorAll(const std::string &selector) const { return querySelectorAll(selector.c_str()); }
72
+ std::vector<NodeHandle> querySelectorAll(const std::string &selector) const { return querySelectorAll(NodeHandle::selectorText(selector)); }
66
73
  ViewElement ensureAppRoot(const char *id = "app") const;
67
74
 
68
75
  // Platforms set this before Application::init to control the size of
@@ -81,6 +88,54 @@ public:
81
88
  void refreshMountedIfDirty() const;
82
89
  void frame(int timestampMs) const;
83
90
  void addEventListener(const char *type, gea::framework::events::EventListener listener) const;
91
+ // Exact typed literal overload prevents a cross-conversion ambiguity with
92
+ // the legacy const-char*/std::function C++ entry point.
93
+ template <typename Handler> requires requires(const Handler &handler) { handler.functionObjectIdentity(); }
94
+ void addEventListener(const char *type, const Handler &handler, bool capture=false, bool once=false) const {
95
+ addEventListener(std::string(type?type:""),handler,capture,once);
96
+ }
97
+ template <typename Result, typename Argument>
98
+ void addEventListener(const std::string &type,
99
+ const gea::CallableObject<Result(Argument)> &handler,
100
+ bool capture = false, bool once = false) const {
101
+ if (documentEventListenersRetiring()) return;
102
+ static_assert(std::is_constructible_v<std::decay_t<Argument>,
103
+ const gea::framework::events::PointerEvent &>,
104
+ "native document listener needs an installed event carrier");
105
+ const auto held = handler;
106
+ if (!addDocumentEventListener(type.c_str(), handler.functionObjectIdentity().get(),
107
+ gea::framework::events::explicitEventCallback([](auto& held, gea::framework::events::PointerEvent &event) {
108
+ held.call(static_cast<std::decay_t<Argument>>(event));
109
+ }, held), capture, once)) std::abort();
110
+ }
111
+ template <typename Result>
112
+ void addEventListener(const std::string &type,
113
+ const gea::CallableObject<Result()> &handler,
114
+ bool capture = false, bool once = false) const {
115
+ if (documentEventListenersRetiring()) return;
116
+ const auto held = handler;
117
+ if (!addDocumentEventListener(type.c_str(), handler.functionObjectIdentity().get(),
118
+ gea::framework::events::explicitEventCallback([](auto& held, gea::framework::events::PointerEvent &) { held.call(); }, held), capture, once)) std::abort();
119
+ }
120
+ template <typename Handler>
121
+ void removeEventListener(const std::string &type, const Handler &handler,
122
+ bool capture = false) const {
123
+ removeDocumentEventListener(type.c_str(), handler.functionObjectIdentity().get(), capture);
124
+ }
125
+
126
+ template <typename Handler, typename Options>
127
+ requires (!std::is_same_v<std::decay_t<Options>,bool>)
128
+ void addEventListener(const std::string &type, const Handler &handler, const Options &options) const {
129
+ const auto parsed=gea::framework::events::listenerOptions(options);
130
+ addEventListener(type,handler,parsed.capture,parsed.once);
131
+ }
132
+ template <typename Handler, typename Options>
133
+ requires (!std::is_same_v<std::decay_t<Options>,bool>)
134
+ void removeEventListener(const std::string &type, const Handler &handler, const Options &options) const {
135
+ const auto parsed=gea::framework::events::listenerOptions(options);
136
+ removeEventListener(type,handler,parsed.capture);
137
+ }
138
+
84
139
 
85
140
  private:
86
141
  Document() = default;
package/ui/input.cpp CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  #include "pixel.h"
5
5
  #include "tree_state.h"
6
+ #include "control_commit.h"
7
+ #include "input_retirement.h"
6
8
 
7
9
  #include "services/frame_scheduler.h"
8
10
 
@@ -105,6 +107,7 @@ public:
105
107
  carryOverAxis_ = momentumAxis_;
106
108
  cancelMomentum();
107
109
  activeScrollNode_ = tree.nodeCount() == 0 ? -1 : findScrollNodeId(0, x, y);
110
+ activeScrollOwner_=NodeHandle(activeScrollNode_);
108
111
  snapAccumDy_ = 0;
109
112
  activeScrollAxis_ = ScrollAxis::None;
110
113
  scrollLastX_ = x;
@@ -127,7 +130,7 @@ public:
127
130
  // A `touch-action="none"` element (e.g. a horizontal drag slider) owns the
128
131
  // gesture: don't let an ancestor scroll container steal it.
129
132
  if (activeScrollNode_ >= 0 && nodeChainDisablesScroll(nodeId)) {
130
- activeScrollNode_ = -1;
133
+ activeScrollNode_ = -1;activeScrollOwner_={};
131
134
  }
132
135
  // Hit-routing audit (camera-studio tap-misrouting investigation): the
133
136
  // resolved node, its tag, and its layout box for every pointer down.
@@ -148,7 +151,7 @@ public:
148
151
  }
149
152
 
150
153
  Node &node = tree.nodes()[activeNodeId];
151
- activeTouchNode_ = activeNodeId;
154
+ activeTouchNode_ = activeNodeId;activeTouchOwner_=NodeHandle(activeNodeId);
152
155
  savedBackgroundColor_ = node.computedStyle().bg_color;
153
156
  savedHasBackground_ = node.computedStyle().has_bg;
154
157
  node.mutableStyle().bg_color = node.mutableStyle().has_active_bg ? node.mutableStyle().active_bg_color : lightenRgb565(node.mutableStyle().bg_color);
@@ -169,7 +172,7 @@ public:
169
172
  int pointerMove(int x, int y)
170
173
  {
171
174
  Tree &tree = Tree::instance();
172
- if (activeScrollNode_ < 0 || activeScrollNode_ >= tree.nodeCount()) {
175
+ if (!activeScrollOwner_.valid() || activeScrollOwner_.id()!=activeScrollNode_) {
173
176
  scrollLastX_ = x;
174
177
  scrollLastY_ = y;
175
178
  return 0;
@@ -243,9 +246,9 @@ public:
243
246
 
244
247
  int pointerUp()
245
248
  {
246
- const int scrollNode = activeScrollNode_;
249
+ const int scrollNode = activeScrollOwner_.valid()?activeScrollNode_:-1;
247
250
  const ScrollAxis scrollAxis = activeScrollAxis_;
248
- activeScrollNode_ = -1;
251
+ activeScrollNode_ = -1;activeScrollOwner_={};
249
252
  activeScrollAxis_ = ScrollAxis::None;
250
253
  if (scrollTraceEnabled())
251
254
  std::fprintf(stderr, "[sc.up] t=%d node=%d\n",
@@ -302,7 +305,7 @@ public:
302
305
  const int count = tree.nodeCount();
303
306
  for (int id = 0; id < count; ++id) {
304
307
  Node &node = tree.nodes()[id];
305
- if (node.computedStyle().display == 1) continue; // display:none
308
+ if (isStructuralNodeType(node.type) || node.computedStyle().display == 1) continue;
306
309
  if (!nodeCanScrollY(id, node)) continue;
307
310
  const int cur = scrollTop(id);
308
311
  int next = cur + dy;
@@ -324,12 +327,12 @@ public:
324
327
  void reset()
325
328
  {
326
329
  treeState().hoveredNodeId = -1;
327
- activeTouchNode_ = -1;
330
+ activeTouchNode_ = -1;activeTouchOwner_={};hoveredOwner_={};
328
331
  savedBackgroundColor_ = 0;
329
332
  savedHasBackground_ = 0;
330
333
  activeBackgroundColor_ = 0;
331
334
  activeHasBackground_ = 0;
332
- activeScrollNode_ = -1;
335
+ activeScrollNode_ = -1;activeScrollOwner_={};
333
336
  activeScrollAxis_ = ScrollAxis::None;
334
337
  snapAccumDy_ = 0;
335
338
  scrollLastX_ = 0;
@@ -340,11 +343,28 @@ public:
340
343
  carryOverAxis_ = ScrollAxis::None;
341
344
  }
342
345
 
346
+ void cancelActiveGesture()
347
+ {
348
+ clearActiveTouch();
349
+ activeScrollNode_=-1;activeScrollOwner_={};activeScrollAxis_=ScrollAxis::None;snapAccumDy_=0;
350
+ resetVelocitySamples();carryOverVelocity_=0;carryOverAxis_=ScrollAxis::None;
351
+ }
352
+ void retireSubtrees(const InputRetirementRoots &removed,const InputRetirementRoots &retained)
353
+ {
354
+ auto leaving=[&](const NodeHandle &owner){return inputOwnerLeaving(owner,removed,retained);};
355
+ if(leaving(activeTouchOwner_) || leaving(activeScrollOwner_)) cancelActiveGesture();
356
+ if(leaving(momentumOwner_)) cancelMomentum();
357
+ if(leaving(hoveredOwner_)){treeState().hoveredNodeId=-1;hoveredOwner_={};StyleSheet::instance().hoverChanged();}
358
+ }
359
+
360
+ void setHoveredOwner(int node){hoveredOwner_=NodeHandle(node);}
361
+ int hoveredId()const{return hoveredOwner_.valid()&&hoveredOwner_.id()==treeState().hoveredNodeId?hoveredOwner_.id():-1;}
362
+
343
363
  void tick(int timestampMs)
344
364
  {
345
365
  if (momentumNode_ < 0) return;
346
366
  Tree &tree = Tree::instance();
347
- if (momentumNode_ >= tree.nodeCount()) {
367
+ if (!momentumOwner_.valid() || momentumOwner_.id()!=momentumNode_) {
348
368
  cancelMomentum();
349
369
  return;
350
370
  }
@@ -464,7 +484,7 @@ private:
464
484
  int hitTestNodeId(int id, int x, int y, bool clipped = false, bool groupRoot = true, bool includePositioned = true)
465
485
  {
466
486
  Node &node = Tree::instance().nodes()[id];
467
- if (node.computedStyle().display == 1 || isCollapsedFlexSubtree(node)) return -1;
487
+ if (isStructuralNodeType(node.type) || node.computedStyle().display == 1 || isCollapsedFlexSubtree(node)) return -1;
468
488
  // CSS `pointer-events: none` — this node and its subtree are never the
469
489
  // target of a pointer event, so the hit-test falls through to whatever is
470
490
  // painted behind it. Without this, a decorative overlay image positioned
@@ -503,7 +523,7 @@ private:
503
523
  int findScrollNodeId(int id, int x, int y, bool clipped = false, bool groupRoot = true, bool includePositioned = true)
504
524
  {
505
525
  Node &node = Tree::instance().nodes()[id];
506
- if (node.computedStyle().display == 1 || isCollapsedFlexSubtree(node)) return -1;
526
+ if (isStructuralNodeType(node.type) || node.computedStyle().display == 1 || isCollapsedFlexSubtree(node)) return -1;
507
527
 
508
528
  const bool inside = pointInsideNodeHitArea(node, x, y);
509
529
  if (LayoutEngine::isViewportFixed(node)) clipped = false;
@@ -672,6 +692,7 @@ private:
672
692
  bool clearActiveTouch()
673
693
  {
674
694
  if (activeTouchNode_ < 0) return false;
695
+ if(!activeTouchOwner_.valid()||activeTouchOwner_.id()!=activeTouchNode_){activeTouchNode_=-1;activeTouchOwner_={};return false;}
675
696
 
676
697
  Node &node = Tree::instance().node(activeTouchNode_);
677
698
  const bool ownsActiveBackground =
@@ -686,7 +707,7 @@ private:
686
707
  #endif
687
708
  Tree::instance().markNodeDisplayCommandsDirty(activeTouchNode_);
688
709
  }
689
- activeTouchNode_ = -1;
710
+ activeTouchNode_ = -1;activeTouchOwner_={};
690
711
  activeBackgroundColor_ = 0;
691
712
  activeHasBackground_ = 0;
692
713
  return ownsActiveBackground;
@@ -797,7 +818,7 @@ private:
797
818
  if (velocityPxPerMs > kMaxMomentumVelocity) velocityPxPerMs = kMaxMomentumVelocity;
798
819
  else if (velocityPxPerMs < -kMaxMomentumVelocity) velocityPxPerMs = -kMaxMomentumVelocity;
799
820
 
800
- momentumNode_ = scrollNode;
821
+ momentumNode_ = scrollNode;momentumOwner_=NodeHandle(scrollNode);
801
822
  momentumAxis_ = axis;
802
823
  momentumVelocity_ = velocityPxPerMs;
803
824
  momentumLastTickMs_ = nowMs;
@@ -810,7 +831,7 @@ private:
810
831
 
811
832
  void cancelMomentum()
812
833
  {
813
- momentumNode_ = -1;
834
+ momentumNode_ = -1;momentumOwner_={};
814
835
  momentumAxis_ = ScrollAxis::None;
815
836
  momentumVelocity_ = 0.0f;
816
837
  momentumScrollAccum_ = 0.0f;
@@ -830,6 +851,7 @@ private:
830
851
  static constexpr float kMomentumDecayMs = GEA_SCROLL_MOMENTUM_DECAY_MS;
831
852
  static constexpr float kStopVelocity = GEA_SCROLL_MOMENTUM_STOP_VELOCITY; // px/ms
832
853
 
854
+ NodeHandle activeTouchOwner_,activeScrollOwner_,momentumOwner_,hoveredOwner_;
833
855
  int activeTouchNode_ = -1;
834
856
  std::uint16_t savedBackgroundColor_ = 0;
835
857
  std::int8_t savedHasBackground_ = 0;
@@ -874,8 +896,8 @@ int Tree::pointerHover(int x, int y)
874
896
  {
875
897
  auto &state = treeState();
876
898
  const int target = x < 0 || y < 0 ? -1 : hitTestNode(x, y);
877
- if (target != state.hoveredNodeId) {
878
- state.hoveredNodeId = target;
899
+ if (target != state.hoveredNodeId || target != InputController::instance().hoveredId()) {
900
+ state.hoveredNodeId = target;InputController::instance().setHoveredOwner(target);
879
901
  StyleSheet::instance().hoverChanged();
880
902
  }
881
903
  return target;
@@ -884,11 +906,15 @@ int Tree::pointerHover(int x, int y)
884
906
  bool Tree::isHovered(int node) const
885
907
  {
886
908
  const auto &state = treeState();
887
- const int target = state.hoveredNodeId;
909
+ const int target = InputController::instance().hoveredId();
888
910
  return target >= 0 && target < state.nodeCount && state.nodeActive[target] &&
889
911
  containsNode(mountedRoot(), target) && containsNode(node, target);
890
912
  }
891
913
 
914
+ void retirePointerInputForSubtrees(const InputRetirementRoots &removed,const InputRetirementRoots &retained)
915
+ {InputController::instance().retireSubtrees(removed,retained);}
916
+ void cancelPrimaryPointerInput(){InputController::instance().cancelActiveGesture();}
917
+
892
918
  void Tree::pointerDown(int x, int y)
893
919
  {
894
920
  InputController::instance().pointerDown(x, y);
@@ -919,9 +945,25 @@ void Tree::resetInput()
919
945
  InputController::instance().reset();
920
946
  }
921
947
 
948
+ #if GEA_UI_INPUT_NODES
949
+ namespace { ControlCommit activeInputCommit; }
950
+ bool Tree::activeInputAdmitted() const {return activeInputCommit.admitted(activeInputId());}
951
+ void Tree::markActiveInputEdited(){activeInputCommit.edited(activeInputId());}
952
+ void Tree::commitActiveInput(){activeInputCommit.commit();}
953
+ #else
954
+ bool Tree::activeInputAdmitted() const{return false;}
955
+ void Tree::markActiveInputEdited(){}
956
+ void Tree::commitActiveInput(){}
957
+ #endif
958
+
922
959
  int Tree::activeInputId() const
923
960
  {
924
- return treeState().activeInputId;
961
+ #if GEA_UI_INPUT_NODES
962
+ const int id=treeState().activeInputId;
963
+ return activeInputCommit.owns(id)?id:-1;
964
+ #else
965
+ return -1;
966
+ #endif
925
967
  }
926
968
 
927
969
  void Tree::setActiveInput(int nodeId)
@@ -929,8 +971,11 @@ void Tree::setActiveInput(int nodeId)
929
971
  #if GEA_UI_INPUT_NODES
930
972
  auto &state = treeState();
931
973
  if (nodeId < -1 || nodeId >= state.nodeCount) nodeId = -1;
932
- if (state.activeInputId == nodeId) return;
933
- const int previousId = state.activeInputId;
974
+ if (state.activeInputId == nodeId && (nodeId<0 || activeInputCommit.admitted(nodeId))) return;
975
+ const int previousId = activeInputId();
976
+ const NodeHandle previousOwner(previousId),nextOwner(nodeId);
977
+ auto previousCommit = activeInputCommit;
978
+ activeInputCommit.begin(nodeId);
934
979
  state.activeInputId = nodeId;
935
980
  state.caretVisible = true;
936
981
  state.caretLastFlipMs = state.lastFrameMs;
@@ -959,6 +1004,13 @@ void Tree::setActiveInput(int nodeId)
959
1004
  // `displayListDirty`; the keyboard subsystem decides activity in
960
1005
  // notifyActiveInputChanged.
961
1006
  state.displayListDirty = true;
1007
+ // All state writes precede reentrant user callbacks.
1008
+ previousCommit.commit();
1009
+ // Capture allocation owners, never reconstruct authority after callbacks.
1010
+ auto stillCurrent=[&](){return nodeId<0?activeInputId()<0:(nextOwner.valid()&&activeInputId()==nextOwner.id());};
1011
+ auto emitFocus=[&](const NodeHandle&owner,gea::framework::events::PointerEventType type){if(!owner.valid())return;gea::framework::events::PointerEvent event{};event.type=type;event.targetId=owner.id();event.cancelable=false;dispatchEvent(event);};
1012
+ if(stillCurrent()&&previousOwner.valid())emitFocus(previousOwner,gea::framework::events::PointerEventType::FocusOut);
1013
+ if(stillCurrent()&&nextOwner.valid())emitFocus(nextOwner,gea::framework::events::PointerEventType::FocusIn);
962
1014
  #endif
963
1015
  }
964
1016
 
@@ -0,0 +1,22 @@
1
+ // Process UI-owner-thread input retirement before a topology commit.
2
+ #pragma once
3
+ #include "node.h"
4
+ #include "tree_internal.h"
5
+ #include <vector>
6
+ namespace gea::embedded::ui {
7
+ using InputRetirementRoots = std::vector<NodeHandle>;
8
+ inline bool inputOwnerLeaving(const NodeHandle &owner,const InputRetirementRoots &removed,const InputRetirementRoots &retained) {
9
+ if(!owner.valid()) return false;
10
+ auto &tree=Tree::instance();
11
+ bool leaving=false;
12
+ for(const auto &root:removed) if(root.valid()&&tree.containsNode(root.id(),owner.id())) {leaving=true;break;}
13
+ if(!leaving)return false;
14
+ for(const auto &root:retained) if(root.valid()&&tree.containsNode(root.id(),owner.id())) return false;
15
+ return true;
16
+ }
17
+ void retirePointerInputForSubtrees(const InputRetirementRoots &,const InputRetirementRoots &);
18
+ void cancelPrimaryPointerInput();
19
+ void retireTouchInputForSubtrees(const InputRetirementRoots &,const InputRetirementRoots &);
20
+ // Weak Core default; actual native platform providers must override this.
21
+ void retirePlatformInputForSubtrees(const InputRetirementRoots &,const InputRetirementRoots &);
22
+ }
package/ui/internal.h CHANGED
@@ -191,6 +191,7 @@ void rootScrollImageHoldTick();
191
191
  int16_t lineHeight;
192
192
  int16_t containerWidth;
193
193
  int16_t fontId;
194
+ int16_t fontWeight,fontStretch;
194
195
  // CSS white-space / text-overflow, carried so the deferred draw
195
196
  // can reproduce single-line truncation. whiteSpace==1 => nowrap
196
197
  // (no width-based wrapping); textOverflow==1 => ellipsis ("...").
@@ -210,6 +211,7 @@ void rootScrollImageHoldTick();
210
211
  int16_t srcX, srcY, srcW, srcH;
211
212
  int16_t x0, y0, x1, y1, x2, y2, x3, y3;
212
213
  int16_t fontId, fontSize;
214
+ int16_t fontWeight,fontStretch;
213
215
  gea::framework::graphics::pixel::native_t color;
214
216
  uint8_t alpha;
215
217
  int8_t textTransform;
@@ -570,7 +572,7 @@ void rootScrollImageHoldTick();
570
572
  int width, uint8_t *outCoverage);
571
573
  static void drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign,
572
574
  int containerWidth, int fontId, int textTransform = 0, int lineHeight = 0, int whiteSpace = 0, int textOverflow = 0, int maxHeight = 0,
573
- int firstLineIndent = 0);
575
+ int firstLineIndent = 0, int fontWeight = 400, int fontStretch = 1000);
574
576
  // Single-line width measure for places that don't go through layout()
575
577
  // — used by InputRenderer to position the caret at the end of the value.
576
578
  static int measureWidth(const char *text, int fontId, int fontSize, int textTransform = 0);
package/ui/layout.cpp CHANGED
@@ -121,7 +121,7 @@ bool suppressAnonymousWhitespace(const Node *nodes, int parent, int child)
121
121
  // Whitespace at a line boundary or between block boxes creates no line.
122
122
  // Preserve the text node itself and spaces between inline siblings.
123
123
  auto adjacentInline = [&](int sibling, bool forward) {
124
- while (sibling >= 0 && (isDisplayNone(nodes[sibling].computedStyle()) || isOutOfFlowPosition(nodes[sibling].computedStyle().position) ||
124
+ while (sibling >= 0 && (isLayoutExcluded(nodes[sibling]) || isOutOfFlowPosition(nodes[sibling].computedStyle().position) ||
125
125
  (isAnonymousTextNode(nodes[sibling]) && (nodes[sibling].computedStyle().white_space == 0 || nodes[sibling].computedStyle().white_space == 1) &&
126
126
  nodes[sibling].text.find_first_not_of(" \t\r\n\f") == std::string::npos)))
127
127
  sibling = forward ? nodes[sibling].next_sibling : nodes[sibling].prev_sibling;
@@ -139,7 +139,7 @@ bool startsFormattingLine(const Node *nodes, int id)
139
139
  while (LayoutEngine::isCssInlineLevelBox(nodes[id]) && LayoutEngine::isInlineLevelNode(nodes[id])) {
140
140
  for (int sibling = nodes[id].prev_sibling; sibling >= 0; sibling = nodes[sibling].prev_sibling) {
141
141
  const Node &previous = nodes[sibling];
142
- if (isDisplayNone(previous.computedStyle()) || isOutOfFlowPosition(previous.computedStyle().position) || previous.computedStyle().float_side)
142
+ if (isLayoutExcluded(previous) || isOutOfFlowPosition(previous.computedStyle().position) || previous.computedStyle().float_side)
143
143
  continue;
144
144
  if (isAnonymousTextNode(previous) &&
145
145
  (previous.computedStyle().white_space == 0 || previous.computedStyle().white_space == 1 || previous.computedStyle().white_space == 4) &&
@@ -788,7 +788,7 @@ public:
788
788
  bool firstInFlow = true;
789
789
  for (int sibling = nodes[parent].first_child; sibling >= 0 && sibling != ancestor;
790
790
  sibling = nodes[sibling].next_sibling) {
791
- if (!isDisplayNone(nodes[sibling].computedStyle()) &&
791
+ if (!isLayoutExcluded(nodes[sibling]) &&
792
792
  !isOutOfFlowPosition(nodes[sibling].computedStyle().position) &&
793
793
  !nodes[sibling].computedStyle().float_side &&
794
794
  !suppressAnonymousWhitespace(nodes, parent, sibling)) {
@@ -815,7 +815,7 @@ public:
815
815
  std::vector<std::pair<int, int>> staticBoundaries;
816
816
  int flowIndex = 0;
817
817
  for (int child = node_.first_child; child >= 0; child = nodes[child].next_sibling) {
818
- if (isDisplayNone(nodes[child].computedStyle()) || suppressAnonymousWhitespace(nodes, parentId, child)) continue;
818
+ if (isLayoutExcluded(nodes[child]) || suppressAnonymousWhitespace(nodes, parentId, child)) continue;
819
819
  if (isOutOfFlowPosition(nodes[child].computedStyle().position)) {
820
820
  if (auto *rare = rareDataFor(child)) rare->inlineStaticPosition.valid = false;
821
821
  if (LayoutEngine::isCssInlineLevelBox(nodes[child], true))
@@ -1196,7 +1196,7 @@ public:
1196
1196
  int run = -1;
1197
1197
  for (int c = wrapper.first_child; c >= 0; c = nodes[c].next_sibling) {
1198
1198
  const Node &child = nodes[c];
1199
- if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
1199
+ if (isLayoutExcluded(child) || isOutOfFlowPosition(child.computedStyle().position)) continue;
1200
1200
  if (run >= 0) return -1; // more than one in-flow child
1201
1201
  if (child.type != NodeType::Text) return -1;
1202
1202
  if (child.computedStyle().margin[0] || child.computedStyle().margin[1] || child.computedStyle().margin[2] ||
@@ -1768,7 +1768,7 @@ private:
1768
1768
  int extent = 0;
1769
1769
  for (int c = childNode.first_child; c >= 0; c = nodes[c].next_sibling) {
1770
1770
  const Node &grand = nodes[c];
1771
- if (isDisplayNone(grand.computedStyle()) || isOutOfFlowPosition(grand.computedStyle().position)) continue;
1771
+ if (isLayoutExcluded(grand) || isOutOfFlowPosition(grand.computedStyle().position)) continue;
1772
1772
  // layout.{x,y} are still parent-relative here: resolveAbsoluteCoords runs
1773
1773
  // after the whole layout pass.
1774
1774
  const int end = isRow_
@@ -2056,7 +2056,7 @@ private:
2056
2056
  const Node *nodes = Tree::instance().nodes();
2057
2057
  for (int c = last ? childNode.last_child : childNode.first_child; c >= 0; c = last ? nodes[c].prev_sibling : nodes[c].next_sibling) {
2058
2058
  const Node &inner = nodes[c];
2059
- if (isDisplayNone(inner.computedStyle()) || isOutOfFlowPosition(inner.computedStyle().position)) continue;
2059
+ if (isLayoutExcluded(inner) || isOutOfFlowPosition(inner.computedStyle().position)) continue;
2060
2060
  return inner.layout.y + childBaseline(inner, last);
2061
2061
  }
2062
2062
  }
@@ -2132,7 +2132,7 @@ bool splitInlineWrapper(const Node *nodes, int id)
2132
2132
  bool containsBlock = false;
2133
2133
  for (int c = n.first_child; c >= 0; c = nodes[c].next_sibling) {
2134
2134
  const Node &child = nodes[c];
2135
- if (isDisplayNone(child.computedStyle())) continue;
2135
+ if (isLayoutExcluded(child)) continue;
2136
2136
  if (isOutOfFlowPosition(child.computedStyle().position)) return false;
2137
2137
  if (child.computedStyle().float_side) continue;
2138
2138
  if (child.type == NodeType::View && (child.computedStyle().display_explicit || !isInlineLevelTag(tagFromId(child.tag_id)))) containsBlock = true;
@@ -2146,7 +2146,7 @@ int formattingEdgeNode(const Node *nodes, int id, bool last)
2146
2146
  if (!splitInlineWrapper(nodes, id)) return id;
2147
2147
  for (int c = last ? nodes[id].last_child : nodes[id].first_child; c >= 0; c = last ? nodes[c].prev_sibling : nodes[c].next_sibling) {
2148
2148
  const Node &child = nodes[c];
2149
- if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position) || child.computedStyle().float_side) continue;
2149
+ if (isLayoutExcluded(child) || isOutOfFlowPosition(child.computedStyle().position) || child.computedStyle().float_side) continue;
2150
2150
  if (isAnonymousTextNode(child) && (child.computedStyle().white_space == 0 || child.computedStyle().white_space == 1) &&
2151
2151
  child.text.find_first_not_of(" \t\r\n\f") == std::string::npos) continue;
2152
2152
  return formattingEdgeNode(nodes, c, last);
@@ -2177,7 +2177,7 @@ public:
2177
2177
  #if GEA_CSS_FIRST_LINE
2178
2178
  if (NodeRareData *rare = rareDataFor(id_)) rare->firstLineBackground.lineValid = false;
2179
2179
  #endif
2180
- if (isDisplayNone(node_.computedStyle())) return;
2180
+ if (isLayoutExcluded(node_)) return;
2181
2181
  prepareOwnSize();
2182
2182
 
2183
2183
  if (isLineBreak(node_) && LayoutEngine::isInlineLevelNode(node_) &&
@@ -2353,7 +2353,7 @@ private:
2353
2353
  auto collect = [&](auto &&self, int parent) -> void {
2354
2354
  for (int c = nodes_[parent].first_child; c >= 0; c = nodes_[c].next_sibling) {
2355
2355
  Node &child = nodes_[c];
2356
- if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position) || suppressAnonymousWhitespace(nodes_, parent, c)) continue;
2356
+ if (isLayoutExcluded(child) || isOutOfFlowPosition(child.computedStyle().position) || suppressAnonymousWhitespace(nodes_, parent, c)) continue;
2357
2357
  if (splitInlineWrapper(nodes_, c)) {
2358
2358
  splitInlineChildren_ = true;
2359
2359
  child.layout.x = child.layout.y = child.layout.width = child.layout.height = 0;
@@ -2391,13 +2391,13 @@ private:
2391
2391
 
2392
2392
  bool blockBox(const Node &n) const
2393
2393
  {
2394
- return n.type == NodeType::View && !isDisplayNone(n.computedStyle()) &&
2394
+ return n.type == NodeType::View && !isLayoutExcluded(n) &&
2395
2395
  (n.computedStyle().display_explicit || !isInlineLevelTag(tagFromId(n.tag_id)));
2396
2396
  }
2397
2397
 
2398
2398
  bool flowChild(int parent, int child) const
2399
2399
  {
2400
- return !isDisplayNone(nodes_[child].computedStyle()) && !isOutOfFlowPosition(nodes_[child].computedStyle().position) &&
2400
+ return !isLayoutExcluded(nodes_[child]) && !isOutOfFlowPosition(nodes_[child].computedStyle().position) &&
2401
2401
  !nodes_[child].computedStyle().float_side && !suppressAnonymousWhitespace(nodes_, parent, child);
2402
2402
  }
2403
2403
 
@@ -2422,7 +2422,7 @@ private:
2422
2422
  auto visit = [&](auto &&self, int parent, int y) -> void {
2423
2423
  for (int id = nodes_[parent].first_child; id >= 0; id = nodes_[id].next_sibling) {
2424
2424
  const Node &child = nodes_[id];
2425
- if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
2425
+ if (isLayoutExcluded(child) || isOutOfFlowPosition(child.computedStyle().position)) continue;
2426
2426
  int top = y + child.layout.y;
2427
2427
  if (parent != id_ && child.computedStyle().position == 2) {
2428
2428
  LayoutNodePass owner(engine_, parent, 0, 0);
@@ -2644,7 +2644,7 @@ private:
2644
2644
  auto containsFloat = [&](auto &&self, int parent) -> bool {
2645
2645
  for (int c = nodes_[parent].first_child; c >= 0; c = nodes_[c].next_sibling) {
2646
2646
  const Node &child = nodes_[c];
2647
- if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
2647
+ if (isLayoutExcluded(child) || isOutOfFlowPosition(child.computedStyle().position)) continue;
2648
2648
  if (child.computedStyle().float_side || (!establishesBlockContext(child) && self(self, c))) return true;
2649
2649
  }
2650
2650
  return false;
@@ -3366,7 +3366,7 @@ private:
3366
3366
  int contentHeight = node_.layout.height;
3367
3367
  visitFormattingChildren(nodes_, id_, [&](int child) {
3368
3368
  Node &childNode = nodes_[child];
3369
- if (isCollapsedFlexItem(childNode) || isDisplayNone(childNode.computedStyle()) || isOutOfFlowPosition(childNode.computedStyle().position)) return;
3369
+ if (isCollapsedFlexItem(childNode) || isLayoutExcluded(childNode) || isOutOfFlowPosition(childNode.computedStyle().position)) return;
3370
3370
  // A visible axis contributes descendant overflow; a clipping axis
3371
3371
  // traps it at this child's border box independently of the other axis.
3372
3372
  const int width = overflowX(childNode.computedStyle()) == 0 ? std::max<int>(childNode.layout.width, childNode.layout.scroll_content_width) : childNode.layout.width;
@@ -3411,7 +3411,7 @@ private:
3411
3411
  if (node_.type != NodeType::VirtualList) return;
3412
3412
  int rowHeight = 0;
3413
3413
  for (int child = node_.first_child; child >= 0; child = nodes_[child].next_sibling) {
3414
- if (isDisplayNone(nodes_[child].computedStyle())) continue;
3414
+ if (isLayoutExcluded(nodes_[child])) continue;
3415
3415
  rowHeight = nodes_[child].layout.height;
3416
3416
  break;
3417
3417
  }
@@ -3432,7 +3432,7 @@ private:
3432
3432
  void captureBlockStaticPositions()
3433
3433
  {
3434
3434
  for (int c = node_.first_child; c >= 0; c = nodes_[c].next_sibling)
3435
- if (isOutOfFlowPosition(nodes_[c].computedStyle().position)) layoutState(c).static_block_axis = 0;
3435
+ if (!isLayoutExcluded(nodes_[c]) && isOutOfFlowPosition(nodes_[c].computedStyle().position)) layoutState(c).static_block_axis = 0;
3436
3436
  if (node_.computedStyle().display != kDisplayBlock || node_.computedStyle().flex_direction_explicit ||
3437
3437
  (LayoutEngine::isInlineLevelNode(node_) && !isOutOfFlowPosition(node_.computedStyle().position))) return;
3438
3438
  const bool vertical = writingMode(node_) != 0;
@@ -3442,7 +3442,7 @@ private:
3442
3442
  CollapsedMargin pending;
3443
3443
  visitFormattingChildren(nodes_, id_, [&](int id) {
3444
3444
  Node &child = nodes_[id];
3445
- if (isDisplayNone(child.computedStyle())) return;
3445
+ if (isLayoutExcluded(child)) return;
3446
3446
  if (isOutOfFlowPosition(child.computedStyle().position)) {
3447
3447
  if (child.parent != id_ || !blockBox(child)) return;
3448
3448
  const int edge = cursor + (first && collapsesWithChildren(id_, false) ? 0 : pending.value());
@@ -3469,7 +3469,7 @@ private:
3469
3469
  captureBlockStaticPositions();
3470
3470
  for (int child = node_.first_child; child >= 0; child = nodes_[child].next_sibling) {
3471
3471
  Node &childNode = nodes_[child];
3472
- if (isDisplayNone(childNode.computedStyle()) || !isOutOfFlowPosition(childNode.computedStyle().position)) continue;
3472
+ if (isLayoutExcluded(childNode) || !isOutOfFlowPosition(childNode.computedStyle().position)) continue;
3473
3473
 
3474
3474
  int childAvailWidth, childAvailHeight;
3475
3475
  int areaX, areaY;
@@ -3534,6 +3534,7 @@ private:
3534
3534
  auto apply = [&](auto &&self, int parent) -> void {
3535
3535
  for (int child = nodes_[parent].first_child; child >= 0; child = nodes_[child].next_sibling) {
3536
3536
  Node &childNode = nodes_[child];
3537
+ if (isLayoutExcluded(childNode)) continue;
3537
3538
  if (splitInlineChildren_ && splitInlineWrapper(nodes_, child)) self(self, child);
3538
3539
  if (childNode.computedStyle().position != 2) continue;
3539
3540
  if (hasPositionOffset<0>(childNode))
@@ -3732,6 +3733,7 @@ void layoutAbsoluteNode(int node, int containing, int areaX, int areaWidth, int
3732
3733
  void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes)
3733
3734
  {
3734
3735
  Node &absolute = nodes[node];
3736
+ if (isLayoutExcluded(absolute)) return;
3735
3737
  const Node &containingNode = nodes[containing];
3736
3738
  const int parent = absolute.parent;
3737
3739
  if (parent < 0) return;
@@ -3792,7 +3794,7 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
3792
3794
  void resolvePositionedDescendants(int node, int root, Node *nodes)
3793
3795
  {
3794
3796
  for (int child = nodes[node].first_child; child >= 0; child = nodes[child].next_sibling) {
3795
- if (isDisplayNone(nodes[child].computedStyle())) continue;
3797
+ if (isLayoutExcluded(nodes[child])) continue;
3796
3798
  if (isOutOfFlowPosition(nodes[child].computedStyle().position))
3797
3799
  positionAbsoluteNodeInContainingBlock(child, containingBlockForAbsoluteNode(child, root, nodes), nodes);
3798
3800
  resolvePositionedDescendants(child, root, nodes);
@@ -3823,13 +3825,14 @@ int LayoutEngine::fixedContainingBlock(const Node &node)
3823
3825
 
3824
3826
  bool LayoutEngine::isViewportFixed(const Node &node)
3825
3827
  {
3826
- return node.computedStyle().position == kPositionFixed && fixedContainingBlock(node) < 0;
3828
+ return !isLayoutExcluded(node) && node.computedStyle().position == kPositionFixed && fixedContainingBlock(node) < 0;
3827
3829
  }
3828
3830
 
3829
3831
  bool LayoutEngine::containsViewportFixed(int node)
3830
3832
  {
3831
3833
  if (!treeState().fixedPositionUsed) return false;
3832
3834
  const Node *nodes = Tree::instance().nodes();
3835
+ if (isLayoutExcluded(nodes[node])) return false;
3833
3836
  if (isViewportFixed(nodes[node])) return true;
3834
3837
  for (int child = nodes[node].first_child; child >= 0; child = nodes[child].next_sibling)
3835
3838
  if (containsViewportFixed(child)) return true;
@@ -4088,7 +4091,8 @@ int LayoutEngine::collectChildren(int parent, int *out, int max, bool skipAbs) c
4088
4091
  int n = 0;
4089
4092
  Node *nodes = Tree::instance().nodes();
4090
4093
  for (int child = nodes[parent].first_child; child >= 0; child = nodes[child].next_sibling) {
4091
- if (isDisplayNone(nodes[child].computedStyle())) continue;
4094
+ if (isStructuralNodeType(nodes[child].type)) continue;
4095
+ if (isLayoutExcluded(nodes[child])) continue;
4092
4096
  if (suppressAnonymousWhitespace(nodes, parent, child)) continue;
4093
4097
  if (skipAbs && isOutOfFlowPosition(nodes[child].computedStyle().position)) continue;
4094
4098
  if (n < max) out[n++] = child;
@@ -4249,6 +4253,7 @@ std::size_t LayoutEngine::memoPeakHeapBytes()
4249
4253
  void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBoxEdges)
4250
4254
  {
4251
4255
  Node &node = Tree::instance().nodes()[id];
4256
+ if (isStructuralNodeType(node.type)) return;
4252
4257
  auto &persistent = layoutState(id);
4253
4258
  const Node *parent = node.parent >= 0 ? &Tree::instance().nodes()[node.parent] : nullptr;
4254
4259
  // Horizontal non-replaced floats use the same min/max-content measurement
@@ -4414,7 +4419,7 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
4414
4419
  for (int i = 0; i < nodeCount; ++i) {
4415
4420
  const Node &n = nodes[i];
4416
4421
  if (i == scope) continue;
4417
- if (n.parent < 0 || !isOutOfFlowPosition(n.computedStyle().position) || isDisplayNone(n.computedStyle())) continue;
4422
+ if (n.parent < 0 || !isOutOfFlowPosition(n.computedStyle().position) || isLayoutExcluded(n)) continue;
4418
4423
  if (!inScope(i)) continue;
4419
4424
  const int containing = containingBlockForAbsoluteNode(i, treeRoot, nodes);
4420
4425
  if (containing >= 0 && !inScope(containing)) {
@@ -4478,7 +4483,7 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
4478
4483
  // Scoped equivalent of the root containing-block pass (both the node and
4479
4484
  // its containing block are inside the scope, in the same relative space).
4480
4485
  for (int i = 0; i < nodeCount; ++i) {
4481
- if (isDisplayNone(nodes[i].computedStyle()) || !isOutOfFlowPosition(nodes[i].computedStyle().position) || nodes[i].parent < 0) continue;
4486
+ if (isLayoutExcluded(nodes[i]) || !isOutOfFlowPosition(nodes[i].computedStyle().position) || nodes[i].parent < 0) continue;
4482
4487
  if (!inScope(i) || i == scope) continue;
4483
4488
  const int containing = containingBlockForAbsoluteNode(i, scope, nodes);
4484
4489
  if (containing < 0) continue;
@@ -4501,6 +4506,7 @@ void LayoutEngine::resolveAbsoluteCoords(int id, int parent_x, int parent_y)
4501
4506
  {
4502
4507
  Node *nodes = Tree::instance().nodes();
4503
4508
  Node *node = &nodes[id];
4509
+ if (isLayoutExcluded(*node)) return;
4504
4510
  if (node->parent < 0) resolveAbsoluteContainingBlocks(id);
4505
4511
  if (!isViewportFixed(*node)) {
4506
4512
  node->layout.x += parent_x;