mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibWeb: Resolve cyclic dependency: Length and CalculatedStyleValue
Previously: Length (and all nearly all of its inline method definitions) depended on the definition of class CalculatedStyleValue. Meanwhile, CalculatedStyleValue (and nearly all of its namespaced structs) depended on the definition of class Length. Thus, a compilation unit that (for example) only contains #include <Userland/Libraries/LibWeb/CSS/Length.h> would fail to compile. This patch resolves this issue by pushing the inline definition of various Web::CSS::Length methods into a different file.
This commit is contained in:
parent
0db6ca4065
commit
21ba485fd3
2 changed files with 60 additions and 36 deletions
|
@ -16,6 +16,55 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
Length::Length() = default;
|
||||
Length::Length(int value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
Length::Length(float value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Length Length::make_auto()
|
||||
{
|
||||
return Length(0, Type::Auto);
|
||||
}
|
||||
Length Length::make_px(float value)
|
||||
{
|
||||
return Length(value, Type::Px);
|
||||
}
|
||||
|
||||
Length Length::resolved(const Length& fallback_for_undefined, const Layout::Node& layout_node, float reference_for_percent) const
|
||||
{
|
||||
if (is_undefined())
|
||||
return fallback_for_undefined;
|
||||
if (is_calculated())
|
||||
return Length(resolve_calculated_value(layout_node, reference_for_percent), Type::Px);
|
||||
if (is_percentage())
|
||||
return make_px(raw_value() / 100.0f * reference_for_percent);
|
||||
if (is_relative())
|
||||
return make_px(to_px(layout_node));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Length Length::resolved_or_auto(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
{
|
||||
return resolved(make_auto(), layout_node, reference_for_percent);
|
||||
}
|
||||
|
||||
Length Length::resolved_or_zero(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
{
|
||||
return resolved(make_px(0), layout_node, reference_for_percent);
|
||||
}
|
||||
|
||||
void Length::set_calculated_style(CalculatedStyleValue* value)
|
||||
{
|
||||
m_calculated_style = value;
|
||||
}
|
||||
|
||||
float Length::relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float root_font_size) const
|
||||
{
|
||||
switch (m_type) {
|
||||
|
|
|
@ -36,43 +36,18 @@ public:
|
|||
Vmin,
|
||||
};
|
||||
|
||||
Length() = default;
|
||||
Length(int value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
Length(float value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
// We have a RefPtr<CalculatedStyleValue> member, but can't include the header StyleValue.h as it includes
|
||||
// this file already. To break the cyclic dependency, we must move all method definitions out.
|
||||
Length();
|
||||
Length(int value, Type type);
|
||||
Length(float value, Type type);
|
||||
|
||||
static Length make_auto() { return Length(0, Type::Auto); }
|
||||
static Length make_px(float value) { return Length(value, Type::Px); }
|
||||
static Length make_auto();
|
||||
static Length make_px(float value);
|
||||
|
||||
Length resolved(const Length& fallback_for_undefined, const Layout::Node& layout_node, float reference_for_percent) const
|
||||
{
|
||||
if (is_undefined())
|
||||
return fallback_for_undefined;
|
||||
if (is_calculated())
|
||||
return Length(resolve_calculated_value(layout_node, reference_for_percent), Type::Px);
|
||||
if (is_percentage())
|
||||
return make_px(raw_value() / 100.0f * reference_for_percent);
|
||||
if (is_relative())
|
||||
return make_px(to_px(layout_node));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Length resolved_or_auto(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
{
|
||||
return resolved(make_auto(), layout_node, reference_for_percent);
|
||||
}
|
||||
|
||||
Length resolved_or_zero(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
{
|
||||
return resolved(make_px(0), layout_node, reference_for_percent);
|
||||
}
|
||||
Length resolved(const Length& fallback_for_undefined, const Layout::Node& layout_node, float reference_for_percent) const;
|
||||
Length resolved_or_auto(const Layout::Node& layout_node, float reference_for_percent) const;
|
||||
Length resolved_or_zero(const Layout::Node& layout_node, float reference_for_percent) const;
|
||||
|
||||
bool is_undefined_or_auto() const { return m_type == Type::Undefined || m_type == Type::Auto; }
|
||||
bool is_undefined() const { return m_type == Type::Undefined; }
|
||||
|
@ -157,7 +132,7 @@ public:
|
|||
return !(*this == other);
|
||||
}
|
||||
|
||||
void set_calculated_style(CalculatedStyleValue* value) { m_calculated_style = value; }
|
||||
void set_calculated_style(CalculatedStyleValue* value);
|
||||
|
||||
float relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float root_font_size) const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue