mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:08:12 +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
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