LibWeb: Parse CSS fit-content(<length-percentage>) values

Before this change, we only parsed fit-content as a standalone keyword,
but CSS-SIZING-3 added it as a function as well. I don't know of
anything else in CSS that is overloaded like this, so it ends up looking
a little awkward in the implementation.

Note that a lot of code had already been prepped for fit-content values
to have an argument, we just weren't parsing it.
This commit is contained in:
Andreas Kling 2025-02-26 18:16:36 +01:00 committed by Andreas Kling
parent 6fc19ec059
commit 8ab61843be
Notes: github-actions[bot] 2025-02-26 23:45:14 +00:00
25 changed files with 185 additions and 67 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
@ -31,6 +31,7 @@
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
@ -301,6 +302,12 @@ Optional<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readon
}
}
if (auto property = any_property_accepts_type(property_ids, ValueType::FitContent); property.has_value()) {
auto context_guard = push_temporary_value_parsing_context(*property);
if (auto value = parse_fit_content_value(tokens))
return PropertyAndValue { *property, value };
}
if (auto property = any_property_accepts_type(property_ids, ValueType::Length); property.has_value()) {
auto context_guard = push_temporary_value_parsing_context(*property);
if (property_accepts_type(*property, ValueType::Percentage)) {