summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/Length.h
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-09-30 22:57:35 +0200
committerLinus Groh <mail@linusgroh.de>2021-10-06 23:52:40 +0100
commit21ba485fd334212ba0dc1251fb164dceafdbca8d (patch)
tree037fca1e9729a37d805a4e3bdd0a514fdaf842d3 /Userland/Libraries/LibWeb/CSS/Length.h
parent0db6ca406547eb2f4fb6d584d4e17733ebaa02e8 (diff)
downloadserenity-21ba485fd334212ba0dc1251fb164dceafdbca8d.zip
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/Length.h')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h47
1 files changed, 11 insertions, 36 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index 0e05727ba0..2fa50e4527 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -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;