Truly independent web browser
LibWeb: Size inputs with a table display by their used display
sideshowbarkerba50ebd4b329
diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rsindex a8e2e39cc86..fd08afcb088 100644--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs@@ -646,6 +646,13 @@ pub(crate) fn construction_fact_word(facts: &super::node_data::NodeConstructionF.fold(0, |word, (bit, _)| word | bit)}+/// Whether an element with the published construction facts `construction_facts` is a replaced element, whatever kind+/// of box it gets.+pub(crate) fn construction_facts_name_replaced_element(construction_facts: u32) -> bool {+ use crate::css::style::bridge::element_construction_fact as fact;+ construction_facts & (fact::IS_HTML_INPUT_ELEMENT | fact::IS_HTML_PROGRESS_OR_METER_ELEMENT) != 0+}+/// The flags a row of `kind` is built with, from its node's published construction facts.pub(crate) fn construction_flags(kind: NodeKind, is_anonymous: bool, construction_facts: u32) -> u32 {use crate::css::style::bridge::element_construction_fact as fact;@@ -656,7 +663,7 @@ pub(crate) fn construction_flags(kind: NodeKind, is_anonymous: bool, constructio// NB: A progress or meter element lays out its internal shadow tree on its own, as other engines do, so no margin// inside it collapses with the content around it.let is_replaced_element =- kind_is_replaced_box(kind) || has(fact::IS_HTML_INPUT_ELEMENT) || has(fact::IS_HTML_PROGRESS_OR_METER_ELEMENT);+ kind_is_replaced_box(kind) || construction_facts_name_replaced_element(construction_facts);[(NodeFlag::Anonymous, is_anonymous),(NodeFlag::HasStyle, has_style),@@ -1319,14 +1326,6 @@ impl<'pass> NodeFacts<'pass> {node_can_have_children(self.data())}- pub(crate) fn has_replaced_element_table_display_adjustment(&self) -> bool {- has_flag(self.data(), NodeFlag::IsReplacedElement)- && self.computed_values_view_if_styled().is_some_and(|style| {- let display = style.display_before_box_type_transformation();- display.is_table_inside() || display.is_internal_table() || display.is_table_caption()- })- }-pub(crate) fn creates_block_formatting_context(&self) -> bool {node_creates_block_formatting_context(self.data(),diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 49c8ccf7920..81d5db9e8a1 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1233,9 +1233,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {// replaced element with a natural aspect ratio and no natural size in that axis, see e.g. CSS2 §10// and CSS Flexible Box Model Level 1 §9.2.// https://drafts.csswg.org/css-sizing-4/#aspect-ratio-automatic- if facts.has_replaced_element_table_display_adjustment()- || (facts.is_replaced_box() && facts.has_auto_content_box_size())- {+ if facts.is_replaced_box() && facts.has_auto_content_box_size() {return true;}if facts.has_preferred_aspect_ratio() || facts.has_auto_content_box_size() {diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 8bc03375180..90ec93e1ab6 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -108,6 +108,13 @@ pub(crate) fn used_display_of_box(kind: NodeKind, flags: u32, display: FfiDisplaif flags & NodeFlag::IsReplacedElement as u32 == 0 {return display;}+ used_display_of_replaced_element(display)+}++/// The display a replaced element's box uses for `display`, its computed display.+pub(crate) fn used_display_of_replaced_element(display: FfiDisplay) -> FfiDisplay {+ use crate::css::css_enums::{display_inside, display_outside};+ let flow = |outside| FfiDisplay::outside_and_inside(outside, display_inside::FLOW, false);// https://drafts.csswg.org/css-display-3/#outer-role// Note: Outer display types do affect replaced elements.if display.is_table_inside() {diff --git a/Libraries/LibWeb/Rust/src/layout/tree_plan/planner.rs b/Libraries/LibWeb/Rust/src/layout/tree_plan/planner.rsindex 80a39fb5220..fbc3ea1a3a7 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_plan/planner.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_plan/planner.rs@@ -4154,17 +4154,27 @@ fn prepare_element(layout_svg_pattern,);prepared_style.layout_kind = layout_kind;+ // NB: A replaced element whose kind of box follows from its display gets the kind for the display it uses, so a+ // table display never makes it a table part. And as an atomic inline, an inline one gets a block container.+ let kind_display = if node_facts::construction_facts_name_replaced_element(construction_facts) {+ let display = crate::layout::tree_builder::used_display_of_replaced_element(published_display);+ if display.is_inline_outside() && display.is_flow_inside() {+ FfiDisplay::outside_and_inside(display.outside, crate::css::css_enums::display_inside::FLOW_ROOT, false)+ } else {+ display+ }+ } else {+ published_display+ };let kind = match layout_kind {ElementLayoutKind::ContentReplacement => Some(NodeKind::ImageBox),ElementLayoutKind::SvgMask => Some(NodeKind::SVGMaskBox),ElementLayoutKind::SvgClipPath => Some(NodeKind::SVGClipBox),ElementLayoutKind::SvgPattern => Some(NodeKind::SVGPatternBox),- ElementLayoutKind::Normal => {- match node_kind_for_element_box_kind(box_kind, published_display, summary.appearance) {- Some(NodeKind::ListItemBox) if uses_button_layout => Some(NodeKind::BlockContainer),- kind => kind,- }- }+ ElementLayoutKind::Normal => match node_kind_for_element_box_kind(box_kind, kind_display, summary.appearance) {+ Some(NodeKind::ListItemBox) if uses_button_layout => Some(NodeKind::BlockContainer),+ kind => kind,+ },};let Some(kind) = kind else {return PreparedElement {diff --git a/Tests/LibWeb/Text/expected/input-with-table-display-size.txt b/Tests/LibWeb/Text/expected/input-with-table-display-size.txtnew file mode 100644index 00000000000..05987227e11--- /dev/null+++ b/Tests/LibWeb/Text/expected/input-with-table-display-size.txt@@ -0,0 +1,35 @@+submit table: same size as display: block+submit inline-table: same size as display: block+submit table-cell: same size as display: block+submit table-row: same size as display: block+submit table-row-group: same size as display: block+submit table-column: same size as display: block+submit table-caption: same size as display: block+button table: same size as display: block+button inline-table: same size as display: block+button table-cell: same size as display: block+button table-row: same size as display: block+button table-row-group: same size as display: block+button table-column: same size as display: block+button table-caption: same size as display: block+reset table: same size as display: block+reset inline-table: same size as display: block+reset table-cell: same size as display: block+reset table-row: same size as display: block+reset table-row-group: same size as display: block+reset table-column: same size as display: block+reset table-caption: same size as display: block+file table: same size as display: block+file inline-table: same size as display: block+file table-cell: same size as display: block+file table-row: same size as display: block+file table-row-group: same size as display: block+file table-column: same size as display: block+file table-caption: same size as display: block+color table: same size as display: block+color inline-table: same size as display: block+color table-cell: same size as display: block+color table-row: same size as display: block+color table-row-group: same size as display: block+color table-column: same size as display: block+color table-caption: same size as display: blockdiff --git a/Tests/LibWeb/Text/input/input-with-table-display-size.html b/Tests/LibWeb/Text/input/input-with-table-display-size.htmlnew file mode 100644index 00000000000..0e1eabfb91c--- /dev/null+++ b/Tests/LibWeb/Text/input/input-with-table-display-size.html@@ -0,0 +1,35 @@+<!doctype html>+<script src="include.js"></script>+<style>+ input {+ font: 16px sans-serif;+ margin: 0;+ }+</style>+<script>+ test(() => {+ const displays = ["table", "inline-table", "table-cell", "table-row", "table-row-group", "table-column", "table-caption"];+ for (const type of ["submit", "button", "reset", "file", "color"]) {+ const reference = document.createElement("input");+ reference.type = type;+ if (type !== "file") reference.value = "Send";+ reference.style.display = "block";+ document.body.append(reference);+ const expected = reference.getBoundingClientRect();+ for (const display of displays) {+ const wrapper = document.createElement("div");+ const input = document.createElement("input");+ input.type = type;+ if (type !== "file") input.value = "Send";+ input.style.display = display;+ wrapper.append(input);+ document.body.append(wrapper);+ const rect = input.getBoundingClientRect();+ const same = rect.width === expected.width && rect.height === expected.height;+ println(`${type} ${display}: ${same ? "same size as display: block" : `${rect.width}x${rect.height}, not ${expected.width}x${expected.height}`}`);+ wrapper.remove();+ }+ reference.remove();+ }+ });+</script>