LibWeb: Add the 'float' CSS property to LayoutStyle

Note that we don't use the property for anything yet, as I'm still
wrapping my head around how to implement floats.
This commit is contained in:
Andreas Kling 2020-06-26 15:08:42 +02:00
parent 53f1090b86
commit 62daa6f73c
Notes: sideshowbarker 2024-07-19 05:22:11 +09:00
6 changed files with 38 additions and 0 deletions

View file

@ -263,6 +263,21 @@ Optional<CSS::WhiteSpace> StyleProperties::white_space() const
return {};
}
Optional<CSS::Float> StyleProperties::float_() const
{
auto value = property(CSS::PropertyID::Float);
if (!value.has_value() || !value.value()->is_string())
return {};
auto string = value.value()->to_string();
if (string == "none")
return CSS::Float::None;
if (string == "left")
return CSS::Float::Left;
if (string == "right")
return CSS::Float::Right;
return {};
}
CSS::Display StyleProperties::display() const
{
auto display = string_or_fallback(CSS::PropertyID::Display, "inline");

View file

@ -62,6 +62,7 @@ public:
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
CSS::TextAlign text_align() const;
CSS::Display display() const;
Optional<CSS::Float> float_() const;
Optional<CSS::WhiteSpace> white_space() const;
const Gfx::Font& font() const

View file

@ -143,6 +143,12 @@ enum class WhiteSpace {
PreWrap,
};
enum class Float {
None,
Left,
Right,
};
}
class StyleValue : public RefCounted<StyleValue> {

View file

@ -181,6 +181,13 @@ Gfx::FloatPoint LayoutNode::box_type_agnostic_position() const
return position;
}
bool LayoutNode::is_floating() const
{
if (!has_style())
return false;
return style().float_() != CSS::Float::None;
}
bool LayoutNode::is_absolutely_positioned() const
{
if (!has_style())
@ -216,6 +223,10 @@ void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style)
if (white_space.has_value())
style.set_white_space(white_space.value());
auto float_ = specified_style.float_();
if (float_.has_value())
style.set_float(float_.value());
style.set_z_index(specified_style.z_index());
style.set_width(specified_style.length_or_fallback(CSS::PropertyID::Width, {}));
style.set_min_width(specified_style.length_or_fallback(CSS::PropertyID::MinWidth, {}));

View file

@ -181,6 +181,7 @@ public:
};
virtual void paint(PaintContext&, PaintPhase);
bool is_floating() const;
bool is_absolutely_positioned() const;
bool is_fixed_position() const;

View file

@ -34,6 +34,7 @@ namespace Web {
class InitialValues {
public:
static CSS::Float float_() { return CSS::Float::None; }
static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
};
@ -45,6 +46,7 @@ public:
class LayoutStyle {
public:
CSS::Float float_() const { return m_float; }
Optional<int> z_index() const { return m_z_index; }
CSS::TextAlign text_align() const { return m_text_align; }
CSS::Position position() const { return m_position; }
@ -66,6 +68,7 @@ public:
const BorderData& border_bottom() const { return m_border_bottom; }
protected:
CSS::Float m_float { InitialValues::float_() };
Optional<int> m_z_index;
CSS::TextAlign m_text_align;
CSS::Position m_position;
@ -90,6 +93,7 @@ class ImmutableLayoutStyle final : public LayoutStyle {
class MutableLayoutStyle final : public LayoutStyle {
public:
void set_float(CSS::Float value) { m_float = value; }
void set_z_index(Optional<int> value) { m_z_index = value; }
void set_text_align(CSS::TextAlign text_align) { m_text_align = text_align; }
void set_position(CSS::Position position) { m_position = position; }