1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

LibWeb: Parse the CSS "flex-direction" property

This commit is contained in:
Andreas Kling 2021-01-18 17:41:57 +01:00
parent fd7920fa8f
commit 149f10b0b9
7 changed files with 43 additions and 0 deletions

View file

@ -45,6 +45,7 @@ public:
static Color color() { return Color::Black; } static Color color() { return Color::Black; }
static Color background_color() { return Color::Transparent; } static Color background_color() { return Color::Transparent; }
static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; } static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; }
static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; }
}; };
struct BorderData { struct BorderData {
@ -65,6 +66,7 @@ public:
CSS::TextTransform text_transform() const { return m_inherited.text_transform; } CSS::TextTransform text_transform() const { return m_inherited.text_transform; }
CSS::Position position() const { return m_noninherited.position; } CSS::Position position() const { return m_noninherited.position; }
CSS::WhiteSpace white_space() const { return m_inherited.white_space; } CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
const CSS::Length& width() const { return m_noninherited.width; } const CSS::Length& width() const { return m_noninherited.width; }
const CSS::Length& min_width() const { return m_noninherited.min_width; } const CSS::Length& min_width() const { return m_noninherited.min_width; }
const CSS::Length& max_width() const { return m_noninherited.max_width; } const CSS::Length& max_width() const { return m_noninherited.max_width; }
@ -123,6 +125,7 @@ protected:
BorderData border_right; BorderData border_right;
BorderData border_bottom; BorderData border_bottom;
Color background_color { InitialValues::background_color() }; Color background_color { InitialValues::background_color() };
CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
} m_noninherited; } m_noninherited;
}; };
@ -156,6 +159,7 @@ public:
BorderData& border_top() { return m_noninherited.border_top; } BorderData& border_top() { return m_noninherited.border_top; }
BorderData& border_right() { return m_noninherited.border_right; } BorderData& border_right() { return m_noninherited.border_right; }
BorderData& border_bottom() { return m_noninherited.border_bottom; } BorderData& border_bottom() { return m_noninherited.border_bottom; }
void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; }
}; };
} }

View file

@ -64,6 +64,8 @@
"capitalize", "capitalize",
"center", "center",
"circle", "circle",
"column",
"column-reverse",
"dashed", "dashed",
"decimal", "decimal",
"disc", "disc",
@ -98,6 +100,8 @@
"relative", "relative",
"ridge", "ridge",
"right", "right",
"row",
"row-reverse",
"small", "small",
"smaller", "smaller",
"solid", "solid",

View file

@ -168,6 +168,10 @@
"inherited": false, "inherited": false,
"initial": "inline" "initial": "inline"
}, },
"flex-direction": {
"inherited": false,
"initial": "row"
},
"float": { "float": {
"inherited": false, "inherited": false,
"initial": "none" "initial": "none"

View file

@ -225,6 +225,25 @@ Optional<int> StyleProperties::z_index() const
return static_cast<int>(value.value()->to_length().raw_value()); return static_cast<int>(value.value()->to_length().raw_value());
} }
Optional<CSS::FlexDirection> StyleProperties::flex_direction() const
{
auto value = property(CSS::PropertyID::FlexDirection);
if (!value.has_value())
return {};
switch (value.value()->to_identifier()) {
case CSS::ValueID::Row:
return CSS::FlexDirection::Row;
case CSS::ValueID::RowReverse:
return CSS::FlexDirection::RowReverse;
case CSS::ValueID::Column:
return CSS::FlexDirection::Column;
case CSS::ValueID::ColumnReverse:
return CSS::FlexDirection::ColumnReverse;
default:
return {};
}
}
Optional<CSS::Position> StyleProperties::position() const Optional<CSS::Position> StyleProperties::position() const
{ {
auto value = property(CSS::PropertyID::Position); auto value = property(CSS::PropertyID::Position);

View file

@ -69,6 +69,7 @@ public:
Optional<CSS::TextDecorationLine> text_decoration_line() const; Optional<CSS::TextDecorationLine> text_decoration_line() const;
Optional<CSS::TextTransform> text_transform() const; Optional<CSS::TextTransform> text_transform() const;
Optional<CSS::ListStyleType> list_style_type() const; Optional<CSS::ListStyleType> list_style_type() const;
Optional<CSS::FlexDirection> flex_direction() const;
const Gfx::Font& font() const const Gfx::Font& font() const
{ {

View file

@ -93,6 +93,13 @@ enum class Display {
Flex, Flex,
}; };
enum class FlexDirection {
Row,
RowReverse,
Column,
ColumnReverse,
};
enum class WhiteSpace { enum class WhiteSpace {
Normal, Normal,
Pre, Pre,

View file

@ -239,6 +239,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
computed_values.set_display(specified_style.display()); computed_values.set_display(specified_style.display());
auto flex_direction = specified_style.flex_direction();
if (flex_direction.has_value())
computed_values.set_flex_direction(flex_direction.value());
auto position = specified_style.position(); auto position = specified_style.position();
if (position.has_value()) if (position.has_value())
computed_values.set_position(position.value()); computed_values.set_position(position.value());