@geastack/engine 0.1.5 → 0.1.6

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.
@@ -27,17 +27,33 @@ void LayoutSnapshot::capture()
27
27
  // ~1ms/frame on the spinning css-3d-cube (the "snap" phase); spine read these as
28
28
  // direct ComputedStyle fields. (Same regression class as the reproject path.)
29
29
  const RareStyle &rs = rstyle(state.nodes[i].style);
30
+ state.nodes[i].render.previous_transformable_box = ViewRenderer::isTransformableBox(state.nodes[i]);
30
31
  if (captureTransforms) {
32
+ state.nodes[i].render.previous_rotate_angle = rs.rotate_angle;
33
+ state.nodes[i].render.previous_rotate_axis_x = rs.rotate_axis_x;
34
+ state.nodes[i].render.previous_rotate_axis_y = rs.rotate_axis_y;
35
+ state.nodes[i].render.previous_rotate_axis_z = rs.rotate_axis_z;
36
+ state.nodes[i].render.previous_scale_x = rs.scale_x;
37
+ state.nodes[i].render.previous_scale_y = rs.scale_y;
38
+ state.nodes[i].render.previous_scale_z = rs.scale_z;
39
+
31
40
  state.nodes[i].render.previous_transform_rotate = rs.transform_rotate;
32
41
  state.nodes[i].render.previous_transform_rotate_x = rs.transform_rotate_x;
33
42
  state.nodes[i].render.previous_transform_rotate_y = rs.transform_rotate_y;
34
- state.nodes[i].render.previous_transform_translate_x = rs.transform_translate_x;
35
- state.nodes[i].render.previous_transform_translate_y = rs.transform_translate_y;
36
- state.nodes[i].render.previous_transform_translate_z = rs.transform_translate_z;
37
- state.nodes[i].render.previous_transform_translate_x_percent = rs.transform_translate_x_percent;
38
- state.nodes[i].render.previous_transform_translate_y_percent = rs.transform_translate_y_percent;
43
+ state.nodes[i].render.previous_transform_translate_x = composedTranslateX(rs);
44
+ state.nodes[i].render.previous_translate_x = rs.translate_x;
45
+ state.nodes[i].render.previous_translate_y = rs.translate_y;
46
+ state.nodes[i].render.previous_translate_z = rs.translate_z;
47
+ state.nodes[i].render.previous_translate_x_percent = rs.translate_x_percent;
48
+ state.nodes[i].render.previous_translate_y_percent = rs.translate_y_percent;
49
+ state.nodes[i].render.previous_transform_translate_outer_axes = rs.transform_translate_outer_axes;
50
+ state.nodes[i].render.previous_transform_translate_y = composedTranslateY(rs);
51
+ state.nodes[i].render.previous_transform_translate_z = composedTranslateZ(rs);
52
+ state.nodes[i].render.previous_transform_translate_x_percent = composedTranslateXPercent(rs);
53
+ state.nodes[i].render.previous_transform_translate_y_percent = composedTranslateYPercent(rs);
39
54
  state.nodes[i].render.previous_transform_scale_x = rs.transform_scale_x;
40
55
  state.nodes[i].render.previous_transform_scale_y = rs.transform_scale_y;
56
+ state.nodes[i].render.previous_transform_scale_z = rs.transform_scale_z;
41
57
  state.nodes[i].render.previous_transform_origin_x = rs.transform_origin_x;
42
58
  state.nodes[i].render.previous_transform_origin_y = rs.transform_origin_y;
43
59
  state.nodes[i].render.previous_perspective = rs.perspective;
@@ -29,14 +29,24 @@ void NodeLifecycle::init(Node *n, NodeType type)
29
29
  n->style.align_content = 0;
30
30
  n->style.align_self = -1;
31
31
  n->style.gap = 0;
32
+ n->style.order = 0;
33
+ n->style.box_sizing = 0;
34
+ n->style.float_side = 0;
35
+ n->style.clear_side = 0;
36
+ n->style.writing_mode = -1;
37
+ n->style.direction = -1;
38
+ n->style.margin_auto = 0;
39
+ n->style.row_gap = n->style.column_gap = kUnset;
40
+ n->style.row_gap_percent = n->style.column_gap_percent = kUnset;
32
41
  // Grid tracks moved to RareStyle (default 0 for a node with no rare_style),
33
42
  // so a fresh node needs no explicit reset here.
43
+ n->style.width_expression = n->style.height_expression = -1;
34
44
  n->style.width = kUnset;
35
45
  n->style.height = kUnset;
36
46
  n->style.width_percent = kUnset;
37
47
  n->style.height_percent = kUnset;
38
- n->style.min_width = 0;
39
- n->style.min_height = 0;
48
+ n->style.min_width = kUnset;
49
+ n->style.min_height = kUnset;
40
50
  n->style.max_width = kUnset;
41
51
  n->style.max_height = kUnset;
42
52
  n->style.flex = 0;
@@ -53,9 +63,10 @@ void NodeLifecycle::init(Node *n, NodeType type)
53
63
  }
54
64
  n->style.position = 0;
55
65
  n->style.z_index = 0;
66
+ n->style.z_index_auto = 1;
56
67
  n->style.bg_color = 0;
57
68
  n->style.has_bg = 0;
58
- n->style.bg_alpha = 255;
69
+ n->style.bg_alpha = 0;
59
70
  n->style.bg_fill = 0;
60
71
  // gradients + background-grid moved to RareStyle (defaults there).
61
72
  n->style.active_bg_color = 0;
@@ -75,6 +86,7 @@ void NodeLifecycle::init(Node *n, NodeType type)
75
86
  n->style.font_size = 0;
76
87
  n->style.font_weight = 400;
77
88
  n->style.line_height = 0;
89
+ n->style.line_height_multiplier = -1;
78
90
  n->style.text_align = 0;
79
91
  n->style.text_decoration = 0;
80
92
  n->style.text_transform = 0;
@@ -89,6 +101,7 @@ void NodeLifecycle::init(Node *n, NodeType type)
89
101
  n->tag_id = 0; // 0 = empty tag (interned tag table index 0)
90
102
  n->style.image_fit = 0;
91
103
  n->style.backface_hidden = 0;
104
+ n->style.visibility = 0;
92
105
  n->style.pointer_events = 0;
93
106
  n->parent = -1;
94
107
  n->first_child = -1;
@@ -110,21 +123,33 @@ void NodeLifecycle::init(Node *n, NodeType type)
110
123
  n->layout.previous_height = 0;
111
124
  n->layout.previous_scroll_x = 0;
112
125
  n->layout.previous_scroll_y = 0;
126
+ n->render.previous_rotate_angle = 0;
127
+ n->render.previous_rotate_axis_x = 0;
128
+ n->render.previous_rotate_axis_y = 0;
129
+ n->render.previous_rotate_axis_z = 1000000;
130
+ n->render.previous_scale_x = 1000;
131
+ n->render.previous_scale_y = 1000;
132
+ n->render.previous_scale_z = 1000;
113
133
  n->render.previous_transform_rotate = 0;
114
134
  n->render.previous_transform_rotate_x = 0;
115
135
  n->render.previous_transform_rotate_y = 0;
116
136
  n->render.previous_transform_translate_x = 0;
137
+ n->render.previous_translate_x = n->render.previous_translate_y = n->render.previous_translate_z = 0;
138
+ n->render.previous_translate_x_percent = n->render.previous_translate_y_percent = 0;
139
+ n->render.previous_transform_translate_outer_axes = 0;
117
140
  n->render.previous_transform_translate_y = 0;
118
141
  n->render.previous_transform_translate_z = 0;
119
142
  n->render.previous_transform_translate_x_percent = 0;
120
143
  n->render.previous_transform_translate_y_percent = 0;
121
144
  n->render.previous_transform_scale_x = 1000;
122
145
  n->render.previous_transform_scale_y = 1000;
146
+ n->render.previous_transform_scale_z = 1000;
123
147
  n->render.previous_transform_origin_x = 500;
124
148
  n->render.previous_transform_origin_y = 500;
125
149
  n->render.previous_perspective = 0;
126
150
  n->render.previous_perspective_origin_x = 500;
127
151
  n->render.previous_perspective_origin_y = 500;
152
+ n->render.previous_transformable_box = 0;
128
153
  n->render.previous_filter_blur_radius = 0;
129
154
  n->render.inline_baseline = 0;
130
155
  n->render.dirty = 0;
package/ui/node_model.h CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "pixel.h"
5
5
 
6
+ #include <algorithm>
6
7
  #include <cstdint>
7
8
  #include <cstddef>
8
9
  #include <deque>
@@ -28,6 +29,18 @@ using style_color_t = gea::framework::graphics::pixel::native_t;
28
29
  #endif
29
30
  inline constexpr int kMaxNodes = GEA_EMBEDDED_MAX_NODES;
30
31
  inline constexpr int kUnset = -32768;
32
+ // Internal value carrier for CSS z-index:auto; numeric stack levels stay int16.
33
+ inline constexpr int kZIndexAuto = INT32_MIN;
34
+ // Dimension expression slots use nonnegative values for pooled expressions,
35
+ // -1 for no expression, and these tags for intrinsic sizing keywords.
36
+ inline constexpr int kSizeMinContent = -2;
37
+ inline constexpr int kSizeMaxContent = -3;
38
+ inline constexpr int kSizeFitContent = -4;
39
+
40
+ inline bool isIntrinsicSizeExpression(int value)
41
+ {
42
+ return value >= kSizeFitContent && value <= kSizeMinContent;
43
+ }
31
44
  inline constexpr int kScrollDirtyWordCount = (kMaxNodes + 63) / 64;
