@geastack/engine 0.1.17 → 0.1.19

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
@@ -16,6 +16,7 @@
16
16
 
17
17
  #include <algorithm>
18
18
  #include <array>
19
+ #include <atomic>
19
20
  #include <cctype>
20
21
  #include <cmath>
21
22
  #include <cstdint>
@@ -599,6 +600,7 @@ bool styleEqualExceptTextPaint(const ComputedStyle &a, const ComputedStyle &b)
599
600
  a.font_id != b.font_id ||
600
601
  a.font_size != b.font_size ||
601
602
  a.font_weight != b.font_weight ||
603
+ a.font_stretch != b.font_stretch ||
602
604
  a.line_height != b.line_height ||
603
605
  a.text_align != b.text_align ||
604
606
  a.overflow != b.overflow ||
@@ -718,6 +720,7 @@ bool styleEqualExceptLocalDisplayCommands(const ComputedStyle &a, const Computed
718
720
  a.font_id != b.font_id ||
719
721
  a.font_size != b.font_size ||
720
722
  a.font_weight != b.font_weight ||
723
+ a.font_stretch != b.font_stretch ||
721
724
  a.line_height != b.line_height ||
722
725
  a.text_align != b.text_align ||
723
726
  a.overflow != b.overflow ||
@@ -1241,6 +1244,7 @@ CssDeclarationId classifyDeclaration(const char *property)
1241
1244
  if (std::strcmp(property, "border-bottom-left-radius") == 0) return CssDeclarationId::BorderBottomLeftRadius;
1242
1245
  if (std::strcmp(property, "font-family") == 0) return CssDeclarationId::FontFamily;
1243
1246
  if (std::strcmp(property, "font-size") == 0) return CssDeclarationId::FontSize;
1247
+ if (std::strcmp(property, "font-stretch") == 0) return CssDeclarationId::FontStretch;
1244
1248
  if (std::strcmp(property, "font-weight") == 0) return CssDeclarationId::FontWeight;
1245
1249
  if (std::strcmp(property, "line-height") == 0) return CssDeclarationId::LineHeight;
1246
1250
  if (std::strcmp(property, "text-align") == 0) return CssDeclarationId::TextAlign;
@@ -1653,7 +1657,9 @@ enum class LengthAxis {
1653
1657
  bool propertyAffectsDescendantStyle(Property property);
1654
1658
  void recomputeDescendantClassStyles(int node);
1655
1659
  void recomputeSubtreeClassStyles(int node);
1656
- void setStyleValue(NodeHandle node, Property property, int value, StyleApplicationSource source);
1660
+ void setStyleValue(const NodeHandle &node, Property property, int value, StyleApplicationSource source);
1661
+ void setValidatedStyleValue(const NodeHandle &node, int id, Property property, int value, StyleApplicationSource source);
1662
+ void setInlineStyleValue(int nodeId, Property property, int value);
1657
1663
  struct ActiveRulePlan;
1658
1664
  #if GEA_CSS_ANIMATIONS
1659
1665
  void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan = nullptr);
@@ -4093,6 +4099,24 @@ int fontSizeValue(const std::string &value, int nodeId)
4093
4099
  return parseLengthForNode(value, nodeId, LengthAxis::Vertical);
4094
4100
  }
4095
4101
 
4102
+ int fontStretchValue(const std::string &value)
4103
+ {
4104
+ const std::string token = toLowerAscii(trimCssValue(value));
4105
+ if (token == "normal") return 1000;
4106
+ if (token == "ultra-condensed") return 500;
4107
+ if (token == "extra-condensed") return 625;
4108
+ if (token == "condensed") return 750;
4109
+ if (token == "semi-condensed") return 875;
4110
+ if (token == "semi-expanded") return 1125;
4111
+ if (token == "expanded") return 1250;
4112
+ if (token == "extra-expanded") return 1500;
4113
+ if (token == "ultra-expanded") return 2000;
4114
+ char *end = nullptr;
4115
+ const double number = std::strtod(token.c_str(), &end);
4116
+ if (!std::isfinite(number) || number <= 0 || !end || std::strcmp(end, "%") != 0) return -1;
4117
+ return static_cast<int>(std::clamp(std::round(number * 10.0), 1.0, 32767.0));
4118
+ }
4119
+
4096
4120
  int fontWeightValue(const std::string &rawValue)
4097
4121
  {
4098
4122
  const std::string value = toLowerAscii(trimCssValue(rawValue));
@@ -7191,6 +7215,9 @@ bool compileKeywordValue(CssDeclarationId declaration, const std::string &value,
7191
7215
  compiled.values[0] = fontFamilyValue(value);
7192
7216
  return true;
7193
7217
  }
7218
+ case CssDeclarationId::FontStretch:
7219
+ compiled.values[0] = fontStretchValue(value);
7220
+ return compiled.values[0] > 0;
7194
7221
  case CssDeclarationId::FontWeight:
7195
7222
  compiled.values[0] = fontWeightValue(value);
7196
7223
  return true;
@@ -7771,7 +7798,7 @@ bool isLineHeightProperty(Property property)
7771
7798
 
7772
7799
  bool isFontMetricProperty(Property property)
7773
7800
  {
7774
- return property == Property::FontId || property == Property::FontSize || property == Property::FontWeight;
7801
+ return property == Property::FontId || property == Property::FontSize || property == Property::FontWeight || property == Property::FontStretch;
7775
7802
  }
7776
7803
 
7777
7804
  void applyGridTemplateValue(NodeHandle node, const std::string &value, bool columns)
@@ -8308,6 +8335,9 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
8308
8335
  #if GEA_CSS_FONT_WEIGHT
8309
8336
  case Property::FontWeight: style.font_weight = value; return true;
8310
8337
  #endif
8338
+ #if GEA_CSS_FONT_STRETCH
8339
+ case Property::FontStretch: style.font_stretch = value; return true;
8340
+ #endif
8311
8341
  #if GEA_CSS_LINE_HEIGHT
8312
8342
  case Property::LineHeight:
8313
8343
  #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
@@ -8491,16 +8521,24 @@ bool setClassRuleValueFast(NodeHandle node, Property property, int value)
8491
8521
  return setClassRuleValueFastUnchecked(target, property, value);
8492
8522
  }
8493
8523
 
8494
- void setStyleValue(NodeHandle node, Property property, int value, StyleApplicationSource source)
8524
+ void setStyleValue(const NodeHandle &node, Property property, int value, StyleApplicationSource source)
8525
+ {
8526
+ // One validity check; a Style would copy the owner only to check it again.
8527
+ const int id = node.id();
8528
+ if (id < 0) return;
8529
+ setValidatedStyleValue(node, id, property, value, source);
8530
+ }
8531
+
8532
+ // setStyleValue for a caller that has already resolved `node`'s live `id`.
8533
+ void setValidatedStyleValue(const NodeHandle &node, int id, Property property, int value, StyleApplicationSource source)
8495
8534
  {
8496
- if (!node) return;
8497
8535
  if (source == StyleApplicationSource::ClassRule) {
8498
- if (node.id() == g_resolvedFontNode && isFontMetricProperty(property)) return;
8499
- if (node.id() == g_resolvedLineHeightNode && isLineHeightProperty(property)) return;
8536
+ if (id == g_resolvedFontNode && isFontMetricProperty(property)) return;
8537
+ if (id == g_resolvedLineHeightNode && isLineHeightProperty(property)) return;
8500
8538
  if (setClassRuleValueFast(node, property, value)) return;
8501
- Tree::instance().setStyleFromClass(node.id(), property, value);
8539
+ Tree::instance().setStyleFromClass(id, property, value);
8502
8540
  } else {
8503
- node.style().set(property, value);
8541
+ setInlineStyleValue(id, property, value);
8504
8542
  }
8505
8543
  }
8506
8544
 
@@ -9209,6 +9247,24 @@ bool applyAnimatedTransformStyleValueFast(int nodeId, Property property, int val
9209
9247
  return true;
9210
9248
  }
9211
9249
 
9250
+ // Style::set for a node id its caller has validated.
9251
+ void setInlineStyleValue(int nodeId, Property property, int value)
9252
+ {
9253
+ if (nodeId < 0) return;
9254
+ #if GEA_CSS_ANIMATIONS
9255
+ double before = 0;
9256
+ const bool transition = inlineTransitionBefore(nodeId, property, before);
9257
+ #endif
9258
+ Tree::instance().setStyle(nodeId, property, value);
9259
+ #if GEA_CSS_ANIMATIONS
9260
+ if (transition) applyInlineTransition(nodeId, property, before);
9261
+ #endif
9262
+ // This element's cascaded lengths can depend on its own font too. Updating
9263
+ // descendants alone leaves, for example, class padding in ch at old metrics.
9264
+ if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId);
9265
+ else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId);
9266
+ }
9267
+
9212
9268
  } // namespace
9213
9269
 
9214
9270
  StorageUsage styleDependencyStorageUsage()
@@ -9303,19 +9359,7 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
9303
9359
 
9304
9360
  void Style::set(Property property, int value) const
9305
9361
  {
9306
- if (nodeId_ < 0) return;
9307
- #if GEA_CSS_ANIMATIONS
9308
- double before = 0;
9309
- const bool transition = inlineTransitionBefore(nodeId_, property, before);
9310
- #endif
9311
- Tree::instance().setStyle(nodeId_, property, value);
9312
- #if GEA_CSS_ANIMATIONS
9313
- if (transition) applyInlineTransition(nodeId_, property, before);
9314
- #endif
9315
- // This element's cascaded lengths can depend on its own font too. Updating
9316
- // descendants alone leaves, for example, class padding in ch at old metrics.
9317
- if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId_);
9318
- else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId_);
9362
+ setInlineStyleValue(nodeId(), property, value);
9319
9363
  }
9320
9364
 
9321
9365
  void Style::backgroundColor(int rgb565) const
@@ -9326,20 +9370,30 @@ void Style::backgroundColor(int rgb565) const
9326
9370
 
9327
9371
  void Style::setProperty(const std::string &property, const std::string &value) const
9328
9372
  {
9329
- if (nodeId_ < 0) return;
9330
- StyleSheet::instance().applyProperty(NodeHandle(nodeId_), property, value);
9373
+ if (nodeId() < 0) return;
9374
+ StyleSheet::instance().applyProperty(NodeHandle(nodeId_, identity_), property, value);
9375
+ }
9376
+
9377
+ bool NodeHandle::setStyleNumberProperty(const std::string &property, double value) const
9378
+ {
9379
+ // applyNumberDeclarationWithSource validates this handle; no Style, so no
9380
+ // second identity owner for the write.
9381
+ return StyleSheet::instance().applyNumberProperty(*this, property.c_str(), value);
9331
9382
  }
9332
9383
 
9333
9384
  bool Style::setNumberProperty(const std::string &property, double value) const
9334
9385
  {
9335
- if (nodeId_ < 0) return false;
9336
- return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId_), property.c_str(), value);
9386
+ if (nodeId() < 0) return false;
9387
+ // This Style holds the validated owner for the whole call, and numeric
9388
+ // style application keeps node ids, not handles, so the handle borrows it.
9389
+ return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId_, identity_, NodeHandle::Borrowed{}),
9390
+ property.c_str(), value);
9337
9391
  }
9338
9392
 
9339
9393
  bool Style::removeProperty(const std::string &property) const
9340
9394
  {
9341
- if (nodeId_ < 0) return false;
9342
- return StyleSheet::instance().removeProperty(NodeHandle(nodeId_), property);
9395
+ if (nodeId() < 0) return false;
9396
+ return StyleSheet::instance().removeProperty(NodeHandle(nodeId_, identity_), property);
9343
9397
  }
9344
9398
 
9345
9399
  void applyAnimatedStyleValue(int nodeId, Property property, int value)
@@ -9377,6 +9431,9 @@ void applyInheritedStyleDefaults(int node)
9377
9431
  style.text_color = parentStyle.text_color;
9378
9432
  #if GEA_CSS_TEXT_ALPHA
9379
9433
  style.text_alpha = parentStyle.text_alpha;
9434
+ #endif
9435
+ #if GEA_CSS_FONT_STRETCH
9436
+ style.font_stretch = parentStyle.font_stretch;
9380
9437
  #endif
9381
9438
  style.font_id = parentStyle.font_id;
9382
9439
  style.font_size = parentStyle.font_size;
@@ -9404,139 +9461,147 @@ void applyInheritedStyleDefaults(int node)
9404
9461
  #endif
9405
9462
  }
9406
9463
 
9407
- bool applyNumberDeclarationWithSource(NodeHandle node,
9464
+ bool applyNumberDeclarationWithSource(const NodeHandle &node,
9408
9465
  CssDeclarationId declaration,
9409
9466
  double value,
9410
9467
  StyleApplicationSource source)
9411
9468
  {
9412
- if (!node) return false;
9469
+ // The node is validated once here; its writes below reuse the live id.
9470
+ const int id = node.id();
9471
+ if (id < 0) return false;
9413
9472
  const int length = numericLength(value);
9414
9473
  switch (declaration) {
9415
9474
  case CssDeclarationId::Order:
9416
9475
  if (std::isfinite(value) && std::trunc(value) == value)
9417
- setStyleValue(node, Property::Order, static_cast<int>(std::clamp(value, -2147483648.0, 2147483647.0)), source);
9476
+ setValidatedStyleValue(node, id, Property::Order, static_cast<int>(std::clamp(value, -2147483648.0, 2147483647.0)), source);
9418
9477
  return true;
9419
9478
  case CssDeclarationId::Gap:
9420
- setStyleValue(node, Property::Gap, length, source);
9479
+ setValidatedStyleValue(node, id, Property::Gap, length, source);
9421
9480
  return true;
9422
9481
  case CssDeclarationId::Width:
9423
- setStyleValue(node, Property::Width, length, source);
9482
+ setValidatedStyleValue(node, id, Property::Width, length, source);
9424
9483
  return true;
9425
9484
  case CssDeclarationId::Height:
9426
- setStyleValue(node, Property::Height, length, source);
9485
+ setValidatedStyleValue(node, id, Property::Height, length, source);
9427
9486
  return true;
9428
9487
  case CssDeclarationId::MinWidth:
9429
- setStyleValue(node, Property::MinWidth, length, source);
9488
+ setValidatedStyleValue(node, id, Property::MinWidth, length, source);
9430
9489
  return true;
9431
9490
  case CssDeclarationId::MinHeight:
9432
- setStyleValue(node, Property::MinHeight, length, source);
9491
+ setValidatedStyleValue(node, id, Property::MinHeight, length, source);
9433
9492
  return true;
9434
9493
  case CssDeclarationId::MaxWidth:
9435
- setStyleValue(node, Property::MaxWidth, length, source);
9494
+ setValidatedStyleValue(node, id, Property::MaxWidth, length, source);
9436
9495
  return true;
9437
9496
  case CssDeclarationId::MaxHeight:
9438
- setStyleValue(node, Property::MaxHeight, length, source);
9497
+ setValidatedStyleValue(node, id, Property::MaxHeight, length, source);
9439
9498
  return true;
9440
9499
  case CssDeclarationId::Flex:
9441
- setStyleValue(node, Property::Flex, rawNumber(value), source);
9442
- setStyleValue(node, Property::FlexShrink, rawNumber(1.0), source);
9443
- setStyleValue(node, Property::FlexBasis, kUnset, source); // numeric `flex: N` has no explicit basis
9500
+ setValidatedStyleValue(node, id, Property::Flex, rawNumber(value), source);
9501
+ setValidatedStyleValue(node, id, Property::FlexShrink, rawNumber(1.0), source);
9502
+ setValidatedStyleValue(node, id, Property::FlexBasis, kUnset, source); // numeric `flex: N` has no explicit basis
9444
9503
  return true;
9445
9504
  case CssDeclarationId::Padding:
9446
9505
  setAllPadding(node, length, source);
9447
9506
  return true;
9448
9507
  case CssDeclarationId::PaddingTop:
9449
- setStyleValue(node, Property::PaddingTop, length, source);
9508
+ setValidatedStyleValue(node, id, Property::PaddingTop, length, source);
9450
9509
  return true;
9451
9510
  case CssDeclarationId::PaddingRight:
9452
- setStyleValue(node, Property::PaddingRight, length, source);
9511
+ setValidatedStyleValue(node, id, Property::PaddingRight, length, source);
9453
9512
  return true;
9454
9513
  case CssDeclarationId::PaddingBottom:
9455
- setStyleValue(node, Property::PaddingBottom, length, source);
9514
+ setValidatedStyleValue(node, id, Property::PaddingBottom, length, source);
9456
9515
  return true;
9457
9516
  case CssDeclarationId::PaddingLeft:
9458
- setStyleValue(node, Property::PaddingLeft, length, source);
9517
+ setValidatedStyleValue(node, id, Property::PaddingLeft, length, source);
9459
9518
  return true;
9460
9519
  case CssDeclarationId::Margin:
9461
9520
  setAllMargin(node, length, source);
9462
9521
  return true;
9463
9522
  case CssDeclarationId::MarginTop:
9464
- setStyleValue(node, Property::MarginTop, length, source);
9523
+ setValidatedStyleValue(node, id, Property::MarginTop, length, source);
9465
9524
  return true;
9466
9525
  case CssDeclarationId::MarginRight:
9467
- setStyleValue(node, Property::MarginRight, length, source);
9526
+ setValidatedStyleValue(node, id, Property::MarginRight, length, source);
9468
9527
  return true;
9469
9528
  case CssDeclarationId::MarginBottom:
9470
- setStyleValue(node, Property::MarginBottom, length, source);
9529
+ setValidatedStyleValue(node, id, Property::MarginBottom, length, source);
9471
9530
  return true;
9472
9531
  case CssDeclarationId::MarginLeft:
9473
- setStyleValue(node, Property::MarginLeft, length, source);
9532
+ setValidatedStyleValue(node, id, Property::MarginLeft, length, source);
9474
9533
  return true;
9475
9534
  case CssDeclarationId::Top:
9476
- setStyleValue(node, Property::Top, length, source);
9535
+ setValidatedStyleValue(node, id, Property::Top, length, source);
9477
9536
  return true;
9478
9537
  case CssDeclarationId::Right:
9479
- setStyleValue(node, Property::Right, length, source);
9538
+ setValidatedStyleValue(node, id, Property::Right, length, source);
9480
9539
  return true;
9481
9540
  case CssDeclarationId::Bottom:
9482
- setStyleValue(node, Property::Bottom, length, source);
9541
+ setValidatedStyleValue(node, id, Property::Bottom, length, source);
9483
9542
  return true;
9484
9543
  case CssDeclarationId::Left:
9485
- setStyleValue(node, Property::Left, length, source);
9544
+ setValidatedStyleValue(node, id, Property::Left, length, source);
9486
9545
  return true;
9487
9546
  case CssDeclarationId::ZIndex:
9488
- setStyleValue(node, Property::ZIndex, rawNumber(value), source);
9547
+ setValidatedStyleValue(node, id, Property::ZIndex, rawNumber(value), source);
9489
9548
  return true;
9490
9549
  case CssDeclarationId::Opacity:
9491
- setStyleValue(node, Property::Opacity, numericOpacity(value), source);
9550
+ setValidatedStyleValue(node, id, Property::Opacity, numericOpacity(value), source);
9492
9551
  return true;
9493
9552
  case CssDeclarationId::BorderWidth:
9494
9553
  if (value >= 0.0 && std::isfinite(value)) setUniformBorderWidth(node, snapBorderWidth(value), source);
9495
9554
  return true;
9496
9555
  case CssDeclarationId::BorderTopWidth:
9497
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderTopWidth, snapBorderWidth(value), source);
9556
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderTopWidth, snapBorderWidth(value), source);
9498
9557
  return true;
9499
9558
  case CssDeclarationId::BorderRightWidth:
9500
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderRightWidth, snapBorderWidth(value), source);
9559
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderRightWidth, snapBorderWidth(value), source);
9501
9560
  return true;
9502
9561
  case CssDeclarationId::BorderBottomWidth:
9503
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderBottomWidth, snapBorderWidth(value), source);
9562
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderBottomWidth, snapBorderWidth(value), source);
9504
9563
  return true;
9505
9564
  case CssDeclarationId::BorderLeftWidth:
9506
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderLeftWidth, snapBorderWidth(value), source);
9565
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderLeftWidth, snapBorderWidth(value), source);
9507
9566
  return true;
9508
9567
  case CssDeclarationId::BorderRadius:
9509
9568
  setAllBorderRadius(node, length, source);
9510
9569
  return true;
9511
9570
  case CssDeclarationId::BorderTopLeftRadius:
9512
- setStyleValue(node, Property::BorderRadiusTopLeft, length, source);
9571
+ setValidatedStyleValue(node, id, Property::BorderRadiusTopLeft, length, source);
9513
9572
  return true;
9514
9573
  case CssDeclarationId::BorderTopRightRadius:
9515
- setStyleValue(node, Property::BorderRadiusTopRight, length, source);
9574
+ setValidatedStyleValue(node, id, Property::BorderRadiusTopRight, length, source);
9516
9575
  return true;
9517
9576
  case CssDeclarationId::BorderBottomRightRadius:
9518
- setStyleValue(node, Property::BorderRadiusBottomRight, length, source);
9577
+ setValidatedStyleValue(node, id, Property::BorderRadiusBottomRight, length, source);
9519
9578
  return true;
9520
9579
  case CssDeclarationId::BorderBottomLeftRadius:
9521
- setStyleValue(node, Property::BorderRadiusBottomLeft, length, source);
9580
+ setValidatedStyleValue(node, id, Property::BorderRadiusBottomLeft, length, source);
9522
9581
  return true;
9523
9582
  case CssDeclarationId::FontSize:
9524
- setStyleValue(node, Property::FontSize, length, source);
9583
+ setValidatedStyleValue(node, id, Property::FontSize, length, source);
9584
+ return true;
9585
+ #if GEA_CSS_FONT_STRETCH
9586
+ case CssDeclarationId::FontStretch:
9587
+ if (!std::isfinite(value) || value <= 0) return false;
9588
+ setValidatedStyleValue(node, id, Property::FontStretch, std::clamp(roundToInt(std::clamp(value, 0.1, 3276.7) * 10), 1, 32767), source);
9525
9589
  return true;
9590
+ #endif
9526
9591
  case CssDeclarationId::FontWeight:
9527
- setStyleValue(node, Property::FontWeight, std::clamp(roundToInt(value), 1, 1000), source);
9592
+ setValidatedStyleValue(node, id, Property::FontWeight, std::clamp(roundToInt(value), 1, 1000), source);
9528
9593
  return true;
9529
9594
  case CssDeclarationId::LineHeight: {
9530
9595
  const float multiplier = static_cast<float>(value);
9531
9596
  if (!std::isfinite(multiplier) || multiplier < 0) return false;
9532
9597
  int bits = 0; if (multiplier != 0) std::memcpy(&bits, &multiplier, sizeof(bits));
9533
- setStyleValue(node, Property::LineHeightMultiplier, bits, source);
9598
+ setValidatedStyleValue(node, id, Property::LineHeightMultiplier, bits, source);
9534
9599
  return true;
9535
9600
  }
9536
9601
  #if GEA_CSS_TRANSFORMS
9537
9602
  case CssDeclarationId::Transform:
9538
- setStyleValue(node, Property::TransformPresent, 1, source);
9539
- setStyleValue(node, Property::TransformRotate, numericRotateTenths(value), source);
9603
+ setValidatedStyleValue(node, id, Property::TransformPresent, 1, source);
9604
+ setValidatedStyleValue(node, id, Property::TransformRotate, numericRotateTenths(value), source);
9540
9605
  return true;
9541
9606
  case CssDeclarationId::Rotate: {
9542
9607
  IndividualRotation rotation; rotation.angle = numericRotateTenths(value);
@@ -9553,9 +9618,10 @@ bool applyNumberDeclarationWithSource(NodeHandle node,
9553
9618
  }
9554
9619
  }
9555
9620
 
9556
- bool applyNumberPropertyWithSource(NodeHandle node, const char *property, double value, StyleApplicationSource source)
9621
+ bool applyNumberPropertyWithSource(const NodeHandle &node, const char *property, double value, StyleApplicationSource source)
9557
9622
  {
9558
- if (!node || !property) return false;
9623
+ // applyNumberDeclarationWithSource validates the node first.
9624
+ if (!property) return false;
9559
9625
  return applyNumberDeclarationWithSource(node, classifyDeclaration(property), value, source);
9560
9626
  }
9561
9627
 
@@ -9622,6 +9688,10 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9622
9688
  case CssDeclarationId::WritingMode:
9623
9689
  return false;
9624
9690
  #endif
9691
+ #if !GEA_CSS_FONT_STRETCH
9692
+ case CssDeclarationId::FontStretch:
9693
+ return false;
9694
+ #endif
9625
9695
 
9626
9696
  case CssDeclarationId::BackgroundClip: {
9627
9697
  const int parent = Tree::instance().node(nodeId).parent;
@@ -10074,6 +10144,9 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
10074
10144
  case CssDeclarationId::Font: {
10075
10145
  ParsedFontShorthand font;
10076
10146
  if (!parseFontShorthand(value, font)) return true;
10147
+ #if GEA_CSS_FONT_STRETCH
10148
+ setStyleValue(node, Property::FontStretch, 1000, source);
10149
+ #endif
10077
10150
  setStyleValue(node, Property::FontWeight, font.weight, source);
10078
10151
  setStyleValue(node, Property::FontId, fontFamilyValue(font.family), source);
10079
10152
  setLengthStyleValue(node, font.size, Property::FontSize, fontSizeValue(font.size, nodeId), source);
@@ -10083,6 +10156,13 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
10083
10156
  case CssDeclarationId::FontSize:
10084
10157
  setLengthStyleValue(node, value, Property::FontSize, fontSizeValue(value, nodeId), source);
10085
10158
  return true;
10159
+ #if GEA_CSS_FONT_STRETCH
10160
+ case CssDeclarationId::FontStretch: {
10161
+ const int stretch = fontStretchValue(value);
10162
+ if (stretch > 0) setStyleValue(node, Property::FontStretch, stretch, source);
10163
+ return true;
10164
+ }
10165
+ #endif
10086
10166
  case CssDeclarationId::FontWeight:
10087
10167
  setStyleValue(node, Property::FontWeight, fontWeightValue(value), source);
10088
10168
  return true;
@@ -11170,6 +11250,7 @@ bool applyCompiledCssValueWithSource(NodeHandle node, const CssCompiledValue &co
11170
11250
  case CssDeclarationId::OverflowX: setStyleValue(node, Property::OverflowX, compiled.values[0], source); return true;
11171
11251
  case CssDeclarationId::OverflowY: setStyleValue(node, Property::OverflowY, compiled.values[0], source); return true;
11172
11252
  case CssDeclarationId::FontFamily: setStyleValue(node, Property::FontId, compiled.values[0], source); return true;
11253
+ case CssDeclarationId::FontStretch: setStyleValue(node, Property::FontStretch, compiled.values[0], source); return true;
11173
11254
  case CssDeclarationId::FontWeight: setStyleValue(node, Property::FontWeight, compiled.values[0], source); return true;
11174
11255
  default: return false;
11175
11256
  }
@@ -14008,6 +14089,7 @@ bool addCachedKeywordDeclaration(CachedStyleApplyOp &op, CssDeclarationId declar
14008
14089
  case CssDeclarationId::OverflowX: return addCachedStyleApplyProperty(op, Property::OverflowX, value);
14009
14090
  case CssDeclarationId::OverflowY: return addCachedStyleApplyProperty(op, Property::OverflowY, value);
14010
14091
  case CssDeclarationId::FontFamily: return addCachedStyleApplyProperty(op, Property::FontId, value);
14092
+ case CssDeclarationId::FontStretch: return addCachedStyleApplyProperty(op, Property::FontStretch, value);
14011
14093
  case CssDeclarationId::FontWeight: return addCachedStyleApplyProperty(op, Property::FontWeight, value);
14012
14094
  default: return false;
14013
14095
  }
@@ -14919,6 +15001,7 @@ bool addCompiledValueWrites(const CssCompiledValue &compiled, PropertyWriteMask
14919
15001
  case CssDeclarationId::OverflowX: addPropertyWrite(mask, Property::OverflowX); return true;
14920
15002
  case CssDeclarationId::OverflowY: addPropertyWrite(mask, Property::OverflowY); return true;
14921
15003
  case CssDeclarationId::FontFamily: addPropertyWrite(mask, Property::FontId); return true;
15004
+ case CssDeclarationId::FontStretch: addPropertyWrite(mask, Property::FontStretch); return true;
14922
15005
  case CssDeclarationId::FontWeight: addPropertyWrite(mask, Property::FontWeight); return true;
14923
15006
  default: return false;
14924
15007
  }
@@ -15721,7 +15804,7 @@ void applyCachedRuleWithSource(NodeHandle node, const CachedRuleApply &op, Style
15721
15804
  bool setsFontMetrics(CssDeclarationId declaration)
15722
15805
  {
15723
15806
  return declaration == CssDeclarationId::Font || declaration == CssDeclarationId::FontFamily ||
15724
- declaration == CssDeclarationId::FontSize || declaration == CssDeclarationId::FontWeight;
15807
+ declaration == CssDeclarationId::FontSize || declaration == CssDeclarationId::FontWeight || declaration == CssDeclarationId::FontStretch;
15725
15808
  }
15726
15809
 
15727
15810
  void applyActiveRuleSpanToNode(int node, const ActiveRulePlan &plan, int bucketId, int metricsOnly = 0)
@@ -16070,6 +16153,11 @@ struct ParentStyleSnapshot {
16070
16153
  std::uint8_t text_alpha;
16071
16154
  #else
16072
16155
  static constexpr std::uint8_t text_alpha = 255;
16156
+ #endif
16157
+ #if GEA_CSS_FONT_STRETCH
16158
+ std::int16_t font_stretch;
16159
+ #else
16160
+ static constexpr std::int16_t font_stretch = 1000;
16073
16161
  #endif
16074
16162
  std::int16_t font_id;
16075
16163
  decltype(ComputedStyle::font_size) font_size;
@@ -16127,6 +16215,9 @@ ParentStyleSnapshot snapshotParentStyle(const ComputedStyle &s)
16127
16215
  #if GEA_CSS_FONT_WEIGHT
16128
16216
  out.font_weight = s.font_weight;
16129
16217
  #endif
16218
+ #if GEA_CSS_FONT_STRETCH
16219
+ out.font_stretch = s.font_stretch;
16220
+ #endif
16130
16221
  #if GEA_CSS_LINE_HEIGHT
16131
16222
  out.line_height = s.line_height;
16132
16223
  #endif
@@ -16157,7 +16248,8 @@ ParentStyleSnapshot snapshotParentStyle(const ComputedStyle &s)
16157
16248
  bool parentStylesDiffer(const ParentStyleSnapshot &a, const ParentStyleSnapshot &b)
16158
16249
  {
16159
16250
  return a.text_color != b.text_color || a.text_alpha != b.text_alpha || a.font_id != b.font_id || a.font_size != b.font_size ||
16160
- a.font_weight != b.font_weight || a.line_height != b.line_height || a.line_height_multiplier != b.line_height_multiplier ||
16251
+ a.font_weight != b.font_weight ||
16252
+ a.font_stretch != b.font_stretch || a.line_height != b.line_height || a.line_height_multiplier != b.line_height_multiplier ||
16161
16253
  a.text_align != b.text_align || a.text_transform != b.text_transform ||
16162
16254
  a.white_space != b.white_space || a.visibility != b.visibility || a.border_widths != b.border_widths;
16163
16255
  }
@@ -17616,19 +17708,28 @@ BackgroundPlacement StyleValues::backgroundPlacement(const ComputedStyle &style,
17616
17708
  if (const auto *v = entry(r.bg_attachment_list)) out.attachment = v->a;
17617
17709
  if (const auto *v = entry(r.bg_origin_list)) out.origin = v->a;
17618
17710
  if (const auto *v = entry(r.bg_repeat_list)) { out.repeatX = v->a; out.repeatY = v->b; }
17619
- const Node &node = treeState().nodes[nodeId];
17711
+ // nodeId comes from ViewGeometry::nodeIndex(), which is -1 for a box that is
17712
+ // not a slot of the tree (a Node recorded straight from the stack, as the
17713
+ // renderer tests do). Indexing nodes[-1] read whatever sits before the heap
17714
+ // TreeState and handed its garbage rare_style handle to rstyle(), so the
17715
+ // result -- and whether the process segfaulted -- depended on the address
17716
+ // layout. Such a box has no scroll state, and its own style is the only
17717
+ // border/padding there is to inset by.
17718
+ const auto &state = treeState();
17719
+ const Node *node = nodeId >= 0 && nodeId < state.nodeCount ? &state.nodes[nodeId] : nullptr;
17720
+ const ComputedStyle &box = node ? node->computedStyle() : style;
17620
17721
  if (out.attachment == 1) {
17621
- x = y = 0; width = treeState().mountedWidth; height = treeState().mountedHeight;
17722
+ x = y = 0; width = state.mountedWidth; height = state.mountedHeight;
17622
17723
  } else {
17623
- if (out.attachment == 2) {
17624
- width = std::max<int>(width, node.layout.scroll_content_width);
17625
- height = std::max<int>(height, node.layout.scroll_content_height);
17626
- x -= node.layout.scroll_x; y -= node.layout.scroll_y;
17724
+ if (out.attachment == 2 && node) {
17725
+ width = std::max<int>(width, node->layout.scroll_content_width);
17726
+ height = std::max<int>(height, node->layout.scroll_content_height);
17727
+ x -= node->layout.scroll_x; y -= node->layout.scroll_y;
17627
17728
  }
17628
17729
  if (out.origin != 0) {
17629
17730
  int inset[4];
17630
- for (int i = 0; i < 4; ++i) inset[i] = computedBorderWidth(node.computedStyle(), i) +
17631
- (out.origin == 2 ? std::max<int>(0, node.computedStyle().padding[i]) : 0);
17731
+ for (int i = 0; i < 4; ++i) inset[i] = computedBorderWidth(box, i) +
17732
+ (out.origin == 2 ? std::max<int>(0, box.padding[i]) : 0);
17632
17733
  x += inset[3]; y += inset[0]; width -= inset[1]+inset[3]; height -= inset[0]+inset[2];
17633
17734
  }
17634
17735
  }
@@ -18474,12 +18575,12 @@ bool StyleSheet::applyPixelLengthProperty(NodeHandle node, StyleDeclaration decl
18474
18575
  return false;
18475
18576
  }
18476
18577
 
18477
- bool StyleSheet::applyNumberProperty(NodeHandle node, const char *property, double value) const
18578
+ bool StyleSheet::applyNumberProperty(const NodeHandle &node, const char *property, double value) const
18478
18579
  {
18479
18580
  return applyNumberPropertyWithSource(node, property, value, StyleApplicationSource::Inline);
18480
18581
  }
18481
18582
 
18482
- bool StyleSheet::applyNumberProperty(NodeHandle node, StyleDeclaration declaration, double value) const
18583
+ bool StyleSheet::applyNumberProperty(const NodeHandle &node, StyleDeclaration declaration, double value) const
18483
18584
  {
18484
18585
  return applyNumberDeclarationWithSource(node, declaration, value, StyleApplicationSource::Inline);
18485
18586
  }
@@ -18554,9 +18655,15 @@ void Tree::setClassName(int node, const char *className)
18554
18655
  // growth, so tagFromId can hand out c_str() pointers that stay valid. Index 0
18555
18656
  // is the empty tag, matching Node::tag_id's zero default.
18556
18657
  namespace {
18658
+ // tagFromId runs for every node on every frame. Without hardware atomics
18659
+ // (ESP32-S3) a guarded function-local static takes an RTOS mutex on each
18660
+ // access, so later calls read the table through an acquire-loaded pointer.
18557
18661
  std::deque<std::string> &tagTable()
18558
18662
  {
18663
+ static std::atomic<std::deque<std::string> *> ready{nullptr};
18664
+ if (auto *table = ready.load(std::memory_order_acquire)) return *table;
18559
18665
  static std::deque<std::string> table = {std::string()};
18666
+ ready.store(&table, std::memory_order_release);
18560
18667
  return table;
18561
18668
  }
18562
18669
  } // namespace
package/ui/style.h CHANGED
@@ -1,6 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
3
 
4
+ #include "native_identity.h"
4
5
  #include <cstdint>
5
6
  #include <initializer_list>
6
7
  #include <string>
@@ -212,6 +213,7 @@ enum class Property : int {
212
213
  BorderBottomRelief,
213
214
  BorderLeftRelief,
214
215
  BorderRelief,
216
+ FontStretch,
215
217
  Count
216
218
  };
217
219
 
@@ -346,14 +348,17 @@ enum class StyleDeclaration : std::uint8_t {
346
348
  BackgroundOrigin,
347
349
  MarginTrim,
348
350
  Transition,
349
- AnimationPlayState
351
+ AnimationPlayState,
352
+ FontStretch
350
353
  };
351
354
 
352
355
  class Style {
353
356
  public:
354
- explicit Style(int nodeId = -1) : nodeId_(nodeId) {}
357
+ explicit Style(int nodeId = -1)
358
+ : nodeId_(nodeId), identity_(gea::framework::identity::node(nodeId)) {}
359
+ Style(int nodeId, gea::framework::identity::Owner owner) : nodeId_(nodeId), identity_(std::move(owner)) {}
355
360
 
356
- int nodeId() const { return nodeId_; }
361
+ int nodeId() const { return gea::framework::identity::current(nodeId_, identity_) ? nodeId_ : -1; }
357
362
  void set(Property property, int value) const;
358
363
 
359
364
  void width(int value) const { set(Property::Width, value); }
@@ -387,6 +392,7 @@ public:
387
392
 
388
393
  private:
389
394
  int nodeId_;
395
+ gea::framework::identity::Owner identity_;
390
396
  };
391
397
 
392
398
  class NodeHandle;
@@ -859,8 +865,8 @@ public:
859
865
  void applyProperty(NodeHandle node, const std::string &property, const std::string &value) const;
860
866
  // Preserve CSS px units through device scaling before property-specific rounding.
861
867
  bool applyPixelLengthProperty(NodeHandle node, StyleDeclaration declaration, double value) const;
862
- bool applyNumberProperty(NodeHandle node, StyleDeclaration declaration, double value) const;
863
- bool applyNumberProperty(NodeHandle node, const char *property, double value) const;
868
+ bool applyNumberProperty(const NodeHandle &node, StyleDeclaration declaration, double value) const;
869
+ bool applyNumberProperty(const NodeHandle &node, const char *property, double value) const;
864
870
  bool removeProperty(NodeHandle node, const std::string &property) const;
865
871
  void recomputeSubtree(int nodeId) const;
866
872
  void hoverChanged() const;