Skip to content

Truly independent web browser

LibWeb: Stop overflow propagation from a body with container-type

sideshowbarkerae6f81c08113
diff --git a/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs b/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs
index 0f851fb0213..1ed47f3b183 100644
--- a/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs
+++ b/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs
@@ -51,11 +51,19 @@ fn published_style(engine: &RetainedState, node: StyleNodeID) -> Option<Computed
fn has_any_containment(style: ComputedValuesView<'_>) -> bool {
let values = style.box_values();
+ // https://drafts.csswg.org/css-conditional-5/#valdef-container-type-size
+ // Applies style containment and size containment to the principal box, and establishes an independent formatting
+ // context.
+ // https://drafts.csswg.org/css-conditional-5/#valdef-container-type-inline-size
+ // Applies style containment and inline-size containment to the principal box, and establishes an independent
+ // formatting context.
values.size_containment
|| values.inline_size_containment
|| values.layout_containment
|| values.style_containment
|| values.paint_containment
+ || values.is_size_container
+ || values.is_inline_size_container
}
/// The document element, which is the first DOM child of the style node the viewport box was
diff --git a/Tests/LibWeb/Text/expected/css/container-type-on-body-stops-overflow-propagation.txt b/Tests/LibWeb/Text/expected/css/container-type-on-body-stops-overflow-propagation.txt
new file mode 100644
index 00000000000..8ea0ab97720
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/container-type-on-body-stops-overflow-propagation.txt
@@ -0,0 +1,4 @@
+body container-type: inline-size: viewport overflow auto, scrolled by wheel: true
+body container-type: normal: viewport overflow hidden, scrolled by wheel: false
+body container-type: size: viewport overflow auto, scrolled by wheel: true
+html container-type: inline-size: viewport overflow auto, scrolled by wheel: true
diff --git a/Tests/LibWeb/Text/input/css/container-type-on-body-stops-overflow-propagation.html b/Tests/LibWeb/Text/input/css/container-type-on-body-stops-overflow-propagation.html
new file mode 100644
index 00000000000..6e3022ecf3a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/container-type-on-body-stops-overflow-propagation.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<style>
+ body {
+ margin: 0;
+ overflow: hidden;
+ container-type: inline-size;
+ }
+ .tall {
+ height: 3000px;
+ }
+</style>
+<div class="tall"></div>
+<script src="../include.js"></script>
+<script>
+ async function report(label) {
+ window.scrollTo(0, 0);
+ await animationFrame();
+ await animationFrame();
+ await internals.wheel(10, 10, 0, 100);
+ println(`${label}: viewport overflow ${internals.viewportOverflowX()}, scrolled by wheel: ${window.scrollY > 0}`);
+ }
+
+ promiseTest(async () => {
+ await report("body container-type: inline-size");
+
+ document.body.style.containerType = "normal";
+ await report("body container-type: normal");
+
+ document.body.style.cssText = "container-type: size; height: 3000px";
+ await report("body container-type: size");
+
+ document.body.style.cssText = "container-type: normal";
+ document.documentElement.style.containerType = "inline-size";
+ await report("html container-type: inline-size");
+ });
+</script>