Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / docs / regions / r35.md

# Region r35: CSS style values II — what other regions need to know

Region r35 ports `CSS/NumericType`, `CSS/StyleValues/CalculatedStyleValue` (the calculation tree,
its simplification, serialization and resolution) and the style values `BasicShape`,
`CounterDefinitions`, `CounterStyle`, `CounterStyleSystem`, `Counter`, `Easing`, `FilterValueList`,
`FontSource`, `FontStyle`, `GridAutoFlow`, `GridTemplateArea`, `GridTrackPlacement`,
`GridTrackSizeList` and `Transformation` (8,448 donor lines). The stub fragment
`stubs/stub_r35_style_values_2.lucb` is gone; every one of its 546 functions is ported.

## Fragments

| Fragment | Donor |
| --- | --- |
| `css/numeric_type` | `NumericType.cpp`/`.h`: unit maps, creating, adding, multiplying, inverting types, percent hints, the matches_* tests, dump |
| `css/style_values/basic_shape_style_value` | `BasicShapeStyleValue.cpp`/`.h`: inset(), xywh(), rect(), circle(), ellipse(), polygon(), path() |
| `css/style_values/calculated_style_value_1` | `CalculatedStyleValue.cpp` 1-228: the NumericValue visit helpers (`css_numeric_value_*`), CalculationContext::for_property, add/multiply the types, simplify_* templates, clamp_and_censor_numeric_value, reify_children |
| `css/style_values/calculated_style_value_2` | 229-597: serialize a math function, sort a calculation's children, serialize a calculation tree, from_style_value, the CalculationNode base |
| `css/style_values/calculated_style_value_3` | 645-1123: numeric_type_from_calculated_style_value, NumericCalculationNode, try_get_value_with_canonical_unit, try_get_number, Sum, Product, Negate, Invert |
| `css/style_values/calculated_style_value_4` | 1123-1638: Min, Max, Clamp, Abs, Sign, Sin |
| `css/style_values/calculated_style_value_5` | 1638-2124: Cos, Tan, Asin, Acos, Atan, Atan2, Pow, Sqrt |
| `css/style_values/calculated_style_value_6` | 2125-2604: Hypot, Log, Exp, Round, Mod |
| `css/style_values/calculated_style_value_7` | 2604-2904: Random, Rem, NonMathFunction |
| `css/style_values/calculated_style_value_8` | 2905-3212: CalculationResult, CalculatedStyleValue (serialize, absolutized, equals, resolve_value and the resolve_*, dump, reify) |
| `css/style_values/calculated_style_value_9` | 3213-3741: find_numeric_child_with_same_unit, make_calculation_node, simplify_a_calculation_tree (one function per step that needs more than a few lines) |
| `css/style_values/counter_definitions_style_value`, `counter_style_style_value`, `counter_style_system_style_value`, `counter_style_value` | the four counter files |
| `css/style_values/easing_style_value` | `EasingStyleValue.cpp`/`.h` |
| `css/style_values/filter_value_list_style_value` | `FilterValueListStyleValue.cpp`/`.h` (with the FilterOperation structs) |
| `css/style_values/font_source_style_value`, `font_style_style_value` | the two font files |
| `css/style_values/grid_auto_flow_style_value`, `grid_template_area_style_value`, `grid_track_placement_style_value`, `grid_track_size_list_style_value` | the four grid files |
| `css/style_values/transformation_style_value_1` | `TransformationStyleValue.cpp` 1-382: create, identity_transformation, to_matrix |
| `css/style_values/transformation_style_value_2` | 383-712: serialize (with the rotate/scale/translate properties), reify_a_transform_function, absolutized, Properties::operator== |
| `css/style_values/tests_style_values_2_cases`, `tests_style_values_2`, `tests_style_values_2_numeric_type`, `tests_style_values_2_focused` | tests (below) |

## What other regions must know

### Conventions (r34's, kept)

- Every style value class has `css_<class>_create` and `css_<class>_construct`; values are heap
  blobs (`alloc` in the current allocator); equality goes through `css_style_values_equal` and
  `<class>_equals_impl` / `properties_equal`. Calculation nodes are blobs too: `css_<node>_create`
  allocates, `css_<node>_construct` runs the base constructor and then
  `css_calculation_node_set_class` (vtable and class id).
- The `Variant` visits over `CalculationNode::NumericValue` are `css_numeric_value_serialize`,
  `_to_string`, `css_numeric_values_equal`, `_is_number`, `_is_percentage`, `_number`,
  `_percentage`, `_dimension_raw_value`, `_dimension_unit_name`, `_dimension_with_raw_value`
  (calculated_style_value_1).
- `NumericType { type, power }` as a value is `css_numeric_type_new(type, power)`.
- ValueComparing pointers of calculation nodes: `css_calculation_nodes_equal`,
  `css_optional_calculation_nodes_equal`; `BasicShape ==` is `css_basic_shapes_equal`.

### Signatures and types changed from the stubs

- `css_numeric_type_for_each_type_and_exponent(this, callback: ak.Function2[CssNumericTypeBaseType, i32, unit])`
  (the C++ template takes any callable; only phase-3 CSSNumericValue calls it).
- The internal-linkage helpers are module-private; `css_simplify_children_vector`,
  `css_simplify_child` and `css_simplify_2_children` take the node class's `create` as a function
  pointer (`CssCreateFromChildren`, ...), since a generic body cannot name `T::create`;
  `css_add_the_types_vector`, `css_multiply_the_types`, `css_run_min_or_max_operation_if_possible`
  and `css_find_numeric_child_with_same_unit` take the vector by pointer; `css_reify_children`
  takes `const (CssCalculationNode*)[]`.