32
45
  inline constexpr int kMaxGridTracks = 8;
33
46
  // Layout-time track capacity: IMPLICIT rows (an auto-flowing grid of N
@@ -37,6 +50,7 @@ inline constexpr int kMaxGridTracks = 8;
37
50
  // Template-declared tracks stay capped at kMaxGridTracks; rows beyond the
38
51
  // template are implicit (auto-sized), so only the layout locals grow.
39
52
  inline constexpr int kMaxGridLayoutTracks = 96;
53
+ inline constexpr int kGridLineSpan = 65536;
40
54
 
41
55
  #ifndef GEA_EMBEDDED_RARE_STYLE_SRAM_POOL_ENTRIES
42
56
  #define GEA_EMBEDDED_RARE_STYLE_SRAM_POOL_ENTRIES 0
@@ -54,6 +68,45 @@ inline constexpr int8_t kDisplayBlock = 0;
54
68
  inline constexpr int8_t kDisplayNone = 1;
55
69
  inline constexpr int8_t kDisplayGrid = 2;
56
70
  inline constexpr int8_t kDisplayFlex = 3;
71
+ inline constexpr int kPositionFixed = 3;
72
+ inline bool isOutOfFlowPosition(int position) { return position == 1 || position == kPositionFixed; }
73
+ // Existing alignment values occupy the low nibble. Overflow-position is
74
+ // independent of the alignment keyword and fits in the existing int8 fields.
75
+ inline constexpr int kAlignSafe = 16;
76
+ inline constexpr int kAlignUnsafe = 32;
77
+ inline constexpr int kAlignStart = 7;
78
+ inline constexpr int kAlignEnd = 8;
79
+ inline constexpr int kAlignLastBaseline = 9;
80
+ inline constexpr int kAlignSelfStart = 10;
81
+ inline constexpr int kAlignSelfEnd = 11;
82
+ inline constexpr int kAlignLeft = 12;
83
+ inline constexpr int kAlignRight = 13;
84
+ inline constexpr int kAlignSpaceEvenly = 14;
85
+ inline bool isDistributedAlignment(int alignment)
86
+ {
87
+ const int keyword = alignment & 15;
88
+ return keyword == 3 || keyword == 4 || keyword == kAlignSpaceEvenly;
89
+ }
90
+ inline int distributedAlignmentOffset(int alignment, int free, int index, int count)
91
+ {
92
+ // Cumulative division keeps rounding error from accumulating across gaps.
93
+ // Distributed alignment falls back to safe start/center on overflow.
94
+ if (free <= 0 || count <= 0) return 0;
95
+ switch (alignment & 15) {
96
+ case 3: return count > 1 ? free * index / (count - 1) : 0;
97
+ case 4: return free * (2 * index + 1) / (2 * count);
98
+ case kAlignSpaceEvenly: return free * (index + 1) / (count + 1);
99
+ default: return 0;
100
+ }
101
+ }
102
+ inline int usedAlignment(int alignment, int freeSpace, bool reversed = false)
103
+ {
104
+ if (alignment < 0) return alignment;
105
+ const int keyword = (alignment & kAlignSafe) && freeSpace < 0 ? kAlignStart : alignment & 15;
106
+ if (keyword == kAlignStart) return reversed ? 2 : 6;
107
+ if (keyword == kAlignEnd) return reversed ? 6 : 2;
108
+ return keyword;
109
+ }
57
110
 
58
111
  enum class NodeType : int8_t {
59
112
  View = 0,
@@ -80,6 +133,26 @@ inline bool isNativeButtonNodeType(NodeType type)
80
133
  // or embedded inline in ComputedStyle when GEA_EMBEDDED_RARE_STYLE_INLINE is set (defined
81
134
  // BEFORE ComputedStyle so it can be a by-value member).
82
135
  struct RareStyle {
136
+ // Logical edges: block-start/end, inline-start/end.
137
+ uint8_t margin_trim = 0;
138
+ // IEEE float bits travel through the existing integer style-value transport.
139
+ // Negative ratios mean `auto <ratio>` (prefer a replaced element's natural ratio).
140
+ int32_t aspect_ratio = 0;
141
+ int32_t flex_line_count = 1;
142
+ int32_t flex_basis_expression = -1;
143
+ int32_t line_height_expression = -1;
144
+ // Individual grid item alignment; auto defers to the parent's justify-items.
145
+ int8_t justify_self = -1;
146
+ // Computed contain flags: size, inline-size, layout, style, paint.
147
+ // Currently consumed by document background propagation.
148
+ uint8_t containment = 0;
149
+ uint16_t bg_clip = 0; // Interned clip list; zero is border-box.
150
+ // row-start, column-start, row-end, column-end; zero is auto. Positive
151
+ // spans carry kGridLineSpan, while signed integers retain explicit lines.
152
+ int32_t grid_line[4] = {};
153
+ // Deferred box edges; absent expressions do not allocate a rare-style record.
154
+ int32_t margin_expression[4] = {-1, -1, -1, -1};
155
+ int32_t padding_expression[4] = {-1, -1, -1, -1};
83
156
  // --- grid (display:grid track templates) ---
84
157
  int8_t grid_column_count = 0;
85
158
  int8_t grid_row_count = 0;
@@ -90,6 +163,19 @@ struct RareStyle {
90
163
 
91
164
  // --- transform / perspective (defaults must match NodeLifecycle::init:
92
165
  // scale 1000 = 1.0x, origins 500 = 50% center; the rest 0) ---
166
+ // Authored identity effects still establish positioning containing blocks.
167
+ uint8_t transform_present = 0;
168
+ uint8_t transform_preserve_3d = 0;
169
+ uint8_t rotate_present = 0;
170
+ int16_t rotate_angle = 0;
171
+ int32_t rotate_axis_x = 0, rotate_axis_y = 0, rotate_axis_z = 1000000;
172
+ int16_t scale_x = 1000, scale_y = 1000, scale_z = 1000;
173
+ uint8_t scale_present = 0;
174
+ uint8_t translate_present = 0;
175
+ uint8_t transform_translate_outer_axes = 0;
176
+ int16_t translate_x = 0, translate_y = 0, translate_z = 0;
177
+ int16_t translate_x_percent = 0, translate_y_percent = 0;
178
+ uint8_t filter_present = 0;
93
179
  int16_t transform_rotate = 0;
94
180
  int16_t transform_rotate_x = 0;
95
181
  int16_t transform_rotate_y = 0;
@@ -100,6 +186,7 @@ struct RareStyle {
100
186
  int16_t transform_translate_y_percent = 0;
101
187
  int16_t transform_scale_x = 1000;
102
188
  int16_t transform_scale_y = 1000;
189
+ int16_t transform_scale_z = 1000;
103
190
  int16_t transform_origin_x = 500;
104
191
  int16_t transform_origin_y = 500;
105
192
  int16_t perspective = 0;
@@ -119,6 +206,11 @@ struct RareStyle {
119
206
  // --- per-side borders (default white/opaque, matching NodeLifecycle::init;
120
207
  // only relevant when a side width > 0, which is rare) ---
121
208
  int16_t border_side_width[4] = {};
209
+ // 0: flat; 1: groove; 2: ridge; 3: inset; 4: outset.
210
+ uint8_t border_relief[4] = {};
211
+ // Bits 0..3: explicit side colors; bit 4: literal common color;
212
+ // bits 5..8: explicit side currentColor. Unspecified colors use currentColor.
213
+ uint16_t border_color_flags = 0;
122
214
  style_color_t border_side_color[4] = {
123
215
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
124
216
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
@@ -131,6 +223,10 @@ struct RareStyle {
131
223
  // --- linear / overlay / radial gradients + background grid (defaults match
132
224
  // NodeLifecycle::init: alphas 255, stops 500/1000, angle 1800, radial
133
225
  // center/extent 500/1000) ---
226
+ uint16_t bg_image_layer_count = 1; // Includes none layers.
227
+ int32_t bg_size_list = -1, bg_position_list = -1, bg_repeat_list = -1;
228
+ int32_t bg_attachment_list = -1, bg_origin_list = -1;
229
+ uint16_t bg_gradient_layer = 0, bg_overlay_gradient_layer = 0, bg_radial_gradient_layer = 0;
134
230
  style_color_t bg_gradient_from_color = 0;
135
231
  style_color_t bg_gradient_mid_color = 0;
136
232
  style_color_t bg_gradient_to_color = 0;
@@ -171,6 +267,19 @@ struct RareStyle {
171
267
  uint8_t bg_grid_line_y = 0;
172
268
  };
173
269
 
270
+ // Individual translation is applied outside the transform list. Its translation
271
+ // therefore adds to the list translation, while authored values stay independent.
272
+ inline bool hasIndividualLinearTransform(const RareStyle &s)
273
+ {
274
+ return ((s.rotate_angle % 3600) != 0 && (s.rotate_axis_x || s.rotate_axis_y || s.rotate_axis_z)) ||
275
+ s.scale_x != 1000 || s.scale_y != 1000 || s.scale_z != 1000;
276
+ }
277
+ inline int composedTranslateX(const RareStyle &s) { return int(s.transform_translate_x) + s.translate_x; }
278
+ inline int composedTranslateY(const RareStyle &s) { return int(s.transform_translate_y) + s.translate_y; }
279
+ inline int composedTranslateZ(const RareStyle &s) { return int(s.transform_translate_z) + s.translate_z; }
280
+ inline int composedTranslateXPercent(const RareStyle &s) { return int(s.transform_translate_x_percent) + s.translate_x_percent; }
281
+ inline int composedTranslateYPercent(const RareStyle &s) { return int(s.transform_translate_y_percent) + s.translate_y_percent; }
282
+
174
283
  struct ComputedStyle {
175
284
  int8_t display;
176
285
  // True iff the `display` property was explicitly authored (a CSS rule or
@@ -182,14 +291,27 @@ struct ComputedStyle {
182
291
  int8_t display_explicit;
183
292
  int8_t flex_direction;
184
293
  int8_t flex_direction_explicit;
185
- int8_t flex_wrap;
294
+ int8_t flex_wrap; // low bits: 0 nowrap, 1 wrap, 2 wrap-reverse; bit 2: balance
186
295
  int8_t justify_content;
187
296
  int8_t align_items;
188
297
  int8_t justify_items;
189
298
  int8_t align_content;
190
299
  int8_t align_self;
191
300
  int16_t gap;
192
-
301
+ int8_t box_sizing; // 0: content-box (CSS initial), 1: border-box
302
+ int8_t float_side; // 0: none, 1: left, 2: right
303
+ int8_t clear_side; // 0: none, 1: left, 2: right, 3: both
304
+ int8_t writing_mode; // -1: inherit, 0: horizontal-tb, 1: vertical-lr, 2: vertical-rl, 3: sideways-rl, 4: sideways-lr
305
+ int8_t direction; // -1: inherit, 0: ltr, 1: rtl
306
+ uint8_t margin_auto; // TRBL bit mask; numeric margins remain zero for auto
307
+ int16_t row_gap, column_gap; // kUnset falls back to native gap
308
+ int16_t row_gap_percent, column_gap_percent;
309
+ int32_t order; // Stable ordering of flex/grid items; never changes tree order.
310
+ // Inherited unitless line-height number as IEEE float bits; -1 means length/normal.
311
+ // Keep this common inherited value out of the much larger rare-style allocation.
312
+ int32_t line_height_multiplier;
313
+
314
+ int32_t width_expression, height_expression;
193
315
  int16_t width, height;
194
316
  int16_t width_percent, height_percent;
195
317
  int16_t min_width, min_height;
@@ -207,6 +329,7 @@ struct ComputedStyle {
207
329
  int16_t margin[4];
208
330
 
209
331
  int8_t position;
332
+ int8_t z_index_auto;
210
333
  int16_t pos_offsets[4];
211
334
  int16_t pos_offset_percent[4];
212
335
  int16_t z_index;
@@ -246,10 +369,10 @@ struct ComputedStyle {
246
369
  int16_t mask_right_fade_width;
247
370
  int8_t image_fit;
248
371
  // CSS `backface-visibility`: 0 = visible (default), 1 = hidden. When hidden, a
249
- // transformed face/text whose projected winding points away from the viewer is
250
- // culled — a closed opaque shape's back faces are occluded anyway, and this skips
251
- // the wasted overdraw. Default 0 = never culled (lone/visible quads stay drawn).
372
+ // flat element's entire painted subtree is culled when its back faces the viewer.
373
+ // A preserve-3d element keeps its descendants' individual visibility.
252
374
  int8_t backface_hidden;
375
+ int8_t visibility; // 0 visible, 1 hidden, 2 collapse (inherited)
253
376
  // CSS `text-decoration` — 0 = none (default), 1 = underline, 2 =
254
377
  // line-through. The text renderer paints a font-size-relative line at
255
378
  // the appropriate y-offset for each decorated run.
@@ -257,10 +380,8 @@ struct ComputedStyle {
257
380
  // CSS `text-transform` — 0 = none, 1 = uppercase, 2 = lowercase,
258
381
  // 3 = capitalize. Rendering applies this without mutating Node::text.
259
382
  int8_t text_transform;
260
- // CSS `white-space` — 0 = normal (text wraps to fit the content width,
261
- // the default), 1 = nowrap (the run is laid out as a single line and is
262
- // never broken on the available width). Inherited, matching CSS. nowrap is
263
- // the precondition for `text-overflow: ellipsis` to do anything.
383
+ // CSS `white-space`: 0 normal, 1 nowrap, 2 pre, 3 pre-wrap, 4 pre-line,
384
+ // 5 break-spaces. Inherited; space preservation and soft wrapping differ.
264
385
  int8_t white_space;
265
386
  // CSS `text-overflow` — 0 = clip (default), 1 = ellipsis. Only consulted
266
387
  // when the line cannot wrap (white-space: nowrap): an overflowing single
@@ -387,6 +508,131 @@ RareStyle &rstyleMut(ComputedStyle &style);
387
508
  void releaseRareStyle(int16_t &handle); // frees the entry (or no-op when embedded)
388
509
  void resetRareStylePool(); // drops all entries (or no-op when embedded)
389
510
 
511
+ inline bool styleHasBackgroundImage(const ComputedStyle &style)
512
+ {
513
+ const auto &rare = rstyle(style);
514
+ return style.bg_fill != 0 || rare.bg_radial_gradient || rare.bg_overlay_gradient || rare.bg_grid_axes;
515
+ }
516
+
517
+ // Authored inheritance stays in the property override; ComputedStyle always
518
+ // contains resolved device-pixel widths, so descendants never re-evaluate em.
519
+ inline constexpr int kInheritedBorderWidth = -1;
520
+ inline int computedBorderWidth(const ComputedStyle &style, int side)
521
+ {
522
+ const int specific = rstyle(style).border_side_width[side];
523
+ return specific > style.border_width ? specific : style.border_width;
524
+ }
525
+
526
+ inline bool setComputedBorderWidth(ComputedStyle &style, int side, int value, const ComputedStyle *parent)
527
+ {
528
+ int widths[4];
529
+ for (int i = 0; i < 4; ++i) {
530
+ widths[i] = computedBorderWidth(style, i);
531
+ if (side < 0 || side == i)
532
+ widths[i] = value == kInheritedBorderWidth ? (parent ? computedBorderWidth(*parent, i) : 0) : value;
533
+ }
534
+ const bool uniform = side < 0 && widths[0] == widths[1] && widths[0] == widths[2] && widths[0] == widths[3];
535
+ // A side can override a wider common border with a narrower or zero edge.
536
+ // Materialize the other sides before clearing that common width.
537
+ const int common = side < 0 ? (uniform ? widths[0] : 0) : (widths[side] < style.border_width ? 0 : style.border_width);
538
+ bool changed = common != style.border_width;
539
+ int stored[4];
540
+ for (int i = 0; i < 4; ++i) {
541
+ stored[i] = side < 0 ? (uniform ? 0 : widths[i]) : (common != style.border_width || side == i ? widths[i] : rstyle(style).border_side_width[i]);
542
+ changed |= stored[i] != rstyle(style).border_side_width[i];
543
+ }
544
+ if (!changed) return false;
545
+ style.border_width = common;
546
+ bool needsRare = false;
547
+ for (int i = 0; i < 4; ++i) needsRare |= stored[i] != rstyle(style).border_side_width[i];
548
+ if (needsRare) {
549
+ auto &rare = rstyleMut(style);
550
+ for (int i = 0; i < 4; ++i) rare.border_side_width[i] = stored[i];
551
+ }
552
+ return true;
553
+ }
554
+
555
+ inline bool setBorderColorBinding(ComputedStyle &style, int side, bool current)
556
+ {
557
+ const unsigned previous = rstyle(style).border_color_flags;
558
+ unsigned next;
559
+ if (side < 0) next = current ? 0u : 16u; // shorthand resets every side
560
+ else {
561
+ next = previous | (1u << side);
562
+ if (current) next |= 1u << (side + 5);
563
+ else next &= ~(1u << (side + 5));
564
+ }
565
+ if (next == previous) return false;
566
+ rstyleMut(style).border_color_flags = static_cast<uint16_t>(next);
567
+ return true;
568
+ }
569
+
570
+ inline bool borderColorIsCurrent(const ComputedStyle &style, int side = -1)
571
+ {
572
+ const unsigned flags = rstyle(style).border_color_flags;
573
+ if (side >= 0 && (flags & (1u << side))) return flags & (1u << (side + 5));
574
+ return !(flags & 16u);
575
+ }
576
+
577
+ inline style_color_t borderPaintColor(const ComputedStyle &style, int side = -1)
578
+ {
579
+ if (borderColorIsCurrent(style, side)) return style.text_color;
580
+ return side >= 0 && (rstyle(style).border_color_flags & (1u << side))
581
+ ? rstyle(style).border_side_color[side] : style.border_color;
582
+ }
583
+
584
+ inline uint8_t borderPaintAlpha(const ComputedStyle &style, int side = -1)
585
+ {
586
+ if (borderColorIsCurrent(style, side)) return style.text_alpha;
587
+ return side >= 0 && (rstyle(style).border_color_flags & (1u << side))
588
+ ? rstyle(style).border_side_alpha[side] : style.border_alpha;
589
+ }
590
+
591
+ inline bool borderColorsDiffer(const ComputedStyle &style)
592
+ {
593
+ for (int side = 1; side < 4; ++side)
594
+ if (borderPaintColor(style, side) != borderPaintColor(style, 0) ||
595
+ borderPaintAlpha(style, side) != borderPaintAlpha(style, 0)) return true;
596
+ return false;
597
+ }
598
+
599
+ inline bool borderUsesCurrentColor(const ComputedStyle &style)
600
+ {
601
+ for (int side = 0; side < 4; ++side)
602
+ if ((style.border_width > 0 || rstyle(style).border_side_width[side] > 0) && borderColorIsCurrent(style, side)) return true;
603
+ return false;
604
+ }
605
+
606
+ // Layout boxes include padding and borders. CSS width/height can select either
607
+ // the content box or border box, but child origins always use these insets.
608
+ inline int boxInset(const ComputedStyle &style, int side)
609
+ {
610
+ const int sideWidth = rstyle(style).border_side_width[side];
611
+ return style.padding[side] + (sideWidth > style.border_width ? sideWidth : style.border_width);
612
+ }
613
+ inline int boxInsets(const ComputedStyle &style, bool horizontal)
614
+ {
615
+ return horizontal ? boxInset(style, 1) + boxInset(style, 3) : boxInset(style, 0) + boxInset(style, 2);
616
+ }
617
+ inline int contentSizeToBorderSize(const ComputedStyle &style, int size, bool horizontal)
618
+ {
619
+ const int insets = boxInsets(style, horizontal);
620
+ const int result = size + (style.box_sizing == 0 ? insets : 0);
621
+ return result < insets ? insets : result;
622
+ }
623
+
624
+ inline int clampBorderBoxSize(const ComputedStyle &style, int size, bool horizontal)
625
+ {
626
+ const int minSize = horizontal ? style.min_width : style.min_height;
627
+ const int maxSize = horizontal ? style.max_width : style.max_height;
628
+ if (maxSize != kUnset) {
629
+ const int limit = contentSizeToBorderSize(style, maxSize, horizontal);
630
+ if (size > limit) size = limit;
631
+ }
632
+ const int floor = contentSizeToBorderSize(style, minSize == kUnset ? 0 : minSize, horizontal);
633
+ return size < floor ? floor : size;
634
+ }
635
+
390
636
  inline bool isDisplayNone(const ComputedStyle &style)
391
637
  {
392
638
  return style.display == kDisplayNone;
@@ -417,22 +663,37 @@ inline bool usesRowLayout(const ComputedStyle &style)
417
663
  return style.flex_direction_explicit ? style.flex_direction == 1 : true;
418
664
  }
419
665
 
666
+ // Keep specified axes separate: changing the other axis must undo CSS's
667
+ // visible->auto / clip->hidden computed-value conversion.
668
+ inline bool isScrollableOverflow(int value) { return value == 1 || value == 2; }
669
+ inline int usedOverflow(int axis, int other)
670
+ {
671
+ return isScrollableOverflow(other) ? (axis == 0 ? 2 : axis == 3 ? 1 : axis) : axis;
672
+ }
673
+ inline int overflowX(const ComputedStyle &style) { return usedOverflow(style.overflow_x, style.overflow_y); }
674
+ inline int overflowY(const ComputedStyle &style) { return usedOverflow(style.overflow_y, style.overflow_x); }
420
675
  inline int8_t aggregateOverflow(int8_t overflowX, int8_t overflowY)
421
676
  {
422
- if (overflowX == 2 || overflowY == 2) return 2;
423
- if (overflowX != 0 || overflowY != 0) return 1;
424
- return 0;
677
+ const int x = usedOverflow(overflowX, overflowY), y = usedOverflow(overflowY, overflowX);
678
+ if (x == 2 || y == 2) return 2;
679
+ if (x == 1 || y == 1) return 1;
680
+ return x == 3 || y == 3 ? 3 : 0;
425
681
  }
426
-
427
- inline bool scrollsOverflowX(const ComputedStyle &style)
682
+ inline bool overflowEstablishesContext(const ComputedStyle &style)
428
683
  {
429
- return style.overflow_x == 2;
684
+ return isScrollableOverflow(overflowX(style)) || isScrollableOverflow(overflowY(style));
430
685
  }
431
-
432
- inline bool scrollsOverflowY(const ComputedStyle &style)
686
+ // Grouping effects force the used transform-style to flat.
687
+ inline bool preserves3D(const ComputedStyle &style)
433
688
  {
434
- return style.overflow_y == 2;
689
+ const auto &rare = rstyle(style);
690
+ return rare.transform_preserve_3d && style.opacity == 255 &&
691
+ !isScrollableOverflow(overflowX(style)) && !isScrollableOverflow(overflowY(style)) &&
692
+ !rare.filter_present && !rare.filter_blur_radius && !(rare.containment & 16) &&
693
+ !style.mask_right_fade_width;
435
694
  }
695
+ inline bool scrollsOverflowX(const ComputedStyle &style) { return overflowX(style) == 2; }
696
+ inline bool scrollsOverflowY(const ComputedStyle &style) { return overflowY(style) == 2; }
436
697
 
437
698
  inline bool hasSideBorder(const ComputedStyle &style)
438
699
  {
@@ -449,8 +710,15 @@ inline bool hasAnyBorder(const ComputedStyle &style)
449
710
  return style.border_width > 0 || hasSideBorder(style);
450
711
  }
451
712
 
713
+ inline bool hasBorderRelief(const ComputedStyle &style)
714
+ {
715
+ const auto &r = rstyle(style);
716
+ return r.border_relief[0] || r.border_relief[1] || r.border_relief[2] || r.border_relief[3];
717
+ }
718
+
452
719
  struct LayoutBox {
453
720
  int16_t x, y;
721
+ int32_t width_expression, height_expression;
454
722
  int16_t width, height;
455
723
 
456
724
  // Inline formatting: x offset, inside this box's content area, at which the
@@ -461,6 +729,11 @@ struct LayoutBox {
461
729
  // every box that starts its own line, which is every box outside an inline
462
730
  // formatting row.
463
731
  int16_t inline_indent = 0;
732
+ // The hypothetical block-start margin edge of an out-of-flow child,
733
+ // relative to its static-position parent. Capture before relative offsets
734
+ // and absolute-coordinate conversion; retained refresh reuses this anchor.
735
+ int16_t static_block_start = 0;
736
+ uint8_t static_block_axis = 0; // 0: unavailable, 1: y, 2: x
464
737
 
465
738
  int16_t previous_x, previous_y;
466
739
  int16_t previous_width, previous_height;
@@ -503,21 +776,29 @@ struct LayoutBox {
503
776
  };
504
777
 
505
778
  struct RenderState {
779
+ int16_t previous_rotate_angle;
780
+ int32_t previous_rotate_axis_x, previous_rotate_axis_y, previous_rotate_axis_z;
781
+ int16_t previous_scale_x, previous_scale_y, previous_scale_z;
506
782
  int16_t previous_transform_rotate;
507
783
  int16_t previous_transform_rotate_x;
508
784
  int16_t previous_transform_rotate_y;
509
- int16_t previous_transform_translate_x;
510
- int16_t previous_transform_translate_y;
511
- int16_t previous_transform_translate_z;
512
- int16_t previous_transform_translate_x_percent;
513
- int16_t previous_transform_translate_y_percent;
785
+ int16_t previous_translate_x, previous_translate_y, previous_translate_z;
786
+ int16_t previous_translate_x_percent, previous_translate_y_percent;
787
+ uint8_t previous_transform_translate_outer_axes;
788
+ int32_t previous_transform_translate_x;
789
+ int32_t previous_transform_translate_y;
790
+ int32_t previous_transform_translate_z;
791
+ int32_t previous_transform_translate_x_percent;
792
+ int32_t previous_transform_translate_y_percent;
514
793
  int16_t previous_transform_scale_x;
515
794
  int16_t previous_transform_scale_y;
795
+ int16_t previous_transform_scale_z;
516
796
  int16_t previous_transform_origin_x;
517
797
  int16_t previous_transform_origin_y;
518
798
  int16_t previous_perspective;
519
799
  int16_t previous_perspective_origin_x;
520
800
  int16_t previous_perspective_origin_y;
801
+ uint8_t previous_transformable_box;
521
802
  int16_t previous_filter_blur_radius;
522
803
 
523
804
  uint8_t dirty;
@@ -560,6 +841,12 @@ struct RenderState {
560
841
  uint8_t inline_baseline;
561
842
  };
562
843
 
844
+ inline bool hadIndividualLinearTransform(const RenderState &s)
845
+ {
846
+ return ((s.previous_rotate_angle % 3600) != 0 && (s.previous_rotate_axis_x || s.previous_rotate_axis_y || s.previous_rotate_axis_z)) ||
847
+ s.previous_scale_x != 1000 || s.previous_scale_y != 1000 || s.previous_scale_z != 1000;
848
+ }
849
+
563
850
  struct Node {
564
851
  NodeType type;
565
852
  ComputedStyle style;
@@ -594,4 +881,17 @@ struct Node {
594
881
  int16_t rare_data = -1;
595
882
  };
596
883
 
884
+ // Overflow clips the padding edge on each non-visible axis. Open axes span
885
+ // the positive display coordinate range and remain stationary during replay.
886
+ inline void overflowClipBounds(const Node &node, int &x, int &y, int &w, int &h)
887
+ {
888
+ const auto &s = node.style;
889
+ const int left = boxInset(s, 3) - s.padding[3], right = boxInset(s, 1) - s.padding[1];
890
+ const int top = boxInset(s, 0) - s.padding[0], bottom = boxInset(s, 2) - s.padding[2];
891
+ x = overflowX(s) ? node.layout.x + left : 0;
892
+ y = overflowY(s) ? node.layout.y + top : 0;
893
+ w = overflowX(s) ? std::max(0, node.layout.width - left - right) : 32767;
894
+ h = overflowY(s) ? std::max(0, node.layout.height - top - bottom) : 32767;
895
+ }
896
+
597
897
  } // namespace gea::embedded::ui