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:
parent
8ffdcce0d0
commit
5f9d80d8bc
7 changed files with 117 additions and 31 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue