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

LibWeb: Use LengthPercentage in CSS::GridSize

Using LengthPercentage instead of Length and Percentage separately
is going to allow GridSize to store calc() values. It also allows
to simplify some parts of layout code.
This commit is contained in:
Aliaksandr Kalenik 2023-05-10 22:38:44 +03:00 committed by Andreas Kling
parent 6a21bbb5b2
commit 7fee05e18c
3 changed files with 53 additions and 75 deletions

View file

@ -7,23 +7,20 @@
#pragma once
#include <AK/Vector.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/CSS/PercentageOr.h>
namespace Web::CSS {
class GridSize {
public:
enum class Type {
Length,
Percentage,
LengthPercentage,
FlexibleLength,
MaxContent,
MinContent,
};
GridSize(Length);
GridSize(Percentage);
GridSize(LengthPercentage);
GridSize(float);
GridSize(Type);
GridSize();
@ -33,14 +30,13 @@ public:
Type type() const { return m_type; }
bool is_length() const { return m_type == Type::Length; }
bool is_percentage() const { return m_type == Type::Percentage; }
bool is_auto() const { return m_type == Type::LengthPercentage && m_length_percentage.is_auto(); }
bool is_length_percentage() const { return m_type == Type::LengthPercentage; }
bool is_flexible_length() const { return m_type == Type::FlexibleLength; }
bool is_max_content() const { return m_type == Type::MaxContent; }
bool is_min_content() const { return m_type == Type::MinContent; }
Length length() const;
Percentage percentage() const { return m_percentage; }
LengthPercentage length_percentage() const { return m_length_percentage; };
float flexible_length() const { return m_flexible_length; }
// https://www.w3.org/TR/css-grid-2/#layout-algorithm
@ -48,29 +44,27 @@ public:
// FIXME: Add missing properties once implemented.
bool is_intrinsic_track_sizing() const
{
return (m_type == Type::Length && m_length.is_auto()) || m_type == Type::MaxContent || m_type == Type::MinContent;
return is_auto() || is_max_content() || is_min_content();
}
bool is_definite() const
{
return (m_type == Type::Length && !m_length.is_auto()) || is_percentage();
return type() == Type::LengthPercentage && !m_length_percentage.is_auto();
}
Size css_size() const;
ErrorOr<String> to_string() const;
bool operator==(GridSize const& other) const
{
return m_type == other.type()
&& m_length == other.length()
&& m_percentage == other.percentage()
&& m_length_percentage == other.length_percentage()
&& m_flexible_length == other.flexible_length();
}
private:
Type m_type;
// Length includes a RefPtr<CalculatedStyleValue> member, but we can't include the header StyleValue.h as it includes
// this file already. To break the cyclic dependency, we must initialize m_length in the constructor.
Length m_length;
Percentage m_percentage { Percentage(0) };
LengthPercentage m_length_percentage;
float m_flexible_length { 0 };
};