From 40270cb6269f3f2d054bcfe51c69c8c545447f9a Mon Sep 17 00:00:00 2001 From: Kenzie Raditya Tirtarahardja Date: Sun, 23 Mar 2025 08:45:59 +0800 Subject: [PATCH] Make input element display-inside always flow-root (#35908) Signed-off-by: Kenzie Raditya Tirtarahardja Co-authored-by: Kenzie Raditya Tirtarahardja --- components/layout_2020/dom_traversal.rs | 30 +++++++++++++++++-- .../fragment_tree/base_fragment.rs | 16 +++++----- .../layout_2020/fragment_tree/box_fragment.rs | 4 +-- components/layout_2020/style_ext.rs | 28 +++++++++++++++-- tests/wpt/meta/MANIFEST.json | 24 +++++++++++++++ .../widgets/text-control-client-width.html | 19 ++++++++++++ .../widgets/text-control-flow-root-ref.html | 14 +++++++++ .../widgets/text-control-flow-root.html | 17 +++++++++++ 8 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 tests/wpt/tests/html/rendering/widgets/text-control-client-width.html create mode 100644 tests/wpt/tests/html/rendering/widgets/text-control-flow-root-ref.html create mode 100644 tests/wpt/tests/html/rendering/widgets/text-control-flow-root.html diff --git a/components/layout_2020/dom_traversal.rs b/components/layout_2020/dom_traversal.rs index 6b44c7f46b4..b8a39ad27fe 100644 --- a/components/layout_2020/dom_traversal.rs +++ b/components/layout_2020/dom_traversal.rs @@ -116,6 +116,15 @@ where }, _ => {}, } + + if matches!( + element.type_id(), + Some(LayoutNodeType::Element( + LayoutElementType::HTMLInputElement | LayoutElementType::HTMLTextAreaElement + )) + ) { + flags.insert(FragmentFlags::IS_TEXT_CONTROL); + } }; Self { @@ -135,12 +144,15 @@ pub(super) enum Contents { } #[derive(Debug)] +#[allow(clippy::enum_variant_names)] pub(super) enum NonReplacedContents { /// Refers to a DOM subtree, plus `::before` and `::after` pseudo-elements. OfElement, /// Content of a `::before` or `::after` pseudo-element that is being generated. /// OfPseudoElement(Vec), + /// Workaround for input and textarea element until we properly implement `display-inside`. + OfTextControl, } #[derive(Debug)] @@ -236,8 +248,18 @@ fn traverse_element<'dom, Node>( } }, Display::GeneratingBox(display) => { - let contents = - replaced.map_or(NonReplacedContents::OfElement.into(), Contents::Replaced); + let contents = if let Some(replaced) = replaced { + Contents::Replaced(replaced) + } else if matches!( + element.type_id(), + LayoutNodeType::Element( + LayoutElementType::HTMLInputElement | LayoutElementType::HTMLTextAreaElement + ) + ) { + NonReplacedContents::OfTextControl.into() + } else { + NonReplacedContents::OfElement.into() + }; let display = display.used_value_for_contents(&contents); let box_slot = element.element_box_slot(); let info = NodeAndStyleInfo::new(element, style); @@ -366,7 +388,9 @@ impl NonReplacedContents { }, }; match self { - NonReplacedContents::OfElement => traverse_children_of(node, context, handler), + NonReplacedContents::OfElement | NonReplacedContents::OfTextControl => { + traverse_children_of(node, context, handler) + }, NonReplacedContents::OfPseudoElement(items) => { traverse_pseudo_element_contents(info, context, handler, items) }, diff --git a/components/layout_2020/fragment_tree/base_fragment.rs b/components/layout_2020/fragment_tree/base_fragment.rs index 38f4f6ba815..45d10d5e282 100644 --- a/components/layout_2020/fragment_tree/base_fragment.rs +++ b/components/layout_2020/fragment_tree/base_fragment.rs @@ -75,31 +75,33 @@ impl From for BaseFragment { bitflags! { /// Flags used to track various information about a DOM node during layout. #[derive(Clone, Copy, Debug)] - pub(crate) struct FragmentFlags: u8 { + pub(crate) struct FragmentFlags: u16 { /// Whether or not the node that created this fragment is a `` element on an HTML document. const IS_BODY_ELEMENT_OF_HTML_ELEMENT_ROOT = 1 << 0; /// Whether or not the node that created this Fragment is a `
` element. const IS_BR_ELEMENT = 1 << 1; + /// Whether or not the node that created this Fragment is a `` or ` + + diff --git a/tests/wpt/tests/html/rendering/widgets/text-control-flow-root-ref.html b/tests/wpt/tests/html/rendering/widgets/text-control-flow-root-ref.html new file mode 100644 index 00000000000..df2783540d8 --- /dev/null +++ b/tests/wpt/tests/html/rendering/widgets/text-control-flow-root-ref.html @@ -0,0 +1,14 @@ + + + + +
+ +
+aaaaaa +
+ +
+ +
+aaaa diff --git a/tests/wpt/tests/html/rendering/widgets/text-control-flow-root.html b/tests/wpt/tests/html/rendering/widgets/text-control-flow-root.html new file mode 100644 index 00000000000..54f7612da34 --- /dev/null +++ b/tests/wpt/tests/html/rendering/widgets/text-control-flow-root.html @@ -0,0 +1,17 @@ + + +display inside of text control should always be flow-root + + + + +
+ +
+aaaaaa +
+ +
+ +
+aaaa