mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Add resolving calc() to a number/integer/percentage
None of these require any outside metrics, which is nice! I believe the Values-4 spec would have us simplify them down into a single value at parse time, but that's a yak for another day.
This commit is contained in:
parent
e111e8e44e
commit
2407a03fd9
Notes:
sideshowbarker
2024-07-17 19:48:33 +09:00
Author: https://github.com/AtkinsSJ
Commit: 2407a03fd9
Pull-request: https://github.com/SerenityOS/serenity/pull/12167
2 changed files with 27 additions and 0 deletions
|
@ -416,6 +416,30 @@ Optional<LengthPercentage> CalculatedStyleValue::resolve_length_percentage(Layou
|
|||
});
|
||||
}
|
||||
|
||||
Optional<Percentage> CalculatedStyleValue::resolve_percentage() const
|
||||
{
|
||||
auto result = m_expression->resolve(nullptr, {});
|
||||
if (result.value().has<Percentage>())
|
||||
return result.value().get<Percentage>();
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<float> CalculatedStyleValue::resolve_number()
|
||||
{
|
||||
auto result = m_expression->resolve(nullptr, {});
|
||||
if (result.value().has<float>())
|
||||
return result.value().get<float>();
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<i64> CalculatedStyleValue::resolve_integer()
|
||||
{
|
||||
auto result = m_expression->resolve(nullptr, {});
|
||||
if (result.value().has<float>())
|
||||
return lroundf(result.value().get<float>());
|
||||
return {};
|
||||
}
|
||||
|
||||
static bool is_number(CalculatedStyleValue::ResolvedType type)
|
||||
{
|
||||
return type == CalculatedStyleValue::ResolvedType::Number || type == CalculatedStyleValue::ResolvedType::Integer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue