@geastack/engine 0.1.14 → 0.1.16

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
@@ -10,6 +10,7 @@
10
10
  #include "tree_state.h"
11
11
  #include "tree_internal.h"
12
12
  #include "internal.h"
13
+ #include <image.h>
13
14
  #include "css/engine.h"
14
15
  #include "refresh_perf.h"
15
16
 
@@ -886,6 +887,38 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
886
887
  Tree::instance().markDisplayListDirty();
887
888
  return;
888
889
  }
890
+ // Class-driven size/position changes owe the same out-of-flow leaf
891
+ // locality as individual Width/Height/Top/Left setters. A selected
892
+ // pagination dot cannot move siblings or change draw order.
893
+ if (beforeImageId == target.image_id && target.first_child < 0 && target.type != NodeType::Text &&
894
+ beforeStyle.position == 1 && target.computedStyle().position == 1 && !firstLineChanged &&
895
+ target.computedStyle().mask_right_fade_width == 0 && rstyle(target.computedStyle()).filter_blur_radius == 0 &&
896
+ rstyle(target.computedStyle()).box_shadow_alpha == 0 &&
897
+ !rstyle(beforeStyle).transform_present && !rstyle(target.computedStyle()).transform_present &&
898
+ !rstyle(beforeStyle).translate_present && !rstyle(target.computedStyle()).translate_present &&
899
+ !rstyle(beforeStyle).rotate_present && !rstyle(target.computedStyle()).rotate_present &&
900
+ !rstyle(beforeStyle).scale_present && !rstyle(target.computedStyle()).scale_present) {
901
+ ComputedStyle geometryNormalized = target.computedStyle();
902
+ geometryNormalized.width = beforeStyle.width;
903
+ geometryNormalized.height = beforeStyle.height;
904
+ #if GEA_CSS_POSITION_TOP
905
+ GEA_CSS_POSITION_PX_0(geometryNormalized) = GEA_CSS_POSITION_PX_0(beforeStyle);
906
+ #endif
907
+ #if GEA_CSS_POSITION_RIGHT
908
+ GEA_CSS_POSITION_PX_1(geometryNormalized) = GEA_CSS_POSITION_PX_1(beforeStyle);
909
+ #endif
910
+ #if GEA_CSS_POSITION_BOTTOM
911
+ GEA_CSS_POSITION_PX_2(geometryNormalized) = GEA_CSS_POSITION_PX_2(beforeStyle);
912
+ #endif
913
+ #if GEA_CSS_POSITION_LEFT
914
+ GEA_CSS_POSITION_PX_3(geometryNormalized) = GEA_CSS_POSITION_PX_3(beforeStyle);
915
+ #endif
916
+ if (styleEqualExceptLocalDisplayCommands(beforeStyle, geometryNormalized)) {
917
+ target.render.layout_dirty = 1;
918
+ Tree::instance().markNodeDisplayCommandsDirty(node);
919
+ return;
920
+ }
921
+ }
889
922
  target.render.layout_dirty = 1;
890
923
  Tree::instance().markDisplayListDirty();
891
924
  }
@@ -1105,11 +1138,12 @@ CssDeclarationId classifyDeclaration(const char *property)
1105
1138
  std::strcmp(property, "scroll-snap-type") == 0 ||
1106
1139
  std::strcmp(property, "scrollbar-width") == 0 ||
1107
1140
  std::strcmp(property, "text-shadow") == 0 ||
1108
- std::strcmp(property, "transition") == 0 ||
1109
1141
  std::strcmp(property, "cursor") == 0 ||
1110
1142
  std::strcmp(property, "-webkit-tap-highlight-color") == 0)
1111
1143
  return CssDeclarationId::Ignored;
1112
1144
  if (std::strcmp(property, "animation") == 0) return CssDeclarationId::Animation;
1145
+ if (std::strcmp(property, "transition") == 0) return CssDeclarationId::Transition;
1146
+ if (std::strcmp(property, "animation-play-state") == 0) return CssDeclarationId::AnimationPlayState;
1113
1147
  if (std::strcmp(property, "font") == 0) return CssDeclarationId::Font;
1114
1148
  if (std::strcmp(property, "display") == 0) return CssDeclarationId::Display;
1115
1149
  if (std::strcmp(property, "flex-direction") == 0) return CssDeclarationId::FlexDirection;
@@ -1542,6 +1576,9 @@ struct CssRule {
1542
1576
  std::uint16_t valueText;
1543
1577
  std::uint16_t mediaText;
1544
1578
  bool userAgent = false;
1579
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
1580
+ std::string debuggerSelector;
1581
+ #endif
1545
1582
  };
1546
1583
 
1547
1584
  struct CssKeyframeRule {
@@ -1620,6 +1657,9 @@ void setStyleValue(NodeHandle node, Property property, int value, StyleApplicati
1620
1657
  struct ActiveRulePlan;
1621
1658
  #if GEA_CSS_ANIMATIONS
1622
1659
  void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan = nullptr);
1660
+ void primeCssTransitionsForNode(int node, const ComputedStyle &before, const ActiveRulePlan &plan);
1661
+ bool inlineTransitionBefore(int node, Property property, double &before);
1662
+ void applyInlineTransition(int node, Property property, double before);
1623
1663
  #endif
1624
1664
  int parseOriginPart(const std::string &part, int fallback);
1625
1665
 
@@ -2495,6 +2535,10 @@ CssRule makeCssRule(CssRule::SelectorType selectorType,
2495
2535
  : kNoCompiledCssAnimationSpec;
2496
2536
  #endif
2497
2537
  const std::uint16_t mediaPlan = compileMediaConditionPlan(media);
2538
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
2539
+ const bool keepValueText = true;
2540
+ const bool keepPropertyText = true;
2541
+ #else
2498
2542
  const bool keepValueText =
2499
2543
  declaration == CssDeclarationId::Custom ||
2500
2544
  #if GEA_CSS_ANIMATIONS
@@ -2506,21 +2550,30 @@ CssRule makeCssRule(CssRule::SelectorType selectorType,
2506
2550
  keepValueText &&
2507
2551
  declaration != CssDeclarationId::Custom &&
2508
2552
  declaration != CssDeclarationId::Animation;
2553
+ #endif
2509
2554
  const std::uint16_t propertyText = keepPropertyText
2510
2555
  ? storeCssRuleText(std::move(property))
2511
2556
  : kNoCssRuleText;
2512
2557
  const std::uint16_t valueText = keepValueText
2513
2558
  ? storeCssRuleText(std::move(value))
2514
2559
  : kNoCssRuleText;
2560
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
2561
+ const std::uint16_t mediaText = storeCssRuleText(std::move(media));
2562
+ #else
2515
2563
  const std::uint16_t mediaText = mediaPlan == kNoMediaConditionPlan
2516
2564
  ? storeCssRuleText(std::move(media))
2517
2565
  : kNoCssRuleText;
2566
+ #endif
2518
2567
  CssRule rule{selectorType, pseudoElement, rulePropertyKind(declaration), declaration, compiledValue,
2519
2568
  #if GEA_CSS_ANIMATIONS
2520
2569
  compiledAnimationSpec,
2521
2570
  #endif
2522
2571
  selectorAtom, propertyAtom, selectorTagId, selectorPlan, mediaPlan,
2523
2572
  propertyText, valueText, mediaText};
2573
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
2574
+ rule.debuggerSelector = selector.str();
2575
+ if (selectorType == CssRule::SelectorType::Class) rule.debuggerSelector.insert(0, ".");
2576
+ #endif
2524
2577
  return rule;
2525
2578
  }
2526
2579
 
@@ -4169,6 +4222,8 @@ std::string firstColorToken(const std::string &value)
4169
4222
  // Parse to a RAW (pre-panel-swap) native style-value int. Callers route through
4170
4223
  // setStyleValue/pixelFromStyleValue (border fallback, keyframe colours), which
4171
4224
  // applies the panel byte-swap on 16-bit boards; identity on full-colour boards.
4225
+ ParsedCssColor parseCssColor(const std::string &value);
4226
+
4172
4227
  int parseColorStyleValue(const std::string &value)
4173
4228
  {
4174
4229
  #if GEA_RECPROF
@@ -4177,9 +4232,8 @@ int parseColorStyleValue(const std::string &value)
4177
4232
  struct ColorTimer { int64_t s; ~ColorTimer() { g_profColorUs += recNow() - s; } } _colorTimer{_ct};
4178
4233
  #endif
4179
4234
  const std::string colorValue = firstColorToken(value);
4180
- ParsedCssColor parsed;
4181
- if (parseRgbFunction(colorValue, parsed)) return static_cast<int>(gea::framework::graphics::pixel::nativeStyleValue(parsed.r, parsed.g, parsed.b));
4182
- if (parseHexCssColor(colorValue, parsed)) return static_cast<int>(gea::framework::graphics::pixel::nativeStyleValue(parsed.r, parsed.g, parsed.b));
4235
+ const ParsedCssColor parsed = parseCssColor(colorValue);
4236
+ if (parsed.valid) return static_cast<int>(gea::framework::graphics::pixel::nativeStyleValue(parsed.r, parsed.g, parsed.b));
4183
4237
  return static_cast<int>(gea::framework::graphics::pixel::nativeStyleValue(255, 255, 255));
4184
4238
  }
4185
4239
 
@@ -4198,6 +4252,167 @@ ParsedCssColor parseCssColor(const std::string &value)
4198
4252
  ParsedCssColor parsed;
4199
4253
  if (parseRgbFunction(colorValue, parsed)) return parsed;
4200
4254
  if (parseHexCssColor(colorValue, parsed)) return parsed;
4255
+ // CSS Color 4 named colors: https://www.w3.org/TR/css-color-4/#named-colors
4256
+ static constexpr struct { const char *name; std::uint32_t rgb; } namedColors[] = {
4257
+ {"aliceblue", 0xf0f8ff},
4258
+ {"antiquewhite", 0xfaebd7},
4259
+ {"aqua", 0x00ffff},
4260
+ {"aquamarine", 0x7fffd4},
4261
+ {"azure", 0xf0ffff},
4262
+ {"beige", 0xf5f5dc},
4263
+ {"bisque", 0xffe4c4},
4264
+ {"black", 0x000000},
4265
+ {"blanchedalmond", 0xffebcd},
4266
+ {"blue", 0x0000ff},
4267
+ {"blueviolet", 0x8a2be2},
4268
+ {"brown", 0xa52a2a},
4269
+ {"burlywood", 0xdeb887},
4270
+ {"cadetblue", 0x5f9ea0},
4271
+ {"chartreuse", 0x7fff00},
4272
+ {"chocolate", 0xd2691e},
4273
+ {"coral", 0xff7f50},
4274
+ {"cornflowerblue", 0x6495ed},
4275
+ {"cornsilk", 0xfff8dc},
4276
+ {"crimson", 0xdc143c},
4277
+ {"cyan", 0x00ffff},
4278
+ {"darkblue", 0x00008b},
4279
+ {"darkcyan", 0x008b8b},
4280
+ {"darkgoldenrod", 0xb8860b},
4281
+ {"darkgray", 0xa9a9a9},
4282
+ {"darkgreen", 0x006400},
4283
+ {"darkgrey", 0xa9a9a9},
4284
+ {"darkkhaki", 0xbdb76b},
4285
+ {"darkmagenta", 0x8b008b},
4286
+ {"darkolivegreen", 0x556b2f},
4287
+ {"darkorange", 0xff8c00},
4288
+ {"darkorchid", 0x9932cc},
4289
+ {"darkred", 0x8b0000},
4290
+ {"darksalmon", 0xe9967a},
4291
+ {"darkseagreen", 0x8fbc8f},
4292
+ {"darkslateblue", 0x483d8b},
4293
+ {"darkslategray", 0x2f4f4f},
4294
+ {"darkslategrey", 0x2f4f4f},
4295
+ {"darkturquoise", 0x00ced1},
4296
+ {"darkviolet", 0x9400d3},
4297
+ {"deeppink", 0xff1493},
4298
+ {"deepskyblue", 0x00bfff},
4299
+ {"dimgray", 0x696969},
4300
+ {"dimgrey", 0x696969},
4301
+ {"dodgerblue", 0x1e90ff},
4302
+ {"firebrick", 0xb22222},
4303
+ {"floralwhite", 0xfffaf0},
4304
+ {"forestgreen", 0x228b22},
4305
+ {"fuchsia", 0xff00ff},
4306
+ {"gainsboro", 0xdcdcdc},
4307
+ {"ghostwhite", 0xf8f8ff},
4308
+ {"gold", 0xffd700},
4309
+ {"goldenrod", 0xdaa520},
4310
+ {"gray", 0x808080},
4311
+ {"green", 0x008000},
4312
+ {"greenyellow", 0xadff2f},
4313
+ {"grey", 0x808080},
4314
+ {"honeydew", 0xf0fff0},
4315
+ {"hotpink", 0xff69b4},
4316
+ {"indianred", 0xcd5c5c},
4317
+ {"indigo", 0x4b0082},
4318
+ {"ivory", 0xfffff0},
4319
+ {"khaki", 0xf0e68c},
4320
+ {"lavender", 0xe6e6fa},
4321
+ {"lavenderblush", 0xfff0f5},
4322
+ {"lawngreen", 0x7cfc00},
4323
+ {"lemonchiffon", 0xfffacd},
4324
+ {"lightblue", 0xadd8e6},
4325
+ {"lightcoral", 0xf08080},
4326
+ {"lightcyan", 0xe0ffff},
4327
+ {"lightgoldenrodyellow", 0xfafad2},
4328
+ {"lightgray", 0xd3d3d3},
4329
+ {"lightgreen", 0x90ee90},
4330
+ {"lightgrey", 0xd3d3d3},
4331
+ {"lightpink", 0xffb6c1},
4332
+ {"lightsalmon", 0xffa07a},
4333
+ {"lightseagreen", 0x20b2aa},
4334
+ {"lightskyblue", 0x87cefa},
4335
+ {"lightslategray", 0x778899},
4336
+ {"lightslategrey", 0x778899},
4337
+ {"lightsteelblue", 0xb0c4de},
4338
+ {"lightyellow", 0xffffe0},
4339
+ {"lime", 0x00ff00},
4340
+ {"limegreen", 0x32cd32},
4341
+ {"linen", 0xfaf0e6},
4342
+ {"magenta", 0xff00ff},
4343
+ {"maroon", 0x800000},
4344
+ {"mediumaquamarine", 0x66cdaa},
4345
+ {"mediumblue", 0x0000cd},
4346
+ {"mediumorchid", 0xba55d3},
4347
+ {"mediumpurple", 0x9370db},
4348
+ {"mediumseagreen", 0x3cb371},
4349
+ {"mediumslateblue", 0x7b68ee},
4350
+ {"mediumspringgreen", 0x00fa9a},
4351
+ {"mediumturquoise", 0x48d1cc},
4352
+ {"mediumvioletred", 0xc71585},
4353
+ {"midnightblue", 0x191970},
4354
+ {"mintcream", 0xf5fffa},
4355
+ {"mistyrose", 0xffe4e1},
4356
+ {"moccasin", 0xffe4b5},
4357
+ {"navajowhite", 0xffdead},
4358
+ {"navy", 0x000080},
4359
+ {"oldlace", 0xfdf5e6},
4360
+ {"olive", 0x808000},
4361
+ {"olivedrab", 0x6b8e23},
4362
+ {"orange", 0xffa500},
4363
+ {"orangered", 0xff4500},
4364
+ {"orchid", 0xda70d6},
4365
+ {"palegoldenrod", 0xeee8aa},
4366
+ {"palegreen", 0x98fb98},
4367
+ {"paleturquoise", 0xafeeee},
4368
+ {"palevioletred", 0xdb7093},
4369
+ {"papayawhip", 0xffefd5},
4370
+ {"peachpuff", 0xffdab9},
4371
+ {"peru", 0xcd853f},
4372
+ {"pink", 0xffc0cb},
4373
+ {"plum", 0xdda0dd},
4374
+ {"powderblue", 0xb0e0e6},
4375
+ {"purple", 0x800080},
4376
+ {"rebeccapurple", 0x663399},
4377
+ {"red", 0xff0000},
4378
+ {"rosybrown", 0xbc8f8f},
4379
+ {"royalblue", 0x4169e1},
4380
+ {"saddlebrown", 0x8b4513},
4381
+ {"salmon", 0xfa8072},
4382
+ {"sandybrown", 0xf4a460},
4383
+ {"seagreen", 0x2e8b57},
4384
+ {"seashell", 0xfff5ee},
4385
+ {"sienna", 0xa0522d},
4386
+ {"silver", 0xc0c0c0},
4387
+ {"skyblue", 0x87ceeb},
4388
+ {"slateblue", 0x6a5acd},
4389
+ {"slategray", 0x708090},
4390
+ {"slategrey", 0x708090},
4391
+ {"snow", 0xfffafa},
4392
+ {"springgreen", 0x00ff7f},
4393
+ {"steelblue", 0x4682b4},
4394
+ {"tan", 0xd2b48c},
4395
+ {"teal", 0x008080},
4396
+ {"thistle", 0xd8bfd8},
4397
+ {"tomato", 0xff6347},
4398
+ {"turquoise", 0x40e0d0},
4399
+ {"violet", 0xee82ee},
4400
+ {"wheat", 0xf5deb3},
4401
+ {"white", 0xffffff},
4402
+ {"whitesmoke", 0xf5f5f5},
4403
+ {"yellow", 0xffff00},
4404
+ {"yellowgreen", 0x9acd32},
4405
+ };
4406
+ const std::string lower = toLowerAscii(colorValue);
4407
+ for (const auto &color : namedColors) {
4408
+ if (lower != color.name) continue;
4409
+ parsed.r = (color.rgb >> 16) & 255;
4410
+ parsed.g = (color.rgb >> 8) & 255;
4411
+ parsed.b = color.rgb & 255;
4412
+ parsed.a = 255;
4413
+ parsed.valid = true;
4414
+ break;
4415
+ }
4201
4416
  return parsed;
4202
4417
  }
4203
4418
 
@@ -4903,10 +5118,7 @@ std::vector<std::string> splitFunctionAwareWords(const std::string &value)
4903
5118
  bool isBoxShadowColorToken(const std::string &token)
4904
5119
  {
4905
5120
  const std::string lower = toLowerAscii(trimCssValue(token));
4906
- return lower == "transparent" ||
4907
- lower.rfind("rgb(", 0) == 0 ||
4908
- lower.rfind("rgba(", 0) == 0 ||
4909
- (!lower.empty() && lower[0] == '#');
5121
+ return parseCssColor(lower).valid;
4910
5122
  }
4911
5123
 
4912
5124
  struct ParsedBoxShadow {
@@ -5362,6 +5574,9 @@ int parseOriginPart(const std::string &part, int fallback)
5362
5574
  char *end = nullptr;
5363
5575
  double v = std::strtod(part.c_str(), &end);
5364
5576
  if (part.find('%') != std::string::npos) return static_cast<int>(v * 10.0 + (v >= 0.0 ? 0.5 : -0.5));
5577
+ if (end != part.c_str() && std::strcmp(end, "px") == 0 && std::isfinite(v)) {
5578
+ return absoluteOriginPixels(parseLengthForNode(part, -1, LengthAxis::Horizontal));
5579
+ }
5365
5580
  // Zero lengths, including unitless CSS zero, have the same origin as 0%.
5366
5581
  // Validate the length suffix so an unrecognized token is not treated as 0.
5367
5582
  if (v == 0.0 && end != part.c_str()) {
@@ -6320,7 +6535,7 @@ bool compileBorderShorthandValue(const std::string &value, CssCompiledValue &com
6320
6535
  continue;
6321
6536
  }
6322
6537
  if (token == "solid" || token == "dashed" || token == "dotted" || token == "double") continue;
6323
- if (part[0] == '#' || token.find("rgb") != std::string::npos || token == "transparent") continue;
6538
+ if (parseCssColor(part).valid) continue;
6324
6539
  if (foundWidth || isNegativeLengthLiteral(part)) return false;
6325
6540
  if (token == "thin" || token == "medium" || token == "thick")
6326
6541
  compiled.lengths[0] = {token == "thin" ? 1.0f : token == "medium" ? 3.0f : 5.0f, CssLengthUnit::Px};
@@ -6331,7 +6546,7 @@ bool compileBorderShorthandValue(const std::string &value, CssCompiledValue &com
6331
6546
  compiled.aux = 0;
6332
6547
  for (const auto &part : parts) {
6333
6548
  if (part.empty()) continue;
6334
- if (part[0] == '#' || part.find("rgb") != std::string::npos || toLowerAscii(part) == "transparent") {
6549
+ if (parseCssColor(part).valid) {
6335
6550
  const ParsedCssColor color = parseCssColor(part);
6336
6551
  if (!color.valid) return false;
6337
6552
  compiled.aux = 1;
@@ -8178,7 +8393,14 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
8178
8393
  return true;
8179
8394
  #endif
8180
8395
  #if GEA_UI_IMAGE_NODES
8181
- case Property::ImageId: target.image_id = value; return true;
8396
+ case Property::ImageId:
8397
+ if (target.image_id != value) {
8398
+ auto &images = gea::framework::graphics::ImageStore::instance();
8399
+ images.retain(value);
8400
+ images.release(target.image_id);
8401
+ target.image_id = value;
8402
+ }
8403
+ return true;
8182
8404
  #endif
8183
8405
  #if GEA_CSS_IMAGE_FIT
8184
8406
  case Property::ImageFit: style.image_fit = value; return true;
@@ -8760,7 +8982,7 @@ void applyBorderShorthand(NodeHandle node, const std::string &value, StyleApplic
8760
8982
  setStyleValue(node, static_cast<Property>(static_cast<int>(Property::BorderTopRelief) + side), compiled.values[2], source);
8761
8983
  for (const auto &part : parts) {
8762
8984
  if (part.empty()) continue;
8763
- if (part[0] == '#' || part.find("rgb") != std::string::npos || toLowerAscii(part) == "transparent") {
8985
+ if (parseCssColor(part).valid) {
8764
8986
  const ParsedCssColor color = parseCssColor(part);
8765
8987
  setStyleValue(node, Property::BorderColor, color.valid ? cssColorStyleValue(color) : parseColorStyleValue(value), source);
8766
8988
  if (color.valid) {
@@ -8830,7 +9052,7 @@ void applyBorderSideShorthand(NodeHandle node, int side, const std::string &valu
8830
9052
  setStyleValue(node, static_cast<Property>(static_cast<int>(Property::BorderTopRelief) + side), compiled.values[2], source);
8831
9053
  for (const auto &part : parts) {
8832
9054
  if (part.empty()) continue;
8833
- if (part[0] == '#' || part.find("rgb") != std::string::npos || toLowerAscii(part) == "transparent") {
9055
+ if (parseCssColor(part).valid) {
8834
9056
  applyBorderSideColorValue(node, side, part, source);
8835
9057
  return;
8836
9058
  }
@@ -9082,7 +9304,14 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
9082
9304
  void Style::set(Property property, int value) const
9083
9305
  {
9084
9306
  if (nodeId_ < 0) return;
9307
+ #if GEA_CSS_ANIMATIONS
9308
+ double before = 0;
9309
+ const bool transition = inlineTransitionBefore(nodeId_, property, before);
9310
+ #endif
9085
9311
  Tree::instance().setStyle(nodeId_, property, value);
9312
+ #if GEA_CSS_ANIMATIONS
9313
+ if (transition) applyInlineTransition(nodeId_, property, before);
9314
+ #endif
9086
9315
  // This element's cascaded lengths can depend on its own font too. Updating
9087
9316
  // descendants alone leaves, for example, class padding in ch at old metrics.
9088
9317
  if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId_);
@@ -9647,6 +9876,8 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9647
9876
  case CssDeclarationId::Ignored:
9648
9877
  case CssDeclarationId::Content:
9649
9878
  case CssDeclarationId::Animation:
9879
+ case CssDeclarationId::Transition:
9880
+ case CssDeclarationId::AnimationPlayState:
9650
9881
  return true;
9651
9882
  case CssDeclarationId::Width:
9652
9883
  setSizeValue(node, Property::Width, Property::WidthPercent, value, LengthAxis::Horizontal, source);
@@ -11329,8 +11560,25 @@ bool removeInlineStyleProperties(int node, std::initializer_list<Property> prope
11329
11560
  auto &state = treeState();
11330
11561
  if (node < 0 || node >= state.nodeCount) return false;
11331
11562
  bool changed = false;
11332
- if (NodeRareData *rd = rareDataFor(node))
11333
- for (const Property property : properties) changed = rd->inlineStyles.remove(property) || changed;
11563
+ if (NodeRareData *rd = rareDataFor(node)) {
11564
+ bool removedBackgroundPaint = false;
11565
+ for (const Property property : properties) {
11566
+ const bool removed = rd->inlineStyles.remove(property);
11567
+ changed = removed || changed;
11568
+ removedBackgroundPaint |= removed && (property == Property::BackgroundColor || property == Property::BackgroundImage);
11569
+ }
11570
+ // HasBackground accompanies color/image declarations. Once the last
11571
+ // inline paint is removed, its flag must also fall back to the cascade.
11572
+ if (removedBackgroundPaint) {
11573
+ bool hasInlinePaint = false;
11574
+ for (std::size_t i = 0; i < rd->inlineStyles.size(); ++i) {
11575
+ const auto &entry = rd->inlineStyles.at(i);
11576
+ hasInlinePaint |= entry.property == Property::BackgroundColor ||
11577
+ (entry.property == Property::BackgroundImage && entry.value >= 0);
11578
+ }
11579
+ if (!hasInlinePaint) changed = rd->inlineStyles.remove(Property::HasBackground) || changed;
11580
+ }
11581
+ }
11334
11582
  if (changed) recomputeSubtreeClassStyles(node);
11335
11583
  return changed;
11336
11584
  }
@@ -11946,7 +12194,8 @@ ParsedSimpleSelector staticSimpleSelectorForSpec(const StaticStyleSimpleSelector
11946
12194
  ParsedSimpleSelector p;
11947
12195
  if (spec.tag && spec.tag[0] != '\0') {
11948
12196
  const std::string tag = toLowerAscii(spec.tag);
11949
- p.hasTag = true;
12197
+ p.hasTag = tag != "*";
12198
+ p.hasMatcher = tag == "*";
11950
12199
  if (tag == "body" || tag == "html")
11951
12200
  p.rootTag = true;
11952
12201
  else
@@ -11962,7 +12211,7 @@ ParsedSimpleSelector staticSimpleSelectorForSpec(const StaticStyleSimpleSelector
11962
12211
  p.wantsFirstChild = spec.wantsFirstChild;
11963
12212
  p.wantsLastChild = spec.wantsLastChild;
11964
12213
  p.wantsHover = spec.wantsHover;
11965
- p.hasMatcher = p.wantsRoot || p.wantsFirstChild || p.wantsLastChild || p.wantsHover ||
12214
+ p.hasMatcher = p.hasMatcher || p.wantsRoot || p.wantsFirstChild || p.wantsLastChild || p.wantsHover ||
11966
12215
  p.hasTag || p.idAtom != kInvalidCssAtom || !p.classIds.empty();
11967
12216
  p.valid = p.hasMatcher;
11968
12217
  return p;
@@ -13067,6 +13316,7 @@ enum ActiveRuleBucket : std::uint8_t {
13067
13316
  #endif
13068
13317
  #if GEA_CSS_ANIMATIONS
13069
13318
  kActiveAnimation,
13319
+ kActiveMotion,
13070
13320
  #endif
13071
13321
  kActiveRuleBucketCount
13072
13322
  };
@@ -15121,6 +15371,8 @@ void addCachedActiveCandidateRule(ActiveRulePlan &plan,
15121
15371
  if (rule.propertyKind == CssRuleProperty::Animation &&
15122
15372
  rule.pseudoElement == CssRule::PseudoElement::None)
15123
15373
  plan.push(kActiveAnimation, ruleIndex);
15374
+ if ((rule.declaration == CssDeclarationId::Transition || rule.declaration == CssDeclarationId::AnimationPlayState) &&
15375
+ rule.pseudoElement == CssRule::PseudoElement::None) plan.push(kActiveMotion, ruleIndex);
15124
15376
  #endif
15125
15377
  }
15126
15378
 
@@ -15148,6 +15400,8 @@ void addActiveCandidateRule(ActiveRulePlan &plan,
15148
15400
  if (rule.propertyKind == CssRuleProperty::Animation &&
15149
15401
  rule.pseudoElement == CssRule::PseudoElement::None)
15150
15402
  plan.push(kActiveAnimation, ruleIndex);
15403
+ if ((rule.declaration == CssDeclarationId::Transition || rule.declaration == CssDeclarationId::AnimationPlayState) &&
15404
+ rule.pseudoElement == CssRule::PseudoElement::None) plan.push(kActiveMotion, ruleIndex);
15151
15405
  #endif
15152
15406
  }
15153
15407
 
@@ -15672,6 +15926,7 @@ void recomputeNodeClassStyles(int node)
15672
15926
  #endif
15673
15927
  int16_t staleRareStyle = beforeStyle.rare_style;
15674
15928
  const int beforeImageId = state.nodes[node].image_id;
15929
+ gea::framework::graphics::ImageReference previousImage(beforeImageId);
15675
15930
  state.styleInvalidationSuppressionDepth++;
15676
15931
  // Record this node's custom-property dependencies fresh (lookupCustomProperty
15677
15932
  // appends into g_nodeRefs[g_recordingNode] for every var() resolved here,
@@ -15730,6 +15985,7 @@ void recomputeNodeClassStyles(int node)
15730
15985
  #endif
15731
15986
  #if GEA_CSS_ANIMATIONS
15732
15987
  primeCssAnimationsForNode(node, &activePlan);
15988
+ primeCssTransitionsForNode(node, beforeStyle, activePlan);
15733
15989
  #endif
15734
15990
  // A runtime `src` attribute's image id is NOT class-derived, so the reset
15735
15991
  // above must not lose it: restore it unless a class rule supplied its own
@@ -15738,8 +15994,10 @@ void recomputeNodeClassStyles(int node)
15738
15994
  // every recompute of the node or any ancestor.)
15739
15995
  #if GEA_UI_IMAGE_NODES
15740
15996
  if (state.nodes[node].type == NodeType::Image && state.nodes[node].image_id < 0 &&
15741
- beforeImageId >= 0 && Tree::instance().hasAttribute(node, "src"))
15997
+ beforeImageId >= 0 && Tree::instance().hasAttribute(node, "src")) {
15998
+ gea::framework::graphics::ImageStore::instance().retain(beforeImageId);
15742
15999
  state.nodes[node].image_id = beforeImageId;
16000
+ }
15743
16001
  #endif
15744
16002
  state.styleInvalidationSuppressionDepth--;
15745
16003
  markClassRecomputeStyleDiff(node, beforeStyle, beforeImageId, firstLineChanged);
@@ -16362,6 +16620,8 @@ struct NodeCssAnimation {
16362
16620
  std::uint32_t startMs = 0;
16363
16621
  bool started = false;
16364
16622
  std::vector<int> handles;
16623
+ bool paused = false;
16624
+ std::uint32_t pauseMs = 0;
16365
16625
  };
16366
16626
 
16367
16627
  // Only nodes with animation declarations occupy storage. Style recomputation
@@ -16621,60 +16881,69 @@ CssAnimationSpec animationSpecForNodeFromActivePlan(const ActiveRulePlan &plan)
16621
16881
  return spec;
16622
16882
  }
16623
16883
 
16624
- double currentStyleValue(const Node &node, Property property)
16884
+ double currentStyleValue(const ComputedStyle &style, Property property)
16625
16885
  {
16626
16886
  switch (property) {
16627
16887
  #if GEA_CSS_TRANSFORMS
16628
- case Property::TransformRotate: return static_cast<double>(rstyle(node.computedStyle()).transform_rotate) / 10.0;
16629
- case Property::TransformRotateX: return static_cast<double>(rstyle(node.computedStyle()).transform_rotate_x) / 10.0;
16630
- case Property::TransformRotateY: return static_cast<double>(rstyle(node.computedStyle()).transform_rotate_y) / 10.0;
16631
- case Property::TransformTranslateOuterAxes: return rstyle(node.computedStyle()).transform_translate_outer_axes;
16632
- case Property::RotateAngle: return static_cast<double>(rstyle(node.computedStyle()).rotate_angle) / 10.0;
16633
- case Property::RotateAxisX: return rstyle(node.computedStyle()).rotate_axis_x;
16634
- case Property::RotateAxisY: return rstyle(node.computedStyle()).rotate_axis_y;
16635
- case Property::RotateAxisZ: return rstyle(node.computedStyle()).rotate_axis_z;
16636
- case Property::ScaleX: return rstyle(node.computedStyle()).scale_x;
16637
- case Property::ScaleY: return rstyle(node.computedStyle()).scale_y;
16638
- case Property::ScaleZ: return rstyle(node.computedStyle()).scale_z;
16639
- case Property::RotatePresent: return rstyle(node.computedStyle()).rotate_present;
16640
- case Property::ScalePresent: return rstyle(node.computedStyle()).scale_present;
16641
- case Property::TranslatePresent: return rstyle(node.computedStyle()).translate_present;
16642
- case Property::TranslateX: return rstyle(node.computedStyle()).translate_x;
16643
- case Property::TranslateY: return rstyle(node.computedStyle()).translate_y;
16644
- case Property::TranslateZ: return rstyle(node.computedStyle()).translate_z;
16645
- case Property::TranslateXPercent: return rstyle(node.computedStyle()).translate_x_percent;
16646
- case Property::TranslateYPercent: return rstyle(node.computedStyle()).translate_y_percent;
16647
- case Property::TransformTranslateX: return rstyle(node.computedStyle()).transform_translate_x;
16648
- case Property::TransformTranslateY: return rstyle(node.computedStyle()).transform_translate_y;
16649
- case Property::TransformTranslateZ: return rstyle(node.computedStyle()).transform_translate_z;
16650
- case Property::TransformTranslateXPercent: return rstyle(node.computedStyle()).transform_translate_x_percent;
16651
- case Property::TransformTranslateYPercent: return rstyle(node.computedStyle()).transform_translate_y_percent;
16652
- case Property::TransformScaleX: return rstyle(node.computedStyle()).transform_scale_x;
16653
- case Property::TransformScaleY: return rstyle(node.computedStyle()).transform_scale_y;
16654
- case Property::TransformScaleZ: return rstyle(node.computedStyle()).transform_scale_z;
16655
- #endif
16656
- case Property::FilterBlur: return (GEA_CSS_FILTERS ? rstyle(node.computedStyle()).filter_blur_radius : 0);
16657
- case Property::Opacity: return node.computedStyle().opacity;
16658
- case Property::Width: return node.computedStyle().width;
16659
- case Property::Height: return node.computedStyle().height;
16660
- case Property::WidthPercent: return node.computedStyle().width_percent == kUnset ? 0 : node.computedStyle().width_percent;
16661
- case Property::HeightPercent: return node.computedStyle().height_percent == kUnset ? 0 : node.computedStyle().height_percent;
16662
- case Property::LineHeight: return node.computedStyle().line_height;
16663
- case Property::FontWeight: return node.computedStyle().font_weight;
16664
- case Property::Top: return GEA_CSS_POSITION_PX_0(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_0(node.computedStyle());
16665
- case Property::Right: return GEA_CSS_POSITION_PX_1(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_1(node.computedStyle());
16666
- case Property::Bottom: return GEA_CSS_POSITION_PX_2(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_2(node.computedStyle());
16667
- case Property::Left: return GEA_CSS_POSITION_PX_3(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PX_3(node.computedStyle());
16668
- case Property::TopPercent: return GEA_CSS_POSITION_PERCENT_0(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_0(node.computedStyle());
16669
- case Property::RightPercent: return GEA_CSS_POSITION_PERCENT_1(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_1(node.computedStyle());
16670
- case Property::BottomPercent: return GEA_CSS_POSITION_PERCENT_2(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_2(node.computedStyle());
16671
- case Property::LeftPercent: return GEA_CSS_POSITION_PERCENT_3(node.computedStyle()) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_3(node.computedStyle());
16672
- case Property::BackgroundColor: return node.computedStyle().bg_color;
16673
- case Property::Color: return node.computedStyle().text_color;
16888
+ case Property::TransformRotate: return static_cast<double>(rstyle(style).transform_rotate) / 10.0;
16889
+ case Property::TransformRotateX: return static_cast<double>(rstyle(style).transform_rotate_x) / 10.0;
16890
+ case Property::TransformRotateY: return static_cast<double>(rstyle(style).transform_rotate_y) / 10.0;
16891
+ case Property::TransformTranslateOuterAxes: return rstyle(style).transform_translate_outer_axes;
16892
+ case Property::RotateAngle: return static_cast<double>(rstyle(style).rotate_angle) / 10.0;
16893
+ case Property::RotateAxisX: return rstyle(style).rotate_axis_x;
16894
+ case Property::RotateAxisY: return rstyle(style).rotate_axis_y;
16895
+ case Property::RotateAxisZ: return rstyle(style).rotate_axis_z;
16896
+ case Property::ScaleX: return rstyle(style).scale_x;
16897
+ case Property::ScaleY: return rstyle(style).scale_y;
16898
+ case Property::ScaleZ: return rstyle(style).scale_z;
16899
+ case Property::RotatePresent: return rstyle(style).rotate_present;
16900
+ case Property::ScalePresent: return rstyle(style).scale_present;
16901
+ case Property::TranslatePresent: return rstyle(style).translate_present;
16902
+ case Property::TranslateX: return rstyle(style).translate_x;
16903
+ case Property::TranslateY: return rstyle(style).translate_y;
16904
+ case Property::TranslateZ: return rstyle(style).translate_z;
16905
+ case Property::TranslateXPercent: return rstyle(style).translate_x_percent;
16906
+ case Property::TranslateYPercent: return rstyle(style).translate_y_percent;
16907
+ case Property::TransformTranslateX: return rstyle(style).transform_translate_x;
16908
+ case Property::TransformTranslateY: return rstyle(style).transform_translate_y;
16909
+ case Property::TransformTranslateZ: return rstyle(style).transform_translate_z;
16910
+ case Property::TransformTranslateXPercent: return rstyle(style).transform_translate_x_percent;
16911
+ case Property::TransformTranslateYPercent: return rstyle(style).transform_translate_y_percent;
16912
+ case Property::TransformScaleX: return rstyle(style).transform_scale_x;
16913
+ case Property::TransformScaleY: return rstyle(style).transform_scale_y;
16914
+ case Property::TransformScaleZ: return rstyle(style).transform_scale_z;
16915
+ #endif
16916
+ case Property::FilterBlur: return (GEA_CSS_FILTERS ? rstyle(style).filter_blur_radius : 0);
16917
+ case Property::Opacity: return style.opacity;
16918
+ case Property::Width: return style.width;
16919
+ case Property::Height: return style.height;
16920
+ case Property::WidthPercent: return style.width_percent == kUnset ? 0 : style.width_percent;
16921
+ case Property::HeightPercent: return style.height_percent == kUnset ? 0 : style.height_percent;
16922
+ case Property::LineHeight: return style.line_height;
16923
+ case Property::FontWeight: return style.font_weight;
16924
+ case Property::Top: return GEA_CSS_POSITION_PX_0(style) == kUnset ? 0 : GEA_CSS_POSITION_PX_0(style);
16925
+ case Property::Right: return GEA_CSS_POSITION_PX_1(style) == kUnset ? 0 : GEA_CSS_POSITION_PX_1(style);
16926
+ case Property::Bottom: return GEA_CSS_POSITION_PX_2(style) == kUnset ? 0 : GEA_CSS_POSITION_PX_2(style);
16927
+ case Property::Left: return GEA_CSS_POSITION_PX_3(style) == kUnset ? 0 : GEA_CSS_POSITION_PX_3(style);
16928
+ case Property::TopPercent: return GEA_CSS_POSITION_PERCENT_0(style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_0(style);
16929
+ case Property::RightPercent: return GEA_CSS_POSITION_PERCENT_1(style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_1(style);
16930
+ case Property::BottomPercent: return GEA_CSS_POSITION_PERCENT_2(style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_2(style);
16931
+ case Property::LeftPercent: return GEA_CSS_POSITION_PERCENT_3(style) == kUnset ? 0 : GEA_CSS_POSITION_PERCENT_3(style);
16932
+ case Property::BackgroundColor: return style.bg_color;
16933
+ case Property::Color: return style.text_color;
16934
+ case Property::BorderRadiusTopLeft: return style.border_radius[GEA_CSS_RADIUS_INDEX(0)];
16935
+ case Property::BorderRadiusTopRight: return style.border_radius[GEA_CSS_RADIUS_INDEX(1)];
16936
+ case Property::BorderRadiusBottomRight: return style.border_radius[GEA_CSS_RADIUS_INDEX(2)];
16937
+ case Property::BorderRadiusBottomLeft: return style.border_radius[GEA_CSS_RADIUS_INDEX(3)];
16674
16938
  default: return 0;
16675
16939
  }
16676
16940
  }
16677
16941
 
16942
+ double currentStyleValue(const Node &node, Property property)
16943
+ {
16944
+ return currentStyleValue(node.computedStyle(), property);
16945
+ }
16946
+
16678
16947
  struct CssAnimationTrack {
16679
16948
  Property property;
16680
16949
  gea::css::KeyframeList keyframes;
@@ -17097,6 +17366,161 @@ void applyPrimedAnimationValue(const gea::css::Animation &animation, double valu
17097
17366
  }
17098
17367
  }
17099
17368
 
17369
+ // Motion declarations keep their authored text and their cascade order in a
17370
+ // separate active bucket: they are timing metadata, not paint properties.
17371
+ std::string motionDeclaration(const ActiveRulePlan &plan, CssDeclarationId declaration)
17372
+ {
17373
+ std::string value;
17374
+ const auto &list = rules();
17375
+ auto visit = [&](int index) {
17376
+ const auto &rule = list[index];
17377
+ if (rule.declaration == declaration) value = cssRuleTextForHandle(rule.valueText).str();
17378
+ };
17379
+ if (plan.cachedEntry) {
17380
+ const auto bucket = activeRulePlanCachedRuleSpan(plan, kActiveMotion);
17381
+ for (std::size_t i = 0; i < bucket.count; ++i) visit(bucket.data[i].ruleIndex);
17382
+ } else {
17383
+ const auto bucket = activeRulePlanBucketSpan(plan, kActiveMotion);
17384
+ for (std::size_t i = 0; i < bucket.count; ++i) visit(bucket.data[i]);
17385
+ }
17386
+ return value;
17387
+ }
17388
+
17389
+ struct NodeCssTransition {
17390
+ int node;
17391
+ Property property;
17392
+ double target;
17393
+ int handle = 0;
17394
+ std::uint32_t duration = 0, delay = 0;
17395
+ gea::css::Easing easing = gea::css::Easing::ease();
17396
+ };
17397
+ std::vector<NodeCssTransition> &nodeCssTransitions()
17398
+ {
17399
+ static std::vector<NodeCssTransition> transitions;
17400
+ return transitions;
17401
+ }
17402
+
17403
+ bool inlineTransitionBefore(int node, Property property, double &before)
17404
+ {
17405
+ if (node < 0 || node >= treeState().nodeCount) return false;
17406
+ // Initial JSX props establish the first rendered frame, without animating
17407
+ // out of the element's uninitialized/default geometry.
17408
+ if (treeState().nodes[node].layout.width <= 0) return false;
17409
+ for (const auto &entry : nodeCssTransitions()) {
17410
+ if (entry.node != node || entry.property != property || entry.duration == 0) continue;
17411
+ before = currentStyleValue(treeState().nodes[node], property);
17412
+ return true;
17413
+ }
17414
+ return false;
17415
+ }
17416
+
17417
+ void applyInlineTransition(int node, Property property, double before)
17418
+ {
17419
+ for (auto &entry : nodeCssTransitions()) {
17420
+ if (entry.node != node || entry.property != property) continue;
17421
+ const double target = currentStyleValue(treeState().nodes[node], property);
17422
+ if (target == entry.target && gea::css::AnimationEngine::instance().contains(entry.handle)) {
17423
+ applyPrimedAnimationValue(gea::css::Animation::transition(node, property, before, target, entry.duration), before);
17424
+ return;
17425
+ }
17426
+ gea::css::AnimationEngine::instance().cancel(entry.handle);
17427
+ entry.handle = 0;
17428
+ entry.target = target;
17429
+ if (target == before || target == kUnset || before == kUnset) return;
17430
+ auto animation = gea::css::Animation::transition(node, property, before, target, entry.duration, entry.easing, entry.delay);
17431
+ animation.fill = gea::css::Fill::Both;
17432
+ applyPrimedAnimationValue(animation, before);
17433
+ entry.handle = gea::css::AnimationEngine::instance().start(std::move(animation), g_cssAnimationNowMs);
17434
+ return;
17435
+ }
17436
+ }
17437
+
17438
+ void clearNodeCssTransitions(int node)
17439
+ {
17440
+ auto &entries = nodeCssTransitions();
17441
+ entries.erase(std::remove_if(entries.begin(), entries.end(), [&](const NodeCssTransition &entry) {
17442
+ if (entry.node != node) return false;
17443
+ gea::css::AnimationEngine::instance().cancel(entry.handle);
17444
+ return true;
17445
+ }), entries.end());
17446
+ }
17447
+
17448
+ void primeCssTransitionsForNode(int node, const ComputedStyle &before, const ActiveRulePlan &plan)
17449
+ {
17450
+ const std::string declaration = motionDeclaration(plan, CssDeclarationId::Transition);
17451
+ if (declaration.empty() || declaration == "none" || isDisplayNone(treeState().nodes[node].computedStyle())) {
17452
+ clearNodeCssTransitions(node);
17453
+ return;
17454
+ }
17455
+ struct Timing { Property property; std::uint32_t duration, delay; gea::css::Easing easing; };
17456
+ std::vector<Timing> timings;
17457
+ const Property supported[] = {Property::Width, Property::Height, Property::Left, Property::Top,
17458
+ Property::Opacity, Property::BackgroundColor, Property::Color,
17459
+ Property::BorderRadiusTopLeft, Property::BorderRadiusTopRight,
17460
+ Property::BorderRadiusBottomRight, Property::BorderRadiusBottomLeft,
17461
+ Property::TransformRotate, Property::TransformRotateX, Property::TransformRotateY,
17462
+ Property::TransformTranslateX, Property::TransformTranslateY, Property::TransformTranslateZ,
17463
+ Property::TransformScaleX, Property::TransformScaleY, Property::TransformScaleZ};
17464
+ for (const auto &item : splitTopLevel(declaration, ',')) {
17465
+ std::string name = "all";
17466
+ std::uint32_t duration = 0, delay = 0;
17467
+ bool sawDuration = false;
17468
+ auto easing = gea::css::Easing::ease();
17469
+ for (const auto &token : splitCssTokens(item)) {
17470
+ std::uint32_t ms;
17471
+ if (parseTimeMs(token, ms)) {
17472
+ if (!sawDuration) { duration = ms; sawDuration = true; } else delay = ms;
17473
+ } else if (token == "linear" || token == "ease" || token == "ease-in" || token == "ease-out" ||
17474
+ token == "ease-in-out" || startsWith(token, "cubic-bezier(") || startsWith(token, "steps(")) easing = easingFromCss(token);
17475
+ else name = token;
17476
+ }
17477
+ for (Property property : supported) {
17478
+ bool matches = name == "all";
17479
+ if (name == "width") matches = property == Property::Width;
17480
+ else if (name == "height") matches = property == Property::Height;
17481
+ else if (name == "left") matches = property == Property::Left;
17482
+ else if (name == "top") matches = property == Property::Top;
17483
+ else if (name == "opacity") matches = property == Property::Opacity;
17484
+ else if (name == "background-color") matches = property == Property::BackgroundColor;
17485
+ else if (name == "color") matches = property == Property::Color;
17486
+ else if (name == "border-radius") matches = property >= Property::BorderRadiusTopLeft && property <= Property::BorderRadiusBottomLeft;
17487
+ else if (name == "transform") matches = property >= Property::TransformRotate && property <= Property::TransformScaleZ;
17488
+ if (!matches) continue;
17489
+ timings.erase(std::remove_if(timings.begin(), timings.end(), [&](const Timing &timing) { return timing.property == property; }), timings.end());
17490
+ timings.push_back({property, duration, delay, easing});
17491
+ }
17492
+ }
17493
+ auto &entries = nodeCssTransitions();
17494
+ entries.erase(std::remove_if(entries.begin(), entries.end(), [&](const NodeCssTransition &entry) {
17495
+ if (entry.node != node) return false;
17496
+ for (const auto &timing : timings) if (entry.property == timing.property) return false;
17497
+ gea::css::AnimationEngine::instance().cancel(entry.handle);
17498
+ return true;
17499
+ }), entries.end());
17500
+ for (const auto &timing : timings) {
17501
+ const double target = currentStyleValue(treeState().nodes[node], timing.property);
17502
+ auto it = std::find_if(entries.begin(), entries.end(), [&](const NodeCssTransition &entry) {
17503
+ return entry.node == node && entry.property == timing.property;
17504
+ });
17505
+ // The first computed style is a baseline, never an entrance transition.
17506
+ if (it == entries.end()) { entries.push_back({node, timing.property, target, 0, timing.duration, timing.delay, timing.easing}); continue; }
17507
+ it->duration = timing.duration; it->delay = timing.delay; it->easing = timing.easing;
17508
+ const double from = currentStyleValue(before, timing.property);
17509
+ if (it->target == target && timing.duration > 0 && gea::css::AnimationEngine::instance().contains(it->handle)) {
17510
+ applyPrimedAnimationValue(gea::css::Animation::transition(node, timing.property, from, target, timing.duration), from);
17511
+ continue;
17512
+ }
17513
+ gea::css::AnimationEngine::instance().cancel(it->handle);
17514
+ it->handle = 0;
17515
+ it->target = target;
17516
+ if (from == target || timing.duration == 0 || target == kUnset || from == kUnset) continue;
17517
+ auto animation = gea::css::Animation::transition(node, timing.property, from, target, timing.duration, timing.easing, timing.delay);
17518
+ animation.fill = gea::css::Fill::Both;
17519
+ applyPrimedAnimationValue(animation, from);
17520
+ it->handle = gea::css::AnimationEngine::instance().start(std::move(animation), g_cssAnimationNowMs);
17521
+ }
17522
+ }
17523
+
17100
17524
  void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan)
17101
17525
  {
17102
17526
  const CssAnimationSpec spec = activePlan ? animationSpecForNodeFromActivePlan(*activePlan) : animationSpecForNode(node);
@@ -17116,8 +17540,15 @@ void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan)
17116
17540
  animations.push_back({node, spec});
17117
17541
  it = animations.end() - 1;
17118
17542
  }
17543
+ const bool paused = activePlan && trimCssValue(motionDeclaration(*activePlan, CssDeclarationId::AnimationPlayState)) == "paused";
17544
+ if (it->paused != paused) {
17545
+ if (paused) it->pauseMs = g_cssAnimationNowMs;
17546
+ else it->startMs += g_cssAnimationNowMs - it->pauseMs;
17547
+ it->paused = paused;
17548
+ for (int handle : it->handles) gea::css::AnimationEngine::instance().setPaused(handle, paused, g_cssAnimationNowMs);
17549
+ }
17119
17550
  const double elapsed = it->started
17120
- ? static_cast<double>(static_cast<std::int32_t>(g_cssAnimationNowMs - it->startMs)) : 0.0;
17551
+ ? static_cast<double>(static_cast<std::int32_t>((it->paused ? it->pauseMs : g_cssAnimationNowMs) - it->startMs)) : 0.0;
17121
17552
  CssAnimationTrackList tracks;
17122
17553
  buildAnimationTracksForNode(node, spec, tracks);
17123
17554
  for (std::size_t i = 0, n = tracks.size(); i < n; ++i) {
@@ -17140,11 +17571,13 @@ void startAnimationForNode(NodeCssAnimation &entry, std::uint32_t nowMs)
17140
17571
  buildAnimationTracksForNode(entry.node, entry.spec, tracks);
17141
17572
  entry.startMs = nowMs;
17142
17573
  entry.started = true;
17574
+ if (entry.paused) entry.pauseMs = nowMs;
17143
17575
  for (std::size_t i = 0, n = tracks.size(); i < n; ++i) {
17144
17576
  const CssAnimationTrack &track = tracks.at(i);
17145
17577
  if (isRotationAxisTrack(track.property)) continue;
17146
17578
  gea::css::Animation animation = animationFromTrack(entry.node, entry.spec, track, tracks);
17147
17579
  entry.handles.push_back(gea::css::AnimationEngine::instance().start(std::move(animation), nowMs));
17580
+ if (entry.paused) gea::css::AnimationEngine::instance().setPaused(entry.handles.back(), true, nowMs);
17148
17581
  }
17149
17582
  }
17150
17583
 
@@ -17401,6 +17834,7 @@ void forgetNodeCssAnimations(int node)
17401
17834
  {
17402
17835
  #if GEA_CSS_ANIMATIONS
17403
17836
  cancelNodeCssAnimation(node);
17837
+ clearNodeCssTransitions(node);
17404
17838
  gea::css::AnimationEngine::instance().cancelNode(node);
17405
17839
  #else
17406
17840
  (void)node;
@@ -17413,6 +17847,7 @@ void StyleSheet::clear()
17413
17847
  #if GEA_CSS_ANIMATIONS
17414
17848
  keyframeRules().clear();
17415
17849
  nodeCssAnimations().clear();
17850
+ nodeCssTransitions().clear();
17416
17851
  g_cssAnimationNowMs = 0;
17417
17852
  #endif
17418
17853
  g_ruleRegistrationBatchDepth = 0;
@@ -18424,4 +18859,74 @@ extern "C" void gea_style_set_viewport_size(int width, int height)
18424
18859
  gea::embedded::ui::setViewportMetrics(width, height, 1.0);
18425
18860
  }
18426
18861
 
18862
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
18863
+ // Edit the real cascade, retaining declaration order and selector identity.
18864
+ bool debuggerSetCssRule(const std::string &selector, const std::string &media,
18865
+ const std::string &property, const std::string &value)
18866
+ {
18867
+ auto &list = rules();
18868
+ int found = -1, owner = -1;
18869
+ for (int i = 0; i < static_cast<int>(list.size()); ++i) {
18870
+ const auto &rule = list[i];
18871
+ if (rule.userAgent || rule.debuggerSelector != selector || cssRuleTextForHandle(rule.mediaText).str() != media) continue;
18872
+ owner = i;
18873
+ if (cssRuleTextForHandle(rule.propertyText).str() == property) found = i;
18874
+ }
18875
+ if (owner < 0) return false;
18876
+ if (value.empty()) {
18877
+ list.erase(std::remove_if(list.begin(), list.end(), [&](const CssRule &rule) {
18878
+ return !rule.userAgent && rule.debuggerSelector == selector &&
18879
+ cssRuleTextForHandle(rule.mediaText).str() == media &&
18880
+ cssRuleTextForHandle(rule.propertyText).str() == property;
18881
+ }), list.end());
18882
+ // An empty CSS block remains a matched, editable rule. Keep a no-op
18883
+ // declaration so its selector/media identity survives the last deletion.
18884
+ const bool remains = std::any_of(list.begin(), list.end(), [&](const CssRule &rule) {
18885
+ return !rule.userAgent && rule.debuggerSelector == selector && cssRuleTextForHandle(rule.mediaText).str() == media;
18886
+ });
18887
+ if (!remains) {
18888
+ const auto slice = selectorTextWithoutPseudo(selector.c_str(), selector.size());
18889
+ list.insert(list.begin() + std::min(owner, static_cast<int>(list.size())),
18890
+ makeCssRule(CssRule::SelectorType::Selector, slice.pseudo,
18891
+ CssText::copy(std::string(slice.data, slice.length)), CssText::copy(std::string()),
18892
+ CssText::copy(std::string()), CssText::copy(media)));
18893
+ }
18894
+ } else {
18895
+ const auto slice = selectorTextWithoutPseudo(selector.c_str(), selector.size());
18896
+ auto replacement = makeCssRule(CssRule::SelectorType::Selector, slice.pseudo,
18897
+ CssText::copy(std::string(slice.data, slice.length)), CssText::copy(property),
18898
+ CssText::copy(value), CssText::copy(media));
18899
+ if (found >= 0) list[found] = std::move(replacement);
18900
+ else list.insert(list.begin() + owner + 1, std::move(replacement));
18901
+ }
18902
+ noteStyleRuleRegistrationChanged();
18903
+ return true;
18904
+ }
18905
+
18906
+ std::vector<DebuggerCssRule> debuggerMatchedCssRules(int nodeId)
18907
+ {
18908
+ std::vector<DebuggerCssRule> out;
18909
+ rebuildRuleIndexIfNeeded();
18910
+ const auto &list = rules();
18911
+ for (int i = 0; i < static_cast<int>(list.size()); ++i) {
18912
+ const auto &rule = list[i];
18913
+ if (!ruleMatchesNode(rule, nodeId) || !ruleMediaMatchesIndex(i) || rule.debuggerSelector.empty()) continue;
18914
+ out.push_back({rule.debuggerSelector, cssRuleTextForHandle(rule.propertyText).str(),
18915
+ cssRuleTextForHandle(rule.valueText).str(), cssRuleTextForHandle(rule.mediaText).str(), rule.userAgent});
18916
+ }
18917
+ return out;
18918
+ }
18919
+
18920
+ std::vector<DebuggerCssRule> debuggerCssRules()
18921
+ {
18922
+ std::vector<DebuggerCssRule> out;
18923
+ for (const auto &rule : rules()) {
18924
+ if (rule.debuggerSelector.empty()) continue;
18925
+ out.push_back({rule.debuggerSelector, cssRuleTextForHandle(rule.propertyText).str(),
18926
+ cssRuleTextForHandle(rule.valueText).str(), cssRuleTextForHandle(rule.mediaText).str(), rule.userAgent});
18927
+ }
18928
+ return out;
18929
+ }
18930
+ #endif
18931
+
18427
18932
  } // namespace gea::embedded::ui