Truly independent web browser
LibWeb: Stretch absolutely positioned form controls between insets
sideshowbarkerae36a2c81f26
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 5b878812889..2b6b4927d03 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -1912,6 +1912,15 @@ impl AbsposEngine<'_> {!equation.has_both_insets() || self.own_self_alignment_keyword(sized, inline_axis).is_some()}+ // 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.+ 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()+ && axis.select(style.width(), style.height()).is_auto()+ && !self.sizes_to_fit_content(sized, equation, matches!(axis, SizingAxis::Inline))+ }+fn shrink_to_fit_available_size(inputs: &abspos_inputs::AbsposLayoutInputs,axis: SizingAxis,@@ -2049,7 +2058,10 @@ impl AbsposEngine<'_> {auto_margin_overflow,);let sizing = self.sizing();- let inline_size = if sizing.box_is_sized_as_replaced_element(sized.sized_box(), available_space, constraints) {+ let uses_replaced_size =+ sizing.box_is_sized_as_replaced_element(sized.sized_box(), available_space, constraints)+ && !self.form_control_stretches(sized, equation, SizingAxis::Inline);+ let inline_size = if uses_replaced_size {// NB: A stretch inline size fills the inset-modified containing block, which replaced element sizing does// not know about.let width = self.style_of(sized).width();@@ -2266,7 +2278,7 @@ impl AbsposEngine<'_> {let containing_block_block_size = available_space.block_size.to_px_or_zero();// NB: The margins of a non-replaced box resolve against the inline size of its containing block, and those of a// replaced box against its block size.- let margin_basis = if is_replaced {+ let margin_basis = if is_replaced && !self.facts(sized.node).is_native_form_control_box() {containing_block_block_size} else {available_space.inline_size.to_px_or_zero()@@ -2279,6 +2291,7 @@ impl AbsposEngine<'_> {margin_basis,auto_margin_overflow,);+ let is_replaced = is_replaced && !self.form_control_stretches(sized, equation, SizingAxis::Block);let resolved_block_size = if is_replaced {Ok(self.replaced_block_size(sized, inputs, available_space, constraints, pass))} else {diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input-ref.htmlnew file mode 100644index 00000000000..554173c6323--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input-ref.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<style>+.cb {+ position: relative;+ border: 3px solid black;+ height: 100px;+ width: 150px;+ display: inline-block;+ vertical-align: top;+ margin: 5px;+}+.wide {+ width: 350px;+}+.abs {+ margin: 0;+ position: absolute;+ box-sizing: border-box;+ top: 3px;+ left: 3px;+ outline: 2px solid lime;+ width: calc(100% - 6px);+ height: calc(100% - 6px);+}+</style>+<div class="cb"><input type="button" class="abs" value="input-btn"></div>+<div class="cb"><input type="submit" class="abs"></div>+<div class="cb"><input type="reset" class="abs"></div>+<div class="cb"><input type="color" class="abs"></div>+<div class="cb wide"><input type="text" class="abs" value="text"></div>+<div class="cb wide"><input type="password" class="abs" value="pass"></div>+<div class="cb wide"><input type="date" class="abs" value="text"></div>+<div class="cb wide"><input type="file" class="abs"></div>+<div class="cb wide"><input type="range" class="abs"></div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other-ref.htmlnew file mode 100644index 00000000000..e334bc0f63d--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other-ref.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<style>+.cb {+ position: relative;+ border: 3px solid black;+ height: 100px;+ width: 150px;+ display: inline-block;+ vertical-align: top;+ margin: 5px;+}+.wide {+ width: 350px;+}+.abs {+ margin: 0;+ position: absolute;+ box-sizing: border-box;+ top: 3px;+ left: 3px;+ outline: 2px solid lime;+ width: calc(100% - 6px);+ height: calc(100% - 6px);+}+</style>+<div class="cb"><select class="abs"><option>select</option></select></div>+<div class="cb"><output class="abs">output</output></div>+<div class="cb"><label class="abs">label</output></div>+<div class="cb"><fieldset class="abs">fieldset</fieldset></div>+<div class="cb wide"><textarea class="abs">textarea</textarea></div>+<div class="cb wide"><progress value="0.4" class="abs"></div>+<div class="cb wide"><meter value="0.4" class="abs"></div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input.htmlnew file mode 100644index 00000000000..9b55d1ec1f8--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input.html@@ -0,0 +1,42 @@+<!DOCTYPE html>+<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6789">+<link rel="match" href="../../../../expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-input-ref.html">+<title>Semi-replaced elements should stretch with an auto main size, and explicit insets in that direction.</title>+<style>+.cb {+ position: relative;+ border: 3px solid black;+ height: 100px;+ width: 150px;+ display: inline-block;+ vertical-align: top;+ margin: 5px;+}+.wide {+ /* Some of the form controls are wider than others+ and need a wider CB in order to see if they're+ stretching or shrinking. */+ width: 350px;+}+.abs {+ margin: 0;+ position: absolute;+ box-sizing: border-box;+ top: 3px;+ right: 3px;+ bottom: 3px;+ left: 3px;+ outline: 2px solid lime;+ width: auto;+ height: auto;+}+</style>+<div class="cb"><input type="button" class="abs" value="input-btn"></div>+<div class="cb"><input type="submit" class="abs"></div>+<div class="cb"><input type="reset" class="abs"></div>+<div class="cb"><input type="color" class="abs"></div>+<div class="cb wide"><input type="text" class="abs" value="text"></div>+<div class="cb wide"><input type="password" class="abs" value="pass"></div>+<div class="cb wide"><input type="date" class="abs" value="text"></div>+<div class="cb wide"><input type="file" class="abs"></div>+<div class="cb wide"><input type="range" class="abs"></div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other.htmlnew file mode 100644index 00000000000..8fc21fd0204--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6789">+<link rel="match" href="../../../../expected/wpt-import/css/css-position/position-absolute-semi-replaced-stretch-other-ref.html">+<title>Semi-replaced elements should stretch with an auto main size, and explicit insets in that direction.</title>+<style>+.cb {+ position: relative;+ border: 3px solid black;+ height: 100px;+ width: 150px;+ display: inline-block;+ vertical-align: top;+ margin: 5px;+}+.wide {+ /* Some of the form controls are wider than others+ and need a wider CB in order to see if they're+ stretching or shrinking. */+ width: 350px;+}+.abs {+ margin: 0;+ position: absolute;+ box-sizing: border-box;+ top: 3px;+ right: 3px;+ bottom: 3px;+ left: 3px;+ outline: 2px solid lime;+ width: auto;+ height: auto;+}+</style>+<div class="cb"><select class="abs"><option>select</option></select></div>+<div class="cb"><output class="abs">output</output></div>+<div class="cb"><label class="abs">label</output></div>+<div class="cb"><fieldset class="abs">fieldset</fieldset></div>+<div class="cb wide"><textarea class="abs">textarea</textarea></div>+<div class="cb wide"><progress value="0.4" class="abs"></div>+<div class="cb wide"><meter value="0.4" class="abs"></div>diff --git a/Tests/LibWeb/Text/expected/abspos-form-control-stretch.txt b/Tests/LibWeb/Text/expected/abspos-form-control-stretch.txtnew file mode 100644index 00000000000..ad939cf28ca--- /dev/null+++ b/Tests/LibWeb/Text/expected/abspos-form-control-stretch.txt@@ -0,0 +1,32 @@+input horizontal-tb ltr: 10,5 270x180+input horizontal-tb rtl: 10,5 270x180+input vertical-rl ltr: 10,5 270x180+input vertical-rl rtl: 10,5 270x180+input vertical-lr ltr: 10,5 270x180+input vertical-lr rtl: 10,5 270x180+input orthogonal: 10,5 270x180+input margins: 20,15 250x160+input percentage margins: 40,35 210x120+input limits: 10,5 220x210+input specified size: 10,5 100x80+input content box: 10,5 270x180+input self-start keeps intrinsic size: true+input one inset keeps intrinsic size: true+input resized: 10,5 170x180+textarea horizontal-tb ltr: 10,5 270x180+textarea horizontal-tb rtl: 10,5 270x180+textarea vertical-rl ltr: 10,5 270x180+textarea vertical-rl rtl: 10,5 270x180+textarea vertical-lr ltr: 10,5 270x180+textarea vertical-lr rtl: 10,5 270x180+textarea orthogonal: 10,5 270x180+textarea margins: 20,15 250x160+textarea percentage margins: 40,35 210x120+textarea limits: 10,5 220x210+textarea specified size: 10,5 100x80+textarea content box: 10,5 270x180+textarea self-start keeps intrinsic size: true+textarea one inset keeps intrinsic size: true+textarea resized: 10,5 170x180+img image keeps natural size: 10,5 80x40+input image keeps natural size: 10,5 80x40diff --git a/Tests/LibWeb/Text/input/abspos-form-control-stretch.html b/Tests/LibWeb/Text/input/abspos-form-control-stretch.htmlnew file mode 100644index 00000000000..8ff664f7476--- /dev/null+++ b/Tests/LibWeb/Text/input/abspos-form-control-stretch.html@@ -0,0 +1,84 @@+<!doctype html>+<script src="include.js"></script>+<style>+ body {+ margin: 0;+ }+ .container {+ position: relative;+ width: 300px;+ height: 200px;+ }+ .control {+ font: 32px monospace;+ margin: 0;+ padding: 7px;+ border: 3px solid;+ box-sizing: border-box;+ }+ .absolute {+ position: absolute;+ inset: 5px 20px 15px 10px;+ width: auto;+ height: auto;+ }+</style>+<script>+ promiseTest(async () => {+ function add(tag, style = "", containerStyle = "") {+ const container = document.createElement("div");+ container.className = "container";+ container.style.cssText = containerStyle;+ const control = document.createElement(tag);+ control.className = "control absolute";+ control.style.cssText = style;+ container.append(control);+ document.body.append(container);+ return [container, control];+ }+ function report(name, container, control) {+ const outer = container.getBoundingClientRect();+ const rect = control.getBoundingClientRect();+ println(`${name}: ${rect.x - outer.x},${rect.y - outer.y} ${rect.width}x${rect.height}`);+ }+ for (const tag of ["input", "textarea"]) {+ for (const mode of ["horizontal-tb", "vertical-rl", "vertical-lr"]) {+ for (const direction of ["ltr", "rtl"]) {+ report(+ `${tag} ${mode} ${direction}`,+ ...add(tag, "", `writing-mode: ${mode}; direction: ${direction}`)+ );+ }+ }+ report(`${tag} orthogonal`, ...add(tag, "writing-mode: vertical-rl"));+ report(`${tag} margins`, ...add(tag, "margin: 10px"));+ report(`${tag} percentage margins`, ...add(tag, "margin: 10%"));+ report(`${tag} limits`, ...add(tag, "max-width: 220px; min-height: 210px"));+ report(`${tag} specified size`, ...add(tag, "width: 100px; height: 80px"));+ report(`${tag} content box`, ...add(tag, "box-sizing: content-box"));+ const [, natural] = add(tag);+ natural.classList.remove("absolute");+ const [, aligned] = add(tag, "justify-self: start; align-self: start");+ const [, oneInset] = add(tag, "right: auto; bottom: auto");+ println(+ `${tag} self-start keeps intrinsic size: ${aligned.offsetWidth === natural.offsetWidth && aligned.offsetHeight === natural.offsetHeight}`+ );+ println(+ `${tag} one inset keeps intrinsic size: ${oneInset.offsetWidth === natural.offsetWidth && oneInset.offsetHeight === natural.offsetHeight}`+ );+ const [container, control] = add(tag);+ container.style.width = "200px";+ report(`${tag} resized`, container, control);+ }+ const source = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="40"></svg>';+ for (const tag of ["img", "input"]) {+ const [container, control] = add(tag, "border: 0; padding: 0");+ if (tag === "input") control.type = "image";+ await new Promise(resolve => {+ control.onload = resolve;+ control.src = source;+ });+ report(`${tag} image keeps natural size`, container, control);+ }+ });+</script>