- `CalculatedStyleValue::percentage_resolved_type` is declared in the donor's header and defined
  nowhere: no port (namemap row removed).
- Types filled by hand: `CssCalculatedStyleValueCalculationResult { m_value, m_type }`,
  `CssCalculatedStyleValueResolvedValue { value, type_ }` (types_calculated_style_value) and
  `CssEasingStyleValueCubicBezierCachedSample { x, y, t }` (types_easing_style_value); their
  namemap kinds are now `struct`. CalculationResult's members are named
  `css_calculated_style_value_calculation_result_*` (namemap rows added).
- Added to `stubs/stub_closure` (phase 3, Typed OM, for `reify`): `css_numeric_array_create`, the
  `css_math_{sum,product,negate,invert,min,max,clamp}_create`s, `CssTransformComponentIs2d`,
  `CssPerspectiveValueInternal`, `as_if_css_keyword_value`, `as_if_css_numeric_value`, the
  `css_{matrix_component,translate,scale,rotate,skew,skew_x,skew_y,perspective}_create`s,
  `geometry_dom_matrix_create` and the 16 `geometry_dom_matrix_set_mNN`. Each create answers
  the base class pointer (`CssNumericValue*`, `CssTransformComponent*`), which is all the
  callers use.

### Where phase-1 paths stop now (other regions' stubs)

- `CalculationContext::for_property` reaches r33's generated property data (ported).
- `BasicShapeStyleValue::to_path` reaches r50's `normalize_border_radii_data` (inset) and
  `svg_path_to_gfx_path` (r55, path()); `TransformationStyleValue::to_matrix` with a paintable
  box reaches r50's `transform_reference_box` and `layout_node`.
- `CounterStyleValue::resolve` reaches r39's CountersSet; `CounterStyleStyleValue::resolve_counter_style`
  of a name reaches r39's `StyleScope::get_registered_counter_style`.
- `@font-face src` with `format()` or `tech()` reaches r41's `font_format_is_supported` /
  `font_tech_is_supported` (three oracle cases wait, marked `!`).
- `reify` and `reify_a_transform_function` reach the phase-3 Typed OM stubs.

## Deviations and notes

- Donor behaviors kept (each commented): `CalculationResult::divide_by` multiplies by the
  divisor's uninverted type; `HypotCalculationNode::equals` compares no sizes (reading past a
  shorter `other` traps here); simplify step 6's `&child == &root_negate.child()` is always true;
  `NumericType::added_to` applies a percent hint to a type that already has one (and VERIFYs) for
  some inputs (`time hint=percent + percent`): the oracle skips that case;
  `FontSourceStyleValue::properties_equal` ignores `tech` and compares `local()` names by pointer;
  `identity_transformation(skew)` is `skew(0px)`; `GridTrackSizeListStyleValue::make_auto` and
  `make_none` build the same empty list; `CounterStyleSystemStyleValue::is_computationally_independent`
  is `VERIFY_NOT_REACHED`.
- `FontStyleStyleValue::to_font_slope`'s function-local statics cache `name_to_slope` of constant
  names; the port calls `web_fonts.name_to_slope`, which answers the same each time.
- Gfx::VectorN's `length()` and `normalized()` (used by rotate3d) are not in gfx yet; they are
  private helpers in transformation_style_value_1 (`css_float_vector3_*`) with the donor's float
  arithmetic.
- Lambdas are private functions named after their enclosing function, with the captures as
  parameters (to_matrix's `get_value`, Product's `accumulate`, ...).

## Tests

- `tests_style_values_2_cases` (455 cases; 3 more wait for r41) and `tests_style_values_2`: a local oracle
  (`luce-browser-tools/oracles/luce-browser-engine/style_values_2`: `oracle.cpp` links the
  reference build's LibWeb objects like r32's, `cases.txt`, `build.sh`, `gen_luce_cases.py`)
  parses each input (`type:` value types, `prop:` parse_css_value, `desc:` parse_descriptor_value)
  and prints the value's normal and resolved serializations, whether a second parse is equal,
  each transformation's matrix, the counter-style system's symbol-count checks, computational
  independence and the absolutized value; for a CalculatedStyleValue the calculation dump, the
  resolved NumericType, the resolves_to_* flags and all ten resolve_* in an empty context, a length
  context and a length context with a percentage basis. `ntype:` cases add, multiply, invert, make
  consistent and match NumericTypes and create them from units and unit maps. All match.
  Coverage: every math function and constant, infinities and NaN, unsimplified trees with font-
  and viewport-relative lengths, percentage-dimension mixes, random() with every sharing form,
  sibling-index()/sibling-count(), every easing form, every transform function and the rotate,
  scale and translate properties, every basic shape, font-style, font-face src, counter(),
  counters(), symbols(), counter-reset/-increment/-set, the counter-style systems, every filter
  function, grid-auto-flow, grid-template-areas, grid placements and track lists.
- `tests_style_values_2_focused`: the FilterOperation accessors, `algorithm_differs_from`, the
  CalculationResult arithmetic, `cell_name_at`, every identity transformation, the counter
  accessors and a reversed() counter definition.
- Other regions' oracles turned on: r32's `css_value_parsing` (all 19 cases marked `!`, including
  `symbols(...)`) and r33's `css_property_parsing` (all 86 cases of `later.txt`) now run and
  match.

## Compiler issues

None new. `const_span_of_pointer_diagnostic` (already reported by r30b) was hit again:
`const CssCalculationNode*[]` and `const (CssCalculationNode*)[]` print the same in the mismatch
diagnostic.