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

LibWeb: Move the offset, margin and padding boxes into LayoutStyle

This commit is contained in:
Andreas Kling 2020-06-24 17:45:42 +02:00
parent 6b334e02e6
commit 4b2ac34725
9 changed files with 66 additions and 79 deletions

View file

@ -73,6 +73,11 @@ public:
return resolved(make_auto(), layout_node, reference_for_percent);
}
Length resolved_or_zero(const LayoutNode& layout_node, float reference_for_percent) const
{
return resolved(make_px(0), layout_node, reference_for_percent);
}
bool is_undefined() const { return m_type == Type::Undefined; }
bool is_percentage() const { return m_type == Type::Percentage; }
bool is_auto() const { return m_type == Type::Auto; }

View file

@ -76,14 +76,14 @@ Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fal
return value.value()->to_length();
}
Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fallback, float reference_for_percentages) const
LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id) const
{
auto value = property(id);
if (!value.has_value())
return fallback;
if (value.value()->is_percentage())
return static_cast<const PercentageStyleValue&>(*value.value()).to_length(reference_for_percentages);
return value.value()->to_length();
LengthBox box;
box.left = length_or_fallback(left_id, {});
box.top = length_or_fallback(top_id, {});
box.right = length_or_fallback(right_id, {});
box.bottom = length_or_fallback(bottom_id, {});
return box;
}
String StyleProperties::string_or_fallback(CSS::PropertyID id, const StringView& fallback) const

View file

@ -30,6 +30,7 @@
#include <AK/NonnullRefPtr.h>
#include <LibGfx/Font.h>
#include <LibGfx/Forward.h>
#include <LibWeb/CSS/LengthBox.h>
#include <LibWeb/CSS/StyleValue.h>
namespace Web {
@ -56,7 +57,7 @@ public:
Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const;
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
Length length_or_fallback(CSS::PropertyID, const Length& fallback, float reference_for_percentages) const;
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id) const;
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
CSS::TextAlign text_align() const;

View file

@ -155,7 +155,6 @@ public:
Initial,
String,
Length,
Percentage,
Color,
Identifier,
Image,
@ -171,7 +170,6 @@ public:
bool is_image() const { return type() == Type::Image; }
bool is_string() const { return type() == Type::String; }
bool is_length() const { return type() == Type::Length; }
bool is_percentage() const { return type() == Type::Percentage; }
bool is_position() const { return type() == Type::Position; }
virtual String to_string() const = 0;
@ -232,31 +230,6 @@ private:
Length m_length;
};
class PercentageStyleValue : public StyleValue {
public:
static NonnullRefPtr<PercentageStyleValue> create(float percentage)
{
return adopt(*new PercentageStyleValue(percentage));
}
virtual ~PercentageStyleValue() override { }
virtual String to_string() const override { return String::format("%g%%", m_percentage); }
Length to_length(float reference) const { return Length((m_percentage / 100.0f) * reference, Length::Type::Px); }
private:
virtual Length to_length() const override { return Length::make_auto(); }
virtual bool is_auto() const override { return false; }
explicit PercentageStyleValue(float percentage)
: StyleValue(Type::Percentage)
, m_percentage(percentage)
{
}
float m_percentage { 0 };
};
class InitialStyleValue final : public StyleValue {
public:
static NonnullRefPtr<InitialStyleValue> create() { return adopt(*new InitialStyleValue); }