diff --git a/Tests/LibWeb/Ref/overflow-hidden-7.html b/Tests/LibWeb/Ref/overflow-hidden-7.html
new file mode 100644
index 0000000000..9a8e0e2148
--- /dev/null
+++ b/Tests/LibWeb/Ref/overflow-hidden-7.html
@@ -0,0 +1,19 @@
+
+
+
+
diff --git a/Tests/LibWeb/Ref/reference/overflow-hidden-7-ref.html b/Tests/LibWeb/Ref/reference/overflow-hidden-7-ref.html
new file mode 100644
index 0000000000..8832d4b857
--- /dev/null
+++ b/Tests/LibWeb/Ref/reference/overflow-hidden-7-ref.html
@@ -0,0 +1,9 @@
+
+
+
diff --git a/Tests/LibWeb/Text/expected/resolve-css-overflow-effective-value.txt b/Tests/LibWeb/Text/expected/resolve-css-overflow-effective-value.txt
new file mode 100644
index 0000000000..14e51c1c13
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/resolve-css-overflow-effective-value.txt
@@ -0,0 +1,2 @@
+ overflow-x: auto
+overflow-y: hidden
diff --git a/Tests/LibWeb/Text/input/resolve-css-overflow-effective-value.html b/Tests/LibWeb/Text/input/resolve-css-overflow-effective-value.html
new file mode 100644
index 0000000000..5b9bac33b3
--- /dev/null
+++ b/Tests/LibWeb/Text/input/resolve-css-overflow-effective-value.html
@@ -0,0 +1,19 @@
+
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 96d5af4aab..6d5c2637a8 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -1959,6 +1959,27 @@ void StyleComputer::absolutize_values(StyleProperties& style) const
style.set_line_height({}, line_height);
}
+void StyleComputer::resolve_effective_overflow_values(StyleProperties& style) const
+{
+ // https://www.w3.org/TR/css-overflow-3/#overflow-control
+ // The visible/clip values of overflow compute to auto/hidden (respectively) if one of overflow-x or
+ // overflow-y is neither visible nor clip.
+ auto overflow_x = value_id_to_overflow(style.property(PropertyID::OverflowX)->to_identifier());
+ auto overflow_y = value_id_to_overflow(style.property(PropertyID::OverflowY)->to_identifier());
+ auto overflow_x_is_visible_or_clip = overflow_x == Overflow::Visible || overflow_x == Overflow::Clip;
+ auto overflow_y_is_visible_or_clip = overflow_y == Overflow::Visible || overflow_y == Overflow::Clip;
+ if (!overflow_x_is_visible_or_clip || !overflow_y_is_visible_or_clip) {
+ if (overflow_x == CSS::Overflow::Visible)
+ style.set_property(CSS::PropertyID::OverflowX, IdentifierStyleValue::create(CSS::ValueID::Auto), nullptr);
+ if (overflow_x == CSS::Overflow::Clip)
+ style.set_property(CSS::PropertyID::OverflowX, IdentifierStyleValue::create(CSS::ValueID::Hidden), nullptr);
+ if (overflow_y == CSS::Overflow::Visible)
+ style.set_property(CSS::PropertyID::OverflowY, IdentifierStyleValue::create(CSS::ValueID::Auto), nullptr);
+ if (overflow_y == CSS::Overflow::Clip)
+ style.set_property(CSS::PropertyID::OverflowY, IdentifierStyleValue::create(CSS::ValueID::Hidden), nullptr);
+ }
+}
+
enum class BoxTypeTransformation {
None,
Blockify,
@@ -2139,6 +2160,9 @@ ErrorOr> StyleComputer::compute_style_impl(DOM::Element&
// 6. Run automatic box type transformations
transform_box_type_if_needed(style, element, pseudo_element);
+ // 7. Resolve effective overflow values
+ resolve_effective_overflow_values(style);
+
return style;
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
index c2760b17df..9c5a92157f 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
@@ -129,6 +129,7 @@ private:
void compute_math_depth(StyleProperties&, DOM::Element const*, Optional) const;
void compute_defaulted_values(StyleProperties&, DOM::Element const*, Optional) const;
void absolutize_values(StyleProperties&) const;
+ void resolve_effective_overflow_values(StyleProperties&) const;
void transform_box_type_if_needed(StyleProperties&, DOM::Element const&, Optional) const;
void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID, Optional) const;