1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibWeb: Add basic support for CSS percentages

Many properties can now have percentage values that get resolved in
layout. The reference value (what is this a percentage *of*?) differs
per property, so I've added a helper where you provide a reference
value as an added parameter to the existing length_or_fallback().
This commit is contained in:
Andreas Kling 2020-05-11 23:04:59 +02:00
parent 8ffdcce0d0
commit 5f9d80d8bc
7 changed files with 117 additions and 31 deletions

View file

@ -71,6 +71,16 @@ Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fal
return value.value()->to_length();
}
Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fallback, float reference_for_percentages) const
{
auto value = property(id);
if (!value.has_value())
return fallback;
if (value.value()->is_percentage())
return static_cast<const PercentageStyleValue&>(*value.value()).to_length(reference_for_percentages);
return value.value()->to_length();
}
String StyleProperties::string_or_fallback(CSS::PropertyID id, const StringView& fallback) const
{
auto value = property(id);