@geastack/engine 0.1.7 → 0.1.9

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
@@ -99,7 +99,9 @@ char g_recprofLast[420];
99
99
  // those keep their existing computed style (identical to a full recompute). A
100
100
  // GEA_INCREMENTAL_VERIFY build additionally runs the full recompute afterwards and
101
101
  // asserts every node's style matches, proving equivalence on-device.
102
+ #if GEA_CSS_CUSTOM_PROPERTIES
102
103
  std::vector<CssAtomId> g_nodeRefOverflow;
104
+ #endif
103
105
 
104
106
  struct CssAtomSmallList {
105
107
  static constexpr std::uint8_t kInlineCount = 16;
@@ -157,6 +159,7 @@ struct CssAtomSmallList {
157
159
  }
158
160
  };
159
161
 
162
+ #if GEA_CSS_CUSTOM_PROPERTIES
160
163
  struct NodeCustomPropRefs {
161
164
  static constexpr std::uint8_t kInlineCount = 4;
162
165
  static constexpr std::uint16_t kNoOverflow = 0xFFFFu;
@@ -301,37 +304,44 @@ struct CustomPropertyLookupCache {
301
304
  };
302
305
 
303
306
  CustomPropertyLookupCache g_customPropertyLookupCache;
307
+ #elif !GEA_EMBEDDED_SHARED_STYLES
308
+ bool g_nodeStyleTracked[kMaxNodes]{};
309
+ #endif
304
310
 
305
311
  void clearDynamicLengthExpressionResolutionCache();
306
312
 
307
313
  inline void clearCustomPropertyLookupCache()
308
314
  {
315
+ #if GEA_CSS_CUSTOM_PROPERTIES
309
316
  g_customPropertyLookupCache.clear();
317
+ #endif
310
318
  clearDynamicLengthExpressionResolutionCache();
311
319
  }
312
320
 
313
321
  struct DenseNodeMark {
322
+ // A mark stores batch identity, not a node index. Byte epochs retain direct
323
+ // loads and halve both dense arrays; clear all marks before epoch reuse.
314
324
  #if GEA_EMBEDDED_UI_STATE_DYNAMIC_INIT
315
- std::uint16_t marks[kMaxNodes];
316
- std::uint16_t serial;
325
+ std::uint8_t marks[kMaxNodes];
326
+ std::uint8_t serial;
317
327
 
318
328
  // Runtime initialization keeps the nonzero serial out of .data (see
319
329
  // state_init.h); noinline stops the compiler folding it back in.
320
330
  __attribute__((noinline)) DenseNodeMark()
321
331
  {
322
- for (std::uint16_t &mark : marks) mark = 0;
332
+ for (std::uint8_t &mark : marks) mark = 0;
323
333
  serial = 1;
324
334
  }
325
335
  #else
326
- std::uint16_t marks[kMaxNodes]{};
327
- std::uint16_t serial = 1;
336
+ std::uint8_t marks[kMaxNodes]{};
337
+ std::uint8_t serial = 1;
328
338
  #endif
329
339
 
330
340
  void clear()
331
341
  {
332
342
  ++serial;
333
343
  if (serial == 0) {
334
- for (std::uint16_t &mark : marks) mark = 0;
344
+ for (std::uint8_t &mark : marks) mark = 0;
335
345
  serial = 1;
336
346
  }
337
347
  }
@@ -362,8 +372,12 @@ std::unordered_set<int> g_incrRecomputedNodes; // nodes the incremental pass ac
362
372
 
363
373
  inline void recordCustomPropRef(CssAtomId name)
364
374
  {
375
+ #if GEA_CSS_CUSTOM_PROPERTIES
365
376
  if (g_recordingNode < 0 || g_recordingNode >= kMaxNodes || name == kInvalidCssAtom) return;
366
377
  g_nodeRefs[g_recordingNode].insert(name);
378
+ #else
379
+ (void)name;
380
+ #endif
367
381
  }
368
382
 
369
383
  bool nodeParticipatesInMountedTree(const TreeState &state, int node)
@@ -445,8 +459,13 @@ bool styleEqualExceptTextPaint(const ComputedStyle &a, const ComputedStyle &b)
445
459
  GEA_CSS_POSITION_PERCENT_2(a) != GEA_CSS_POSITION_PERCENT_2(b) ||
446
460
  GEA_CSS_POSITION_PERCENT_3(a) != GEA_CSS_POSITION_PERCENT_3(b)) return false;
447
461
  for (int i = 0; i < 4; ++i) {
448
- if (a.padding[i] != b.padding[i] ||
462
+ if (
463
+ #if GEA_CSS_PADDING
464
+ a.padding[i] != b.padding[i] ||
465
+ #endif
466
+ #if GEA_CSS_MARGINS
449
467
  a.margin[i] != b.margin[i] ||
468
+ #endif
450
469
  #if GEA_CSS_BOX_EXPRESSIONS
451
470
  ar.margin_expression[i] != br.margin_expression[i] ||
452
471
  #endif
@@ -666,8 +685,12 @@ bool styleEqualExceptLocalDisplayCommands(const ComputedStyle &a, const Computed
666
685
  GEA_CSS_POSITION_PERCENT_3(a) != GEA_CSS_POSITION_PERCENT_3(b)) return false;
667
686
  for (int i = 0; i < 4; ++i) {
668
687
  if (boxInset(a, i) != boxInset(b, i) ||
688
+ #if GEA_CSS_PADDING
669
689
  a.padding[i] != b.padding[i] ||
690
+ #endif
691
+ #if GEA_CSS_MARGINS
670
692
  a.margin[i] != b.margin[i] ||
693
+ #endif
671
694
  #if GEA_CSS_BOX_EXPRESSIONS
672
695
  ar.margin_expression[i] != br.margin_expression[i] ||
673
696
  #endif
@@ -741,7 +764,7 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
741
764
  auto &state = treeState();
742
765
  if (node < 0 || node >= state.nodeCount) return;
743
766
  Node &target = state.nodes[node];
744
- if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.style) && !firstLineChanged) return;
767
+ if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.computedStyle()) && !firstLineChanged) return;
745
768
  if (!nodeParticipatesInMountedTree(state, node)) return;
746
769
  const bool hadRecolor = target.render.bg_recolor_pending;
747
770
  const bool canRecolor = !target.render.dirty || hadRecolor;
@@ -770,12 +793,12 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
770
793
  };
771
794
  invalidateText(invalidateText, node);
772
795
  }
773
- if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.style) && firstLineChanged) {
796
+ if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.computedStyle()) && firstLineChanged) {
774
797
  return;
775
798
  }
776
799
 
777
- if (beforeImageId == target.image_id && styleEqualExceptTextPaint(beforeStyle, target.style)) {
778
- if (target.type == NodeType::Text || borderUsesCurrentColor(target.style) || borderUsesCurrentColor(beforeStyle)) {
800
+ if (beforeImageId == target.image_id && styleEqualExceptTextPaint(beforeStyle, target.computedStyle())) {
801
+ if (target.type == NodeType::Text || borderUsesCurrentColor(target.computedStyle()) || borderUsesCurrentColor(beforeStyle)) {
779
802
  target.render.dirty = 1; // paint-only: text color; geometry untouched
780
803
  #if GEA_CSS_SCROLLING
781
804
  target.render.non_scroll_dirty = 1;
@@ -785,7 +808,7 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
785
808
  return;
786
809
  }
787
810
 
788
- if (beforeImageId == target.image_id && styleEqualExceptPlainBackgroundColor(beforeStyle, target.style)) {
811
+ if (beforeImageId == target.image_id && styleEqualExceptPlainBackgroundColor(beforeStyle, target.computedStyle())) {
789
812
  // Preserve `bg_recolor_from` across coalesced changes. The in-place recolor
790
813
  // rewrites framebuffer pixels equal to `from`. If several background-color
791
814
  // changes land between renders (e.g. fast rotary spins A->B->C), overwriting
@@ -810,13 +833,13 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
810
833
  #if GEA_CSS_SCROLLING
811
834
  target.render.non_scroll_dirty = 1;
812
835
  #endif
813
- if (preserves3D(beforeStyle) != preserves3D(target.style))
836
+ if (preserves3D(beforeStyle) != preserves3D(target.computedStyle()))
814
837
  Tree::instance().markDisplayListDirty();
815
- if (beforeImageId == target.image_id && styleEqualExceptLocalDisplayCommands(beforeStyle, target.style)) {
838
+ if (beforeImageId == target.image_id && styleEqualExceptLocalDisplayCommands(beforeStyle, target.computedStyle())) {
816
839
  // Local display-command diff: geometry equal by the predicate's
817
840
  // construction (transforms ride transform_dirty), so no layout pass.
818
841
  const RareStyle &beforeRare = rstyle(beforeStyle);
819
- const RareStyle &targetRare = rstyle(target.style);
842
+ const RareStyle &targetRare = rstyle(target.computedStyle());
820
843
  if (beforeRare.transform_rotate != targetRare.transform_rotate ||
821
844
  beforeRare.transform_translate_outer_axes != targetRare.transform_translate_outer_axes ||
822
845
  beforeRare.rotate_angle != targetRare.rotate_angle ||
@@ -858,8 +881,8 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
858
881
  }
859
882
  Tree::instance().markNodeDisplayCommandsDirty(node);
860
883
  // Flattened backface visibility changes the whole descendant paint group.
861
- if (beforeStyle.backface_hidden != target.style.backface_hidden ||
862
- rstyle(beforeStyle).transform_preserve_3d != rstyle(target.style).transform_preserve_3d)
884
+ if (beforeStyle.backface_hidden != target.computedStyle().backface_hidden ||
885
+ rstyle(beforeStyle).transform_preserve_3d != rstyle(target.computedStyle()).transform_preserve_3d)
863
886
  Tree::instance().markDisplayListDirty();
864
887
  return;
865
888
  }
@@ -1068,6 +1091,11 @@ using CssDeclarationId = StyleDeclaration;
1068
1091
  CssDeclarationId classifyDeclaration(const char *property)
1069
1092
  {
1070
1093
  if (!property || !*property) return CssDeclarationId::Unknown;
1094
+ // Position updates are frequent; resolve them before the long declaration list.
1095
+ if (std::strcmp(property, "top") == 0) return CssDeclarationId::Top;
1096
+ if (std::strcmp(property, "left") == 0) return CssDeclarationId::Left;
1097
+ if (std::strcmp(property, "right") == 0) return CssDeclarationId::Right;
1098
+ if (std::strcmp(property, "bottom") == 0) return CssDeclarationId::Bottom;
1071
1099
  if (property[0] == '-' && property[1] == '-') return CssDeclarationId::Custom;
1072
1100
  if (std::strcmp(property, "color-scheme") == 0 ||
1073
1101
  std::strcmp(property, "isolation") == 0 ||
@@ -1131,10 +1159,6 @@ CssDeclarationId classifyDeclaration(const char *property)
1131
1159
  if (std::strcmp(property, "margin-left") == 0) return CssDeclarationId::MarginLeft;
1132
1160
  if (std::strcmp(property, "position") == 0) return CssDeclarationId::Position;
1133
1161
  if (std::strcmp(property, "inset") == 0) return CssDeclarationId::Inset;
1134
- if (std::strcmp(property, "top") == 0) return CssDeclarationId::Top;
1135
- if (std::strcmp(property, "right") == 0) return CssDeclarationId::Right;
1136
- if (std::strcmp(property, "bottom") == 0) return CssDeclarationId::Bottom;
1137
- if (std::strcmp(property, "left") == 0) return CssDeclarationId::Left;
1138
1162
  if (std::strcmp(property, "box-sizing") == 0) return CssDeclarationId::BoxSizing;
1139
1163
  if (std::strcmp(property, "float") == 0) return CssDeclarationId::Float;
1140
1164
  if (std::strcmp(property, "aspect-ratio") == 0) return CssDeclarationId::AspectRatio;
@@ -2273,19 +2297,21 @@ std::vector<CssLengthExpression> &compiledCssLengthExpressions()
2273
2297
  }
2274
2298
 
2275
2299
  struct StaticLengthExpressionResolution {
2276
- ResolvedCssLength value;
2300
+ // Reuse ResolvedCssLength's two tail-padding bytes for cache bookkeeping.
2301
+ // All members remain direct loads; the cached value keeps its full precision.
2302
+ [[no_unique_address]] ResolvedCssLength value;
2277
2303
  std::uint8_t status = 0; // 0 unknown, 1 dynamic, 2 cacheable
2278
2304
  std::uint8_t valid = 0;
2279
2305
  };
2280
2306
 
2281
2307
  struct DynamicLengthExpressionResolution {
2282
2308
  #if GEA_EMBEDDED_UI_STATE_DYNAMIC_INIT
2283
- ResolvedCssLength value;
2309
+ [[no_unique_address]] ResolvedCssLength value;
2310
+ std::uint8_t axis;
2311
+ std::uint8_t valid;
2284
2312
  std::uint16_t handle;
2285
2313
  std::int16_t nodeId;
2286
2314
  int basis;
2287
- std::uint8_t axis;
2288
- std::uint8_t valid;
2289
2315
 
2290
2316
  // Runtime initialization keeps the nonzero sentinels out of .data (see
2291
2317
  // state_init.h); noinline stops the compiler folding them back in.
@@ -2299,12 +2325,12 @@ struct DynamicLengthExpressionResolution {
2299
2325
  valid = 0;
2300
2326
  }
2301
2327
  #else
2302
- ResolvedCssLength value;
2328
+ [[no_unique_address]] ResolvedCssLength value;
2329
+ std::uint8_t axis = 0;
2330
+ std::uint8_t valid = 0;
2303
2331
  std::uint16_t handle = kNoCompiledCssLengthExpression;
2304
2332
  std::int16_t nodeId = -1;
2305
2333
  int basis = 0;
2306
- std::uint8_t axis = 0;
2307
- std::uint8_t valid = 0;
2308
2334
  #endif
2309
2335
  };
2310
2336
 
@@ -3484,6 +3510,7 @@ std::vector<std::string> splitTopLevel(const std::string &value, char delimiter)
3484
3510
 
3485
3511
  const NodeCustomProperty *lookupCustomPropertyEntry(int nodeId, CssAtomId name)
3486
3512
  {
3513
+ #if GEA_CSS_CUSTOM_PROPERTIES
3487
3514
  // Record the dependency against the node currently being recomputed (not nodeId:
3488
3515
  // pseudo-element resolution looks up from the pseudo node but the dependency
3489
3516
  // belongs to its owner, which is g_recordingNode). Record on every lookup, hit or
@@ -3517,6 +3544,9 @@ const NodeCustomProperty *lookupCustomPropertyEntry(int nodeId, CssAtomId name)
3517
3544
  }
3518
3545
  }
3519
3546
  storeVisited(nullptr);
3547
+ #else
3548
+ (void)nodeId; (void)name;
3549
+ #endif
3520
3550
  return nullptr;
3521
3551
  }
3522
3552
 
@@ -3583,17 +3613,17 @@ int percentBasisForNode(int nodeId, LengthAxis axis)
3583
3613
  int parent = nodeId >= 0 && nodeId < state.nodeCount ? state.nodes[nodeId].parent : -1;
3584
3614
  if (parent >= 0 && parent < state.nodeCount) {
3585
3615
  const auto &p = state.nodes[parent];
3586
- const int padding = boxInsets(p.style, axis != LengthAxis::Vertical);
3616
+ const int padding = boxInsets(p.computedStyle(), axis != LengthAxis::Vertical);
3587
3617
  auto contentBasis = [padding](int value) {
3588
3618
  value -= padding;
3589
3619
  return value < 0 ? 0 : value;
3590
3620
  };
3591
3621
  if (axis == LengthAxis::Vertical) {
3592
3622
  if (p.layout.height > 0) return contentBasis(p.layout.height);
3593
- if (p.style.height != kUnset) return p.style.box_sizing == 0 ? p.style.height : contentBasis(p.style.height);
3623
+ if (p.computedStyle().height != kUnset) return p.computedStyle().box_sizing == 0 ? p.computedStyle().height : contentBasis(p.computedStyle().height);
3594
3624
  } else {
3595
3625
  if (p.layout.width > 0) return contentBasis(p.layout.width);
3596
- if (p.style.width != kUnset) return p.style.box_sizing == 0 ? p.style.width : contentBasis(p.style.width);
3626
+ if (p.computedStyle().width != kUnset) return p.computedStyle().box_sizing == 0 ? p.computedStyle().width : contentBasis(p.computedStyle().width);
3597
3627
  }
3598
3628
  }
3599
3629
  return axis == LengthAxis::Vertical ? g_viewport_height : g_viewport_width;
@@ -3640,7 +3670,7 @@ int lineHeightForLength(int nodeId, bool rootRelative)
3640
3670
  if (basis >= 0 && basis < state.nodeCount &&
3641
3671
  (basis == g_fontSizeBasisNode || basis == g_lineHeightBasisNode)) basis = state.nodes[basis].parent;
3642
3672
  if (basis >= 0 && basis < state.nodeCount) {
3643
- const auto &style = state.nodes[basis].style;
3673
+ const auto &style = state.nodes[basis].computedStyle();
3644
3674
  if (style.line_height > 0) return style.line_height;
3645
3675
  return TextRenderer::measureHeight(" ", style.font_id, currentFontSizeForNode(basis));
3646
3676
  }
@@ -3652,7 +3682,7 @@ int zeroAdvanceForNode(int nodeId)
3652
3682
  {
3653
3683
  const auto &state = treeState();
3654
3684
  nodeId = fontMetricBasisNode(nodeId);
3655
- const int fontId = nodeId >= 0 && nodeId < state.nodeCount ? state.nodes[nodeId].style.font_id : -1;
3685
+ const int fontId = nodeId >= 0 && nodeId < state.nodeCount ? state.nodes[nodeId].computedStyle().font_id : -1;
3656
3686
  return TextRenderer::measureWidth("0", fontId, currentFontSizeForNode(nodeId));
3657
3687
  }
3658
3688
 
@@ -3861,8 +3891,8 @@ int parseLength(const std::string &value)
3861
3891
  int currentFontSizeForNode(int nodeId)
3862
3892
  {
3863
3893
  auto &state = treeState();
3864
- if (nodeId >= 0 && nodeId < state.nodeCount && state.nodes[nodeId].style.font_size > 0)
3865
- return state.nodes[nodeId].style.font_size;
3894
+ if (nodeId >= 0 && nodeId < state.nodeCount && state.nodes[nodeId].computedStyle().font_size > 0)
3895
+ return state.nodes[nodeId].computedStyle().font_size;
3866
3896
  return cssPixelLength(16.0);
3867
3897
  }
3868
3898
 
@@ -4174,7 +4204,7 @@ ParsedCssColor parseCssColor(const std::string &value)
4174
4204
  // RAW (pre-panel-swap) native style-value for colours applied via setStyleValue()
4175
4205
  // -> Tree::setStyle() -> StyleValues::pixelFromStyleValue(), which applies the
4176
4206
  // panel byte-swap once on 16-bit boards (must be raw here or colours double-swap,
4177
- // e.g. cream text rendered periwinkle). Colours written straight into node.style
4207
+ // e.g. cream text rendered periwinkle). Colours written straight into node.computedStyle()
4178
4208
  // (gradient stops, grid lines) bypass that swap and use cssColorNative() instead.
4179
4209
  // On full-colour boards there is no panel concept, so both are identical RGBA8888.
4180
4210
  gea::framework::graphics::pixel::native_t cssColorStyleValue(const ParsedCssColor &color)
@@ -7491,7 +7521,7 @@ void applyCompiledGridTemplateValue(NodeHandle node, const CssCompiledGridTempla
7491
7521
  const int nodeId = node.id();
7492
7522
  Node &target = treeState().nodes[nodeId];
7493
7523
  const LengthAxis axis = columns ? LengthAxis::Horizontal : LengthAxis::Vertical;
7494
- RareStyle &rs = rstyleMut(target.style);
7524
+ RareStyle &rs = rstyleMut(target.mutableStyle());
7495
7525
  int8_t *types = columns ? rs.grid_column_type : rs.grid_row_type;
7496
7526
  int16_t *values = columns ? rs.grid_column_value : rs.grid_row_value;
7497
7527
  int8_t &count = columns ? rs.grid_column_count : rs.grid_row_count;
@@ -7541,16 +7571,20 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7541
7571
  &target == &treeState().nodes[g_resolvedFontNode]) return true;
7542
7572
  if (g_resolvedLineHeightNode >= 0 && isLineHeightProperty(property) &&
7543
7573
  &target == &treeState().nodes[g_resolvedLineHeightNode]) return true;
7544
- ComputedStyle &style = target.style;
7574
+ ComputedStyle &style = target.mutableStyle();
7545
7575
  switch (property) {
7546
7576
  case Property::Display:
7577
+ #if GEA_CSS_DISPLAY_EXPLICIT
7547
7578
  style.display_explicit = 1;
7579
+ #endif
7548
7580
  style.display = value;
7549
7581
  return true;
7582
+ #if GEA_CSS_FLEX_DIRECTION
7550
7583
  case Property::FlexDirection:
7551
7584
  style.flex_direction_explicit = 1;
7552
7585
  style.flex_direction = value;
7553
7586
  return true;
7587
+ #endif
7554
7588
  #if GEA_CSS_FLEX_WRAP
7555
7589
  case Property::FlexWrap: style.flex_wrap = value; return true;
7556
7590
  #endif
@@ -7569,8 +7603,12 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7569
7603
  #if GEA_CSS_CONTAINMENT
7570
7604
  case Property::Containment: rstyleMut(style).containment = value; return true;
7571
7605
  #endif
7606
+ #if GEA_CSS_JUSTIFY_CONTENT
7572
7607
  case Property::JustifyContent: style.justify_content = value; return true;
7608
+ #endif
7609
+ #if GEA_CSS_ALIGN_ITEMS
7573
7610
  case Property::AlignItems: style.align_items = value; return true;
7611
+ #endif
7574
7612
  #if GEA_CSS_JUSTIFY_ITEMS
7575
7613
  case Property::JustifyItems: style.justify_items = value; return true;
7576
7614
  #endif
@@ -7589,7 +7627,9 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7589
7627
  case Property::GridRowEnd: rstyleMut(style).grid_line[2] = value; return true;
7590
7628
  case Property::GridColumnEnd: rstyleMut(style).grid_line[3] = value; return true;
7591
7629
  #endif
7630
+ #if GEA_CSS_BOX_SIZING
7592
7631
  case Property::BoxSizing: style.box_sizing = value; return true;
7632
+ #endif
7593
7633
  #if GEA_CSS_FLOATS
7594
7634
  case Property::Float: style.float_side = value; return true;
7595
7635
  #endif
@@ -7616,10 +7656,18 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7616
7656
  case Property::RowGapPercent: style.row_gap_percent = value; return true;
7617
7657
  case Property::ColumnGapPercent: style.column_gap_percent = value; return true;
7618
7658
  #endif
7659
+ #if GEA_CSS_MARGIN_AUTO
7619
7660
  case Property::MarginTopAuto: style.margin_auto = (style.margin_auto & ~1) | (value ? 1 : 0); return true;
7661
+ #endif
7662
+ #if GEA_CSS_MARGIN_AUTO
7620
7663
  case Property::MarginRightAuto: style.margin_auto = (style.margin_auto & ~2) | (value ? 2 : 0); return true;
7664
+ #endif
7665
+ #if GEA_CSS_MARGIN_AUTO
7621
7666
  case Property::MarginBottomAuto: style.margin_auto = (style.margin_auto & ~4) | (value ? 4 : 0); return true;
7667
+ #endif
7668
+ #if GEA_CSS_MARGIN_AUTO
7622
7669
  case Property::MarginLeftAuto: style.margin_auto = (style.margin_auto & ~8) | (value ? 8 : 0); return true;
7670
+ #endif
7623
7671
  #if GEA_CSS_BOX_EXPRESSIONS
7624
7672
  case Property::MarginTopExpression: rstyleMut(style).margin_expression[0] = value; return true;
7625
7673
  #endif
@@ -7644,13 +7692,28 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7644
7692
  #if GEA_CSS_BOX_EXPRESSIONS
7645
7693
  case Property::PaddingLeftExpression: rstyleMut(style).padding_expression[3] = value; return true;
7646
7694
  #endif
7647
- case Property::WidthExpression: style.width_expression = value; style.width = style.width_percent = kUnset; return true;
7695
+ #if GEA_CSS_WIDTH_EXPRESSIONS
7696
+ case Property::WidthExpression:
7697
+ style.width_expression = value;
7698
+ style.width = kUnset;
7699
+ #if GEA_CSS_WIDTH_PERCENT
7700
+ style.width_percent = kUnset;
7701
+ #endif
7702
+ return true;
7703
+ #endif
7648
7704
  #if GEA_CSS_HEIGHT_EXPRESSIONS
7649
- case Property::HeightExpression: style.height_expression = value; style.height = style.height_percent = kUnset; return true;
7705
+ case Property::HeightExpression:
7706
+ style.height_expression = value;
7707
+ style.height = kUnset;
7708
+ #if GEA_CSS_HEIGHT_PERCENT
7709
+ style.height_percent = kUnset;
7710
+ #endif
7711
+ return true;
7650
7712
  #endif
7651
7713
  #if GEA_CSS_ORDER
7652
7714
  case Property::Order: style.order = value; return true;
7653
7715
  #endif
7716
+ #if GEA_CSS_GAP
7654
7717
  case Property::Gap:
7655
7718
  style.gap = value;
7656
7719
  #if GEA_CSS_AXIS_GAP
@@ -7660,40 +7723,59 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7660
7723
  style.row_gap_percent = style.column_gap_percent = kUnset;
7661
7724
  #endif
7662
7725
  return true;
7726
+ #endif
7663
7727
  case Property::Width:
7728
+ #if GEA_CSS_WIDTH_EXPRESSIONS
7664
7729
  style.width_expression = -1;
7730
+ #endif
7665
7731
  style.width = value;
7732
+ #if GEA_CSS_WIDTH_PERCENT
7666
7733
  style.width_percent = kUnset;
7734
+ #endif
7667
7735
  return true;
7668
7736
  case Property::Height:
7669
7737
  #if GEA_CSS_HEIGHT_EXPRESSIONS
7670
7738
  style.height_expression = -1;
7671
7739
  #endif
7672
7740
  style.height = value;
7741
+ #if GEA_CSS_HEIGHT_PERCENT
7673
7742
  style.height_percent = kUnset;
7743
+ #endif
7674
7744
  return true;
7675
7745
  case Property::WidthPercent:
7746
+ #if GEA_CSS_WIDTH_EXPRESSIONS
7676
7747
  style.width_expression = -1;
7748
+ #endif
7749
+ #if GEA_CSS_WIDTH_PERCENT
7677
7750
  style.width_percent = value;
7751
+ #endif
7678
7752
  style.width = kUnset;
7679
7753
  return true;
7680
7754
  case Property::HeightPercent:
7681
7755
  #if GEA_CSS_HEIGHT_EXPRESSIONS
7682
7756
  style.height_expression = -1;
7683
7757
  #endif
7758
+ #if GEA_CSS_HEIGHT_PERCENT
7684
7759
  style.height_percent = value;
7760
+ #endif
7685
7761
  style.height = kUnset;
7686
7762
  return true;
7687
7763
  #if GEA_CSS_MIN_WIDTH
7688
7764
  case Property::MinWidth: style.min_width = value; return true;
7689
7765
  #endif
7766
+ #if GEA_CSS_MIN_HEIGHT
7690
7767
  case Property::MinHeight: style.min_height = value; return true;
7768
+ #endif
7769
+ #if GEA_CSS_MAX_WIDTH
7691
7770
  case Property::MaxWidth: style.max_width = value; return true;
7771
+ #endif
7692
7772
  #if GEA_CSS_MAX_HEIGHT
7693
7773
  case Property::MaxHeight: style.max_height = value; return true;
7694
7774
  #endif
7775
+ #if GEA_CSS_FLEX_FACTORS
7695
7776
  case Property::Flex: style.flex = value; return true;
7696
7777
  case Property::FlexShrink: style.flex_shrink = value; return true;
7778
+ #endif
7697
7779
  case Property::FlexBasis:
7698
7780
  #if GEA_CSS_FLEX_BASIS_EXPRESSIONS
7699
7781
  if (rstyle(style).flex_basis_expression >= 0) rstyleMut(style).flex_basis_expression = -1;
@@ -7710,6 +7792,7 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7710
7792
  #endif
7711
7793
  return true;
7712
7794
  #endif
7795
+ #if GEA_CSS_PADDING
7713
7796
  case Property::PaddingTop:
7714
7797
  #if GEA_CSS_BOX_EXPRESSIONS
7715
7798
  if (rstyle(style).padding_expression[0] >= 0) rstyleMut(style).padding_expression[0] = -1;
@@ -7730,26 +7813,45 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7730
7813
  if (rstyle(style).padding_expression[3] >= 0) rstyleMut(style).padding_expression[3] = -1;
7731
7814
  #endif
7732
7815
  style.padding[3] = value; return true;
7816
+ #endif
7817
+ #if GEA_CSS_MARGINS
7733
7818
  case Property::MarginTop:
7734
7819
  #if GEA_CSS_BOX_EXPRESSIONS
7735
7820
  if (rstyle(style).margin_expression[0] >= 0) rstyleMut(style).margin_expression[0] = -1;
7736
7821
  #endif
7737
- style.margin_auto &= ~1; style.margin[0] = value; return true;
7822
+
7823
+ #if GEA_CSS_MARGIN_AUTO
7824
+ style.margin_auto &= ~1;
7825
+ #endif
7826
+ style.margin[0] = value; return true;
7738
7827
  case Property::MarginRight:
7739
7828
  #if GEA_CSS_BOX_EXPRESSIONS
7740
7829
  if (rstyle(style).margin_expression[1] >= 0) rstyleMut(style).margin_expression[1] = -1;
7741
7830
  #endif
7742
- style.margin_auto &= ~2; style.margin[1] = value; return true;
7831
+
7832
+ #if GEA_CSS_MARGIN_AUTO
7833
+ style.margin_auto &= ~2;
7834
+ #endif
7835
+ style.margin[1] = value; return true;
7743
7836
  case Property::MarginBottom:
7744
7837
  #if GEA_CSS_BOX_EXPRESSIONS
7745
7838
  if (rstyle(style).margin_expression[2] >= 0) rstyleMut(style).margin_expression[2] = -1;
7746
7839
  #endif
7747
- style.margin_auto &= ~4; style.margin[2] = value; return true;
7840
+
7841
+ #if GEA_CSS_MARGIN_AUTO
7842
+ style.margin_auto &= ~4;
7843
+ #endif
7844
+ style.margin[2] = value; return true;
7748
7845
  case Property::MarginLeft:
7749
7846
  #if GEA_CSS_BOX_EXPRESSIONS
7750
7847
  if (rstyle(style).margin_expression[3] >= 0) rstyleMut(style).margin_expression[3] = -1;
7751
7848
  #endif
7752
- style.margin_auto &= ~8; style.margin[3] = value; return true;
7849
+
7850
+ #if GEA_CSS_MARGIN_AUTO
7851
+ style.margin_auto &= ~8;
7852
+ #endif
7853
+ style.margin[3] = value; return true;
7854
+ #endif
7753
7855
  case Property::Position: if (value == kPositionFixed) treeState().fixedPositionUsed = true; style.position = value; return true;
7754
7856
  case Property::Top:
7755
7857
  #if GEA_CSS_POSITION_TOP
@@ -7847,10 +7949,14 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7847
7949
  StyleValues::applyBackgroundImage(style, value, static_cast<int>(&target - treeState().nodes));
7848
7950
  return true;
7849
7951
  case Property::HasBackground: style.has_bg = value; return true;
7952
+ #if GEA_CSS_ACTIVE_BACKGROUND
7850
7953
  case Property::ActiveBackgroundColor:
7851
7954
  style.active_bg_color = StyleValues::pixelFromStyleValue(value);
7852
7955
  return true;
7956
+ #endif
7957
+ #if GEA_CSS_ACTIVE_BACKGROUND
7853
7958
  case Property::HasActiveBackground: style.has_active_bg = value; return true;
7959
+ #endif
7854
7960
  case Property::Color:
7855
7961
  style.text_color = StyleValues::pixelFromStyleValue(value);
7856
7962
  #if GEA_CSS_TEXT_ALPHA
@@ -7890,7 +7996,8 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7890
7996
  return true;
7891
7997
  #endif
7892
7998
  case Property::BorderWidth:
7893
- setComputedBorderWidth(style, -1, value, target.parent >= 0 ? &treeState().nodes[target.parent].style : nullptr); return true;
7999
+ setComputedBorderWidth(style, -1, value, target.parent >= 0 ? &treeState().nodes[target.parent].computedStyle() : nullptr); return true;
8000
+ #if GEA_CSS_BORDER_COLORS
7894
8001
  case Property::BorderColor:
7895
8002
  setBorderColorBinding(style, -1, false);
7896
8003
  style.border_color = StyleValues::pixelFromStyleValue(value);
@@ -7898,6 +8005,7 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7898
8005
  style.border_alpha = 255;
7899
8006
  #endif
7900
8007
  return true;
8008
+ #endif
7901
8009
  #if GEA_CSS_BORDER_RELIEF
7902
8010
  case Property::BorderTopRelief:
7903
8011
  case Property::BorderRightRelief:
@@ -7913,10 +8021,10 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7913
8021
  return true;
7914
8022
  #endif
7915
8023
  #if GEA_CSS_SIDE_BORDERS
7916
- case Property::BorderTopWidth: setComputedBorderWidth(style, 0, value, target.parent >= 0 ? &treeState().nodes[target.parent].style : nullptr); return true;
7917
- case Property::BorderRightWidth: setComputedBorderWidth(style, 1, value, target.parent >= 0 ? &treeState().nodes[target.parent].style : nullptr); return true;
7918
- case Property::BorderBottomWidth: setComputedBorderWidth(style, 2, value, target.parent >= 0 ? &treeState().nodes[target.parent].style : nullptr); return true;
7919
- case Property::BorderLeftWidth: setComputedBorderWidth(style, 3, value, target.parent >= 0 ? &treeState().nodes[target.parent].style : nullptr); return true;
8024
+ case Property::BorderTopWidth: setComputedBorderWidth(style, 0, value, target.parent >= 0 ? &treeState().nodes[target.parent].computedStyle() : nullptr); return true;
8025
+ case Property::BorderRightWidth: setComputedBorderWidth(style, 1, value, target.parent >= 0 ? &treeState().nodes[target.parent].computedStyle() : nullptr); return true;
8026
+ case Property::BorderBottomWidth: setComputedBorderWidth(style, 2, value, target.parent >= 0 ? &treeState().nodes[target.parent].computedStyle() : nullptr); return true;
8027
+ case Property::BorderLeftWidth: setComputedBorderWidth(style, 3, value, target.parent >= 0 ? &treeState().nodes[target.parent].computedStyle() : nullptr); return true;
7920
8028
  case Property::BorderTopColor:
7921
8029
  setBorderColorBinding(style, 0, false);
7922
8030
  rstyleMut(style).border_side_color[0] = StyleValues::pixelFromStyleValue(value);
@@ -7982,34 +8090,50 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
7982
8090
  #endif
7983
8091
  case Property::FontId: style.font_id = value; return true;
7984
8092
  case Property::FontSize: style.font_size = value; return true;
8093
+ #if GEA_CSS_FONT_WEIGHT
7985
8094
  case Property::FontWeight: style.font_weight = value; return true;
8095
+ #endif
8096
+ #if GEA_CSS_LINE_HEIGHT
7986
8097
  case Property::LineHeight:
8098
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
7987
8099
  if (style.line_height_multiplier >= 0) style.line_height_multiplier = -1;
8100
+ #endif
7988
8101
  #if GEA_CSS_LINE_HEIGHT_EXPRESSIONS
7989
8102
  if (rstyle(style).line_height_expression >= 0) rstyleMut(style).line_height_expression = -1;
7990
8103
  #endif
7991
8104
  style.line_height = value; return true;
7992
8105
  #if GEA_CSS_LINE_HEIGHT_EXPRESSIONS
7993
8106
  case Property::LineHeightExpression:
8107
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
7994
8108
  if (style.line_height_multiplier >= 0) style.line_height_multiplier = -1;
8109
+ #endif
7995
8110
  rstyleMut(style).line_height_expression = value;
7996
8111
  style.line_height = resolveLineHeightExpression(static_cast<int>(&target - treeState().nodes), value); return true;
7997
8112
  #endif
8113
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
7998
8114
  case Property::LineHeightMultiplier:
7999
8115
  style.line_height_multiplier = value;
8000
8116
  #if GEA_CSS_LINE_HEIGHT_EXPRESSIONS
8001
8117
  if (rstyle(style).line_height_expression >= 0) rstyleMut(style).line_height_expression = -1;
8002
8118
  #endif
8003
8119
  style.line_height = resolveLineHeightMultiplier(static_cast<int>(&target - treeState().nodes), value); return true;
8120
+ #endif
8121
+ #endif
8122
+ #if GEA_CSS_TEXT_ALIGN
8004
8123
  case Property::TextAlign: style.text_align = value; return true;
8124
+ #endif
8005
8125
  #if GEA_CSS_TEXT_DECORATION
8006
8126
  case Property::TextDecoration: style.text_decoration = value; return true;
8007
8127
  #endif
8008
8128
  #if GEA_CSS_TEXT_TRANSFORM
8009
8129
  case Property::TextTransform: style.text_transform = value; return true;
8010
8130
  #endif
8131
+ #if GEA_CSS_WHITE_SPACE
8011
8132
  case Property::WhiteSpace: style.white_space = static_cast<std::int8_t>(value); return true;
8133
+ #endif
8134
+ #if GEA_CSS_TEXT_OVERFLOW
8012
8135
  case Property::TextOverflow: style.text_overflow = static_cast<std::int8_t>(value); return true;
8136
+ #endif
8013
8137
  #if GEA_CSS_TRANSFORMS
8014
8138
  case Property::TransformStyle: rstyleMut(style).transform_preserve_3d = value != 0; return true;
8015
8139
  #endif
@@ -8482,7 +8606,7 @@ bool applyTransformComponentsFast(NodeHandle node, const TransformComponents &t,
8482
8606
  const int nodeId = node.id();
8483
8607
  if (nodeId < 0 || nodeId >= state.nodeCount) return true;
8484
8608
  Node &target = state.nodes[nodeId];
8485
- const RareStyle &current = rstyle(target.style);
8609
+ const RareStyle &current = rstyle(target.computedStyle());
8486
8610
  if (current.transform_rotate_x == static_cast<int16_t>(t.rotateX) &&
8487
8611
  current.transform_rotate_y == static_cast<int16_t>(t.rotateY) &&
8488
8612
  current.transform_rotate == static_cast<int16_t>(t.rotateZ) &&
@@ -8495,7 +8619,7 @@ bool applyTransformComponentsFast(NodeHandle node, const TransformComponents &t,
8495
8619
  current.transform_scale_y == static_cast<int16_t>(t.scaleY) &&
8496
8620
  current.transform_scale_z == static_cast<int16_t>(t.scaleZ))
8497
8621
  return true;
8498
- RareStyle &rs = rstyleMut(target.style);
8622
+ RareStyle &rs = rstyleMut(target.mutableStyle());
8499
8623
  rs.transform_rotate_x = static_cast<int16_t>(t.rotateX);
8500
8624
  rs.transform_rotate_y = static_cast<int16_t>(t.rotateY);
8501
8625
  rs.transform_rotate = static_cast<int16_t>(t.rotateZ);
@@ -8551,7 +8675,7 @@ bool applyTransformSlotsFast(NodeHandle node, const std::int16_t *slots, StyleAp
8551
8675
  const int nodeId = node.id();
8552
8676
  if (nodeId < 0 || nodeId >= state.nodeCount) return true;
8553
8677
  Node &target = state.nodes[nodeId];
8554
- const RareStyle &current = rstyle(target.style);
8678
+ const RareStyle &current = rstyle(target.computedStyle());
8555
8679
  if (current.transform_rotate_x == slots[0] &&
8556
8680
  current.transform_rotate_y == slots[1] &&
8557
8681
  current.transform_rotate == slots[2] &&
@@ -8564,7 +8688,7 @@ bool applyTransformSlotsFast(NodeHandle node, const std::int16_t *slots, StyleAp
8564
8688
  current.transform_scale_y == slots[9] &&
8565
8689
  current.transform_scale_z == slots[10])
8566
8690
  return true;
8567
- RareStyle &rs = rstyleMut(target.style);
8691
+ RareStyle &rs = rstyleMut(target.mutableStyle());
8568
8692
  rs.transform_rotate_x = slots[0];
8569
8693
  rs.transform_rotate_y = slots[1];
8570
8694
  rs.transform_rotate = slots[2];
@@ -8764,7 +8888,7 @@ void applyBackgroundSizeValue(NodeHandle node, const std::string &value)
8764
8888
  {
8765
8889
  if (!node) return;
8766
8890
  Node &target = treeState().nodes[node.id()];
8767
- if (rstyle(target.style).bg_grid_axes == 0) return;
8891
+ if (rstyle(target.computedStyle()).bg_grid_axes == 0) return;
8768
8892
  const auto layers = splitTopLevel(value, ',');
8769
8893
  if (layers.empty()) return;
8770
8894
  const auto parts = splitWords(layers[0]);
@@ -8772,8 +8896,8 @@ void applyBackgroundSizeValue(NodeHandle node, const std::string &value)
8772
8896
  const int stepX = parseLengthForNode(parts[0], node.id(), LengthAxis::Horizontal);
8773
8897
  const int stepY = parseLengthForNode(parts.size() > 1 ? parts[1] : parts[0], node.id(), LengthAxis::Vertical);
8774
8898
  #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS
8775
- if (stepX > 0) rstyleMut(target.style).bg_grid_step_x = static_cast<uint16_t>(std::min(stepX, 65535));
8776
- if (stepY > 0) rstyleMut(target.style).bg_grid_step_y = static_cast<uint16_t>(std::min(stepY, 65535));
8899
+ if (stepX > 0) rstyleMut(target.mutableStyle()).bg_grid_step_x = static_cast<uint16_t>(std::min(stepX, 65535));
8900
+ if (stepY > 0) rstyleMut(target.mutableStyle()).bg_grid_step_y = static_cast<uint16_t>(std::min(stepY, 65535));
8777
8901
  #endif
8778
8902
  markNodeDisplayCommandsDirtyForStyleApply(node.id());
8779
8903
  }
@@ -8838,7 +8962,7 @@ bool applyAnimatedTransformStyleValueFast(int nodeId, Property property, int val
8838
8962
  auto &state = treeState();
8839
8963
  if (nodeId < 0 || nodeId >= state.nodeCount) return true;
8840
8964
  Node &target = state.nodes[nodeId];
8841
- RareStyle &rs = rstyleMut(target.style);
8965
+ RareStyle &rs = rstyleMut(target.mutableStyle());
8842
8966
  int16_t *slot = animatedTransformSlot(rs, property);
8843
8967
  if (!slot) return false;
8844
8968
  const int16_t next = static_cast<int16_t>(value);
@@ -8865,6 +8989,18 @@ bool applyAnimatedTransformStyleValueFast(int nodeId, Property property, int val
8865
8989
 
8866
8990
  } // namespace
8867
8991
 
8992
+ StorageUsage styleDependencyStorageUsage()
8993
+ {
8994
+ StorageUsage usage;
8995
+ #if GEA_CSS_CUSTOM_PROPERTIES
8996
+ usage.staticBytes = sizeof(g_nodeRefs) + sizeof(g_nodeRefOverflow) + sizeof(g_recordingNode) + sizeof(g_customPropertyLookupCache);
8997
+ usage.addVector(g_nodeRefOverflow);
8998
+ #elif !GEA_EMBEDDED_SHARED_STYLES
8999
+ usage.staticBytes = sizeof(g_nodeStyleTracked);
9000
+ #endif
9001
+ return usage;
9002
+ }
9003
+
8868
9004
  bool layoutSizeExpressionUsesPercentage(int nodeId, int expression)
8869
9005
  {
8870
9006
  return expression >= 0 && lengthDependsOnInput(
@@ -8892,7 +9028,7 @@ int resolveLineHeightExpression(int nodeId, int expression)
8892
9028
 
8893
9029
  int resolveLayoutFlexBasis(int nodeId, int percentageBasis, bool horizontal)
8894
9030
  {
8895
- const auto &style = treeState().nodes[nodeId].style;
9031
+ const auto &style = treeState().nodes[nodeId].computedStyle();
8896
9032
  const int expression = rstyle(style).flex_basis_expression;
8897
9033
  if (expression < 0) return style.flex_basis;
8898
9034
  if (percentageBasis < 0 && layoutSizeExpressionUsesPercentage(nodeId, expression)) return kUnset;
@@ -8908,9 +9044,9 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
8908
9044
  #if GEA_CSS_BOX_EXPRESSIONS
8909
9045
  auto &node = treeState().nodes[nodeId];
8910
9046
  #if !GEA_EMBEDDED_RARE_STYLE_INLINE
8911
- if (node.style.rare_style < 0) return false;
9047
+ if (node.computedStyle().rare_style < 0) return false;
8912
9048
  #endif
8913
- const RareStyle &rare = rstyle(node.style);
9049
+ const RareStyle &rare = rstyle(node.computedStyle());
8914
9050
  const int previous = g_boxPercentageBasis;
8915
9051
  g_boxPercentageBasis = std::max(0, percentageBasis);
8916
9052
  bool changed = false;
@@ -8923,9 +9059,13 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
8923
9059
  // Padding can have a proven unsigned byte range while margin remains
8924
9060
  // signed. Keep writes typed; the existing side choice already branches.
8925
9061
  if (padding) {
8926
- if (node.style.padding[side] != value) { node.style.padding[side] = value; changed = true; }
8927
- } else if (node.style.margin[side] != value) {
8928
- node.style.margin[side] = static_cast<int16_t>(value); changed = true;
9062
+ #if GEA_CSS_PADDING
9063
+ if (node.computedStyle().padding[side] != value) { node.mutableStyle().padding[side] = value; changed = true; }
9064
+ #endif
9065
+ } else {
9066
+ #if GEA_CSS_MARGINS
9067
+ if (node.computedStyle().margin[side] != value) { node.mutableStyle().margin[side] = static_cast<int16_t>(value); changed = true; }
9068
+ #endif
8929
9069
  }
8930
9070
  }
8931
9071
  }
@@ -8961,6 +9101,12 @@ void Style::setProperty(const std::string &property, const std::string &value) c
8961
9101
  StyleSheet::instance().applyProperty(NodeHandle(nodeId_), property, value);
8962
9102
  }
8963
9103
 
9104
+ bool Style::setNumberProperty(const std::string &property, double value) const
9105
+ {
9106
+ if (nodeId_ < 0) return false;
9107
+ return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId_), property.c_str(), value);
9108
+ }
9109
+
8964
9110
  bool Style::removeProperty(const std::string &property) const
8965
9111
  {
8966
9112
  if (nodeId_ < 0) return false;
@@ -8997,23 +9143,33 @@ void applyInheritedStyleDefaults(int node)
8997
9143
  const int parent = state.nodes[node].parent;
8998
9144
  if (parent < 0 || parent >= state.nodeCount) return;
8999
9145
 
9000
- const auto &parentStyle = state.nodes[parent].style;
9001
- auto &style = state.nodes[node].style;
9146
+ const auto &parentStyle = state.nodes[parent].computedStyle();
9147
+ auto &style = state.nodes[node].mutableStyle();
9002
9148
  style.text_color = parentStyle.text_color;
9003
9149
  #if GEA_CSS_TEXT_ALPHA
9004
9150
  style.text_alpha = parentStyle.text_alpha;
9005
9151
  #endif
9006
9152
  style.font_id = parentStyle.font_id;
9007
9153
  style.font_size = parentStyle.font_size;
9154
+ #if GEA_CSS_FONT_WEIGHT
9008
9155
  style.font_weight = parentStyle.font_weight;
9156
+ #endif
9157
+ #if GEA_CSS_LINE_HEIGHT
9009
9158
  style.line_height = parentStyle.line_height;
9159
+ #endif
9160
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
9010
9161
  if (parentStyle.line_height_multiplier >= 0)
9011
9162
  style.line_height_multiplier = parentStyle.line_height_multiplier;
9163
+ #endif
9164
+ #if GEA_CSS_TEXT_ALIGN
9012
9165
  style.text_align = parentStyle.text_align;
9166
+ #endif
9013
9167
  #if GEA_CSS_TEXT_TRANSFORM
9014
9168
  style.text_transform = parentStyle.text_transform;
9015
9169
  #endif
9170
+ #if GEA_CSS_WHITE_SPACE
9016
9171
  style.white_space = parentStyle.white_space;
9172
+ #endif
9017
9173
  #if GEA_CSS_VISIBILITY
9018
9174
  style.visibility = parentStyle.visibility;
9019
9175
  #endif
@@ -9190,7 +9346,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9190
9346
  if (placement != Property::Count) {
9191
9347
  const int parent = Tree::instance().node(nodeId).parent;
9192
9348
  const int handle = toLowerAscii(trimCssValue(value)) == "inherit"
9193
- ? (parent >= 0 ? backgroundPlacementHandle(Tree::instance().node(parent).style, placement) : -1)
9349
+ ? (parent >= 0 ? backgroundPlacementHandle(Tree::instance().node(parent).computedStyle(), placement) : -1)
9194
9350
  : compileBackgroundPlacement(declaration, value);
9195
9351
  if (handle >= -1) setStyleValue(node, placement, handle, source);
9196
9352
  return true;
@@ -9241,7 +9397,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9241
9397
  case CssDeclarationId::BackgroundClip: {
9242
9398
  const int parent = Tree::instance().node(nodeId).parent;
9243
9399
  const int clip = toLowerAscii(trimCssValue(value)) == "inherit"
9244
- ? (parent >= 0 ? rstyle(Tree::instance().node(parent).style).bg_clip : 0)
9400
+ ? (parent >= 0 ? rstyle(Tree::instance().node(parent).computedStyle()).bg_clip : 0)
9245
9401
  : compileBackgroundClip(value);
9246
9402
  if (clip >= 0) setStyleValue(node, Property::BackgroundClip, clip, source);
9247
9403
  return true;
@@ -9249,7 +9405,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9249
9405
  case CssDeclarationId::Contain: {
9250
9406
  const int parent = Tree::instance().node(nodeId).parent;
9251
9407
  const int flags = toLowerAscii(trimCssValue(value)) == "inherit"
9252
- ? (parent >= 0 ? (GEA_CSS_CONTAINMENT ? rstyle(Tree::instance().node(parent).style).containment : 0) : 0)
9408
+ ? (parent >= 0 ? (GEA_CSS_CONTAINMENT ? rstyle(Tree::instance().node(parent).computedStyle()).containment : 0) : 0)
9253
9409
  : containmentValue(value);
9254
9410
  if (flags >= 0) setStyleValue(node, Property::Containment, flags, source);
9255
9411
  return true;
@@ -9263,7 +9419,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9263
9419
  }
9264
9420
  if (ratio == "inherit") {
9265
9421
  const int parent = Tree::instance().node(nodeId).parent;
9266
- setStyleValue(node, Property::AspectRatio, parent >= 0 ? (GEA_CSS_ASPECT_RATIO ? rstyle(Tree::instance().node(parent).style).aspect_ratio : 0) : 0, source);
9422
+ setStyleValue(node, Property::AspectRatio, parent >= 0 ? (GEA_CSS_ASPECT_RATIO ? rstyle(Tree::instance().node(parent).computedStyle()).aspect_ratio : 0) : 0, source);
9267
9423
  return true;
9268
9424
  }
9269
9425
  const auto words = splitFunctionAwareWords(ratio);
@@ -9314,7 +9470,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9314
9470
  case CssDeclarationId::MarginTrim: {
9315
9471
  const int parent = Tree::instance().node(nodeId).parent;
9316
9472
  const int flags = toLowerAscii(trimCssValue(value)) == "inherit"
9317
- ? (parent >= 0 ? (GEA_CSS_MARGIN_TRIM ? rstyle(Tree::instance().node(parent).style).margin_trim : 0) : 0)
9473
+ ? (parent >= 0 ? (GEA_CSS_MARGIN_TRIM ? rstyle(Tree::instance().node(parent).computedStyle()).margin_trim : 0) : 0)
9318
9474
  : marginTrimValue(value);
9319
9475
  if (flags >= 0) setStyleValue(node, Property::MarginTrim, flags, source);
9320
9476
  return true;
@@ -9390,7 +9546,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9390
9546
  case CssDeclarationId::FlexWrap:
9391
9547
  if (value == "inherit") {
9392
9548
  const int parent = Tree::instance().node(nodeId).parent;
9393
- setStyleValue(node, Property::FlexWrap, parent >= 0 ? Tree::instance().node(parent).style.flex_wrap : 0, source);
9549
+ setStyleValue(node, Property::FlexWrap, parent >= 0 ? Tree::instance().node(parent).computedStyle().flex_wrap : 0, source);
9394
9550
  } else if (flexWrapValue(value) >= 0) setStyleValue(node, Property::FlexWrap, flexWrapValue(value), source);
9395
9551
  return true;
9396
9552
  case CssDeclarationId::FlexLineCount: {
@@ -9398,7 +9554,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9398
9554
  if (value == "initial" || value == "unset") setStyleValue(node, Property::FlexLineCount, 1, source);
9399
9555
  else if (value == "inherit") {
9400
9556
  const int parent = Tree::instance().node(nodeId).parent;
9401
- setStyleValue(node, Property::FlexLineCount, parent >= 0 ? (GEA_CSS_FLEX_LINE_COUNT ? rstyle(Tree::instance().node(parent).style).flex_line_count : 1) : 1, source);
9557
+ setStyleValue(node, Property::FlexLineCount, parent >= 0 ? (GEA_CSS_FLEX_LINE_COUNT ? rstyle(Tree::instance().node(parent).computedStyle()).flex_line_count : 1) : 1, source);
9402
9558
  } else if (parseOrder(value, count) && count >= 1) setStyleValue(node, Property::FlexLineCount, count, source);
9403
9559
  return true;
9404
9560
  }
@@ -9437,7 +9593,7 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9437
9593
  if (parent < 0) {
9438
9594
  align = justify = declaration == CssDeclarationId::PlaceSelf ? -1 : 0;
9439
9595
  } else {
9440
- const auto &inherited = Tree::instance().node(parent).style;
9596
+ const auto &inherited = Tree::instance().node(parent).computedStyle();
9441
9597
  align = declaration == CssDeclarationId::PlaceItems ? inherited.align_items : declaration == CssDeclarationId::PlaceContent ? inherited.align_content : inherited.align_self;
9442
9598
  justify = declaration == CssDeclarationId::PlaceItems ? inherited.justify_items : declaration == CssDeclarationId::PlaceContent ? inherited.justify_content : (GEA_CSS_JUSTIFY_SELF ? rstyle(inherited).justify_self : -1);
9443
9599
  }
@@ -9939,8 +10095,8 @@ bool applyCompiledColorValue(NodeHandle node,
9939
10095
  Node &target = treeState().nodes[nodeId];
9940
10096
  switch (declaration) {
9941
10097
  case CssDeclarationId::Color:
9942
- if (source == StyleApplicationSource::ClassRule && target.style.text_color == static_cast<style_color_t>(nativeColor) &&
9943
- target.style.text_alpha == static_cast<std::uint8_t>(alpha))
10098
+ if (source == StyleApplicationSource::ClassRule && target.computedStyle().text_color == static_cast<style_color_t>(nativeColor) &&
10099
+ target.computedStyle().text_alpha == static_cast<std::uint8_t>(alpha))
9944
10100
  return true;
9945
10101
  setStyleValueKnownTarget(node, target, Property::Color, styleColor, source);
9946
10102
  #if GEA_CSS_TEXT_ALPHA
@@ -9966,8 +10122,8 @@ bool applyCompiledColorValue(NodeHandle node,
9966
10122
  markNodeDisplayCommandsDirtyForStyleApply(nodeId);
9967
10123
  return true;
9968
10124
  case CssDeclarationId::BorderColor:
9969
- if (source == StyleApplicationSource::ClassRule && target.style.border_color_flags == 16u && target.style.border_color == static_cast<style_color_t>(nativeColor) &&
9970
- target.style.border_alpha == static_cast<std::uint8_t>(alpha))
10125
+ if (source == StyleApplicationSource::ClassRule && target.computedStyle().border_color_flags == 16u && target.computedStyle().border_color == static_cast<style_color_t>(nativeColor) &&
10126
+ target.computedStyle().border_alpha == static_cast<std::uint8_t>(alpha))
9971
10127
  return true;
9972
10128
  setStyleValueKnownTarget(node, target, Property::BorderColor, styleColor, source);
9973
10129
  #if GEA_CSS_BORDER_ALPHA
@@ -9982,8 +10138,8 @@ bool applyCompiledColorValue(NodeHandle node,
9982
10138
  const int side = declaration == CssDeclarationId::BorderTopColor ? 0 :
9983
10139
  declaration == CssDeclarationId::BorderRightColor ? 1 :
9984
10140
  declaration == CssDeclarationId::BorderBottomColor ? 2 : 3;
9985
- const RareStyle &current = rstyle(target.style);
9986
- if (source == StyleApplicationSource::ClassRule && (target.style.border_color_flags & (1u << side)) && !borderColorIsCurrent(target.style, side) && current.border_side_color[side] == static_cast<style_color_t>(nativeColor) &&
10141
+ const RareStyle &current = rstyle(target.computedStyle());
10142
+ if (source == StyleApplicationSource::ClassRule && (target.computedStyle().border_color_flags & (1u << side)) && !borderColorIsCurrent(target.computedStyle(), side) && current.border_side_color[side] == static_cast<style_color_t>(nativeColor) &&
9987
10143
  current.border_side_alpha[side] == static_cast<std::uint8_t>(alpha))
9988
10144
  return true;
9989
10145
  setStyleValueKnownTarget(node, target, borderSideColorProperty(side), styleColor, source);
@@ -10493,10 +10649,10 @@ bool applyRuntimeBackgroundSizeValue(NodeHandle node,
10493
10649
  auto &state = treeState();
10494
10650
  if (nodeId < 0 || nodeId >= state.nodeCount) return true;
10495
10651
  Node &target = state.nodes[nodeId];
10496
- if (rstyle(target.style).bg_grid_axes == 0) return true;
10652
+ if (rstyle(target.computedStyle()).bg_grid_axes == 0) return true;
10497
10653
  const int stepX = resolveCompiledLengthForNode(stepXLength, nodeId, LengthAxis::Horizontal);
10498
10654
  const int stepY = resolveCompiledLengthForNode(stepYLength, nodeId, LengthAxis::Vertical);
10499
- RareStyle &rs = rstyleMut(target.style);
10655
+ RareStyle &rs = rstyleMut(target.mutableStyle());
10500
10656
  #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS
10501
10657
  if (stepX > 0) rs.bg_grid_step_x = static_cast<std::uint16_t>(std::min(stepX, 65535));
10502
10658
  if (stepY > 0) rs.bg_grid_step_y = static_cast<std::uint16_t>(std::min(stepY, 65535));
@@ -10990,6 +11146,37 @@ const CssCompiledValue *inlineCompiledStyleValueFor(CssDeclarationId declaration
10990
11146
  #endif
10991
11147
  }
10992
11148
 
11149
+ // Unitless integers use rawNumber, exactly as parseLengthForNode does.
11150
+ // Units, fractions, expressions and values outside this exact range retain
11151
+ // the general parser (including px device-pixel-ratio conversion).
11152
+ bool applyIntegerPosition(NodeHandle node, CssDeclarationId declaration,
11153
+ const std::string &text, StyleApplicationSource source)
11154
+ {
11155
+ Property property;
11156
+ switch (declaration) {
11157
+ case CssDeclarationId::Top: property = Property::Top; break;
11158
+ case CssDeclarationId::Right: property = Property::Right; break;
11159
+ case CssDeclarationId::Bottom: property = Property::Bottom; break;
11160
+ case CssDeclarationId::Left: property = Property::Left; break;
11161
+ default: return false;
11162
+ }
11163
+ if (text.empty()) return false;
11164
+ std::size_t index = (text[0] == '-' || text[0] == '+') ? 1 : 0;
11165
+ if (index == text.size()) return false;
11166
+ int value = 0;
11167
+ for (; index < text.size(); ++index) {
11168
+ const unsigned digit = static_cast<unsigned char>(text[index]) - '0';
11169
+ if (digit > 9) return false;
11170
+ value = value * 10 + static_cast<int>(digit);
11171
+ if (value > 32767) return false;
11172
+ }
11173
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
11174
+ refreshPerfStatsMutable().treeIntegerPositionFastCalls++;
11175
+ #endif
11176
+ setStyleValue(node, property, rawNumber(text[0] == '-' ? -value : value), source);
11177
+ return true;
11178
+ }
11179
+
10993
11180
  void applyPropertyWithSource(NodeHandle node,
10994
11181
  CssDeclarationId declaration,
10995
11182
  const std::string &rawValue,
@@ -10998,6 +11185,7 @@ void applyPropertyWithSource(NodeHandle node,
10998
11185
  if (!node) return;
10999
11186
  const int nodeId = node.id();
11000
11187
  if (declaration == CssDeclarationId::Unknown) return;
11188
+ if (applyIntegerPosition(node, declaration, rawValue, source)) return;
11001
11189
  #if GEA_CSS_GRID
11002
11190
  if (source == StyleApplicationSource::Inline &&
11003
11191
  (declaration == CssDeclarationId::GridTemplateColumns || declaration == CssDeclarationId::GridTemplateRows ||
@@ -11151,6 +11339,7 @@ bool removeInlineStyleProperty(NodeHandle node, const std::string &property)
11151
11339
  {
11152
11340
  if (!node) return false;
11153
11341
  if (property.rfind("--", 0) == 0) {
11342
+ #if GEA_CSS_CUSTOM_PROPERTIES
11154
11343
  NodeRareData *rare = rareDataFor(node.id());
11155
11344
  if (!rare) return false;
11156
11345
  auto &values = rare->inlineCustomProperties.values;
@@ -11160,6 +11349,9 @@ bool removeInlineStyleProperty(NodeHandle node, const std::string &property)
11160
11349
  values.erase(end, values.end());
11161
11350
  recomputeSubtreeClassStyles(node.id());
11162
11351
  return true;
11352
+ #else
11353
+ return false;
11354
+ #endif
11163
11355
  }
11164
11356
  const int id = node.id();
11165
11357
  #if GEA_CSS_GRID
@@ -12429,7 +12621,10 @@ int ensurePseudoChild(int parent, CssRule::PseudoElement pseudo)
12429
12621
 
12430
12622
  #endif
12431
12623
 
12432
- static constexpr std::size_t kRuleCandidateCacheClassCapacity = 6;
12624
+ // The class-list proof also bounds cache keys. Unknown/overflow-capable apps
12625
+ // retain the six-token fast key and the existing uncached fallback beyond it.
12626
+ static constexpr std::size_t kRuleCandidateCacheClassCapacity =
12627
+ GEA_UI_CLASS_OVERFLOW ? 6 : std::min<std::size_t>(6, GEA_UI_CLASS_INLINE_TOKENS);
12433
12628
 
12434
12629
  struct RuleCandidateSignature {
12435
12630
  CssAtomId classes[kRuleCandidateCacheClassCapacity]{};
@@ -12850,16 +13045,24 @@ CssAtomId nodeIdAttributeAtom(int node)
12850
13045
  }
12851
13046
 
12852
13047
  enum ActiveRuleBucket : std::uint8_t {
13048
+ #if GEA_CSS_CUSTOM_PROPERTIES
12853
13049
  kActiveMainCustom,
13050
+ #endif
12854
13051
  kActiveMainRule,
12855
13052
  #if GEA_CSS_PSEUDO_ELEMENTS
13053
+ #if GEA_CSS_CUSTOM_PROPERTIES
12856
13054
  kActiveBeforeCustom,
13055
+ #endif
12857
13056
  kActiveBeforeRule,
13057
+ #if GEA_CSS_CUSTOM_PROPERTIES
12858
13058
  kActiveAfterCustom,
13059
+ #endif
12859
13060
  kActiveAfterRule,
12860
13061
  #endif
12861
13062
  #if GEA_CSS_FIRST_LINE
13063
+ #if GEA_CSS_CUSTOM_PROPERTIES
12862
13064
  kActiveFirstLineCustom,
13065
+ #endif
12863
13066
  kActiveFirstLineRule,
12864
13067
  #endif
12865
13068
  #if GEA_CSS_ANIMATIONS
@@ -12868,6 +13071,19 @@ enum ActiveRuleBucket : std::uint8_t {
12868
13071
  kActiveRuleBucketCount
12869
13072
  };
12870
13073
 
13074
+ #if !GEA_CSS_CUSTOM_PROPERTIES
13075
+ // Bucket readers already treat negative IDs as empty. Keep that contract
13076
+ // without reserving a bucket, count or offset for an absent CSS feature.
13077
+ static constexpr int kActiveMainCustom = -1;
13078
+ #if GEA_CSS_PSEUDO_ELEMENTS
13079
+ static constexpr int kActiveBeforeCustom = -1;
13080
+ static constexpr int kActiveAfterCustom = -1;
13081
+ #endif
13082
+ #if GEA_CSS_FIRST_LINE
13083
+ static constexpr int kActiveFirstLineCustom = -1;
13084
+ #endif
13085
+ #endif
13086
+
12871
13087
  struct ActiveRulePlanCacheEntry;
12872
13088
 
12873
13089
  struct ActiveRulePlan {
@@ -15083,8 +15299,8 @@ bool applyCachedStyleApplyOpWithSource(NodeHandle node,
15083
15299
  auto &state = treeState();
15084
15300
  if (nodeId < 0 || nodeId >= state.nodeCount) return true;
15085
15301
  Node &target = state.nodes[nodeId];
15086
- if (rstyle(target.style).bg_grid_axes == 0) return true;
15087
- RareStyle &rs = rstyleMut(target.style);
15302
+ if (rstyle(target.computedStyle()).bg_grid_axes == 0) return true;
15303
+ RareStyle &rs = rstyleMut(target.mutableStyle());
15088
15304
  #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS
15089
15305
  if (op.values[0] > 0) rs.bg_grid_step_x = static_cast<std::uint16_t>(op.values[0]);
15090
15306
  if (op.values[1] > 0) rs.bg_grid_step_y = static_cast<std::uint16_t>(op.values[1]);
@@ -15291,7 +15507,11 @@ void applyActiveRuleSpanToNode(int node, const ActiveRulePlan &plan, int bucketI
15291
15507
 
15292
15508
  void applyActiveRuleSpansToNode(int node, const ActiveRulePlan &plan, int customBucket, int ruleBucket)
15293
15509
  {
15510
+ #if GEA_CSS_CUSTOM_PROPERTIES
15294
15511
  applyActiveRuleSpanToNode(node, plan, customBucket);
15512
+ #else
15513
+ (void)customBucket;
15514
+ #endif
15295
15515
  // Resolve the font cascade before any property consumes its metrics. Keep
15296
15516
  // the winning font fixed while replaying the ordinary cascade so intervening
15297
15517
  // font declarations cannot change the basis of a padding/line-height/length.
@@ -15306,9 +15526,11 @@ void applyActiveRuleSpansToNode(int node, const ActiveRulePlan &plan, int custom
15306
15526
  g_resolvedFontNode = node;
15307
15527
  // Inherited unitless numbers are resolved against this element's final font.
15308
15528
  // Lengths and percentages inherit their already-computed pixel value.
15309
- auto &style = treeState().nodes[node].style;
15529
+ auto &style = treeState().nodes[node].mutableStyle();
15530
+ #if GEA_CSS_LINE_HEIGHT
15310
15531
  if (style.line_height_multiplier >= 0)
15311
15532
  style.line_height = resolveLineHeightMultiplier(node, style.line_height_multiplier);
15533
+ #endif
15312
15534
  // lh consumers need the winning line-height, evaluated using the final font.
15313
15535
  applyActiveRuleSpanToNode(node, plan, ruleBucket, 2);
15314
15536
  if (const NodeRareData *rd = rareDataFor(node))
@@ -15425,9 +15647,9 @@ void syncPseudoElementsForNode(int node, const ActiveRulePlan &plan)
15425
15647
  if (pseudoNode < 0) continue;
15426
15648
  if (NodeRareData *rd = rareDataFor(pseudoNode)) rd->customProperties.clear();
15427
15649
  clearCustomPropertyLookupCache();
15428
- int16_t staleRareStyle = treeState().nodes[pseudoNode].style.rare_style;
15650
+ int16_t staleRareStyle = treeState().nodes[pseudoNode].computedStyle().rare_style;
15429
15651
  Tree::instance().resetStyleForClassRecompute(pseudoNode);
15430
- if (staleRareStyle >= 0 && treeState().nodes[pseudoNode].style.rare_style != staleRareStyle)
15652
+ if (staleRareStyle >= 0 && treeState().nodes[pseudoNode].computedStyle().rare_style != staleRareStyle)
15431
15653
  releaseRareStyle(staleRareStyle);
15432
15654
  applyInheritedStyleDefaults(pseudoNode);
15433
15655
  applyDefaultStyleOverrides(pseudoNode);
@@ -15443,7 +15665,7 @@ void recomputeNodeClassStyles(int node)
15443
15665
  auto &state = treeState();
15444
15666
  if (node < 0 || node >= state.nodeCount) return;
15445
15667
 
15446
- const ComputedStyle beforeStyle = state.nodes[node].style;
15668
+ const ComputedStyle beforeStyle = state.nodes[node].computedStyle();
15447
15669
  #if GEA_CSS_FIRST_LINE
15448
15670
  const FirstLineBackground beforeFirstLine = rareDataFor(node)
15449
15671
  ? rareDataFor(node)->firstLineBackground : FirstLineBackground{};
@@ -15454,9 +15676,17 @@ void recomputeNodeClassStyles(int node)
15454
15676
  // Record this node's custom-property dependencies fresh (lookupCustomProperty
15455
15677
  // appends into g_nodeRefs[g_recordingNode] for every var() resolved here,
15456
15678
  // including the node's pseudo-elements via syncPseudoElementsForNode below).
15679
+ #if GEA_CSS_CUSTOM_PROPERTIES
15457
15680
  const int prevRecordingNode = g_recordingNode;
15458
15681
  g_recordingNode = node;
15682
+ #endif
15683
+ #if GEA_CSS_CUSTOM_PROPERTIES
15459
15684
  if (node >= 0 && node < kMaxNodes) g_nodeRefs[node].clearForRecompute();
15685
+ #elif GEA_EMBEDDED_SHARED_STYLES
15686
+ state.nodes[node].class_style_tracked = true;
15687
+ #else
15688
+ g_nodeStyleTracked[node] = true;
15689
+ #endif
15460
15690
  #if GEA_RECPROF
15461
15691
  g_profNodes++;
15462
15692
  int64_t _t = recNow();
@@ -15513,7 +15743,7 @@ void recomputeNodeClassStyles(int node)
15513
15743
  #endif
15514
15744
  state.styleInvalidationSuppressionDepth--;
15515
15745
  markClassRecomputeStyleDiff(node, beforeStyle, beforeImageId, firstLineChanged);
15516
- if (staleRareStyle >= 0 && state.nodes[node].style.rare_style != staleRareStyle)
15746
+ if (staleRareStyle >= 0 && state.nodes[node].computedStyle().rare_style != staleRareStyle)
15517
15747
  releaseRareStyle(staleRareStyle);
15518
15748
  #if GEA_RECPROF
15519
15749
  g_profMiscUs += recNow() - _t;
@@ -15527,7 +15757,10 @@ void recomputeNodeClassStyles(int node)
15527
15757
  #if GEA_RECPROF
15528
15758
  g_profPseudoUs += recNow() - _t;
15529
15759
  #endif
15760
+ state.nodes[node].internComputedStyle();
15761
+ #if GEA_CSS_CUSTOM_PROPERTIES
15530
15762
  g_recordingNode = prevRecordingNode;
15763
+ #endif
15531
15764
  }
15532
15765
 
15533
15766
  // When set (during the initial app mount), per-op class-style recomputes are
@@ -15582,16 +15815,36 @@ struct ParentStyleSnapshot {
15582
15815
  #endif
15583
15816
  std::int16_t font_id;
15584
15817
  decltype(ComputedStyle::font_size) font_size;
15818
+ #if GEA_CSS_FONT_WEIGHT
15585
15819
  std::int16_t font_weight;
15820
+ #else
15821
+ static constexpr std::int16_t font_weight = 400;
15822
+ #endif
15823
+ #if GEA_CSS_LINE_HEIGHT
15586
15824
  decltype(ComputedStyle::line_height) line_height;
15825
+ #else
15826
+ static constexpr std::int16_t line_height = 0;
15827
+ #endif
15828
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
15587
15829
  std::int32_t line_height_multiplier;
15830
+ #else
15831
+ static constexpr std::int32_t line_height_multiplier = -1;
15832
+ #endif
15833
+ #if GEA_CSS_TEXT_ALIGN
15588
15834
  std::uint8_t text_align;
15835
+ #else
15836
+ static constexpr std::uint8_t text_align = 0;
15837
+ #endif
15589
15838
  #if GEA_CSS_TEXT_TRANSFORM
15590
15839
  std::uint8_t text_transform;
15591
15840
  #else
15592
15841
  static constexpr std::uint8_t text_transform = 0;
15593
15842
  #endif
15843
+ #if GEA_CSS_WHITE_SPACE
15594
15844
  std::uint8_t white_space;
15845
+ #else
15846
+ static constexpr std::uint8_t white_space = 0;
15847
+ #endif
15595
15848
  #if GEA_CSS_VISIBILITY
15596
15849
  std::uint8_t visibility;
15597
15850
  #else
@@ -15600,7 +15853,7 @@ struct ParentStyleSnapshot {
15600
15853
  #if GEA_CSS_SIDE_BORDERS
15601
15854
  std::array<int, 4> border_widths;
15602
15855
  #else
15603
- std::array<decltype(ComputedStyle::border_width), 1> border_widths;
15856
+ std::array<std::remove_cv_t<decltype(ComputedStyle::border_width)>, 1> border_widths;
15604
15857
  #endif
15605
15858
  };
15606
15859
 
@@ -15613,14 +15866,24 @@ ParentStyleSnapshot snapshotParentStyle(const ComputedStyle &s)
15613
15866
  #endif
15614
15867
  out.font_id = s.font_id;
15615
15868
  out.font_size = s.font_size;
15869
+ #if GEA_CSS_FONT_WEIGHT
15616
15870
  out.font_weight = s.font_weight;
15871
+ #endif
15872
+ #if GEA_CSS_LINE_HEIGHT
15617
15873
  out.line_height = s.line_height;
15874
+ #endif
15875
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
15618
15876
  out.line_height_multiplier = s.line_height_multiplier;
15877
+ #endif
15878
+ #if GEA_CSS_TEXT_ALIGN
15619
15879
  out.text_align = s.text_align;
15880
+ #endif
15620
15881
  #if GEA_CSS_TEXT_TRANSFORM
15621
15882
  out.text_transform = s.text_transform;
15622
15883
  #endif
15884
+ #if GEA_CSS_WHITE_SPACE
15623
15885
  out.white_space = s.white_space;
15886
+ #endif
15624
15887
  #if GEA_CSS_VISIBILITY
15625
15888
  out.visibility = s.visibility;
15626
15889
  #endif
@@ -15866,9 +16129,18 @@ void recomputeNodeIncremental(int node, const CssAtomSmallList &changedAbove, bo
15866
16129
  if (node < 0 || node >= state.nodeCount) return;
15867
16130
  if (isGeneratedPseudoNode(state.nodes[node])) return;
15868
16131
 
16132
+ #if GEA_CSS_CUSTOM_PROPERTIES
15869
16133
  const NodeCustomPropRefs &refs = g_nodeRefs[node];
15870
16134
  const bool tracked = refs.tracked;
15871
16135
  const bool referencesChanged = refs.touches(changedAbove);
16136
+ #else
16137
+ #if GEA_EMBEDDED_SHARED_STYLES
16138
+ const bool tracked = state.nodes[node].class_style_tracked;
16139
+ #else
16140
+ const bool tracked = g_nodeStyleTracked[node];
16141
+ #endif
16142
+ constexpr bool referencesChanged = false;
16143
+ #endif
15872
16144
  const bool directlyChanged = pending.contains(node);
15873
16145
  // A never-recorded node (e.g. freshly created this batch) must recompute — we
15874
16146
  // have no dependency info to justify skipping it.
@@ -15888,15 +16160,15 @@ void recomputeNodeIncremental(int node, const CssAtomSmallList &changedAbove, bo
15888
16160
  #if GEA_INCREMENTAL_VERIFY
15889
16161
  g_incrRecomputedNodes.insert(node);
15890
16162
  #endif
15891
- const ParentStyleSnapshot before = snapshotParentStyle(state.nodes[node].style);
16163
+ const ParentStyleSnapshot before = snapshotParentStyle(state.nodes[node].computedStyle());
15892
16164
  CustomPropertySnapshot beforeCustom;
15893
16165
  snapshotCustomProperties(rareDataFor(node), beforeCustom);
15894
16166
  recomputeNodeClassStyles(node);
15895
- inheritablesChanged = parentStylesDiffer(before, snapshotParentStyle(state.nodes[node].style));
16167
+ inheritablesChanged = parentStylesDiffer(before, snapshotParentStyle(state.nodes[node].computedStyle()));
15896
16168
  // Reconcile the cascaded custom-property set for descendants: a (re)defined
15897
16169
  // property whose value changed is now changed for them; one whose value is
15898
16170
  // unchanged shadows any same-named change from above; a removed one un-shadows.
15899
- static const std::vector<NodeCustomProperty> kNoCustomProps;
16171
+ static const NodeCustomPropertyStore::Values kNoCustomProps;
15900
16172
  const NodeRareData *rdCustomAfter = rareDataFor(node);
15901
16173
  const auto &afterCustom = rdCustomAfter ? rdCustomAfter->customProperties.values : kNoCustomProps;
15902
16174
  for (const auto &kv : afterCustom) {
@@ -15938,7 +16210,7 @@ void collectSubtreeStyles(int node, std::vector<int> &ids, std::vector<ComputedS
15938
16210
  auto &state = treeState();
15939
16211
  if (node < 0 || node >= state.nodeCount) return;
15940
16212
  ids.push_back(node);
15941
- styles.push_back(state.nodes[node].style);
16213
+ styles.push_back(state.nodes[node].computedStyle());
15942
16214
  imageIds.push_back(state.nodes[node].image_id);
15943
16215
  for (int child = state.nodes[node].first_child; child >= 0; child = state.nodes[child].next_sibling)
15944
16216
  collectSubtreeStyles(child, ids, styles, imageIds);
@@ -15957,9 +16229,17 @@ void syncNodeClassAttribute(int node)
15957
16229
  void recomputeAllClassStyles()
15958
16230
  {
15959
16231
  auto &state = treeState();
16232
+ #if GEA_CSS_CUSTOM_PROPERTIES
15960
16233
  g_nodeRefOverflow.clear();
16234
+ #endif
15961
16235
  clearCustomPropertyLookupCache();
16236
+ #if GEA_CSS_CUSTOM_PROPERTIES
15962
16237
  for (auto &refs : g_nodeRefs) refs.reset();
16238
+ #elif GEA_EMBEDDED_SHARED_STYLES
16239
+ for (auto &node : treeState().nodes) node.class_style_tracked = false;
16240
+ #else
16241
+ std::fill(std::begin(g_nodeStyleTracked), std::end(g_nodeStyleTracked), false);
16242
+ #endif
15963
16243
  for (int i = 0; i < state.nodeCount; i++) {
15964
16244
  if (state.nodes[i].parent < 0) recomputeSubtreeClassStyles(i);
15965
16245
  }
@@ -16308,52 +16588,52 @@ double currentStyleValue(const Node &node, Property property)
16308
16588
  {
16309
16589
  switch (property) {
16310
16590
  #if GEA_CSS_TRANSFORMS
16311
- case Property::TransformRotate: return static_cast<double>(rstyle(node.style).transform_rotate) / 10.0;
16312
- case Property::TransformRotateX: return static_cast<double>(rstyle(node.style).transform_rotate_x) / 10.0;
16313
- case Property::TransformRotateY: return static_cast<double>(rstyle(node.style).transform_rotate_y) / 10.0;
16314
- case Property::TransformTranslateOuterAxes: return rstyle(node.style).transform_translate_outer_axes;
16315
- case Property::RotateAngle: return static_cast<double>(rstyle(node.style).rotate_angle) / 10.0;
16316
- case Property::RotateAxisX: return rstyle(node.style).rotate_axis_x;
16317
- case Property::RotateAxisY: return rstyle(node.style).rotate_axis_y;
16318
- case Property::RotateAxisZ: return rstyle(node.style).rotate_axis_z;
16319
- case Property::ScaleX: return rstyle(node.style).scale_x;
16320
- case Property::ScaleY: return rstyle(node.style).scale_y;
16321
- case Property::ScaleZ: return rstyle(node.style).scale_z;
16322
- case Property::RotatePresent: return rstyle(node.style).rotate_present;
16323
- case Property::ScalePresent: return rstyle(node.style).scale_present;
16324
- case Property::TranslatePresent: return rstyle(node.style).translate_present;
16325
- case Property::TranslateX: return rstyle(node.style).translate_x;
16326
- case Property::TranslateY: return rstyle(node.style).translate_y;
16327
- case Property::TranslateZ: return rstyle(node.style).translate_z;
16328
- case Property::TranslateXPercent: return rstyle(node.style).translate_x_percent;
16329
- case Property::TranslateYPercent: return rstyle(node.style).translate_y_percent;
16330
- case Property::TransformTranslateX: return rstyle(node.style).transform_translate_x;
16331
- case Property::TransformTranslateY: return rstyle(node.style).transform_translate_y;
16332
- case Property::TransformTranslateZ: return rstyle(node.style).transform_translate_z;
16333
- case Property::TransformTranslateXPercent: return rstyle(node.style).transform_translate_x_percent;
16334
- case Property::TransformTranslateYPercent: return rstyle(node.style).transform_translate_y_percent;
16335
- case Property::TransformScaleX: return rstyle(node.style).transform_scale_x;
16336
- case Property::TransformScaleY: return rstyle(node.style).transform_scale_y;
16337
- case Property::TransformScaleZ: return rstyle(node.style).transform_scale_z;
16338
- #endif
16339
- case Property::FilterBlur: return (GEA_CSS_FILTERS ? rstyle(node.style).filter_blur_radius : 0);
16340
- case Property::Opacity: return node.style.opacity;
16341
- case Property::Width: return node.style.width;
16342
- case Property::Height: return node.style.height;
16343
- case Property::WidthPercent: return node.style.width_percent == kUnset ? 0 : node.style.width_percent;
16344
- case Property::HeightPercent: return node.style.height_percent == kUnset ? 0 : node.style.height_percent;
16345
- case Property::LineHeight: return node.style.line_height;
16346
- case Property::FontWeight: return node.style.font_weight;
16347
- case Property::Top: return GEA_CSS_POSITION_PX_0(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PX_0(node.style);
16348
- case Property::Right: return GEA_CSS_POSITION_PX_1(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PX_1(node.style);
16349
- case Property::Bottom: return GEA_CSS_POSITION_PX_2(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PX_2(node.style);
16350
- case Property::Left: return GEA_CSS_POSITION_PX_3(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PX_3(node.style);
16351
- case Property::TopPercent: return GEA_CSS_POSITION_PERCENT_0(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_0(node.style);
16352
- case Property::RightPercent: return GEA_CSS_POSITION_PERCENT_1(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_1(node.style);
16353
- case Property::BottomPercent: return GEA_CSS_POSITION_PERCENT_2(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_2(node.style);
16354
- case Property::LeftPercent: return GEA_CSS_POSITION_PERCENT_3(node.style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_3(node.style);
16355
- case Property::BackgroundColor: return node.style.bg_color;
16356
- case Property::Color: return node.style.text_color;
16591
+ case Property::TransformRotate: return static_cast<double>(rstyle(node.computedStyle()).transform_rotate) / 10.0;
16592
+ case Property::TransformRotateX: return static_cast<double>(rstyle(node.computedStyle()).transform_rotate_x) / 10.0;
16593
+ case Property::TransformRotateY: return static_cast<double>(rstyle(node.computedStyle()).transform_rotate_y) / 10.0;
16594
+ case Property::TransformTranslateOuterAxes: return rstyle(node.computedStyle()).transform_translate_outer_axes;
16595
+ case Property::RotateAngle: return static_cast<double>(rstyle(node.computedStyle()).rotate_angle) / 10.0;
16596
+ case Property::RotateAxisX: return rstyle(node.computedStyle()).rotate_axis_x;
16597
+ case Property::RotateAxisY: return rstyle(node.computedStyle()).rotate_axis_y;
16598
+ case Property::RotateAxisZ: return rstyle(node.computedStyle()).rotate_axis_z;
16599
+ case Property::ScaleX: return rstyle(node.computedStyle()).scale_x;
16600
+ case Property::ScaleY: return rstyle(node.computedStyle()).scale_y;
16601
+ case Property::ScaleZ: return rstyle(node.computedStyle()).scale_z;
16602
+ case Property::RotatePresent: return rstyle(node.computedStyle()).rotate_present;
16603
+ case Property::ScalePresent: return rstyle(node.computedStyle()).scale_present;
16604
+ case Property::TranslatePresent: return rstyle(node.computedStyle()).translate_present;
16605
+ case Property::TranslateX: return rstyle(node.computedStyle()).translate_x;
16606
+ case Property::TranslateY: return rstyle(node.computedStyle()).translate_y;
16607
+ case Property::TranslateZ: return rstyle(node.computedStyle()).translate_z;
16608
+ case Property::TranslateXPercent: return rstyle(node.computedStyle()).translate_x_percent;
16609
+ case Property::TranslateYPercent: return rstyle(node.computedStyle()).translate_y_percent;
16610
+ case Property::TransformTranslateX: return rstyle(node.computedStyle()).transform_translate_x;
16611
+ case Property::TransformTranslateY: return rstyle(node.computedStyle()).transform_translate_y;
16612
+ case Property::TransformTranslateZ: return rstyle(node.computedStyle()).transform_translate_z;
16613
+ case Property::TransformTranslateXPercent: return rstyle(node.computedStyle()).transform_translate_x_percent;
16614
+ case Property::TransformTranslateYPercent: return rstyle(node.computedStyle()).transform_translate_y_percent;
16615
+ case Property::TransformScaleX: return rstyle(node.computedStyle()).transform_scale_x;
16616
+ case Property::TransformScaleY: return rstyle(node.computedStyle()).transform_scale_y;
16617
+ case Property::TransformScaleZ: return rstyle(node.computedStyle()).transform_scale_z;
16618
+ #endif
16619
+ case Property::FilterBlur: return (GEA_CSS_FILTERS ? rstyle(node.computedStyle()).filter_blur_radius : 0);
16620
+ case Property::Opacity: return node.computedStyle().opacity;
16621
+ case Property::Width: return node.computedStyle().width;
16622
+ case Property::Height: return node.computedStyle().height;
16623
+ case Property::WidthPercent: return node.computedStyle().width_percent == kUnset ? 0 : node.computedStyle().width_percent;
16624
+ case Property::HeightPercent: return node.computedStyle().height_percent == kUnset ? 0 : node.computedStyle().height_percent;
16625
+ case Property::LineHeight: return node.computedStyle().line_height;
16626
+ case Property::FontWeight: return node.computedStyle().font_weight;
16627
+ case Property::Top: return GEA_CSS_POSITION_PX_0(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_0(node.computedStyle());
16628
+ case Property::Right: return GEA_CSS_POSITION_PX_1(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_1(node.computedStyle());
16629
+ case Property::Bottom: return GEA_CSS_POSITION_PX_2(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_2(node.computedStyle());
16630
+ case Property::Left: return GEA_CSS_POSITION_PX_3(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_3(node.computedStyle());
16631
+ case Property::TopPercent: return GEA_CSS_POSITION_PERCENT_0(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_0(node.computedStyle());
16632
+ case Property::RightPercent: return GEA_CSS_POSITION_PERCENT_1(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_1(node.computedStyle());
16633
+ case Property::BottomPercent: return GEA_CSS_POSITION_PERCENT_2(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_2(node.computedStyle());
16634
+ case Property::LeftPercent: return GEA_CSS_POSITION_PERCENT_3(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_3(node.computedStyle());
16635
+ case Property::BackgroundColor: return node.computedStyle().bg_color;
16636
+ case Property::Color: return node.computedStyle().text_color;
16357
16637
  default: return 0;
16358
16638
  }
16359
16639
  }
@@ -16863,8 +17143,8 @@ BackgroundPlacement StyleValues::backgroundPlacement(const ComputedStyle &style,
16863
17143
  }
16864
17144
  if (out.origin != 0) {
16865
17145
  int inset[4];
16866
- for (int i = 0; i < 4; ++i) inset[i] = computedBorderWidth(node.style, i) +
16867
- (out.origin == 2 ? std::max<int>(0, node.style.padding[i]) : 0);
17146
+ for (int i = 0; i < 4; ++i) inset[i] = computedBorderWidth(node.computedStyle(), i) +
17147
+ (out.origin == 2 ? std::max<int>(0, node.computedStyle().padding[i]) : 0);
16868
17148
  x += inset[3]; y += inset[0]; width -= inset[1]+inset[3]; height -= inset[0]+inset[2];
16869
17149
  }
16870
17150
  }
@@ -16976,14 +17256,18 @@ void endStyleMountBatch()
16976
17256
  const int id = vIds[i];
16977
17257
  // Field-wise compare (ComputedStyle has padding, so memcmp gives false diffs).
16978
17258
  // styleEqualExceptTextPaint covers every field but text_color, which we add.
16979
- const bool equal = styleEqualExceptTextPaint(vStyles[i], state.nodes[id].style) &&
16980
- vStyles[i].text_color == state.nodes[id].style.text_color &&
17259
+ const bool equal = styleEqualExceptTextPaint(vStyles[i], state.nodes[id].computedStyle()) &&
17260
+ vStyles[i].text_color == state.nodes[id].computedStyle().text_color &&
16981
17261
  vImg[i] == state.nodes[id].image_id;
16982
17262
  if (!equal) {
16983
17263
  mismatches++;
16984
17264
  if (logged < 8) {
16985
17265
  const bool recomputed = g_incrRecomputedNodes.count(id) > 0;
17266
+ #if GEA_CSS_CUSTOM_PROPERTIES
16986
17267
  const std::string refs = (id >= 0 && id < kMaxNodes) ? g_nodeRefs[id].debugString() : std::string();
17268
+ #else
17269
+ const std::string refs;
17270
+ #endif
16987
17271
  GEA_STYLE_LOGW("gea.recincr", " mismatch node=%d tag=%s class=[%s] incrRecomputed=%d refs=[%s]", id,
16988
17272
  tagFromId(state.nodes[id].tag_id), state.classLists[id].value().c_str(), recomputed ? 1 : 0,
16989
17273
  refs.c_str());
@@ -17091,9 +17375,17 @@ void StyleSheet::clear()
17091
17375
  #endif
17092
17376
  invalidateRuleIndex();
17093
17377
  clearSelectorPartsCache();
17378
+ #if GEA_CSS_CUSTOM_PROPERTIES
17094
17379
  g_nodeRefOverflow.clear();
17380
+ #endif
17095
17381
  clearCustomPropertyLookupCache();
17096
- for (auto &refs : g_nodeRefs) refs.reset(); // stale per-node custom-prop dependencies from the previous app
17382
+ #if GEA_CSS_CUSTOM_PROPERTIES
17383
+ for (auto &refs : g_nodeRefs) refs.reset();
17384
+ #elif GEA_EMBEDDED_SHARED_STYLES
17385
+ for (auto &node : treeState().nodes) node.class_style_tracked = false;
17386
+ #else
17387
+ std::fill(std::begin(g_nodeStyleTracked), std::end(g_nodeStyleTracked), false);
17388
+ #endif
17097
17389
  g_pendingRecomputeMark.clear();
17098
17390
  g_forceFullSubtreeMark.clear();
17099
17391
  recomputeAllClassStyles();
@@ -17736,7 +18028,7 @@ void StyleSheet::startCssAnimations(std::uint32_t nowMs) const
17736
18028
  if (g_ruleIndex.animationRules.empty()) return;
17737
18029
  auto &state = treeState();
17738
18030
  for (int node = 0; node < state.nodeCount; ++node) {
17739
- if (isDisplayNone(state.nodes[node].style)) continue;
18031
+ if (isDisplayNone(state.nodes[node].computedStyle())) continue;
17740
18032
  const CssAnimationSpec spec = animationSpecForNode(node);
17741
18033
  startAnimationForNode(node, spec, nowMs);
17742
18034
  }