Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/Layout/Node.cpp (C++)

Code before:
            layer.background_image->as_image().visit_edges(visitor);
    }
    if (m_list_style_image && m_list_style_image->is_image())
        m_list_style_image->as_image().visit_edges(visitor);
}

void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
{
    auto& computed_values = mutable_computed_values();

    // NOTE: color-scheme must be set first to ensure system colors can be resolved correctly.
    computed_values.set_color_scheme(computed_style.color_scheme(document().page().preferred_color_scheme(), document().supported_color_schemes()));

    // NOTE: We have to be careful that font-related properties get set in the right order.
    //       m_font is used by Length::to_px() when resolving sizes against this layout node.
    //       That's why it has to be set before everything else.
    computed_values.set_font_list(computed_style.computed_font_list(document().font_computer()));
    computed_values.set_font_size(computed_style.font_size());
    computed_values.set_font_weight(computed_style.font_weight());
    computed_values.set_line_height(computed_style.line_height());

    // NOTE: color must be set after color-scheme to ensure currentColor can be resolved in other properties (e.g. background-color).
    // NOTE: color must be set after font_size as `CalculatedStyleValue`s can rely on it being set for resolving lengths.
    computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, CSS::ColorResolutionContext::for_layout_node_with_style(*this), CSS::InitialValues::color()));
    // NOTE: Currently there are still discussions about `accentColor` and `currentColor` interactions, so the line below might need changing in the future
    computed_values.set_accent_color(computed_style.color_or_fallback(CSS::PropertyID::AccentColor, CSS::ColorResolutionContext::for_layout_node_with_style(*this), CSS::InitialValues::accent_color()));
    // NOTE: This color resolution context must be created after we set color above so that currentColor resolves correctly
    // FIXME: We should resolve colors to their absolute forms at compute time (i.e. by implementing the relevant absolutized methods)
    auto color_resolution_context = CSS::ColorResolutionContext::for_layout_node_with_style(*this);

    computed_values.set_vertical_align(computed_style.vertical_align());

    auto background_layers = computed_style.background_layers();

    for (auto const& layer : background_layers) {
        if (layer.background_image)
            const_cast<CSS::AbstractImageStyleValue&>(*layer.background_image).load_any_resources(document());
    }

    computed_values.set_background_layers(move(background_layers));

    computed_values.set_background_color(computed_style.color_or_fallback(CSS::PropertyID::BackgroundColor, color_resolution_context, CSS::InitialValues::background_color()));

    computed_values.set_box_sizing(computed_style.box_sizing());

    if (auto maybe_font_language_override = computed_style.font_language_override(); maybe_font_language_override.has_value())
        computed_values.set_font_language_override(maybe_font_language_override.release_value());
    computed_values.set_font_features(computed_style.font_features());
    computed_values.set_font_variation_settings(computed_style.font_variation_settings());

    auto const& border_bottom_left_radius = computed_style.property(CSS::PropertyID::BorderBottomLeftRadius);

Review comment (suggestion):
Same point about InitialValues::accent_color(), but you'll have to get the `color_scheme` from `computed_values`.

Code after:

    auto has_z_index = computed_values.z_index().has_value() || will_change_property(CSS::PropertyID::ZIndex);

    // Element with a position value absolute or relative and z-index value other than auto.
    if (position == CSS::Positioning::Absolute || position == CSS::Positioning::Relative) {
        if (has_z_index) {
            return true;
        }
    }

    // Element with a position value fixed or sticky.
    if (position == CSS::Positioning::Fixed || position == CSS::Positioning::Sticky
        || will_change_property(CSS::PropertyID::Position)) {
        return true;
    }

    if (!computed_values.transformations().is_empty() || will_change_property(CSS::PropertyID::Transform))
        return true;

    if (computed_values.translate() || will_change_property(CSS::PropertyID::Translate))
        return true;

    if (computed_values.rotate() || will_change_property(CSS::PropertyID::Rotate))
        return true;

    if (computed_values.scale() || will_change_property(CSS::PropertyID::Scale))
        return true;

    // Element that is a child of a flex container, with z-index value other than auto.
    if (parent() && parent()->display().is_flex_inside() && has_z_index)
        return true;

    // Element that is a child of a grid container, with z-index value other than auto.
    if (parent() && parent()->display().is_grid_inside() && has_z_index)
        return true;

    // https://drafts.fxtf.org/filter-effects/#FilterProperty
    // https://drafts.fxtf.org/filter-effects-2/#backdrop-filter-operation
    // A computed value of other than none results in the creation of both a stacking context
    // [CSS21] and a Containing Block for absolute and fixed position descendants, unless the
    // element it applies to is a document root element in the current browsing context.
    // Spec Note: This rule works in the same way as for the filter property.
    if (computed_values.backdrop_filter().has_filters() || computed_values.filter().has_filters()
        || will_change_property(CSS::PropertyID::BackdropFilter)
        || will_change_property(CSS::PropertyID::Filter)) {
        return true;
    }

    // Element with any of the following properties with value other than none:
    // - transform
    // - filter