mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:37:36 +00:00
LibWeb: Remove default Length constructor and add make_auto()/make_px()
To prepare for adding an undefined/empty state for Length, let's first move away from Length() creating an auto value.
This commit is contained in:
parent
26eef65017
commit
5744dd43c5
7 changed files with 60 additions and 58 deletions
|
@ -40,7 +40,6 @@ public:
|
|||
Rem,
|
||||
};
|
||||
|
||||
Length() { }
|
||||
Length(int value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
|
@ -52,6 +51,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
static Length make_auto() { return Length(0, Type::Auto); }
|
||||
static Length make_px(float value) { return Length(value, Type::Px); }
|
||||
|
||||
bool is_auto() const { return m_type == Type::Auto; }
|
||||
bool is_absolute() const { return m_type == Type::Px; }
|
||||
bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; }
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
namespace Web {
|
||||
|
||||
struct LengthBox {
|
||||
Length top;
|
||||
Length right;
|
||||
Length bottom;
|
||||
Length left;
|
||||
Length top { Length::make_auto() };
|
||||
Length right { Length::make_auto() };
|
||||
Length bottom { Length::make_auto() };
|
||||
Length left { Length::make_auto() };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ void StyleProperties::load_font() const
|
|||
|
||||
float StyleProperties::line_height(const LayoutNode& layout_node) const
|
||||
{
|
||||
auto line_height_length = length_or_fallback(CSS::PropertyID::LineHeight, {});
|
||||
auto line_height_length = length_or_fallback(CSS::PropertyID::LineHeight, Length::make_auto());
|
||||
if (line_height_length.is_absolute())
|
||||
return (float)line_height_length.to_px(layout_node);
|
||||
return (float)font().glyph_height() * 1.4f;
|
||||
|
|
|
@ -155,7 +155,7 @@ public:
|
|||
bool is_position() const { return type() == Type::Position; }
|
||||
|
||||
virtual String to_string() const = 0;
|
||||
virtual Length to_length() const { return {}; }
|
||||
virtual Length to_length() const { return Length::make_auto(); }
|
||||
virtual Color to_color(const Document&) const { return {}; }
|
||||
|
||||
virtual bool is_auto() const { return false; }
|
||||
|
@ -225,7 +225,7 @@ public:
|
|||
Length to_length(float reference) const { return Length((m_percentage / 100.0f) * reference, Length::Type::Px); }
|
||||
|
||||
private:
|
||||
virtual Length to_length() const override { return {}; }
|
||||
virtual Length to_length() const override { return Length::make_auto(); }
|
||||
virtual bool is_auto() const override { return false; }
|
||||
|
||||
explicit PercentageStyleValue(float percentage)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue