diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 40eb62c52e..63dc4bfa0a 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -31,6 +31,7 @@ public: static Color color() { return Color::Black; } static Color background_color() { return Color::Transparent; } static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; } + static CSS::Visibility visibility() { return CSS::Visibility::Visible; } static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; } static CSS::FlexWrap flex_wrap() { return CSS::FlexWrap::Nowrap; } static CSS::ImageRendering image_rendering() { return CSS::ImageRendering::Auto; } @@ -127,6 +128,7 @@ public: float flex_shrink() const { return m_noninherited.flex_shrink; } CSS::AlignItems align_items() const { return m_noninherited.align_items; } float opacity() const { return m_noninherited.opacity; } + CSS::Visibility visibility() const { return m_inherited.visibility; } CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; } CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; } Vector const& box_shadow() const { return m_noninherited.box_shadow; } @@ -191,6 +193,7 @@ protected: CSS::TextTransform text_transform { InitialValues::text_transform() }; CSS::WhiteSpace white_space { InitialValues::white_space() }; CSS::ListStyleType list_style_type { InitialValues::list_style_type() }; + CSS::Visibility visibility { InitialValues::visibility() }; Optional fill; Optional stroke; @@ -303,6 +306,7 @@ public: void set_transformations(Vector value) { m_noninherited.transformations = move(value); } void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; } void set_vertical_align(Variant value) { m_noninherited.vertical_align = value; } + void set_visibility(CSS::Visibility value) { m_inherited.visibility = value; } void set_fill(Color value) { m_inherited.fill = value; } void set_stroke(Color value) { m_inherited.stroke = value; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 3ed1a06945..aaf84c44a6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -698,6 +698,23 @@ Optional StyleProperties::cursor() const } } +Optional StyleProperties::visibility() const +{ + auto value = property(CSS::PropertyID::Visibility); + if (!value.has_value() || !value.value()->is_identifier()) + return {}; + switch (value.value()->to_identifier()) { + case CSS::ValueID::Visible: + return CSS::Visibility::Visible; + case CSS::ValueID::Hidden: + return CSS::Visibility::Hidden; + case CSS::ValueID::Collapse: + return CSS::Visibility::Collapse; + default: + return {}; + } +} + CSS::Display StyleProperties::display() const { auto value = property(CSS::PropertyID::Display); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 1d5febe700..f964873500 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -66,6 +66,7 @@ public: float flex_shrink() const; Optional align_items() const; float opacity() const; + Optional visibility() const; Optional image_rendering() const; Optional justify_content() const; Optional overflow_x() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index fb5267db7b..8d86abb4c6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -315,6 +315,12 @@ enum class VerticalAlign { Top, }; +enum class Visibility { + Visible, + Hidden, + Collapse, +}; + enum class WhiteSpace { Normal, Pre, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 854241eb2d..49701d0e3c 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -465,7 +465,11 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) computed_values.set_z_index(specified_style.z_index()); computed_values.set_opacity(specified_style.opacity()); - if (computed_values.opacity() == 0) + + if (auto maybe_visibility = specified_style.visibility(); maybe_visibility.has_value()) + computed_values.set_visibility(maybe_visibility.release_value()); + + if (computed_values.opacity() == 0 || computed_values.visibility() != CSS::Visibility::Visible) m_visible = false; if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::Width); maybe_length_percentage.has_value())