Skip to content

Truly independent web browser

LibWeb: Stretch abspos checkboxes and radios between insets

sideshowbarkerd844fe51d2ce
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 5c3cd3698a7..2e9791bf62b 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -1924,10 +1924,12 @@ impl AbsposEngine<'_> {
}
// https://drafts.csswg.org/css-position-3/#abspos-auto-size
- // Resizable form controls use non-replaced sizing here, so their intrinsic dimensions don't prevent stretching.
+ // Form controls use non-replaced sizing here, so their intrinsic dimensions don't prevent stretching. That covers
+ // checkboxes and radio buttons too, which pages lay over a styled box between zero insets to make it clickable.
fn form_control_stretches(&self, sized: OutOfFlowBox<'_>, equation: AxisEquation, axis: SizingAxis) -> bool {
let style = self.style_of(sized);
- self.facts(sized.node).is_native_form_control_box()
+ let facts = self.facts(sized.node);
+ (facts.is_native_form_control_box() || facts.is_non_devolvable_widget())
&& axis.select(style.width(), style.height()).is_auto()
&& !self.sizes_to_fit_content(sized, equation, matches!(axis, SizingAxis::Inline))
}
diff --git a/Tests/LibWeb/Text/expected/abspos-checkbox-radio-stretch.txt b/Tests/LibWeb/Text/expected/abspos-checkbox-radio-stretch.txt
new file mode 100644
index 00000000000..e5a12c123d1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/abspos-checkbox-radio-stretch.txt
@@ -0,0 +1,13 @@
+checkbox inset: 0: 0,0 300x50
+radio inset: 0: 0,0 300x50
+checkbox left: 0; right: 0; top: 0: 0,0 300x13
+radio top: 0; bottom: 0; left: 0: 0,0 12x50
+checkbox inset: 0; justify-self: start: 0,0 13x50
+checkbox inset: 0; align-self: center: 0,18.5 300x13
+checkbox inset: 0; padding: 5px; border: 3px solid: 0,0 300x50
+checkbox inset: 0; max-width: 100px: 0,0 100x50
+checkbox inset: 0; margin: 10px: 10,10 280x30
+checkbox inset: 10px; height: 20px: 10,10 280x20
+checkbox inset: 0; writing-mode: vertical-lr: 0,0 300x50
+checkbox inset: 0; aspect-ratio: 1: 0,0 300x300
+radio inset: 0; appearance: none: 0,0 300x50
diff --git a/Tests/LibWeb/Text/input/abspos-checkbox-radio-stretch.html b/Tests/LibWeb/Text/input/abspos-checkbox-radio-stretch.html
new file mode 100644
index 00000000000..9d005f23989
--- /dev/null
+++ b/Tests/LibWeb/Text/input/abspos-checkbox-radio-stretch.html
@@ -0,0 +1,45 @@
+<!doctype html>
+<script src="include.js"></script>
+<style>
+ .container {
+ position: relative;
+ width: 300px;
+ height: 50px;
+ }
+ .container > input {
+ position: absolute;
+ margin: 0;
+ }
+</style>
+<script>
+ test(() => {
+ const cases = [
+ ["checkbox", "inset: 0"],
+ ["radio", "inset: 0"],
+ ["checkbox", "left: 0; right: 0; top: 0"],
+ ["radio", "top: 0; bottom: 0; left: 0"],
+ ["checkbox", "inset: 0; justify-self: start"],
+ ["checkbox", "inset: 0; align-self: center"],
+ ["checkbox", "inset: 0; padding: 5px; border: 3px solid"],
+ ["checkbox", "inset: 0; max-width: 100px"],
+ ["checkbox", "inset: 0; margin: 10px"],
+ ["checkbox", "inset: 10px; height: 20px"],
+ ["checkbox", "inset: 0; writing-mode: vertical-lr"],
+ ["checkbox", "inset: 0; aspect-ratio: 1"],
+ ["radio", "inset: 0; appearance: none"],
+ ];
+ for (const [type, style] of cases) {
+ const container = document.createElement("div");
+ container.className = "container";
+ const input = document.createElement("input");
+ input.type = type;
+ input.style.cssText = style;
+ container.append(input);
+ document.body.append(container);
+ const outer = container.getBoundingClientRect();
+ const rect = input.getBoundingClientRect();
+ println(`${type} ${style}: ${rect.x - outer.x},${rect.y - outer.y} ${rect.width}x${rect.height}`);
+ container.remove();
+ }
+ });
+</script>