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

LibWeb: Add CSS::Percentage, PercentageOr and LengthPercentage types

Length and Percentage are different types, and sometimes only one or the
other is allowed in a given CSS property. This is a first step towards
separating them.
This commit is contained in:
Sam Atkins 2022-01-14 12:23:54 +00:00 committed by Andreas Kling
parent 71ab8fb757
commit 01b57fa8b7
5 changed files with 158 additions and 2 deletions

View file

@ -10,6 +10,7 @@
#include <LibGfx/Font.h>
#include <LibGfx/Rect.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLHtmlElement.h>
@ -32,11 +33,22 @@ Length Length::make_auto()
{
return Length(0, Type::Auto);
}
Length Length::make_px(float value)
{
return Length(value, Type::Px);
}
Length Length::percentage_of(Percentage const& percentage) const
{
if (is_undefined_or_auto()) {
dbgln("Attempting to get percentage of an undefined or auto length, this seems wrong? But for now we just return the original length.");
return *this;
}
return Length { percentage.as_fraction() * raw_value(), m_type };
}
Length Length::resolved(const Length& fallback_for_undefined, const Layout::Node& layout_node, float reference_for_percent) const
{
if (is_undefined())