1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

LibWeb: Add parsing and application of CSS "overflow" property

We don't actually do anything with the values yet, but now they are
available for layout nodes once we are ready to implement them.
This commit is contained in:
Andreas Kling 2021-02-22 15:20:31 +01:00
parent 42f582bf8b
commit 21371bf6ee
8 changed files with 85 additions and 0 deletions

View file

@ -46,6 +46,7 @@ public:
static Color background_color() { return Color::Transparent; }
static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; }
static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; }
static CSS::Overflow overflow() { return CSS::Overflow::Visible; }
};
struct BorderData {
@ -83,6 +84,9 @@ public:
const BorderData& border_right() const { return m_noninherited.border_right; }
const BorderData& border_bottom() const { return m_noninherited.border_bottom; }
CSS::Overflow overflow_x() const { return m_noninherited.overflow_x; }
CSS::Overflow overflow_y() const { return m_noninherited.overflow_y; }
Color color() const { return m_inherited.color; }
Color background_color() const { return m_noninherited.background_color; }
@ -126,6 +130,8 @@ protected:
BorderData border_bottom;
Color background_color { InitialValues::background_color() };
CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
CSS::Overflow overflow_x { InitialValues::overflow() };
CSS::Overflow overflow_y { InitialValues::overflow() };
} m_noninherited;
};
@ -153,6 +159,8 @@ public:
void set_offset(const CSS::LengthBox& offset) { m_noninherited.offset = offset; }
void set_margin(const CSS::LengthBox& margin) { m_noninherited.margin = margin; }
void set_padding(const CSS::LengthBox& padding) { m_noninherited.padding = padding; }
void set_overflow_x(CSS::Overflow value) { m_noninherited.overflow_x = value; }
void set_overflow_y(CSS::Overflow value) { m_noninherited.overflow_y = value; }
void set_list_style_type(CSS::ListStyleType value) { m_inherited.list_style_type = value; }
void set_display(CSS::Display value) { m_noninherited.display = value; }
BorderData& border_left() { return m_noninherited.border_left; }

View file

@ -56,6 +56,7 @@
"-libweb-palette-window",
"-libweb-palette-window-text",
"absolute",
"auto",
"blink",
"block",
"bold",
@ -64,6 +65,7 @@
"capitalize",
"center",
"circle",
"clip",
"column",
"column-reverse",
"dashed",
@ -102,6 +104,7 @@
"right",
"row",
"row-reverse",
"scroll",
"small",
"smaller",
"solid",
@ -119,6 +122,7 @@
"table-row-group",
"underline",
"uppercase",
"visible",
"x-large",
"x-small",
"xx-large",

View file

@ -271,6 +271,22 @@
"inherited": false,
"initial": "0"
},
"overflow": {
"longhands": [
"overflow-x",
"overflow-y"
],
"inherited": false,
"initial": "visible"
},
"overflow-x": {
"inherited": false,
"initial": "visible"
},
"overflow-y": {
"inherited": false,
"initial": "visible"
},
"padding": {
"longhands": [
"padding-top",

View file

@ -497,4 +497,36 @@ Optional<CSS::ListStyleType> StyleProperties::list_style_type() const
}
}
Optional<CSS::Overflow> StyleProperties::overflow_x() const
{
return overflow(CSS::PropertyID::OverflowX);
}
Optional<CSS::Overflow> StyleProperties::overflow_y() const
{
return overflow(CSS::PropertyID::OverflowY);
}
Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) const
{
auto value = property(property_id);
if (!value.has_value())
return {};
switch (value.value()->to_identifier()) {
case CSS::ValueID::Auto:
return CSS::Overflow::Auto;
case CSS::ValueID::Visible:
return CSS::Overflow::Visible;
case CSS::ValueID::Hidden:
return CSS::Overflow::Hidden;
case CSS::ValueID::Clip:
return CSS::Overflow::Clip;
case CSS::ValueID::Scroll:
return CSS::Overflow::Scroll;
default:
return {};
}
}
}

View file

@ -70,6 +70,8 @@ public:
Optional<CSS::TextTransform> text_transform() const;
Optional<CSS::ListStyleType> list_style_type() const;
Optional<CSS::FlexDirection> flex_direction() const;
Optional<CSS::Overflow> overflow_x() const;
Optional<CSS::Overflow> overflow_y() const;
const Gfx::Font& font() const
{
@ -88,6 +90,7 @@ public:
private:
HashMap<unsigned, NonnullRefPtr<StyleValue>> m_property_values;
Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
void load_font() const;

View file

@ -243,6 +243,12 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
return;
}
if (property_id == CSS::PropertyID::Overflow) {
style.set_property(CSS::PropertyID::OverflowX, value);
style.set_property(CSS::PropertyID::OverflowY, value);
return;
}
if (property_id == CSS::PropertyID::Border) {
set_property_expanding_shorthands(style, CSS::PropertyID::BorderTop, value, document);
set_property_expanding_shorthands(style, CSS::PropertyID::BorderRight, value, document);

View file

@ -142,6 +142,14 @@ enum class ListStyleType {
Decimal,
};
enum class Overflow : u8 {
Auto,
Clip,
Hidden,
Scroll,
Visible,
};
class StyleValue : public RefCounted<StyleValue> {
public:
virtual ~StyleValue();

View file

@ -260,6 +260,14 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
if (clear.has_value())
computed_values.set_clear(clear.value());
auto overflow_x = specified_style.overflow_x();
if (overflow_x.has_value())
computed_values.set_overflow_x(overflow_x.value());
auto overflow_y = specified_style.overflow_y();
if (overflow_y.has_value())
computed_values.set_overflow_y(overflow_y.value());
auto text_decoration_line = specified_style.text_decoration_line();
if (text_decoration_line.has_value())
computed_values.set_text_decoration_line(text_decoration_line.value());