mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibWeb/CSS: Tell CalculationContext whether to treat numbers as integers
Calc simplification eventually produces a single style-value as its output. This extra context data will let us know whether a calculated number should be treated as a `<number>` or an `<integer>`, so that for example, `z-index: 12` and `z-index: calc(12)` both produce an `IntegerStyleValue` containing 12.
This commit is contained in:
parent
91831438e0
commit
39cefd7abf
Notes:
github-actions[bot]
2025-01-30 18:32:58 +00:00
Author: https://github.com/AtkinsSJ
Commit: 39cefd7abf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3383
2 changed files with 12 additions and 8 deletions
|
@ -1921,23 +1921,26 @@ RefPtr<CalculatedStyleValue> Parser::parse_calculated_value(ComponentValue const
|
|||
|
||||
CalculationContext context {};
|
||||
for (auto const& value_context : m_value_context.in_reverse()) {
|
||||
auto percentages_resolve_as = value_context.visit(
|
||||
[](PropertyID property_id) -> Optional<ValueType> {
|
||||
return property_resolves_percentages_relative_to(property_id);
|
||||
auto maybe_context = value_context.visit(
|
||||
[](PropertyID property_id) -> Optional<CalculationContext> {
|
||||
return CalculationContext {
|
||||
.percentages_resolve_as = property_resolves_percentages_relative_to(property_id),
|
||||
.resolve_numbers_as_integers = property_accepts_type(property_id, ValueType::Integer),
|
||||
};
|
||||
},
|
||||
[](FunctionContext const& function) -> Optional<ValueType> {
|
||||
[](FunctionContext const& function) -> Optional<CalculationContext> {
|
||||
// Gradients resolve percentages as lengths relative to the gradient-box.
|
||||
if (function.name.is_one_of_ignoring_ascii_case(
|
||||
"linear-gradient"sv, "repeating-linear-gradient"sv,
|
||||
"radial-gradient"sv, "repeating-radial-gradient"sv,
|
||||
"conic-gradient"sv, "repeating-conic-gradient"sv)) {
|
||||
return ValueType::Length;
|
||||
return CalculationContext { .percentages_resolve_as = ValueType::Length };
|
||||
}
|
||||
// FIXME: Add other functions that provide a context for resolving percentages
|
||||
// FIXME: Add other functions that provide a context for resolving values
|
||||
return {};
|
||||
});
|
||||
if (percentages_resolve_as.has_value()) {
|
||||
context.percentages_resolve_as = move(percentages_resolve_as);
|
||||
if (maybe_context.has_value()) {
|
||||
context = maybe_context.release_value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class CalculationNode;
|
|||
// Contains the context available at parse-time.
|
||||
struct CalculationContext {
|
||||
Optional<ValueType> percentages_resolve_as {};
|
||||
bool resolve_numbers_as_integers = false;
|
||||
};
|
||||
// Contains the context for resolving the calculation.
|
||||
struct CalculationResolutionContext {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue